Skip to content

Commit

Permalink
Merge pull request #65 from BeeInventor/feature/update-dropdown
Browse files Browse the repository at this point in the history
Feature/update dropdown
  • Loading branch information
steven11329 authored Jul 18, 2023
2 parents 86088b2 + 7b75531 commit 93a1ee9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beeinventor/dasiot-react-component-lib",
"version": "1.8.1",
"version": "1.8.2",
"module": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
Expand Down
34 changes: 25 additions & 9 deletions src/components/Dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,31 @@ export const Selected: Story = {
};

export const Selection: Story = {
render: () => (
<Dropdown
placeholder="Select"
list={list}
selectedId="A004"
selectionId="A003"
onSelect={() => {}}
/>
),
render: () => {
const [selectionIds, setSelectionIds] = useState<string[]>([]);
const [selectedId, setSelectedId] = useState<string>();

const onChange = (value: string | number) => {
const updateValue = [...selectionIds];
if (selectionIds.includes(value as string)) {
updateValue.splice(updateValue.indexOf(value as string), 1);
} else {
updateValue.push(value as string);
}
setSelectionIds(updateValue);
setSelectedId(value as string);
};

return (
<Dropdown
placeholder="Select"
selectedId={selectedId}
list={list}
selectionIds={selectionIds}
onSelect={onChange}
/>
);
},
};

export const WithDialog: Story = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const Dropdown: React.VFC<DropDownProps> = (props) => {
disabled,
onSelect,
popperProps,
selectionId,
selectionIds,
mode = 'light',
...otherProps
} = props;
Expand Down Expand Up @@ -136,7 +136,7 @@ const Dropdown: React.VFC<DropDownProps> = (props) => {
};

const items = list
.filter((item) => item.id !== selectionId)
.filter((item) => !selectionIds?.includes(item.id))
.map((item, i) => (
<Item
key={`dropdown-item-${item.id}`}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dropdown/Dropdown.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ export interface DropDownProps extends Omit<BoxProps, 'onSelect'> {
/**
* filter the list out of this id
*/
selectionId?: string;
selectionIds?: string[];
}

0 comments on commit 93a1ee9

Please sign in to comment.