Commit 409706c3 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Make annotator component UI scale correctly to host page

Make certain annotator components — the adder toolbar popup, e.g. —
scale when the root font size of the underlying host page changes.

Make sure other annotator UI that is associated with the sidebar — the
toolbar and bucket bar — do NOT scale with text scaling.

All controls should scale with user/page zoom.
parent 9481c420
...@@ -76,10 +76,10 @@ function ToolbarButton({ badgeCount, icon, label, onClick, shortcut }) { ...@@ -76,10 +76,10 @@ function ToolbarButton({ badgeCount, icon, label, onClick, shortcut }) {
'transition-colors duration-200', 'transition-colors duration-200',
'dim-item' 'dim-item'
)} )}
icon={icon}
onClick={onClick} onClick={onClick}
title={title} title={title}
> >
{icon && <Icon classes="text-annotator-lg" name={icon} title={title} />}
{typeof badgeCount === 'number' && <NumberIcon badgeCount={badgeCount} />} {typeof badgeCount === 'number' && <NumberIcon badgeCount={badgeCount} />}
<span className="font-normal">{label}</span> <span className="font-normal">{label}</span>
</LabeledButton> </LabeledButton>
......
...@@ -61,6 +61,10 @@ function BucketItem({ children, topPosition }) { ...@@ -61,6 +61,10 @@ function BucketItem({ children, topPosition }) {
* A list of buckets, including up and down navigation (when applicable) and * A list of buckets, including up and down navigation (when applicable) and
* on-screen buckets * on-screen buckets
* *
* This component and its buttons are sized with absolute units such that they
* don't scale with changes to the host page's root font size. They will still
* properly scale with user/browser zooming.
*
* @param {object} props * @param {object} props
* @param {Bucket} props.above * @param {Bucket} props.above
* @param {Bucket} props.below * @param {Bucket} props.below
......
...@@ -18,8 +18,9 @@ function ToolbarButton({ ...buttonProps }) { ...@@ -18,8 +18,9 @@ function ToolbarButton({ ...buttonProps }) {
<IconButton <IconButton
className={classnames( className={classnames(
'w-[30px] h-[30px]', // These buttons have precise dimensions 'w-[30px] h-[30px]', // These buttons have precise dimensions
'rounded-px', // size of border radius in absolute units
'flex items-center justify-center', 'flex items-center justify-center',
'border rounded bg-white text-grey-6 hover:text-grey-9 text-annotator-lg', 'border bg-white text-grey-6 hover:text-grey-9',
'shadow transition-colors' 'shadow transition-colors'
)} )}
icon={icon} icon={icon}
...@@ -61,6 +62,10 @@ function ToolbarButton({ ...buttonProps }) { ...@@ -61,6 +62,10 @@ function ToolbarButton({ ...buttonProps }) {
* Controls on the edge of the sidebar for opening/closing the sidebar, * Controls on the edge of the sidebar for opening/closing the sidebar,
* controlling highlight visibility and creating new page notes. * controlling highlight visibility and creating new page notes.
* *
* This component and its buttons are sized with absolute units such that they
* don't scale with changes to the host page's root font size. They will still
* properly scale with user/browser zooming.
*
* @param {ToolbarProps} props * @param {ToolbarProps} props
*/ */
export default function Toolbar({ export default function Toolbar({
...@@ -75,7 +80,12 @@ export default function Toolbar({ ...@@ -75,7 +80,12 @@ export default function Toolbar({
useMinimalControls = false, useMinimalControls = false,
}) { }) {
return ( return (
<div className="absolute left-[-33px] w-[33px] z-2"> <div
className={classnames(
'absolute left-[-33px] w-[33px] z-2',
'text-px-base leading-none' // non-scaling sizing
)}
>
{/* In the clean theme (`useMinimalControls` is `true`), {/* In the clean theme (`useMinimalControls` is `true`),
the only button that should appear is a button the only button that should appear is a button
to close the sidebar, and only if the sidebar is open. This button is to close the sidebar, and only if the sidebar is open. This button is
...@@ -84,9 +94,9 @@ export default function Toolbar({ ...@@ -84,9 +94,9 @@ export default function Toolbar({
{useMinimalControls && isSidebarOpen && ( {useMinimalControls && isSidebarOpen && (
<IconButton <IconButton
className={classnames( className={classnames(
'w-[27px] h-[27px] mt-[140px] ml-[6px]', 'w-[27px] h-[27px] mt-[140px] ml-px-1.5',
'flex items-center justify-center bg-white border', 'flex items-center justify-center bg-white border',
'text-grey-6 hover:text-grey-9 text-annotator-lg transition-colors', 'text-grey-6 hover:text-grey-9 transition-colors',
// Turn off right border to blend with sidebar // Turn off right border to blend with sidebar
'border-r-0', 'border-r-0',
// A more intense shadow than other ToolbarButtons, to match that // A more intense shadow than other ToolbarButtons, to match that
...@@ -103,8 +113,8 @@ export default function Toolbar({ ...@@ -103,8 +113,8 @@ export default function Toolbar({
<IconButton <IconButton
className={classnames( className={classnames(
// Height and width to align with the sidebar's top bar // Height and width to align with the sidebar's top bar
'h-[40px] w-[33px]', 'h-[40px] w-[33px] pl-px-1.5',
'bg-white text-grey-5 pl-1.5 hover:text-grey-9', 'bg-white text-grey-5 hover:text-grey-9',
// Turn on left and bottom borders to continue the // Turn on left and bottom borders to continue the
// border of the sidebar's top bar // border of the sidebar's top bar
'border-l border-b' 'border-l border-b'
...@@ -116,7 +126,7 @@ export default function Toolbar({ ...@@ -116,7 +126,7 @@ export default function Toolbar({
pressed={isSidebarOpen} pressed={isSidebarOpen}
onClick={toggleSidebar} onClick={toggleSidebar}
/> />
<div className="space-y-1.5 mt-2"> <div className="space-y-px-1.5 mt-px-2">
<ToolbarButton <ToolbarButton
title="Show highlights" title="Show highlights"
icon={showHighlights ? 'show' : 'hide'} icon={showHighlights ? 'show' : 'hide'}
......
...@@ -12,10 +12,16 @@ ...@@ -12,10 +12,16 @@
// down or left. On its own, it will be lozenge-shaped. Compose with one // down or left. On its own, it will be lozenge-shaped. Compose with one
// of the directional classes below to style a button fully, e.g. // of the directional classes below to style a button fully, e.g.
// `classname="BucketButton LeftBucketButton` // `classname="BucketButton LeftBucketButton`
// These buttons use absolute units for sizing, fonts, border-radius. This is
// purposeful: they should not scale with root-font scaling in the host page.
// This is to make sure they still properly align with the sidebar UI.
//
// These will still properly scale if the user zooms the font in the browser.
.BucketButton { .BucketButton {
// A lozenge-shaped element with very small text // A lozenge-shaped element with very small text
@apply w-[26px] h-[16px] absolute border bg-white shadow rounded; @apply w-[26px] h-[16px] absolute border bg-white shadow rounded-px;
@apply font-sans text-center text-tiny font-bold text-color-text-light leading-none; @apply font-sans text-center text-px-tiny font-bold text-color-text-light leading-none;
// Establish :before and :after content for later manipulation into // Establish :before and :after content for later manipulation into
// different pointer shapes and directions // different pointer shapes and directions
...@@ -27,7 +33,7 @@ ...@@ -27,7 +33,7 @@
// Style a `BucketButton` to point left // Style a `BucketButton` to point left
.LeftBucketButton { .LeftBucketButton {
@apply rounded-r rounded-l-sm; @apply rounded-r-px rounded-l-px-sm;
// Position to the left of the button and centered vertically // Position to the left of the button and centered vertically
&::before, &::before,
...@@ -54,7 +60,7 @@ ...@@ -54,7 +60,7 @@
// Style a `BucketButton` to point up // Style a `BucketButton` to point up
.UpBucketButton { .UpBucketButton {
// Z-index assures that left-pointing buttons will scroll behind this // Z-index assures that left-pointing buttons will scroll behind this
@apply z-1 rounded-t-sm rounded-b; @apply z-1 rounded-t-px-sm rounded-b-px;
// Position above the button and horizontally centered // Position above the button and horizontally centered
&::before, &::before,
...@@ -79,7 +85,7 @@ ...@@ -79,7 +85,7 @@
// Style a `BucketButton` to point down // Style a `BucketButton` to point down
.DownBucketButton { .DownBucketButton {
// Z-index assures that left-pointing buttons will scroll behind this // Z-index assures that left-pointing buttons will scroll behind this
@apply z-1 rounded-t rounded-b-sm; @apply z-1 rounded-t-px rounded-b-px-sm;
// Position below the button and horizontally centered // Position below the button and horizontally centered
&::before, &::before,
......
...@@ -17,6 +17,14 @@ export default { ...@@ -17,6 +17,14 @@ export default {
adderPopUp: 'adderPopUp 0.08s ease-in forwards', adderPopUp: 'adderPopUp 0.08s ease-in forwards',
adderPopDown: 'adderPopDown 0.08s ease-in forwards', adderPopDown: 'adderPopDown 0.08s ease-in forwards',
}, },
borderRadius: {
// Tailwind provides a default set of border-radius utility styles
// in rem units. Add some values for places where border radius needs
// to be a fixed size and not scale with changes to root font size
// example: bucket bar indicator buttons
'px-sm': '2px',
px: '4px',
},
boxShadow: { boxShadow: {
DEFAULT: '0 1px 1px rgba(0, 0, 0, 0.1)', DEFAULT: '0 1px 1px rgba(0, 0, 0, 0.1)',
adderToolbar: '0px 2px 10px 0px rgba(0, 0, 0, 0.25)', adderToolbar: '0px 2px 10px 0px rgba(0, 0, 0, 0.25)',
...@@ -45,18 +53,26 @@ export default { ...@@ -45,18 +53,26 @@ export default {
// in the app (descriptive), but should not be interpreted as defining // in the app (descriptive), but should not be interpreted as defining
// an ideal design system (prescriptive). // an ideal design system (prescriptive).
fontSize: { fontSize: {
// This is a collection of font sizes used in existing sidebar components,
// which will grow during the conversion-to-Tailwind process. These
// are descriptive, not aspirational or prescriptive.
tiny: ['10px'], tiny: ['10px'],
sm: ['11px', '1.4'], sm: ['11px', '1.4'],
base: ['13px', '1.4'], base: ['13px', '1.4'], // Current base font size for sidebar
lg: ['14px'], lg: ['14px'],
xl: ['16px'], xl: ['16px'],
// Keep separate font settings for the annotator; these may need to // rem-based font sizes for annotator controls that should scale
// remain as pixels when sidebar converts to rems or otherwise be // with text scaling in the underlying document
// independent of sidebar font sizes 'annotator-sm': ['0.75rem'],
'annotator-sm': ['12px'], 'annotator-base': ['0.875rem'],
'annotator-base': ['14px'], 'annotator-lg': ['1rem'],
'annotator-lg': ['16px'], 'annotator-xl': ['1.125rem'],
'annotator-xl': ['18px'], // These are known cases when we want absolute sizing for fonts so
// that they do not scale, for example annotator components that are
// rendered next to the sidebar (which doesn't scale with host root
// font sizing)
'px-tiny': ['10px'],
'px-base': ['16px'],
}, },
keyframes: { keyframes: {
adderPopDown: { adderPopDown: {
...@@ -94,6 +110,15 @@ export default { ...@@ -94,6 +110,15 @@ export default {
// Tablet and up // Tablet and up
'annotator-lg': '600px', 'annotator-lg': '600px',
}, },
spacing: {
// These are selective, pixel-specific variants of Tailwind's default
// rem-based spacing scale and follow the same naming conventions with
// a `px-` prefix. They should only be used where UI should not scale
// with text scaling (i.e. `1rem != 16px`). Example: spacing between
// buttons in the annotator toolbar
'px-1.5': '6px',
'px-2': '8px',
},
zIndex: { zIndex: {
1: '1', 1: '1',
2: '2', 2: '2',
......
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