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
96425a93
Commit
96425a93
authored
Mar 16, 2021
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Mar 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update `SidebarPanel` to use `Panel` component
parent
93234f34
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
45 deletions
+22
-45
SidebarPanel.js
src/sidebar/components/SidebarPanel.js
+12
-25
SidebarPanel-test.js
src/sidebar/components/test/SidebarPanel-test.js
+10
-12
SidebarPanel.scss
src/styles/sidebar/components/SidebarPanel.scss
+0
-7
sidebar.scss
src/styles/sidebar/sidebar.scss
+0
-1
No files found.
src/sidebar/components/SidebarPanel.js
View file @
96425a93
import
{
SvgIcon
}
from
'@hypothesis/frontend-shared'
;
import
{
useEffect
,
useRef
}
from
'preact/hooks'
;
import
{
useCallback
,
useEffect
,
useRef
}
from
'preact/hooks'
;
import
scrollIntoView
from
'scroll-into-view'
;
import
{
useStoreProxy
}
from
'../store/use-store'
;
import
Button
from
'./Button
'
;
import
Panel
from
'./Panel
'
;
import
Slider
from
'./Slider'
;
/**
...
...
@@ -13,22 +12,19 @@ import Slider from './Slider';
/**
* @typedef SidebarPanelProps
* @prop {
Object} [children]
* @prop {
import("preact").ComponentChildren} children
* @prop {string} [icon] - An optional icon name for display next to the panel's title
* @prop {PanelName} panelName -
* A string identifying this panel. Only one `panelName` may be active at any time.
* Multiple panels with the same `panelName` would be "in sync", opening and closing together.
* @prop {string} title - The panel's title
: rendered in its containing visual "frame"
* @prop {string} title - The panel's title
* @prop {(active: boolean) => any} [onActiveChanged] -
* Optional callback to invoke when this panel's active status changes
*/
/**
* Base component for a sidebar panel.
*
* This component provides a basic visual container for sidebar panels, as well
* as providing a close button. Only one sidebar panel (as defined by the panel's
* `panelName`) is active at one time.
* Base component for a sidebar panel. Only one sidebar panel
* (as defined by the panel's `panelName`) is active (visible) at one time.
*
* @param {SidebarPanelProps} props
*/
...
...
@@ -58,25 +54,16 @@ export default function SidebarPanel({
}
},
[
panelIsActive
,
onActiveChanged
]);
const
closePanel
=
()
=>
{
const
closePanel
=
useCallback
(
()
=>
{
store
.
toggleSidebarPanel
(
panelName
,
false
);
};
}
,
[
store
,
panelName
])
;
return
(
<
Slider
visible
=
{
panelIsActive
}
>
<
div
className
=
"SidebarPanel"
ref
=
{
panelElement
}
>
<
div
className
=
"SidebarPanel__header"
>
{
icon
&&
(
<
div
className
=
"SidebarPanel__header-icon"
>
<
SvgIcon
name
=
{
icon
}
title
=
{
title
}
/
>
<
/div
>
)}
<
h2
className
=
"SidebarPanel__title u-stretch"
>
{
title
}
<
/h2
>
<
div
>
<
Button
icon
=
"cancel"
buttonText
=
"Close"
onClick
=
{
closePanel
}
/
>
<
/div
>
<
/div
>
<
div
className
=
"SidebarPanel__content"
>
{
children
}
<
/div
>
<
div
ref
=
{
panelElement
}
>
<
Panel
title
=
{
title
}
icon
=
{
icon
}
onClose
=
{
closePanel
}
>
{
children
}
<
/Panel
>
<
/div
>
<
/Slider
>
);
...
...
src/sidebar/components/test/SidebarPanel-test.js
View file @
96425a93
...
...
@@ -37,24 +37,22 @@ describe('SidebarPanel', () => {
$imports
.
$restore
();
});
it
(
'renders the provided title'
,
()
=>
{
const
wrapper
=
createSidebarPanel
({
title
:
'My Panel'
});
const
titleEl
=
wrapper
.
find
(
'.SidebarPanel__title'
);
assert
.
equal
(
titleEl
.
text
(),
'My Panel'
);
});
it
(
'renders an icon if provided'
,
()
=>
{
const
wrapper
=
createSidebarPanel
({
icon
:
'restricted'
});
it
(
'renders a panel with provided title and icon'
,
()
=>
{
const
wrapper
=
createSidebarPanel
({
title
:
'My Panel'
,
icon
:
'restricted'
,
});
const
icon
=
wrapper
.
find
(
'SvgIcon'
).
filter
({
name
:
'restricted'
}
);
const
panel
=
wrapper
.
find
(
'Panel'
);
assert
.
isTrue
(
icon
.
exists
());
assert
.
equal
(
panel
.
props
().
icon
,
'restricted'
);
assert
.
equal
(
panel
.
props
().
title
,
'My Panel'
);
});
it
(
'
closes the panel when close button is clicked
'
,
()
=>
{
it
(
'
provides an `onClose` handler that closes the panel
'
,
()
=>
{
const
wrapper
=
createSidebarPanel
({
panelName
:
'flibberty'
});
wrapper
.
find
(
'
Button'
).
props
().
onClick
();
wrapper
.
find
(
'
Panel'
).
props
().
onClose
();
assert
.
calledWith
(
fakeStore
.
toggleSidebarPanel
,
'flibberty'
,
false
);
});
...
...
src/styles/sidebar/components/SidebarPanel.scss
deleted
100644 → 0
View file @
93234f34
@use
"../../mixins/molecules"
;
.SidebarPanel
{
@include
molecules
.
panel
;
position
:
relative
;
margin-bottom
:
0
.75em
;
}
src/styles/sidebar/sidebar.scss
View file @
96425a93
...
...
@@ -48,7 +48,6 @@
@use
'./components/SearchInput'
;
@use
'./components/ShareLinks'
;
@use
'./components/SidebarContentError'
;
@use
'./components/SidebarPanel'
;
@use
'./components/Spinner'
;
@use
'./components/TagEditor'
;
@use
'./components/TagList'
;
...
...
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