-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useLocalStorage, writeStorage } from '@rehooks/local-storage'; | ||
|
||
import { Paneset } from '@folio/stripes-components'; | ||
|
||
const propTypes = { | ||
appId: PropTypes.string.isRequired, | ||
children: PropTypes.node, | ||
id: PropTypes.string.isRequired, | ||
}; | ||
|
||
const PersistedPaneset = ({ | ||
appId, | ||
children, | ||
id: panesetId, | ||
}) => { | ||
const persistKey = `${appId}/${panesetId}/layout`; | ||
const [storedPanesetLayout] = useLocalStorage(persistKey); | ||
|
||
return ( | ||
<Paneset | ||
id={panesetId} | ||
initialLayouts={storedPanesetLayout} | ||
onResize={({ layoutCache }) => { | ||
// We don't want to persist any layout that contains a NaN so filter those out first. | ||
const persistedLayoutCache = layoutCache.filter(layout => { | ||
const widths = Object.values(layout); | ||
const hasNaN = widths.some(width => width.includes('NaN')); | ||
return !hasNaN; | ||
}); | ||
|
||
writeStorage(persistKey, persistedLayoutCache); | ||
}} | ||
> | ||
{children} | ||
</Paneset> | ||
); | ||
}; | ||
|
||
PersistedPaneset.propTypes = propTypes; | ||
export default PersistedPaneset; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './PersistedPaneset'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# PersistedPaneset | ||
|
||
Paneset with LocalStorage-backed persistence | ||
|
||
## Description | ||
|
||
`stripes-components` provides a `Paneset` component that supports drag-and-drop resizing of its child `Pane`s. This component saves those layout sizes to the client browser's `localStorage`. | ||
|
||
### Properties | ||
|
||
Name | Type | Required | Description | ||
--- | --- | --- | ---- | ||
appId | string | Yes | The app ID that will be used for namespacing `localStorage`. Eg, `@folio/users` | ||
id | string | Yes | The ID of the Paneset itself. This will be used for namespacing `localStorage`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters