sforkowany z mirror/soapbox
FeaturesPanel: add onChange event
rodzic
b84e4403ab
commit
ef86b27435
|
@ -10,11 +10,12 @@ const messages = defineMessages({
|
||||||
});
|
});
|
||||||
|
|
||||||
interface IFeaturesPanel {
|
interface IFeaturesPanel {
|
||||||
features: Record<string, any>,
|
features: Record<string, boolean>,
|
||||||
|
onChange?: (features: Record<string, boolean>) => void,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A UI for managing conditional feature flags. */
|
/** A UI for managing conditional feature flags. */
|
||||||
const FeaturesPanel: React.FC<IFeaturesPanel> = ({ features: userFeatures }) => {
|
const FeaturesPanel: React.FC<IFeaturesPanel> = ({ features: userFeatures, onChange }) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const autoFeatures = useFeatures();
|
const autoFeatures = useFeatures();
|
||||||
|
|
||||||
|
@ -22,12 +23,20 @@ const FeaturesPanel: React.FC<IFeaturesPanel> = ({ features: userFeatures }) =>
|
||||||
return Object.assign({ ...autoFeatures }, { ...userFeatures });
|
return Object.assign({ ...autoFeatures }, { ...userFeatures });
|
||||||
}, [userFeatures, autoFeatures]);
|
}, [userFeatures, autoFeatures]);
|
||||||
|
|
||||||
|
const handleChange = (key: string): React.ChangeEventHandler<HTMLInputElement> => {
|
||||||
|
return (e) => {
|
||||||
|
if (onChange) {
|
||||||
|
onChange({ ...userFeatures, [key]: e.target.checked });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column label={intl.formatMessage(messages.title)}>
|
<Column label={intl.formatMessage(messages.title)}>
|
||||||
<List>
|
<List>
|
||||||
{Object.keys(autoFeatures).map(key => (
|
{Object.keys(autoFeatures).map(key => (
|
||||||
<ListItem label={key}>
|
<ListItem label={key}>
|
||||||
<Toggle checked={features[key]} />
|
<Toggle checked={features[key]} onChange={handleChange(key)} />
|
||||||
</ListItem>
|
</ListItem>
|
||||||
))}
|
))}
|
||||||
</List>
|
</List>
|
||||||
|
|
Ładowanie…
Reference in New Issue