Streamfield: support label and hint text
This commit is contained in:
parent
a6f4f07d9f
commit
96401006ff
|
@ -3,9 +3,9 @@ import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
interface IFormGroup {
|
interface IFormGroup {
|
||||||
/** Input label message. */
|
/** Input label message. */
|
||||||
hintText?: string | React.ReactNode,
|
labelText: React.ReactNode,
|
||||||
/** Input hint message. */
|
/** Input hint message. */
|
||||||
labelText: string | React.ReactNode,
|
hintText?: React.ReactNode,
|
||||||
/** Input errors. */
|
/** Input errors. */
|
||||||
errors?: string[]
|
errors?: string[]
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,19 +4,32 @@ import Button from '../button/button';
|
||||||
import HStack from '../hstack/hstack';
|
import HStack from '../hstack/hstack';
|
||||||
import IconButton from '../icon-button/icon-button';
|
import IconButton from '../icon-button/icon-button';
|
||||||
import Stack from '../stack/stack';
|
import Stack from '../stack/stack';
|
||||||
|
import Text from '../text/text';
|
||||||
|
|
||||||
interface IStreamfield {
|
interface IStreamfield {
|
||||||
|
/** Array of values for the streamfield. */
|
||||||
values: any[],
|
values: any[],
|
||||||
|
/** Input label message. */
|
||||||
|
labelText?: React.ReactNode,
|
||||||
|
/** Input hint message. */
|
||||||
|
hintText?: React.ReactNode,
|
||||||
|
/** Callback to add an item. */
|
||||||
onAddItem?: () => void,
|
onAddItem?: () => void,
|
||||||
|
/** Callback to remove an item by index. */
|
||||||
onRemoveItem?: (i: number) => void,
|
onRemoveItem?: (i: number) => void,
|
||||||
|
/** Callback when values are changed. */
|
||||||
onChange: (values: any[]) => void,
|
onChange: (values: any[]) => void,
|
||||||
|
/** Input to render for each value. */
|
||||||
component: React.ComponentType<{ onChange: (value: any) => void, value: any }>,
|
component: React.ComponentType<{ onChange: (value: any) => void, value: any }>,
|
||||||
|
/** Maximum number of allowed inputs. */
|
||||||
maxItems?: number,
|
maxItems?: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** List of inputs that can be added or removed. */
|
/** List of inputs that can be added or removed. */
|
||||||
const Streamfield: React.FC<IStreamfield> = ({
|
const Streamfield: React.FC<IStreamfield> = ({
|
||||||
values,
|
values,
|
||||||
|
labelText,
|
||||||
|
hintText,
|
||||||
onAddItem,
|
onAddItem,
|
||||||
onRemoveItem,
|
onRemoveItem,
|
||||||
onChange,
|
onChange,
|
||||||
|
@ -34,6 +47,10 @@ const Streamfield: React.FC<IStreamfield> = ({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack space={4}>
|
<Stack space={4}>
|
||||||
|
<Stack>
|
||||||
|
{labelText && <Text size='sm' weight='medium'>{labelText}</Text>}
|
||||||
|
{hintText && <Text size='xs' theme='muted'>{hintText}</Text>}
|
||||||
|
</Stack>
|
||||||
|
|
||||||
<Stack>
|
<Stack>
|
||||||
{values.map((value, i) => (
|
{values.map((value, i) => (
|
||||||
|
|
|
@ -423,6 +423,8 @@ const EditProfile: React.FC = () => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Streamfield
|
<Streamfield
|
||||||
|
labelText={<FormattedMessage id='edit_profile.fields.meta_fields_label' defaultMessage='Profile fields' />}
|
||||||
|
hintText={<FormattedMessage id='edit_profile.hints.meta_fields' defaultMessage='You can have up to {count, plural, one {# custom field} other {# custom fields}} displayed on your profile.' values={{ count: maxFields }} />}
|
||||||
values={data.fields_attributes || []}
|
values={data.fields_attributes || []}
|
||||||
onChange={handleFieldsChange}
|
onChange={handleFieldsChange}
|
||||||
onAddItem={handleAddField}
|
onAddItem={handleAddField}
|
||||||
|
|
Loading…
Reference in New Issue