Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -1,49 +1,18 @@
import type { CheckboxPropsShared } from '@metamask/design-system-shared';
import type { PressableProps, ViewProps } from 'react-native';

import type { IconProps } from '../Icon';
import type { TextProps } from '../Text';

/**
* Checkbox component props.
*/

export type CheckboxProps = {
/**
* Required prop to determine whether the checkbox is currently selected.
* This component is fully controlled, so you must manage this state
* in your parent component.
*/
isSelected: boolean;

/**
* Optional prop that when true, disables the checkbox.
*
* @default false
*/
isDisabled?: boolean;

/**
* Optional prop that when true, displays the invalid/error state of the checkbox.
*
* @default false
*/
isInvalid?: boolean;

/**
* Optional label prop that renders text or a React node as a label beside the checkbox.
*/
label?: React.ReactNode | string;

export type CheckboxProps = CheckboxPropsShared & {
/**
* Optional props to be passed to the label's Text component.
*/
labelProps?: Omit<Partial<TextProps>, 'children'>;

/**
* Required callback for when the checked state changes.
* Use this to update your state.
*/
onChange: (isSelected: boolean) => void;

/**
* Optional props passed to the container view wrapping the checkbox icon.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CheckboxPropsShared } from '@metamask/design-system-shared';
import type { ComponentProps } from 'react';

import type { IconProps } from '../Icon';
Expand All @@ -6,79 +7,48 @@ import type { TextProps } from '../Text';
export type CheckboxProps = Omit<
ComponentProps<'label'>,
'style' | 'className' | 'children' | 'htmlFor'
> & {
/**
* Required unique identifier for the checkbox input element.
* This is used for the input's ID and the label's htmlFor attributes.
*/
id: string;

/**
* Required prop to determine whether the checkbox is currently selected.
* This component is fully controlled, so you must manage this state
* in your parent component.
*/
isSelected: boolean;

/**
* Optional prop that when true, disables the checkbox.
*
* @default false
*/
isDisabled?: boolean;

/**
* Optional prop that when true, displays the invalid/error state of the checkbox.
*
* @default false
*/
isInvalid?: boolean;

/**
* Optional label prop that renders text or a React node as a label beside the checkbox.
*/
label?: React.ReactNode | string;

/**
* Optional props to be passed to the label's Text component
*/
labelProps?: Omit<Partial<TextProps>, 'children'>;

/**
* Required callback for when the checked state changes.
* Use this to update your state.
*/
onChange: (isSelected: boolean) => void;

/**
* Optional props passed to the input element.
*/
inputProps?: Omit<
ComponentProps<'input'>,
'type' | 'checked' | 'onChange' | 'disabled'
> & {
[key: `data-${string}`]: string;
};

/**
* Optional props passed to the container div wrapping the checkbox icon.
*/
checkboxContainerProps?: (Omit<ComponentProps<'div'>, 'children'> & {
> &
CheckboxPropsShared & {
/**
* Required unique identifier for the checkbox input element.
* This is used for the input's ID and the label's htmlFor attributes.
*/
id: string;

/**
* Optional props to be passed to the label's Text component
*/
labelProps?: Omit<Partial<TextProps>, 'children'>;

/**
* Optional props passed to the input element.
*/
inputProps?: Omit<
ComponentProps<'input'>,
'type' | 'checked' | 'onChange' | 'disabled'
> & {
[key: `data-${string}`]: string;
};

/**
* Optional props passed to the container div wrapping the checkbox icon.
*/
checkboxContainerProps?: (Omit<ComponentProps<'div'>, 'children'> & {
className?: string;
}) &
Record<string, unknown>;

/**
* Optional props to be passed to the check Icon component
*/
checkedIconProps?: Partial<IconProps>;
/**
* Optional prop for additional CSS classes to be applied to the Checkbox component.
* These classes will be merged with the component's default classes using twMerge.
*/
className?: string;
}) &
Record<string, unknown>;

/**
* Optional props to be passed to the check Icon component
*/
checkedIconProps?: Partial<IconProps>;
/**
* Optional prop for additional CSS classes to be applied to the Checkbox component.
* These classes will be merged with the component's default classes using twMerge.
*/
className?: string;
/**
* Optional CSS styles for the outer container.
*/
style?: React.CSSProperties;
};
/**
* Optional CSS styles for the outer container.
*/
style?: React.CSSProperties;
};
3 changes: 3 additions & 0 deletions packages/design-system-shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ export {
type BadgeWrapperCustomPosition,
type BadgeWrapperPropsShared,
} from './types/BadgeWrapper';

// Checkbox types (ADR-0004)
export { type CheckboxPropsShared } from './types/Checkbox';
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { ReactNode } from 'react';

/**
* Checkbox component shared props (ADR-0004)
* Platform-independent properties shared across React and React Native.
*/
export type CheckboxPropsShared = {
/**
* Required prop to determine whether the checkbox is currently selected.
* This component is fully controlled, so you must manage this state
* in your parent component.
*/
isSelected: boolean;

/**
* Optional prop that when true, disables the checkbox.
*
* @default false
*/
isDisabled?: boolean;

/**
* Optional prop that when true, displays the invalid/error state of the checkbox.
*
* @default false
*/
isInvalid?: boolean;

/**
* Optional label prop that renders text or a React node as a label beside the checkbox.
*/
label?: ReactNode | string;

/**
* Required callback for when the checked state changes.
* Use this to update your state.
*/
onChange: (isSelected: boolean) => void;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { type CheckboxPropsShared } from './Checkbox.types';
Loading