react-onsenui
Version:
Onsen UI - React Components for Hybrid Cordova/PhoneGap Apps with Material Design and iOS UI components
86 lines (74 loc) • 2 kB
JSX
import PropTypes from 'prop-types';
import 'onsenui/esm/elements/ons-switch';
import onsCustomElement from '../onsCustomElement';
import oneTimeProp from '../oneTimeProp';
import INPUT_PROPS from '../inputProps';
const nameMap = {
...INPUT_PROPS
};
const withDefaultChecked = component => oneTimeProp(component, 'defaultChecked', 'checked');
/**
* @original ons-switch
* @category form
* @tutorial react/Reference/switch
* @description
* [en] Switch component. The switch can be toggled both by dragging and tapping.
* Will automatically displays a Material Design switch on Android devices.
[/en]
* [ja][/ja]
* @example
* <Switch checked={this.state.checked} onChange={this.onChange} />
*/
const Switch = withDefaultChecked(onsCustomElement('ons-switch', {deprecated: nameMap}));
Switch.propTypes = {
/**
* @name modifier
* @type string
* @required false
* @description
* [en]The appearance of the checkbox.[/en]
* [ja][/ja]
*/
modifier: PropTypes.string,
/**
* @name onChange
* @type function
* @description
* [en] Called when the value of the switch changes (checked/unchecked) [/en]
* [ja][/ja]
*/
onChange: PropTypes.func,
/**
* @name checked
* @type bool
* @description
* [en] Whether the switch is checked.[/en]
* [ja][/ja]
*/
checked: PropTypes.bool,
/**
* @name defaultChecked
* @type boolean
* @description
* [en]Defined the state of the switch at first render for uncontrolled inputs.[/en]
* [ja][/ja]
*/
defaultChecked: PropTypes.bool,
/**
* @name disabled
* @type bool
* @description
* [en] If set, the switch is disabled.[/en]
* [ja][/ja]
*/
disabled: PropTypes.bool,
/**
* @name inputId
* @type string
* @description
* [en] Specify the `id` attribute of the inner `<input>` element. This is useful when using `<label for="...">` elements.[/en]
* [ja][/ja]
*/
inputId: PropTypes.string
};
export default Switch;