-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(list-picker): add recent component (#1522)
- Loading branch information
1 parent
a83a563
commit 853048d
Showing
7 changed files
with
180 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { slice } from 'lodash'; | ||
import React, { useContext } from 'react'; | ||
import { List, OptionProps } from '../list'; | ||
import { ListContext } from '../list/context'; | ||
|
||
export const ITEM_KEY = '__GIO_SELECTION_KEY'; | ||
|
||
interface RecentProps { | ||
title?: string; | ||
max?: number; | ||
} | ||
|
||
const Recent: React.FC<RecentProps> & { isRecent: boolean } = (props) => { | ||
const { max = 5, title } = props; | ||
const context = useContext(ListContext); | ||
const localStorageValue = window?.localStorage?.getItem(ITEM_KEY) || '[]'; | ||
const matchValue = JSON.parse(localStorageValue); // localStorage.getItem('__GIO_SELECTION_KEY') | ||
const mayBeArray = Array.from((context?.options ?? new Map())?.values()); | ||
const options = slice( | ||
mayBeArray?.filter((value?: OptionProps) => matchValue?.includes(value?.value)), | ||
0, | ||
max | ||
); | ||
const handleOnChange = (value?: string | string[], opts?: OptionProps | OptionProps[]) => | ||
context?.onChange?.(value, opts); | ||
return <List title={title} id={ITEM_KEY} options={options} value="" onChange={handleOnChange} />; | ||
}; | ||
Recent.isRecent = true; | ||
export default Recent; |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { ListPickerProps } from './interfance'; | ||
|
||
import ListPicker from './listPicker'; | ||
import Recent from './Recent'; | ||
|
||
export type { ListPickerProps }; | ||
|
||
export { ListPicker, Recent }; | ||
export default ListPicker; |
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
Oops, something went wrong.
853048d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: