@lumx/react 3.10.1-alpha.5 → 3.10.1-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_internal/Falsy.d.ts +7 -0
- package/index.d.ts +291 -5
- package/index.js +167 -267
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/alert-dialog/AlertDialog.tsx +3 -2
- package/src/components/autocomplete/Autocomplete.tsx +2 -2
- package/src/components/autocomplete/AutocompleteMultiple.tsx +2 -2
- package/src/components/avatar/Avatar.tsx +3 -3
- package/src/components/badge/Badge.tsx +3 -3
- package/src/components/badge/BadgeWrapper.tsx +2 -3
- package/src/components/button/Button.tsx +4 -4
- package/src/components/button/ButtonGroup.tsx +2 -3
- package/src/components/button/IconButton.tsx +2 -2
- package/src/components/checkbox/Checkbox.tsx +3 -3
- package/src/components/chip/Chip.tsx +3 -3
- package/src/components/chip/ChipGroup.tsx +2 -3
- package/src/components/comment-block/CommentBlock.tsx +3 -3
- package/src/components/date-picker/constants.ts +2 -2
- package/src/components/dialog/Dialog.tsx +5 -5
- package/src/components/divider/Divider.tsx +3 -3
- package/src/components/drag-handle/DragHandle.tsx +3 -3
- package/src/components/dropdown/Dropdown.tsx +3 -4
- package/src/components/expansion-panel/ExpansionPanel.tsx +6 -6
- package/src/components/flag/Flag.tsx +3 -3
- package/src/components/flex-box/FlexBox.tsx +3 -3
- package/src/components/generic-block/GenericBlock.tsx +2 -3
- package/src/components/grid/Grid.tsx +3 -3
- package/src/components/grid/GridItem.tsx +3 -3
- package/src/components/grid-column/GridColumn.tsx +2 -3
- package/src/components/heading/Heading.tsx +2 -3
- package/src/components/icon/Icon.tsx +3 -3
- package/src/components/image-block/ImageBlock.tsx +3 -3
- package/src/components/image-lightbox/constants.ts +2 -2
- package/src/components/inline-list/InlineList.tsx +3 -3
- package/src/components/input-helper/InputHelper.tsx +3 -3
- package/src/components/input-label/InputLabel.tsx +3 -3
- package/src/components/lightbox/Lightbox.tsx +3 -3
- package/src/components/link/Link.tsx +3 -3
- package/src/components/link-preview/LinkPreview.tsx +3 -3
- package/src/components/list/List.tsx +3 -3
- package/src/components/list/ListDivider.tsx +2 -3
- package/src/components/list/ListItem.tsx +3 -3
- package/src/components/list/ListSubheader.tsx +2 -3
- package/src/components/list/useInteractiveList.tsx +3 -3
- package/src/components/message/Message.tsx +3 -3
- package/src/components/mosaic/Mosaic.tsx +3 -3
- package/src/components/navigation/Navigation.tsx +3 -3
- package/src/components/navigation/NavigationItem.tsx +9 -3
- package/src/components/navigation/NavigationSection.tsx +3 -3
- package/src/components/notification/Notification.tsx +3 -3
- package/src/components/popover/Popover.tsx +3 -3
- package/src/components/popover-dialog/PopoverDialog.tsx +2 -3
- package/src/components/post-block/PostBlock.tsx +3 -3
- package/src/components/progress/Progress.tsx +3 -3
- package/src/components/progress/ProgressCircular.tsx +3 -3
- package/src/components/progress/ProgressLinear.tsx +3 -3
- package/src/components/progress-tracker/ProgressTracker.tsx +2 -3
- package/src/components/progress-tracker/ProgressTrackerStep.tsx +3 -3
- package/src/components/radio-button/RadioButton.tsx +3 -3
- package/src/components/radio-button/RadioGroup.tsx +2 -3
- package/src/components/select/Select.tsx +3 -2
- package/src/components/select/SelectMultiple.tsx +3 -2
- package/src/components/select/WithSelectContext.tsx +3 -2
- package/src/components/side-navigation/SideNavigation.tsx +3 -4
- package/src/components/side-navigation/SideNavigationItem.tsx +4 -4
- package/src/components/skeleton/SkeletonCircle.tsx +3 -3
- package/src/components/skeleton/SkeletonRectangle.tsx +3 -3
- package/src/components/skeleton/SkeletonTypography.tsx +3 -3
- package/src/components/slider/Slider.tsx +3 -3
- package/src/components/slideshow/Slides.tsx +3 -3
- package/src/components/slideshow/SlideshowControls.tsx +3 -3
- package/src/components/slideshow/SlideshowItem.tsx +2 -3
- package/src/components/slideshow/SlideshowItemGroup.tsx +2 -3
- package/src/components/switch/Switch.tsx +3 -3
- package/src/components/table/Table.tsx +3 -3
- package/src/components/table/TableBody.tsx +2 -3
- package/src/components/table/TableCell.tsx +3 -3
- package/src/components/table/TableHeader.tsx +2 -3
- package/src/components/table/TableRow.tsx +3 -3
- package/src/components/text/Text.tsx +4 -9
- package/src/components/text-field/TextField.tsx +3 -3
- package/src/components/thumbnail/Thumbnail.tsx +3 -3
- package/src/components/toolbar/Toolbar.tsx +3 -3
- package/src/components/tooltip/Tooltip.tsx +3 -3
- package/src/components/uploader/Uploader.tsx +3 -3
- package/src/components/user-block/UserBlock.tsx +3 -3
- package/src/utils/className/index.ts +0 -1
- package/src/utils/className.test.js +41 -0
- package/src/utils/type/Callback.ts +4 -0
- package/src/utils/type/Comp.ts +14 -0
- package/src/utils/type/ComponentClassName.ts +7 -0
- package/src/utils/type/ComponentRef.ts +16 -0
- package/src/utils/type/Falsy.ts +5 -0
- package/src/utils/type/GenericProps.ts +11 -0
- package/src/utils/type/HasAriaLabelOrLabelledBy.ts +19 -0
- package/src/utils/type/HasClassName.ts +6 -0
- package/src/utils/type/HasCloseMode.ts +7 -0
- package/src/utils/type/HasPolymorphicAs.ts +8 -0
- package/src/utils/type/HasTheme.ts +8 -0
- package/src/utils/type/HeadingElement.ts +2 -0
- package/src/utils/type/KebabCase.ts +6 -0
- package/src/utils/type/MaybeElementOrRef.ts +6 -0
- package/src/utils/type/Point.ts +4 -0
- package/src/utils/type/Predicate.ts +2 -0
- package/src/utils/type/RectSize.ts +4 -0
- package/src/utils/type/TextElement.ts +4 -0
- package/src/utils/type/ValueOf.ts +2 -0
- package/src/utils/type/index.ts +19 -0
- package/src/utils/type/isComponentType.ts +9 -0
- package/utils/index.d.ts +1 -1
- package/_internal/index.d.ts +0 -285
- package/src/utils/className/getRootClassName.test.ts +0 -11
- package/src/utils/className/getRootClassName.ts +0 -24
- package/src/utils/type.ts +0 -164
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HasClassName } from './HasClassName';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Define a generic props types.
|
|
5
|
+
*/
|
|
6
|
+
export interface GenericProps extends HasClassName {
|
|
7
|
+
/**
|
|
8
|
+
* Any prop (particularly any supported prop for a HTML element).
|
|
9
|
+
*/
|
|
10
|
+
[propName: string]: any;
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Require either `aria-label` or `arial-labelledby` prop.
|
|
3
|
+
* If none are set, the order will prioritize `aria-labelledby` over `aria-label` as it
|
|
4
|
+
* needs a visible element.
|
|
5
|
+
*/
|
|
6
|
+
export type HasAriaLabelOrLabelledBy<T = string | undefined> = T extends string
|
|
7
|
+
? {
|
|
8
|
+
/**
|
|
9
|
+
* The id of the element to use as title of the dialog. Can be within or out of the dialog.
|
|
10
|
+
* Although it is not recommended, aria-label can be used instead if no visible element is available.
|
|
11
|
+
*/
|
|
12
|
+
'aria-labelledby': T;
|
|
13
|
+
/** The label of the dialog. */
|
|
14
|
+
'aria-label'?: undefined;
|
|
15
|
+
}
|
|
16
|
+
: {
|
|
17
|
+
'aria-label': string;
|
|
18
|
+
'aria-labelledby'?: undefined;
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { Callback } from './Callback';
|
|
2
|
+
export { Comp } from './Comp';
|
|
3
|
+
export { ComponentRef } from './ComponentRef';
|
|
4
|
+
export { Falsy } from './Falsy';
|
|
5
|
+
export { GenericProps } from './GenericProps';
|
|
6
|
+
export { HasAriaLabelOrLabelledBy } from './HasAriaLabelOrLabelledBy';
|
|
7
|
+
export { HasClassName } from './HasClassName';
|
|
8
|
+
export { HasCloseMode } from './HasCloseMode';
|
|
9
|
+
export { HasPolymorphicAs } from './HasPolymorphicAs';
|
|
10
|
+
export { HasTheme } from './HasTheme';
|
|
11
|
+
export { HeadingElement } from './HeadingElement';
|
|
12
|
+
export { isComponentType } from './isComponentType';
|
|
13
|
+
export { MaybeElementOrRef } from './MaybeElementOrRef';
|
|
14
|
+
export { Point } from './Point';
|
|
15
|
+
export { Predicate } from './Predicate';
|
|
16
|
+
export { RectSize } from './RectSize';
|
|
17
|
+
export { TextElement } from './TextElement';
|
|
18
|
+
export { ValueOf } from './ValueOf';
|
|
19
|
+
export { ComponentClassName } from './ComponentClassName';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React, { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Similar to `isComponent` but more precise as it's not based on the component `displayName` but on the component function reference.
|
|
5
|
+
*/
|
|
6
|
+
export const isComponentType =
|
|
7
|
+
(type: ReactElement['type']) =>
|
|
8
|
+
(node: ReactNode): node is ReactElement =>
|
|
9
|
+
React.isValidElement(node) && node.type === type;
|
package/utils/index.d.ts
CHANGED
package/_internal/index.d.ts
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import React, { Ref, ReactElement } from 'react';
|
|
2
|
-
|
|
3
|
-
/** Get types of the values of a record. */
|
|
4
|
-
type ValueOf<T extends Record<any, any>> = T[keyof T];
|
|
5
|
-
/** LumX Component Type. */
|
|
6
|
-
type Comp<P, T = HTMLElement> = {
|
|
7
|
-
(props: P & {
|
|
8
|
-
ref?: Ref<T>;
|
|
9
|
-
}): ReactElement | null;
|
|
10
|
-
/** React component type. */
|
|
11
|
-
readonly $$typeof: symbol;
|
|
12
|
-
/** Component default props. */
|
|
13
|
-
defaultProps?: Partial<P>;
|
|
14
|
-
/** Component name. */
|
|
15
|
-
displayName?: string;
|
|
16
|
-
/** Component base class name. */
|
|
17
|
-
className?: string;
|
|
18
|
-
};
|
|
19
|
-
/** Union type of all heading elements */
|
|
20
|
-
type HeadingElement = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
21
|
-
/** Union type of all text elements */
|
|
22
|
-
type TextElement = 'span' | 'p' | HeadingElement;
|
|
23
|
-
interface HasTheme {
|
|
24
|
-
/**
|
|
25
|
-
* Theme adapting the component to light or dark background.
|
|
26
|
-
*/
|
|
27
|
-
theme?: Theme;
|
|
28
|
-
}
|
|
29
|
-
interface HasClassName {
|
|
30
|
-
/**
|
|
31
|
-
* Class name forwarded to the root element of the component.
|
|
32
|
-
*/
|
|
33
|
-
className?: string;
|
|
34
|
-
}
|
|
35
|
-
interface HasCloseMode {
|
|
36
|
-
/**
|
|
37
|
-
* Choose how the children are hidden when closed
|
|
38
|
-
* ('hide' keeps the children in DOM but hide them, 'unmount' remove the children from the DOM).
|
|
39
|
-
*/
|
|
40
|
-
closeMode?: 'hide' | 'unmount';
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Define a generic props types.
|
|
44
|
-
*/
|
|
45
|
-
interface GenericProps extends HasClassName {
|
|
46
|
-
/**
|
|
47
|
-
* Any prop (particularly any supported prop for a HTML element).
|
|
48
|
-
*/
|
|
49
|
-
[propName: string]: any;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Callback function type alias (use for readability)
|
|
53
|
-
*/
|
|
54
|
-
type Callback = () => void;
|
|
55
|
-
/**
|
|
56
|
-
* JS falsy values.
|
|
57
|
-
* (excluding `NaN` as it can't be distinguished from `number`)
|
|
58
|
-
*/
|
|
59
|
-
type Falsy = false | undefined | null | 0 | '';
|
|
60
|
-
/**
|
|
61
|
-
* Require either `aria-label` or `arial-labelledby` prop.
|
|
62
|
-
* If none are set, the order will prioritize `aria-labelledby` over `aria-label` as it
|
|
63
|
-
* needs a visible element.
|
|
64
|
-
*/
|
|
65
|
-
type HasAriaLabelOrLabelledBy<T = string | undefined> = T extends string ? {
|
|
66
|
-
/**
|
|
67
|
-
* The id of the element to use as title of the dialog. Can be within or out of the dialog.
|
|
68
|
-
* Although it is not recommended, aria-label can be used instead if no visible element is available.
|
|
69
|
-
*/
|
|
70
|
-
'aria-labelledby': T;
|
|
71
|
-
/** The label of the dialog. */
|
|
72
|
-
'aria-label'?: undefined;
|
|
73
|
-
} : {
|
|
74
|
-
'aria-label': string;
|
|
75
|
-
'aria-labelledby'?: undefined;
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Extract ref type for a component or JSX intrinsic element
|
|
79
|
-
*
|
|
80
|
-
* @example ComponentRef<'div'> => React.Ref<HTMLDivElement>
|
|
81
|
-
* @example ComponentRef<Button> => React.Ref<HTMLButtonElement
|
|
82
|
-
*/
|
|
83
|
-
type ComponentRef<C> = C extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[C]['ref'] : C extends Comp<any, infer T> ? React.Ref<T> : C extends React.JSXElementConstructor<{
|
|
84
|
-
ref?: infer R;
|
|
85
|
-
}> ? R : never;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Alignments.
|
|
89
|
-
*/
|
|
90
|
-
declare const Alignment: {
|
|
91
|
-
readonly bottom: "bottom";
|
|
92
|
-
readonly center: "center";
|
|
93
|
-
readonly end: "end";
|
|
94
|
-
readonly left: "left";
|
|
95
|
-
readonly right: "right";
|
|
96
|
-
readonly spaceAround: "space-around";
|
|
97
|
-
readonly spaceBetween: "space-between";
|
|
98
|
-
readonly spaceEvenly: "space-evenly";
|
|
99
|
-
readonly start: "start";
|
|
100
|
-
readonly top: "top";
|
|
101
|
-
};
|
|
102
|
-
type Alignment = ValueOf<typeof Alignment>;
|
|
103
|
-
type VerticalAlignment = Extract<Alignment, 'top' | 'center' | 'bottom'>;
|
|
104
|
-
type HorizontalAlignment = Extract<Alignment, 'right' | 'center' | 'left'>;
|
|
105
|
-
/**
|
|
106
|
-
* See SCSS variable $lumx-color-palette
|
|
107
|
-
*/
|
|
108
|
-
declare const ColorPalette: {
|
|
109
|
-
readonly primary: "primary";
|
|
110
|
-
readonly secondary: "secondary";
|
|
111
|
-
readonly blue: "blue";
|
|
112
|
-
readonly dark: "dark";
|
|
113
|
-
readonly green: "green";
|
|
114
|
-
readonly yellow: "yellow";
|
|
115
|
-
readonly red: "red";
|
|
116
|
-
readonly light: "light";
|
|
117
|
-
readonly grey: "grey";
|
|
118
|
-
};
|
|
119
|
-
type ColorPalette = ValueOf<typeof ColorPalette>;
|
|
120
|
-
type Color = ColorPalette | string;
|
|
121
|
-
/**
|
|
122
|
-
* See SCSS variable $lumx-color-variants
|
|
123
|
-
*/
|
|
124
|
-
declare const ColorVariant: {
|
|
125
|
-
readonly D1: "D1";
|
|
126
|
-
readonly D2: "D2";
|
|
127
|
-
readonly L1: "L1";
|
|
128
|
-
readonly L2: "L2";
|
|
129
|
-
readonly L3: "L3";
|
|
130
|
-
readonly L4: "L4";
|
|
131
|
-
readonly L5: "L5";
|
|
132
|
-
readonly L6: "L6";
|
|
133
|
-
readonly N: "N";
|
|
134
|
-
};
|
|
135
|
-
type ColorVariant = ValueOf<typeof ColorVariant>;
|
|
136
|
-
declare const Theme: {
|
|
137
|
-
readonly light: "light";
|
|
138
|
-
readonly dark: "dark";
|
|
139
|
-
};
|
|
140
|
-
type Theme = ValueOf<typeof Theme>;
|
|
141
|
-
declare const Size: {
|
|
142
|
-
readonly xxs: "xxs";
|
|
143
|
-
readonly xs: "xs";
|
|
144
|
-
readonly s: "s";
|
|
145
|
-
readonly m: "m";
|
|
146
|
-
readonly l: "l";
|
|
147
|
-
readonly xl: "xl";
|
|
148
|
-
readonly xxl: "xxl";
|
|
149
|
-
readonly tiny: "tiny";
|
|
150
|
-
readonly regular: "regular";
|
|
151
|
-
readonly medium: "medium";
|
|
152
|
-
readonly big: "big";
|
|
153
|
-
readonly huge: "huge";
|
|
154
|
-
};
|
|
155
|
-
type Size = ValueOf<typeof Size>;
|
|
156
|
-
type GlobalSize = Extract<Size, 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'>;
|
|
157
|
-
declare const Orientation: {
|
|
158
|
-
readonly horizontal: "horizontal";
|
|
159
|
-
readonly vertical: "vertical";
|
|
160
|
-
};
|
|
161
|
-
type Orientation = ValueOf<typeof Orientation>;
|
|
162
|
-
declare const Emphasis: {
|
|
163
|
-
readonly low: "low";
|
|
164
|
-
readonly medium: "medium";
|
|
165
|
-
readonly high: "high";
|
|
166
|
-
};
|
|
167
|
-
type Emphasis = ValueOf<typeof Emphasis>;
|
|
168
|
-
/**
|
|
169
|
-
* List of typographies that can't be customized.
|
|
170
|
-
*/
|
|
171
|
-
declare const TypographyInterface: {
|
|
172
|
-
readonly overline: "overline";
|
|
173
|
-
readonly caption: "caption";
|
|
174
|
-
readonly body1: "body1";
|
|
175
|
-
readonly body2: "body2";
|
|
176
|
-
readonly subtitle1: "subtitle1";
|
|
177
|
-
readonly subtitle2: "subtitle2";
|
|
178
|
-
readonly title: "title";
|
|
179
|
-
readonly headline: "headline";
|
|
180
|
-
readonly display1: "display1";
|
|
181
|
-
};
|
|
182
|
-
type TypographyInterface = ValueOf<typeof TypographyInterface>;
|
|
183
|
-
/**
|
|
184
|
-
* List of title typographies that can be customized (via CSS variables).
|
|
185
|
-
*/
|
|
186
|
-
declare const TypographyTitleCustom: {
|
|
187
|
-
readonly title1: "custom-title1";
|
|
188
|
-
readonly title2: "custom-title2";
|
|
189
|
-
readonly title3: "custom-title3";
|
|
190
|
-
readonly title4: "custom-title4";
|
|
191
|
-
readonly title5: "custom-title5";
|
|
192
|
-
readonly title6: "custom-title6";
|
|
193
|
-
};
|
|
194
|
-
type TypographyTitleCustom = ValueOf<typeof TypographyTitleCustom>;
|
|
195
|
-
/**
|
|
196
|
-
* List of typographies that can be customized (via CSS variables).
|
|
197
|
-
*/
|
|
198
|
-
declare const TypographyCustom: {
|
|
199
|
-
readonly intro: "custom-intro";
|
|
200
|
-
readonly 'body-large': "custom-body-large";
|
|
201
|
-
readonly body: "custom-body";
|
|
202
|
-
readonly quote: "custom-quote";
|
|
203
|
-
readonly 'publish-info': "custom-publish-info";
|
|
204
|
-
readonly button: "custom-button";
|
|
205
|
-
readonly title1: "custom-title1";
|
|
206
|
-
readonly title2: "custom-title2";
|
|
207
|
-
readonly title3: "custom-title3";
|
|
208
|
-
readonly title4: "custom-title4";
|
|
209
|
-
readonly title5: "custom-title5";
|
|
210
|
-
readonly title6: "custom-title6";
|
|
211
|
-
};
|
|
212
|
-
type TypographyCustom = ValueOf<typeof TypographyCustom>;
|
|
213
|
-
/**
|
|
214
|
-
* List of all typographies.
|
|
215
|
-
*/
|
|
216
|
-
declare const Typography: {
|
|
217
|
-
readonly custom: {
|
|
218
|
-
readonly intro: "custom-intro";
|
|
219
|
-
readonly 'body-large': "custom-body-large";
|
|
220
|
-
readonly body: "custom-body";
|
|
221
|
-
readonly quote: "custom-quote";
|
|
222
|
-
readonly 'publish-info': "custom-publish-info";
|
|
223
|
-
readonly button: "custom-button";
|
|
224
|
-
readonly title1: "custom-title1";
|
|
225
|
-
readonly title2: "custom-title2";
|
|
226
|
-
readonly title3: "custom-title3";
|
|
227
|
-
readonly title4: "custom-title4";
|
|
228
|
-
readonly title5: "custom-title5";
|
|
229
|
-
readonly title6: "custom-title6";
|
|
230
|
-
};
|
|
231
|
-
readonly overline: "overline";
|
|
232
|
-
readonly caption: "caption";
|
|
233
|
-
readonly body1: "body1";
|
|
234
|
-
readonly body2: "body2";
|
|
235
|
-
readonly subtitle1: "subtitle1";
|
|
236
|
-
readonly subtitle2: "subtitle2";
|
|
237
|
-
readonly title: "title";
|
|
238
|
-
readonly headline: "headline";
|
|
239
|
-
readonly display1: "display1";
|
|
240
|
-
};
|
|
241
|
-
type Typography = TypographyInterface | TypographyCustom;
|
|
242
|
-
/**
|
|
243
|
-
* All available aspect ratios.
|
|
244
|
-
*/
|
|
245
|
-
declare const AspectRatio: {
|
|
246
|
-
/** Intrinsic content ratio. */
|
|
247
|
-
readonly original: "original";
|
|
248
|
-
/** Ratio 3:1 */
|
|
249
|
-
readonly panoramic: "panoramic";
|
|
250
|
-
/** Ratio 16:9 */
|
|
251
|
-
readonly wide: "wide";
|
|
252
|
-
/** Ratio 3:2 */
|
|
253
|
-
readonly horizontal: "horizontal";
|
|
254
|
-
/** Ratio 3:2 */
|
|
255
|
-
readonly vertical: "vertical";
|
|
256
|
-
/** Ratio 1:1 */
|
|
257
|
-
readonly square: "square";
|
|
258
|
-
/** Ratio constrained by the parent. */
|
|
259
|
-
readonly free: "free";
|
|
260
|
-
};
|
|
261
|
-
type AspectRatio = ValueOf<typeof AspectRatio>;
|
|
262
|
-
/**
|
|
263
|
-
* Semantic info about the purpose of the component
|
|
264
|
-
*/
|
|
265
|
-
declare const Kind: {
|
|
266
|
-
readonly info: "info";
|
|
267
|
-
readonly success: "success";
|
|
268
|
-
readonly warning: "warning";
|
|
269
|
-
readonly error: "error";
|
|
270
|
-
};
|
|
271
|
-
type Kind = ValueOf<typeof Kind>;
|
|
272
|
-
/**
|
|
273
|
-
* All available white-space values
|
|
274
|
-
* */
|
|
275
|
-
declare const WhiteSpace: {
|
|
276
|
-
normal: string;
|
|
277
|
-
nowrap: string;
|
|
278
|
-
pre: string;
|
|
279
|
-
'pre-wrap': string;
|
|
280
|
-
'pre-line': string;
|
|
281
|
-
'break-spaces': string;
|
|
282
|
-
};
|
|
283
|
-
type WhiteSpace = ValueOf<typeof WhiteSpace>;
|
|
284
|
-
|
|
285
|
-
export { Alignment as A, type Comp as C, Emphasis as E, type Falsy as F, type GenericProps as G, type HasTheme as H, Kind as K, Orientation as O, Size as S, Typography as T, type ValueOf as V, WhiteSpace as W, type HorizontalAlignment as a, ColorPalette as b, type VerticalAlignment as c, ColorVariant as d, type TextElement as e, type HeadingElement as f, AspectRatio as g, type HasClassName as h, type ComponentRef as i, type HasAriaLabelOrLabelledBy as j, type HasCloseMode as k, type GlobalSize as l, TypographyInterface as m, Theme as n, type Color as o, TypographyTitleCustom as p, TypographyCustom as q, type Callback as r };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { getRootClassName } from '@lumx/react/utils/className/getRootClassName';
|
|
2
|
-
|
|
3
|
-
describe(getRootClassName, () => {
|
|
4
|
-
it('should transform the component name into a lumx class', () => {
|
|
5
|
-
expect(getRootClassName('Table')).toBe('lumx-table');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
it('should transform the sub component name into a lumx class', () => {
|
|
9
|
-
expect(getRootClassName('TableBody', true)).toBe('lumx-table__body');
|
|
10
|
-
});
|
|
11
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { CSS_PREFIX } from '@lumx/core/js/constants';
|
|
2
|
-
import kebabCase from 'lodash/kebabCase';
|
|
3
|
-
|
|
4
|
-
// See https://regex101.com/r/YjS1uI/3
|
|
5
|
-
const LAST_PART_CLASSNAME = /^(.*)-(.+)$/gi;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Get the name of the root CSS class of a component based on its name.
|
|
9
|
-
*
|
|
10
|
-
* @param componentName The name of the component. This name should contains the component prefix and be
|
|
11
|
-
* written in PascalCase.
|
|
12
|
-
* @param subComponent Whether the current component is a sub component, if true, define the class according
|
|
13
|
-
* to BEM standards.
|
|
14
|
-
* @return The name of the root CSS class. This classname include the CSS classname prefix and is written in
|
|
15
|
-
* lower-snake-case.
|
|
16
|
-
*/
|
|
17
|
-
export function getRootClassName(componentName: string, subComponent?: boolean): string {
|
|
18
|
-
const formattedClassName = `${CSS_PREFIX}-${kebabCase(componentName)}`;
|
|
19
|
-
|
|
20
|
-
if (subComponent) {
|
|
21
|
-
return formattedClassName.replace(LAST_PART_CLASSNAME, '$1__$2');
|
|
22
|
-
}
|
|
23
|
-
return formattedClassName;
|
|
24
|
-
}
|
package/src/utils/type.ts
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import get from 'lodash/get';
|
|
2
|
-
import React, { ReactElement, ReactNode, Ref } from 'react';
|
|
3
|
-
import { Theme } from '@lumx/react';
|
|
4
|
-
|
|
5
|
-
/** Get types of the values of a record. */
|
|
6
|
-
export type ValueOf<T extends Record<any, any>> = T[keyof T];
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Properties of a component to use to determine it's name.
|
|
10
|
-
* In the order of preference.
|
|
11
|
-
*/
|
|
12
|
-
const NAME_PROPERTIES: string[] = [
|
|
13
|
-
'type',
|
|
14
|
-
'type.displayName',
|
|
15
|
-
'displayName',
|
|
16
|
-
'name',
|
|
17
|
-
'type.name',
|
|
18
|
-
'props.mdxType',
|
|
19
|
-
'_reactInternalFiber.elementType.name',
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
/** LumX Component Type. */
|
|
23
|
-
export type Comp<P, T = HTMLElement> = {
|
|
24
|
-
(props: P & { ref?: Ref<T> }): ReactElement | null;
|
|
25
|
-
/** React component type. */
|
|
26
|
-
readonly $$typeof: symbol;
|
|
27
|
-
/** Component default props. */
|
|
28
|
-
defaultProps?: Partial<P>;
|
|
29
|
-
/** Component name. */
|
|
30
|
-
displayName?: string;
|
|
31
|
-
/** Component base class name. */
|
|
32
|
-
className?: string;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/** Union type of all heading elements */
|
|
36
|
-
export type HeadingElement = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
37
|
-
|
|
38
|
-
/** Union type of all text elements */
|
|
39
|
-
export type TextElement = 'span' | 'p' | HeadingElement;
|
|
40
|
-
|
|
41
|
-
export type HasPolymorphicAs<E extends React.ElementType> = React.ComponentPropsWithoutRef<E> & {
|
|
42
|
-
/**
|
|
43
|
-
* Customize the rendered component.
|
|
44
|
-
*/
|
|
45
|
-
as?: E;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export interface HasTheme {
|
|
49
|
-
/**
|
|
50
|
-
* Theme adapting the component to light or dark background.
|
|
51
|
-
*/
|
|
52
|
-
theme?: Theme;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface HasClassName {
|
|
56
|
-
/**
|
|
57
|
-
* Class name forwarded to the root element of the component.
|
|
58
|
-
*/
|
|
59
|
-
className?: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface HasCloseMode {
|
|
63
|
-
/**
|
|
64
|
-
* Choose how the children are hidden when closed
|
|
65
|
-
* ('hide' keeps the children in DOM but hide them, 'unmount' remove the children from the DOM).
|
|
66
|
-
*/
|
|
67
|
-
closeMode?: 'hide' | 'unmount';
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Define a generic props types.
|
|
72
|
-
*/
|
|
73
|
-
export interface GenericProps extends HasClassName {
|
|
74
|
-
/**
|
|
75
|
-
* Any prop (particularly any supported prop for a HTML element).
|
|
76
|
-
*/
|
|
77
|
-
[propName: string]: any;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Callback function type alias (use for readability)
|
|
82
|
-
*/
|
|
83
|
-
export type Callback = () => void;
|
|
84
|
-
export type Predicate<T> = (t: T) => boolean;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Create a predicate function that checks if a ReactNode is a react element from the given component.
|
|
88
|
-
*
|
|
89
|
-
* @param component React function component or the component name
|
|
90
|
-
* @return predicate returning true if value is instance of the component
|
|
91
|
-
*/
|
|
92
|
-
export const isComponent =
|
|
93
|
-
<C>(component: Comp<C, any> | string) =>
|
|
94
|
-
(instance: ReactNode): instance is ReactElement => {
|
|
95
|
-
const componentName = typeof component === 'string' ? component : component.displayName;
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
!!get(instance, '$$typeof') &&
|
|
99
|
-
NAME_PROPERTIES.some((nameProperty: string): boolean => get(instance, nameProperty) === componentName)
|
|
100
|
-
);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Similar to `isComponent` but more precise as it's not based on the component `displayName` but on the component function reference.
|
|
105
|
-
*/
|
|
106
|
-
export const isComponentType =
|
|
107
|
-
(type: ReactElement['type']) =>
|
|
108
|
-
(node: ReactNode): node is ReactElement =>
|
|
109
|
-
React.isValidElement(node) && node.type === type;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* JS falsy values.
|
|
113
|
-
* (excluding `NaN` as it can't be distinguished from `number`)
|
|
114
|
-
*/
|
|
115
|
-
export type Falsy = false | undefined | null | 0 | '';
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Require either `aria-label` or `arial-labelledby` prop.
|
|
119
|
-
* If none are set, the order will prioritize `aria-labelledby` over `aria-label` as it
|
|
120
|
-
* needs a visible element.
|
|
121
|
-
*/
|
|
122
|
-
export type HasAriaLabelOrLabelledBy<T = string | undefined> = T extends string
|
|
123
|
-
? {
|
|
124
|
-
/**
|
|
125
|
-
* The id of the element to use as title of the dialog. Can be within or out of the dialog.
|
|
126
|
-
* Although it is not recommended, aria-label can be used instead if no visible element is available.
|
|
127
|
-
*/
|
|
128
|
-
'aria-labelledby': T;
|
|
129
|
-
/** The label of the dialog. */
|
|
130
|
-
'aria-label'?: undefined;
|
|
131
|
-
}
|
|
132
|
-
: {
|
|
133
|
-
'aria-label': string;
|
|
134
|
-
'aria-labelledby'?: undefined;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Extract ref type for a component or JSX intrinsic element
|
|
139
|
-
*
|
|
140
|
-
* @example ComponentRef<'div'> => React.Ref<HTMLDivElement>
|
|
141
|
-
* @example ComponentRef<Button> => React.Ref<HTMLButtonElement
|
|
142
|
-
*/
|
|
143
|
-
export type ComponentRef<C> = C extends keyof JSX.IntrinsicElements
|
|
144
|
-
? JSX.IntrinsicElements[C]['ref']
|
|
145
|
-
: C extends Comp<any, infer T>
|
|
146
|
-
? React.Ref<T>
|
|
147
|
-
: C extends React.JSXElementConstructor<{ ref?: infer R }>
|
|
148
|
-
? R
|
|
149
|
-
: never;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Rectangle size
|
|
153
|
-
*/
|
|
154
|
-
export type RectSize = { width: number; height: number };
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Maybe a HTMLElement or a React ref of a HTMLElement
|
|
158
|
-
*/
|
|
159
|
-
export type MaybeElementOrRef<E extends HTMLElement> = E | React.RefObject<E | null> | null | undefined;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* A point coordinate in 2D space
|
|
163
|
-
*/
|
|
164
|
-
export type Point = { x: number; y: number };
|