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
84d6c6b5
Commit
84d6c6b5
authored
Dec 06, 2022
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Dec 13, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert `SelectionTabs` to TS
parent
cf04ea00
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
33 deletions
+38
-33
SelectionTabs.tsx
src/sidebar/components/SelectionTabs.tsx
+38
-33
No files found.
src/sidebar/components/SelectionTabs.
js
→
src/sidebar/components/SelectionTabs.
tsx
View file @
84d6c6b5
...
...
@@ -7,32 +7,36 @@ import {
PlusIcon
,
}
from
'@hypothesis/frontend-shared/lib/next'
;
import
classnames
from
'classnames'
;
import
type
{
ComponentChildren
}
from
'preact'
;
import
type
{
SidebarSettings
}
from
'../../types/config'
;
import
type
{
TabName
}
from
'../../types/sidebar'
;
import
{
applyTheme
}
from
'../helpers/theme'
;
import
type
{
AnnotationsService
}
from
'../services/annotations'
;
import
{
withServices
}
from
'../service-context'
;
import
{
useSidebarStore
}
from
'../store'
;
/**
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
* @typedef {import('../../types/sidebar').TabName} TabName
*/
type
TabProps
=
{
children
:
ComponentChildren
;
/**
* @typedef {import('preact').ComponentChildren} Children
*
* @typedef TabProps
* @prop {Children} children
* @prop {number} count - The total annotations for this tab
* @prop {boolean} isSelected - Is this tab currently selected?
* @prop {boolean} isWaitingToAnchor - Are there any annotations still waiting to anchor?
* @prop {string} label - A string label to use for a11y
* @prop {() => void} onSelect - Callback to invoke when this tab is selected
*/
/** The total number of annotations for this tab */
count
:
number
;
/** Is this tab the currently-active tab? */
isSelected
:
boolean
;
/** Are there any annotations still waiting to anchor? */
isWaitingToAnchor
:
boolean
;
label
:
string
;
/** Callback to invoke when this tab is selected */
onSelect
:
()
=>
void
;
};
/**
* Display name of the tab and annotation count
*
* @param {TabProps} props
*/
function
Tab
({
children
,
...
...
@@ -41,7 +45,7 @@ function Tab({
isSelected
,
label
,
onSelect
,
})
{
}
:
TabProps
)
{
const
selectTab
=
()
=>
{
if
(
!
isSelected
)
{
onSelect
();
...
...
@@ -52,13 +56,13 @@ function Tab({
return
(
<
LinkButton
classes
=
{
classnames
(
'
!inline
bg-transparent min-w-[5.25rem]'
,
{
classes=
{
classnames
(
'bg-transparent min-w-[5.25rem]'
,
{
'font-bold'
:
isSelected
,
})
}
color=
"text"
// 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
// to enable selecting the tab via other input methods.
color
=
"text"
onClick=
{
selectTab
}
onMouseDown=
{
selectTab
}
pressed=
{
!!
isSelected
}
...
...
@@ -79,19 +83,23 @@ function Tab({
);
}
/**
* @typedef SelectionTabsProps
* @prop {boolean} isLoading - Are we waiting on any annotations from the server?
* @prop {SidebarSettings} settings - Injected service.
* @prop {import('../services/annotations').AnnotationsService} annotationsService
*/
export
type
SelectionTabProps
=
{
/** Are we waiting on any annotations from the server? */
isLoading
:
boolean
;
// injected
settings
:
SidebarSettings
;
annotationsService
:
AnnotationsService
;
};
/**
* Tabbed display of annotations and notes
*
* @param {SelectionTabsProps} props
*/
function
SelectionTabs
({
annotationsService
,
isLoading
,
settings
})
{
function
SelectionTabs
({
annotationsService
,
isLoading
,
settings
,
}:
SelectionTabProps
)
{
const
store
=
useSidebarStore
();
const
selectedTab
=
store
.
selectedTab
();
const
noteCount
=
store
.
noteCount
();
...
...
@@ -99,10 +107,7 @@ function SelectionTabs({ annotationsService, isLoading, settings }) {
const
orphanCount
=
store
.
orphanCount
();
const
isWaitingToAnchorAnnotations
=
store
.
isWaitingToAnchorAnnotations
();
/**
* @param {TabName} tabId
*/
const
selectTab
=
tabId
=>
{
const
selectTab
=
(
tabId
:
TabName
)
=>
{
store
.
clearSelection
();
store
.
selectTab
(
tabId
);
};
...
...
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