Skip to content

Commit 09ee0ea

Browse files
chore: add styles to FormControl and subcomponents (#6937)
1 parent aa033b4 commit 09ee0ea

File tree

7 files changed

+37
-6
lines changed

7 files changed

+37
-6
lines changed

.changeset/sweet-owls-do.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
chore: add styles to formcontrol and subcomponents

packages/react/src/FormControl/FormControl.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ export type FormControlProps = {
4242
*/
4343
layout?: 'horizontal' | 'vertical'
4444
className?: string
45+
style?: React.CSSProperties
4546
} & SxProp
4647

4748
const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
48-
({children, disabled: disabledProp, layout = 'vertical', id: idProp, required, sx, className}, ref) => {
49+
({children, disabled: disabledProp, layout = 'vertical', id: idProp, required, sx, className, style}, ref) => {
4950
const [slots, childrenWithoutSlots] = useSlots(children, {
5051
caption: FormControlCaption,
5152
label: FormControlLabel,
@@ -173,6 +174,7 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
173174
data-has-leading-visual={slots.leadingVisual ? '' : undefined}
174175
sx={sx}
175176
className={clsx(className, classes.ControlHorizontalLayout)}
177+
style={style}
176178
>
177179
{InputChildren}
178180
</BoxWithFallback>
@@ -182,6 +184,7 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
182184
data-has-label={!isLabelHidden ? '' : undefined}
183185
sx={sx}
184186
className={clsx(className, classes.ControlVerticalLayout)}
187+
style={style}
185188
>
186189
{slots.label}
187190
{React.isValidElement(InputComponent) &&

packages/react/src/FormControl/FormControlCaption.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ type FormControlCaptionProps = React.PropsWithChildren<
1010
{
1111
id?: string
1212
className?: string
13+
style?: React.CSSProperties
1314
} & SxProp
1415
>
1516

16-
function FormControlCaption({id, children, sx, className}: FormControlCaptionProps) {
17+
function FormControlCaption({id, children, sx, className, style}: FormControlCaptionProps) {
1718
const {captionId, disabled} = useFormControlContext()
1819

1920
return (
@@ -23,6 +24,7 @@ function FormControlCaption({id, children, sx, className}: FormControlCaptionPro
2324
className={clsx(className, classes.Caption)}
2425
data-control-disabled={disabled ? '' : undefined}
2526
sx={sx}
27+
style={style}
2628
>
2729
{children}
2830
</BoxWithFallback>

packages/react/src/FormControl/FormControlLabel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type Props = {
1212
requiredIndicator?: boolean
1313
id?: string
1414
className?: string
15+
style?: React.CSSProperties
1516
} & SxProp
1617

1718
const FormControlLabel: React.FC<

packages/react/src/FormControl/FormControlLeadingVisual.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ import {useFormControlContext} from './_FormControlContext'
55
import styled from 'styled-components'
66
import sx from '../sx'
77

8-
const FormControlLeadingVisual: React.FC<React.PropsWithChildren<SxProp>> = ({children, sx}) => {
8+
const FormControlLeadingVisual: React.FC<React.PropsWithChildren<SxProp & {style?: React.CSSProperties}>> = ({
9+
children,
10+
sx,
11+
style,
12+
}) => {
913
const {disabled, captionId} = useFormControlContext()
1014
return (
1115
<StyledLeadingVisual
1216
data-control-disabled={disabled ? '' : undefined}
17+
style={style}
1318
data-has-caption={captionId ? '' : undefined}
1419
sx={sx}
1520
>

packages/react/src/FormControl/_FormControlValidation.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type FormControlValidationProps = {
88
variant: FormValidationStatus
99
id?: string
1010
className?: string
11+
style?: React.CSSProperties
1112
} & SxProp
1213

1314
const FormControlValidation: React.FC<React.PropsWithChildren<FormControlValidationProps>> = ({
@@ -16,10 +17,17 @@ const FormControlValidation: React.FC<React.PropsWithChildren<FormControlValidat
1617
variant,
1718
sx,
1819
id,
20+
style,
1921
}) => {
2022
const {validationMessageId} = useFormControlContext()
2123
return (
22-
<InputValidation className={className} validationStatus={variant} id={id || validationMessageId || ''} sx={sx}>
24+
<InputValidation
25+
className={className}
26+
validationStatus={variant}
27+
id={id || validationMessageId || ''}
28+
sx={sx}
29+
style={style}
30+
>
2331
{children}
2432
</InputValidation>
2533
)

packages/react/src/internal/components/InputValidation.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Props = {
1111
className?: string
1212
id: string
1313
validationStatus?: FormValidationStatus
14+
style?: React.CSSProperties
1415
} & SxProp
1516

1617
const validationIconMap: Record<
@@ -21,7 +22,13 @@ const validationIconMap: Record<
2122
error: AlertFillIcon,
2223
}
2324

24-
const InputValidation: React.FC<React.PropsWithChildren<Props>> = ({children, className, id, validationStatus}) => {
25+
const InputValidation: React.FC<React.PropsWithChildren<Props>> = ({
26+
children,
27+
className,
28+
id,
29+
validationStatus,
30+
style,
31+
}) => {
2532
const IconComponent = validationStatus ? validationIconMap[validationStatus] : undefined
2633

2734
// TODO: use `text-caption-lineHeight` token as a custom property when it's available
@@ -31,7 +38,7 @@ const InputValidation: React.FC<React.PropsWithChildren<Props>> = ({children, cl
3138
const iconBoxMinHeight = iconSize * captionLineHeight
3239

3340
return (
34-
<Text className={clsx(className, classes.InputValidation)} data-validation-status={validationStatus}>
41+
<Text className={clsx(className, classes.InputValidation)} data-validation-status={validationStatus} style={style}>
3542
{IconComponent ? (
3643
<span
3744
aria-hidden="true"

0 commit comments

Comments
 (0)