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

Convert SelectionTabs to Tailwind

parent fb95af45
import { Frame, Icon, LabeledButton } from '@hypothesis/frontend-shared'; import {
Frame,
Icon,
LabeledButton,
LinkButton,
} from '@hypothesis/frontend-shared';
import classnames from 'classnames'; import classnames from 'classnames';
import { applyTheme } from '../helpers/theme'; import { applyTheme } from '../helpers/theme';
...@@ -44,10 +49,13 @@ function Tab({ ...@@ -44,10 +49,13 @@ function Tab({
const title = count > 0 ? `${label} (${count} available)` : label; const title = count > 0 ? `${label} (${count} available)` : label;
return ( return (
<LabeledButton <LinkButton
classes={classnames('text-color-text', 'SelectionTab', { classes={classnames(
'is-selected': isSelected, 'inline bg-transparent min-w-[5.25rem] text-color-text hover:!no-underline',
})} {
'font-bold': isSelected,
}
)}
// Listen for `onMouseDown` so that the tab is selected when _pressed_ // Listen for `onMouseDown` so that the tab is selected when _pressed_
// as this makes the UI feel faster. Also listen for `onClick` as a fallback // as this makes the UI feel faster. Also listen for `onClick` as a fallback
// to enable selecting the tab via other input methods. // to enable selecting the tab via other input methods.
...@@ -61,15 +69,12 @@ function Tab({ ...@@ -61,15 +69,12 @@ function Tab({
<> <>
{children} {children}
{count > 0 && !isWaitingToAnchor && ( {count > 0 && !isWaitingToAnchor && (
<span <span className="relative bottom-[3px] left-[2px] text-tiny">
className="text-tiny"
style="position:relative;bottom:3px;left:2px"
>
{count} {count}
</span> </span>
)} )}
</> </>
</LabeledButton> </LinkButton>
); );
} }
...@@ -109,11 +114,13 @@ function SelectionTabs({ annotationsService, isLoading, settings }) { ...@@ -109,11 +114,13 @@ function SelectionTabs({ annotationsService, isLoading, settings }) {
const showNotesUnavailableMessage = selectedTab === 'note' && noteCount === 0; const showNotesUnavailableMessage = selectedTab === 'note' && noteCount === 0;
return ( return (
<div className="hyp-u-vertical-spacing--4 SelectionTabs__container">
<div <div
className="hyp-u-layout-row hyp-u-horizontal-spacing--6 SelectionTabs" className={classnames(
role="tablist" // 9px balances out the space above the tabs
'space-y-3 pb-[9px]'
)}
> >
<div className="flex gap-x-6 theme-clean:ml-[15px]" role="tablist">
<Tab <Tab
count={annotationCount} count={annotationCount}
isWaitingToAnchor={isWaitingToAnchorAnnotations} isWaitingToAnchor={isWaitingToAnchorAnnotations}
...@@ -145,7 +152,7 @@ function SelectionTabs({ annotationsService, isLoading, settings }) { ...@@ -145,7 +152,7 @@ function SelectionTabs({ annotationsService, isLoading, settings }) {
)} )}
</div> </div>
{selectedTab === 'note' && settings.enableExperimentalNewNoteButton && ( {selectedTab === 'note' && settings.enableExperimentalNewNoteButton && (
<div className="hyp-u-layout-row--justify-right"> <div className="flex justify-end">
<LabeledButton <LabeledButton
data-testid="new-note-button" data-testid="new-note-button"
icon="add" icon="add"
...@@ -171,7 +178,7 @@ function SelectionTabs({ annotationsService, isLoading, settings }) { ...@@ -171,7 +178,7 @@ function SelectionTabs({ annotationsService, isLoading, settings }) {
<br /> <br />
Create one by selecting some text and clicking the{' '} Create one by selecting some text and clicking the{' '}
<Icon <Icon
classes="m-0.5 inline -mt-0.5" classes="inline m-0.5 -mt-0.5"
name="annotate" name="annotate"
title="Annotate" title="Annotate"
/>{' '} />{' '}
......
...@@ -72,8 +72,8 @@ describe('SelectionTabs', () => { ...@@ -72,8 +72,8 @@ describe('SelectionTabs', () => {
const annotationTab = wrapper.find('Tab[label="Annotations"]'); const annotationTab = wrapper.find('Tab[label="Annotations"]');
const noteTab = wrapper.find('Tab[label="Page notes"]'); const noteTab = wrapper.find('Tab[label="Page notes"]');
assert.isTrue(annotationTab.find('LabeledButton').props().pressed); assert.isTrue(annotationTab.find('LinkButton').props().pressed);
assert.isFalse(noteTab.find('LabeledButton').props().pressed); assert.isFalse(noteTab.find('LinkButton').props().pressed);
}); });
it('should not display the add-page-note button when the annotations tab is active', () => { it('should not display the add-page-note button when the annotations tab is active', () => {
...@@ -93,12 +93,11 @@ describe('SelectionTabs', () => { ...@@ -93,12 +93,11 @@ describe('SelectionTabs', () => {
const annotationTabButton = wrapper const annotationTabButton = wrapper
.find('Tab[label="Annotations"]') .find('Tab[label="Annotations"]')
.find('LabeledButton'); .find('LinkButton');
const noteTabButton = wrapper const noteTabButton = wrapper
.find('Tab[label="Page notes"]') .find('Tab[label="Page notes"]')
.find('LabeledButton'); .find('LinkButton');
assert.isTrue(noteTabButton.find('button').hasClass('is-selected'));
assert.isTrue(noteTabButton.prop('pressed')); assert.isTrue(noteTabButton.prop('pressed'));
assert.isFalse(annotationTabButton.prop('pressed')); assert.isFalse(annotationTabButton.prop('pressed'));
}); });
...@@ -175,7 +174,7 @@ describe('SelectionTabs', () => { ...@@ -175,7 +174,7 @@ describe('SelectionTabs', () => {
const wrapper = createComponent(); const wrapper = createComponent();
const orphanTab = wrapper.find('Tab[label="Orphans"]'); const orphanTab = wrapper.find('Tab[label="Orphans"]');
assert.isTrue(orphanTab.find('LabeledButton').prop('pressed')); assert.isTrue(orphanTab.find('LinkButton').prop('pressed'));
}); });
it('should not display orphans tab if there are 0 orphans', () => { it('should not display orphans tab if there are 0 orphans', () => {
......
@use '../../variables' as var;
.SelectionTabs__container {
// FIXME: This should be a margin, and it should be handled by the parent,
// but needs to be considered carefully because applying vertical rhythm to
// this component's parent messes with the calculations in the virtualized
// thread list. Needs another pass. Note also that it is `10px` (and looks
// unbalanced at the standard vertical rhythm size of `1rem`)
padding-bottom: 10px;
}
.SelectionTab {
margin: 0;
padding: 0;
font-weight: normal;
background-color: transparent;
min-width: 5.25rem;
&:hover:not([disabled]) {
color: var.$color-link-hover;
}
&.is-selected {
font-weight: bold;
}
}
/** Clean theme affordances */
#{var.$sidebar--theme-clean} .SelectionTabs {
margin-left: 15px;
}
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
@use './NotebookView'; @use './NotebookView';
@use './NotebookResultCount'; @use './NotebookResultCount';
@use './PaginationNavigation'; @use './PaginationNavigation';
@use './SelectionTabs';
@use './SearchInput'; @use './SearchInput';
@use './StyledText'; @use './StyledText';
@use './ToastMessages'; @use './ToastMessages';
......
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