import * as React from 'react'; import classnames from 'classnames'; import CheckmarkSVG from '../../../svg/checkmark--big.svg'; import ExclamationSVG from '../../../svg/exclamation.svg'; import styles from './RadioBlock.sass'; import { Container } from '../../modules/Container/Container'; import ILocalContainerProps from '../../../common/structures/ILocalContainerProps'; import { Title, TitlePropSize } from '../../text/Title/Title'; import { FunctionGeneric } from '../../../common/structures/Generics'; interface IRadioBlockItemProps extends ILocalContainerProps { disabled?: boolean; warn?: boolean; heightSize?: 'm' | 'l' | 'none'; label?: string; onClick?: FunctionGeneric; readonly?: boolean; selected?: boolean; svg?: any; value?: string | null; content?: React.ReactNode; borderOnHover?: boolean; centerContent?: boolean; } const RadioBlockItem: React.FC = (props: IRadioBlockItemProps) => { const { svg: svgProp, value, selected, disabled, onClick, warn, centerContent, heightSize, borderOnHover, label, content, readonly, container, className, ...otherProps } = props; const handleClick = () => { if (disabled) { return; } if (onClick) { onClick(value); } }; const onKeyDown = (event: any) => { if (event.key === ' ' || event.key === 'Enter') { event.preventDefault(); event.target.click(); } }; const svg = warn ? : svgProp || ; return ( // wrap in optional container
{label && ( {label} )} {content && (
{content}
)}
{svg}
); }; RadioBlockItem.defaultProps = { disabled: false, heightSize: 'l', borderOnHover: true, centerContent: true, }; interface IProps extends ILocalContainerProps { default?: string | null; direction?: 'horiz' | 'vert'; disabled?: boolean; warn?: boolean; heightSize?: 'm' | 'l' | 'none'; onChange?: FunctionGeneric; options: { [key: string]: IRadioBlockItemProps }; readonly?: boolean; borderOnHover?: boolean; centerContent?: boolean; } const RadioBlock: React.FC = (props: IProps) => { const { default: defaultValue, direction, disabled, warn, heightSize, onChange, centerContent, options, readonly, borderOnHover, container, className, id, style, ...otherProps } = props; const [value, setValue] = React.useState(null || defaultValue); React.useEffect(() => { setValue(defaultValue); }, [defaultValue]); const onClick = (selection: string | null) => { setValue(selection); if (onChange) { onChange(selection); } }; return ( // wrap in optional container
{Object.keys(options).map((optionValue: string) => ( ))}
); }; export default RadioBlock;