Commit 68932733 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Extract and convert styles for annotator sidebar container

Transition styling for the sidebar frame and its container to
tailwind. Rename some classes for clarity:

* `div.annotator-frame` -> `div.sidebar-container` as this is not a
   frame, and it contains the sidebar frame inside it
* `iframe.h-sidebar-iframe` -> `iframe.sidebar-frame`
parent d8f25398
...@@ -45,7 +45,7 @@ function createSidebarIframe(config) { ...@@ -45,7 +45,7 @@ function createSidebarIframe(config) {
sidebarFrame.src = sidebarAppSrc; sidebarFrame.src = sidebarAppSrc;
sidebarFrame.title = 'Hypothesis annotation viewer'; sidebarFrame.title = 'Hypothesis annotation viewer';
sidebarFrame.className = 'h-sidebar-iframe'; sidebarFrame.className = 'sidebar-frame';
return sidebarFrame; return sidebarFrame;
} }
...@@ -106,10 +106,10 @@ export class Sidebar { ...@@ -106,10 +106,10 @@ export class Sidebar {
} else { } else {
this.iframeContainer = document.createElement('div'); this.iframeContainer = document.createElement('div');
this.iframeContainer.style.display = 'none'; this.iframeContainer.style.display = 'none';
this.iframeContainer.className = 'annotator-frame'; this.iframeContainer.className = 'sidebar-container';
if (config.theme === 'clean') { if (config.theme === 'clean') {
this.iframeContainer.classList.add('annotator-frame--theme-clean'); this.iframeContainer.classList.add('theme-clean');
} else { } else {
this.bucketBar = new BucketBar(this.iframeContainer, { this.bucketBar = new BucketBar(this.iframeContainer, {
onFocusAnnotations: tags => onFocusAnnotations: tags =>
......
...@@ -190,11 +190,7 @@ describe('Sidebar', () => { ...@@ -190,11 +190,7 @@ describe('Sidebar', () => {
it('applies a style if theme is configured as "clean"', () => { it('applies a style if theme is configured as "clean"', () => {
const sidebar = createSidebar({ theme: 'clean' }); const sidebar = createSidebar({ theme: 'clean' });
assert.isTrue( assert.isTrue(sidebar.iframeContainer.classList.contains('theme-clean'));
sidebar.iframeContainer.classList.contains(
'annotator-frame--theme-clean'
)
);
}); });
it('becomes visible when the sidebar application has loaded', async () => { it('becomes visible when the sidebar application has loaded', async () => {
......
...@@ -3,108 +3,11 @@ ...@@ -3,108 +3,11 @@
// which do not use shadow roots go in other bundles (eg. highlights.css, // which do not use shadow roots go in other bundles (eg. highlights.css,
// pdfjs-overrides.scss). // pdfjs-overrides.scss).
@use 'sass:meta';
@use 'sass:color' as color;
@use '../variables' as var;
@use './base'; @use './base';
@use './components'; @use './components';
@use './utilities'; @use './utilities';
// Styles for all top-level elements in shadow roots. // Styles for all top-level elements in shadow roots.
:host > * { :host > * {
font-family: var.$sans-font-family; @apply font-sans;
}
// Sidebar
.annotator-frame {
// frame styles
position: fixed;
top: 0;
left: 100%;
height: 100%;
z-index: 2147483647;
direction: ltr;
font-size: var.$annotator-adder-font-size;
line-height: var.$annotator-base-line-height;
user-select: none;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
&.is-hidden {
visibility: hidden;
transition: visibility var.$annotator-timing--sidebar-collapse-transition;
}
&.annotator-collapsed {
margin-left: 0;
.h-sidebar-iframe {
// Add a transition when collapsing only. This serves to delay
// the effect until the sidebar finishes closing. Visibility is
// a boolean value and can not actually animate.
transition: visibility var.$annotator-timing--sidebar-collapse-transition;
visibility: hidden;
}
}
.h-sidebar-iframe {
border: none;
height: 100%;
width: 100%;
z-index: 3;
position: relative;
}
}
// this disables the width transition for the sidebar when
// it is manually resized by dragging
.annotator-no-transition {
transition: none !important;
}
/** Affordances for clean theme */
#{var.$annotator--theme-clean} {
box-shadow: var.$annotator-shadow--sidebar;
}
/*
Mobile layout
240-479 px
*/
@media screen and (min-width: 15em) {
.annotator-frame {
width: 90%;
margin-left: -90%;
}
}
/*
Wide mobile layout
480-599 px
*/
@media screen and (min-width: 30em) {
.annotator-frame {
width: 70%;
margin-left: -70%;
}
}
/*
Tablet layout
600-above px
*/
@media screen and (min-width: 37.5em) {
.annotator-frame {
transition: margin-left var.$annotator-timing--sidebar-collapse-transition
cubic-bezier(0.55, 0, 0.2, 0.8);
width: 428px;
margin-left: -428px;
}
} }
...@@ -4,3 +4,4 @@ ...@@ -4,3 +4,4 @@
// Annotator-specific components. // Annotator-specific components.
@use './AdderToolbar'; @use './AdderToolbar';
@use './Buckets'; @use './Buckets';
@use './sidebar';
/**
* Styles for the container and iframe containing the sidebar app. These
* classes are used by the `Sidebar` class (not a UI component).
*/
@layer utilities {
.sidebar-transition-visibility {
// This transition delays the visibility change to when
// collapsing the sidebar. This serves to delay
// the effect until the sidebar finishes closing. Visibility is
// a boolean value and can not actually animate.
@apply invisible transition-[visibility] duration-150;
}
.sidebar-transition-margin {
// This transition makes the sidebar slide in and off of the screen
// when opening or closing.
@apply transition-[margin-left] duration-150 ease-[cubic-bezier(0.55,0,0.2,0.8)];
}
}
@layer components {
.sidebar-container {
// Typically applied as an HTML attribute; there is no corresponding
// tailwind utility class
direction: ltr;
// Full height, fixed position all the way to the right (offscreen) to start
@apply fixed top-0 left-full h-full z-max select-none;
// Next, set different widths and left-margin positions for different
// breakpoints
@apply annotator-sm:w-[90%] annotator-sm:ml-[-90%];
@apply annotator-md:w-[70%] annotator-md:ml-[-70%];
@apply annotator-lg:w-[428px] annotator-lg:ml-[-428px];
// Wider screens: apply transition when opening/closing of the sidebar
@apply annotator-lg:sidebar-transition-margin;
&.is-hidden {
@apply sidebar-transition-visibility;
}
// We can't use `theme-clean:` or `sidebar-collapsed:` tailwind modifiers
// here because this is the one place in the project where the relevant
// classes are assigned to the same element, not a parent element.
&.theme-clean {
@apply shadow-sidebar;
}
&.sidebar-collapsed {
@apply ml-0;
}
}
// The sidebar's iframe
.sidebar-frame {
@apply relative border-0 h-full w-full z-3;
@apply sidebar-collapsed:sidebar-transition-visibility;
}
// this disables the width transition for the sidebar when
// it is manually resized by dragging
.annotator-no-transition {
transition: none !important;
}
}
...@@ -8,6 +8,8 @@ export default { ...@@ -8,6 +8,8 @@ export default {
'./src/annotator/components/**/*.js', './src/annotator/components/**/*.js',
'./dev-server/ui-playground/components/**/*.js', './dev-server/ui-playground/components/**/*.js',
'./node_modules/@hypothesis/frontend-shared/lib/**/*.js', './node_modules/@hypothesis/frontend-shared/lib/**/*.js',
// This module references `sidebar-frame` and related classes
'./src/annotator/sidebar.js',
], ],
theme: { theme: {
extend: { extend: {
...@@ -84,9 +86,18 @@ export default { ...@@ -84,9 +86,18 @@ export default {
}, },
}, },
}, },
screens: {
// Narrow mobile screens
'annotator-sm': '240px',
// Wider mobile screens/small tablets
'annotator-md': '480px',
// Tablet and up
'annotator-lg': '600px',
},
zIndex: { zIndex: {
1: '1', 1: '1',
2: '2', 2: '2',
3: '3',
max: '2147483647', max: '2147483647',
}, },
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment