Skip to content

Commit 158703b

Browse files
Remove support for sx from FormControl component (#6681)
Co-authored-by: Liu Liu <[email protected]>
1 parent 19befd6 commit 158703b

File tree

14 files changed

+112
-90
lines changed

14 files changed

+112
-90
lines changed

.changeset/grumpy-lobsters-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': major
3+
---
4+
5+
Update FormControl component to no longer support sx

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

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@
9898
"description": "Class name(s) for custom styling.",
9999
"defaultValue": ""
100100
},
101-
{
102-
"name": "sx",
103-
"type": "SystemStyleObject",
104-
"deprecated": true
105-
},
106101
{
107102
"name": "ref",
108103
"type": "React.RefObject<HTMLDivElement>"
@@ -152,11 +147,6 @@
152147
"type": "string",
153148
"description": "Class name(s) for custom styling.",
154149
"defaultValue": ""
155-
},
156-
{
157-
"name": "sx",
158-
"type": "SystemStyleObject",
159-
"deprecated": true
160150
}
161151
]
162152
},
@@ -174,11 +164,6 @@
174164
"type": "React.ReactNode",
175165
"defaultValue": "",
176166
"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
182167
}
183168
]
184169
},
@@ -203,11 +188,6 @@
203188
"type": "string",
204189
"description": "May be used to override the ID assigned by FormControl's React Context",
205190
"defaultValue": ""
206-
},
207-
{
208-
"name": "sx",
209-
"type": "SystemStyleObject",
210-
"deprecated": true
211191
}
212192
]
213193
},
@@ -219,13 +199,8 @@
219199
"type": "React.ReactNode",
220200
"defaultValue": "",
221201
"description": "The visual to render before the choice input's label"
222-
},
223-
{
224-
"name": "sx",
225-
"type": "SystemStyleObject",
226-
"deprecated": true
227202
}
228203
]
229204
}
230205
]
231-
}
206+
}

packages/react/src/FormControl/FormControl.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ 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'
1514
import {useId} from '../hooks/useId'
1615
import {FormControlCaption} from './FormControlCaption'
1716
import FormControlLabel from './FormControlLabel'
@@ -20,7 +19,6 @@ import FormControlValidation from './_FormControlValidation'
2019
import {FormControlContextProvider} from './_FormControlContext'
2120
import {warning} from '../utils/warning'
2221
import classes from './FormControl.module.css'
23-
import {BoxWithFallback} from '../internal/components/BoxWithFallback'
2422

2523
export type FormControlProps = {
2624
children?: React.ReactNode
@@ -42,10 +40,10 @@ export type FormControlProps = {
4240
*/
4341
layout?: 'horizontal' | 'vertical'
4442
className?: string
45-
} & SxProp
43+
}
4644

4745
const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
48-
({children, disabled: disabledProp, layout = 'vertical', id: idProp, required, sx, className}, ref) => {
46+
({children, disabled: disabledProp, layout = 'vertical', id: idProp, required, className}, ref) => {
4947
const [slots, childrenWithoutSlots] = useSlots(children, {
5048
caption: FormControlCaption,
5149
label: FormControlLabel,
@@ -168,19 +166,17 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
168166
}}
169167
>
170168
{isChoiceInput || layout === 'horizontal' ? (
171-
<BoxWithFallback
169+
<div
172170
ref={ref}
173171
data-has-leading-visual={slots.leadingVisual ? '' : undefined}
174-
sx={sx}
175172
className={clsx(className, classes.ControlHorizontalLayout)}
176173
>
177174
{InputChildren}
178-
</BoxWithFallback>
175+
</div>
179176
) : (
180-
<BoxWithFallback
177+
<div
181178
ref={ref}
182179
data-has-label={!isLabelHidden ? '' : undefined}
183-
sx={sx}
184180
className={clsx(className, classes.ControlVerticalLayout)}
185181
>
186182
{slots.label}
@@ -207,7 +203,7 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
207203
<ValidationAnimationContainer show>{slots.validation}</ValidationAnimationContainer>
208204
) : null}
209205
{slots.caption}
210-
</BoxWithFallback>
206+
</div>
211207
)}
212208
</FormControlContextProvider>
213209
)

packages/react/src/FormControl/FormControlCaption.tsx

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

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

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

1915
return (
20-
<BoxWithFallback
21-
as={Text}
16+
<Text
2217
id={id ?? captionId}
2318
className={clsx(className, classes.Caption)}
2419
data-control-disabled={disabled ? '' : undefined}
25-
sx={sx}
2620
>
2721
{children}
28-
</BoxWithFallback>
22+
</Text>
2923
)
3024
}
3125

packages/react/src/FormControl/FormControlLabel.tsx

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

@@ -12,11 +11,11 @@ export type Props = {
1211
requiredIndicator?: boolean
1312
id?: string
1413
className?: string
15-
} & SxProp
14+
}
1615

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

2221
/**
@@ -33,7 +32,6 @@ const FormControlLabel: React.FC<
3332
requiredText,
3433
requiredIndicator,
3534
disabled,
36-
sx,
3735
...props,
3836
}
3937
: {
@@ -46,7 +44,6 @@ const FormControlLabel: React.FC<
4644
requiredText,
4745
requiredIndicator,
4846
disabled,
49-
sx,
5047
...props,
5148
}
5249

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.LeadingVisual {
2+
--leadingVisual-size: 16px;
3+
4+
color: var(--fgColor-default);
5+
display: flex;
6+
align-items: center;
7+
8+
&:where([data-control-disabled]) {
9+
color: var(--control-fgColor-disabled);
10+
}
11+
12+
& > * {
13+
min-width: var(--leadingVisual-size);
14+
min-height: var(--leadingVisual-size);
15+
fill: currentColor;
16+
}
17+
18+
&:where([data-has-caption]) {
19+
--leadingVisual-size: 24px;
20+
}
21+
}
Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,18 @@
11
import type React from 'react'
2-
import {get} from '../constants'
3-
import type {SxProp} from '../sx'
42
import {useFormControlContext} from './_FormControlContext'
5-
import styled from 'styled-components'
6-
import sx from '../sx'
3+
import classes from './FormControlLeadingVisual.module.css'
74

8-
const FormControlLeadingVisual: React.FC<React.PropsWithChildren<SxProp>> = ({children, sx}) => {
5+
const FormControlLeadingVisual: React.FC<React.PropsWithChildren> = ({children}) => {
96
const {disabled, captionId} = useFormControlContext()
107
return (
11-
<StyledLeadingVisual
8+
<div
9+
className={classes.LeadingVisual}
1210
data-control-disabled={disabled ? '' : undefined}
1311
data-has-caption={captionId ? '' : undefined}
14-
sx={sx}
1512
>
1613
{children}
17-
</StyledLeadingVisual>
14+
</div>
1815
)
1916
}
2017

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-
4618
export default FormControlLeadingVisual
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ exports[`@primer/react > should not update exports without a semver change 1`] =
7373
"type FocusTrapHookSettings",
7474
"type FocusZoneHookSettings",
7575
"FormControl",
76+
"type FormControlCaptionProps",
77+
"type FormControlLabelProps",
78+
"type FormControlProps",
79+
"type FormControlValidationProps",
7680
"Header",
7781
"type HeaderItemProps",
7882
"type HeaderLinkProps",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@
5656
max-height: 0;
5757
overflow: hidden;
5858
}
59+
60+
.FormControl {
61+
margin-bottom: var(--base-size-8);
62+
}

0 commit comments

Comments
 (0)