@omniumretail/component-library 1.0.64 → 1.0.66

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.
Files changed (176) hide show
  1. package/.storybook/main.js +16 -16
  2. package/.storybook/preview-head.html +20 -20
  3. package/.storybook/preview.js +27 -27
  4. package/README.md +54 -54
  5. package/bitbucket-pipelines.yml +94 -94
  6. package/package.json +198 -198
  7. package/src/assets/scss/_global.scss +89 -89
  8. package/src/assets/scss/index.scss +2 -2
  9. package/src/components/AnalyticsBar/AnalyticsBar.stories.tsx +236 -236
  10. package/src/components/AnalyticsBar/helpers/codeMutation.tsx +19 -19
  11. package/src/components/AnalyticsBar/index.tsx +76 -76
  12. package/src/components/AnalyticsBar/interfaces/analyticsBar.tsx +13 -13
  13. package/src/components/AnalyticsBar/styles.module.scss +108 -108
  14. package/src/components/Button/Button.stories.tsx +26 -26
  15. package/src/components/Button/index.tsx +24 -24
  16. package/src/components/Button/styles.module.scss +65 -65
  17. package/src/components/Category/Category.stories.tsx +88 -88
  18. package/src/components/Category/CategoryContent/index.tsx +188 -188
  19. package/src/components/Category/CategoryContent/styles.module.scss +51 -51
  20. package/src/components/Category/CategorySidebar/index.tsx +268 -268
  21. package/src/components/Category/CategorySidebar/styles.module.scss +28 -28
  22. package/src/components/Category/index.tsx +76 -76
  23. package/src/components/Category/styles.module.scss +13 -13
  24. package/src/components/CategoryReadOnly/CategoryReadOnly.stories.tsx +270 -270
  25. package/src/components/CategoryReadOnly/evaluationOptions.tsx +81 -81
  26. package/src/components/CategoryReadOnly/index.tsx +254 -254
  27. package/src/components/CategoryReadOnly/styles.module.scss +184 -184
  28. package/src/components/CategoryResponse/CategoryResponse.stories.tsx +251 -251
  29. package/src/components/CategoryResponse/evaluationOptions.tsx +81 -81
  30. package/src/components/CategoryResponse/index.tsx +277 -277
  31. package/src/components/CategoryResponse/styles.module.scss +160 -137
  32. package/src/components/DatePicker/DatePicker.stories.tsx +16 -16
  33. package/src/components/DatePicker/index.tsx +38 -38
  34. package/src/components/DatePicker/styles.module.scss +3 -3
  35. package/src/components/DatePickerTag/DatePickerTag.stories.tsx +19 -19
  36. package/src/components/DatePickerTag/index.tsx +89 -85
  37. package/src/components/DatePickerTag/styles.module.scss +31 -31
  38. package/src/components/Footer/Footer.stories.tsx +14 -14
  39. package/src/components/Footer/index.tsx +38 -38
  40. package/src/components/Footer/styles.module.scss +38 -38
  41. package/src/components/Input/Input.stories.tsx +13 -13
  42. package/src/components/Input/index.tsx +31 -31
  43. package/src/components/Input/styles.module.scss +8 -8
  44. package/src/components/InputCountryCode/index.tsx +75 -75
  45. package/src/components/InputCountryCode/inputCountryCode.stories.tsx +55 -55
  46. package/src/components/InputCountryCode/styles.module.scss +3 -3
  47. package/src/components/Label/Label.stories.tsx +21 -21
  48. package/src/components/Label/index.tsx +19 -19
  49. package/src/components/Label/styles.module.scss +16 -16
  50. package/src/components/Link/Link.stories.tsx +30 -30
  51. package/src/components/Link/index.tsx +21 -21
  52. package/src/components/Link/styles.module.scss +24 -24
  53. package/src/components/Menu/Menu.stories.tsx +178 -178
  54. package/src/components/Menu/helpers/codeMutation.tsx +19 -19
  55. package/src/components/Menu/index.tsx +23 -23
  56. package/src/components/ModalConfirmation/ModalConfirmation.stories.tsx +40 -40
  57. package/src/components/ModalConfirmation/ModalStatusList.tsx +5 -5
  58. package/src/components/ModalConfirmation/index.tsx +70 -70
  59. package/src/components/ModalConfirmation/styles.module.scss +62 -62
  60. package/src/components/ModalWithTable/ModalWithTable.stories.tsx +96 -96
  61. package/src/components/ModalWithTable/index.tsx +232 -232
  62. package/src/components/ModalWithTable/styles.module.scss +77 -77
  63. package/src/components/Navigation/Navigation.stories.tsx +17 -17
  64. package/src/components/Navigation/index.tsx +33 -33
  65. package/src/components/Navigation/styles.module.scss +42 -42
  66. package/src/components/Notification/Notification.stories.tsx +29 -29
  67. package/src/components/Notification/index.tsx +21 -21
  68. package/src/components/Questions/Questions.stories.tsx +37 -37
  69. package/src/components/Questions/SingleQuestion/index.tsx +84 -84
  70. package/src/components/Questions/SingleQuestion/styles.module.scss +81 -81
  71. package/src/components/Questions/index.tsx +78 -78
  72. package/src/components/Radio/Radio.stories.tsx +43 -43
  73. package/src/components/Radio/index.tsx +26 -26
  74. package/src/components/Radio/styles.module.scss +23 -23
  75. package/src/components/Select/Select.stories.tsx +39 -39
  76. package/src/components/Select/index.tsx +27 -27
  77. package/src/components/Select/styles.module.scss +13 -13
  78. package/src/components/Separator/Separator.stories.tsx +22 -22
  79. package/src/components/Separator/index.tsx +27 -27
  80. package/src/components/Separator/styles.module.scss +25 -25
  81. package/src/components/Sidebar/Sidebar.stories.tsx +85 -61
  82. package/src/components/Sidebar/index.tsx +104 -58
  83. package/src/components/Sidebar/styles.module.scss +86 -73
  84. package/src/components/Switch/Switch.stories.tsx +14 -14
  85. package/src/components/Switch/index.tsx +8 -8
  86. package/src/components/Switch/styles.module.scss +7 -7
  87. package/src/components/Table/Table.stories.tsx +221 -221
  88. package/src/components/Table/index.tsx +271 -271
  89. package/src/components/Table/styles.module.scss +75 -75
  90. package/src/components/Tag/Tag.stories.tsx +22 -22
  91. package/src/components/Tag/index.tsx +189 -189
  92. package/src/components/Tag/styles.module.scss +60 -60
  93. package/src/components/Upload/Upload.stories.tsx +45 -45
  94. package/src/components/Upload/index.tsx +91 -91
  95. package/src/components/UserInfo/UserInfo.stories.tsx +37 -37
  96. package/src/components/UserInfo/index.tsx +62 -62
  97. package/src/components/UserInfo/styles.module.scss +29 -29
  98. package/src/components/index.tsx +25 -25
  99. package/src/constants/i18n.ts +25 -25
  100. package/src/constants/translationHelper.ts +7 -7
  101. package/src/index.ts +2 -2
  102. package/src/locales/en.json +86 -81
  103. package/src/locales/es.json +86 -81
  104. package/src/locales/pt.json +86 -81
  105. package/src/types/Global.d.ts +4 -4
  106. package/tsconfig.json +29 -29
  107. package/webpack.config.js +51 -51
  108. package/dist/bundle.js +0 -12047
  109. package/dist/main.css +0 -1172
  110. package/dist/types/components/AnalyticsBar/AnalyticsBar.stories.d.ts +0 -5
  111. package/dist/types/components/AnalyticsBar/helpers/codeMutation.d.ts +0 -4
  112. package/dist/types/components/AnalyticsBar/index.d.ts +0 -2
  113. package/dist/types/components/AnalyticsBar/interfaces/analyticsBar.d.ts +0 -12
  114. package/dist/types/components/Button/Button.stories.d.ts +0 -6
  115. package/dist/types/components/Button/index.d.ts +0 -7
  116. package/dist/types/components/Category/Category.stories.d.ts +0 -4
  117. package/dist/types/components/Category/CategoryContent/index.d.ts +0 -7
  118. package/dist/types/components/Category/CategorySidebar/index.d.ts +0 -26
  119. package/dist/types/components/Category/index.d.ts +0 -7
  120. package/dist/types/components/CategoryReadOnly/CategoryReadOnly.stories.d.ts +0 -4
  121. package/dist/types/components/CategoryReadOnly/evaluationOptions.d.ts +0 -10
  122. package/dist/types/components/CategoryReadOnly/index.d.ts +0 -9
  123. package/dist/types/components/CategoryResponse/CategoryResponse.stories.d.ts +0 -4
  124. package/dist/types/components/CategoryResponse/evaluationOptions.d.ts +0 -10
  125. package/dist/types/components/CategoryResponse/index.d.ts +0 -9
  126. package/dist/types/components/DatePicker/DatePicker.stories.d.ts +0 -5
  127. package/dist/types/components/DatePicker/index.d.ts +0 -8
  128. package/dist/types/components/DatePickerTag/DatePickerTag.stories.d.ts +0 -5
  129. package/dist/types/components/DatePickerTag/index.d.ts +0 -6
  130. package/dist/types/components/Footer/Footer.stories.d.ts +0 -5
  131. package/dist/types/components/Footer/index.d.ts +0 -4
  132. package/dist/types/components/Input/Input.stories.d.ts +0 -5
  133. package/dist/types/components/Input/index.d.ts +0 -10
  134. package/dist/types/components/InputCountryCode/index.d.ts +0 -10
  135. package/dist/types/components/InputCountryCode/inputCountryCode.stories.d.ts +0 -5
  136. package/dist/types/components/Label/Label.stories.d.ts +0 -6
  137. package/dist/types/components/Label/index.d.ts +0 -7
  138. package/dist/types/components/Link/Link.stories.d.ts +0 -7
  139. package/dist/types/components/Link/index.d.ts +0 -7
  140. package/dist/types/components/Menu/Menu.stories.d.ts +0 -5
  141. package/dist/types/components/Menu/helpers/codeMutation.d.ts +0 -4
  142. package/dist/types/components/Menu/index.d.ts +0 -2
  143. package/dist/types/components/ModalConfirmation/ModalConfirmation.stories.d.ts +0 -5
  144. package/dist/types/components/ModalConfirmation/ModalStatusList.d.ts +0 -5
  145. package/dist/types/components/ModalConfirmation/index.d.ts +0 -9
  146. package/dist/types/components/ModalWithTable/ModalWithTable.stories.d.ts +0 -5
  147. package/dist/types/components/ModalWithTable/index.d.ts +0 -13
  148. package/dist/types/components/Navigation/Navigation.stories.d.ts +0 -5
  149. package/dist/types/components/Navigation/index.d.ts +0 -10
  150. package/dist/types/components/Notification/Notification.stories.d.ts +0 -5
  151. package/dist/types/components/Notification/index.d.ts +0 -9
  152. package/dist/types/components/Questions/Questions.stories.d.ts +0 -4
  153. package/dist/types/components/Questions/SingleQuestion/index.d.ts +0 -1
  154. package/dist/types/components/Questions/index.d.ts +0 -5
  155. package/dist/types/components/Radio/Radio.stories.d.ts +0 -5
  156. package/dist/types/components/Radio/index.d.ts +0 -10
  157. package/dist/types/components/Select/Select.stories.d.ts +0 -6
  158. package/dist/types/components/Select/index.d.ts +0 -5
  159. package/dist/types/components/Separator/Separator.stories.d.ts +0 -6
  160. package/dist/types/components/Separator/index.d.ts +0 -11
  161. package/dist/types/components/Sidebar/Sidebar.stories.d.ts +0 -6
  162. package/dist/types/components/Sidebar/index.d.ts +0 -13
  163. package/dist/types/components/Switch/Switch.stories.d.ts +0 -5
  164. package/dist/types/components/Switch/index.d.ts +0 -2
  165. package/dist/types/components/Table/Table.stories.d.ts +0 -9
  166. package/dist/types/components/Table/index.d.ts +0 -36
  167. package/dist/types/components/Tag/Tag.stories.d.ts +0 -5
  168. package/dist/types/components/Tag/index.d.ts +0 -8
  169. package/dist/types/components/Upload/Upload.stories.d.ts +0 -4
  170. package/dist/types/components/Upload/index.d.ts +0 -8
  171. package/dist/types/components/UserInfo/UserInfo.stories.d.ts +0 -4
  172. package/dist/types/components/UserInfo/index.d.ts +0 -8
  173. package/dist/types/components/index.d.ts +0 -25
  174. package/dist/types/constants/i18n.d.ts +0 -1
  175. package/dist/types/constants/translationHelper.d.ts +0 -2
  176. package/dist/types/index.d.ts +0 -2
@@ -1,75 +1,75 @@
1
- .tableWrapper {
2
- display: flex;
3
- flex-wrap: wrap;
4
- flex-direction: column;
5
-
6
- :global {
7
- .ant-table-thead > tr > th {
8
- background-color: transparent;
9
- border: 0px;
10
- color: var(--color-blue);
11
-
12
- &:before {
13
- display: none;
14
- }
15
- }
16
-
17
- .ant-table-tbody {
18
- > tr {
19
- cursor: pointer;
20
-
21
- &:last-child {
22
- > td {
23
- border-bottom: 1px solid var(--color-grey-light) !important;
24
- }
25
- }
26
-
27
- &:first-child {
28
- > td {
29
- border-top: 1px solid var(--color-blue) !important;
30
- }
31
- }
32
-
33
- &:hover {
34
- td {
35
- border-radius: 0 !important;
36
- border-bottom-color: var(--color-grey-light) !important;
37
- }
38
- }
39
- }
40
- }
41
-
42
- .ant-space {
43
- align-self: flex-end;
44
- }
45
-
46
- .ant-select-selection-placeholder {
47
- color: var(--color-black);
48
- }
49
-
50
- .ant-select-selector,
51
- .ant-select-focused .ant-select-selection-search {
52
- border: none !important;
53
- box-shadow: none !important;
54
-
55
- &:focus,
56
- &:hover {
57
- border: none !important;
58
- box-shadow: none !important;
59
- }
60
- }
61
-
62
- .ant-pagination {
63
- max-width: calc(100% - 200px);
64
- margin-left: auto !important;
65
- }
66
-
67
- button[type="button"].ant-pagination-item-link {
68
- margin-top: 0 !important;
69
- }
70
- }
71
-
72
- button[type="button"] {
73
- margin-top: -50px;
74
- }
75
- }
1
+ .tableWrapper {
2
+ display: flex;
3
+ flex-wrap: wrap;
4
+ flex-direction: column;
5
+
6
+ :global {
7
+ .ant-table-thead > tr > th {
8
+ background-color: transparent;
9
+ border: 0px;
10
+ color: var(--color-blue);
11
+
12
+ &:before {
13
+ display: none;
14
+ }
15
+ }
16
+
17
+ .ant-table-tbody {
18
+ > tr {
19
+ cursor: pointer;
20
+
21
+ &:last-child {
22
+ > td {
23
+ border-bottom: 1px solid var(--color-grey-light) !important;
24
+ }
25
+ }
26
+
27
+ &:first-child {
28
+ > td {
29
+ border-top: 1px solid var(--color-blue) !important;
30
+ }
31
+ }
32
+
33
+ &:hover {
34
+ td {
35
+ border-radius: 0 !important;
36
+ border-bottom-color: var(--color-grey-light) !important;
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ .ant-space {
43
+ align-self: flex-end;
44
+ }
45
+
46
+ .ant-select-selection-placeholder {
47
+ color: var(--color-black);
48
+ }
49
+
50
+ .ant-select-selector,
51
+ .ant-select-focused .ant-select-selection-search {
52
+ border: none !important;
53
+ box-shadow: none !important;
54
+
55
+ &:focus,
56
+ &:hover {
57
+ border: none !important;
58
+ box-shadow: none !important;
59
+ }
60
+ }
61
+
62
+ .ant-pagination {
63
+ max-width: calc(100% - 200px);
64
+ margin-left: auto !important;
65
+ }
66
+
67
+ button[type="button"].ant-pagination-item-link {
68
+ margin-top: 0 !important;
69
+ }
70
+ }
71
+
72
+ button[type="button"] {
73
+ margin-top: -50px;
74
+ }
75
+ }
@@ -1,22 +1,22 @@
1
- import { Meta, Story } from "@storybook/react";
2
- import { TagField } from '.';
3
- import { TagProps } from 'antd';
4
- import { useState } from "react";
5
-
6
- export default {
7
- title: 'TagField',
8
- component: TagField,
9
- } as Meta;
10
-
11
- const Template: Story<TagProps> = (args) => {
12
- const [tagsInfo, setTagsInfo] = useState<any>({});
13
- const [advancedTagsInfo, setAdvancedTagsInfo] = useState<any>({});
14
-
15
- console.log('page: basic', tagsInfo,'advanced', advancedTagsInfo);
16
-
17
- return <TagField {...args} tagsInfo={setTagsInfo} advancedTagsInfo={setAdvancedTagsInfo}></TagField>;
18
- }
19
-
20
- export const Primary = Template.bind({});
21
- Primary.args = {
22
- };
1
+ import { Meta, Story } from "@storybook/react";
2
+ import { TagField } from '.';
3
+ import { TagProps } from 'antd';
4
+ import { useState } from "react";
5
+
6
+ export default {
7
+ title: 'TagField',
8
+ component: TagField,
9
+ } as Meta;
10
+
11
+ const Template: Story<TagProps> = (args) => {
12
+ const [tagsInfo, setTagsInfo] = useState<any>({});
13
+ const [advancedTagsInfo, setAdvancedTagsInfo] = useState<any>({});
14
+
15
+ console.log('page: basic', tagsInfo,'advanced', advancedTagsInfo);
16
+
17
+ return <TagField {...args} tagsInfo={setTagsInfo} advancedTagsInfo={setAdvancedTagsInfo}></TagField>;
18
+ }
19
+
20
+ export const Primary = Template.bind({});
21
+ Primary.args = {
22
+ };
@@ -1,189 +1,189 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- import { SearchOutlined } from '@ant-design/icons';
3
- import type { InputRef } from 'antd';
4
- import { Input, Tag, TagProps } from 'antd';
5
- import { TweenOneGroup } from 'rc-tween-one';
6
- import styles from './styles.module.scss';
7
- import classNames from 'classnames';
8
- import { t } from 'i18next';
9
-
10
- export interface customTagProps extends TagProps {
11
- customTags?: string[],
12
- tagsInfo?: (tags: string[]) => void,
13
- advancedTagsInfo?: (tags: string[]) => void,
14
- advancedTags?: string[],
15
- }
16
-
17
- export const TagField = (props: customTagProps) => {
18
- const { customTags = [], advancedTags } = props;
19
-
20
- const [tags, setTags] = useState<string[]>(customTags.filter(tag => !tag.includes('=')));
21
- const [inputVisible, setInputVisible] = useState<boolean>(false);
22
- const [inputValue, setInputValue] = useState('');
23
- const inputRef = useRef<InputRef>(null);
24
- const [advancedTagList, setAdvancedTagList] = useState<string[]>([]);
25
- const [allTags, setAllTags] = useState<string[]>([]);
26
-
27
- useEffect(() => {
28
- if (inputVisible) {
29
- inputRef.current?.focus();
30
- }
31
- }, [inputVisible]);
32
-
33
- const handleClose = (removedTag: string) => {
34
- const newAllTags = allTags.filter((tag) => tag !== removedTag);
35
- setAllTags(newAllTags);
36
-
37
- const newTags = tags.filter((tag) => tag !== removedTag);
38
- setTags(newTags);
39
-
40
- if (advancedTags && advancedTagList.includes(removedTag)) {
41
- const newAdvancedTags = advancedTagList.filter((tag) => tag !== removedTag);
42
- setAdvancedTagList(newAdvancedTags);
43
- }
44
- };
45
-
46
- const showInput = () => {
47
- setInputVisible(true);
48
- };
49
-
50
- const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
51
- setInputValue(e.target.value);
52
- };
53
-
54
- const handleInputConfirm = () => {
55
- let isAdvancedTag = false;
56
- if (inputValue && allTags.indexOf(inputValue) === -1) {
57
- setAllTags([...allTags, inputValue]); // Add to allTags
58
- if (advancedTags && advancedTags.includes(inputValue.split('=')[0]) && !advancedTags.includes(inputValue)) {
59
- setAdvancedTagList([...advancedTagList, inputValue]);
60
- isAdvancedTag = true;
61
- }
62
-
63
- // Only add the inputValue to the tags array if it's not an advanced tag
64
- if (!isAdvancedTag) {
65
- setTags([...tags, inputValue]);
66
- }
67
- }
68
-
69
- setInputVisible(false);
70
- setInputValue('');
71
-
72
- const basicTags = tags.filter((tag) => !advancedTagList.includes(tag));
73
- props.tagsInfo?.(basicTags);
74
- props.advancedTagsInfo?.(advancedTagList);
75
- };
76
-
77
- const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
78
- const cursorPosition: any = e.currentTarget.selectionStart;
79
- const advancedFilterMatch = advancedTags && advancedTags.find((filter: any) => inputValue.startsWith(`${filter}=`));
80
- if (advancedFilterMatch) {
81
- const filterLength = advancedFilterMatch.length;
82
- if (cursorPosition <= filterLength && ![8, 46].includes(e.keyCode)) {
83
- e.preventDefault();
84
- }
85
- }
86
-
87
- // Prevent the input of '=' manually
88
- if (e.key === "=") {
89
- e.preventDefault();
90
- }
91
- };
92
-
93
- const doSomething = (e: any) => {
94
- const tag = e.target.innerText;
95
- if (!advancedTagList.map(tag => tag.split('=')[0]).includes(tag)) {
96
- setInputValue(`${tag}=`);
97
- setInputVisible(true);
98
- }
99
- };
100
-
101
-
102
- useEffect(() => {
103
- props.tagsInfo?.(tags);
104
- props.advancedTagsInfo?.(advancedTagList);
105
- }, [tags, advancedTagList]);
106
-
107
- const forMap = (tag: string) => {
108
- const tagElem = (
109
- <Tag
110
- closable
111
- onClose={(e) => {
112
- e.preventDefault();
113
- handleClose(tag);
114
- }}
115
- >
116
- {tag}
117
- </Tag>
118
- );
119
- return (
120
- <span key={tag} className={styles['tagfield__new']} style={{ display: 'inline-block' }}>
121
- {tagElem}
122
- </span>
123
- );
124
- };
125
-
126
- const advancedTagsMap = (tag: string) => {
127
- const disabled = advancedTagList.map(tag => tag.split('=')[0]).includes(tag);
128
- return (
129
- <div onClick={!disabled ? doSomething : undefined} key={tag} style={{ color: disabled ? 'gray' : undefined }}>
130
- {tag}
131
- </div>
132
- )
133
- }
134
-
135
- const tagChild = allTags.map(forMap);
136
- const advancedTagsChild = advancedTags && advancedTags.map(advancedTagsMap);
137
-
138
- return (
139
- <div className={styles.tagfield}>
140
- {inputVisible && (
141
- <Input
142
- ref={inputRef}
143
- type="text"
144
- size="small"
145
- value={inputValue}
146
- onChange={handleInputChange}
147
- onKeyDown={handleKeyDown}
148
- onPressEnter={handleInputConfirm}
149
- className={styles['tagfield__input']}
150
- />
151
- )}
152
- {!inputVisible && (
153
- <Tag onClick={showInput} className={classNames(styles['tagfield__creator'], 'site-tag-plus')}>
154
- <SearchOutlined /> {t('components.tag.search')}
155
- </Tag>
156
- )}
157
- {
158
- advancedTags &&
159
- <div style={{ marginTop: 16, marginBottom: 16 }} className={styles.advancedTagsWrapper}>
160
- <div className={styles.label}>
161
- {t('components.tag.advancedFields')}:
162
- </div>
163
- <div className={styles.advancedTags}>
164
- {advancedTagsChild}
165
- </div>
166
- </div>
167
- }
168
- <div style={{ marginTop: 16 }}>
169
- <TweenOneGroup
170
- enter={{
171
- scale: 0.8,
172
- opacity: 0,
173
- type: 'from',
174
- duration: 100,
175
- }}
176
- onEnd={(e: any) => {
177
- if (e.type === 'appear' || e.type === 'enter') {
178
- (e.target as any).style = 'display: inline-block';
179
- }
180
- }}
181
- leave={{ opacity: 0, width: 0, scale: 0, duration: 200 }}
182
- appear={false}
183
- >
184
- {tagChild}
185
- </TweenOneGroup>
186
- </div>
187
- </div>
188
- );
189
- }
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { SearchOutlined } from '@ant-design/icons';
3
+ import type { InputRef } from 'antd';
4
+ import { Input, Tag, TagProps } from 'antd';
5
+ import { TweenOneGroup } from 'rc-tween-one';
6
+ import styles from './styles.module.scss';
7
+ import classNames from 'classnames';
8
+ import { t } from 'i18next';
9
+
10
+ export interface customTagProps extends TagProps {
11
+ customTags?: string[],
12
+ tagsInfo?: (tags: string[]) => void,
13
+ advancedTagsInfo?: (tags: string[]) => void,
14
+ advancedTags?: string[],
15
+ }
16
+
17
+ export const TagField = (props: customTagProps) => {
18
+ const { customTags = [], advancedTags } = props;
19
+
20
+ const [tags, setTags] = useState<string[]>(customTags.filter(tag => !tag.includes('=')));
21
+ const [inputVisible, setInputVisible] = useState<boolean>(false);
22
+ const [inputValue, setInputValue] = useState('');
23
+ const inputRef = useRef<InputRef>(null);
24
+ const [advancedTagList, setAdvancedTagList] = useState<string[]>([]);
25
+ const [allTags, setAllTags] = useState<string[]>([]);
26
+
27
+ useEffect(() => {
28
+ if (inputVisible) {
29
+ inputRef.current?.focus();
30
+ }
31
+ }, [inputVisible]);
32
+
33
+ const handleClose = (removedTag: string) => {
34
+ const newAllTags = allTags.filter((tag) => tag !== removedTag);
35
+ setAllTags(newAllTags);
36
+
37
+ const newTags = tags.filter((tag) => tag !== removedTag);
38
+ setTags(newTags);
39
+
40
+ if (advancedTags && advancedTagList.includes(removedTag)) {
41
+ const newAdvancedTags = advancedTagList.filter((tag) => tag !== removedTag);
42
+ setAdvancedTagList(newAdvancedTags);
43
+ }
44
+ };
45
+
46
+ const showInput = () => {
47
+ setInputVisible(true);
48
+ };
49
+
50
+ const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
51
+ setInputValue(e.target.value);
52
+ };
53
+
54
+ const handleInputConfirm = () => {
55
+ let isAdvancedTag = false;
56
+ if (inputValue && allTags.indexOf(inputValue) === -1) {
57
+ setAllTags([...allTags, inputValue]); // Add to allTags
58
+ if (advancedTags && advancedTags.includes(inputValue.split('=')[0]) && !advancedTags.includes(inputValue)) {
59
+ setAdvancedTagList([...advancedTagList, inputValue]);
60
+ isAdvancedTag = true;
61
+ }
62
+
63
+ // Only add the inputValue to the tags array if it's not an advanced tag
64
+ if (!isAdvancedTag) {
65
+ setTags([...tags, inputValue]);
66
+ }
67
+ }
68
+
69
+ setInputVisible(false);
70
+ setInputValue('');
71
+
72
+ const basicTags = tags.filter((tag) => !advancedTagList.includes(tag));
73
+ props.tagsInfo?.(basicTags);
74
+ props.advancedTagsInfo?.(advancedTagList);
75
+ };
76
+
77
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
78
+ const cursorPosition: any = e.currentTarget.selectionStart;
79
+ const advancedFilterMatch = advancedTags && advancedTags.find((filter: any) => inputValue.startsWith(`${filter}=`));
80
+ if (advancedFilterMatch) {
81
+ const filterLength = advancedFilterMatch.length;
82
+ if (cursorPosition <= filterLength && ![8, 46].includes(e.keyCode)) {
83
+ e.preventDefault();
84
+ }
85
+ }
86
+
87
+ // Prevent the input of '=' manually
88
+ if (e.key === "=") {
89
+ e.preventDefault();
90
+ }
91
+ };
92
+
93
+ const doSomething = (e: any) => {
94
+ const tag = e.target.innerText;
95
+ if (!advancedTagList.map(tag => tag.split('=')[0]).includes(tag)) {
96
+ setInputValue(`${tag}=`);
97
+ setInputVisible(true);
98
+ }
99
+ };
100
+
101
+
102
+ useEffect(() => {
103
+ props.tagsInfo?.(tags);
104
+ props.advancedTagsInfo?.(advancedTagList);
105
+ }, [tags, advancedTagList]);
106
+
107
+ const forMap = (tag: string) => {
108
+ const tagElem = (
109
+ <Tag
110
+ closable
111
+ onClose={(e) => {
112
+ e.preventDefault();
113
+ handleClose(tag);
114
+ }}
115
+ >
116
+ {tag}
117
+ </Tag>
118
+ );
119
+ return (
120
+ <span key={tag} className={styles['tagfield__new']} style={{ display: 'inline-block' }}>
121
+ {tagElem}
122
+ </span>
123
+ );
124
+ };
125
+
126
+ const advancedTagsMap = (tag: string) => {
127
+ const disabled = advancedTagList.map(tag => tag.split('=')[0]).includes(tag);
128
+ return (
129
+ <div onClick={!disabled ? doSomething : undefined} key={tag} style={{ color: disabled ? 'gray' : undefined }}>
130
+ {tag}
131
+ </div>
132
+ )
133
+ }
134
+
135
+ const tagChild = allTags.map(forMap);
136
+ const advancedTagsChild = advancedTags && advancedTags.map(advancedTagsMap);
137
+
138
+ return (
139
+ <div className={styles.tagfield}>
140
+ {inputVisible && (
141
+ <Input
142
+ ref={inputRef}
143
+ type="text"
144
+ size="small"
145
+ value={inputValue}
146
+ onChange={handleInputChange}
147
+ onKeyDown={handleKeyDown}
148
+ onPressEnter={handleInputConfirm}
149
+ className={styles['tagfield__input']}
150
+ />
151
+ )}
152
+ {!inputVisible && (
153
+ <Tag onClick={showInput} className={classNames(styles['tagfield__creator'], 'site-tag-plus')}>
154
+ <SearchOutlined /> {t('components.tag.search')}
155
+ </Tag>
156
+ )}
157
+ {
158
+ advancedTags &&
159
+ <div style={{ marginTop: 16, marginBottom: 16 }} className={styles.advancedTagsWrapper}>
160
+ <div className={styles.label}>
161
+ {t('components.tag.advancedFields')}:
162
+ </div>
163
+ <div className={styles.advancedTags}>
164
+ {advancedTagsChild}
165
+ </div>
166
+ </div>
167
+ }
168
+ <div style={{ marginTop: 16 }}>
169
+ <TweenOneGroup
170
+ enter={{
171
+ scale: 0.8,
172
+ opacity: 0,
173
+ type: 'from',
174
+ duration: 100,
175
+ }}
176
+ onEnd={(e: any) => {
177
+ if (e.type === 'appear' || e.type === 'enter') {
178
+ (e.target as any).style = 'display: inline-block';
179
+ }
180
+ }}
181
+ leave={{ opacity: 0, width: 0, scale: 0, duration: 200 }}
182
+ appear={false}
183
+ >
184
+ {tagChild}
185
+ </TweenOneGroup>
186
+ </div>
187
+ </div>
188
+ );
189
+ }