mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 06:50:51 +00:00
Merge pull request #11314 from strapi/ctb/create-cat
[V4] CTB: Add combobox in CTB to create component category
This commit is contained in:
commit
cae639a20f
@ -104,7 +104,7 @@ const ComponentIconPicker = ({ error, isCreating, intlLabel, name, onChange, val
|
|||||||
</Searchbar>
|
</Searchbar>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<IconButton onClick={toggleSearch} aria-label="Edit" icon={<SearchIcon />} />
|
<IconButton onClick={toggleSearch} aria-label="Edit" icon={<SearchIcon />} noBorder />
|
||||||
)}
|
)}
|
||||||
</Row>
|
</Row>
|
||||||
<Stack size={1}>
|
<Stack size={1}>
|
||||||
|
@ -4,39 +4,45 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Select, Option } from '@strapi/parts/Select';
|
import { ComboboxOption, CreatableCombobox } from '@strapi/parts/Combobox';
|
||||||
import useDataManager from '../../hooks/useDataManager';
|
import useDataManager from '../../hooks/useDataManager';
|
||||||
|
|
||||||
// FIXME replace with Creatable Combobox
|
|
||||||
const SelectCategory = ({ error, intlLabel, name, onChange, value }) => {
|
const SelectCategory = ({ error, intlLabel, name, onChange, value }) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const { allComponentsCategories } = useDataManager();
|
const { allComponentsCategories } = useDataManager();
|
||||||
|
const [categories, setCategories] = useState(allComponentsCategories);
|
||||||
|
|
||||||
const errorMessage = error ? formatMessage({ id: error, defaultMessage: error }) : '';
|
const errorMessage = error ? formatMessage({ id: error, defaultMessage: error }) : '';
|
||||||
const label = formatMessage(intlLabel);
|
const label = formatMessage(intlLabel);
|
||||||
|
|
||||||
return (
|
const handleChange = value => {
|
||||||
<Select
|
|
||||||
error={errorMessage}
|
|
||||||
label={label}
|
|
||||||
id={name}
|
|
||||||
name={name}
|
|
||||||
onChange={value => {
|
|
||||||
onChange({ target: { name, value, type: 'select-category' } });
|
onChange({ target: { name, value, type: 'select-category' } });
|
||||||
}}
|
};
|
||||||
value={value || ''}
|
|
||||||
>
|
const handleCreateOption = value => {
|
||||||
{allComponentsCategories.map(category => {
|
setCategories(prev => [...prev, value]);
|
||||||
|
handleChange(value);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Option key={category} value={category}>
|
<CreatableCombobox
|
||||||
|
error={errorMessage}
|
||||||
|
id={name}
|
||||||
|
label={label}
|
||||||
|
name={name}
|
||||||
|
onChange={handleChange}
|
||||||
|
onCreateOption={handleCreateOption}
|
||||||
|
value={value}
|
||||||
|
>
|
||||||
|
{categories.map(category => (
|
||||||
|
<ComboboxOption key={category} value={category}>
|
||||||
{category}
|
{category}
|
||||||
</Option>
|
</ComboboxOption>
|
||||||
);
|
))}
|
||||||
})}
|
</CreatableCombobox>
|
||||||
</Select>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user