diff --git a/.changeset/grumpy-lobsters-obey.md b/.changeset/grumpy-lobsters-obey.md new file mode 100644 index 00000000000..80311ebbeda --- /dev/null +++ b/.changeset/grumpy-lobsters-obey.md @@ -0,0 +1,5 @@ +--- +'@primer/react': major +--- + +Update FormControl component to no longer support sx diff --git a/packages/react/src/FormControl/FormControl.docs.json b/packages/react/src/FormControl/FormControl.docs.json index c1f113f2db3..aee7010d566 100644 --- a/packages/react/src/FormControl/FormControl.docs.json +++ b/packages/react/src/FormControl/FormControl.docs.json @@ -98,11 +98,6 @@ "description": "Class name(s) for custom styling.", "defaultValue": "" }, - { - "name": "sx", - "type": "SystemStyleObject", - "deprecated": true - }, { "name": "ref", "type": "React.RefObject" @@ -152,11 +147,6 @@ "type": "string", "description": "Class name(s) for custom styling.", "defaultValue": "" - }, - { - "name": "sx", - "type": "SystemStyleObject", - "deprecated": true } ] }, @@ -174,11 +164,6 @@ "type": "React.ReactNode", "defaultValue": "", "description": "The content (usually just text) that is rendered to give contextual info about the field" - }, - { - "name": "sx", - "type": "SystemStyleObject", - "deprecated": true } ] }, @@ -203,11 +188,6 @@ "type": "string", "description": "May be used to override the ID assigned by FormControl's React Context", "defaultValue": "" - }, - { - "name": "sx", - "type": "SystemStyleObject", - "deprecated": true } ] }, @@ -219,13 +199,8 @@ "type": "React.ReactNode", "defaultValue": "", "description": "The visual to render before the choice input's label" - }, - { - "name": "sx", - "type": "SystemStyleObject", - "deprecated": true } ] } ] -} \ No newline at end of file +} diff --git a/packages/react/src/FormControl/FormControl.tsx b/packages/react/src/FormControl/FormControl.tsx index ae6f0ff9400..802418f6fc0 100644 --- a/packages/react/src/FormControl/FormControl.tsx +++ b/packages/react/src/FormControl/FormControl.tsx @@ -11,7 +11,6 @@ import Textarea from '../Textarea' import {CheckboxOrRadioGroupContext} from '../internal/components/CheckboxOrRadioGroup' import ValidationAnimationContainer from '../internal/components/ValidationAnimationContainer' import {useSlots} from '../hooks/useSlots' -import type {SxProp} from '../sx' import {useId} from '../hooks/useId' import {FormControlCaption} from './FormControlCaption' import FormControlLabel from './FormControlLabel' @@ -20,7 +19,6 @@ import FormControlValidation from './_FormControlValidation' import {FormControlContextProvider} from './_FormControlContext' import {warning} from '../utils/warning' import classes from './FormControl.module.css' -import {BoxWithFallback} from '../internal/components/BoxWithFallback' export type FormControlProps = { children?: React.ReactNode @@ -42,10 +40,10 @@ export type FormControlProps = { */ layout?: 'horizontal' | 'vertical' className?: string -} & SxProp +} const FormControl = React.forwardRef( - ({children, disabled: disabledProp, layout = 'vertical', id: idProp, required, sx, className}, ref) => { + ({children, disabled: disabledProp, layout = 'vertical', id: idProp, required, className}, ref) => { const [slots, childrenWithoutSlots] = useSlots(children, { caption: FormControlCaption, label: FormControlLabel, @@ -168,19 +166,17 @@ const FormControl = React.forwardRef( }} > {isChoiceInput || layout === 'horizontal' ? ( - {InputChildren} - + ) : ( - {slots.label} @@ -207,7 +203,7 @@ const FormControl = React.forwardRef( {slots.validation} ) : null} {slots.caption} - + )} ) diff --git a/packages/react/src/FormControl/FormControlCaption.tsx b/packages/react/src/FormControl/FormControlCaption.tsx index 862cdc5533d..d01b2bd710e 100644 --- a/packages/react/src/FormControl/FormControlCaption.tsx +++ b/packages/react/src/FormControl/FormControlCaption.tsx @@ -1,31 +1,25 @@ import {clsx} from 'clsx' import type React from 'react' import Text from '../Text' -import type {SxProp} from '../sx' import classes from './FormControlCaption.module.css' import {useFormControlContext} from './_FormControlContext' -import {BoxWithFallback} from '../internal/components/BoxWithFallback' -type FormControlCaptionProps = React.PropsWithChildren< - { - id?: string - className?: string - } & SxProp -> +export type FormControlCaptionProps = React.PropsWithChildren<{ + id?: string + className?: string +}> -function FormControlCaption({id, children, sx, className}: FormControlCaptionProps) { +function FormControlCaption({id, children, className}: FormControlCaptionProps) { const {captionId, disabled} = useFormControlContext() return ( - {children} - + ) } diff --git a/packages/react/src/FormControl/FormControlLabel.tsx b/packages/react/src/FormControl/FormControlLabel.tsx index 0ac71b80bd9..59b6f4a5fcd 100644 --- a/packages/react/src/FormControl/FormControlLabel.tsx +++ b/packages/react/src/FormControl/FormControlLabel.tsx @@ -1,5 +1,4 @@ import type React from 'react' -import type {SxProp} from '../sx' import {useFormControlContext} from './_FormControlContext' import {InputLabel} from '../internal/components/InputLabel' @@ -12,11 +11,11 @@ export type Props = { requiredIndicator?: boolean id?: string className?: string -} & SxProp +} const FormControlLabel: React.FC< React.PropsWithChildren<{htmlFor?: string} & React.ComponentProps & Props> -> = ({as, children, htmlFor, id, visuallyHidden, requiredIndicator = true, requiredText, sx, className, ...props}) => { +> = ({as, children, htmlFor, id, visuallyHidden, requiredIndicator = true, requiredText, className, ...props}) => { const {disabled, id: formControlId, required} = useFormControlContext() /** @@ -33,7 +32,6 @@ const FormControlLabel: React.FC< requiredText, requiredIndicator, disabled, - sx, ...props, } : { @@ -46,7 +44,6 @@ const FormControlLabel: React.FC< requiredText, requiredIndicator, disabled, - sx, ...props, } diff --git a/packages/react/src/FormControl/FormControlLeadingVisual.module.css b/packages/react/src/FormControl/FormControlLeadingVisual.module.css new file mode 100644 index 00000000000..35c81bfe8d5 --- /dev/null +++ b/packages/react/src/FormControl/FormControlLeadingVisual.module.css @@ -0,0 +1,21 @@ +.LeadingVisual { + --leadingVisual-size: 16px; + + color: var(--fgColor-default); + display: flex; + align-items: center; + + &:where([data-control-disabled]) { + color: var(--control-fgColor-disabled); + } + + & > * { + min-width: var(--leadingVisual-size); + min-height: var(--leadingVisual-size); + fill: currentColor; + } + + &:where([data-has-caption]) { + --leadingVisual-size: 24px; + } +} diff --git a/packages/react/src/FormControl/FormControlLeadingVisual.tsx b/packages/react/src/FormControl/FormControlLeadingVisual.tsx index 3f2a86ef277..fa253d1aa4f 100644 --- a/packages/react/src/FormControl/FormControlLeadingVisual.tsx +++ b/packages/react/src/FormControl/FormControlLeadingVisual.tsx @@ -1,46 +1,18 @@ import type React from 'react' -import {get} from '../constants' -import type {SxProp} from '../sx' import {useFormControlContext} from './_FormControlContext' -import styled from 'styled-components' -import sx from '../sx' +import classes from './FormControlLeadingVisual.module.css' -const FormControlLeadingVisual: React.FC> = ({children, sx}) => { +const FormControlLeadingVisual: React.FC = ({children}) => { const {disabled, captionId} = useFormControlContext() return ( - {children} - + ) } -const StyledLeadingVisual = styled.div` - --leadingVisual-size: ${get('fontSizes.2')}; - - color: var(--fgColor-default); - - display: flex; - align-items: center; /* Vertical alignment */ - - &:where([data-control-disabled]) { - color: var(--control-fgColor-disabled); - } - - & > * { - min-width: var(--leadingVisual-size); - min-height: var(--leadingVisual-size); - fill: currentColor; - } - - &:where([data-has-caption]) { - --leadingVisual-size: ${get('fontSizes.4')}; - } - - ${sx} -` - export default FormControlLeadingVisual diff --git a/packages/react/src/FormControl/index.ts b/packages/react/src/FormControl/index.ts index a79a15f5d3e..a4293bef9d9 100644 --- a/packages/react/src/FormControl/index.ts +++ b/packages/react/src/FormControl/index.ts @@ -1,2 +1,6 @@ export {useFormControlForwardedProps} from './_FormControlContext' export {default} from './FormControl' +export type {FormControlProps} from './FormControl' +export type {FormControlCaptionProps} from './FormControlCaption' +export type {Props as FormControlLabelProps} from './FormControlLabel' +export type {FormControlValidationProps} from './_FormControlValidation' diff --git a/packages/react/src/__tests__/__snapshots__/exports.test.ts.snap b/packages/react/src/__tests__/__snapshots__/exports.test.ts.snap index 574c3bf2a19..7871f21dd20 100644 --- a/packages/react/src/__tests__/__snapshots__/exports.test.ts.snap +++ b/packages/react/src/__tests__/__snapshots__/exports.test.ts.snap @@ -73,6 +73,10 @@ exports[`@primer/react > should not update exports without a semver change 1`] = "type FocusTrapHookSettings", "type FocusZoneHookSettings", "FormControl", + "type FormControlCaptionProps", + "type FormControlLabelProps", + "type FormControlProps", + "type FormControlValidationProps", "Header", "type HeaderItemProps", "type HeaderLinkProps", diff --git a/packages/react/src/experimental/SelectPanel2/SelectPanel.examples.stories.module.css b/packages/react/src/experimental/SelectPanel2/SelectPanel.examples.stories.module.css index 88cbedab134..731d400ca03 100644 --- a/packages/react/src/experimental/SelectPanel2/SelectPanel.examples.stories.module.css +++ b/packages/react/src/experimental/SelectPanel2/SelectPanel.examples.stories.module.css @@ -56,3 +56,7 @@ max-height: 0; overflow: hidden; } + +.FormControl { + margin-bottom: var(--base-size-8); +} diff --git a/packages/react/src/experimental/SelectPanel2/SelectPanel.examples.stories.tsx b/packages/react/src/experimental/SelectPanel2/SelectPanel.examples.stories.tsx index 0d81ff12f76..b21b6b87d07 100644 --- a/packages/react/src/experimental/SelectPanel2/SelectPanel.examples.stories.tsx +++ b/packages/react/src/experimental/SelectPanel2/SelectPanel.examples.stories.tsx @@ -1069,11 +1069,11 @@ const CreateNewLabelDialog = ({ Note this Dialog is not accessible. Do not copy this.
- + Name - + Color diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index c64013bba6c..922b7b637c4 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -97,6 +97,12 @@ export {ConfirmationDialog} from './ConfirmationDialog/ConfirmationDialog' export {default as Flash} from './Flash' export type {FlashProps} from './Flash' export {default as FormControl} from './FormControl' +export type { + FormControlProps, + FormControlCaptionProps, + FormControlLabelProps, + FormControlValidationProps, +} from './FormControl' export {useFormControlForwardedProps} from './FormControl' export {default as Header} from './Header' export type {HeaderProps, HeaderItemProps, HeaderLinkProps} from './Header' diff --git a/packages/styled-react/src/components/FormControl.tsx b/packages/styled-react/src/components/FormControl.tsx new file mode 100644 index 00000000000..b4affd914be --- /dev/null +++ b/packages/styled-react/src/components/FormControl.tsx @@ -0,0 +1,44 @@ +import { + Box, + FormControl as PrimerFormControl, + type FormControlProps as PrimerFormControlProps, + type FormControlCaptionProps as PrimerFormControlCaptionProps, + type FormControlValidationProps as PrimerFormControlValidationProps, + type SxProp, +} from '@primer/react' +import {forwardRef, type PropsWithChildren} from 'react' + +type FormControlProps = PropsWithChildren & SxProp + +const FormControlImpl = forwardRef(function FormControl(props, ref) { + return +}) + +type FormControlCaptionProps = PropsWithChildren & SxProp +const FormControlCaption = (props: FormControlCaptionProps) => { + return +} + +type FormControlValidationProps = PropsWithChildren & SxProp + +const FormControlValidation = (props: FormControlValidationProps) => { + return +} + +const FormControlLeadingVisual = (props: PropsWithChildren) => { + return +} + +const FormControl = Object.assign(FormControlImpl, { + Caption: FormControlCaption, + LeadingVisual: FormControlLeadingVisual, + Validation: FormControlValidation, + Label: PrimerFormControl.Label, +}) as typeof FormControlImpl & { + Caption: typeof FormControlCaption + LeadingVisual: typeof FormControlLeadingVisual + Validation: typeof FormControlValidation + Label: typeof PrimerFormControl.Label +} + +export {FormControl, type FormControlProps} diff --git a/packages/styled-react/src/index.tsx b/packages/styled-react/src/index.tsx index c21bf22b9b0..2994d9b7cdd 100644 --- a/packages/styled-react/src/index.tsx +++ b/packages/styled-react/src/index.tsx @@ -8,7 +8,6 @@ export {Button} from '@primer/react' export {CheckboxGroup} from '@primer/react' export {CircleBadge} from '@primer/react' export {Details} from '@primer/react' -export {FormControl} from '@primer/react' export {Heading} from '@primer/react' export {IconButton} from '@primer/react' export {Label} from '@primer/react' @@ -36,6 +35,7 @@ export {Checkbox, type CheckboxProps} from './components/Checkbox' export {CounterLabel, type CounterLabelProps} from './components/CounterLabel' export {Dialog, type DialogProps} from './components/Dialog' export {Flash} from './components/Flash' +export {FormControl, type FormControlProps} from './components/FormControl' export {Header, type HeaderProps} from './components/Header' export {Link, type LinkProps} from './components/Link' export {LinkButton, type LinkButtonProps} from './components/LinkButton'