@true-engineering/true-react-common-ui-kit 2.1.1 → 2.2.0
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/Button/Button.d.ts +3 -4
- package/dist/components/Input/Input.d.ts +3 -4
- package/dist/components/List/List.d.ts +3 -4
- package/dist/components/ScrollIntoViewIfNeeded/ScrollIntoViewIfNeeded.d.ts +4 -4
- package/dist/components/Select/Select.d.ts +2 -3
- package/dist/helpers/deprecated.d.ts +12 -0
- package/dist/helpers/index.d.ts +2 -2
- package/dist/helpers/misc.d.ts +19 -0
- package/dist/helpers/snippets.d.ts +3 -3
- package/dist/true-react-common-ui-kit.js +238 -308
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +238 -309
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/dist/types.d.ts +3 -1
- package/package.json +2 -1
- package/src/components/Button/Button.tsx +9 -29
- package/src/components/Checkbox/Checkbox.tsx +7 -2
- package/src/components/DatePicker/DatePicker.tsx +6 -1
- package/src/components/DatePicker/helpers.ts +5 -1
- package/src/components/FiltersPane/FilterSelect/FilterSelect.tsx +3 -2
- package/src/components/FiltersPane/FilterWithDates/FilterWithDates.tsx +2 -1
- package/src/components/IncrementInput/IncrementInput.tsx +3 -2
- package/src/components/Input/Input.tsx +15 -10
- package/src/components/List/List.tsx +13 -10
- package/src/components/Modal/Modal.tsx +8 -3
- package/src/components/MoreMenu/MoreMenu.tsx +3 -2
- package/src/components/Notification/Notification.tsx +11 -7
- package/src/components/NumberInput/NumberInput.tsx +2 -2
- package/src/components/NumberInput/helpers.ts +3 -2
- package/src/components/RadioButton/RadioButton.tsx +3 -2
- package/src/components/ScrollIntoViewIfNeeded/ScrollIntoViewIfNeeded.ts +4 -4
- package/src/components/SearchInput/SearchInput.tsx +2 -1
- package/src/components/Select/MultiSelect.stories.tsx +2 -2
- package/src/components/Select/Select.stories.tsx +2 -2
- package/src/components/Select/Select.tsx +8 -8
- package/src/components/Select/SelectList/SelectList.tsx +11 -5
- package/src/components/Select/SelectListItem/SelectListItem.tsx +2 -1
- package/src/components/Select/helpers.ts +1 -1
- package/src/components/Switch/Switch.tsx +3 -2
- package/src/components/Toaster/Toaster.tsx +10 -5
- package/src/helpers/deprecated.ts +22 -0
- package/src/helpers/index.ts +2 -2
- package/src/helpers/{utils.ts → misc.ts} +11 -84
- package/src/helpers/phone.ts +5 -5
- package/src/helpers/snippets.tsx +4 -3
- package/src/types.ts +10 -1
- package/dist/helpers/colors.d.ts +0 -2
- package/dist/helpers/utils.d.ts +0 -43
- package/src/helpers/colors.ts +0 -3
- package/src/helpers/dateHelpers/date-helpers.ts +0 -9
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import {
|
|
3
|
+
import { addDataTestId, isReactNodeNotEmpty } from '@true-engineering/true-react-platform-helpers';
|
|
4
|
+
import { addDataAttributes } from '../../helpers';
|
|
4
5
|
import { useTheme } from '../../hooks';
|
|
5
6
|
import { ICommonProps } from '../../types';
|
|
6
7
|
import { styles, SwitchStyles } from './Switch.styles';
|
|
@@ -67,7 +68,7 @@ export const Switch = <V extends string>({
|
|
|
67
68
|
{...addDataTestId(testId, 'input')}
|
|
68
69
|
/>
|
|
69
70
|
</span>
|
|
70
|
-
{
|
|
71
|
+
{isReactNodeNotEmpty(children) && (
|
|
71
72
|
<span
|
|
72
73
|
className={clsx(
|
|
73
74
|
classes.label,
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { FC, ReactNode, useEffect } from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
isNotEmpty,
|
|
5
|
+
isReactNodeNotEmpty,
|
|
6
|
+
isStringNotEmpty,
|
|
7
|
+
} from '@true-engineering/true-react-platform-helpers';
|
|
8
|
+
import { addDataAttributes } from '../../helpers';
|
|
4
9
|
import { useTheme, useTweakStyles } from '../../hooks';
|
|
5
10
|
import { ICommonProps } from '../../types';
|
|
6
11
|
import { CloseButton } from '../CloseButton';
|
|
@@ -87,11 +92,11 @@ export const Toaster: FC<IToasterProps> = ({
|
|
|
87
92
|
<Icon type={`status-${type}`} />
|
|
88
93
|
</div>
|
|
89
94
|
<div>
|
|
90
|
-
{
|
|
91
|
-
{
|
|
92
|
-
{
|
|
95
|
+
{isStringNotEmpty(title) && <div className={classes.title}>{title}</div>}
|
|
96
|
+
{isStringNotEmpty(text) && <div className={classes.text}>{text}</div>}
|
|
97
|
+
{isReactNodeNotEmpty(children) && <div className={classes.content}>{children}</div>}
|
|
93
98
|
</div>
|
|
94
|
-
{hasCloseButton && onClose
|
|
99
|
+
{hasCloseButton && isNotEmpty(onClose) && (
|
|
95
100
|
<div className={classes.close}>
|
|
96
101
|
<CloseButton
|
|
97
102
|
onClose={onClose}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addClickHandler as addClickHandlerHelper,
|
|
3
|
+
addDataTestId as addDataTestIdHelper,
|
|
4
|
+
createFilter as createFilterHelper,
|
|
5
|
+
getSelectKeyHandler as getSelectKeyHandlerHelper,
|
|
6
|
+
getTestId as getTestIdHelper,
|
|
7
|
+
isEmpty as isEmptyHelper,
|
|
8
|
+
isNumberInteger,
|
|
9
|
+
isString,
|
|
10
|
+
isStringNotEmpty as isStringNotEmptyHelper,
|
|
11
|
+
} from '@true-engineering/true-react-platform-helpers';
|
|
12
|
+
|
|
13
|
+
export const isInt = isNumberInteger;
|
|
14
|
+
export const addClickHandler = addClickHandlerHelper;
|
|
15
|
+
export const addDataTestId = addDataTestIdHelper;
|
|
16
|
+
export const createFilter = createFilterHelper;
|
|
17
|
+
export const getSelectKeyHandler = getSelectKeyHandlerHelper;
|
|
18
|
+
export const getTestId = getTestIdHelper;
|
|
19
|
+
export const isStringNotEmpty = isStringNotEmptyHelper;
|
|
20
|
+
export const isEmpty = isEmptyHelper;
|
|
21
|
+
export const isNotEmpty = <T>(val: T | null | undefined): val is T =>
|
|
22
|
+
(isString(val) && isStringNotEmpty(val)) || isNotEmpty(val);
|
package/src/helpers/index.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import hexToRgba from 'hex-to-rgba';
|
|
2
|
+
import {
|
|
3
|
+
isNotEmpty,
|
|
4
|
+
isString,
|
|
5
|
+
isStringNotEmpty,
|
|
6
|
+
} from '@true-engineering/true-react-platform-helpers';
|
|
2
7
|
import { IDataAttributes } from '../types';
|
|
3
8
|
|
|
9
|
+
export const rgba = hexToRgba;
|
|
10
|
+
|
|
4
11
|
export const transformToKebab = (string: string): string => {
|
|
5
12
|
let result = '';
|
|
6
13
|
string.split('').forEach((char) => {
|
|
@@ -135,97 +142,17 @@ export const setCaretPosition = (elem: HTMLInputElement, caretPos: number | null
|
|
|
135
142
|
export const isSpaceChar = (char?: string): boolean =>
|
|
136
143
|
char !== undefined && char.match(/\s/) !== null;
|
|
137
144
|
|
|
138
|
-
export const isInt = (n: number): boolean => n % 1 === 0;
|
|
139
|
-
|
|
140
145
|
export const getNumberLength = (n?: number): number =>
|
|
141
146
|
n === undefined || isNaN(n) ? 0 : n.toString().length;
|
|
142
147
|
|
|
143
|
-
// TODO: Не должен проверять строку, т.к. под это есть отдельный хелпер
|
|
144
|
-
/**
|
|
145
|
-
* Проверяет, что `val` не `null`, не `undefined` и не пустая строка
|
|
146
|
-
*/
|
|
147
|
-
export const isNotEmpty = <T>(val: T | null | undefined): val is T =>
|
|
148
|
-
typeof val === 'string' ? val.trim() !== '' : val !== null && val !== undefined;
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Проверяет, что переданное значение `null` или `undefined`
|
|
152
|
-
*/
|
|
153
|
-
export const isEmpty = <T>(val: T | null | undefined): val is null | undefined =>
|
|
154
|
-
val === null || val === undefined;
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Проверяет, что передана непустая строка
|
|
158
|
-
*/
|
|
159
|
-
export const isStringNotEmpty = <T extends string>(value: T | undefined | null): value is T =>
|
|
160
|
-
(value ?? '').trim() !== '';
|
|
161
|
-
|
|
162
148
|
export const trimStringToMaxLength = (val: string, maxLength: number) =>
|
|
163
149
|
val.length > maxLength ? val.slice(0, maxLength) : val;
|
|
164
150
|
|
|
165
151
|
export const addDataAttributes = (data: IDataAttributes = {}): IDataAttributes =>
|
|
166
152
|
Object.fromEntries(
|
|
167
153
|
Object.entries(data).map(([key, value]) =>
|
|
168
|
-
|
|
154
|
+
(isString(value) && isStringNotEmpty(value)) || isNotEmpty(value)
|
|
155
|
+
? [`data-${transformToKebab(key)}`, value]
|
|
156
|
+
: [],
|
|
169
157
|
),
|
|
170
158
|
);
|
|
171
|
-
|
|
172
|
-
export const addDataTestId = (
|
|
173
|
-
...args: Parameters<typeof getTestId>
|
|
174
|
-
): { 'data-testid': string } | undefined => {
|
|
175
|
-
const testId = getTestId(...args);
|
|
176
|
-
return isNotEmpty(testId) ? { 'data-testid': testId } : undefined;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
export const getTestId = (
|
|
180
|
-
testId: string | undefined,
|
|
181
|
-
postfix?: string | number,
|
|
182
|
-
): string | undefined => {
|
|
183
|
-
if (!isNotEmpty(testId)) {
|
|
184
|
-
return undefined;
|
|
185
|
-
}
|
|
186
|
-
return isNotEmpty(postfix) ? `${testId}-${postfix}` : testId;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
export const getSelectKeyHandler =
|
|
190
|
-
(cb: (e: KeyboardEvent) => void): ((e: KeyboardEvent) => void) =>
|
|
191
|
-
(e) => {
|
|
192
|
-
if (e.code === 'Enter' || e.code === 'NumpadEnter') {
|
|
193
|
-
cb(e);
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
export const addClickHandler = (
|
|
198
|
-
cb?: (e: MouseEvent | KeyboardEvent) => void,
|
|
199
|
-
hasAction = true,
|
|
200
|
-
): HTMLAttributes<unknown> =>
|
|
201
|
-
hasAction && isNotEmpty(cb)
|
|
202
|
-
? {
|
|
203
|
-
tabIndex: 0,
|
|
204
|
-
onClick: cb as (e: MouseEvent) => void,
|
|
205
|
-
onKeyDown: getSelectKeyHandler(cb),
|
|
206
|
-
}
|
|
207
|
-
: {
|
|
208
|
-
tabIndex: -1,
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Позволяет создать текстовый фильтр для набора items
|
|
213
|
-
* @param getter - функция возвращающая набор строковых значений из каждого item,
|
|
214
|
-
* по которым должен осуществляться поиск
|
|
215
|
-
*/
|
|
216
|
-
export const createFilter =
|
|
217
|
-
<T>(
|
|
218
|
-
getter: (item: T) => Array<string | undefined>,
|
|
219
|
-
compareFn?: (item: string, query: string) => boolean,
|
|
220
|
-
): ((items: T[], query: string) => T[]) =>
|
|
221
|
-
(items, query) =>
|
|
222
|
-
items.filter((item) => {
|
|
223
|
-
const possibleValues = getter(item).reduce(
|
|
224
|
-
(acc, cur) => [...acc, ...(isStringNotEmpty(cur) ? [cur.toLowerCase()] : [])],
|
|
225
|
-
[] as string[],
|
|
226
|
-
);
|
|
227
|
-
const queryString = query.toLowerCase().trim();
|
|
228
|
-
return possibleValues.some((v) =>
|
|
229
|
-
(compareFn ?? (() => v?.includes(queryString)))(v, queryString),
|
|
230
|
-
);
|
|
231
|
-
});
|
package/src/helpers/phone.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import { isNotEmpty, isEmpty } from '@true-engineering/true-react-platform-helpers';
|
|
1
2
|
import { phoneInfo, IPhoneInfo, IPhoneValue } from '../components';
|
|
2
|
-
import { isNotEmpty } from './utils';
|
|
3
3
|
|
|
4
4
|
export const findCountryByCode = (
|
|
5
5
|
countryCode?: string,
|
|
6
6
|
countriesList = phoneInfo,
|
|
7
7
|
): IPhoneInfo | undefined =>
|
|
8
|
-
countryCode
|
|
8
|
+
isNotEmpty(countryCode)
|
|
9
9
|
? countriesList.find((info) => info.countryCode === countryCode)
|
|
10
10
|
: undefined;
|
|
11
11
|
|
|
12
12
|
export const findCountryIndexByCode = (countryCode?: string, countriesList = phoneInfo): number =>
|
|
13
|
-
countryCode
|
|
13
|
+
isNotEmpty(countryCode)
|
|
14
14
|
? countriesList.findIndex((info) => info.countryCode === countryCode)
|
|
15
15
|
: -1;
|
|
16
16
|
|
|
@@ -47,7 +47,7 @@ export const getCountryCodeFromPhone = (phoneWithCode: string): string | undefin
|
|
|
47
47
|
info.fullCodes.some((code) => phoneWithCode.startsWith(code)),
|
|
48
48
|
)?.countryCode;
|
|
49
49
|
|
|
50
|
-
if (countryCode
|
|
50
|
+
if (isEmpty(countryCode) && isNotEmpty(phoneWithCode)) {
|
|
51
51
|
// если не нашли уникальный fullCode (dialCode + arealCode),
|
|
52
52
|
// то пробуем найти dialCode и выбираем с наименьшим Priority
|
|
53
53
|
countryCode = phoneInfo
|
|
@@ -72,7 +72,7 @@ export const DEFAULT_PHONE_MASK = '+ 9 999 999 999 999 99';
|
|
|
72
72
|
|
|
73
73
|
export const getPhoneMask = (countryCode?: string): string => {
|
|
74
74
|
let mask = DEFAULT_PHONE_MASK;
|
|
75
|
-
if (countryCode
|
|
75
|
+
if (isNotEmpty(countryCode)) {
|
|
76
76
|
const countrySettings = findCountryByCode(countryCode);
|
|
77
77
|
|
|
78
78
|
if (countrySettings !== undefined) {
|
package/src/helpers/snippets.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Icon
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { Icon } from '../components';
|
|
3
|
+
import { IIcon } from '../types';
|
|
3
4
|
|
|
4
|
-
export const renderIcon = (icon:
|
|
5
|
+
export const renderIcon = (icon: IIcon): ReactNode =>
|
|
5
6
|
typeof icon === 'string' ? <Icon type={icon} /> : icon;
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
1
2
|
import { Styles } from 'react-jss';
|
|
2
3
|
import { Modifier, Placement } from 'react-overlays/usePopper';
|
|
3
|
-
import {
|
|
4
|
+
import type {
|
|
5
|
+
ICommonIcon,
|
|
6
|
+
IComplexIcon,
|
|
7
|
+
IIconType,
|
|
8
|
+
IPreloaderSvgType,
|
|
9
|
+
ISvgIcon,
|
|
10
|
+
} from './components';
|
|
4
11
|
|
|
5
12
|
export interface IDataAttributes {
|
|
6
13
|
[key: string]: unknown;
|
|
@@ -25,6 +32,8 @@ export interface IDropdownWithPopperOptions {
|
|
|
25
32
|
flipOptions?: Record<string, any>; // только с shouldUsePopper
|
|
26
33
|
}
|
|
27
34
|
|
|
35
|
+
export type IIcon = IIconType | ReactElement;
|
|
36
|
+
|
|
28
37
|
export type ComponentStyles<StyleSheet, Props = unknown> = Partial<Styles<keyof StyleSheet, Props>>;
|
|
29
38
|
|
|
30
39
|
// TODO: Скрипт
|
package/dist/helpers/colors.d.ts
DELETED
package/dist/helpers/utils.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { HTMLAttributes, KeyboardEvent, MouseEvent } from 'react';
|
|
2
|
-
import { IDataAttributes } from '../types';
|
|
3
|
-
export declare const transformToKebab: (string: string) => string;
|
|
4
|
-
export declare const hasExactParent: (element: Element, parent: Element) => boolean;
|
|
5
|
-
export declare const getParentNode: (element: Element | ShadowRoot | Document) => Element;
|
|
6
|
-
export declare const getStyleComputedProperty: (element: Element) => Partial<CSSStyleDeclaration>;
|
|
7
|
-
export declare const getScrollParent: (element: Element | Document) => Element;
|
|
8
|
-
export declare const isElementOffScreen: (element: HTMLElement, input?: HTMLElement) => boolean;
|
|
9
|
-
export declare const getNumberInRange: (value: number, min?: number, max?: number) => number;
|
|
10
|
-
export declare const formatStringNumber: (val?: string, separator?: string) => string;
|
|
11
|
-
export declare const formatNumber: (val?: number, separator?: string) => string;
|
|
12
|
-
export declare const removeStringFormat: (val?: string) => string;
|
|
13
|
-
export declare const stringToNumber: (val?: string) => number | undefined;
|
|
14
|
-
export declare const setCaretPosition: (elem: HTMLInputElement, caretPos: number | null) => void;
|
|
15
|
-
export declare const isSpaceChar: (char?: string) => boolean;
|
|
16
|
-
export declare const isInt: (n: number) => boolean;
|
|
17
|
-
export declare const getNumberLength: (n?: number) => number;
|
|
18
|
-
/**
|
|
19
|
-
* Проверяет, что `val` не `null`, не `undefined` и не пустая строка
|
|
20
|
-
*/
|
|
21
|
-
export declare const isNotEmpty: <T>(val: T | null | undefined) => val is T;
|
|
22
|
-
/**
|
|
23
|
-
* Проверяет, что переданное значение `null` или `undefined`
|
|
24
|
-
*/
|
|
25
|
-
export declare const isEmpty: <T>(val: T | null | undefined) => val is null | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* Проверяет, что передана непустая строка
|
|
28
|
-
*/
|
|
29
|
-
export declare const isStringNotEmpty: <T extends string>(value: T | null | undefined) => value is T;
|
|
30
|
-
export declare const trimStringToMaxLength: (val: string, maxLength: number) => string;
|
|
31
|
-
export declare const addDataAttributes: (data?: IDataAttributes) => IDataAttributes;
|
|
32
|
-
export declare const addDataTestId: (testId: string | undefined, postfix?: string | number | undefined) => {
|
|
33
|
-
'data-testid': string;
|
|
34
|
-
} | undefined;
|
|
35
|
-
export declare const getTestId: (testId: string | undefined, postfix?: string | number) => string | undefined;
|
|
36
|
-
export declare const getSelectKeyHandler: (cb: (e: KeyboardEvent) => void) => (e: KeyboardEvent) => void;
|
|
37
|
-
export declare const addClickHandler: (cb?: ((e: MouseEvent | KeyboardEvent) => void) | undefined, hasAction?: boolean) => HTMLAttributes<unknown>;
|
|
38
|
-
/**
|
|
39
|
-
* Позволяет создать текстовый фильтр для набора items
|
|
40
|
-
* @param getter - функция возвращающая набор строковых значений из каждого item,
|
|
41
|
-
* по которым должен осуществляться поиск
|
|
42
|
-
*/
|
|
43
|
-
export declare const createFilter: <T>(getter: (item: T) => Array<string | undefined>, compareFn?: ((item: string, query: string) => boolean) | undefined) => (items: T[], query: string) => T[];
|
package/src/helpers/colors.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { parse, isValid } from 'date-fns';
|
|
2
|
-
|
|
3
|
-
export const DATE_FORMAT = 'dd.MM.yyyy';
|
|
4
|
-
|
|
5
|
-
export const isDateValid = (value: string): boolean =>
|
|
6
|
-
isValid(parse(value, DATE_FORMAT, new Date()));
|
|
7
|
-
|
|
8
|
-
export const parseStringToDate = (value: string): Date =>
|
|
9
|
-
parse(value, DATE_FORMAT, new Date()) || null;
|