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
6d8a96b7
Commit
6d8a96b7
authored
Nov 29, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Nov 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a more prominent pressed state for top bar buttons
parent
247f7eff
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
18 deletions
+48
-18
PressableIconButton.tsx
src/sidebar/components/PressableIconButton.tsx
+25
-0
TopBar.tsx
src/sidebar/components/TopBar.tsx
+9
-9
TopBar-test.js
src/sidebar/components/test/TopBar-test.js
+14
-9
No files found.
src/sidebar/components/PressableIconButton.tsx
0 → 100644
View file @
6d8a96b7
import
type
{
IconButtonProps
}
from
'@hypothesis/frontend-shared'
;
import
{
IconButton
}
from
'@hypothesis/frontend-shared'
;
import
classnames
from
'classnames'
;
export
type
PressableIconButtonProps
=
IconButtonProps
;
/**
* An IconButton which can be used as a toggle with a more visible pressed state.
* Appropriate when the pressed state is not otherwise obvious from the context.
*/
export
default
function
PressableIconButton
({
classes
,
...
rest
}:
PressableIconButtonProps
)
{
return
(
<
IconButton
{
...
rest
}
classes=
{
classnames
(
classes
,
'border border-transparent'
,
'aria-pressed:border-grey-3 aria-pressed:bg-grey-1'
,
)
}
/>
);
}
src/sidebar/components/TopBar.tsx
View file @
6d8a96b7
import
{
import
{
LinkButton
,
HelpIcon
,
ShareIcon
}
from
'@hypothesis/frontend-shared'
;
IconButton
,
LinkButton
,
HelpIcon
,
ShareIcon
,
}
from
'@hypothesis/frontend-shared'
;
import
classnames
from
'classnames'
;
import
classnames
from
'classnames'
;
import
type
{
SidebarSettings
}
from
'../../types/config'
;
import
type
{
SidebarSettings
}
from
'../../types/config'
;
...
@@ -14,6 +9,7 @@ import type { FrameSyncService } from '../services/frame-sync';
...
@@ -14,6 +9,7 @@ import type { FrameSyncService } from '../services/frame-sync';
import
{
useSidebarStore
}
from
'../store'
;
import
{
useSidebarStore
}
from
'../store'
;
import
GroupList
from
'./GroupList'
;
import
GroupList
from
'./GroupList'
;
import
PendingUpdatesButton
from
'./PendingUpdatesButton'
;
import
PendingUpdatesButton
from
'./PendingUpdatesButton'
;
import
PressableIconButton
from
'./PressableIconButton'
;
import
SearchInput
from
'./SearchInput'
;
import
SearchInput
from
'./SearchInput'
;
import
SortMenu
from
'./SortMenu'
;
import
SortMenu
from
'./SortMenu'
;
import
StreamSearchInput
from
'./StreamSearchInput'
;
import
StreamSearchInput
from
'./StreamSearchInput'
;
...
@@ -108,28 +104,32 @@ function TopBar({
...
@@ -108,28 +104,32 @@ function TopBar({
/>
/>
<
SortMenu
/>
<
SortMenu
/>
{
showShareButton
&&
(
{
showShareButton
&&
(
<
IconButton
<
Pressable
IconButton
icon=
{
ShareIcon
}
icon=
{
ShareIcon
}
expanded=
{
isAnnotationsPanelOpen
}
expanded=
{
isAnnotationsPanelOpen
}
pressed=
{
isAnnotationsPanelOpen
}
onClick=
{
toggleSharePanel
}
onClick=
{
toggleSharePanel
}
size=
"xs"
size=
"xs"
title=
"Share annotations on this page"
title=
"Share annotations on this page"
data
-
testid=
"share-icon-button"
/>
/>
)
}
)
}
</>
</>
)
}
)
}
<
IconButton
<
Pressable
IconButton
icon=
{
HelpIcon
}
icon=
{
HelpIcon
}
expanded=
{
isHelpPanelOpen
}
expanded=
{
isHelpPanelOpen
}
pressed=
{
isHelpPanelOpen
}
onClick=
{
requestHelp
}
onClick=
{
requestHelp
}
size=
"xs"
size=
"xs"
title=
"Help"
title=
"Help"
data
-
testid=
"help-icon-button"
/>
/>
{
isLoggedIn
?
(
{
isLoggedIn
?
(
<
UserMenu
onLogout=
{
onLogout
}
/>
<
UserMenu
onLogout=
{
onLogout
}
/>
)
:
(
)
:
(
<
div
<
div
className=
"flex items-center text-md font-medium space-x-1"
className=
"flex items-center text-md font-medium space-x-1
pl-1
"
data
-
testid=
"login-links"
data
-
testid=
"login-links"
>
>
{
!
isLoggedIn
&&
!
hasFetchedProfile
&&
<
span
>
⋯
</
span
>
}
{
!
isLoggedIn
&&
!
hasFetchedProfile
&&
<
span
>
⋯
</
span
>
}
...
...
src/sidebar/components/test/TopBar-test.js
View file @
6d8a96b7
...
@@ -39,17 +39,22 @@ describe('TopBar', () => {
...
@@ -39,17 +39,22 @@ describe('TopBar', () => {
'../store'
:
{
useSidebarStore
:
()
=>
fakeStore
},
'../store'
:
{
useSidebarStore
:
()
=>
fakeStore
},
'../config/service-config'
:
{
serviceConfig
:
fakeServiceConfig
},
'../config/service-config'
:
{
serviceConfig
:
fakeServiceConfig
},
});
});
$imports
.
$restore
({
// `PressableIconButton` is a presentation-only component. Not mocking it
// allows to get it covered.
'./PressableIconButton'
:
true
,
});
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
$imports
.
$restore
();
$imports
.
$restore
();
});
});
// Helper to retrieve an `Button` by
icon name
, for convenience
// Helper to retrieve an `Button` by
test ID
, for convenience
function
getButton
(
wrapper
,
iconName
)
{
function
getButton
(
wrapper
,
testId
)
{
return
wrapper
return
wrapper
.
find
(
'IconButton'
)
.
find
(
'
Pressable
IconButton'
)
.
filterWhere
(
n
=>
n
.
find
(
iconName
).
exists
());
.
filterWhere
(
n
=>
n
.
find
(
`[data-testid="
${
testId
}
"]`
).
exists
());
}
}
function
createTopBar
(
props
=
{})
{
function
createTopBar
(
props
=
{})
{
...
@@ -69,7 +74,7 @@ describe('TopBar', () => {
...
@@ -69,7 +74,7 @@ describe('TopBar', () => {
context
(
'no help service handler configured in services (default)'
,
()
=>
{
context
(
'no help service handler configured in services (default)'
,
()
=>
{
it
(
'toggles Help Panel on click'
,
()
=>
{
it
(
'toggles Help Panel on click'
,
()
=>
{
const
wrapper
=
createTopBar
();
const
wrapper
=
createTopBar
();
const
helpButton
=
getButton
(
wrapper
,
'
HelpIc
on'
);
const
helpButton
=
getButton
(
wrapper
,
'
help-icon-butt
on'
);
helpButton
.
props
().
onClick
();
helpButton
.
props
().
onClick
();
...
@@ -79,7 +84,7 @@ describe('TopBar', () => {
...
@@ -79,7 +84,7 @@ describe('TopBar', () => {
it
(
'displays a help icon active state when help panel active'
,
()
=>
{
it
(
'displays a help icon active state when help panel active'
,
()
=>
{
fakeStore
.
isSidebarPanelOpen
.
withArgs
(
'help'
).
returns
(
true
);
fakeStore
.
isSidebarPanelOpen
.
withArgs
(
'help'
).
returns
(
true
);
const
wrapper
=
createTopBar
();
const
wrapper
=
createTopBar
();
const
helpButton
=
getButton
(
wrapper
,
'
HelpIc
on'
);
const
helpButton
=
getButton
(
wrapper
,
'
help-icon-butt
on'
);
wrapper
.
update
();
wrapper
.
update
();
...
@@ -91,7 +96,7 @@ describe('TopBar', () => {
...
@@ -91,7 +96,7 @@ describe('TopBar', () => {
fakeServiceConfig
.
returns
({
onHelpRequestProvided
:
true
});
fakeServiceConfig
.
returns
({
onHelpRequestProvided
:
true
});
const
wrapper
=
createTopBar
();
const
wrapper
=
createTopBar
();
const
helpButton
=
getButton
(
wrapper
,
'
HelpIc
on'
);
const
helpButton
=
getButton
(
wrapper
,
'
help-icon-butt
on'
);
helpButton
.
props
().
onClick
();
helpButton
.
props
().
onClick
();
...
@@ -164,7 +169,7 @@ describe('TopBar', () => {
...
@@ -164,7 +169,7 @@ describe('TopBar', () => {
it
(
'toggles the share annotations panel when "Share" is clicked'
,
()
=>
{
it
(
'toggles the share annotations panel when "Share" is clicked'
,
()
=>
{
const
wrapper
=
createTopBar
();
const
wrapper
=
createTopBar
();
const
shareButton
=
getButton
(
wrapper
,
'
ShareIc
on'
);
const
shareButton
=
getButton
(
wrapper
,
'
share-icon-butt
on'
);
shareButton
.
props
().
onClick
();
shareButton
.
props
().
onClick
();
...
@@ -176,7 +181,7 @@ describe('TopBar', () => {
...
@@ -176,7 +181,7 @@ describe('TopBar', () => {
.
withArgs
(
'shareGroupAnnotations'
)
.
withArgs
(
'shareGroupAnnotations'
)
.
returns
(
true
);
.
returns
(
true
);
const
wrapper
=
createTopBar
();
const
wrapper
=
createTopBar
();
const
shareButton
=
getButton
(
wrapper
,
'
ShareIc
on'
);
const
shareButton
=
getButton
(
wrapper
,
'
share-icon-butt
on'
);
assert
.
isTrue
(
shareButton
.
prop
(
'expanded'
));
assert
.
isTrue
(
shareButton
.
prop
(
'expanded'
));
});
});
...
...
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