@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
111 lines (110 loc) • 4.34 kB
TypeScript
/**
* Web ToggleButton Component
*
* This is a legacy component.
* For referencing while developing new features, please use a Functional component.
*/
import React from 'react';
declare const _default: ToggleButtonComponent;
export default _default;
import type { ButtonIconPosition, ButtonSize, ButtonTooltip } from '../Button';
import type { FormStatusProps, FormStatusState, FormStatusText } from '../FormStatus';
import type { GlobalStatusConfigObject } from '../GlobalStatus';
import type { IconIcon, IconSize } from '../Icon';
import type { SkeletonShow } from '../Skeleton';
import type { SpacingProps, SpaceType } from '../space/types';
import type { ToggleButtonGroupProps } from './ToggleButtonGroup';
export type ToggleButtonVariant = 'default' | 'checkbox' | 'radio';
export type ToggleButtonSuffix = string | ((...args: any[]) => any) | React.ReactNode;
export type ToggleButtonValue = string | number | Record<string, unknown> | any[];
export type ToggleButtonAttributes = string | Record<string, unknown>;
export type ToggleButtonChildren = string | ((...args: any[]) => any);
export interface ToggleButtonProps extends Omit<React.HTMLProps<HTMLButtonElement>, 'ref' | 'label' | 'value'>, Omit<SpacingProps, 'top' | 'right' | 'bottom' | 'left'> {
/**
* The text shown in the ToggleButton.
*/
text?: React.ReactNode;
/**
* Use either the `label` property or provide a custom one.
*/
label?: string | React.ReactNode;
label_direction?: 'horizontal' | 'vertical';
label_sr_only?: boolean;
/**
* The `title` of the input - describing it a bit further for accessibility reasons.
*/
title?: string;
/**
* Determine whether the ToggleButton is checked or not. The default will be `false`.
*/
checked?: boolean;
variant?: ToggleButtonVariant;
left_component?: React.ReactNode;
disabled?: boolean;
/**
* If set to `true`, an overlaying skeleton with animation will be shown.
*/
skeleton?: SkeletonShow;
id?: string;
/**
* 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`.
*/
status_state?: FormStatusState;
/**
* Use an object to define additional FormStatus properties.
*/
status_props?: FormStatusProps;
status_no_animation?: 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 ToggleButton more than the label. You can also send in a React component, so it gets wrapped inside the ToggleButton component.
*/
suffix?: ToggleButtonSuffix;
/**
* Provide a string or a React Element to be shown as the tooltip content.
*/
tooltip?: ButtonTooltip;
/**
* Defines the `value` as a string. Use it to get the value during the `on_change` event listener callback in the **ToggleButtonGroup**.
*/
value?: ToggleButtonValue;
/**
* The size of the button. For now there is `small`, `medium`, `default` and `large`.
*/
size?: ButtonSize;
/**
* Icon to be included in the toggle button.
*/
icon?: IconIcon;
/**
* Position of the icon inside the toggle button. Set to `left` or `right`. Defaults to `right` if not set.
*/
icon_position?: ButtonIconPosition;
/**
* Define icon width and height. Defaults to `16px`.
*/
icon_size?: IconSize;
attributes?: ToggleButtonAttributes;
readOnly?: boolean;
className?: string;
children?: ToggleButtonChildren;
on_change?: (...args: any[]) => any;
on_state_update?: (...args: any[]) => any;
onChange?: (...args: any[]) => any;
top?: SpaceType;
right?: SpaceType;
bottom?: SpaceType;
left?: SpaceType;
}
export interface ToggleButtonComponent extends React.ComponentClass<ToggleButtonProps> {
Group: React.ComponentClass<ToggleButtonGroupProps>;
_formElement: boolean;
_supportsSpacingProps: boolean;
}