@true-engineering/true-react-common-ui-kit 3.9.0 → 3.9.1
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/LICENSE +201 -201
- package/README.md +6 -0
- package/dist/true-react-common-ui-kit.js +61 -60
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +61 -60
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/components/AccountInfo/AccountInfo.stories.tsx +32 -32
- package/src/components/AccountInfo/AccountInfo.tsx +80 -80
- package/src/components/AddButton/AddButton.stories.tsx +21 -21
- package/src/components/AddButton/AddButton.tsx +52 -52
- package/src/components/Button/Button.stories.tsx +56 -56
- package/src/components/Button/Button.tsx +129 -129
- package/src/components/Checkbox/Checkbox.stories.tsx +28 -28
- package/src/components/CloseButton/CloseButton.tsx +34 -34
- package/src/components/Colors/Colors.stories.tsx +7 -7
- package/src/components/DateInput/DateInput.tsx +90 -90
- package/src/components/DateInput/constants.ts +2 -2
- package/src/components/DatePicker/DatePicker.tsx +308 -308
- package/src/components/Description/Description.stories.tsx +27 -27
- package/src/components/Description/Description.tsx +61 -61
- package/src/components/FiltersPane/FiltersPane.tsx +158 -158
- package/src/components/FiltersPane/components/Filter/Filter.tsx +203 -203
- package/src/components/FiltersPane/components/FilterValueView/FilterValueView.tsx +166 -166
- package/src/components/FiltersPane/components/FilterWithDates/FilterWithDates.tsx +210 -210
- package/src/components/FiltersPane/components/FilterWithPeriod/FilterWithPeriod.tsx +177 -177
- package/src/components/FiltersPane/components/FilterWrapper/FilterWrapper.tsx +167 -167
- package/src/components/Flag/Flag.stories.tsx +29 -29
- package/src/components/Flag/Flag.tsx +26 -26
- package/src/components/Flag/augment.d.ts +1 -1
- package/src/components/FlexibleTable/FlexibleTable.stories.tsx +267 -267
- package/src/components/FlexibleTable/FlexibleTable.styles.ts +110 -110
- package/src/components/FlexibleTable/FlexibleTable.tsx +271 -271
- package/src/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.styles.ts +38 -38
- package/src/components/FlexibleTable/components/FlexibleTableCell/FlexibleTableCell.tsx +83 -83
- package/src/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.styles.ts +25 -25
- package/src/components/FlexibleTable/components/FlexibleTableRow/FlexibleTableRow.tsx +196 -196
- package/src/components/FlexibleTable/helpers.ts +13 -13
- package/src/components/FlexibleTable/types.ts +52 -52
- package/src/components/Icon/Icon.stories.tsx +86 -86
- package/src/components/Icon/complexIcons/augment.d.ts +1 -1
- package/src/components/Icon/complexIcons/avatarGreen.svg +57 -57
- package/src/components/Icon/complexIcons/index.ts +1 -1
- package/src/components/IncrementInput/IncrementInput.tsx +105 -105
- package/src/components/Input/Input.tsx +297 -297
- package/src/components/Input/types.ts +32 -32
- package/src/components/List/List.stories.tsx +70 -70
- package/src/components/List/List.tsx +33 -33
- package/src/components/List/components/ListItem/ListItem.tsx +57 -57
- package/src/components/Modal/Modal.stories.tsx +105 -105
- package/src/components/Modal/Modal.tsx +196 -196
- package/src/components/MoreMenu/MoreMenu.styles.ts +68 -68
- package/src/components/MultiSelect/MultiSelect.stories.tsx +46 -46
- package/src/components/MultiSelect/MultiSelect.tsx +106 -106
- package/src/components/MultiSelect/components/MultiSelectInput/MultiSelectInput.tsx +53 -53
- package/src/components/MultiSelectList/MultiSelectList.tsx +461 -461
- package/src/components/Notification/Notification.stories.tsx +46 -46
- package/src/components/Notification/Notification.tsx +69 -69
- package/src/components/NumberInput/NumberInput.tsx +137 -137
- package/src/components/NumberInput/index.ts +1 -1
- package/src/components/PhoneInput/PhoneInput.tsx +214 -214
- package/src/components/PhoneInput/components/PhoneInputCountryList/PhoneInputCountryList.tsx +155 -155
- package/src/components/PhoneInput/types.ts +16 -16
- package/src/components/RadioButton/RadioButton.stories.tsx +46 -46
- package/src/components/RadioButton/RadioButton.tsx +57 -57
- package/src/components/ScrollIntoViewIfNeeded/index.ts +1 -1
- package/src/components/Select/CustomSelect.stories.tsx +217 -217
- package/src/components/Select/MultiSelect.stories.tsx +240 -240
- package/src/components/Select/Select.stories.tsx +235 -235
- package/src/components/Select/constants.ts +2 -2
- package/src/components/Select/types.ts +1 -1
- package/src/components/Selector/Selector.stories.tsx +62 -62
- package/src/components/Selector/Selector.styles.ts +164 -164
- package/src/components/Selector/Selector.tsx +115 -115
- package/src/components/Selector/index.ts +2 -2
- package/src/components/Selector/types.ts +12 -12
- package/src/components/Skeleton/Skeleton.stories.tsx +19 -19
- package/src/components/SmartInput/SmartInput.tsx +134 -134
- package/src/components/Status/Status.stories.tsx +73 -73
- package/src/components/Status/Status.styles.ts +143 -143
- package/src/components/Status/Status.tsx +49 -49
- package/src/components/Status/constants.ts +11 -11
- package/src/components/Status/index.ts +3 -3
- package/src/components/Status/types.ts +5 -5
- package/src/components/Switch/Switch.stories.tsx +40 -40
- package/src/components/Switch/Switch.tsx +75 -75
- package/src/components/TextArea/TextArea.tsx +180 -180
- package/src/components/TextButton/TextButton.stories.tsx +46 -46
- package/src/components/TextButton/TextButton.styles.ts +129 -129
- package/src/components/TextButton/TextButton.tsx +103 -103
- package/src/components/TextButton/index.ts +4 -4
- package/src/components/TextWithInfo/TextWithInfo.stories.tsx +53 -53
- package/src/components/TextWithInfo/TextWithInfo.tsx +62 -62
- package/src/components/TextWithTooltip/TextWithTooltip.stories.tsx +58 -58
- package/src/components/ThemedPreloader/ThemedPreloader.stories.tsx +41 -41
- package/src/components/ThemedPreloader/ThemedPreloader.tsx +54 -54
- package/src/components/ThemedPreloader/components/DefaultPreloader/index.ts +1 -1
- package/src/components/Toaster/Toaster.stories.tsx +30 -30
- package/src/components/Toaster/Toaster.tsx +108 -108
- package/src/components/Tooltip/Tooltip.stories.tsx +19 -19
- package/src/components/Tooltip/Tooltip.tsx +35 -35
- package/src/components/Tooltip/types.ts +1 -1
- package/src/components/WithPopup/WithPopup.tsx +1 -0
- package/src/helpers/popper-helpers.ts +17 -17
- package/src/hooks/use-dropdown.ts +84 -84
- package/src/hooks/use-is-mounted.ts +15 -15
- package/src/theme/helpers.ts +76 -76
- package/src/vite-env.d.ts +1 -1
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
import { useState, useRef, RefObject } from 'react';
|
|
2
|
-
import { CSSTransition } from 'react-transition-group';
|
|
3
|
-
import clsx from 'clsx';
|
|
4
|
-
import { addDataTestId, getTestId } from '@true-engineering/true-react-platform-helpers';
|
|
5
|
-
import { addDataAttributes } from '../../../../helpers';
|
|
6
|
-
import { useTweakStyles } from '../../../../hooks';
|
|
7
|
-
import { ICommonProps } from '../../../../types';
|
|
8
|
-
import { Icon } from '../../../Icon';
|
|
9
|
-
import { ConfigItem, IFilterLocaleKey, IPartialFilterLocale } from '../../types';
|
|
10
|
-
import { Filter } from '../Filter';
|
|
11
|
-
import { FilterValueView } from '../FilterValueView';
|
|
12
|
-
import { useStyles, IFilterWrapperStyles } from './FilterWrapper.styles';
|
|
13
|
-
|
|
14
|
-
export interface IFilterWrapperProps<Values, Key extends keyof Values>
|
|
15
|
-
extends ICommonProps<IFilterWrapperStyles> {
|
|
16
|
-
filter: ConfigItem<Values[Key]>;
|
|
17
|
-
value?: Values[Key];
|
|
18
|
-
isDisabled?: boolean;
|
|
19
|
-
localeKey?: IFilterLocaleKey;
|
|
20
|
-
locale?: IPartialFilterLocale;
|
|
21
|
-
filtersPaneRef: RefObject<HTMLDivElement> | null;
|
|
22
|
-
onChange: <V>(value: V) => void;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function FilterWrapper<Values, Key extends keyof Values>({
|
|
26
|
-
filter,
|
|
27
|
-
value,
|
|
28
|
-
isDisabled,
|
|
29
|
-
locale,
|
|
30
|
-
localeKey,
|
|
31
|
-
data,
|
|
32
|
-
testId,
|
|
33
|
-
filtersPaneRef,
|
|
34
|
-
tweakStyles,
|
|
35
|
-
onChange,
|
|
36
|
-
}: IFilterWrapperProps<Values, Key>): JSX.Element {
|
|
37
|
-
const classes = useStyles({ theme: tweakStyles });
|
|
38
|
-
|
|
39
|
-
const tweakFilterValueViewStyles = useTweakStyles({
|
|
40
|
-
tweakStyles,
|
|
41
|
-
className: 'tweakValueView',
|
|
42
|
-
currentComponentName: 'FilterWrapper',
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
46
|
-
const refItem = useRef<HTMLDivElement>(null);
|
|
47
|
-
|
|
48
|
-
const { type } = filter;
|
|
49
|
-
|
|
50
|
-
let hasValue = false;
|
|
51
|
-
|
|
52
|
-
if (Array.isArray(value) && value.length > 0) {
|
|
53
|
-
hasValue = true;
|
|
54
|
-
} else if (
|
|
55
|
-
typeof value === 'object' &&
|
|
56
|
-
Object.values(value as unknown as Record<any, any>).some((v) =>
|
|
57
|
-
Array.isArray(v) ? v.length > 0 : Boolean(v),
|
|
58
|
-
)
|
|
59
|
-
) {
|
|
60
|
-
hasValue = true;
|
|
61
|
-
} else if (!Array.isArray(value) && typeof value !== 'object') {
|
|
62
|
-
hasValue = Boolean(value);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Для того, чтобы фильтр закрывался, если мы работаем с простыми значениями, типа селекта
|
|
66
|
-
function handleChange<V>(v: V) {
|
|
67
|
-
if (type === 'select') {
|
|
68
|
-
setIsOpen(false);
|
|
69
|
-
}
|
|
70
|
-
onChange(v);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const handleLabelClick = () => {
|
|
74
|
-
if (!isBoolean && !isDisabled) {
|
|
75
|
-
setIsOpen(!isOpen);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (isBoolean) {
|
|
79
|
-
onChange(!value);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const handleOnClose = () => {
|
|
84
|
-
setIsOpen(false);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const isBoolean = filter.type === 'boolean';
|
|
88
|
-
|
|
89
|
-
return !filter.isInline ? (
|
|
90
|
-
<div
|
|
91
|
-
className={clsx(classes.root, {
|
|
92
|
-
[classes.noValue]: !hasValue,
|
|
93
|
-
[classes.openNoValue]: isOpen && !hasValue,
|
|
94
|
-
[classes.withValue]: !isOpen && hasValue,
|
|
95
|
-
[classes.openWithValue]: isOpen && hasValue,
|
|
96
|
-
[classes.boolean]: isBoolean,
|
|
97
|
-
[classes.disabled]: isDisabled,
|
|
98
|
-
})}
|
|
99
|
-
{...addDataTestId(testId)}
|
|
100
|
-
{...addDataAttributes(data)}
|
|
101
|
-
>
|
|
102
|
-
<div
|
|
103
|
-
ref={refItem}
|
|
104
|
-
onClick={handleLabelClick}
|
|
105
|
-
className={clsx(classes.item, {
|
|
106
|
-
[classes.booleanItem]: isBoolean,
|
|
107
|
-
})}
|
|
108
|
-
>
|
|
109
|
-
<div className={classes.name}>{filter.name}</div>
|
|
110
|
-
{!isBoolean && value !== undefined && value !== null && (
|
|
111
|
-
<div className={classes.value}>
|
|
112
|
-
<FilterValueView
|
|
113
|
-
value={value}
|
|
114
|
-
filter={filter}
|
|
115
|
-
localeKey={localeKey}
|
|
116
|
-
locale={locale}
|
|
117
|
-
testId={getTestId(testId, 'value')}
|
|
118
|
-
tweakStyles={tweakFilterValueViewStyles}
|
|
119
|
-
/>
|
|
120
|
-
</div>
|
|
121
|
-
)}
|
|
122
|
-
{!isBoolean && (
|
|
123
|
-
<div className={clsx(classes.iconContainer, isOpen && classes.open)}>
|
|
124
|
-
<Icon type="chevron-down" />
|
|
125
|
-
</div>
|
|
126
|
-
)}
|
|
127
|
-
</div>
|
|
128
|
-
<CSSTransition
|
|
129
|
-
in={isOpen}
|
|
130
|
-
timeout={150}
|
|
131
|
-
unmountOnExit
|
|
132
|
-
classNames={{
|
|
133
|
-
enter: classes['dropdown-enter'],
|
|
134
|
-
enterActive: classes['dropdown-enter-active'],
|
|
135
|
-
exit: classes['dropdown-exit'],
|
|
136
|
-
exitActive: classes['dropdown-exit-active'],
|
|
137
|
-
}}
|
|
138
|
-
>
|
|
139
|
-
<Filter
|
|
140
|
-
value={value}
|
|
141
|
-
filter={filter}
|
|
142
|
-
localeKey={localeKey}
|
|
143
|
-
locale={locale}
|
|
144
|
-
onClose={handleOnClose}
|
|
145
|
-
onChange={handleChange}
|
|
146
|
-
parentRef={refItem}
|
|
147
|
-
filtersPaneRef={filtersPaneRef}
|
|
148
|
-
testId={testId}
|
|
149
|
-
classes={classes}
|
|
150
|
-
/>
|
|
151
|
-
</CSSTransition>
|
|
152
|
-
</div>
|
|
153
|
-
) : (
|
|
154
|
-
<Filter
|
|
155
|
-
value={value}
|
|
156
|
-
filter={filter}
|
|
157
|
-
localeKey={localeKey}
|
|
158
|
-
locale={locale}
|
|
159
|
-
onClose={handleOnClose}
|
|
160
|
-
onChange={onChange}
|
|
161
|
-
isInline
|
|
162
|
-
filtersPaneRef={filtersPaneRef}
|
|
163
|
-
testId={testId}
|
|
164
|
-
classes={classes}
|
|
165
|
-
/>
|
|
166
|
-
);
|
|
167
|
-
}
|
|
1
|
+
import { useState, useRef, RefObject } from 'react';
|
|
2
|
+
import { CSSTransition } from 'react-transition-group';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import { addDataTestId, getTestId } from '@true-engineering/true-react-platform-helpers';
|
|
5
|
+
import { addDataAttributes } from '../../../../helpers';
|
|
6
|
+
import { useTweakStyles } from '../../../../hooks';
|
|
7
|
+
import { ICommonProps } from '../../../../types';
|
|
8
|
+
import { Icon } from '../../../Icon';
|
|
9
|
+
import { ConfigItem, IFilterLocaleKey, IPartialFilterLocale } from '../../types';
|
|
10
|
+
import { Filter } from '../Filter';
|
|
11
|
+
import { FilterValueView } from '../FilterValueView';
|
|
12
|
+
import { useStyles, IFilterWrapperStyles } from './FilterWrapper.styles';
|
|
13
|
+
|
|
14
|
+
export interface IFilterWrapperProps<Values, Key extends keyof Values>
|
|
15
|
+
extends ICommonProps<IFilterWrapperStyles> {
|
|
16
|
+
filter: ConfigItem<Values[Key]>;
|
|
17
|
+
value?: Values[Key];
|
|
18
|
+
isDisabled?: boolean;
|
|
19
|
+
localeKey?: IFilterLocaleKey;
|
|
20
|
+
locale?: IPartialFilterLocale;
|
|
21
|
+
filtersPaneRef: RefObject<HTMLDivElement> | null;
|
|
22
|
+
onChange: <V>(value: V) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function FilterWrapper<Values, Key extends keyof Values>({
|
|
26
|
+
filter,
|
|
27
|
+
value,
|
|
28
|
+
isDisabled,
|
|
29
|
+
locale,
|
|
30
|
+
localeKey,
|
|
31
|
+
data,
|
|
32
|
+
testId,
|
|
33
|
+
filtersPaneRef,
|
|
34
|
+
tweakStyles,
|
|
35
|
+
onChange,
|
|
36
|
+
}: IFilterWrapperProps<Values, Key>): JSX.Element {
|
|
37
|
+
const classes = useStyles({ theme: tweakStyles });
|
|
38
|
+
|
|
39
|
+
const tweakFilterValueViewStyles = useTweakStyles({
|
|
40
|
+
tweakStyles,
|
|
41
|
+
className: 'tweakValueView',
|
|
42
|
+
currentComponentName: 'FilterWrapper',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
46
|
+
const refItem = useRef<HTMLDivElement>(null);
|
|
47
|
+
|
|
48
|
+
const { type } = filter;
|
|
49
|
+
|
|
50
|
+
let hasValue = false;
|
|
51
|
+
|
|
52
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
53
|
+
hasValue = true;
|
|
54
|
+
} else if (
|
|
55
|
+
typeof value === 'object' &&
|
|
56
|
+
Object.values(value as unknown as Record<any, any>).some((v) =>
|
|
57
|
+
Array.isArray(v) ? v.length > 0 : Boolean(v),
|
|
58
|
+
)
|
|
59
|
+
) {
|
|
60
|
+
hasValue = true;
|
|
61
|
+
} else if (!Array.isArray(value) && typeof value !== 'object') {
|
|
62
|
+
hasValue = Boolean(value);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Для того, чтобы фильтр закрывался, если мы работаем с простыми значениями, типа селекта
|
|
66
|
+
function handleChange<V>(v: V) {
|
|
67
|
+
if (type === 'select') {
|
|
68
|
+
setIsOpen(false);
|
|
69
|
+
}
|
|
70
|
+
onChange(v);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const handleLabelClick = () => {
|
|
74
|
+
if (!isBoolean && !isDisabled) {
|
|
75
|
+
setIsOpen(!isOpen);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (isBoolean) {
|
|
79
|
+
onChange(!value);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const handleOnClose = () => {
|
|
84
|
+
setIsOpen(false);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const isBoolean = filter.type === 'boolean';
|
|
88
|
+
|
|
89
|
+
return !filter.isInline ? (
|
|
90
|
+
<div
|
|
91
|
+
className={clsx(classes.root, {
|
|
92
|
+
[classes.noValue]: !hasValue,
|
|
93
|
+
[classes.openNoValue]: isOpen && !hasValue,
|
|
94
|
+
[classes.withValue]: !isOpen && hasValue,
|
|
95
|
+
[classes.openWithValue]: isOpen && hasValue,
|
|
96
|
+
[classes.boolean]: isBoolean,
|
|
97
|
+
[classes.disabled]: isDisabled,
|
|
98
|
+
})}
|
|
99
|
+
{...addDataTestId(testId)}
|
|
100
|
+
{...addDataAttributes(data)}
|
|
101
|
+
>
|
|
102
|
+
<div
|
|
103
|
+
ref={refItem}
|
|
104
|
+
onClick={handleLabelClick}
|
|
105
|
+
className={clsx(classes.item, {
|
|
106
|
+
[classes.booleanItem]: isBoolean,
|
|
107
|
+
})}
|
|
108
|
+
>
|
|
109
|
+
<div className={classes.name}>{filter.name}</div>
|
|
110
|
+
{!isBoolean && value !== undefined && value !== null && (
|
|
111
|
+
<div className={classes.value}>
|
|
112
|
+
<FilterValueView
|
|
113
|
+
value={value}
|
|
114
|
+
filter={filter}
|
|
115
|
+
localeKey={localeKey}
|
|
116
|
+
locale={locale}
|
|
117
|
+
testId={getTestId(testId, 'value')}
|
|
118
|
+
tweakStyles={tweakFilterValueViewStyles}
|
|
119
|
+
/>
|
|
120
|
+
</div>
|
|
121
|
+
)}
|
|
122
|
+
{!isBoolean && (
|
|
123
|
+
<div className={clsx(classes.iconContainer, isOpen && classes.open)}>
|
|
124
|
+
<Icon type="chevron-down" />
|
|
125
|
+
</div>
|
|
126
|
+
)}
|
|
127
|
+
</div>
|
|
128
|
+
<CSSTransition
|
|
129
|
+
in={isOpen}
|
|
130
|
+
timeout={150}
|
|
131
|
+
unmountOnExit
|
|
132
|
+
classNames={{
|
|
133
|
+
enter: classes['dropdown-enter'],
|
|
134
|
+
enterActive: classes['dropdown-enter-active'],
|
|
135
|
+
exit: classes['dropdown-exit'],
|
|
136
|
+
exitActive: classes['dropdown-exit-active'],
|
|
137
|
+
}}
|
|
138
|
+
>
|
|
139
|
+
<Filter
|
|
140
|
+
value={value}
|
|
141
|
+
filter={filter}
|
|
142
|
+
localeKey={localeKey}
|
|
143
|
+
locale={locale}
|
|
144
|
+
onClose={handleOnClose}
|
|
145
|
+
onChange={handleChange}
|
|
146
|
+
parentRef={refItem}
|
|
147
|
+
filtersPaneRef={filtersPaneRef}
|
|
148
|
+
testId={testId}
|
|
149
|
+
classes={classes}
|
|
150
|
+
/>
|
|
151
|
+
</CSSTransition>
|
|
152
|
+
</div>
|
|
153
|
+
) : (
|
|
154
|
+
<Filter
|
|
155
|
+
value={value}
|
|
156
|
+
filter={filter}
|
|
157
|
+
localeKey={localeKey}
|
|
158
|
+
locale={locale}
|
|
159
|
+
onClose={handleOnClose}
|
|
160
|
+
onChange={onChange}
|
|
161
|
+
isInline
|
|
162
|
+
filtersPaneRef={filtersPaneRef}
|
|
163
|
+
testId={testId}
|
|
164
|
+
classes={classes}
|
|
165
|
+
/>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { countries } from 'country-flag-icons';
|
|
2
|
-
import { ComponentStory } from '@storybook/react';
|
|
3
|
-
import { Flag } from './Flag';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: 'Data Display/Flag',
|
|
7
|
-
component: Flag,
|
|
8
|
-
argTypes: {
|
|
9
|
-
countryCode: { control: 'select', options: countries },
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const Template: ComponentStory<typeof Flag> = (args) => (
|
|
14
|
-
<div style={{ width: 60, height: 40 }}>
|
|
15
|
-
<Flag {...args} />
|
|
16
|
-
</div>
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
export const Default = Template.bind({});
|
|
20
|
-
|
|
21
|
-
Default.args = {
|
|
22
|
-
countryCode: 'ug',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
Default.parameters = {
|
|
26
|
-
controls: {
|
|
27
|
-
exclude: ['data'],
|
|
28
|
-
},
|
|
29
|
-
};
|
|
1
|
+
import { countries } from 'country-flag-icons';
|
|
2
|
+
import { ComponentStory } from '@storybook/react';
|
|
3
|
+
import { Flag } from './Flag';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Data Display/Flag',
|
|
7
|
+
component: Flag,
|
|
8
|
+
argTypes: {
|
|
9
|
+
countryCode: { control: 'select', options: countries },
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const Template: ComponentStory<typeof Flag> = (args) => (
|
|
14
|
+
<div style={{ width: 60, height: 40 }}>
|
|
15
|
+
<Flag {...args} />
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const Default = Template.bind({});
|
|
20
|
+
|
|
21
|
+
Default.args = {
|
|
22
|
+
countryCode: 'ug',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
Default.parameters = {
|
|
26
|
+
controls: {
|
|
27
|
+
exclude: ['data'],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import { hasFlag } from 'country-flag-icons';
|
|
3
|
-
import Flags from 'country-flag-icons/react/3x2';
|
|
4
|
-
import { ICommonProps } from '../../types';
|
|
5
|
-
import { Icon } from '../Icon';
|
|
6
|
-
import { useStyles, IFlagStyles } from './Flag.styles';
|
|
7
|
-
|
|
8
|
-
export interface IFlagProps extends Pick<ICommonProps<IFlagStyles>, 'tweakStyles'> {
|
|
9
|
-
/** @default '' */
|
|
10
|
-
countryCode?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const Flag: FC<IFlagProps> = ({ countryCode = '', tweakStyles }) => {
|
|
14
|
-
const classes = useStyles({ theme: tweakStyles });
|
|
15
|
-
const CC = countryCode.toUpperCase();
|
|
16
|
-
|
|
17
|
-
const TheFlag = hasFlag(CC)
|
|
18
|
-
? Flags[CC as keyof typeof Flags]
|
|
19
|
-
: () => (
|
|
20
|
-
<div className={classes.noFlag}>
|
|
21
|
-
<Icon type="minus" />
|
|
22
|
-
</div>
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
return <TheFlag className={classes.root} />;
|
|
26
|
-
};
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { hasFlag } from 'country-flag-icons';
|
|
3
|
+
import Flags from 'country-flag-icons/react/3x2';
|
|
4
|
+
import { ICommonProps } from '../../types';
|
|
5
|
+
import { Icon } from '../Icon';
|
|
6
|
+
import { useStyles, IFlagStyles } from './Flag.styles';
|
|
7
|
+
|
|
8
|
+
export interface IFlagProps extends Pick<ICommonProps<IFlagStyles>, 'tweakStyles'> {
|
|
9
|
+
/** @default '' */
|
|
10
|
+
countryCode?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const Flag: FC<IFlagProps> = ({ countryCode = '', tweakStyles }) => {
|
|
14
|
+
const classes = useStyles({ theme: tweakStyles });
|
|
15
|
+
const CC = countryCode.toUpperCase();
|
|
16
|
+
|
|
17
|
+
const TheFlag = hasFlag(CC)
|
|
18
|
+
? Flags[CC as keyof typeof Flags]
|
|
19
|
+
: () => (
|
|
20
|
+
<div className={classes.noFlag}>
|
|
21
|
+
<Icon type="minus" />
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return <TheFlag className={classes.root} />;
|
|
26
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
declare module 'country-flag-icons/react/3x2';
|
|
1
|
+
declare module 'country-flag-icons/react/3x2';
|