import classNames from 'classnames' import { Text, Link, types, isAdmin } from 'react-bricks/rsc' import blockNames from '../../blockNames' import { buttonColors } from '../../colors' import { buttonColorsEditProps } from '../../LayoutSideProps' import ButtonClient from './ButtonClient' export interface ButtonProps { type: 'button' | 'link' text: types.TextValue href: string isTargetBlank: boolean buttonType: 'submit' | 'button' | 'reset' buttonColor: { color: string classNameSolid: string classNameOutline: string } variant: 'solid' | 'outline' | 'ghost' padding: 'normal' | 'small' className?: string simpleAnchorLink: boolean disabled?: boolean } const Button: types.Brick = ({ type, href, isTargetBlank, buttonType, buttonColor, variant, padding, className, simpleAnchorLink = false, text, disabled = false, }) => { const target = isTargetBlank ? { target: '_blank', rel: 'noopener noreferrer' } : {} if (type === 'link') { return ( {children}} /> ) } if (!isAdmin() && buttonType !== 'submit') { return ( ) } return ( ) } Button.schema = { name: blockNames.Button, label: 'Button', category: 'shared', hideFromAddMenu: true, playgroundLinkLabel: 'View source code on Github', playgroundLinkUrl: 'https://github.com/ReactBricks/reactbricks-starters/blob/main/packages/reactbricks-ui/nextjs-app/src/shared/bricks/Button.tsx', getDefaultProps: () => ({ type: 'link', text: 'Click me', href: '', isTargetBlank: false, buttonType: 'submit', buttonColor: buttonColors.SKY.value, variant: 'solid', padding: 'normal', }), sideEditProps: [ { groupName: 'Button functionality', defaultOpen: true, props: [ { name: 'type', label: 'Type', type: types.SideEditPropType.Select, selectOptions: { display: types.OptionsDisplay.Radio, options: [ { value: 'link', label: 'Link' }, { value: 'button', label: 'Form Button' }, ], }, }, { name: 'href', label: 'Link (external or path)', type: types.SideEditPropType.Text, show: (props) => props.type === 'link', }, { name: 'isTargetBlank', label: 'Open in new window', type: types.SideEditPropType.Boolean, show: (props) => props.type === 'link', }, { name: 'simpleAnchorLink', label: 'Simple anchor (no SPA link)', type: types.SideEditPropType.Boolean, show: (props) => props.type === 'link', }, { name: 'buttonType', label: 'Button type', type: types.SideEditPropType.Select, selectOptions: { display: types.OptionsDisplay.Radio, options: [ { value: 'submit', label: 'Form submit' }, { value: 'reset', label: 'Form reset' }, { value: 'button', label: 'Button' }, ], }, show: (props) => props.type === 'button', }, ], }, { groupName: 'Visual', defaultOpen: true, props: [ buttonColorsEditProps, { name: 'variant', label: 'Variant', type: types.SideEditPropType.Select, selectOptions: { display: types.OptionsDisplay.Radio, options: [ { value: 'solid', label: 'Solid' }, { value: 'outline', label: 'Outline' }, { value: 'ghost', label: 'Ghost' }, ], }, }, { name: 'padding', label: 'Size', type: types.SideEditPropType.Select, selectOptions: { display: types.OptionsDisplay.Radio, options: [ { value: 'normal', label: 'Normal' }, { value: 'small', label: 'Small' }, ], }, }, ], }, ], } export default Button