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

Update shared components in `Toolbar`

parent 93f699c7
import { IconButton } from '@hypothesis/frontend-shared'; import {
ButtonBase,
AnnotateIcon,
CancelIcon,
CaretRightIcon,
CaretLeftIcon,
HideIcon,
NoteIcon,
ShowIcon,
} from '@hypothesis/frontend-shared/lib/next';
import classnames from 'classnames'; import classnames from 'classnames';
/** /**
* @typedef {import("@hypothesis/frontend-shared/lib/components/buttons").IconButtonProps} IconButtonProps * @typedef {import('@hypothesis/frontend-shared/lib/types').PresentationalProps} PresentationalProps
* * @typedef {import('@hypothesis/frontend-shared/lib/components/input/ButtonBase').ButtonCommonProps} ButtonCommonProps
* @typedef {Omit<IconButtonProps, "className">} ToolbarButtonProps * @typedef {Omit<import('preact').JSX.HTMLAttributes<HTMLButtonElement>, 'icon'|'size'>} HTMLButtonAttributes
* @typedef {import('@hypothesis/frontend-shared/lib/types').IconComponent} IconComponent
*/ */
/** /**
* Style an IconButton for use on the Toolbar * Style an IconButton for use on the Toolbar
* *
* @param {ToolbarButtonProps} props * @param {PresentationalProps & ButtonCommonProps & HTMLButtonAttributes & {icon: IconComponent}} props
*/ */
function ToolbarButton({ ...buttonProps }) { function ToolbarButton({ icon: Icon, ...buttonProps }) {
const { icon, title, ...restProps } = buttonProps;
return ( return (
<IconButton <ButtonBase
className={classnames( classes={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 'rounded-px', // size of border radius in absolute units
'flex items-center justify-center', 'flex items-center justify-center',
'border bg-white text-grey-6 hover:text-grey-9', 'border bg-white text-grey-6 hover:text-grey-9',
'shadow transition-colors' 'shadow transition-colors'
)} )}
icon={icon} {...buttonProps}
title={title} >
{...restProps} <Icon />
/> </ButtonBase>
); );
} }
...@@ -71,7 +80,7 @@ function StatusNotifier({ highlightsVisible }) { ...@@ -71,7 +80,7 @@ function StatusNotifier({ highlightsVisible }) {
* Callback to toggle visibility of highlights in the document. * Callback to toggle visibility of highlights in the document.
* @prop {() => void} toggleSidebar - * @prop {() => void} toggleSidebar -
* Callback to toggle the visibility of the sidebar. * Callback to toggle the visibility of the sidebar.
* @prop {import("preact").Ref<HTMLButtonElement>} [toggleSidebarRef] - * @prop {import("preact").RefObject<HTMLElement>} [toggleSidebarRef] -
* Ref that gets set to the toolbar button for toggling the sidebar. * Ref that gets set to the toolbar button for toggling the sidebar.
* This is exposed to enable the drag-to-resize functionality of this * This is exposed to enable the drag-to-resize functionality of this
* button. * button.
...@@ -114,8 +123,8 @@ export default function Toolbar({ ...@@ -114,8 +123,8 @@ export default function Toolbar({
absolutely positioned some way down the edge of the sidebar. absolutely positioned some way down the edge of the sidebar.
*/} */}
{useMinimalControls && isSidebarOpen && ( {useMinimalControls && isSidebarOpen && (
<IconButton <ButtonBase
className={classnames( classes={classnames(
'w-[27px] h-[27px] mt-[140px] ml-px-1.5', '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 transition-colors', 'text-grey-6 hover:text-grey-9 transition-colors',
...@@ -126,32 +135,34 @@ export default function Toolbar({ ...@@ -126,32 +135,34 @@ export default function Toolbar({
'shadow-sidebar' 'shadow-sidebar'
)} )}
title="Close annotation sidebar" title="Close annotation sidebar"
icon="cancel"
onClick={closeSidebar} onClick={closeSidebar}
/> >
<CancelIcon />
</ButtonBase>
)} )}
{!useMinimalControls && ( {!useMinimalControls && (
<> <>
<IconButton <ButtonBase
className={classnames( classes={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] pl-px-1.5', 'h-[40px] w-[33px] pl-[6px]',
'bg-white text-grey-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'
)} )}
buttonRef={toggleSidebarRef} elementRef={toggleSidebarRef}
title="Annotation sidebar" title="Annotation sidebar"
icon={isSidebarOpen ? 'caret-right' : 'caret-left'}
expanded={isSidebarOpen} expanded={isSidebarOpen}
pressed={isSidebarOpen} pressed={isSidebarOpen}
onClick={toggleSidebar} onClick={toggleSidebar}
/> >
{isSidebarOpen ? <CaretRightIcon /> : <CaretLeftIcon />}
</ButtonBase>
<div className="space-y-px-1.5 mt-px-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 ? ShowIcon : HideIcon}
selected={showHighlights} selected={showHighlights}
onClick={toggleHighlights} onClick={toggleHighlights}
/> />
...@@ -161,7 +172,7 @@ export default function Toolbar({ ...@@ -161,7 +172,7 @@ export default function Toolbar({
? 'New page note' ? 'New page note'
: 'New annotation' : 'New annotation'
} }
icon={newAnnotationType === 'note' ? 'note' : 'annotate'} icon={newAnnotationType === 'note' ? NoteIcon : AnnotateIcon}
onClick={createAnnotation} onClick={createAnnotation}
/> />
</div> </div>
......
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