Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
d674e11b
Commit
d674e11b
authored
Jan 23, 2023
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Jan 24, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert `Buckets` to TS
Perform an internal refactor to reduce the number of internal components
parent
0facdc30
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
72 deletions
+61
-72
Buckets.tsx
src/annotator/components/Buckets.tsx
+59
-70
Buckets-test.js
src/annotator/components/test/Buckets-test.js
+2
-2
No files found.
src/annotator/components/Buckets.
js
→
src/annotator/components/Buckets.
tsx
View file @
d674e11b
import
{
LabeledButton
}
from
'@hypothesis/frontend-shared'
;
import
{
LabeledButton
}
from
'@hypothesis/frontend-shared'
;
import
classnames
from
'classnames'
;
import
classnames
from
'classnames'
;
/**
import
type
{
Bucket
}
from
'../util/buckets'
;
* @typedef {import('../util/buckets').Bucket} Bucket
* @typedef {import("preact").ComponentChildren} Children
*/
/**
export
type
BucketsProps
=
{
* Render a set of buckets in a vertical channel positioned along the edge of
/**
* the sidebar.
* Bucket containing the $tags of any annotations that are offscreen above
*
* the current viewport. If the set of $tags is non-empty, up navigation
* @param {object} props
* will be rendered.
* @param {Children} props.children
*/
*/
above
:
Bucket
;
function
BucketList
({
children
})
{
return
(
<
ul
className
=
{
classnames
(
// 2020-11-20: Making bucket bar one pixel wider (23px vs 22px) is an
// interim and pragmatic solution for an apparent glitch on
// Safari and Chrome. Adding one pixel resolves this issue:
// https://github.com/hypothesis/client/pull/2750
'absolute w-[23px] left-[-22px] h-full'
,
// The background is set to low opacity when the sidebar is collapsed.
'bg-grey-2 sidebar-collapsed:bg-black/[.08]'
,
// Disable pointer events along the sidebar itself; re-enable them in
// bucket indicator buttons
'pointer-events-none'
)}
>
{
children
}
<
/ul
>
);
}
/**
/**
* Render a vertically-positioned bucket-list item.
* Bucket containing the $tags of any annotations that are offscreen below
*
* the current viewport. If the set of $tags is non-empty, down navigation
* @param {object} props
* will be rendered.
* @param {Children} props.children
*/
* @param {number} props.topPosition - The vertical top position, in pixels,
below
:
Bucket
;
* for this bucket item relative to the top of the containing BucketList
*/
/**
function
BucketItem
({
children
,
topPosition
})
{
* A list of buckets visible on-screen. A left-pointing arrow will be
return
(
* rendered for each bucket.
<
li
*/
className
=
{
classnames
(
buckets
:
Bucket
[];
'absolute right-0'
,
onFocusAnnotations
:
(
$tags
:
string
[])
=>
void
;
// Re-enable pointer events, which are disabled on the containing list
onScrollToClosestOffScreenAnchor
:
(
'pointer-events-auto'
$tags
:
string
[],
)}
direction
:
'down'
|
'up'
style
=
{{
top
:
topPosition
}}
)
=>
void
;
>
onSelectAnnotations
:
(
$tags
:
string
[],
toggle
:
boolean
)
=>
void
;
{
children
}
};
<
/li
>
);
}
/**
/**
* A list of buckets, including up and down navigation (when applicable) and
* A list of buckets, including up and down navigation (when applicable) and
...
@@ -64,14 +38,6 @@ function BucketItem({ children, topPosition }) {
...
@@ -64,14 +38,6 @@ function BucketItem({ children, topPosition }) {
* This component and its buttons are sized with absolute units such that they
* 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
* don't scale with changes to the host page's root font size. They will still
* properly scale with user/browser zooming.
* properly scale with user/browser zooming.
*
* @param {object} props
* @param {Bucket} props.above
* @param {Bucket} props.below
* @param {Bucket[]} props.buckets
* @param {(tags: string[]) => void} props.onFocusAnnotations
* @param {(tags: string[], direction: 'down'|'up') => void} props.onScrollToClosestOffScreenAnchor
* @param {(tags: string[], toggle: boolean) => void} props.onSelectAnnotations
*/
*/
export
default
function
Buckets
({
export
default
function
Buckets
({
above
,
above
,
...
@@ -80,14 +46,30 @@ export default function Buckets({
...
@@ -80,14 +46,30 @@ export default function Buckets({
onFocusAnnotations
,
onFocusAnnotations
,
onScrollToClosestOffScreenAnchor
,
onScrollToClosestOffScreenAnchor
,
onSelectAnnotations
,
onSelectAnnotations
,
})
{
}
:
BucketsProps
)
{
const
showUpNavigation
=
above
.
tags
.
size
>
0
;
const
showUpNavigation
=
above
.
tags
.
size
>
0
;
const
showDownNavigation
=
below
.
tags
.
size
>
0
;
const
showDownNavigation
=
below
.
tags
.
size
>
0
;
return
(
return
(
<
BucketList
>
<
ul
className=
{
classnames
(
// 2020-11-20: Making bucket bar one pixel wider (23px vs 22px) is an
// interim and pragmatic solution for an apparent glitch on
// Safari and Chrome. Adding one pixel resolves this issue:
// https://github.com/hypothesis/client/pull/2750
'absolute w-[23px] left-[-22px] h-full'
,
// The background is set to low opacity when the sidebar is collapsed.
'bg-grey-2 sidebar-collapsed:bg-black/[.08]'
,
// Disable pointer events along the sidebar itself; re-enable them in
// bucket indicator buttons
'pointer-events-none'
)
}
>
{
showUpNavigation
&&
(
{
showUpNavigation
&&
(
<
BucketItem
topPosition
=
{
above
.
position
}
>
<
li
className=
"absolute right-0 pointer-events-auto"
style=
{
{
top
:
above
.
position
}
}
>
<
LabeledButton
<
LabeledButton
className=
{
classnames
(
className=
{
classnames
(
'BucketButton UpBucketButton'
,
'BucketButton UpBucketButton'
,
...
@@ -109,10 +91,14 @@ export default function Buckets({
...
@@ -109,10 +91,14 @@ export default function Buckets({
>
>
{
above
.
tags
.
size
}
{
above
.
tags
.
size
}
</
LabeledButton
>
</
LabeledButton
>
<
/
BucketItem
>
</
li
>
)
}
)
}
{
buckets
.
map
((
bucket
,
index
)
=>
(
{
buckets
.
map
((
bucket
,
index
)
=>
(
<
BucketItem
topPosition
=
{
bucket
.
position
}
key
=
{
index
}
>
<
li
className=
"absolute right-0 pointer-events-auto"
key=
{
index
}
style=
{
{
top
:
bucket
.
position
}
}
>
<
LabeledButton
<
LabeledButton
className=
{
classnames
(
className=
{
classnames
(
'BucketButton LeftBucketButton'
,
'BucketButton LeftBucketButton'
,
...
@@ -134,10 +120,13 @@ export default function Buckets({
...
@@ -134,10 +120,13 @@ export default function Buckets({
>
>
{
bucket
.
tags
.
size
}
{
bucket
.
tags
.
size
}
</
LabeledButton
>
</
LabeledButton
>
<
/
BucketItem
>
</
li
>
))
}
))
}
{
showDownNavigation
&&
(
{
showDownNavigation
&&
(
<
BucketItem
topPosition
=
{
below
.
position
}
>
<
li
className=
"absolute right-0 pointer-events-auto"
style=
{
{
top
:
below
.
position
}
}
>
<
LabeledButton
<
LabeledButton
className=
"BucketButton DownBucketButton right-0"
className=
"BucketButton DownBucketButton right-0"
data
-
testid=
"down-navigation-button"
data
-
testid=
"down-navigation-button"
...
@@ -152,8 +141,8 @@ export default function Buckets({
...
@@ -152,8 +141,8 @@ export default function Buckets({
>
>
{
below
.
tags
.
size
}
{
below
.
tags
.
size
}
</
LabeledButton
>
</
LabeledButton
>
<
/
BucketItem
>
</
li
>
)
}
)
}
<
/
BucketList
>
</
ul
>
);
);
}
}
src/annotator/components/test/Buckets-test.js
View file @
d674e11b
...
@@ -124,7 +124,7 @@ describe('Buckets', () => {
...
@@ -124,7 +124,7 @@ describe('Buckets', () => {
const
wrapper
=
createComponent
();
const
wrapper
=
createComponent
();
const
upButton
=
wrapper
.
find
(
upButtonSelector
);
const
upButton
=
wrapper
.
find
(
upButtonSelector
);
// The list item element wrapping the button
// The list item element wrapping the button
const
bucketItem
=
wrapper
.
find
(
'
BucketItem
'
).
first
();
const
bucketItem
=
wrapper
.
find
(
'
li
'
).
first
();
assert
.
isTrue
(
upButton
.
exists
());
assert
.
isTrue
(
upButton
.
exists
());
assert
.
equal
(
assert
.
equal
(
...
@@ -144,7 +144,7 @@ describe('Buckets', () => {
...
@@ -144,7 +144,7 @@ describe('Buckets', () => {
const
downButton
=
wrapper
.
find
(
downButtonSelector
);
const
downButton
=
wrapper
.
find
(
downButtonSelector
);
// The list item element wrapping the button
// The list item element wrapping the button
const
bucketItem
=
wrapper
.
find
(
'
BucketItem
'
).
last
();
const
bucketItem
=
wrapper
.
find
(
'
li
'
).
last
();
assert
.
isTrue
(
downButton
.
exists
());
assert
.
isTrue
(
downButton
.
exists
());
assert
.
equal
(
assert
.
equal
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment