@appbuckets/react-ui
Version:
Just Another React UI Framework
60 lines (57 loc) • 1.67 kB
JavaScript
import { __rest } from 'tslib';
import * as React from 'react';
import { createShorthandFactory } from '@appbuckets/react-ui-core';
import '../BucketTheme/BucketTheme.js';
import { useWithDefaultProps } from '../BucketTheme/BucketContext.js';
import Checkbox from '../Checkbox/Checkbox.js';
import { useRadioContext } from './Radio.context.js';
/* --------
* Component Definition
* -------- */
var RadioOption = React.forwardRef(function (receivedProps, ref) {
var props = useWithDefaultProps('radioOption', receivedProps);
var /** Strict radio props */
value = props.value,
/** All other props passed to Checkbox */
rest = __rest(props, ['value']);
// ----
// Hook Usage
// ----
var _a = useRadioContext() || {},
currentValue = _a.currentValue,
setValue = _a.setValue;
// ----
// Render the Component
// ----
return Checkbox.create(rest, {
autoGenerateKey: false,
overrideProps: function () {
return {
ref: ref,
checked: !!rest.checked || currentValue === value,
radio: true,
onClick: function (event) {
/** Call user defined click event if exists */
if (typeof rest.onClick === 'function') {
rest.onClick(event, props);
}
/** Set the new value */
if (typeof setValue === 'function') {
setValue(event, value);
}
},
};
},
});
});
RadioOption.displayName = 'RadioOption';
RadioOption.create = createShorthandFactory(
RadioOption,
function (value) {
return { value: value };
},
function (props) {
return props.value;
}
);
export { RadioOption as default };