EditActions
View Source
Helper component that manages switching between initial and editing states of inline forms. It uses an optimisitic save that will render a checkmark after the loading prop has been set to false
.
Edit this value
Copy
Edit
class EditActionsExample extends React.Component {constructor(props) {super(props)this.state = {value: 'Edit this value',isBusy: false,}}render() {const { value, isBusy } = this.stateconst resetBusy = () => {setTimeout(() => this.setState({ isBusy: false }), 2000)}return (<EditActionsdisplay={<Text>{value}</Text>}edit={<InputautoFocusvalue={value}onChange={(e) =>this.setState({ value: e.target.value, isBusy: true }, resetBusy)}/>}loading={isBusy}/>)}}render(EditActionsExample)
Charlie's favorite candy is Wonka Bar
Copy
Edit
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.stateconst resetBusy = () => {setTimeout(() => this.setState({ isBusy: false }), 2500)}return (<EditActionsdisplay={<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={[<InputautoFocusvalue={value.name}onChange={(e) =>this.setState({value: {...value,name: e.target.value,},isBusy: true,},resetBusy)}/>,<SelectmatchWidths={false}multipleplacement="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)