import * as React from 'react' import classNames from 'classnames' import { types, Text, Plain } from 'react-bricks/frontend' import { FieldErrorsImpl, UseFormRegister } from 'react-hook-form' import blockNames from '../../blockNames' import { useAdminContext } from 'react-bricks/frontend' import { textColors } from '../../colors' export interface FormSingleRadioProps { register: UseFormRegister fieldName: string label: types.TextValue value: string isRequired: boolean errors: FieldErrorsImpl<{ [x: string]: any }> } const FormSingleRadio: types.Brick = ({ register, fieldName, label, value, isRequired, errors, }) => { const labelTextContent = typeof label === 'string' ? label : Plain.serialize(label) const { isAdmin } = useAdminContext() const registerAttributes = fieldName ? register( fieldName?.replace(/\s/g, '').toLowerCase(), //@ts-ignore { required: isRequired, } ) : {} return (
) } FormSingleRadio.schema = { name: blockNames.FormSingleRadio, label: 'Radio option', category: 'contact', hideFromAddMenu: true, playgroundLinkLabel: 'View source code on Github', playgroundLinkUrl: 'https://github.com/ReactBricks/reactbricks-starters/blob/main/packages/reactbricks-ui/nextjs-pages/src/contacts/FormBuilder/FormSingleRadio.tsx', // tags: [], // Defaults when a new brick is added getDefaultProps: () => ({ label: 'New option', value: 'new-option', }), // Sidebar Edit controls for props sideEditProps: [ { name: 'value', type: types.SideEditPropType.Text, label: 'Value' }, ], } export default FormSingleRadio