@skbkontur/react-ui 0.0.0-a5ba2462c5 → 0.0.0-a6f09fbded

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 (246) hide show
  1. package/CHANGELOG.md +0 -30
  2. package/cjs/components/Autocomplete/Autocomplete.md +113 -0
  3. package/cjs/components/Button/Button.md +261 -0
  4. package/cjs/components/Calendar/Calendar.md +276 -0
  5. package/cjs/components/Calendar/CalendarDay.md +70 -0
  6. package/cjs/components/Center/Center.md +26 -0
  7. package/cjs/components/Checkbox/Checkbox.md +171 -0
  8. package/cjs/components/ComboBox/ComboBox.d.ts +11 -5
  9. package/cjs/components/ComboBox/ComboBox.js +10 -1
  10. package/cjs/components/ComboBox/ComboBox.js.map +1 -1
  11. package/cjs/components/ComboBox/ComboBox.md +574 -0
  12. package/cjs/components/CurrencyInput/CurrencyInput.md +39 -0
  13. package/cjs/components/CurrencyLabel/CurrencyLabel.js +2 -2
  14. package/cjs/components/CurrencyLabel/CurrencyLabel.js.map +1 -1
  15. package/cjs/components/CurrencyLabel/CurrencyLabel.md +29 -0
  16. package/cjs/components/DateInput/DateInput.md +111 -0
  17. package/cjs/components/DatePicker/DatePicker.md +368 -0
  18. package/cjs/components/Dropdown/Dropdown.md +45 -0
  19. package/cjs/components/DropdownMenu/DropdownMenu.md +290 -0
  20. package/cjs/components/FileUploader/FileUploader.md +131 -0
  21. package/cjs/components/FxInput/FxInput.md +31 -0
  22. package/cjs/components/Gapped/Gapped.md +44 -0
  23. package/cjs/components/GlobalLoader/GlobalLoader.md +97 -0
  24. package/cjs/components/Group/Group.md +19 -0
  25. package/cjs/components/Hint/Hint.md +86 -0
  26. package/cjs/components/Input/Input.md +86 -0
  27. package/cjs/components/Input/InputLayout/InputLayout.d.ts +1 -0
  28. package/cjs/components/Input/InputLayout/InputLayout.js +4 -2
  29. package/cjs/components/Input/InputLayout/InputLayout.js.map +1 -1
  30. package/cjs/components/Kebab/Kebab.md +306 -0
  31. package/cjs/components/Link/Link.md +182 -0
  32. package/cjs/components/Loader/Loader.md +33 -0
  33. package/cjs/components/MaskedInput/MaskedInput.d.ts +0 -8
  34. package/cjs/components/MaskedInput/MaskedInput.js +2 -23
  35. package/cjs/components/MaskedInput/MaskedInput.js.map +1 -1
  36. package/cjs/components/MaskedInput/MaskedInput.md +114 -0
  37. package/cjs/components/MenuFooter/MenuFooter.md +27 -0
  38. package/cjs/components/MenuHeader/MenuHeader.md +35 -0
  39. package/cjs/components/MenuItem/MenuItem.md +139 -0
  40. package/cjs/components/MenuSeparator/MenuSeparator.md +14 -0
  41. package/cjs/components/MiniModal/MiniModal.md +231 -0
  42. package/cjs/components/Modal/Modal.md +56 -0
  43. package/cjs/components/Paging/Paging.md +57 -0
  44. package/cjs/components/PasswordInput/PasswordInput.md +29 -0
  45. package/cjs/components/Radio/Radio.md +57 -0
  46. package/cjs/components/RadioGroup/RadioGroup.md +44 -0
  47. package/cjs/components/ResponsiveLayout/ResponsiveLayout.md +75 -0
  48. package/cjs/components/ScrollContainer/ScrollContainer.md +224 -0
  49. package/cjs/components/Select/Select.md +113 -0
  50. package/cjs/components/SidePage/SidePage.md +65 -0
  51. package/cjs/components/SingleToast/SingleToast.md +36 -0
  52. package/cjs/components/Spinner/Spinner.md +36 -0
  53. package/cjs/components/Sticky/Sticky.md +28 -0
  54. package/cjs/components/Switcher/Switcher.md +111 -0
  55. package/cjs/components/Tabs/Tab.md +73 -0
  56. package/cjs/components/Tabs/Tabs.md +54 -0
  57. package/cjs/components/Textarea/Textarea.d.ts +6 -1
  58. package/cjs/components/Textarea/Textarea.js +16 -3
  59. package/cjs/components/Textarea/Textarea.js.map +1 -1
  60. package/cjs/components/Textarea/Textarea.md +58 -0
  61. package/cjs/components/Textarea/Textarea.styles.js +2 -1
  62. package/cjs/components/Textarea/Textarea.styles.js.map +1 -1
  63. package/cjs/components/Toast/Toast.md +69 -0
  64. package/cjs/components/Toggle/Toggle.md +110 -0
  65. package/cjs/components/Token/Token.md +48 -0
  66. package/cjs/components/TokenInput/TokenInput.md +277 -0
  67. package/cjs/components/Tooltip/Tooltip.d.ts +1 -1
  68. package/cjs/components/Tooltip/Tooltip.js +6 -8
  69. package/cjs/components/Tooltip/Tooltip.js.map +1 -1
  70. package/cjs/components/Tooltip/Tooltip.md +322 -0
  71. package/cjs/components/TooltipMenu/TooltipMenu.md +241 -0
  72. package/cjs/internal/ClearCrossIcon/ClearCrossIcon.d.ts +1 -0
  73. package/cjs/internal/ClearCrossIcon/ClearCrossIcon.js +16 -7
  74. package/cjs/internal/ClearCrossIcon/ClearCrossIcon.js.map +1 -1
  75. package/cjs/internal/ClearCrossIcon/ClearCrossIcon.styles.d.ts +3 -0
  76. package/cjs/internal/ClearCrossIcon/ClearCrossIcon.styles.js +27 -9
  77. package/cjs/internal/ClearCrossIcon/ClearCrossIcon.styles.js.map +1 -1
  78. package/cjs/internal/CustomComboBox/ComboBoxView.d.ts +7 -6
  79. package/cjs/internal/CustomComboBox/ComboBoxView.js +2 -7
  80. package/cjs/internal/CustomComboBox/ComboBoxView.js.map +1 -1
  81. package/cjs/internal/CustomComboBox/CustomComboBox.d.ts +6 -5
  82. package/cjs/internal/CustomComboBox/CustomComboBox.js +1 -3
  83. package/cjs/internal/CustomComboBox/CustomComboBox.js.map +1 -1
  84. package/cjs/internal/CustomComboBox/getComboBoxTheme.d.ts +2 -1
  85. package/cjs/internal/CustomComboBox/getComboBoxTheme.js +10 -7
  86. package/cjs/internal/CustomComboBox/getComboBoxTheme.js.map +1 -1
  87. package/cjs/internal/DataTids/DATATIDS.md +12 -0
  88. package/cjs/internal/DataTids/DataTids.d.ts +12 -0
  89. package/cjs/internal/DataTids/DataTids.js +50 -0
  90. package/cjs/internal/DataTids/DataTids.js.map +1 -0
  91. package/cjs/internal/DataTids/DataTids.styles.d.ts +7 -0
  92. package/cjs/internal/DataTids/DataTids.styles.js +42 -0
  93. package/cjs/internal/DataTids/DataTids.styles.js.map +1 -0
  94. package/cjs/internal/DataTids/componentsDataTids.d.ts +5 -0
  95. package/cjs/internal/DataTids/componentsDataTids.js +15 -0
  96. package/cjs/internal/DataTids/componentsDataTids.js.map +1 -0
  97. package/cjs/internal/InputLikeText/InputLikeText.styles.d.ts +1 -0
  98. package/cjs/internal/InputLikeText/InputLikeText.styles.js +12 -4
  99. package/cjs/internal/InputLikeText/InputLikeText.styles.js.map +1 -1
  100. package/cjs/internal/InternalTextareaWithLayout/InternalTextareaWithLayout.d.ts +37 -0
  101. package/cjs/internal/InternalTextareaWithLayout/InternalTextareaWithLayout.js +235 -0
  102. package/cjs/internal/InternalTextareaWithLayout/InternalTextareaWithLayout.js.map +1 -0
  103. package/cjs/internal/InternalTextareaWithLayout/InternalTextareaWithLayout.styles.d.ts +3 -0
  104. package/cjs/internal/InternalTextareaWithLayout/InternalTextareaWithLayout.styles.js +10 -0
  105. package/cjs/internal/InternalTextareaWithLayout/InternalTextareaWithLayout.styles.js.map +1 -0
  106. package/cjs/internal/ThemePlayground/Playground.md +7 -0
  107. package/cjs/internal/ThemeShowcase/VariablesCollector.d.ts +1 -1
  108. package/cjs/internal/themes/BasicTheme.d.ts +2 -0
  109. package/cjs/internal/themes/BasicTheme.js +11 -6
  110. package/cjs/internal/themes/BasicTheme.js.map +1 -1
  111. package/cjs/internal/themes/DarkTheme5_4.js +10 -3
  112. package/cjs/internal/themes/DarkTheme5_4.js.map +1 -1
  113. package/cjs/internal/themes/LightTheme5_4.js +10 -3
  114. package/cjs/internal/themes/LightTheme5_4.js.map +1 -1
  115. package/cjs/internal/themes/consts.d.ts +7 -0
  116. package/cjs/internal/themes/consts.js +7 -0
  117. package/cjs/internal/themes/consts.js.map +1 -0
  118. package/cjs/lib/featureFlagsContext/FEATUREFLAGSCONTEXT.md +64 -0
  119. package/cjs/lib/locale/LOCALECONTEXT.md +222 -0
  120. package/cjs/lib/theming/ThemeContext.md +265 -0
  121. package/components/Autocomplete/Autocomplete.md +113 -0
  122. package/components/Button/Button.md +261 -0
  123. package/components/Calendar/Calendar.md +276 -0
  124. package/components/Calendar/CalendarDay.md +70 -0
  125. package/components/Center/Center.md +26 -0
  126. package/components/Checkbox/Checkbox.md +171 -0
  127. package/components/ComboBox/ComboBox/ComboBox.js +2 -1
  128. package/components/ComboBox/ComboBox/ComboBox.js.map +1 -1
  129. package/components/ComboBox/ComboBox.d.ts +11 -5
  130. package/components/ComboBox/ComboBox.md +574 -0
  131. package/components/CurrencyInput/CurrencyInput.md +39 -0
  132. package/components/CurrencyLabel/CurrencyLabel/CurrencyLabel.js +1 -1
  133. package/components/CurrencyLabel/CurrencyLabel/CurrencyLabel.js.map +1 -1
  134. package/components/CurrencyLabel/CurrencyLabel.md +29 -0
  135. package/components/DateInput/DateInput.md +111 -0
  136. package/components/DatePicker/DatePicker.md +368 -0
  137. package/components/Dropdown/Dropdown.md +45 -0
  138. package/components/DropdownMenu/DropdownMenu.md +290 -0
  139. package/components/FileUploader/FileUploader.md +131 -0
  140. package/components/FxInput/FxInput.md +31 -0
  141. package/components/Gapped/Gapped.md +44 -0
  142. package/components/GlobalLoader/GlobalLoader.md +97 -0
  143. package/components/Group/Group.md +19 -0
  144. package/components/Hint/Hint.md +86 -0
  145. package/components/Input/Input.md +86 -0
  146. package/components/Input/InputLayout/InputLayout/InputLayout.js +5 -2
  147. package/components/Input/InputLayout/InputLayout/InputLayout.js.map +1 -1
  148. package/components/Input/InputLayout/InputLayout.d.ts +1 -0
  149. package/components/Kebab/Kebab.md +306 -0
  150. package/components/Link/Link.md +182 -0
  151. package/components/Loader/Loader.md +33 -0
  152. package/components/MaskedInput/MaskedInput/MaskedInput.js +1 -11
  153. package/components/MaskedInput/MaskedInput/MaskedInput.js.map +1 -1
  154. package/components/MaskedInput/MaskedInput.d.ts +0 -8
  155. package/components/MaskedInput/MaskedInput.md +114 -0
  156. package/components/MenuFooter/MenuFooter.md +27 -0
  157. package/components/MenuHeader/MenuHeader.md +35 -0
  158. package/components/MenuItem/MenuItem.md +139 -0
  159. package/components/MenuSeparator/MenuSeparator.md +14 -0
  160. package/components/MiniModal/MiniModal.md +231 -0
  161. package/components/Modal/Modal.md +56 -0
  162. package/components/Paging/Paging.md +57 -0
  163. package/components/PasswordInput/PasswordInput.md +29 -0
  164. package/components/Radio/Radio.md +57 -0
  165. package/components/RadioGroup/RadioGroup.md +44 -0
  166. package/components/ResponsiveLayout/ResponsiveLayout.md +75 -0
  167. package/components/ScrollContainer/ScrollContainer.md +224 -0
  168. package/components/Select/Select.md +113 -0
  169. package/components/SidePage/SidePage.md +65 -0
  170. package/components/SingleToast/SingleToast.md +36 -0
  171. package/components/Spinner/Spinner.md +36 -0
  172. package/components/Sticky/Sticky.md +28 -0
  173. package/components/Switcher/Switcher.md +111 -0
  174. package/components/Tabs/Tab.md +73 -0
  175. package/components/Tabs/Tabs.md +54 -0
  176. package/components/Textarea/Textarea/Textarea.js +11 -2
  177. package/components/Textarea/Textarea/Textarea.js.map +1 -1
  178. package/components/Textarea/Textarea.d.ts +6 -1
  179. package/components/Textarea/Textarea.md +58 -0
  180. package/components/Textarea/Textarea.styles/Textarea.styles.js +1 -1
  181. package/components/Textarea/Textarea.styles/Textarea.styles.js.map +1 -1
  182. package/components/Toast/Toast.md +69 -0
  183. package/components/Toggle/Toggle.md +110 -0
  184. package/components/Token/Token.md +48 -0
  185. package/components/TokenInput/TokenInput.md +277 -0
  186. package/components/Tooltip/Tooltip/Tooltip.js +4 -7
  187. package/components/Tooltip/Tooltip/Tooltip.js.map +1 -1
  188. package/components/Tooltip/Tooltip.d.ts +1 -1
  189. package/components/Tooltip/Tooltip.md +322 -0
  190. package/components/TooltipMenu/TooltipMenu.md +241 -0
  191. package/internal/ClearCrossIcon/ClearCrossIcon/ClearCrossIcon.js +21 -7
  192. package/internal/ClearCrossIcon/ClearCrossIcon/ClearCrossIcon.js.map +1 -1
  193. package/internal/ClearCrossIcon/ClearCrossIcon.d.ts +1 -0
  194. package/internal/ClearCrossIcon/ClearCrossIcon.styles/ClearCrossIcon.styles.js +14 -5
  195. package/internal/ClearCrossIcon/ClearCrossIcon.styles/ClearCrossIcon.styles.js.map +1 -1
  196. package/internal/ClearCrossIcon/ClearCrossIcon.styles.d.ts +3 -0
  197. package/internal/CustomComboBox/ComboBoxView/ComboBoxView.js +44 -51
  198. package/internal/CustomComboBox/ComboBoxView/ComboBoxView.js.map +1 -1
  199. package/internal/CustomComboBox/ComboBoxView.d.ts +7 -6
  200. package/internal/CustomComboBox/CustomComboBox/CustomComboBox.js +3 -5
  201. package/internal/CustomComboBox/CustomComboBox/CustomComboBox.js.map +1 -1
  202. package/internal/CustomComboBox/CustomComboBox.d.ts +6 -5
  203. package/internal/CustomComboBox/getComboBoxTheme/getComboBoxTheme.js +5 -3
  204. package/internal/CustomComboBox/getComboBoxTheme/getComboBoxTheme.js.map +1 -1
  205. package/internal/CustomComboBox/getComboBoxTheme.d.ts +2 -1
  206. package/internal/DataTids/DATATIDS.md +12 -0
  207. package/internal/DataTids/DataTids/DataTids.js +69 -0
  208. package/internal/DataTids/DataTids/DataTids.js.map +1 -0
  209. package/internal/DataTids/DataTids/package.json +6 -0
  210. package/internal/DataTids/DataTids.d.ts +12 -0
  211. package/internal/DataTids/DataTids.styles/DataTids.styles.js +20 -0
  212. package/internal/DataTids/DataTids.styles/DataTids.styles.js.map +1 -0
  213. package/internal/DataTids/DataTids.styles/package.json +6 -0
  214. package/internal/DataTids/DataTids.styles.d.ts +7 -0
  215. package/internal/DataTids/componentsDataTids/componentsDataTids.js +12 -0
  216. package/internal/DataTids/componentsDataTids/componentsDataTids.js.map +1 -0
  217. package/internal/DataTids/componentsDataTids/package.json +6 -0
  218. package/internal/DataTids/componentsDataTids.d.ts +5 -0
  219. package/internal/InputLikeText/InputLikeText.styles/InputLikeText.styles.js +7 -4
  220. package/internal/InputLikeText/InputLikeText.styles/InputLikeText.styles.js.map +1 -1
  221. package/internal/InputLikeText/InputLikeText.styles.d.ts +1 -0
  222. package/internal/InternalTextareaWithLayout/InternalTextareaWithLayout/InternalTextareaWithLayout.js +249 -0
  223. package/internal/InternalTextareaWithLayout/InternalTextareaWithLayout/InternalTextareaWithLayout.js.map +1 -0
  224. package/internal/InternalTextareaWithLayout/InternalTextareaWithLayout/package.json +6 -0
  225. package/internal/InternalTextareaWithLayout/InternalTextareaWithLayout.d.ts +37 -0
  226. package/internal/InternalTextareaWithLayout/InternalTextareaWithLayout.styles/InternalTextareaWithLayout.styles.js +8 -0
  227. package/internal/InternalTextareaWithLayout/InternalTextareaWithLayout.styles/InternalTextareaWithLayout.styles.js.map +1 -0
  228. package/internal/InternalTextareaWithLayout/InternalTextareaWithLayout.styles/package.json +6 -0
  229. package/internal/InternalTextareaWithLayout/InternalTextareaWithLayout.styles.d.ts +3 -0
  230. package/internal/ThemePlayground/Playground.md +7 -0
  231. package/internal/ThemeShowcase/VariablesCollector.d.ts +1 -1
  232. package/internal/themes/BasicTheme/BasicTheme.js +4 -4
  233. package/internal/themes/BasicTheme/BasicTheme.js.map +1 -1
  234. package/internal/themes/BasicTheme.d.ts +2 -0
  235. package/internal/themes/DarkTheme5_4/DarkTheme5_4.js +4 -2
  236. package/internal/themes/DarkTheme5_4/DarkTheme5_4.js.map +1 -1
  237. package/internal/themes/LightTheme5_4/LightTheme5_4.js +4 -2
  238. package/internal/themes/LightTheme5_4/LightTheme5_4.js.map +1 -1
  239. package/internal/themes/consts/consts.js +7 -0
  240. package/internal/themes/consts/consts.js.map +1 -0
  241. package/internal/themes/consts/package.json +6 -0
  242. package/internal/themes/consts.d.ts +7 -0
  243. package/lib/featureFlagsContext/FEATUREFLAGSCONTEXT.md +64 -0
  244. package/lib/locale/LOCALECONTEXT.md +222 -0
  245. package/lib/theming/ThemeContext.md +265 -0
  246. package/package.json +6 -1
@@ -0,0 +1,574 @@
1
+ ### Комбобокс с валидацией
2
+
3
+ ```jsx harmony
4
+ import { Tooltip } from '@skbkontur/react-ui';
5
+
6
+ const delay = time => args => new Promise(resolve => setTimeout(resolve, time, args));
7
+
8
+ let maybeReject = x => (Math.random() * 3 < 1 ? Promise.reject() : Promise.resolve(x));
9
+
10
+ let getItems = q =>
11
+ Promise.resolve(
12
+ [
13
+ { value: 1, label: 'First' },
14
+ { value: 2, label: 'Second' },
15
+ { value: 3, label: 'Third' },
16
+ { value: 4, label: 'Fourth' },
17
+ { value: 5, label: 'Fifth' },
18
+ { value: 6, label: 'Sixth' },
19
+ ].filter(x => x.label.toLowerCase().includes(q.toLowerCase()) || x.value.toString(10) === q),
20
+ )
21
+ .then(delay(500))
22
+ .then(maybeReject);
23
+
24
+ const [selected, setSelected] = React.useState({ value: 3, label: 'Third' });
25
+ const [error, setError] = React.useState(false);
26
+
27
+ let handleValueChange = value => {
28
+ setSelected(value);
29
+ setError(false);
30
+ };
31
+
32
+ let handleUnexpectedInput = () => {
33
+ setSelected(null);
34
+ setError(true);
35
+ };
36
+
37
+ let handleFocus = () => setError(false);
38
+
39
+ <Tooltip closeButton={false} render={() => 'Item must be selected!'} trigger={error ? 'opened' : 'closed'}>
40
+ <ComboBox
41
+ error={error}
42
+ getItems={getItems}
43
+ onValueChange={handleValueChange}
44
+ onFocus={handleFocus}
45
+ onUnexpectedInput={handleUnexpectedInput}
46
+ placeholder="Enter number"
47
+ value={selected}
48
+ />
49
+ </Tooltip>;
50
+ ```
51
+
52
+ ### Очистка комбобокса
53
+ Очистить значение в `ComboBox`'е можно с помощью пустой строки, `null` или `undefined`
54
+ ```jsx harmony
55
+ import { Group, ComboBox, Button } from '@skbkontur/react-ui';
56
+
57
+ const [value, setValue] = React.useState({ value: 2, label: 'Second' });
58
+
59
+ const getItems = q => {
60
+ return Promise.resolve(
61
+ [
62
+ { value: 1, label: 'First' },
63
+ { value: 2, label: 'Second' },
64
+ { value: 3, label: 'Third' },
65
+ { value: 4, label: 'Fourth' },
66
+ { value: 5, label: 'Fifth' },
67
+ { value: 6, label: 'Sixth' },
68
+ ].filter(x => x.label.toLowerCase().includes(q.toLowerCase()) || x.value.toString(10) === q),
69
+ )
70
+ };
71
+
72
+ <Group>
73
+ <ComboBox
74
+ getItems={getItems}
75
+ onValueChange={setValue}
76
+ placeholder="Введите число"
77
+ value={value}
78
+ />
79
+ <Button onClick={() => setValue(null)}>Null</Button>
80
+ <Button onClick={() => setValue(undefined)}>Undefined</Button>
81
+ <Button onClick={() => setValue('')}>Пустая строка</Button>
82
+ </Group>
83
+ ```
84
+
85
+ ### ComboBox with popular values, complex menu items and total count message
86
+
87
+ ```jsx harmony
88
+ import { getCities } from '@skbkontur/react-ui/components/ComboBox/__mocks__/getCities';
89
+ import { Gapped, MenuSeparator } from '@skbkontur/react-ui';
90
+ import {MenuFooter} from "@skbkontur/react-ui/components/MenuFooter";
91
+
92
+ let popularItems = [
93
+ { Id: 956, City: 'Махачкала' },
94
+ { Id: 4974, City: 'Верхняя-Пышма' },
95
+ { Id: 4980, City: 'Екатеринбург' },
96
+ ];
97
+
98
+ const [value, setValue] = React.useState(null);
99
+
100
+ let mapCity = ({ Id, City }) => ({
101
+ value: Id,
102
+ label: City,
103
+ });
104
+
105
+ let hasSelectedItem = itemsSets => itemsSets.some(items => items.find(item => value.value === item.Id));
106
+
107
+ let shouldInsertSelectedItem = (query, items) => value && !query && !hasSelectedItem([items, popularItems]);
108
+
109
+ let getPopularItems = query => (query ? [] : popularItems.map(mapCity));
110
+ let renderSeparator = query => (query ? [] : <MenuSeparator />);
111
+ let getSelectedItem = (query, items) => (!shouldInsertSelectedItem(query, items) ? [] : value);
112
+
113
+ let prepareItems = (query, items) =>
114
+ (!shouldInsertSelectedItem(query, items) ? items : items.slice(0, -1)).map(mapCity);
115
+
116
+ let renderTotalCount = (foundCount, totalCount) =>
117
+ foundCount < totalCount ? (
118
+ <MenuFooter>
119
+ Показано {foundCount} из {totalCount} найденных городов.
120
+ </MenuFooter>
121
+ ) : (
122
+ []
123
+ );
124
+
125
+ let getItems = query =>
126
+ getCities(query).then(({ foundItems, totalCount }) =>
127
+ [].concat(
128
+ getPopularItems(query),
129
+ renderSeparator(query),
130
+ getSelectedItem(query, foundItems),
131
+ prepareItems(query, foundItems),
132
+ renderTotalCount(foundItems.length, totalCount),
133
+ ),
134
+ );
135
+
136
+ let renderItem = item => (
137
+ <Gapped>
138
+ <div style={{ width: 40 }}>{item.value}</div>
139
+ <div style={{ width: 210, whiteSpace: 'normal' }}>{item.label}</div>
140
+ </Gapped>
141
+ );
142
+
143
+ <ComboBox
144
+ onValueChange={setValue}
145
+ getItems={getItems}
146
+ placeholder="Начните вводить название"
147
+ value={value}
148
+ renderItem={renderItem}
149
+ />;
150
+ ```
151
+
152
+ ### Переопределение `renderValue`, `renderItem` и `itemWrapper`
153
+
154
+ ```jsx harmony
155
+ import { CheckAIcon16Regular } from '@skbkontur/icons/icons/CheckAIcon/CheckAIcon16Regular';
156
+ import { Tooltip } from '@skbkontur/react-ui';
157
+
158
+ const delay = time => args => new Promise(resolve => setTimeout(resolve, time, args));
159
+
160
+ const getItems = q =>
161
+ Promise.resolve(
162
+ [
163
+ { approved: true, value: 1, label: 'Леонид Долецкий', email: 'first@skbkontur.ru' },
164
+ { approved: true, value: 2, label: 'Владислав Нашкодивший', email: 'second@skbkontur.ru' },
165
+ { approved: false, value: 3, label: 'Розенкранц Харитонов', email: 'third@skbkontur.ru' },
166
+ { approved: false, value: 4, label: 'Надежда Дубова', email: 'fourth@skbkontur.ru' },
167
+ { approved: true, value: 5, label: 'Владислав Сташкеевич', email: 'fifth@skbkontur.ru' },
168
+ { approved: true, value: 6, label: 'Василиса Александровна Поволоцкая', email: 'sixth@skbkontur.ru' },
169
+ ].filter(x => x.label.toLowerCase().includes(q.toLowerCase()) || x.value.toString(10) === q),
170
+ ).then(delay(500));
171
+
172
+ const [selected, setSelected] = React.useState({
173
+ approved: false,
174
+ value: 3,
175
+ label: 'Розенкранц Харитонов',
176
+ email: 'third@skbkontur.ru',
177
+ });
178
+ const [error, setError] = React.useState(false);
179
+
180
+ const handleValueChange = value => {
181
+ setSelected(value);
182
+ setError(false);
183
+ };
184
+
185
+ const handleUnexpectedInput = () => {
186
+ setSelected(null);
187
+ setError(true);
188
+ };
189
+
190
+ const handleFocus = () => setError(false);
191
+
192
+ const customRenderItem = item => (
193
+ <div
194
+ style={{
195
+ display: 'flex',
196
+ }}
197
+ >
198
+ <div
199
+ style={{
200
+ width: '55%',
201
+ display: 'flex',
202
+ }}
203
+ >
204
+ <span
205
+ style={{
206
+ minWidth: '20px',
207
+ }}
208
+ >
209
+ {item.approved ? <CheckAIcon16Regular size={14} /> : null}
210
+ </span>
211
+ <span
212
+ style={{
213
+ flexGrow: '1',
214
+ }}
215
+ >
216
+ {item.label}
217
+ </span>
218
+ </div>
219
+ <div
220
+ style={{
221
+ opacity: '0.6',
222
+ paddingLeft: '10px',
223
+ boxSizing: 'border-box',
224
+ }}
225
+ >
226
+ {item.email}
227
+ </div>
228
+ </div>
229
+ );
230
+
231
+ const customItemWrapper = item => {
232
+ if (item.value === 3) {
233
+ return (props) => <div {...props} />;
234
+ }
235
+
236
+ return (props) => <button {...props} />
237
+ }
238
+
239
+ const customRenderValue = item => (
240
+ <div
241
+ style={{
242
+ display: 'flex',
243
+ }}
244
+ >
245
+ <div
246
+ style={{
247
+ width: '55%',
248
+ overflow: 'hidden',
249
+ textOverflow: 'ellipsis'
250
+ }}
251
+ >
252
+ {item.label}
253
+ </div>
254
+ <div
255
+ style={{
256
+ opacity: '0.6',
257
+ paddingLeft: '10px',
258
+ boxSizing: 'border-box',
259
+ }}
260
+ >
261
+ {item.email}
262
+ </div>
263
+ </div>
264
+ );
265
+
266
+ <Tooltip closeButton={false} render={() => 'Item must be selected!'} trigger={error ? 'opened' : 'closed'}>
267
+ <ComboBox
268
+ error={error}
269
+ getItems={getItems}
270
+ onValueChange={handleValueChange}
271
+ onFocus={handleFocus}
272
+ onUnexpectedInput={handleUnexpectedInput}
273
+ placeholder="Enter number"
274
+ value={selected}
275
+ renderItem={customRenderItem}
276
+ itemWrapper={customItemWrapper}
277
+ renderValue={customRenderValue}
278
+ width="400px"
279
+ />
280
+ </Tooltip>;
281
+ ```
282
+
283
+ ### Подсветка результата поиска
284
+
285
+ ```jsx harmony
286
+ import { Tooltip } from '@skbkontur/react-ui';
287
+
288
+ const delay = time => args => new Promise(resolve => setTimeout(resolve, time, args));
289
+
290
+ const getItems = query =>
291
+ Promise.resolve(
292
+ [
293
+ { value: 1, label: 'First' },
294
+ { value: 2, label: 'Second' },
295
+ { value: 3, label: 'Third' },
296
+ { value: 4, label: 'Fourth' },
297
+ { value: 5, label: 'Fifth' },
298
+ { value: 6, label: 'Sixth' },
299
+ ]
300
+ .filter(x => x.label.toLowerCase().includes(query.toLowerCase()) || x.value.toString(10) === query)
301
+ .map(({ label, ...rest }) => {
302
+ const start = label.toLowerCase().indexOf(query.toLowerCase());
303
+ const end = start + query.length;
304
+
305
+ return {
306
+ ...rest,
307
+ label,
308
+ highlightedLabel:
309
+ start >= 0 ? (
310
+ <span>
311
+ {label.substring(0, start)}
312
+ <strong
313
+ style={{
314
+ fontSize: '1.1em',
315
+ }}
316
+ >
317
+ {label.substring(start, end)}
318
+ </strong>
319
+ {label.substring(end)}
320
+ </span>
321
+ ) : null,
322
+ };
323
+ }),
324
+ ).then(delay(500));
325
+
326
+ const [selected, setSelected] = React.useState({ value: 3, label: 'Third' });
327
+ const [error, setError] = React.useState(false);
328
+
329
+ let handleValueChange = value => {
330
+ setSelected(value);
331
+ setError(false);
332
+ };
333
+
334
+ let handleUnexpectedInput = () => {
335
+ setSelected(null);
336
+ setError(true);
337
+ };
338
+
339
+ let handleFocus = () => setError(false);
340
+
341
+ const renderItem = item => {
342
+ if (item.highlightedLabel) {
343
+ return item.highlightedLabel;
344
+ }
345
+
346
+ return item.label;
347
+ };
348
+
349
+ <Tooltip closeButton={false} render={() => 'Item must be selected!'} trigger={error ? 'opened' : 'closed'}>
350
+ <ComboBox
351
+ error={error}
352
+ getItems={getItems}
353
+ onValueChange={handleValueChange}
354
+ onFocus={handleFocus}
355
+ onUnexpectedInput={handleUnexpectedInput}
356
+ placeholder="Enter number"
357
+ value={selected}
358
+ renderItem={renderItem}
359
+ />
360
+ </Tooltip>;
361
+ ```
362
+
363
+ ### Добавление элементов в меню
364
+
365
+ ```jsx harmony
366
+ import { MenuItem } from '@skbkontur/react-ui';
367
+
368
+ const delay = time => args => new Promise(resolve => setTimeout(resolve, time, args));
369
+
370
+ class ComboboxExample extends React.Component {
371
+ constructor(props) {
372
+ super(props);
373
+
374
+ this.state = {
375
+ items: [
376
+ { value: 1, label: 'First' },
377
+ { value: 2, label: 'Second' },
378
+ { value: 3, label: 'Third' },
379
+ { value: 4, label: 'Fourth' },
380
+ { value: 5, label: 'Fifth' },
381
+ { value: 6, label: 'Sixth' },
382
+ ],
383
+ query: '',
384
+ selected: { value: 3, label: 'Third' },
385
+ error: false,
386
+ shouldRenderAddButton: false,
387
+ };
388
+
389
+ this.comboBoxElement = null;
390
+
391
+ this.getItems = this.getItems.bind(this);
392
+ this.handleValueChange = this.handleValueChange.bind(this);
393
+ this.handleFocus = this.handleFocus.bind(this);
394
+ this.handleInputValueChange = this.handleInputValueChange.bind(this);
395
+ this.renderAddButton = this.renderAddButton.bind(this);
396
+ this.refComboBox = this.refComboBox.bind(this);
397
+ this.addItem = this.addItem.bind(this);
398
+ }
399
+
400
+ render() {
401
+ return (
402
+ <ComboBox
403
+ error={this.state.error}
404
+ getItems={this.getItems}
405
+ onValueChange={this.handleValueChange}
406
+ onFocus={this.handleFocus}
407
+ placeholder="Enter number"
408
+ value={this.state.selected}
409
+ onInputValueChange={this.handleInputValueChange}
410
+ renderAddButton={this.renderAddButton}
411
+ ref={this.refComboBox}
412
+ />
413
+ );
414
+ }
415
+
416
+ getItems(q) {
417
+ return Promise.resolve(
418
+ this.state.items.filter(x => x.label.toLowerCase().includes(q.toLowerCase()) || x.value.toString(10) === q),
419
+ ).then(delay(500));
420
+ }
421
+
422
+ handleInputValueChange(query) {
423
+ const isItemExists = this.state.items.find(x => x.label.toLowerCase() == query.toLowerCase());
424
+ this.setState({ query, shouldRenderAddButton: !isItemExists });
425
+ }
426
+
427
+ handleValueChange(value) {
428
+ this.setState({ selected: value, error: false, shouldRenderAddButton: false });
429
+ }
430
+
431
+ handleFocus() {
432
+ this.setState({ error: false });
433
+ }
434
+
435
+ renderAddButton() {
436
+ if (!this.state.shouldRenderAddButton) {
437
+ return null;
438
+ }
439
+ return (
440
+ <MenuItem link onClick={this.addItem}>
441
+ + Добавить "{this.state.query}"
442
+ </MenuItem>
443
+ );
444
+ }
445
+
446
+ refComboBox(element) {
447
+ this.comboBoxElement = element;
448
+ }
449
+
450
+ addItem() {
451
+ this.setState(currentState => {
452
+ const newItem = {
453
+ value: Math.max(...currentState.items.map(({ value }) => value)) + 1,
454
+ label: currentState.query,
455
+ };
456
+
457
+ return {
458
+ items: [...currentState.items, newItem],
459
+ selected: newItem,
460
+ error: false,
461
+ shouldRenderAddButton: false,
462
+ };
463
+ });
464
+ }
465
+ }
466
+
467
+ <ComboboxExample />;
468
+ ```
469
+
470
+ ### Сброс контрола
471
+ Если нужно сбросить контрол без изменения `value`, то можно использовать метод `reset`.
472
+
473
+ ```jsx harmony
474
+ import { Button } from '@skbkontur/react-ui';
475
+
476
+ const [selected, setSelected] = React.useState({ value: 1, label: "First" });
477
+ const ref = React.useRef(null);
478
+
479
+ const handleReset = () => {
480
+ if (ref.current) {
481
+ ref.current.reset();
482
+ }
483
+ };
484
+
485
+ const getItems = (q) =>
486
+ Promise.resolve(
487
+ [
488
+ { value: 1, label: "First" },
489
+ { value: 2, label: "Second" },
490
+ { value: 3, label: "Third" }
491
+ ].filter(
492
+ (x) =>
493
+ x.label.toLowerCase().includes(q.toLowerCase()) ||
494
+ x.value.toString(10) === q
495
+ )
496
+ );
497
+
498
+ <div>
499
+ <ComboBox
500
+ ref={ref}
501
+ getItems={getItems}
502
+ onValueChange={setSelected}
503
+ placeholder="Enter number"
504
+ value={selected}
505
+ />
506
+ <Button onClick={handleReset}>Reset</Button>
507
+ </div>
508
+
509
+ ```
510
+
511
+ ### Локали по умолчанию
512
+
513
+ ```typescript static
514
+ interface ComboBoxLocale {
515
+ notFound?: string;
516
+ errorNetworkButton?: string;
517
+ errorNetworkMessage?: string;
518
+ }
519
+
520
+ const ru_RU = {
521
+ notFound: 'Не найдено',
522
+ errorNetworkButton: 'Обновить',
523
+ errorNetworkMessage: 'Что-то пошло не так. Проверьте соединение с интернетом и попробуйте еще раз',
524
+ };
525
+
526
+ const en_GB = {
527
+ notFound: 'Not found',
528
+ errorNetworkButton: 'Refresh',
529
+ errorNetworkMessage: 'Something went wrong. Check your internet connection and try again',
530
+ };
531
+ ```
532
+
533
+ ### Размер
534
+ ```jsx harmony
535
+ import { Gapped } from '@skbkontur/react-ui';
536
+
537
+ const getItems = q => {
538
+ return Promise.resolve(
539
+ [
540
+ { value: 1, label: 'Маленький' },
541
+ { value: 2, label: 'Средний' },
542
+ { value: 3, label: 'Большой' },
543
+ ].filter(x => x.label.toLowerCase().includes(q.toLowerCase()) || x.value.toString(10) === q),
544
+ )
545
+ };
546
+
547
+ const [valueSmall, setValueSmall] = React.useState('Маленький');
548
+ const [valueMedium, setValueMedium] = React.useState('Средний');
549
+ const [valueLarge, setValueLarge] = React.useState('Большой');
550
+
551
+ <Gapped vertical>
552
+ <ComboBox
553
+ getItems={getItems}
554
+ onValueChange={setValueSmall}
555
+ placeholder="Введите число"
556
+ value={valueSmall}
557
+ size={'small'}
558
+ />
559
+ <ComboBox
560
+ getItems={getItems}
561
+ onValueChange={setValueMedium}
562
+ placeholder="Введите число"
563
+ value={valueMedium}
564
+ size={'medium'}
565
+ />
566
+ <ComboBox
567
+ getItems={getItems}
568
+ onValueChange={setValueLarge}
569
+ placeholder="Введите число"
570
+ value={valueLarge}
571
+ size={'large'}
572
+ />
573
+ </Gapped>
574
+ ```
@@ -0,0 +1,39 @@
1
+ ### Базовый пример
2
+ ```jsx harmony
3
+ const [value, setValue] = React.useState();
4
+
5
+ <CurrencyInput value={value} fractionDigits={3} onValueChange={setValue} />
6
+ ```
7
+
8
+ ### Очистка значения
9
+ Очистить значение в `CurrencyInput` можно с помощью `null` или `undefined`
10
+ ```jsx harmony
11
+ import { Button, Group } from '@skbkontur/react-ui';
12
+
13
+ const [value, setValue] = React.useState();
14
+
15
+ <Group>
16
+ <CurrencyInput value={value} onValueChange={setValue} />
17
+ <Button onClick={() => setValue(null)}>Null</Button>
18
+ <Button onClick={() => setValue(undefined)}>Undefined</Button>
19
+ </Group>
20
+ ```
21
+
22
+ ### fractionDigits={15}
23
+
24
+ ```jsx harmony
25
+ const [value, setValue] = React.useState();
26
+
27
+ <CurrencyInput value={value} fractionDigits={15} onValueChange={setValue} />
28
+ ```
29
+
30
+ ---
31
+
32
+ ### <a name="/CurrencyInput?id=why15" href="#/CurrencyInput?id=why15">Почему 15?</a>
33
+
34
+ Максимальное безопасное целочисленное значение - `9007199254740991` (16 цифр).
35
+ Убрав один разряд, мы получим "новое" максимальное безопасное значение - **`999999999999999` (15 цифр)**.
36
+
37
+ При этом десятичный резделитель может находиться в любом месте. Если целая часть равна `0`, то она не учитывается.
38
+
39
+ _Детали можно почитать здесь - <a href="https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER">MDN web docs</a>_
@@ -47,8 +47,8 @@ var CurrencyLabel = exports.CurrencyLabel = (0, _forwardRefAndName.forwardRefAnd
47
47
  {var id = _ref.id,value = _ref.value,_ref$fractionDigits = _ref.fractionDigits,fractionDigits = _ref$fractionDigits === void 0 ? FRACTION_DIGITS_DEFAULT : _ref$fractionDigits,currencySymbol = _ref.currencySymbol,_ref$hideTrailingZero = _ref.hideTrailingZeros,hideTrailingZeros = _ref$hideTrailingZero === void 0 ? false : _ref$hideTrailingZero,rest = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
48
48
  _react.default.useEffect(function () {
49
49
  (0, _warning.default)(
50
- fractionDigits <= _constants.MAX_SAFE_DIGITS, "[CurrencyLabel]: Prop 'fractionDigits' exceeds " +
51
- _constants.MAX_SAFE_DIGITS + ".\nSee CurrencyInput documentation"
50
+ fractionDigits <= _constants.MAX_SAFE_DIGITS,
51
+ "[CurrencyLabel]: Prop 'fractionDigits' exceeds " + _constants.MAX_SAFE_DIGITS + "." + "\nSee CurrencyInput documentation"
52
52
  );
53
53
 
54
54
  var _ref2 = _CurrencyHelper.CurrencyHelper.destructString(String(value)) || { fraction: '' },fraction = _ref2.fraction;
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_warning","_constants","_CurrencyHelper","_CommonWrapper","_forwardRefAndName","_excluded","FRACTION_DIGITS_DEFAULT","CurrencyLabelDataTids","exports","root","CurrencyLabel","forwardRefAndName","_ref","ref","id","value","_ref$fractionDigits","fractionDigits","currencySymbol","_ref$hideTrailingZero","hideTrailingZeros","rest","_objectWithoutPropertiesLoose2","default","React","useEffect","warning","MAX_SAFE_DIGITS","_ref2","CurrencyHelper","destructString","String","fraction","length","Number","isInteger","createElement","CommonWrapper","format","fromCharCode"],"sources":["CurrencyLabel.tsx"],"sourcesContent":["import type { HTMLAttributes } from 'react';\nimport React from 'react';\nimport warning from 'warning';\n\nimport { MAX_SAFE_DIGITS } from '../CurrencyInput/constants';\nimport { CurrencyHelper } from '../CurrencyInput/CurrencyHelper';\nimport type { CommonProps } from '../../internal/CommonWrapper';\nimport { CommonWrapper } from '../../internal/CommonWrapper';\nimport { forwardRefAndName } from '../../lib/forwardRefAndName';\n\nexport interface CurrencyLabelProps extends CommonProps, Pick<HTMLAttributes<HTMLElement>, 'id'> {\n /** Устанавливает минимальное количество отображаемых знаков после запятой.\n * @default 2 */\n fractionDigits?: number;\n\n /** Устанавливает значение. */\n value: number;\n\n /** Задает символ валюты. */\n currencySymbol?: React.ReactNode;\n\n /** Убирает лишние нули после запятой. */\n hideTrailingZeros?: boolean;\n}\n\nconst FRACTION_DIGITS_DEFAULT = 2;\n\nexport const CurrencyLabelDataTids = {\n root: 'CurrencyLabel__root',\n} as const;\n\n/**\n * `CurrencyLabel` — подпись для денежных сумм (и других числовых значений).\n */\nconst CurrencyLabel = forwardRefAndName(\n 'CurrencyLabel',\n function CurrencyLabel(\n {\n id,\n value,\n fractionDigits = FRACTION_DIGITS_DEFAULT,\n currencySymbol,\n hideTrailingZeros = false,\n ...rest\n }: CurrencyLabelProps,\n ref: React.Ref<HTMLDivElement>,\n ) {\n React.useEffect(() => {\n warning(\n fractionDigits <= MAX_SAFE_DIGITS,\n `[CurrencyLabel]: Prop 'fractionDigits' exceeds ${MAX_SAFE_DIGITS}.\\nSee CurrencyInput documentation`,\n );\n\n const { fraction } = CurrencyHelper.destructString(String(value)) || { fraction: '' };\n warning(\n fraction.length <= fractionDigits,\n `[CurrencyLabel]: Prop 'fractionDigits' less than fractional part of the 'value' property,` +\n `'value' will not be cutted`,\n );\n\n warning(\n Number.isInteger(fractionDigits),\n `[CurrencyLabel]: Prop 'fractionDigits' is not integer, fraction part of these property will not be used`,\n );\n }, [fractionDigits, value]);\n\n return (\n <CommonWrapper {...rest}>\n <span id={id} data-tid={CurrencyLabelDataTids.root} ref={ref}>\n {CurrencyHelper.format(value, { fractionDigits, hideTrailingZeros })}\n {currencySymbol && String.fromCharCode(0xa0) /* &nbsp; */}\n {currencySymbol}\n </span>\n </CommonWrapper>\n );\n },\n);\n\nexport { CurrencyLabel };\n"],"mappings":";AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;;AAEA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;;AAEA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,kBAAA,GAAAL,OAAA,gCAAgE,IAAAM,SAAA;;;;;;;;;;;;;;;;;AAiBhE,IAAMC,uBAAuB,GAAG,CAAC;;AAE1B,IAAMC,qBAAqB,GAAAC,OAAA,CAAAD,qBAAA,GAAG;EACnCE,IAAI,EAAE;AACR,CAAU;;AAEV;AACA;AACA;AACA,IAAMC,aAAa,GAAAF,OAAA,CAAAE,aAAA,GAAG,IAAAC,oCAAiB;EACrC,eAAe;EACf,SAASD,aAAaA,CAAAE,IAAA;;;;;;;;;EASpBC,GAA8B;EAC9B,KAREC,EAAE,GAAAF,IAAA,CAAFE,EAAE,CACFC,KAAK,GAAAH,IAAA,CAALG,KAAK,CAAAC,mBAAA,GAAAJ,IAAA,CACLK,cAAc,CAAdA,cAAc,GAAAD,mBAAA,cAAGV,uBAAuB,GAAAU,mBAAA,CACxCE,cAAc,GAAAN,IAAA,CAAdM,cAAc,CAAAC,qBAAA,GAAAP,IAAA,CACdQ,iBAAiB,CAAjBA,iBAAiB,GAAAD,qBAAA,cAAG,KAAK,GAAAA,qBAAA,CACtBE,IAAI,OAAAC,8BAAA,CAAAC,OAAA,EAAAX,IAAA,EAAAP,SAAA;IAITmB,cAAK,CAACC,SAAS,CAAC,YAAM;MACpB,IAAAC,gBAAO;QACLT,cAAc,IAAIU,0BAAe;QACiBA,0BAAe;MACnE,CAAC;;MAED,IAAAC,KAAA,GAAqBC,8BAAc,CAACC,cAAc,CAACC,MAAM,CAAChB,KAAK,CAAC,CAAC,IAAI,EAAEiB,QAAQ,EAAE,EAAE,CAAC,CAAC,CAA7EA,QAAQ,GAAAJ,KAAA,CAARI,QAAQ;MAChB,IAAAN,gBAAO;QACLM,QAAQ,CAACC,MAAM,IAAIhB,cAAc;QACjC;;MAEF,CAAC;;MAED,IAAAS,gBAAO;QACLQ,MAAM,CAACC,SAAS,CAAClB,cAAc,CAAC;;MAElC,CAAC;IACH,CAAC,EAAE,CAACA,cAAc,EAAEF,KAAK,CAAC,CAAC;;IAE3B;MACElB,MAAA,CAAA0B,OAAA,CAAAa,aAAA,CAACjC,cAAA,CAAAkC,aAAa,EAAKhB,IAAI;MACrBxB,MAAA,CAAA0B,OAAA,CAAAa,aAAA,WAAMtB,EAAE,EAAEA,EAAG,EAAC,YAAUP,qBAAqB,CAACE,IAAK,EAACI,GAAG,EAAEA,GAAI;MAC1DgB,8BAAc,CAACS,MAAM,CAACvB,KAAK,EAAE,EAAEE,cAAc,EAAdA,cAAc,EAAEG,iBAAiB,EAAjBA,iBAAiB,CAAC,CAAC,CAAC;MACnEF,cAAc,IAAIa,MAAM,CAACQ,YAAY,CAAC,IAAI,CAAC,CAAC;MAC5CrB;MACG;MACO,CAAC;;EAEpB;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_warning","_constants","_CurrencyHelper","_CommonWrapper","_forwardRefAndName","_excluded","FRACTION_DIGITS_DEFAULT","CurrencyLabelDataTids","exports","root","CurrencyLabel","forwardRefAndName","_ref","ref","id","value","_ref$fractionDigits","fractionDigits","currencySymbol","_ref$hideTrailingZero","hideTrailingZeros","rest","_objectWithoutPropertiesLoose2","default","React","useEffect","warning","MAX_SAFE_DIGITS","_ref2","CurrencyHelper","destructString","String","fraction","length","Number","isInteger","createElement","CommonWrapper","format","fromCharCode"],"sources":["CurrencyLabel.tsx"],"sourcesContent":["import type { HTMLAttributes } from 'react';\nimport React from 'react';\nimport warning from 'warning';\n\nimport { MAX_SAFE_DIGITS } from '../CurrencyInput/constants';\nimport { CurrencyHelper } from '../CurrencyInput/CurrencyHelper';\nimport type { CommonProps } from '../../internal/CommonWrapper';\nimport { CommonWrapper } from '../../internal/CommonWrapper';\nimport { forwardRefAndName } from '../../lib/forwardRefAndName';\n\nexport interface CurrencyLabelProps extends CommonProps, Pick<HTMLAttributes<HTMLElement>, 'id'> {\n /** Устанавливает минимальное количество отображаемых знаков после запятой.\n * @default 2 */\n fractionDigits?: number;\n\n /** Устанавливает значение. */\n value: number;\n\n /** Задает символ валюты. */\n currencySymbol?: React.ReactNode;\n\n /** Убирает лишние нули после запятой. */\n hideTrailingZeros?: boolean;\n}\n\nconst FRACTION_DIGITS_DEFAULT = 2;\n\nexport const CurrencyLabelDataTids = {\n root: 'CurrencyLabel__root',\n} as const;\n\n/**\n * `CurrencyLabel` — подпись для денежных сумм (и других числовых значений).\n */\nconst CurrencyLabel = forwardRefAndName(\n 'CurrencyLabel',\n function CurrencyLabel(\n {\n id,\n value,\n fractionDigits = FRACTION_DIGITS_DEFAULT,\n currencySymbol,\n hideTrailingZeros = false,\n ...rest\n }: CurrencyLabelProps,\n ref: React.Ref<HTMLDivElement>,\n ) {\n React.useEffect(() => {\n warning(\n fractionDigits <= MAX_SAFE_DIGITS,\n `[CurrencyLabel]: Prop 'fractionDigits' exceeds ${MAX_SAFE_DIGITS}.` + `\\nSee CurrencyInput documentation`,\n );\n\n const { fraction } = CurrencyHelper.destructString(String(value)) || { fraction: '' };\n warning(\n fraction.length <= fractionDigits,\n `[CurrencyLabel]: Prop 'fractionDigits' less than fractional part of the 'value' property,` +\n `'value' will not be cutted`,\n );\n\n warning(\n Number.isInteger(fractionDigits),\n `[CurrencyLabel]: Prop 'fractionDigits' is not integer, fraction part of these property will not be used`,\n );\n }, [fractionDigits, value]);\n\n return (\n <CommonWrapper {...rest}>\n <span id={id} data-tid={CurrencyLabelDataTids.root} ref={ref}>\n {CurrencyHelper.format(value, { fractionDigits, hideTrailingZeros })}\n {currencySymbol && String.fromCharCode(0xa0) /* &nbsp; */}\n {currencySymbol}\n </span>\n </CommonWrapper>\n );\n },\n);\n\nexport { CurrencyLabel };\n"],"mappings":";AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;;AAEA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;;AAEA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,kBAAA,GAAAL,OAAA,gCAAgE,IAAAM,SAAA;;;;;;;;;;;;;;;;;AAiBhE,IAAMC,uBAAuB,GAAG,CAAC;;AAE1B,IAAMC,qBAAqB,GAAAC,OAAA,CAAAD,qBAAA,GAAG;EACnCE,IAAI,EAAE;AACR,CAAU;;AAEV;AACA;AACA;AACA,IAAMC,aAAa,GAAAF,OAAA,CAAAE,aAAA,GAAG,IAAAC,oCAAiB;EACrC,eAAe;EACf,SAASD,aAAaA,CAAAE,IAAA;;;;;;;;;EASpBC,GAA8B;EAC9B,KAREC,EAAE,GAAAF,IAAA,CAAFE,EAAE,CACFC,KAAK,GAAAH,IAAA,CAALG,KAAK,CAAAC,mBAAA,GAAAJ,IAAA,CACLK,cAAc,CAAdA,cAAc,GAAAD,mBAAA,cAAGV,uBAAuB,GAAAU,mBAAA,CACxCE,cAAc,GAAAN,IAAA,CAAdM,cAAc,CAAAC,qBAAA,GAAAP,IAAA,CACdQ,iBAAiB,CAAjBA,iBAAiB,GAAAD,qBAAA,cAAG,KAAK,GAAAA,qBAAA,CACtBE,IAAI,OAAAC,8BAAA,CAAAC,OAAA,EAAAX,IAAA,EAAAP,SAAA;IAITmB,cAAK,CAACC,SAAS,CAAC,YAAM;MACpB,IAAAC,gBAAO;QACLT,cAAc,IAAIU,0BAAe;QACjC,oDAAkDA,0BAAe;MACnE,CAAC;;MAED,IAAAC,KAAA,GAAqBC,8BAAc,CAACC,cAAc,CAACC,MAAM,CAAChB,KAAK,CAAC,CAAC,IAAI,EAAEiB,QAAQ,EAAE,EAAE,CAAC,CAAC,CAA7EA,QAAQ,GAAAJ,KAAA,CAARI,QAAQ;MAChB,IAAAN,gBAAO;QACLM,QAAQ,CAACC,MAAM,IAAIhB,cAAc;QACjC;;MAEF,CAAC;;MAED,IAAAS,gBAAO;QACLQ,MAAM,CAACC,SAAS,CAAClB,cAAc,CAAC;;MAElC,CAAC;IACH,CAAC,EAAE,CAACA,cAAc,EAAEF,KAAK,CAAC,CAAC;;IAE3B;MACElB,MAAA,CAAA0B,OAAA,CAAAa,aAAA,CAACjC,cAAA,CAAAkC,aAAa,EAAKhB,IAAI;MACrBxB,MAAA,CAAA0B,OAAA,CAAAa,aAAA,WAAMtB,EAAE,EAAEA,EAAG,EAAC,YAAUP,qBAAqB,CAACE,IAAK,EAACI,GAAG,EAAEA,GAAI;MAC1DgB,8BAAc,CAACS,MAAM,CAACvB,KAAK,EAAE,EAAEE,cAAc,EAAdA,cAAc,EAAEG,iBAAiB,EAAjBA,iBAAiB,CAAC,CAAC,CAAC;MACnEF,cAAc,IAAIa,MAAM,CAACQ,YAAY,CAAC,IAAI,CAAC,CAAC;MAC5CrB;MACG;MACO,CAAC;;EAEpB;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,29 @@
1
+ ### To render rubles
2
+
3
+ ```jsx
4
+ <CurrencyLabel value={12356.1} currencySymbol={'₽'} />
5
+ ```
6
+
7
+ ### ...or dollars
8
+
9
+ ```jsx
10
+ <CurrencyLabel value={12356.1} currencySymbol={'$'} />
11
+ ```
12
+
13
+ ### ...or nothing
14
+
15
+ ```jsx
16
+ <CurrencyLabel value={12356.1} />
17
+ ```
18
+
19
+ ### Count of fraction digits can be changed
20
+
21
+ ```jsx
22
+ <CurrencyLabel value={3562001.1} fractionDigits={3} currencySymbol={'₽'} />
23
+ ```
24
+
25
+ ### Can hide trailing zeros
26
+
27
+ ```jsx
28
+ <CurrencyLabel value={356.167} fractionDigits={5} hideTrailingZeros />
29
+ ```