Skip to content

Commit ad24c55

Browse files
committed
Convert AnnotationShareControl to TW and use shared Card component
Previously, this component was _styled_ as a "panel", via SASS mixins, but did not have any behavioral "panel-ness." For now, use the shared Card (presentational) component for this component, and remove unused SASS and mixins.
1 parent e9cdc38 commit ad24c55

File tree

5 files changed

+70
-107
lines changed

5 files changed

+70
-107
lines changed

src/sidebar/components/Annotation/AnnotationShareControl.js

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
2+
Card,
23
Icon,
34
IconButton,
45
TextInput,
56
TextInputWithButton,
67
useElementShouldClose,
78
} from '@hypothesis/frontend-shared';
9+
import classnames from 'classnames';
810
import { useEffect, useRef, useState } from 'preact/hooks';
911

1012
import { isShareableURI } from '../../helpers/annotation-sharing';
@@ -37,6 +39,23 @@ function selectionOverflowsInputElement() {
3739
return isIOS();
3840
}
3941

42+
/**
43+
*
44+
* @param {object} props
45+
* @param {string} [props.classes] - Optional additional CSS classes
46+
*/
47+
function MenuArrowDown({ classes }) {
48+
return (
49+
<Icon
50+
name="pointer"
51+
classes={classnames(
52+
'absolute inline z-2 text-grey-3 fill-white rotate-180',
53+
classes
54+
)}
55+
/>
56+
);
57+
}
58+
4059
/**
4160
* "Popup"-style component for sharing a single annotation.
4261
*
@@ -123,53 +142,69 @@ function AnnotationShareControl({
123142
);
124143

125144
return (
126-
<div className="AnnotationShareControl" ref={shareRef}>
145+
<div className="relative" ref={shareRef}>
127146
<IconButton
128147
icon="share"
129148
title="Share"
130149
onClick={toggleSharePanel}
131150
expanded={isOpen}
132151
/>
133152
{isOpen && (
134-
<div className="annotation-share-panel">
135-
<div className="annotation-share-panel__header">
136-
<div className="annotation-share-panel__title">
153+
<Card
154+
classes={classnames(
155+
// Prefer width 96 (24rem) but ensure that component isn't wider
156+
// than 85vw
157+
'w-96 max-w-[85vw]',
158+
// Position this Card above its IconButton. Account for larger
159+
// IconButtons in touch interfaces
160+
'absolute bottom-8 right-1 touch:bottom-touch-minimum',
161+
'space-y-2 p-2',
162+
// Cards do not have a border in the clean theme. Turn it back on.
163+
'theme-clean:border'
164+
)}
165+
>
166+
<div className="flex items-center pb-2 border-b">
167+
<h2 className="text-brand text-lg font-medium">
137168
Share this annotation
138-
</div>
169+
</h2>
170+
</div>
171+
<div
172+
className={classnames(
173+
// Slightly larger font size for touch devices to correspond with
174+
// larger button and input sizes
175+
'flex w-full text-sm touch:text-base'
176+
)}
177+
>
178+
<TextInputWithButton>
179+
<TextInput
180+
aria-label="Use this URL to share this annotation"
181+
type="text"
182+
value={shareUri}
183+
readOnly
184+
inputRef={inputRef}
185+
/>
186+
<IconButton
187+
icon="copy"
188+
title="Copy share link to clipboard"
189+
onClick={copyShareLink}
190+
variant="dark"
191+
/>
192+
</TextInputWithButton>
139193
</div>
140-
<div className="annotation-share-panel__content">
141-
<div className="hyp-u-layout-row annotation-share-panel__inputs">
142-
<TextInputWithButton>
143-
<TextInput
144-
aria-label="Use this URL to share this annotation"
145-
type="text"
146-
value={shareUri}
147-
readOnly
148-
inputRef={inputRef}
149-
/>
150-
<IconButton
151-
icon="copy"
152-
title="Copy share link to clipboard"
153-
onClick={copyShareLink}
154-
variant="dark"
155-
/>
156-
</TextInputWithButton>
157-
</div>
194+
<div className="text-base font-normal" data-testid="share-details">
158195
{inContextAvailable ? (
159-
<div className="annotation-share-panel__details">
160-
{annotationSharingInfo}
161-
</div>
196+
<>{annotationSharingInfo}</>
162197
) : (
163-
<div className="annotation-share-panel__details">
198+
<>
164199
This annotation cannot be shared in its original context because
165200
it was made on a document that is not available on the web. This
166201
link shares the annotation by itself.
167-
</div>
202+
</>
168203
)}
169-
{showShareLinks && <ShareLinks shareURI={shareUri} />}
170204
</div>
171-
<Icon name="pointer" classes="annotation-share-panel__arrow" />
172-
</div>
205+
{showShareLinks && <ShareLinks shareURI={shareUri} />}
206+
<MenuArrowDown classes="bottom-[-12px] right-1 touch:right-[9px]" />
207+
</Card>
173208
)}
174209
</div>
175210
);

src/sidebar/components/Annotation/test/AnnotationShareControl-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe('AnnotationShareControl', () => {
106106
const wrapper = createComponent();
107107

108108
// Component is not `open` initially
109-
assert.isFalse(wrapper.find('.annotation-share-panel').exists());
109+
assert.isFalse(wrapper.find('Card').exists());
110110
});
111111

112112
it('toggles the share control element when the button is clicked', () => {
@@ -118,7 +118,7 @@ describe('AnnotationShareControl', () => {
118118
});
119119
wrapper.update();
120120

121-
assert.isTrue(wrapper.find('.annotation-share-panel').exists());
121+
assert.isTrue(wrapper.find('Card').exists());
122122
});
123123

124124
it('renders the share URI in a readonly input field', () => {
@@ -194,7 +194,7 @@ describe('AnnotationShareControl', () => {
194194
const wrapper = createComponent({ isPrivate: testcase.isPrivate });
195195
openElement(wrapper);
196196

197-
const permissionsEl = wrapper.find('.annotation-share-panel__details');
197+
const permissionsEl = wrapper.find('[data-testid="share-details"]');
198198
assert.equal(permissionsEl.text(), testcase.expected);
199199
});
200200
});
@@ -204,7 +204,7 @@ describe('AnnotationShareControl', () => {
204204
const wrapper = createComponent();
205205
openElement(wrapper);
206206

207-
const detailsEl = wrapper.find('.annotation-share-panel__details');
207+
const detailsEl = wrapper.find('[data-testid="share-details"]');
208208
assert.include(
209209
detailsEl.text(),
210210
'This annotation cannot be shared in its original context'

src/styles/mixins/molecules.scss

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,6 @@
105105
}
106106
}
107107

108-
/**
109-
* `panel` with tighter margins and padding, for use in more confined spaces
110-
*/
111-
@mixin panel--compact {
112-
@include panel($rhythm: var.$layout-space--xsmall);
113-
width: 24em;
114-
// Keep panel constrained within annotation card boundaries and not cut off
115-
// on left side when sidebar is extremely narrow
116-
max-width: 85vw;
117-
padding: var.$layout-space--small;
118-
119-
&__header {
120-
padding-bottom: var.$layout-space--xsmall;
121-
}
122-
}
123-
124108
/**
125109
* A full-width banner with optional "type" and styled icon at left
126110
*/

src/styles/sidebar/components/AnnotationShareControl.scss

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/styles/sidebar/components/_index.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
// UI (Preact) Components
1414
// ----------
15-
@use './AnnotationShareControl';
1615
@use './AutocompleteList';
1716
@use './FilterSelect';
1817
@use './FilterStatus';

0 commit comments

Comments
 (0)