UNPKG

@bigfishtv/cockpit

Version:

34 lines (29 loc) 842 B
import React, { Component } from 'react' import { createValue } from '@bigfishtv/react-forms' import Button from '../button/Button' export default class SwapFieldValues extends Component { static defaultProps = { text: 'Swap', icon: 'swap-calls', options: {}, formValue: createValue({ schema: null, value: {}, }), } handleSwap() { const { options, formValue } = this.props const keys = Object.keys(options) const oldFormValue = formValue.value const newFormValue = { ...oldFormValue } for (let key of keys) { newFormValue[key] = oldFormValue[options[key]] newFormValue[options[key]] = oldFormValue[key] } this.props.formValue.update(newFormValue) } render() { const { text, formValue, ...rest } = this.props return <Button {...rest} text={' ' + text} onClick={() => this.handleSwap()} /> } }