import { useId } from 'react' import * as React from 'react' import { RadioGroup as UIRadioGroup, Radio as UIRadio, SIZE_SMALL, } from '@planview/pv-uikit' import type { RadioGroupProps, RadioProps } from '@planview/pv-uikit' import Field from '../field' import styled from 'styled-components' type Props = Omit & Pick< React.ComponentPropsWithRef, 'label' | 'error' | 'withAsterisk' | 'labelPosition' | 'warning' > & { /** * Orientation of radio buttons */ orientation?: 'horizontal' | 'vertical' /** Callback triggered after a Radio button is selected */ onChange?: ( val: string, event: React.ChangeEvent ) => void } const StyledGroup = styled(UIRadioGroup)<{ $orientation: 'horizontal' | 'vertical' }>` ${(props) => props.$orientation === 'horizontal' ? `display: flex; flex-wrap: wrap;` : null}; ` /** * Implementation combines [Form Field specification](https://design.planview.com/components/forms/form-field) * with [Radio and RadioGroup specification](https://design.planview.com/components/forms/radio). * * `import { RadioGroup, Radio } from '@planview/pv-form'` */ const RadioGroup: React.FC = ({ id: incomingId, label, error, warning, withAsterisk, children, labelPosition, orientation = 'vertical', size = 'small', onChange, ...inputProps }) => { const internalId = `pv-form-${useId()}` const id = incomingId || internalId return ( {(fieldProps) => ( {children} )} ) } const Radio: React.FC = (props) => ( ) export { RadioGroup, Radio } export default RadioGroup