const candies = [
{
label: 'Wonka Bar',
value: 'wonka-bar',
},
{
label: 'Bubblegum',
value: 'bubblegum',
},
{
label: 'Raisins',
value: 'raisins',
},
{
label: 'Oranges',
value: 'oranges',
},
]
class EditActionsExample extends React.Component {
constructor(props) {
super(props)
this.state = {
value: {
name: 'Charlie',
favoriteCandy: ['wonka-bar'],
},
isBusy: false,
}
}
render() {
const { value, isBusy } = this.state
const resetBusy = () => {
setTimeout(() => this.setState({ isBusy: false }), 2500)
}
return (
<EditActions
display={
<Text>
{value.name}'s favorite candy is{' '}
<StackView inline as="span" axis="horizontal" spacing=", ">
{candies
.filter(
(candy) => value.favoriteCandy.indexOf(candy.value) > -1
)
.map((candy) => candy.label)}
</StackView>
</Text>
}
edit={[
<Input
autoFocus
value={value.name}
onChange={(e) =>
this.setState(
{
value: {
...value,
name: e.target.value,
},
isBusy: true,
},
resetBusy
)
}
/>,
<Select
matchWidths={false}
multiple
placement="bottom-start"
value={value.favoriteCandy}
onChange={(e) =>
this.setState(
{
value: {
...value,
favoriteCandy: e.value,
},
isBusy: true,
},
resetBusy
)
}
>
{candies.map((candy) => (
<Select.Option key={candy.value} value={candy.value}>
{candy.label}
</Select.Option>
))}
</Select>,
]}
loading={isBusy}
/>
)
}
}
render(EditActionsExample)