-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
9 changed files
with
132 additions
and
4 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
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,93 @@ | ||
import { | ||
ComboboxStringData, | ||
TagsInput as MantineTagsInput, | ||
} from "@mantine/core"; | ||
import { useDidUpdate } from "@mantine/hooks"; | ||
import { BoxProps } from "props/box"; | ||
import { __CloseButtonProps } from "props/button"; | ||
import { ComboboxLikeProps } from "props/combobox"; | ||
import { DashBaseProps, PersistenceProps } from "props/dash"; | ||
import { __BaseInputProps } from "props/input"; | ||
import { ScrollAreaProps } from "props/scrollarea"; | ||
import { StylesApiProps } from "props/styles"; | ||
import React, { useState } from "react"; | ||
|
||
interface Props | ||
extends BoxProps, | ||
__BaseInputProps, | ||
Omit<ComboboxLikeProps, "data">, | ||
StylesApiProps, | ||
DashBaseProps, | ||
PersistenceProps { | ||
/** Data displayed in the dropdown */ | ||
data?: ComboboxStringData; | ||
/** Controlled component value */ | ||
value?: string[]; | ||
/** Controlled search value */ | ||
searchValue?: string; | ||
/** Maximum number of tags, `Infinity` by default */ | ||
maxTags?: number; | ||
/** Determines whether duplicate tags are allowed, `false` by default */ | ||
allowDuplicates?: boolean; | ||
/** Characters that should trigger tags split, `[',']` by default */ | ||
splitChars?: string[]; | ||
/** Determines whether the clear button should be displayed in the right section when the component has value, `false` by default */ | ||
clearable?: boolean; | ||
/** Props passed down to the clear button */ | ||
clearButtonProps?: __CloseButtonProps; | ||
/** Props passed down to the hidden input */ | ||
hiddenInputProps?: object; | ||
/** Divider used to separate values in the hidden input `value` attribute, `','` by default */ | ||
hiddenInputValuesDivider?: string; | ||
/** Props passed down to the underlying `ScrollArea` component in the dropdown */ | ||
scrollAreaProps?: ScrollAreaProps; | ||
} | ||
|
||
/** TagsInput */ | ||
const TagsInput = (props: Props) => { | ||
const { setProps, data, searchValue, value, ...others } = props; | ||
|
||
const [selected, setSelected] = useState(value); | ||
const [options, setOptions] = useState(data); | ||
const [searchVal, setSearchVal] = useState(searchValue); | ||
|
||
useDidUpdate(() => { | ||
setOptions(data); | ||
}, [data]); | ||
|
||
useDidUpdate(() => { | ||
setProps({ data: options }); | ||
}, [options]); | ||
|
||
useDidUpdate(() => { | ||
setProps({ value: selected }); | ||
}, [selected]); | ||
|
||
useDidUpdate(() => { | ||
setSelected(value); | ||
}, [value]); | ||
|
||
useDidUpdate(() => { | ||
setProps({ searchValue: searchVal }); | ||
}, [searchVal]); | ||
|
||
return ( | ||
<MantineTagsInput | ||
wrapperProps={{ autoComplete: "off" }} | ||
data={options} | ||
onChange={setSelected} | ||
value={selected} | ||
searchValue={searchVal} | ||
onSearchChange={setSearchVal} | ||
{...others} | ||
/> | ||
); | ||
}; | ||
|
||
TagsInput.defaultProps = { | ||
persisted_props: ["value"], | ||
persistence_type: "local", | ||
data: [], | ||
}; | ||
|
||
export default TagsInput; |
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
File renamed without changes.
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,25 @@ | ||
import { BoxProps } from "props/box"; | ||
import { StylesApiProps } from "props/styles"; | ||
import React from "react"; | ||
|
||
export interface ScrollAreaProps extends BoxProps, StylesApiProps { | ||
/** Scrollbar size, any valid CSS value for width/height, numbers are converted to rem, default value is 0.75rem */ | ||
scrollbarSize?: number | string; | ||
/** | ||
* Defines scrollbars behavior, `hover` by default | ||
* - `hover` – scrollbars are visible when mouse is over the scroll area | ||
* - `scroll` – scrollbars are visible when the scroll area is scrolled | ||
* - `always` – scrollbars are always visible | ||
* - `never` – scrollbars are always hidden | ||
* - `auto` – similar to `overflow: auto` – scrollbars are always visible when the content is overflowing | ||
* */ | ||
type?: "auto" | "always" | "scroll" | "hover" | "never"; | ||
/** Scroll hide delay in ms, applicable only when type is set to `hover` or `scroll`, `1000` by default */ | ||
scrollHideDelay?: number; | ||
/** Axis at which scrollbars must be rendered, `'xy'` by default */ | ||
scrollbars?: "x" | "y" | "xy" | false; | ||
/** Determines whether scrollbars should be offset with padding on given axis, `false` by default */ | ||
offsetScrollbars?: boolean | "x" | "y"; | ||
/** Content */ | ||
children?: React.ReactNode; | ||
} |