Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/add-disabled-prop-to-field-templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baseplate-dev/react-generators': patch
---

Add disabled prop to form field component templates with consistent data-disabled attribute on Field wrapper
5 changes: 5 additions & 0 deletions .changeset/add-disabled-prop-to-fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baseplate-dev/ui-components': patch
---

Add disabled prop to FormFieldProps and all form field components with consistent data-disabled attribute on Field wrapper for label dimming
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function CheckboxField({
label,
description,
error,
disabled,
onChange,
value,
className,
Expand All @@ -47,11 +48,13 @@ function CheckboxField({
<Field
orientation="horizontal"
data-invalid={!!error || undefined}
data-disabled={disabled ?? undefined}
className={className}
>
<Checkbox
{...props}
id={id}
disabled={disabled}
aria-invalid={!!error}
onCheckedChange={(checked) => {
onChange?.(checked);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export interface ComboboxFieldProps<OptionType>
className?: string;
noResultsText?: React.ReactNode;
placeholder?: string;
disabled?: boolean;
value?: string | null;
onChange?: (value: string | null) => void;
inputValue?: string;
Expand Down Expand Up @@ -62,7 +61,11 @@ function ComboboxField<OptionType>({
options.find((o) => getOptionValue(o) === value) ?? null;

return (
<Field data-invalid={!!error} className={className}>
<Field
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={className}
>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
<Combobox
value={selectedOption}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Popover, PopoverContent, PopoverTrigger } from './popover';
export interface DatePickerFieldProps extends FormFieldProps {
className?: string;
wrapperClassName?: string;
disabled?: boolean;
placeholder?: string;
onChange?: (value: string | undefined) => void;
value?: string | undefined;
Expand Down Expand Up @@ -100,7 +99,11 @@ function DatePickerField({

if (addWrapper) {
return (
<Field data-invalid={!!error} className={cn('gap-2', wrapperClassName)}>
<Field
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={cn('gap-2', wrapperClassName)}
>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
{inputComponent}
<FieldDescription>{description}</FieldDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { Popover, PopoverContent, PopoverTrigger } from './popover';
export interface DateTimePickerFieldProps extends FormFieldProps {
className?: string;
wrapperClassName?: string;
disabled?: boolean;
placeholder?: string;
onChange?: (value: string | undefined) => void;
value?: string | undefined;
Expand Down Expand Up @@ -177,7 +176,11 @@ function DateTimePickerField({

if (addWrapper) {
return (
<Field data-invalid={!!error} className={cn('gap-2', wrapperClassName)}>
<Field
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={cn('gap-2', wrapperClassName)}
>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
{inputComponent}
<FieldDescription>{description}</FieldDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function InputField({
label,
description,
error,
disabled,
onChange,
register,
className,
Expand All @@ -45,10 +46,15 @@ function InputField({
}: InputFieldProps): React.ReactElement {
const id = useId();
return (
<Field data-invalid={!!error} className={cn('gap-1.5', className)}>
<Field
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={cn('gap-1.5', className)}
>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
<Input
id={id}
disabled={disabled}
onChange={
onChange &&
((e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export interface MultiComboboxFieldProps<OptionType>
extends MultiSelectOptionProps<OptionType>, FormFieldProps {
className?: string;
noResultsText?: React.ReactNode;
disabled?: boolean;
}

/**
Expand Down Expand Up @@ -62,7 +61,11 @@ function MultiComboboxField<OptionType>({
);

return (
<Field data-invalid={!!error} className={className}>
<Field
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={className}
>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
<Combobox
multiple
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function SelectField<OptionType>({
label,
description,
error,
disabled,
value,
placeholder,
options,
Expand All @@ -47,9 +48,18 @@ function SelectField<OptionType>({
const selectedOption = options.find((o) => getOptionValue(o) === value);

return (
<Field data-invalid={!!error} className={className}>
<Field
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={className}
>
<FieldLabel htmlFor={triggerId}>{label}</FieldLabel>
<Select value={value} onValueChange={(val) => onChange?.(val)} {...props}>
<Select
value={value}
onValueChange={(val) => onChange?.(val)}
disabled={disabled}
{...props}
>
<SelectTrigger id={triggerId} aria-invalid={!!error}>
<SelectValue placeholder={placeholder}>
{selectedOption ? getOptionLabel(selectedOption) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function SwitchField({
label,
description,
error,
disabled,
onChange,
value,
className,
Expand All @@ -49,12 +50,14 @@ function SwitchField({
<Field
orientation="horizontal"
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={className}
id={id}
>
<Switch
{...props}
id={switchId}
disabled={disabled}
onCheckedChange={(checked) => onChange?.(checked)}
checked={value}
aria-invalid={!!error}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,21 @@ function TextareaField({
label,
description,
error,
disabled,
onChange,
register,
...props
}: TextareaFieldProps): React.ReactElement {
const id = useId();
return (
<Field data-invalid={!!error || undefined}>
<Field
data-invalid={!!error || undefined}
data-disabled={disabled ?? undefined}
>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
<Textarea
id={id}
disabled={disabled}
onChange={
onChange &&
((e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface FormFieldProps {
label?: React.ReactNode;
error?: React.ReactNode;
description?: React.ReactNode;
disabled?: boolean;
}

type SelectOptionLabelRenderer<OptionType> = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function CheckboxField({
label,
description,
error,
disabled,
onChange,
value,
className,
Expand All @@ -47,11 +48,13 @@ function CheckboxField({
<Field
orientation="horizontal"
data-invalid={!!error || undefined}
data-disabled={disabled ?? undefined}
className={className}
>
<Checkbox
{...props}
id={id}
disabled={disabled}
aria-invalid={!!error}
onCheckedChange={(checked) => {
onChange?.(checked);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export interface ComboboxFieldProps<OptionType>
className?: string;
noResultsText?: React.ReactNode;
placeholder?: string;
disabled?: boolean;
value?: string | null;
onChange?: (value: string | null) => void;
inputValue?: string;
Expand Down Expand Up @@ -62,7 +61,11 @@ function ComboboxField<OptionType>({
options.find((o) => getOptionValue(o) === value) ?? null;

return (
<Field data-invalid={!!error} className={className}>
<Field
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={className}
>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
<Combobox
value={selectedOption}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Popover, PopoverContent, PopoverTrigger } from './popover';
export interface DatePickerFieldProps extends FormFieldProps {
className?: string;
wrapperClassName?: string;
disabled?: boolean;
placeholder?: string;
onChange?: (value: string | undefined) => void;
value?: string | undefined;
Expand Down Expand Up @@ -100,7 +99,11 @@ function DatePickerField({

if (addWrapper) {
return (
<Field data-invalid={!!error} className={cn('gap-2', wrapperClassName)}>
<Field
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={cn('gap-2', wrapperClassName)}
>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
{inputComponent}
<FieldDescription>{description}</FieldDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { Popover, PopoverContent, PopoverTrigger } from './popover';
export interface DateTimePickerFieldProps extends FormFieldProps {
className?: string;
wrapperClassName?: string;
disabled?: boolean;
placeholder?: string;
onChange?: (value: string | undefined) => void;
value?: string | undefined;
Expand Down Expand Up @@ -177,7 +176,11 @@ function DateTimePickerField({

if (addWrapper) {
return (
<Field data-invalid={!!error} className={cn('gap-2', wrapperClassName)}>
<Field
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={cn('gap-2', wrapperClassName)}
>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
{inputComponent}
<FieldDescription>{description}</FieldDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function InputField({
label,
description,
error,
disabled,
onChange,
register,
className,
Expand All @@ -45,10 +46,15 @@ function InputField({
}: InputFieldProps): React.ReactElement {
const id = useId();
return (
<Field data-invalid={!!error} className={cn('gap-1.5', className)}>
<Field
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={cn('gap-1.5', className)}
>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
<Input
id={id}
disabled={disabled}
onChange={
onChange &&
((e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export interface MultiComboboxFieldProps<OptionType>
extends MultiSelectOptionProps<OptionType>, FormFieldProps {
className?: string;
noResultsText?: React.ReactNode;
disabled?: boolean;
}

/**
Expand Down Expand Up @@ -62,7 +61,11 @@ function MultiComboboxField<OptionType>({
);

return (
<Field data-invalid={!!error} className={className}>
<Field
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={className}
>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
<Combobox
multiple
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function SelectField<OptionType>({
label,
description,
error,
disabled,
value,
placeholder,
options,
Expand All @@ -47,9 +48,18 @@ function SelectField<OptionType>({
const selectedOption = options.find((o) => getOptionValue(o) === value);

return (
<Field data-invalid={!!error} className={className}>
<Field
data-invalid={!!error}
data-disabled={disabled ?? undefined}
className={className}
>
<FieldLabel htmlFor={triggerId}>{label}</FieldLabel>
<Select value={value} onValueChange={(val) => onChange?.(val)} {...props}>
<Select
value={value}
onValueChange={(val) => onChange?.(val)}
disabled={disabled}
{...props}
>
<SelectTrigger id={triggerId} aria-invalid={!!error}>
<SelectValue placeholder={placeholder}>
{selectedOption ? getOptionLabel(selectedOption) : null}
Expand Down
Loading
Loading