Streamfield: export generic StreamfieldComponent<T> type

api-accept
Alex Gleason 2 years ago
parent eaeeed29c0
commit 0f341eee6e
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

@ -12,6 +12,12 @@ const messages = defineMessages({
remove: { id: 'streamfield.remove', defaultMessage: 'Remove' },
});
/** Type of the inner Streamfield input component. */
export type StreamfieldComponent<T> = React.ComponentType<{
value: T,
onChange: (value: T) => void,
}>;
interface IStreamfield {
/** Array of values for the streamfield. */
values: any[],
@ -26,7 +32,7 @@ interface IStreamfield {
/** Callback when values are changed. */
onChange: (values: any[]) => void,
/** Input to render for each value. */
component: React.ComponentType<{ onChange: (value: any) => void, value: any }>,
component: StreamfieldComponent<any>,
/** Maximum number of allowed inputs. */
maxItems?: number,
}

@ -12,7 +12,7 @@ import { normalizeAccount } from 'soapbox/normalizers';
import resizeImage from 'soapbox/utils/resize_image';
import { Button, Column, Form, FormActions, FormGroup, Input, Textarea, HStack } from '../../components/ui';
import Streamfield from '../../components/ui/streamfield/streamfield';
import Streamfield, { StreamfieldComponent } from '../../components/ui/streamfield/streamfield';
import ProfilePreview from './components/profile-preview';
@ -147,12 +147,7 @@ const accountToCredentials = (account: Account): AccountCredentials => {
};
};
interface IProfileField {
value: AccountCredentialsField,
onChange: (field: AccountCredentialsField) => void,
}
const ProfileField: React.FC<IProfileField> = ({ value, onChange }) => {
const ProfileField: StreamfieldComponent<AccountCredentialsField> = ({ value, onChange }) => {
const intl = useIntl();
const handleChange = (key: string): React.ChangeEventHandler<HTMLInputElement> => {

Loading…
Cancel
Save