@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
111 lines (110 loc) • 4.37 kB
TypeScript
/**
* Web Checkbox Component
*/
import React from 'react';
import type { SpacingProps } from '../space/types';
import type { FormStatusProps, FormStatusState, FormStatusText } from '../FormStatus';
import type { SkeletonShow } from '../Skeleton';
import type { GlobalStatusConfigObject } from '../GlobalStatus';
export type CheckboxLabelPosition = 'left' | 'right';
export type CheckboxSize = 'default' | 'medium' | 'large';
export type CheckboxAttributes = string | Record<string, unknown>;
export type OnChangeParams = {
checked: boolean;
event: React.ChangeEvent<HTMLInputElement>;
};
export type OnClickParams = React.MouseEvent<HTMLInputElement> & {
checked: boolean;
event: React.MouseEvent<HTMLInputElement>;
};
export type CheckboxProps = {
/**
* Use either the `label` property or provide a custom one.
*/
label?: React.ReactNode;
/**
* Defines the position of the `label`. Use either `left` or `right`. Defaults to `right`.
*/
labelPosition?: CheckboxLabelPosition;
/**
* Use `true` to make the label only readable by screen readers.
*/
labelSrOnly?: boolean;
/**
* The `title` of the input - describing it a bit further for accessibility reasons.
*/
title?: string;
/**
* Determine whether the checkbox is checked or not. The default is `false`.
*/
checked?: boolean | undefined | null;
/**
* Determine whether to show the indeterminate checked state when checked. The default is `false`.
*/
indeterminate?: boolean;
/**
* The size of the checkbox. For now there is "medium" (default) and "large".
*/
size?: CheckboxSize;
/**
* Text with a status message. The style defaults to an error message. You can use `true` to only get the status color, without a message.
*/
status?: FormStatusText;
/**
* Defines the state of the status. Currently, there are two statuses `[error, info]`. Defaults to `error`.
*/
statusState?: FormStatusState;
/**
* Use an object to define additional FormStatus properties. See [FormStatus](/uilib/components/form-status/properties/)
*/
statusProps?: FormStatusProps;
statusNoAnimation?: boolean;
/**
* The [configuration](/uilib/components/global-status/properties/#configuration-object) used for the target [GlobalStatus](/uilib/components/global-status)
*/
globalStatus?: GlobalStatusConfigObject;
/**
* Text describing the content of the Checkbox more than the label. You can also send in a React component, so it gets wrapped inside the Checkbox component.
*/
suffix?: React.ReactNode;
value?: string;
element?: React.ElementType;
attributes?: CheckboxAttributes;
/**
* If set to `true`, an overlaying skeleton with animation will be shown.
*/
skeleton?: SkeletonShow;
/**
* Will be called on state changes made by the user. Returns an boolean `{ checked, event }`.
*/
onChange?: (args: OnChangeParams) => void;
/**
* Will be called on click made by the user. Returns the ClickEvent.
*/
onClick?: (args: OnClickParams) => void;
/**
* By providing a React.ref we can get the internally used input element (DOM). E.g. `innerRef={myRef}` by using `React.createRef()` or `React.useRef()`.
*/
innerRef?: React.MutableRefObject<HTMLInputElement> | ((elem: HTMLInputElement) => void);
} & SpacingProps & Omit<React.HTMLProps<HTMLInputElement>, 'ref' | 'label' | 'size' | 'onChange' | 'onClick'> & DeprecatedCheckboxProps;
type DeprecatedCheckboxProps = {
/** @deprecated use the `label` prop instead */
children?: React.ReactNode;
/** @deprecated use `onChange` */
on_change?: (args: OnChangeParams) => void;
/** @deprecated use `labelPosition` */
label_position?: CheckboxLabelPosition;
/** @deprecated use `labelSrOnly` */
label_sr_only?: boolean;
/** @deprecated use `statusState` */
status_state?: FormStatusState;
/** @deprecated use `statusProps` */
status_props?: FormStatusProps;
/** @deprecated use `statusNoAnimation` */
status_no_animation?: boolean;
};
declare function Checkbox(localProps: CheckboxProps): import("react/jsx-runtime").JSX.Element;
declare namespace Checkbox {
var _formElement: boolean;
}
export default Checkbox;