-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
1 parent
216f6bf
commit 6039239
Showing
2 changed files
with
85 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { FC } from 'react' | ||
import { | ||
ScrollArea, | ||
Input, | ||
Stack, | ||
TextInput, | ||
TextInputProps, | ||
Button, | ||
ActionIcon, | ||
} from '@mantine/core' | ||
import { mdiClose, mdiPlus } from '@mdi/js' | ||
import { Icon } from '@mdi/react' | ||
|
||
interface HintListProps extends TextInputProps { | ||
hints: string[] | ||
onChangeHint: (value: string[]) => void | ||
disabled?: boolean | ||
height?: number | ||
} | ||
|
||
export const HintList: FC<HintListProps> = (props) => { | ||
const { hints, onChangeHint, disabled, height, ...rest } = props | ||
|
||
const hintdict = hints.map((hint, key) => ({ hint, key })) | ||
|
||
const handleChange = (key: number, value: string) => { | ||
const newHints = [...hintdict] | ||
newHints[key].hint = value | ||
onChangeHint(newHints.map((h) => h.hint)) | ||
} | ||
|
||
const handleAdd = () => { | ||
const newHints = [...hintdict, { hint: '', key: hintdict.length }] | ||
onChangeHint(newHints.map((h) => h.hint)) | ||
} | ||
|
||
const handleDelete = (key: number) => { | ||
const newHints = hintdict.filter((h) => h.key !== key) | ||
onChangeHint(newHints.map((h) => h.hint)) | ||
} | ||
|
||
return ( | ||
<Input.Wrapper {...rest}> | ||
<ScrollArea offsetScrollbars scrollbarSize={4} style={{ height }}> | ||
<Stack spacing="xs"> | ||
{hintdict.map((kv) => ( | ||
<TextInput | ||
style={{ marginRight: 4 }} | ||
value={kv.hint} | ||
disabled={disabled} | ||
key={kv.key} | ||
onChange={(e) => handleChange(kv.key, e.target.value)} | ||
rightSection={ | ||
<ActionIcon onClick={() => handleDelete(kv.key)}> | ||
<Icon path={mdiClose} size={1} /> | ||
</ActionIcon> | ||
} | ||
/> | ||
))} | ||
<Button | ||
style={{ marginRight: 4 }} | ||
leftIcon={<Icon path={mdiPlus} size={1} />} | ||
onClick={handleAdd} | ||
> | ||
添加提示 | ||
</Button> | ||
</Stack> | ||
</ScrollArea> | ||
</Input.Wrapper> | ||
) | ||
} | ||
|
||
export default HintList |
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