Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sweet-owls-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

chore: add styles to formcontrol and subcomponents
5 changes: 4 additions & 1 deletion packages/react/src/FormControl/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ export type FormControlProps = {
*/
layout?: 'horizontal' | 'vertical'
className?: string
style?: React.CSSProperties
}

const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
({children, disabled: disabledProp, layout = 'vertical', id: idProp, required, className}, ref) => {
({children, disabled: disabledProp, layout = 'vertical', id: idProp, required, className, style}, ref) => {
const [slots, childrenWithoutSlots] = useSlots(children, {
caption: FormControlCaption,
label: FormControlLabel,
Expand Down Expand Up @@ -170,6 +171,7 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
ref={ref}
data-has-leading-visual={slots.leadingVisual ? '' : undefined}
className={clsx(className, classes.ControlHorizontalLayout)}
style={style}
>
{InputChildren}
</div>
Expand All @@ -178,6 +180,7 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
ref={ref}
data-has-label={!isLabelHidden ? '' : undefined}
className={clsx(className, classes.ControlVerticalLayout)}
style={style}
>
{slots.label}
{React.isValidElement(InputComponent) &&
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/FormControl/FormControlCaption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import {useFormControlContext} from './_FormControlContext'
export type FormControlCaptionProps = React.PropsWithChildren<{
id?: string
className?: string
style?: React.CSSProperties
}>

function FormControlCaption({id, children, className}: FormControlCaptionProps) {
function FormControlCaption({id, children, className, style}: FormControlCaptionProps) {
const {captionId, disabled} = useFormControlContext()

return (
<Text
id={id ?? captionId}
className={clsx(className, classes.Caption)}
data-control-disabled={disabled ? '' : undefined}
style={style}
>
{children}
</Text>
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/FormControl/FormControlLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type Props = {
requiredIndicator?: boolean
id?: string
className?: string
style?: React.CSSProperties
Comment thread
francinelucca marked this conversation as resolved.
}

const FormControlLabel: React.FC<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import type React from 'react'
import {useFormControlContext} from './_FormControlContext'
import classes from './FormControlLeadingVisual.module.css'

const FormControlLeadingVisual: React.FC<React.PropsWithChildren> = ({children}) => {
const FormControlLeadingVisual: React.FC<React.PropsWithChildren & {style?: React.CSSProperties}> = ({
children,
style,
}) => {
const {disabled, captionId} = useFormControlContext()
return (
<div
className={classes.LeadingVisual}
data-control-disabled={disabled ? '' : undefined}
style={style}
data-has-caption={captionId ? '' : undefined}
>
{children}
Expand Down
10 changes: 9 additions & 1 deletion packages/react/src/FormControl/_FormControlValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type FormControlValidationProps = {
variant: FormValidationStatus
id?: string
className?: string
style?: React.CSSProperties
} & SxProp

const FormControlValidation: React.FC<React.PropsWithChildren<FormControlValidationProps>> = ({
Expand All @@ -16,10 +17,17 @@ const FormControlValidation: React.FC<React.PropsWithChildren<FormControlValidat
variant,
sx,
id,
style,
}) => {
const {validationMessageId} = useFormControlContext()
return (
<InputValidation className={className} validationStatus={variant} id={id || validationMessageId || ''} sx={sx}>
<InputValidation
className={className}
validationStatus={variant}
id={id || validationMessageId || ''}
sx={sx}
style={style}
>
{children}
</InputValidation>
)
Expand Down
11 changes: 9 additions & 2 deletions packages/react/src/internal/components/InputValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Props = {
className?: string
id: string
validationStatus?: FormValidationStatus
style?: React.CSSProperties
} & SxProp

const validationIconMap: Record<
Expand All @@ -21,7 +22,13 @@ const validationIconMap: Record<
error: AlertFillIcon,
}

const InputValidation: React.FC<React.PropsWithChildren<Props>> = ({children, className, id, validationStatus}) => {
const InputValidation: React.FC<React.PropsWithChildren<Props>> = ({
children,
className,
id,
validationStatus,
style,
}) => {
const IconComponent = validationStatus ? validationIconMap[validationStatus] : undefined

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

return (
<Text className={clsx(className, classes.InputValidation)} data-validation-status={validationStatus}>
<Text className={clsx(className, classes.InputValidation)} data-validation-status={validationStatus} style={style}>
{IconComponent ? (
<span
aria-hidden="true"
Expand Down
Loading