Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
aresnik11 committed Sep 12, 2024
1 parent 0d49df6 commit 445f990
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const ConnectedCheckbox: React.FC<ConnectedCheckboxProps> = ({
disabled,
id,
label,
'aria-label': ariaLabel,
multiline,
name,
onUpdate,
Expand Down Expand Up @@ -38,6 +39,7 @@ export const ConnectedCheckbox: React.FC<ConnectedCheckboxProps> = ({
}}
onBlur={onBlur}
label={label}
aria-label={ariaLabel}
multiline={multiline}
id={id}
aria-required={isRequired}
Expand Down
27 changes: 20 additions & 7 deletions packages/gamut/src/ConnectedForm/ConnectedInputs/types.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { ReactNode } from 'react';
import { ComponentProps, ReactNode } from 'react';

import {
Checkbox,
CheckboxLabelProps,
CheckboxProps,
CheckboxReactNodeLabelProps,
CheckboxStringLabelProps,
InputWrapperProps,
RadioGroupProps,
RadioProps,
SelectProps,
TextAreaProps,
VanillaCheckboxProps,
} from '../../Form';
import { DistributiveOmit } from '../utility';

export interface BaseConnectedFieldProps {
onUpdate?: (value: boolean) => void;
Expand All @@ -16,13 +22,20 @@ export interface BaseConnectedFieldProps {
export interface ConnectedFieldProps extends BaseConnectedFieldProps {
name: string;
}
// export type ConnectedCheckboxProps = DistributiveOmit<
// ComponentProps<typeof Checkbox>,
// 'name'
// >;
// ConnectedFieldProps;

export interface ConnectedCheckboxProps
extends Omit<
CheckboxProps,
'defaultValue' | 'name' | 'htmlFor' | 'validation'
>,
ConnectedFieldProps {}
type NewVanillaCheckboxProps = Omit<
VanillaCheckboxProps,
'defaultValue' | 'name' | 'htmlFor' | 'validation' | 'label' | 'aria-label'
> &
ConnectedFieldProps;

export type ConnectedCheckboxProps = NewVanillaCheckboxProps &
(CheckboxReactNodeLabelProps | CheckboxStringLabelProps);

type FieldComponent<T> = Omit<T, 'defaultValue' | 'name' | 'validation'>;

Expand Down
3 changes: 3 additions & 0 deletions packages/gamut/src/ConnectedForm/utility.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type DistributiveOmit<T, K extends keyof Entity> = T extends Entity
? Omit<T, K>
: never;
24 changes: 20 additions & 4 deletions packages/gamut/src/Form/inputs/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,31 @@ import { BaseInputProps } from '../types';
export type CheckboxTextProps = StyleProps<typeof checkboxTextStates>;
export type CheckboxPaddingProps = StyleProps<typeof checkboxPadding>;

export type CheckboxProps = Omit<
export type CheckboxStringLabelProps = {
label: string;
'aria-label'?: string;
};

export type CheckboxReactNodeLabelProps = {
label: number;
'aria-label': string;
};

export type CheckboxLabelProps =
| CheckboxStringLabelProps
| CheckboxReactNodeLabelProps;

export type VanillaCheckboxProps = Omit<
InputHTMLAttributes<HTMLInputElement>,
'value'
'value' | 'label' | 'aria-label'
> &
CheckboxPaddingProps &
Pick<BaseInputProps, 'name' | 'required'> & {
/**
* If the label is a ReactNode, an aria-label must be added.
*/
label: ReactNode | string;
'aria-label'?: string;
// label: ReactNode | string;
// 'aria-label'?: string;
multiline?: boolean;
className?: string;
/**
Expand Down Expand Up @@ -71,6 +85,8 @@ export type CheckboxProps = Omit<
dontAriaHideLabel?: boolean;
};

export type CheckboxProps = VanillaCheckboxProps & CheckboxLabelProps;

const CheckboxLabel = styled.label<Pick<CheckboxProps, 'disabled' | 'spacing'>>(
noSelect,
checkboxLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const ConnectedFormPlayground: React.FC<ConnectedFormPlayground> = ({
label="checkbox field"
field={{
component: ConnectedCheckbox,
label: 'check it ouuut',
label: <div>check it ouuut</div>,
}}
{...connectedFormGroup}
/>
Expand Down

0 comments on commit 445f990

Please sign in to comment.