@lumx/react 3.13.3-alpha.0 → 3.13.3-alpha.2
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/index.d.ts +27 -24
- package/index.js +53 -56
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/avatar/Avatar.stories.tsx +1 -1
- package/src/components/avatar/Avatar.tsx +1 -1
- package/src/components/button/IconButton.tsx +4 -2
- package/src/components/expansion-panel/ExpansionPanel.stories.tsx +58 -0
- package/src/components/expansion-panel/ExpansionPanel.tsx +8 -17
- package/src/components/icon/Icon.tsx +6 -5
- package/src/components/image-block/ImageCaption.tsx +3 -2
- package/src/components/image-lightbox/ImageLightbox.stories.tsx +2 -6
- package/src/components/image-lightbox/ImageLightbox.tsx +14 -12
- package/src/components/image-lightbox/internal/ImageSlideshow.tsx +2 -11
- package/src/components/index.ts +2 -33
- package/src/components/inline-list/InlineList.tsx +4 -5
- package/src/components/link/Link.tsx +11 -5
- package/src/components/text/Text.tsx +4 -5
- package/src/utils/className/fontColorClass.test.ts +15 -0
- package/src/utils/className/fontColorClass.ts +12 -0
- package/src/utils/className/index.ts +2 -1
- package/src/utils/className/resolveColorWithVariants.test.ts +33 -0
- package/src/utils/className/resolveColorWithVariants.ts +11 -0
- package/src/utils/type/color/index.ts +43 -0
- package/src/utils/className/getFontColorClassName.test.ts +0 -11
- package/src/utils/className/getFontColorClassName.ts +0 -9
package/package.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"url": "https://github.com/lumapps/design-system/issues"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@lumx/core": "^3.13.3-alpha.
|
|
10
|
-
"@lumx/icons": "^3.13.3-alpha.
|
|
9
|
+
"@lumx/core": "^3.13.3-alpha.2",
|
|
10
|
+
"@lumx/icons": "^3.13.3-alpha.2",
|
|
11
11
|
"@popperjs/core": "^2.5.4",
|
|
12
12
|
"body-scroll-lock": "^3.1.5",
|
|
13
13
|
"classnames": "^2.3.2",
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"build:storybook": "storybook build"
|
|
111
111
|
},
|
|
112
112
|
"sideEffects": false,
|
|
113
|
-
"version": "3.13.3-alpha.
|
|
113
|
+
"version": "3.13.3-alpha.2"
|
|
114
114
|
}
|
|
@@ -13,7 +13,7 @@ import { withNestedProps } from '@lumx/react/stories/decorators/withNestedProps'
|
|
|
13
13
|
import { iconArgType } from '@lumx/react/stories/controls/icons';
|
|
14
14
|
import { Avatar } from './Avatar';
|
|
15
15
|
|
|
16
|
-
const AVATAR_SIZES = [Size.xs, Size.s, Size.m, Size.l, Size.xl, Size.xxl];
|
|
16
|
+
const AVATAR_SIZES = [Size.xxs, Size.xs, Size.s, Size.m, Size.l, Size.xl, Size.xxl];
|
|
17
17
|
|
|
18
18
|
export default {
|
|
19
19
|
title: 'LumX components/avatar/Avatar',
|
|
@@ -12,7 +12,7 @@ import { forwardRef } from '@lumx/react/utils/react/forwardRef';
|
|
|
12
12
|
/**
|
|
13
13
|
* Avatar sizes.
|
|
14
14
|
*/
|
|
15
|
-
export type AvatarSize = Extract<Size, 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'>;
|
|
15
|
+
export type AvatarSize = Extract<Size, 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'>;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Defines the props of the component.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { Emphasis, Icon, Size, Theme, Tooltip, TooltipProps } from '@lumx/react';
|
|
3
|
+
import { Emphasis, Icon, Size, Theme, ThemeProvider, Tooltip, TooltipProps } from '@lumx/react';
|
|
4
4
|
import { BaseButtonProps, ButtonRoot } from '@lumx/react/components/button/ButtonRoot';
|
|
5
5
|
import { getRootClassName } from '@lumx/react/utils/className';
|
|
6
6
|
import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
|
|
@@ -80,7 +80,9 @@ export const IconButton = forwardRef<IconButtonProps, HTMLButtonElement>((props,
|
|
|
80
80
|
src={image}
|
|
81
81
|
/>
|
|
82
82
|
) : (
|
|
83
|
-
<
|
|
83
|
+
<ThemeProvider value={undefined}>
|
|
84
|
+
<Icon icon={icon as string} />
|
|
85
|
+
</ThemeProvider>
|
|
84
86
|
)}
|
|
85
87
|
</ButtonRoot>
|
|
86
88
|
</Tooltip>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { ExpansionPanel, FlexBox } from '@lumx/react';
|
|
5
|
+
import { withNestedProps } from '@lumx/react/stories/decorators/withNestedProps';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'LumX components/expansion-panel/ExpansionPanel',
|
|
9
|
+
component: ExpansionPanel,
|
|
10
|
+
args: {
|
|
11
|
+
'toggleButtonProps.label': 'Toggle',
|
|
12
|
+
children: 'Content',
|
|
13
|
+
label: 'Label',
|
|
14
|
+
},
|
|
15
|
+
decorators: [withNestedProps()],
|
|
16
|
+
render({ toggleButtonProps, ...args }: any) {
|
|
17
|
+
const [isOpen, setOpen] = React.useState(args.isOpen);
|
|
18
|
+
return (
|
|
19
|
+
<ExpansionPanel isOpen={isOpen} toggleButtonProps={toggleButtonProps} onToggleOpen={setOpen} {...args} />
|
|
20
|
+
);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Minimal expansion panel config */
|
|
25
|
+
export const Default = {};
|
|
26
|
+
|
|
27
|
+
/** hasBackground variant */
|
|
28
|
+
export const HasBackground = {
|
|
29
|
+
args: {
|
|
30
|
+
hasBackground: true,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** hasHeaderDivider variant */
|
|
35
|
+
export const HasHeaderDivider = {
|
|
36
|
+
args: {
|
|
37
|
+
isOpen: true,
|
|
38
|
+
hasBackground: true,
|
|
39
|
+
hasHeaderDivider: true,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** Test resizable content work */
|
|
44
|
+
export const ResizingContent = {
|
|
45
|
+
args: {
|
|
46
|
+
hasBackground: true,
|
|
47
|
+
children: (
|
|
48
|
+
<FlexBox
|
|
49
|
+
style={{ resize: 'both', overflow: 'hidden' }}
|
|
50
|
+
hAlign="center"
|
|
51
|
+
vAlign="center"
|
|
52
|
+
className="lumx-spacing-padding-huge"
|
|
53
|
+
>
|
|
54
|
+
Content
|
|
55
|
+
</FlexBox>
|
|
56
|
+
),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import React, { Children, PropsWithChildren, ReactNode,
|
|
1
|
+
import React, { Children, PropsWithChildren, ReactNode, useRef } from 'react';
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
|
|
5
5
|
import { mdiChevronDown, mdiChevronUp } from '@lumx/icons';
|
|
6
6
|
|
|
7
|
-
import get from 'lodash/get';
|
|
8
7
|
import isEmpty from 'lodash/isEmpty';
|
|
9
|
-
import isFunction from 'lodash/isFunction';
|
|
10
8
|
|
|
11
9
|
import { ColorPalette, DragHandle, Emphasis, IconButton, IconButtonProps, Theme } from '@lumx/react';
|
|
12
10
|
import { GenericProps, HasTheme, isComponent } from '@lumx/react/utils/type';
|
|
@@ -101,13 +99,13 @@ export const ExpansionPanel = forwardRef<ExpansionPanelProps, HTMLDivElement>((p
|
|
|
101
99
|
const toggleOpen = (event: React.MouseEvent) => {
|
|
102
100
|
const shouldOpen = !isOpen;
|
|
103
101
|
|
|
104
|
-
if (
|
|
102
|
+
if (onOpen && shouldOpen) {
|
|
105
103
|
onOpen(event);
|
|
106
104
|
}
|
|
107
|
-
if (
|
|
105
|
+
if (onClose && !shouldOpen) {
|
|
108
106
|
onClose(event);
|
|
109
107
|
}
|
|
110
|
-
if (
|
|
108
|
+
if (onToggleOpen) {
|
|
111
109
|
onToggleOpen(shouldOpen, event);
|
|
112
110
|
}
|
|
113
111
|
};
|
|
@@ -133,13 +131,6 @@ export const ExpansionPanel = forwardRef<ExpansionPanelProps, HTMLDivElement>((p
|
|
|
133
131
|
/** Hide the children at the end of the transition */
|
|
134
132
|
const isChildrenVisible = useTransitionVisibility(wrapperRef, !!isOpen, EXPANSION_PANEL_TRANSITION_DURATION);
|
|
135
133
|
|
|
136
|
-
// Switch max height on/off to activate the CSS transition (updates when children changes).
|
|
137
|
-
const [maxHeight, setMaxHeight] = useState('0');
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
const height = isOpen ? get(wrapperRef.current, 'offsetHeight', 0) : 0;
|
|
140
|
-
setMaxHeight(`${height}px`);
|
|
141
|
-
}, [children, isOpen]);
|
|
142
|
-
|
|
143
134
|
return (
|
|
144
135
|
<section ref={ref} {...forwardedProps} className={rootClassName}>
|
|
145
136
|
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}
|
|
@@ -161,15 +152,15 @@ export const ExpansionPanel = forwardRef<ExpansionPanelProps, HTMLDivElement>((p
|
|
|
161
152
|
</div>
|
|
162
153
|
</header>
|
|
163
154
|
|
|
164
|
-
{
|
|
165
|
-
|
|
155
|
+
<div className={`${CLASSNAME}__wrapper`}>
|
|
156
|
+
{(isOpen || isChildrenVisible) && (
|
|
166
157
|
<div className={`${CLASSNAME}__container`} ref={wrapperRef}>
|
|
167
158
|
<div className={`${CLASSNAME}__content`}>{content}</div>
|
|
168
159
|
|
|
169
160
|
{footer && <div className={`${CLASSNAME}__footer`}>{footer}</div>}
|
|
170
161
|
</div>
|
|
171
|
-
|
|
172
|
-
|
|
162
|
+
)}
|
|
163
|
+
</div>
|
|
173
164
|
</section>
|
|
174
165
|
);
|
|
175
166
|
});
|
|
@@ -3,9 +3,9 @@ import React from 'react';
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
|
|
5
5
|
import { mdiAlertCircle } from '@lumx/icons';
|
|
6
|
-
import { ColorPalette, ColorVariant, Size, Theme } from '@lumx/react';
|
|
6
|
+
import { ColorPalette, ColorVariant, ColorWithVariants, Size, Theme } from '@lumx/react';
|
|
7
7
|
import { GenericProps, HasTheme } from '@lumx/react/utils/type';
|
|
8
|
-
import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
|
|
8
|
+
import { getRootClassName, handleBasicClasses, resolveColorWithVariants } from '@lumx/react/utils/className';
|
|
9
9
|
import { forwardRef } from '@lumx/react/utils/react/forwardRef';
|
|
10
10
|
import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
|
|
11
11
|
|
|
@@ -16,7 +16,7 @@ export type IconSizes = Extract<Size, 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'x
|
|
|
16
16
|
*/
|
|
17
17
|
export interface IconProps extends GenericProps, HasTheme {
|
|
18
18
|
/** Color variant. */
|
|
19
|
-
color?:
|
|
19
|
+
color?: ColorWithVariants;
|
|
20
20
|
/** Lightened or darkened variant of the selected icon color. */
|
|
21
21
|
colorVariant?: ColorVariant;
|
|
22
22
|
/** Whether the icon has a shape. */
|
|
@@ -58,8 +58,8 @@ export const Icon = forwardRef<IconProps, HTMLElement>((props, ref) => {
|
|
|
58
58
|
const defaultTheme = useTheme();
|
|
59
59
|
const {
|
|
60
60
|
className,
|
|
61
|
-
color,
|
|
62
|
-
colorVariant,
|
|
61
|
+
color: propColor,
|
|
62
|
+
colorVariant: propColorVariant,
|
|
63
63
|
hasShape,
|
|
64
64
|
icon,
|
|
65
65
|
size,
|
|
@@ -67,6 +67,7 @@ export const Icon = forwardRef<IconProps, HTMLElement>((props, ref) => {
|
|
|
67
67
|
alt,
|
|
68
68
|
...forwardedProps
|
|
69
69
|
} = props;
|
|
70
|
+
const [color, colorVariant] = resolveColorWithVariants(propColor, propColorVariant);
|
|
70
71
|
|
|
71
72
|
// Color
|
|
72
73
|
let iconColor = color;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { CSSProperties, ReactNode } from 'react';
|
|
2
2
|
|
|
3
|
-
import { FlexBox, HorizontalAlignment, Text, TextProps } from '@lumx/react';
|
|
3
|
+
import { FlexBox, HorizontalAlignment, Text, TextProps, useTheme } from '@lumx/react';
|
|
4
4
|
import { HasPolymorphicAs, HasTheme } from '@lumx/react/utils/type';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
6
|
|
|
@@ -36,9 +36,10 @@ export type ImageCaptionProps<AS extends As = 'figcaption'> = HasTheme &
|
|
|
36
36
|
|
|
37
37
|
/** Internal component used to render image captions */
|
|
38
38
|
export const ImageCaption = <AS extends As>(props: ImageCaptionProps<AS>) => {
|
|
39
|
+
const defaultTheme = useTheme();
|
|
39
40
|
const {
|
|
40
41
|
baseClassName,
|
|
41
|
-
theme,
|
|
42
|
+
theme = defaultTheme,
|
|
42
43
|
as = 'figcaption',
|
|
43
44
|
title,
|
|
44
45
|
titleProps,
|
|
@@ -24,12 +24,8 @@ const MULTIPLE_IMAGES: ImageLightboxProps['images'] = [
|
|
|
24
24
|
description: 'A black labrador puppy with big brown eyes, looking up with a curious and innocent expression.',
|
|
25
25
|
tags: (
|
|
26
26
|
<ChipGroup>
|
|
27
|
-
<Chip
|
|
28
|
-
|
|
29
|
-
</Chip>
|
|
30
|
-
<Chip theme="dark" size="s">
|
|
31
|
-
Tag 2
|
|
32
|
-
</Chip>
|
|
27
|
+
<Chip size="s">Tag 1</Chip>
|
|
28
|
+
<Chip size="s">Tag 2</Chip>
|
|
33
29
|
</ChipGroup>
|
|
34
30
|
),
|
|
35
31
|
},
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
|
|
5
|
-
import { Lightbox } from '@lumx/react';
|
|
5
|
+
import { Lightbox, ThemeProvider } from '@lumx/react';
|
|
6
6
|
import { ClickAwayProvider } from '@lumx/react/utils';
|
|
7
7
|
import { useMergeRefs } from '@lumx/react/utils/react/mergeRefs';
|
|
8
8
|
import { forwardRef } from '@lumx/react/utils/react/forwardRef';
|
|
@@ -60,17 +60,19 @@ const Inner = forwardRef<ImageLightboxProps, HTMLDivElement>((props, ref) => {
|
|
|
60
60
|
preventAutoClose
|
|
61
61
|
>
|
|
62
62
|
<ClickAwayProvider childrenRefs={clickAwayChildrenRefs} callback={onClickAway}>
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
<ThemeProvider value="dark">
|
|
64
|
+
<ImageSlideshow
|
|
65
|
+
activeImageIndex={activeImageIndex}
|
|
66
|
+
slideGroupLabel={slideGroupLabel}
|
|
67
|
+
slideshowControlsProps={slideshowControlsProps}
|
|
68
|
+
images={images}
|
|
69
|
+
zoomInButtonProps={zoomInButtonProps}
|
|
70
|
+
zoomOutButtonProps={zoomOutButtonProps}
|
|
71
|
+
footerRef={footerRef}
|
|
72
|
+
activeImageRef={useMergeRefs(propImageRef, imageRef)}
|
|
73
|
+
currentPaginationItemRef={currentPaginationItemRef}
|
|
74
|
+
/>
|
|
75
|
+
</ThemeProvider>
|
|
74
76
|
</ClickAwayProvider>
|
|
75
77
|
</Lightbox>
|
|
76
78
|
);
|
|
@@ -48,14 +48,13 @@ export const ImageSlideshow: React.FC<ImageSlideshowProps> = ({
|
|
|
48
48
|
const tags = images[activeIndex]?.tags;
|
|
49
49
|
const metadata =
|
|
50
50
|
title || description || tags ? (
|
|
51
|
-
<ImageCaption
|
|
51
|
+
<ImageCaption as="div" title={title} description={description} tags={tags} align="center" />
|
|
52
52
|
) : null;
|
|
53
53
|
|
|
54
54
|
// Slideshow controls
|
|
55
55
|
const slideShowControls =
|
|
56
56
|
slidesCount > 1 && slideshowControlsProps ? (
|
|
57
57
|
<SlideshowControls
|
|
58
|
-
theme="dark"
|
|
59
58
|
activeIndex={activeIndex}
|
|
60
59
|
slidesCount={slidesCount}
|
|
61
60
|
onNextClick={onNextClick}
|
|
@@ -93,16 +92,9 @@ export const ImageSlideshow: React.FC<ImageSlideshowProps> = ({
|
|
|
93
92
|
}, [activeIndex]);
|
|
94
93
|
const zoomControls = zoomEnabled && (
|
|
95
94
|
<>
|
|
96
|
-
<IconButton
|
|
97
|
-
{...zoomInButtonProps}
|
|
98
|
-
theme="dark"
|
|
99
|
-
emphasis="low"
|
|
100
|
-
icon={mdiMagnifyPlusOutline}
|
|
101
|
-
onClick={zoomIn}
|
|
102
|
-
/>
|
|
95
|
+
<IconButton {...zoomInButtonProps} emphasis="low" icon={mdiMagnifyPlusOutline} onClick={zoomIn} />
|
|
103
96
|
<IconButton
|
|
104
97
|
{...zoomOutButtonProps}
|
|
105
|
-
theme="dark"
|
|
106
98
|
emphasis="low"
|
|
107
99
|
isDisabled={!scale || scale <= 1}
|
|
108
100
|
icon={mdiMagnifyMinusOutline}
|
|
@@ -127,7 +119,6 @@ export const ImageSlideshow: React.FC<ImageSlideshowProps> = ({
|
|
|
127
119
|
<>
|
|
128
120
|
<Slides
|
|
129
121
|
activeIndex={activeIndex}
|
|
130
|
-
theme="dark"
|
|
131
122
|
slideGroupLabel={slideGroupLabel}
|
|
132
123
|
fillHeight
|
|
133
124
|
id={slideshowId}
|
package/src/components/index.ts
CHANGED
|
@@ -19,39 +19,6 @@ export type Alignment = ValueOf<typeof Alignment>;
|
|
|
19
19
|
export type VerticalAlignment = Extract<Alignment, 'top' | 'center' | 'bottom'>;
|
|
20
20
|
export type HorizontalAlignment = Extract<Alignment, 'right' | 'center' | 'left'>;
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* See SCSS variable $lumx-color-palette
|
|
24
|
-
*/
|
|
25
|
-
export const ColorPalette = {
|
|
26
|
-
primary: 'primary',
|
|
27
|
-
secondary: 'secondary',
|
|
28
|
-
blue: 'blue',
|
|
29
|
-
dark: 'dark',
|
|
30
|
-
green: 'green',
|
|
31
|
-
yellow: 'yellow',
|
|
32
|
-
red: 'red',
|
|
33
|
-
light: 'light',
|
|
34
|
-
grey: 'grey',
|
|
35
|
-
} as const;
|
|
36
|
-
export type ColorPalette = ValueOf<typeof ColorPalette>;
|
|
37
|
-
export type Color = ColorPalette | string;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* See SCSS variable $lumx-color-variants
|
|
41
|
-
*/
|
|
42
|
-
export const ColorVariant = {
|
|
43
|
-
D1: 'D1',
|
|
44
|
-
D2: 'D2',
|
|
45
|
-
L1: 'L1',
|
|
46
|
-
L2: 'L2',
|
|
47
|
-
L3: 'L3',
|
|
48
|
-
L4: 'L4',
|
|
49
|
-
L5: 'L5',
|
|
50
|
-
L6: 'L6',
|
|
51
|
-
N: 'N',
|
|
52
|
-
} as const;
|
|
53
|
-
export type ColorVariant = ValueOf<typeof ColorVariant>;
|
|
54
|
-
|
|
55
22
|
export const Theme = {
|
|
56
23
|
light: 'light',
|
|
57
24
|
dark: 'dark',
|
|
@@ -189,3 +156,5 @@ export type WhiteSpace = ValueOf<typeof WhiteSpace>;
|
|
|
189
156
|
* Re-exporting some utils types.
|
|
190
157
|
*/
|
|
191
158
|
export type { HeadingElement, TextElement, GenericProps, Callback } from '../utils/type';
|
|
159
|
+
|
|
160
|
+
export * from '../utils/type/color';
|
|
@@ -2,9 +2,9 @@ import React, { Children, isValidElement } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { ColorVariant, ColorWithVariants, Typography } from '@lumx/react';
|
|
6
6
|
import { GenericProps } from '@lumx/react/utils/type';
|
|
7
|
-
import {
|
|
7
|
+
import { fontColorClass, getRootClassName, getTypographyClassName } from '@lumx/react/utils/className';
|
|
8
8
|
import { forwardRef } from '@lumx/react/utils/react/forwardRef';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -14,7 +14,7 @@ export interface InlineListProps extends GenericProps {
|
|
|
14
14
|
/**
|
|
15
15
|
* Text color.
|
|
16
16
|
*/
|
|
17
|
-
color?:
|
|
17
|
+
color?: ColorWithVariants;
|
|
18
18
|
/**
|
|
19
19
|
* Lightened or darkened variant of the selected color.
|
|
20
20
|
*/
|
|
@@ -57,7 +57,6 @@ const DEFAULT_PROPS = {} as const;
|
|
|
57
57
|
*/
|
|
58
58
|
export const InlineList = forwardRef<InlineListProps>((props, ref) => {
|
|
59
59
|
const { className, color, colorVariant, typography, children, wrap, ...forwardedProps } = props;
|
|
60
|
-
const fontColorClassName = color && getFontColorClassName(color, colorVariant);
|
|
61
60
|
const typographyClassName = typography && getTypographyClassName(typography);
|
|
62
61
|
return (
|
|
63
62
|
// eslint-disable-next-line jsx-a11y/no-redundant-roles
|
|
@@ -68,7 +67,7 @@ export const InlineList = forwardRef<InlineListProps>((props, ref) => {
|
|
|
68
67
|
className,
|
|
69
68
|
CLASSNAME,
|
|
70
69
|
wrap && `${CLASSNAME}--wrap`,
|
|
71
|
-
|
|
70
|
+
fontColorClass(color, colorVariant),
|
|
72
71
|
typographyClassName,
|
|
73
72
|
)}
|
|
74
73
|
// Lists with removed bullet style can lose their a11y list role on some browsers
|
|
@@ -2,9 +2,14 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { ColorVariant, ColorWithVariants, Icon, Typography } from '@lumx/react';
|
|
6
6
|
import { GenericProps } from '@lumx/react/utils/type';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
getRootClassName,
|
|
9
|
+
getTypographyClassName,
|
|
10
|
+
handleBasicClasses,
|
|
11
|
+
resolveColorWithVariants,
|
|
12
|
+
} from '@lumx/react/utils/className';
|
|
8
13
|
import { forwardRef } from '@lumx/react/utils/react/forwardRef';
|
|
9
14
|
import { wrapChildrenIconWithSpaces } from '@lumx/react/utils/react/wrapChildrenIconWithSpaces';
|
|
10
15
|
|
|
@@ -15,7 +20,7 @@ type HTMLAnchorProps = React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAn
|
|
|
15
20
|
*/
|
|
16
21
|
export interface LinkProps extends GenericProps {
|
|
17
22
|
/** Color variant. */
|
|
18
|
-
color?:
|
|
23
|
+
color?: ColorWithVariants;
|
|
19
24
|
/** Lightened or darkened variant of the selected icon color. */
|
|
20
25
|
colorVariant?: ColorVariant;
|
|
21
26
|
/** Link href. */
|
|
@@ -63,8 +68,8 @@ export const Link = forwardRef<LinkProps, HTMLAnchorElement | HTMLButtonElement>
|
|
|
63
68
|
const {
|
|
64
69
|
children,
|
|
65
70
|
className,
|
|
66
|
-
color,
|
|
67
|
-
colorVariant,
|
|
71
|
+
color: propColor,
|
|
72
|
+
colorVariant: propColorVariant,
|
|
68
73
|
disabled,
|
|
69
74
|
isDisabled = disabled,
|
|
70
75
|
href,
|
|
@@ -75,6 +80,7 @@ export const Link = forwardRef<LinkProps, HTMLAnchorElement | HTMLButtonElement>
|
|
|
75
80
|
typography,
|
|
76
81
|
...forwardedProps
|
|
77
82
|
} = props;
|
|
83
|
+
const [color, colorVariant] = resolveColorWithVariants(propColor, propColorVariant);
|
|
78
84
|
|
|
79
85
|
const isLink = linkAs || href;
|
|
80
86
|
const Component = isLink && !isDisabled ? linkAs || 'a' : 'button';
|
|
@@ -2,10 +2,10 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { ColorWithVariants, ColorVariant, Typography, WhiteSpace } from '@lumx/react';
|
|
6
6
|
import { GenericProps, TextElement } from '@lumx/react/utils/type';
|
|
7
7
|
import {
|
|
8
|
-
|
|
8
|
+
fontColorClass,
|
|
9
9
|
getRootClassName,
|
|
10
10
|
handleBasicClasses,
|
|
11
11
|
getTypographyClassName,
|
|
@@ -22,7 +22,7 @@ export interface TextProps extends GenericProps {
|
|
|
22
22
|
/**
|
|
23
23
|
* Color variant.
|
|
24
24
|
*/
|
|
25
|
-
color?:
|
|
25
|
+
color?: ColorWithVariants;
|
|
26
26
|
/**
|
|
27
27
|
* Lightened or darkened variant of the selected color.
|
|
28
28
|
*/
|
|
@@ -95,7 +95,6 @@ export const Text = forwardRef<TextProps>((props, ref) => {
|
|
|
95
95
|
...forwardedProps
|
|
96
96
|
} = props;
|
|
97
97
|
|
|
98
|
-
const colorClass = color && getFontColorClassName(color, colorVariant);
|
|
99
98
|
const typographyClass = typography && getTypographyClassName(typography);
|
|
100
99
|
|
|
101
100
|
// Truncate mode
|
|
@@ -126,7 +125,7 @@ export const Text = forwardRef<TextProps>((props, ref) => {
|
|
|
126
125
|
isTruncatedMultiline,
|
|
127
126
|
}),
|
|
128
127
|
typographyClass,
|
|
129
|
-
|
|
128
|
+
fontColorClass(color, colorVariant),
|
|
130
129
|
noWrap && `${CLASSNAME}--no-wrap`,
|
|
131
130
|
)}
|
|
132
131
|
title={tooltipLabel}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { fontColorClass } from '@lumx/react/utils/className/fontColorClass';
|
|
2
|
+
|
|
3
|
+
describe(fontColorClass, () => {
|
|
4
|
+
it('should get lumx class for font color', () => {
|
|
5
|
+
expect(fontColorClass('dark')).toBe('lumx-color-font-dark-N');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should get lumx class for font color with variant', () => {
|
|
9
|
+
expect(fontColorClass('red', 'L2')).toBe('lumx-color-font-red-L2');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should get lumx class for font color with variant with override', () => {
|
|
13
|
+
expect(fontColorClass('red-N', 'L2')).toBe('lumx-color-font-red-L2');
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ColorVariant, ColorWithVariants } from '@lumx/react';
|
|
2
|
+
import { resolveColorWithVariants } from '@lumx/react/utils/className';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the classname associated to the given color and variant.
|
|
6
|
+
* For example, for 'dark' and 'L2' it returns `lumx-color-font-dark-L2`
|
|
7
|
+
*/
|
|
8
|
+
export function fontColorClass(propColor?: ColorWithVariants, propColorVariant?: ColorVariant) {
|
|
9
|
+
if (!propColor) return undefined;
|
|
10
|
+
const [color, colorVariant = ColorVariant.N] = resolveColorWithVariants(propColor, propColorVariant);
|
|
11
|
+
return `lumx-color-font-${color}-${colorVariant}`;
|
|
12
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getBasicClass, handleBasicClasses } from '@lumx/core/js/utils';
|
|
2
2
|
export { getRootClassName } from './getRootClassName';
|
|
3
3
|
export { getTypographyClassName } from './getTypographyClassName';
|
|
4
|
-
export {
|
|
4
|
+
export { fontColorClass } from './fontColorClass';
|
|
5
|
+
export { resolveColorWithVariants } from './resolveColorWithVariants';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { resolveColorWithVariants } from './resolveColorWithVariants';
|
|
2
|
+
|
|
3
|
+
describe(resolveColorWithVariants, () => {
|
|
4
|
+
it('should handle undefined color', () => {
|
|
5
|
+
const result = resolveColorWithVariants(undefined);
|
|
6
|
+
expect(result).toEqual([undefined, undefined]);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('should handle undefined color with variant', () => {
|
|
10
|
+
const result = resolveColorWithVariants(undefined, 'L2');
|
|
11
|
+
expect(result).toEqual([undefined, 'L2']);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should handle color with undefined variant', () => {
|
|
15
|
+
const result = resolveColorWithVariants('primary');
|
|
16
|
+
expect(result).toEqual(['primary', undefined]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should handle color & variant separated', () => {
|
|
20
|
+
const result = resolveColorWithVariants('primary', 'L2');
|
|
21
|
+
expect(result).toEqual(['primary', 'L2']);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should handle color with variant all in one', () => {
|
|
25
|
+
const result = resolveColorWithVariants('primary-L2');
|
|
26
|
+
expect(result).toEqual(['primary', 'L2']);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should override color variant with the given color variant', () => {
|
|
30
|
+
const result = resolveColorWithVariants('primary-L2', 'D2');
|
|
31
|
+
expect(result).toEqual(['primary', 'D2']);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ColorPalette, ColorVariant, ColorWithVariants } from '@lumx/react';
|
|
2
|
+
|
|
3
|
+
/** Resolve color & color variant from a `ColorWithVariants` and optionally a `ColorVariant`. */
|
|
4
|
+
export function resolveColorWithVariants(
|
|
5
|
+
colorWithVariants?: ColorWithVariants,
|
|
6
|
+
colorVariant?: ColorVariant,
|
|
7
|
+
): [color?: ColorPalette, colorVariant?: ColorVariant] {
|
|
8
|
+
if (!colorWithVariants) return [undefined, colorVariant];
|
|
9
|
+
const [color, baseColorVariant] = colorWithVariants.split('-');
|
|
10
|
+
return [color as ColorPalette, (colorVariant || baseColorVariant) as ColorVariant];
|
|
11
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ValueOf } from '@lumx/react/utils/type';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* See SCSS variable $lumx-color-palette
|
|
5
|
+
*/
|
|
6
|
+
export const ColorPalette = {
|
|
7
|
+
primary: 'primary',
|
|
8
|
+
secondary: 'secondary',
|
|
9
|
+
blue: 'blue',
|
|
10
|
+
dark: 'dark',
|
|
11
|
+
green: 'green',
|
|
12
|
+
yellow: 'yellow',
|
|
13
|
+
red: 'red',
|
|
14
|
+
light: 'light',
|
|
15
|
+
grey: 'grey',
|
|
16
|
+
} as const;
|
|
17
|
+
export type ColorPalette = ValueOf<typeof ColorPalette>;
|
|
18
|
+
export type Color = ColorPalette | string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* See SCSS variable $lumx-color-variants
|
|
22
|
+
*/
|
|
23
|
+
export const ColorVariant = {
|
|
24
|
+
D1: 'D1',
|
|
25
|
+
D2: 'D2',
|
|
26
|
+
L1: 'L1',
|
|
27
|
+
L2: 'L2',
|
|
28
|
+
L3: 'L3',
|
|
29
|
+
L4: 'L4',
|
|
30
|
+
L5: 'L5',
|
|
31
|
+
L6: 'L6',
|
|
32
|
+
N: 'N',
|
|
33
|
+
} as const;
|
|
34
|
+
export type ColorVariant = ValueOf<typeof ColorVariant>;
|
|
35
|
+
|
|
36
|
+
/** ColorPalette with all possible color variant combination */
|
|
37
|
+
export type ColorWithVariants =
|
|
38
|
+
| ColorPalette
|
|
39
|
+
| Exclude<
|
|
40
|
+
`${ColorPalette}-${ColorVariant}`,
|
|
41
|
+
// No dark variant for light and dark
|
|
42
|
+
`light-D${number}` | `dark-D${number}`
|
|
43
|
+
>;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { getFontColorClassName } from '@lumx/react/utils/className/getFontColorClassName';
|
|
2
|
-
|
|
3
|
-
describe(getFontColorClassName, () => {
|
|
4
|
-
it('should get lumx class for font color', () => {
|
|
5
|
-
expect(getFontColorClassName('dark')).toBe('lumx-color-font-dark-N');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
it('should get lumx class for font color with variant', () => {
|
|
9
|
-
expect(getFontColorClassName('red', 'L2')).toBe('lumx-color-font-red-L2');
|
|
10
|
-
});
|
|
11
|
-
});
|