@true-engineering/true-react-common-ui-kit 4.0.0-alpha61 → 4.0.0-alpha62
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/dist/components/List/List.d.ts +2 -1
- package/dist/components/List/List.styles.d.ts +2 -1
- package/dist/components/List/components/ListItem/ListItem.d.ts +2 -0
- package/dist/components/List/components/ListItem/ListItem.styles.d.ts +2 -1
- package/dist/components/List/index.d.ts +1 -1
- package/dist/components/List/types.d.ts +4 -0
- package/dist/components/NewMoreMenu/NewMoreMenu.d.ts +5 -2
- package/dist/true-react-common-ui-kit.js +50 -38
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/components/List/List.stories.tsx +12 -0
- package/src/components/List/List.styles.ts +2 -1
- package/src/components/List/List.tsx +10 -4
- package/src/components/List/components/ListItem/ListItem.styles.ts +2 -1
- package/src/components/List/components/ListItem/ListItem.tsx +5 -1
- package/src/components/List/index.ts +1 -1
- package/src/components/List/types.ts +6 -0
- package/src/components/NewMoreMenu/NewMoreMenu.stories.tsx +10 -0
- package/src/components/NewMoreMenu/NewMoreMenu.tsx +28 -19
package/package.json
CHANGED
|
@@ -2,9 +2,17 @@ import { FC } from 'react';
|
|
|
2
2
|
import { type Meta } from '@storybook/react';
|
|
3
3
|
import { excludeStorybookParams } from '../../helpers';
|
|
4
4
|
import { colors } from '../../theme';
|
|
5
|
+
import { IExtendableProps } from '../../types';
|
|
5
6
|
import { IListProps, List } from './List';
|
|
6
7
|
import { IListItemProps as IListItem } from './components';
|
|
7
8
|
|
|
9
|
+
const SIZES = ['micro'] as const;
|
|
10
|
+
|
|
11
|
+
declare module './types' {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
13
|
+
export interface IListSizes extends IExtendableProps<typeof SIZES> {}
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
const listItems: IListItem[] = [
|
|
9
17
|
{
|
|
10
18
|
item: 'Печатать билет',
|
|
@@ -83,6 +91,10 @@ const meta: Meta<typeof Story> = {
|
|
|
83
91
|
component: Story,
|
|
84
92
|
args: {
|
|
85
93
|
items: listItems,
|
|
94
|
+
size: undefined,
|
|
95
|
+
},
|
|
96
|
+
argTypes: {
|
|
97
|
+
size: { options: [undefined, ...SIZES], control: 'inline-radio' },
|
|
86
98
|
},
|
|
87
99
|
parameters: {
|
|
88
100
|
controls: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { colors, createThemedStyles, ITweakStyles } from '../../theme';
|
|
2
2
|
import { IWithPopupStyles } from '../WithPopup';
|
|
3
|
+
import { IListSizes } from './types';
|
|
3
4
|
|
|
4
5
|
export const useStyles = createThemedStyles('List', {
|
|
5
6
|
root: {
|
|
@@ -23,4 +24,4 @@ export const withPopupStyles: IWithPopupStyles = {
|
|
|
23
24
|
},
|
|
24
25
|
};
|
|
25
26
|
|
|
26
|
-
export type IListStyles = ITweakStyles<typeof useStyles>;
|
|
27
|
+
export type IListStyles = ITweakStyles<typeof useStyles, IListSizes>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FC, Fragment, KeyboardEvent, MouseEvent } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
2
3
|
import {
|
|
3
4
|
addDataAttributes,
|
|
4
5
|
getTestId,
|
|
@@ -8,15 +9,16 @@ import {
|
|
|
8
9
|
import { ICommonProps } from '../../types';
|
|
9
10
|
import { WithPopup } from '../WithPopup';
|
|
10
11
|
import { IListItemProps, ListItem } from './components';
|
|
11
|
-
import { IListItem } from './types';
|
|
12
|
+
import { IListItem, IListSize } from './types';
|
|
12
13
|
import { useStyles, IListStyles, withPopupStyles } from './List.styles';
|
|
13
14
|
|
|
14
15
|
export interface IListProps extends ICommonProps<IListStyles> {
|
|
15
16
|
items: IListItem[];
|
|
17
|
+
size?: IListSize;
|
|
16
18
|
onClick?: (event: MouseEvent | KeyboardEvent) => void;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
export const List: FC<IListProps> = ({ items, testId, data, tweakStyles, onClick }) => {
|
|
21
|
+
export const List: FC<IListProps> = ({ items, size, testId, data, tweakStyles, onClick }) => {
|
|
20
22
|
const classes = useStyles({ theme: tweakStyles });
|
|
21
23
|
|
|
22
24
|
const handleItemClick = (
|
|
@@ -32,10 +34,14 @@ export const List: FC<IListProps> = ({ items, testId, data, tweakStyles, onClick
|
|
|
32
34
|
const filteredItems = items.filter(({ isHidden }) => !isHidden);
|
|
33
35
|
|
|
34
36
|
return (
|
|
35
|
-
<div
|
|
37
|
+
<div
|
|
38
|
+
className={clsx(classes.root, isNotEmpty(size) && classes[size])}
|
|
39
|
+
{...addDataAttributes(data, testId)}
|
|
40
|
+
>
|
|
36
41
|
{filteredItems.map((item, i) => {
|
|
37
42
|
const itemProps: IListItemProps = {
|
|
38
43
|
testId: getTestId(testId, `item-${i}`),
|
|
44
|
+
size,
|
|
39
45
|
...item,
|
|
40
46
|
shouldDrawSpacerAbove: item.shouldDrawSpacerAbove && i !== 0,
|
|
41
47
|
shouldDrawSpacerBelow: item.shouldDrawSpacerBelow && i !== items.length - 1,
|
|
@@ -56,7 +62,7 @@ export const List: FC<IListProps> = ({ items, testId, data, tweakStyles, onClick
|
|
|
56
62
|
)}
|
|
57
63
|
>
|
|
58
64
|
<div className={classes.nestedItems}>
|
|
59
|
-
<List items={item.nestedItems} onClick={onClick} />
|
|
65
|
+
<List items={item.nestedItems} size={size} onClick={onClick} />
|
|
60
66
|
</div>
|
|
61
67
|
</WithPopup>
|
|
62
68
|
) : (
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { animations, colors, createThemedStyles, ITweakStyles } from '../../../../theme';
|
|
2
|
+
import type { IListSizes as IListItemSizes } from '../../types';
|
|
2
3
|
|
|
3
4
|
const ITEM_HORIZONTAL_PADDING = 16;
|
|
4
5
|
const ICON_SIZE = 20;
|
|
@@ -49,4 +50,4 @@ export const useStyles = createThemedStyles('ListItem', {
|
|
|
49
50
|
},
|
|
50
51
|
});
|
|
51
52
|
|
|
52
|
-
export type IListItemStyles = ITweakStyles<typeof useStyles>;
|
|
53
|
+
export type IListItemStyles = ITweakStyles<typeof useStyles, IListItemSizes>;
|
|
@@ -4,10 +4,12 @@ import {
|
|
|
4
4
|
addClickHandler,
|
|
5
5
|
addDataAttributes,
|
|
6
6
|
isArrayNotEmpty,
|
|
7
|
+
isNotEmpty,
|
|
7
8
|
isReactNodeNotEmpty,
|
|
8
9
|
} from '@true-engineering/true-react-platform-helpers';
|
|
9
10
|
import { ICommonProps } from '../../../../types';
|
|
10
11
|
import { renderIcon, IIcon, Icon } from '../../../Icon';
|
|
12
|
+
import type { IListSize as IListItemSize } from '../../types';
|
|
11
13
|
import { useStyles, IListItemStyles } from './ListItem.styles';
|
|
12
14
|
|
|
13
15
|
export interface IListItemProps extends ICommonProps<IListItemStyles> {
|
|
@@ -15,6 +17,7 @@ export interface IListItemProps extends ICommonProps<IListItemStyles> {
|
|
|
15
17
|
view?: 'default' | 'destructive';
|
|
16
18
|
icon?: IIcon;
|
|
17
19
|
nestedItems?: IListItemProps[];
|
|
20
|
+
size?: IListItemSize;
|
|
18
21
|
isFocused?: boolean;
|
|
19
22
|
disabled?: boolean;
|
|
20
23
|
shouldDrawSpacerAbove?: boolean;
|
|
@@ -27,6 +30,7 @@ export const ListItem: FC<IListItemProps> = ({
|
|
|
27
30
|
icon,
|
|
28
31
|
item,
|
|
29
32
|
nestedItems,
|
|
33
|
+
size,
|
|
30
34
|
disabled: isDisabled,
|
|
31
35
|
isFocused,
|
|
32
36
|
shouldDrawSpacerAbove,
|
|
@@ -44,7 +48,7 @@ export const ListItem: FC<IListItemProps> = ({
|
|
|
44
48
|
<>
|
|
45
49
|
{shouldDrawSpacerAbove && <div className={classes.spacer} />}
|
|
46
50
|
<div
|
|
47
|
-
className={clsx(classes.root, classes[view], {
|
|
51
|
+
className={clsx(classes.root, classes[view], isNotEmpty(size) && classes[size], {
|
|
48
52
|
[classes.disabledItem]: isDisabled,
|
|
49
53
|
[classes.withIconGap]: withIconGap,
|
|
50
54
|
[classes.focused]: isFocused,
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { IListItemProps } from './components';
|
|
2
2
|
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
4
|
+
export interface IListSizes {}
|
|
5
|
+
|
|
6
|
+
export type IListSize = keyof IListSizes;
|
|
7
|
+
|
|
3
8
|
export interface IListItem extends IListItemProps {
|
|
4
9
|
isHidden?: boolean;
|
|
10
|
+
size?: IListSize;
|
|
5
11
|
}
|
|
@@ -2,9 +2,17 @@ import { FC } from 'react';
|
|
|
2
2
|
import { type Meta } from '@storybook/react';
|
|
3
3
|
import { excludeStorybookParams } from '../../helpers';
|
|
4
4
|
import { colors } from '../../theme';
|
|
5
|
+
import { IExtendableProps } from '../../types';
|
|
5
6
|
import { IListItem } from '../List';
|
|
6
7
|
import { INewMoreMenuProps, NewMoreMenu } from './NewMoreMenu';
|
|
7
8
|
|
|
9
|
+
const SIZES = ['micro'] as const;
|
|
10
|
+
|
|
11
|
+
declare module '../List/types' {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
13
|
+
export interface IListSizes extends IExtendableProps<typeof SIZES> {}
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
const menuItems: IListItem[] = [
|
|
9
17
|
{ item: 'Печатать билет', onClick: console.log },
|
|
10
18
|
{ item: 'Выписать', onClick: console.log },
|
|
@@ -61,9 +69,11 @@ const meta: Meta<typeof Story> = {
|
|
|
61
69
|
placement: 'bottom-end',
|
|
62
70
|
shouldRenderInBody: false,
|
|
63
71
|
shouldHideOnScroll: false,
|
|
72
|
+
listSize: undefined,
|
|
64
73
|
},
|
|
65
74
|
argTypes: {
|
|
66
75
|
placement: { control: 'select', options: placements },
|
|
76
|
+
listSize: { options: [undefined, ...SIZES], control: 'inline-radio' },
|
|
67
77
|
},
|
|
68
78
|
parameters: {
|
|
69
79
|
controls: {
|
|
@@ -2,10 +2,11 @@ import { FC } from 'react';
|
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import { addDataAttributes, isArrayEmpty } from '@true-engineering/true-react-platform-helpers';
|
|
4
4
|
import { useTweakStyles } from '../../hooks';
|
|
5
|
-
import { ICommonProps } from '../../types';
|
|
5
|
+
import { ICommonProps, IRenderNode } from '../../types';
|
|
6
6
|
import { Icon } from '../Icon';
|
|
7
|
-
import { IListItem, List } from '../List';
|
|
7
|
+
import { IListItem, IListSize, List } from '../List';
|
|
8
8
|
import { IWithPopupProps, WithPopup } from '../WithPopup';
|
|
9
|
+
import { IWithPopupTriggerProps } from '../WithPopup/types';
|
|
9
10
|
import { useStyles, INewMoreMenuStyles } from './NewMoreMenu.styles';
|
|
10
11
|
|
|
11
12
|
export interface INewMoreMenuProps
|
|
@@ -20,6 +21,8 @@ export interface INewMoreMenuProps
|
|
|
20
21
|
>,
|
|
21
22
|
ICommonProps<INewMoreMenuStyles> {
|
|
22
23
|
items: IListItem[];
|
|
24
|
+
renderTrigger?: IRenderNode<IWithPopupTriggerProps>;
|
|
25
|
+
listSize?: IListSize;
|
|
23
26
|
/** @default false */
|
|
24
27
|
isDisabled?: boolean;
|
|
25
28
|
/** @default true */
|
|
@@ -31,6 +34,8 @@ export const NewMoreMenu: FC<INewMoreMenuProps> = ({
|
|
|
31
34
|
isDisabled = false,
|
|
32
35
|
hasDefaultStateBackground = true,
|
|
33
36
|
data,
|
|
37
|
+
renderTrigger,
|
|
38
|
+
listSize,
|
|
34
39
|
testId,
|
|
35
40
|
tweakStyles,
|
|
36
41
|
...rest
|
|
@@ -49,29 +54,33 @@ export const NewMoreMenu: FC<INewMoreMenuProps> = ({
|
|
|
49
54
|
currentComponentName: 'NewMoreMenu',
|
|
50
55
|
});
|
|
51
56
|
|
|
57
|
+
const defaultTrigger = ({ triggerProps, referenceProps }: IWithPopupTriggerProps) => (
|
|
58
|
+
<button
|
|
59
|
+
className={clsx(classes.button, {
|
|
60
|
+
[classes.hasCircle]: hasDefaultStateBackground,
|
|
61
|
+
[classes.disabled]: triggerProps.isDisabled,
|
|
62
|
+
[classes.active]: triggerProps.isActive,
|
|
63
|
+
})}
|
|
64
|
+
disabled={triggerProps.isDisabled}
|
|
65
|
+
{...addDataAttributes(data, testId)}
|
|
66
|
+
{...referenceProps}
|
|
67
|
+
>
|
|
68
|
+
<div className={classes.icon}>
|
|
69
|
+
<Icon type="menu" />
|
|
70
|
+
</div>
|
|
71
|
+
</button>
|
|
72
|
+
);
|
|
73
|
+
|
|
52
74
|
return (
|
|
53
75
|
<WithPopup
|
|
54
76
|
isDisabled={isDisabled || isArrayEmpty(items)}
|
|
55
77
|
tweakStyles={tweakWithPopupStyles}
|
|
56
78
|
{...rest}
|
|
57
|
-
trigger={
|
|
58
|
-
<button
|
|
59
|
-
className={clsx(classes.button, {
|
|
60
|
-
[classes.hasCircle]: hasDefaultStateBackground,
|
|
61
|
-
[classes.disabled]: triggerProps.isDisabled,
|
|
62
|
-
[classes.active]: triggerProps.isActive,
|
|
63
|
-
})}
|
|
64
|
-
disabled={triggerProps.isDisabled}
|
|
65
|
-
{...addDataAttributes(data, testId)}
|
|
66
|
-
{...referenceProps}
|
|
67
|
-
>
|
|
68
|
-
<div className={classes.icon}>
|
|
69
|
-
<Icon type="menu" />
|
|
70
|
-
</div>
|
|
71
|
-
</button>
|
|
72
|
-
)}
|
|
79
|
+
trigger={renderTrigger ?? defaultTrigger}
|
|
73
80
|
>
|
|
74
|
-
{({ onClose }) =>
|
|
81
|
+
{({ onClose }) => (
|
|
82
|
+
<List items={items} size={listSize} tweakStyles={tweakListStyles} onClick={onClose} />
|
|
83
|
+
)}
|
|
75
84
|
</WithPopup>
|
|
76
85
|
);
|
|
77
86
|
};
|