-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
112 additions
and
3 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
59 changes: 59 additions & 0 deletions
59
src/app/(authed)/admin/forms/create/_components/FormLabelField.tsx
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,59 @@ | ||
import Autocomplete from '@mui/material/Autocomplete'; | ||
import Box from '@mui/material/Box'; | ||
import Chip from '@mui/material/Chip'; | ||
import TextField from '@mui/material/TextField'; | ||
import type { GetFormLabelsResponse } from '@/app/api/_schemas/ResponseSchemas'; | ||
import type { Dispatch, SetStateAction } from 'react'; | ||
|
||
const FormLabelField = (props: { | ||
labelOptions: GetFormLabelsResponse; | ||
setLabels: Dispatch<SetStateAction<GetFormLabelsResponse>>; | ||
}) => { | ||
return ( | ||
<Autocomplete | ||
multiple | ||
id="label" | ||
options={props.labelOptions.map((label) => label.name)} | ||
getOptionLabel={(option) => option} | ||
renderTags={(value: readonly string[], getTagProps) => | ||
value.map((option: string, index: number) => ( | ||
<Chip | ||
label={option} | ||
sx={{ background: '#FFFFFF29' }} | ||
{...getTagProps({ index })} | ||
key={index} | ||
/> | ||
)) | ||
} | ||
renderOption={(props, option) => { | ||
return ( | ||
<Box | ||
{...props} | ||
key={option} | ||
component="span" | ||
style={{ color: 'black' }} | ||
> | ||
{option} | ||
</Box> | ||
); | ||
}} | ||
renderInput={(params) => ( | ||
// @ts-expect-error (解決方法がよくわからないのでとりあえずignoreする) | ||
// FIXME: あとで調べる | ||
<TextField | ||
{...params} | ||
variant="standard" | ||
label="フォームラベル設定" | ||
sx={{ borderBottom: '1px solid #FFFFFF6B' }} | ||
/> | ||
)} | ||
onChange={(_event, value) => { | ||
props.setLabels( | ||
props.labelOptions.filter((label) => value.includes(label.name)) | ||
); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default FormLabelField; |
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