@true-engineering/true-react-common-ui-kit 3.0.0-alpha.2 → 3.0.0-alpha.20
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/Checkbox/Checkbox.d.ts +1 -1
- package/dist/components/FiltersPane/components/FilterSelect/FilterSelect.d.ts +1 -5
- package/dist/components/FiltersPane/components/FiltersPaneSearch/FiltersPaneSearch.d.ts +1 -3
- package/dist/components/FlexibleTable/FlexibleTable.d.ts +6 -2
- package/dist/components/FlexibleTable/FlexibleTable.styles.d.ts +1 -1
- package/dist/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.d.ts +1 -1
- package/dist/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.d.ts +1 -1
- package/dist/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.styles.d.ts +1 -1
- package/dist/components/FlexibleTable/helpers.d.ts +3 -0
- package/dist/components/FlexibleTable/types.d.ts +1 -1
- package/dist/components/MultiSelectList/MultiSelectList.d.ts +1 -2
- package/dist/components/Skeleton/Skeleton.d.ts +7 -0
- package/dist/components/Skeleton/Skeleton.styles.d.ts +3 -0
- package/dist/components/Skeleton/index.d.ts +2 -0
- package/dist/components/Switch/Switch.d.ts +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/helpers/phone.d.ts +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/use-merged-refs.d.ts +2 -0
- package/dist/theme/types.d.ts +2 -1
- package/dist/true-react-common-ui-kit.js +1100 -757
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +1099 -756
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/components/Checkbox/Checkbox.tsx +1 -1
- package/src/components/DateInput/DateInput.tsx +1 -9
- package/src/components/DatePicker/DatePicker.stories.tsx +1 -0
- package/src/components/DatePicker/DatePicker.tsx +1 -3
- package/src/components/FiltersPane/FiltersPane.stories.tsx +0 -8
- package/src/components/FiltersPane/components/FilterInterval/FilterInterval.styles.ts +2 -1
- package/src/components/FiltersPane/components/FilterSelect/FilterSelect.styles.ts +3 -1
- package/src/components/FiltersPane/components/FilterSelect/FilterSelect.tsx +1 -6
- package/src/components/FiltersPane/components/FilterWithDates/FilterWithDates.styles.ts +2 -1
- package/src/components/FiltersPane/components/FiltersPaneSearch/FiltersPaneSearch.styles.ts +1 -0
- package/src/components/FiltersPane/components/FiltersPaneSearch/FiltersPaneSearch.tsx +1 -4
- package/src/components/FiltersPane/types.ts +1 -1
- package/src/components/FlexibleTable/FlexibleTable.stories.tsx +15 -12
- package/src/components/FlexibleTable/FlexibleTable.styles.ts +9 -10
- package/src/components/FlexibleTable/FlexibleTable.tsx +124 -60
- package/src/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.styles.ts +4 -0
- package/src/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.tsx +25 -27
- package/src/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.styles.ts +4 -0
- package/src/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.tsx +12 -11
- package/src/components/FlexibleTable/helpers.ts +15 -0
- package/src/components/FlexibleTable/types.ts +1 -1
- package/src/components/MultiSelectList/MultiSelectList.styles.ts +4 -0
- package/src/components/MultiSelectList/MultiSelectList.tsx +1 -3
- package/src/components/Skeleton/Skeleton.stories.tsx +19 -0
- package/src/components/Skeleton/Skeleton.styles.ts +46 -0
- package/src/components/Skeleton/Skeleton.tsx +12 -0
- package/src/components/Skeleton/index.ts +2 -0
- package/src/components/Switch/Switch.tsx +2 -2
- package/src/components/index.ts +1 -0
- package/src/helpers/phone.ts +1 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-merged-refs.ts +4 -0
- package/src/theme/types.ts +2 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import {
|
|
3
|
+
import { isNotEmpty } from '@true-engineering/true-react-platform-helpers';
|
|
4
4
|
import type { ICommonProps } from '../../../../types';
|
|
5
|
-
import {
|
|
5
|
+
import { formatCellContent } from '../../helpers';
|
|
6
6
|
import type { IFlexibleTableConfigType } from '../../types';
|
|
7
7
|
import { useStyles, IFlexibleTableCellStyles } from './FlexibleTableCell.styles';
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ export interface IFlexibleTableCellProps<Values extends Record<string, any>>
|
|
|
10
10
|
extends Pick<ICommonProps<IFlexibleTableCellStyles>, 'tweakStyles'> {
|
|
11
11
|
item: Values;
|
|
12
12
|
columnName: keyof Values;
|
|
13
|
-
config
|
|
13
|
+
config: IFlexibleTableConfigType<Values>;
|
|
14
14
|
isFocusedRow?: boolean;
|
|
15
15
|
isSecond?: boolean;
|
|
16
16
|
isSticky?: boolean;
|
|
@@ -33,39 +33,37 @@ function FlexibleTableCell<Values extends Record<string, any>>({
|
|
|
33
33
|
}: IFlexibleTableCellProps<Values>): JSX.Element {
|
|
34
34
|
const classes = useStyles({ theme: tweakStyles });
|
|
35
35
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
let content = null;
|
|
36
|
+
const { component, cellAlign, position, right, left, cellVerticalAlign } =
|
|
37
|
+
config[columnName] ?? {};
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
const ValueComponent = itemConfig?.component;
|
|
42
|
-
content = ValueComponent({
|
|
43
|
-
value,
|
|
44
|
-
row: item,
|
|
45
|
-
isFocusedRow,
|
|
46
|
-
isNestedComponentExpanded,
|
|
47
|
-
isRowNestedComponentExpanded,
|
|
48
|
-
onSetNestedComponent,
|
|
49
|
-
});
|
|
50
|
-
} else if (typeof value === 'string' || typeof value === 'number') {
|
|
51
|
-
content = value;
|
|
52
|
-
} else if ((value as any) instanceof Date) {
|
|
53
|
-
content = format(value, itemConfig?.dateFormat || DEFAULT_DATE_FORMAT);
|
|
54
|
-
}
|
|
39
|
+
const value = item[columnName];
|
|
55
40
|
|
|
56
41
|
return (
|
|
57
42
|
<td
|
|
58
43
|
key={columnName as string}
|
|
59
44
|
className={clsx(classes.root, { [classes.sticky]: isSticky, [classes.second]: isSecond })}
|
|
60
45
|
style={{
|
|
61
|
-
textAlign:
|
|
62
|
-
position: isSticky ? 'sticky' :
|
|
63
|
-
right
|
|
64
|
-
left: isSticky ? 0 :
|
|
65
|
-
verticalAlign:
|
|
46
|
+
textAlign: cellAlign,
|
|
47
|
+
position: isSticky ? 'sticky' : position,
|
|
48
|
+
right,
|
|
49
|
+
left: isSticky ? 0 : left,
|
|
50
|
+
verticalAlign: cellVerticalAlign,
|
|
66
51
|
}}
|
|
67
52
|
>
|
|
68
|
-
{
|
|
53
|
+
{isNotEmpty(value) && (
|
|
54
|
+
<>
|
|
55
|
+
{isNotEmpty(component)
|
|
56
|
+
? component({
|
|
57
|
+
value,
|
|
58
|
+
row: item,
|
|
59
|
+
isFocusedRow,
|
|
60
|
+
isNestedComponentExpanded,
|
|
61
|
+
isRowNestedComponentExpanded,
|
|
62
|
+
onSetNestedComponent,
|
|
63
|
+
})
|
|
64
|
+
: formatCellContent(value, config[columnName])}
|
|
65
|
+
</>
|
|
66
|
+
)}
|
|
69
67
|
</td>
|
|
70
68
|
);
|
|
71
69
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReactNode, useState, memo } from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
+
import { isNotEmpty } from '@true-engineering/true-react-platform-helpers';
|
|
3
4
|
import { addDataAttributes } from '../../../../helpers';
|
|
4
5
|
import { useTweakStyles } from '../../../../hooks';
|
|
5
6
|
import { ICommonProps, IDataAttributes } from '../../../../types';
|
|
@@ -14,7 +15,7 @@ export interface IFlexibleTableRowProps<Values extends Record<string, any>>
|
|
|
14
15
|
uniqueField?: keyof Values;
|
|
15
16
|
isFirstColumnSticky?: boolean;
|
|
16
17
|
isActive: boolean;
|
|
17
|
-
config
|
|
18
|
+
config: IFlexibleTableConfigType<Values>;
|
|
18
19
|
enabledColumns?: Array<keyof Values>;
|
|
19
20
|
rowAttributes?: Array<keyof Values>;
|
|
20
21
|
expandableRowComponent?(item: Values, isOpen: boolean, close: () => void): ReactNode;
|
|
@@ -81,7 +82,7 @@ function FlexibleTableRowInner<Values extends Record<string, any>>({
|
|
|
81
82
|
onRowClick?.(item[uniqueField]);
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
if (expandableRowComponent
|
|
85
|
+
if (isNotEmpty(expandableRowComponent)) {
|
|
85
86
|
const newNestedComponent = expandableRowComponent(item, true, closeNestedComponent);
|
|
86
87
|
|
|
87
88
|
if (!nestedComponent.isOpen && newNestedComponent !== null) {
|
|
@@ -96,16 +97,16 @@ function FlexibleTableRowInner<Values extends Record<string, any>>({
|
|
|
96
97
|
}
|
|
97
98
|
};
|
|
98
99
|
|
|
99
|
-
const items = enabledColumns ?? Object.keys(
|
|
100
|
+
const items = enabledColumns ?? Object.keys(config);
|
|
100
101
|
|
|
101
102
|
return (
|
|
102
103
|
<>
|
|
103
104
|
<tr
|
|
104
|
-
className={clsx(
|
|
105
|
-
classes.
|
|
106
|
-
|
|
107
|
-
(onRowClick
|
|
108
|
-
)}
|
|
105
|
+
className={clsx(classes.root, {
|
|
106
|
+
[classes.active]: isActive,
|
|
107
|
+
[classes.editable]: isNotEmpty(onRowClick) || isNotEmpty(onRowHover),
|
|
108
|
+
[classes.clickable]: isNotEmpty(onRowClick) || isNotEmpty(expandableRowComponent),
|
|
109
|
+
})}
|
|
109
110
|
onMouseEnter={(e) => {
|
|
110
111
|
if (uniqueField !== undefined && onRowHover !== undefined) {
|
|
111
112
|
e.stopPropagation();
|
|
@@ -120,11 +121,11 @@ function FlexibleTableRowInner<Values extends Record<string, any>>({
|
|
|
120
121
|
isExpandableComponentActive: nestedComponent.isOpen ? true : undefined,
|
|
121
122
|
})}
|
|
122
123
|
>
|
|
123
|
-
{items.map((key,
|
|
124
|
+
{items.map((key, i) => (
|
|
124
125
|
<FlexibleTableCell
|
|
125
126
|
columnName={key}
|
|
126
|
-
isSticky={isFirstColumnSticky &&
|
|
127
|
-
isSecond={isFirstColumnSticky &&
|
|
127
|
+
isSticky={isFirstColumnSticky && i === 0}
|
|
128
|
+
isSecond={isFirstColumnSticky && i === 1}
|
|
128
129
|
key={key as string}
|
|
129
130
|
item={item}
|
|
130
131
|
config={config}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { format } from 'date-fns';
|
|
2
|
+
import { isNotEmpty } from '@true-engineering/true-react-platform-helpers';
|
|
3
|
+
import { DEFAULT_DATE_FORMAT } from './constants';
|
|
4
|
+
import { IFlexibleTableConfigType } from './types';
|
|
5
|
+
|
|
6
|
+
export const hasHorizontalScrollBar = (el: HTMLElement | null | undefined): boolean =>
|
|
7
|
+
isNotEmpty(el) && el.scrollWidth !== el.clientWidth;
|
|
8
|
+
|
|
9
|
+
export const formatCellContent = <Values>(
|
|
10
|
+
value: unknown,
|
|
11
|
+
config?: IFlexibleTableConfigType<Values>[keyof Values],
|
|
12
|
+
): string =>
|
|
13
|
+
value instanceof Date
|
|
14
|
+
? format(value as Date, config?.dateFormat ?? DEFAULT_DATE_FORMAT)
|
|
15
|
+
: String(value);
|
|
@@ -23,7 +23,7 @@ export type IFlexibleTableConfigType<Values> = {
|
|
|
23
23
|
[Key in keyof Values]?: {
|
|
24
24
|
title?: ReactNode;
|
|
25
25
|
titleComponent?: ITitleComponent<unknown>;
|
|
26
|
-
component?: IValueComponent<Values, Values[Key]
|
|
26
|
+
component?: IValueComponent<Values, NonNullable<Values[Key]>>;
|
|
27
27
|
dateFormat?: string;
|
|
28
28
|
minWidth?: string | number;
|
|
29
29
|
width?: string | number;
|
|
@@ -8,6 +8,7 @@ const TOP_GAP = 12;
|
|
|
8
8
|
|
|
9
9
|
export const useStyles = createThemedStyles('MultiSelectList', {
|
|
10
10
|
root: {
|
|
11
|
+
width: 220,
|
|
11
12
|
background: colors.CLASSIC_WHITE,
|
|
12
13
|
},
|
|
13
14
|
|
|
@@ -101,10 +102,13 @@ export const searchInputStyles: ISearchInputStyles = {
|
|
|
101
102
|
export const checkboxStyles: ICheckboxStyles = {
|
|
102
103
|
root: {
|
|
103
104
|
padding: [11, 16],
|
|
105
|
+
boxSizing: 'border-box',
|
|
106
|
+
width: '100%',
|
|
104
107
|
},
|
|
105
108
|
|
|
106
109
|
children: {
|
|
107
110
|
marginRight: 'auto',
|
|
111
|
+
overflow: 'hidden',
|
|
108
112
|
},
|
|
109
113
|
};
|
|
110
114
|
|
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
export interface IMultiSelectListProps<Value, Option> extends ICommonProps<IMultiSelectListStyles> {
|
|
23
23
|
value?: Value;
|
|
24
24
|
isSearchEnabled?: boolean;
|
|
25
|
-
width?: number | string;
|
|
26
25
|
localeKey?: IMultiSelectLocaleKey;
|
|
27
26
|
locale?: Partial<IMultiSelectLocale>;
|
|
28
27
|
onClose?: () => void;
|
|
@@ -43,7 +42,6 @@ export function MultiSelectList<Value extends IMultiSelectListValues<Option>, Op
|
|
|
43
42
|
tweakStyles,
|
|
44
43
|
data,
|
|
45
44
|
isSearchEnabled = false,
|
|
46
|
-
width = 220,
|
|
47
45
|
localeKey = DEFAULT_LOCALE,
|
|
48
46
|
locale = MultiSelectLocales[localeKey],
|
|
49
47
|
onChange,
|
|
@@ -329,7 +327,7 @@ export function MultiSelectList<Value extends IMultiSelectListValues<Option>, Op
|
|
|
329
327
|
const shouldShowOptionsList = !isLoading && allOptions.length !== 0;
|
|
330
328
|
|
|
331
329
|
return (
|
|
332
|
-
<div className={classes.root}
|
|
330
|
+
<div className={classes.root} {...addDataAttributes(data)}>
|
|
333
331
|
{isSearchEnabled && (
|
|
334
332
|
<div className={classes.dropdownInput}>
|
|
335
333
|
<SearchInput
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ComponentStory } from '@storybook/react';
|
|
2
|
+
import { Skeleton } from './Skeleton';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Skeleton',
|
|
6
|
+
component: Skeleton,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const Template: ComponentStory<typeof Skeleton> = (args) => (
|
|
10
|
+
<div style={{ padding: 32, backgroundColor: '#fff', width: 200 }}>
|
|
11
|
+
<Skeleton {...args} />
|
|
12
|
+
</div>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const Default = Template.bind({});
|
|
16
|
+
|
|
17
|
+
Default.args = {
|
|
18
|
+
height: '20px',
|
|
19
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { rgba } from '../../helpers';
|
|
2
|
+
import { colors, createThemedStyles, ITweakStyles } from '../../theme';
|
|
3
|
+
|
|
4
|
+
export const useStyles = createThemedStyles('Skeleton', {
|
|
5
|
+
root: {
|
|
6
|
+
display: 'flex',
|
|
7
|
+
width: '100%',
|
|
8
|
+
height: '100%',
|
|
9
|
+
backgroundColor: rgba(colors.GREY_DISABLED, 0.8),
|
|
10
|
+
position: 'relative',
|
|
11
|
+
borderRadius: 4,
|
|
12
|
+
overflow: 'hidden',
|
|
13
|
+
'-webkit-mask-image': '-webkit-radial-gradient(white, black)',
|
|
14
|
+
|
|
15
|
+
'&::after': {
|
|
16
|
+
content: '""',
|
|
17
|
+
animation: '$skeleton 1.6s linear 0.5s infinite',
|
|
18
|
+
background: `linear-gradient(90deg, transparent, ${rgba(
|
|
19
|
+
colors.GREY_BACKGROUND,
|
|
20
|
+
0.65,
|
|
21
|
+
)}, transparent)`,
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
transform: 'translateX(-100%)',
|
|
24
|
+
bottom: 0,
|
|
25
|
+
left: 0,
|
|
26
|
+
right: 0,
|
|
27
|
+
top: 0,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
'@keyframes skeleton': {
|
|
32
|
+
'0%': {
|
|
33
|
+
transform: 'translateX(-100%)',
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
'50%': {
|
|
37
|
+
transform: 'translateX(100%)',
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
'100%': {
|
|
41
|
+
transform: 'translateX(100%)',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export type ISkeletonStyles = ITweakStyles<typeof useStyles>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CSSProperties, FC } from 'react';
|
|
2
|
+
import { ICommonProps } from '../../types';
|
|
3
|
+
import { ISkeletonStyles, useStyles } from './Skeleton.styles';
|
|
4
|
+
|
|
5
|
+
export interface ISkeletonProps extends Pick<ICommonProps<ISkeletonStyles>, 'tweakStyles'> {
|
|
6
|
+
height?: CSSProperties['height'];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const Skeleton: FC<ISkeletonProps> = ({ height, tweakStyles }) => {
|
|
10
|
+
const classes = useStyles({ theme: tweakStyles });
|
|
11
|
+
return <div className={classes.root} style={{ height }} />;
|
|
12
|
+
};
|
|
@@ -9,7 +9,7 @@ import { useStyles, ISwitchStyles } from './Switch.styles';
|
|
|
9
9
|
export interface ISwitchProps<V extends string> extends ICommonProps<ISwitchStyles> {
|
|
10
10
|
children?: ReactNode;
|
|
11
11
|
value: V;
|
|
12
|
-
isChecked: boolean;
|
|
12
|
+
isChecked: boolean | undefined;
|
|
13
13
|
isDisabled?: boolean;
|
|
14
14
|
isInvalid?: boolean;
|
|
15
15
|
/**
|
|
@@ -25,7 +25,7 @@ export interface ISwitchProps<V extends string> extends ICommonProps<ISwitchStyl
|
|
|
25
25
|
|
|
26
26
|
export const Switch = <V extends string>({
|
|
27
27
|
isDisabled,
|
|
28
|
-
isChecked,
|
|
28
|
+
isChecked = false,
|
|
29
29
|
isInvalid,
|
|
30
30
|
value,
|
|
31
31
|
children,
|
package/src/components/index.ts
CHANGED
package/src/helpers/phone.ts
CHANGED
|
@@ -18,7 +18,7 @@ export const getCountryTextByLocale = (country: IPhoneInfo, locale: string): str
|
|
|
18
18
|
locale.toLowerCase() === 'ru' ? country.countryRu : country.countryEn;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Мутирует countriesList!
|
|
22
22
|
*/
|
|
23
23
|
export const sortCountriesByLocale = (countriesList: IPhoneInfo[], locale: string): IPhoneInfo[] =>
|
|
24
24
|
countriesList.sort((countryA, countryB) =>
|
package/src/hooks/index.ts
CHANGED
package/src/theme/types.ts
CHANGED
|
@@ -52,6 +52,7 @@ import type {
|
|
|
52
52
|
IFlexibleTableCellStyles,
|
|
53
53
|
IFlexibleTableRowStyles,
|
|
54
54
|
IFilterValueViewStyles,
|
|
55
|
+
ISkeletonStyles,
|
|
55
56
|
} from '../components';
|
|
56
57
|
|
|
57
58
|
export type IStyles<C extends string, P> = Styles<C, P, Partial<Styles<C, P>>>;
|
|
@@ -108,6 +109,7 @@ export interface IComponentStyles {
|
|
|
108
109
|
SearchInput: ISearchInputStyles;
|
|
109
110
|
Select: ISelectStyles;
|
|
110
111
|
SelectList: ISelectListStyles;
|
|
112
|
+
Skeleton: ISkeletonStyles;
|
|
111
113
|
Switch: ISwitchStyles;
|
|
112
114
|
TextArea: ITextAreaStyles;
|
|
113
115
|
TextWithInfo: ITextWithInfoStyles;
|