Skip to content

Commit d5fea1d

Browse files
francineluccapksjce
authored andcommitted
revert: Remove support for sx from FormControl component (#6681) (#6939)
1 parent d0b36a7 commit d5fea1d

File tree

14 files changed

+90
-112
lines changed

14 files changed

+90
-112
lines changed

.changeset/grumpy-lobsters-obey.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/react/src/FormControl/FormControl.docs.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@
9898
"description": "Class name(s) for custom styling.",
9999
"defaultValue": ""
100100
},
101+
{
102+
"name": "sx",
103+
"type": "SystemStyleObject",
104+
"deprecated": true
105+
},
101106
{
102107
"name": "ref",
103108
"type": "React.RefObject<HTMLDivElement>"
@@ -147,6 +152,11 @@
147152
"type": "string",
148153
"description": "Class name(s) for custom styling.",
149154
"defaultValue": ""
155+
},
156+
{
157+
"name": "sx",
158+
"type": "SystemStyleObject",
159+
"deprecated": true
150160
}
151161
]
152162
},
@@ -164,6 +174,11 @@
164174
"type": "React.ReactNode",
165175
"defaultValue": "",
166176
"description": "The content (usually just text) that is rendered to give contextual info about the field"
177+
},
178+
{
179+
"name": "sx",
180+
"type": "SystemStyleObject",
181+
"deprecated": true
167182
}
168183
]
169184
},
@@ -188,6 +203,11 @@
188203
"type": "string",
189204
"description": "May be used to override the ID assigned by FormControl's React Context",
190205
"defaultValue": ""
206+
},
207+
{
208+
"name": "sx",
209+
"type": "SystemStyleObject",
210+
"deprecated": true
191211
}
192212
]
193213
},
@@ -199,8 +219,13 @@
199219
"type": "React.ReactNode",
200220
"defaultValue": "",
201221
"description": "The visual to render before the choice input's label"
222+
},
223+
{
224+
"name": "sx",
225+
"type": "SystemStyleObject",
226+
"deprecated": true
202227
}
203228
]
204229
}
205230
]
206-
}
231+
}

packages/react/src/FormControl/FormControl.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Textarea from '../Textarea'
1111
import {CheckboxOrRadioGroupContext} from '../internal/components/CheckboxOrRadioGroup'
1212
import ValidationAnimationContainer from '../internal/components/ValidationAnimationContainer'
1313
import {useSlots} from '../hooks/useSlots'
14+
import type {SxProp} from '../sx'
1415
import {useId} from '../hooks/useId'
1516
import {FormControlCaption} from './FormControlCaption'
1617
import FormControlLabel from './FormControlLabel'
@@ -19,6 +20,7 @@ import FormControlValidation from './_FormControlValidation'
1920
import {FormControlContextProvider} from './_FormControlContext'
2021
import {warning} from '../utils/warning'
2122
import classes from './FormControl.module.css'
23+
import {BoxWithFallback} from '../internal/components/BoxWithFallback'
2224

2325
export type FormControlProps = {
2426
children?: React.ReactNode
@@ -40,10 +42,10 @@ export type FormControlProps = {
4042
*/
4143
layout?: 'horizontal' | 'vertical'
4244
className?: string
43-
}
45+
} & SxProp
4446

4547
const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
46-
({children, disabled: disabledProp, layout = 'vertical', id: idProp, required, className}, ref) => {
48+
({children, disabled: disabledProp, layout = 'vertical', id: idProp, required, sx, className}, ref) => {
4749
const [slots, childrenWithoutSlots] = useSlots(children, {
4850
caption: FormControlCaption,
4951
label: FormControlLabel,
@@ -166,17 +168,19 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
166168
}}
167169
>
168170
{isChoiceInput || layout === 'horizontal' ? (
169-
<div
171+
<BoxWithFallback
170172
ref={ref}
171173
data-has-leading-visual={slots.leadingVisual ? '' : undefined}
174+
sx={sx}
172175
className={clsx(className, classes.ControlHorizontalLayout)}
173176
>
174177
{InputChildren}
175-
</div>
178+
</BoxWithFallback>
176179
) : (
177-
<div
180+
<BoxWithFallback
178181
ref={ref}
179182
data-has-label={!isLabelHidden ? '' : undefined}
183+
sx={sx}
180184
className={clsx(className, classes.ControlVerticalLayout)}
181185
>
182186
{slots.label}
@@ -203,7 +207,7 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
203207
<ValidationAnimationContainer show>{slots.validation}</ValidationAnimationContainer>
204208
) : null}
205209
{slots.caption}
206-
</div>
210+
</BoxWithFallback>
207211
)}
208212
</FormControlContextProvider>
209213
)

packages/react/src/FormControl/FormControlCaption.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
import {clsx} from 'clsx'
22
import type React from 'react'
33
import Text from '../Text'
4+
import type {SxProp} from '../sx'
45
import classes from './FormControlCaption.module.css'
56
import {useFormControlContext} from './_FormControlContext'
7+
import {BoxWithFallback} from '../internal/components/BoxWithFallback'
68

7-
export type FormControlCaptionProps = React.PropsWithChildren<{
8-
id?: string
9-
className?: string
10-
}>
9+
type FormControlCaptionProps = React.PropsWithChildren<
10+
{
11+
id?: string
12+
className?: string
13+
} & SxProp
14+
>
1115

12-
function FormControlCaption({id, children, className}: FormControlCaptionProps) {
16+
function FormControlCaption({id, children, sx, className}: FormControlCaptionProps) {
1317
const {captionId, disabled} = useFormControlContext()
1418

1519
return (
16-
<Text
20+
<BoxWithFallback
21+
as={Text}
1722
id={id ?? captionId}
1823
className={clsx(className, classes.Caption)}
1924
data-control-disabled={disabled ? '' : undefined}
25+
sx={sx}
2026
>
2127
{children}
22-
</Text>
28+
</BoxWithFallback>
2329
)
2430
}
2531

packages/react/src/FormControl/FormControlLabel.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type React from 'react'
2+
import type {SxProp} from '../sx'
23
import {useFormControlContext} from './_FormControlContext'
34
import {InputLabel} from '../internal/components/InputLabel'
45

@@ -11,11 +12,11 @@ export type Props = {
1112
requiredIndicator?: boolean
1213
id?: string
1314
className?: string
14-
}
15+
} & SxProp
1516

1617
const FormControlLabel: React.FC<
1718
React.PropsWithChildren<{htmlFor?: string} & React.ComponentProps<typeof InputLabel> & Props>
18-
> = ({as, children, htmlFor, id, visuallyHidden, requiredIndicator = true, requiredText, className, ...props}) => {
19+
> = ({as, children, htmlFor, id, visuallyHidden, requiredIndicator = true, requiredText, sx, className, ...props}) => {
1920
const {disabled, id: formControlId, required} = useFormControlContext()
2021

2122
/**
@@ -32,6 +33,7 @@ const FormControlLabel: React.FC<
3233
requiredText,
3334
requiredIndicator,
3435
disabled,
36+
sx,
3537
...props,
3638
}
3739
: {
@@ -44,6 +46,7 @@ const FormControlLabel: React.FC<
4446
requiredText,
4547
requiredIndicator,
4648
disabled,
49+
sx,
4750
...props,
4851
}
4952

packages/react/src/FormControl/FormControlLeadingVisual.module.css

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,46 @@
11
import type React from 'react'
2+
import {get} from '../constants'
3+
import type {SxProp} from '../sx'
24
import {useFormControlContext} from './_FormControlContext'
3-
import classes from './FormControlLeadingVisual.module.css'
5+
import styled from 'styled-components'
6+
import sx from '../sx'
47

5-
const FormControlLeadingVisual: React.FC<React.PropsWithChildren> = ({children}) => {
8+
const FormControlLeadingVisual: React.FC<React.PropsWithChildren<SxProp>> = ({children, sx}) => {
69
const {disabled, captionId} = useFormControlContext()
710
return (
8-
<div
9-
className={classes.LeadingVisual}
11+
<StyledLeadingVisual
1012
data-control-disabled={disabled ? '' : undefined}
1113
data-has-caption={captionId ? '' : undefined}
14+
sx={sx}
1215
>
1316
{children}
14-
</div>
17+
</StyledLeadingVisual>
1518
)
1619
}
1720

21+
const StyledLeadingVisual = styled.div`
22+
--leadingVisual-size: ${get('fontSizes.2')};
23+
24+
color: var(--fgColor-default);
25+
26+
display: flex;
27+
align-items: center; /* Vertical alignment */
28+
29+
&:where([data-control-disabled]) {
30+
color: var(--control-fgColor-disabled);
31+
}
32+
33+
& > * {
34+
min-width: var(--leadingVisual-size);
35+
min-height: var(--leadingVisual-size);
36+
fill: currentColor;
37+
}
38+
39+
&:where([data-has-caption]) {
40+
--leadingVisual-size: ${get('fontSizes.4')};
41+
}
42+
43+
${sx}
44+
`
45+
1846
export default FormControlLeadingVisual
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
export {useFormControlForwardedProps} from './_FormControlContext'
22
export {default} from './FormControl'
3-
export type {FormControlProps} from './FormControl'
4-
export type {FormControlCaptionProps} from './FormControlCaption'
5-
export type {Props as FormControlLabelProps} from './FormControlLabel'
6-
export type {FormControlValidationProps} from './_FormControlValidation'

packages/react/src/__tests__/__snapshots__/exports.test.ts.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ exports[`@primer/react > should not update exports without a semver change 1`] =
7474
"type FocusTrapHookSettings",
7575
"type FocusZoneHookSettings",
7676
"FormControl",
77-
"type FormControlCaptionProps",
78-
"type FormControlLabelProps",
79-
"type FormControlProps",
80-
"type FormControlValidationProps",
8177
"Header",
8278
"type HeaderItemProps",
8379
"type HeaderLinkProps",

packages/react/src/experimental/SelectPanel2/SelectPanel.examples.stories.module.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,3 @@
6060
max-height: 0;
6161
overflow: hidden;
6262
}
63-
64-
.FormControl {
65-
margin-bottom: var(--base-size-8);
66-
}

0 commit comments

Comments
 (0)