UNPKG

saagie-ui

Version:

Saagie UI from Saagie Design System

73 lines (61 loc) 1.51 kB
import React from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; const propTypes = { /** * The FormOptionsGroupItem content */ children: PropTypes.node.isRequired, /** * The className property allows you to add more classes to the component. */ className: PropTypes.string, /** * The component default class. */ defaultClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]), /** * Disable the FormOptionsGroupItem. */ isDisabled: PropTypes.bool, /** * Type of FormOptionsGroupItem. */ type: PropTypes.oneOf(['default', 'light']), /** * The component used for the root node. * Either a string to use a DOM element or a component. */ tag: PropTypes.elementType, }; const defaultProps = { className: '', defaultClassName: 'sui-a-form-options-group__label', isDisabled: false, tag: 'label', type: 'default', }; export const FormOptionsGroupItem = ({ children, className, defaultClassName, isDisabled, tag: Tag, type, ...attributes }) => { const classes = classnames( className, defaultClassName, `as--${type}` ); const isInputDisabled = attributes.disabled || isDisabled; return ( <Tag> <input type="radio" {...attributes} disabled={isInputDisabled} /> <span className={classes}>{children}</span> </Tag> ); }; FormOptionsGroupItem.propTypes = propTypes; FormOptionsGroupItem.defaultProps = defaultProps;