Skip to content

Commit 513cc3f

Browse files
authored
Remove support for sx from Checkbox component (#6654)
1 parent 077befc commit 513cc3f

File tree

5 files changed

+18
-36
lines changed

5 files changed

+18
-36
lines changed

.changeset/tasty-cheetahs-pay.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 Checkbox component to no longer support sx

packages/react/src/Checkbox/Checkbox.docs.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,7 @@
7272
"name": "as",
7373
"type": "React.ElementType",
7474
"defaultValue": "\"input\""
75-
},
76-
{
77-
"name": "sx",
78-
"type": "SystemStyleObject",
79-
"deprecated": true
8075
}
8176
],
8277
"subcomponents": []
83-
}
78+
}

packages/react/src/Checkbox/Checkbox.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import FormControl from '../FormControl'
55
import type {FormControlArgs} from '../utils/form-story-helpers'
66
import {formControlArgTypesWithoutValidation, getFormControlArgsByChildComponent} from '../utils/form-story-helpers'
77

8-
const excludedControlKeys = ['required', 'value', 'validationStatus', 'sx']
8+
const excludedControlKeys = ['required', 'value', 'validationStatus']
99

1010
export default {
1111
title: 'Components/Checkbox',

packages/react/src/Checkbox/Checkbox.tsx

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import {clsx} from 'clsx'
22
import {useProvidedRefOrCreate} from '../hooks'
33
import React, {useContext, useEffect, type ChangeEventHandler, type InputHTMLAttributes, type ReactElement} from 'react'
4-
import {type SxProp} from '../sx'
54
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect'
65
import type {FormValidationStatus} from '../utils/types/FormValidationStatus'
76
import {CheckboxGroupContext} from '../CheckboxGroup/CheckboxGroupContext'
87
import classes from './Checkbox.module.css'
98
import sharedClasses from './shared.module.css'
10-
import Box from '../Box'
119

1210
export type CheckboxProps = {
1311
/**
@@ -35,27 +33,14 @@ export type CheckboxProps = {
3533
* Used during form submission and to identify which checkbox inputs are selected
3634
*/
3735
value?: string
38-
} & Exclude<InputHTMLAttributes<HTMLInputElement>, 'value'> &
39-
SxProp
36+
} & Exclude<InputHTMLAttributes<HTMLInputElement>, 'value'>
4037

4138
/**
4239
* An accessible, native checkbox component
4340
*/
4441
const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
4542
(
46-
{
47-
checked,
48-
className,
49-
defaultChecked,
50-
indeterminate,
51-
disabled,
52-
onChange,
53-
sx: sxProp,
54-
required,
55-
validationStatus,
56-
value,
57-
...rest
58-
},
43+
{checked, className, defaultChecked, indeterminate, disabled, onChange, required, validationStatus, value, ...rest},
5944
ref,
6045
): ReactElement => {
6146
const checkboxRef = useProvidedRefOrCreate(ref as React.RefObject<HTMLInputElement>)
@@ -99,16 +84,6 @@ const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
9984
}
10085
})
10186

102-
if (sxProp) {
103-
return (
104-
<Box
105-
as="input"
106-
{...inputProps}
107-
className={clsx(className, sharedClasses.Input, classes.Checkbox)}
108-
sx={sxProp}
109-
/>
110-
)
111-
}
11287
return <input {...inputProps} className={clsx(className, sharedClasses.Input, classes.Checkbox)} />
11388
},
11489
)

packages/styled-react/src/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
Box,
44
type BoxProps,
55
type SxProp,
6+
Checkbox as PrimerCheckbox,
7+
type CheckboxProps as PrimerCheckboxProps,
68
StateLabel as PrimerStateLabel,
79
type StateLabelProps as PrimerStateLabelProps,
810
SubNav as PrimerSubNav,
@@ -62,6 +64,12 @@ const SegmentedControl = Object.assign(SegmentedControlImpl, {
6264
IconButton: SegmentedControlIconButton,
6365
})
6466

67+
type CheckboxProps = PrimerCheckboxProps & SxProp
68+
69+
const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(function Checkbox(props, ref) {
70+
return <Box as={PrimerCheckbox} ref={ref} {...props} />
71+
})
72+
6573
type StateLabelProps = PrimerStateLabelProps & SxProp
6674

6775
const StateLabel = forwardRef<HTMLSpanElement, StateLabelProps>(function StateLabel(props, ref) {
@@ -90,7 +98,7 @@ const ToggleSwitch = forwardRef<HTMLButtonElement, ToggleSwitchProps>(function T
9098
return <Box as={PrimerToggleSwitch} ref={ref} {...props} />
9199
})
92100

93-
export {SegmentedControl, StateLabel, SubNav, ToggleSwitch}
101+
export {Checkbox, SegmentedControl, StateLabel, SubNav, ToggleSwitch}
94102

95103
export {
96104
ActionList,
@@ -99,7 +107,6 @@ export {
99107
Avatar,
100108
Breadcrumbs,
101109
Button,
102-
Checkbox,
103110
CheckboxGroup,
104111
CircleBadge,
105112
CounterLabel,

0 commit comments

Comments
 (0)