mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: List select component.
This commit is contained in:
35
client/src/components/ListSelect.js
Normal file
35
client/src/components/ListSelect.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Button,
|
||||
} from '@blueprintjs/core';
|
||||
import { Select } from '@blueprintjs/select';
|
||||
|
||||
export default function ListSelect ({
|
||||
buttonProps,
|
||||
defaultText,
|
||||
labelProp,
|
||||
|
||||
selectedItem,
|
||||
selectedItemProp = 'id',
|
||||
...selectProps
|
||||
}) {
|
||||
const [currentItem, setCurrentItem] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedItem && selectedItemProp) {
|
||||
const item = selectProps.items.find(i => i[selectedItemProp] === selectedItem);
|
||||
setCurrentItem(item);
|
||||
}
|
||||
}, [selectedItem, selectedItemProp, selectProps.items]);
|
||||
|
||||
return (
|
||||
<Select
|
||||
{...selectProps}
|
||||
>
|
||||
<Button
|
||||
text={currentItem ? currentItem[labelProp] : defaultText}
|
||||
{...buttonProps}
|
||||
/>
|
||||
</Select>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user