1
- import styled from 'styled-components'
2
1
import type { ChangeEventHandler , InputHTMLAttributes , ReactElement } from 'react'
3
2
import React , { useContext } from 'react'
4
3
import type { SxProp } from '../sx'
5
- import sx from '../sx'
6
4
import type { FormValidationStatus } from '../utils/types/FormValidationStatus'
7
5
import { RadioGroupContext } from '../RadioGroup/RadioGroup'
8
- import getGlobalFocusStyles from '../internal/utils/getGlobalFocusStyles'
9
- import { get } from '../constants'
10
- import { sharedCheckboxAndRadioStyles } from '../internal/utils/sharedCheckboxAndRadioStyles'
11
- import { toggleStyledComponent } from '../internal/utils/toggleStyledComponent'
12
- import { useFeatureFlag } from '../FeatureFlags'
13
6
import { clsx } from 'clsx'
14
7
import classes from './Radio.module.css'
15
8
import sharedClasses from '../Checkbox/shared.module.css'
9
+ import { defaultSxProp } from '../utils/defaultSxProp'
10
+ import Box from '../Box'
16
11
17
12
export type RadioProps = {
18
13
/**
@@ -47,42 +42,6 @@ export type RadioProps = {
47
42
} & InputHTMLAttributes < HTMLInputElement > &
48
43
SxProp
49
44
50
- const StyledRadio = toggleStyledComponent (
51
- 'primer_react_css_modules_ga' ,
52
- 'input' ,
53
- styled . input `
54
- ${ sharedCheckboxAndRadioStyles } ;
55
- border-radius: var(--borderRadius-full, 100vh);
56
- transition:
57
- background-color,
58
- border-color 80ms cubic-bezier(0.33, 1, 0.68, 1); /* checked -> unchecked - add 120ms delay to fully see animation-out */
59
-
60
- &:checked {
61
- border-width: var(--base-size-4, 4px);
62
- border-color: var(
63
- --control-checked-bgColor-rest,
64
- ${ get ( 'colors.accent.fg' ) }
65
- ); /* using bgColor here to avoid a border change in dark high contrast */
66
- background-color: var(--control-checked-fgColor-rest, ${ get ( 'colors.fg.onEmphasis' ) } );
67
-
68
- &:disabled {
69
- cursor: not-allowed;
70
- border-color: ${ get ( 'colors.fg.muted' ) } ;
71
- background-color: ${ get ( 'colors.fg.muted' ) } ;
72
- }
73
- }
74
-
75
- ${ getGlobalFocusStyles ( ) } ;
76
-
77
- @media (forced-colors: active) {
78
- background-color: canvastext;
79
- border-color: canvastext;
80
- }
81
-
82
- ${ sx }
83
- ` ,
84
- )
85
-
86
45
/**
87
46
* An accessible, native radio component for selecting one option from a list.
88
47
*/
@@ -93,7 +52,7 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
93
52
disabled,
94
53
name : nameProp ,
95
54
onChange,
96
- sx : sxProp ,
55
+ sx : sxProp = defaultSxProp ,
97
56
required,
98
57
validationStatus,
99
58
value,
@@ -103,7 +62,6 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
103
62
ref ,
104
63
) : ReactElement => {
105
64
const radioGroupContext = useContext ( RadioGroupContext )
106
- const enabled = useFeatureFlag ( 'primer_react_css_modules_ga' )
107
65
const handleOnChange : ChangeEventHandler < HTMLInputElement > = e => {
108
66
radioGroupContext ?. onChange && radioGroupContext . onChange ( e )
109
67
onChange && onChange ( e )
@@ -117,8 +75,32 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
117
75
)
118
76
}
119
77
78
+ if ( sxProp !== defaultSxProp ) {
79
+ return (
80
+ // eslint-disable-next-line github/a11y-role-supports-aria-props
81
+ < Box
82
+ as = "input"
83
+ sx = { sxProp }
84
+ type = "radio"
85
+ value = { value }
86
+ name = { name }
87
+ ref = { ref }
88
+ disabled = { disabled }
89
+ checked = { checked }
90
+ aria-checked = { checked ? 'true' : 'false' }
91
+ required = { required }
92
+ aria-required = { required ? 'true' : 'false' }
93
+ aria-invalid = { validationStatus === 'error' ? 'true' : 'false' }
94
+ onChange = { handleOnChange }
95
+ className = { clsx ( className , sharedClasses . Input , classes . Radio ) }
96
+ { ...rest }
97
+ />
98
+ )
99
+ }
100
+
120
101
return (
121
- < StyledRadio
102
+ // eslint-disable-next-line github/a11y-role-supports-aria-props
103
+ < input
122
104
type = "radio"
123
105
value = { value }
124
106
name = { name }
@@ -129,12 +111,8 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
129
111
required = { required }
130
112
aria-required = { required ? 'true' : 'false' }
131
113
aria-invalid = { validationStatus === 'error' ? 'true' : 'false' }
132
- sx = { sxProp }
133
114
onChange = { handleOnChange }
134
- className = { clsx ( className , {
135
- [ sharedClasses . Input ] : enabled ,
136
- [ classes . Radio ] : enabled ,
137
- } ) }
115
+ className = { clsx ( className , sharedClasses . Input , classes . Radio ) }
138
116
{ ...rest }
139
117
/>
140
118
)
0 commit comments