-
Notifications
You must be signed in to change notification settings - Fork 4k
/
types.ts
145 lines (137 loc) · 3.37 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* External dependencies
*/
import type { ReactNode } from 'react';
/**
* Internal dependencies
*/
import type { BaseControlProps } from '../base-control/types';
import type { TooltipProps } from '../tooltip/types';
export type ToggleGroupControlOptionBaseProps = {
children: ReactNode;
/**
* Style the option as an icon option.
*
* @default false
*/
isIcon?: boolean;
value: string | number;
/**
* Whether to display a Tooltip for the control option. If set to `true`, the tooltip will
* show the aria-label or the label prop text.
*
* @default false
*/
showTooltip?: boolean;
};
export type ToggleGroupControlOptionIconProps = Pick<
ToggleGroupControlOptionBaseProps,
'value'
> & {
/**
* Icon displayed as the content of the option. Usually one of the icons from
* the `@wordpress/icons` package, or a custom React `<svg>` icon.
*/
icon: JSX.Element;
/**
* The text to accessibly label the icon option. Will also be shown in a tooltip.
*/
label: string;
};
export type ToggleGroupControlOptionProps = Pick<
ToggleGroupControlOptionBaseProps,
'value' | 'showTooltip'
> & {
/**
* Label for the option. If needed, the `aria-label` prop can be used in addition
* to specify a different label for assistive technologies.
*/
label: string;
};
export type WithToolTipProps = {
/**
* React children
*/
children: TooltipProps[ 'children' ];
/**
* Label for the Tooltip component.
*/
text?: string;
/**
* Whether to wrap the control option in a Tooltip component.
*
* @default false
*/
showTooltip?: boolean;
};
export type ToggleGroupControlProps = Pick<
BaseControlProps,
'help' | '__nextHasNoMarginBottom'
> & {
/**
* Label for the control.
*/
label: string;
/**
* If true, the label will only be visible to screen readers.
*
* @default false
*/
hideLabelFromVision?: boolean;
/**
* Determines if segments should be rendered with equal widths.
*
* @default false
*/
isAdaptiveWidth?: boolean;
/**
* Renders `ToggleGroupControl` as a (CSS) block element, spanning the entire width of
* the available space. This is the recommended style when the options are text-based and not icons.
*
* @default false
*/
isBlock?: boolean;
/**
* Whether an option can be deselected by clicking it again.
*
* @default false
*/
isDeselectable?: boolean;
/**
* Callback when a segment is selected.
*/
onChange?: ( value: string | number | undefined ) => void;
/**
* The selected value.
*/
value?: string | number;
/**
* The options to render in the `ToggleGroupControl`, using either the `ToggleGroupControlOption` or
* `ToggleGroupControlOptionIcon` components.
*/
children: ReactNode;
/**
* The size variant of the control.
*
* @default 'default'
*/
size?: 'default' | '__unstable-large';
/**
* Start opting into the larger default height that will become the default size in a future version.
*
* @default false
*/
__next40pxDefaultSize?: boolean;
};
export type ToggleGroupControlContextProps = {
isDeselectable?: boolean;
baseId: string;
isBlock: ToggleGroupControlProps[ 'isBlock' ];
size: ToggleGroupControlProps[ 'size' ];
value: ToggleGroupControlProps[ 'value' ];
setValue: ( newValue: string | number | undefined ) => void;
};
export type ToggleGroupControlMainControlProps = Pick<
ToggleGroupControlProps,
'children' | 'isAdaptiveWidth' | 'label' | 'size' | 'onChange' | 'value'
>;