1- import React , { useEffect , useState } from 'react' ;
21import PropTypes from 'prop-types' ;
32import { omit } from 'ramda' ;
3+ import React , { useEffect , useState } from 'react' ;
44
55/**
66 * Creates a single radio button. Use the `checked` prop in your callbacks.
77 */
88const RadioButton = props => {
9- const { checked, loading_state, setProps, ...otherProps } = props ;
9+ const { checked, loading_state, disabled , setProps, ...otherProps } = props ;
1010 const [ checkedState , setCheckedState ] = useState ( checked || false ) ;
1111
1212 useEffect ( ( ) => {
@@ -23,12 +23,15 @@ const RadioButton = props => {
2323 [ 'setProps' , 'persistence' , 'persistence_type' , 'persisted_props' ] ,
2424 otherProps
2525 ) }
26+ disabled = { disabled }
2627 onClick = { ( ) => {
27- setCheckedState ( ! checkedState ) ;
28- if ( setProps ) {
29- setProps ( {
30- checked : ! checkedState
31- } ) ;
28+ if ( ! disabled ) {
29+ setCheckedState ( ! checkedState ) ;
30+ if ( setProps ) {
31+ setProps ( {
32+ checked : ! checkedState
33+ } ) ;
34+ }
3235 }
3336 } }
3437 onChange = { ( ) => { } }
@@ -124,7 +127,12 @@ RadioButton.propTypes = {
124127 * local: window.localStorage, data is kept after the browser quit.
125128 * session: window.sessionStorage, data is cleared once the browser quit.
126129 */
127- persistence_type : PropTypes . oneOf ( [ 'local' , 'session' , 'memory' ] )
130+ persistence_type : PropTypes . oneOf ( [ 'local' , 'session' , 'memory' ] ) ,
131+
132+ /**
133+ * Disable the RadioButton.
134+ */
135+ disabled : PropTypes . bool
128136} ;
129137
130138export default RadioButton ;
0 commit comments