@chayns-components/core 5.0.0-beta.49 → 5.0.0-beta.492

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 (442) hide show
  1. package/README.md +3 -19
  2. package/lib/api/image/post.d.ts +14 -0
  3. package/lib/api/image/post.js +33 -0
  4. package/lib/api/image/post.js.map +1 -0
  5. package/lib/api/signature/delete.d.ts +1 -0
  6. package/lib/api/signature/delete.js +27 -0
  7. package/lib/api/signature/delete.js.map +1 -0
  8. package/lib/api/signature/get.d.ts +1 -0
  9. package/lib/api/signature/get.js +33 -0
  10. package/lib/api/signature/get.js.map +1 -0
  11. package/lib/api/signature/put.d.ts +1 -0
  12. package/lib/api/signature/put.js +31 -0
  13. package/lib/api/signature/put.js.map +1 -0
  14. package/lib/api/theme/get.d.ts +2 -0
  15. package/lib/api/theme/get.js +14 -0
  16. package/lib/api/theme/get.js.map +1 -0
  17. package/lib/api/video/post.d.ts +15 -0
  18. package/lib/api/video/post.js +30 -0
  19. package/lib/api/video/post.js.map +1 -0
  20. package/lib/components/accordion/Accordion.d.ts +21 -6
  21. package/lib/components/accordion/Accordion.js +78 -54
  22. package/lib/components/accordion/Accordion.js.map +1 -1
  23. package/lib/components/accordion/Accordion.styles.d.ts +11 -7
  24. package/lib/components/accordion/Accordion.styles.js +66 -53
  25. package/lib/components/accordion/Accordion.styles.js.map +1 -1
  26. package/lib/components/accordion/accordion-body/AccordionBody.d.ts +9 -1
  27. package/lib/components/accordion/accordion-body/AccordionBody.js +12 -20
  28. package/lib/components/accordion/accordion-body/AccordionBody.js.map +1 -1
  29. package/lib/components/accordion/accordion-body/AccordionBody.styles.d.ts +268 -3
  30. package/lib/components/accordion/accordion-body/AccordionBody.styles.js +6 -15
  31. package/lib/components/accordion/accordion-body/AccordionBody.styles.js.map +1 -1
  32. package/lib/components/accordion/accordion-content/AccordionContent.js +8 -16
  33. package/lib/components/accordion/accordion-content/AccordionContent.js.map +1 -1
  34. package/lib/components/accordion/accordion-content/AccordionContent.styles.d.ts +8 -6
  35. package/lib/components/accordion/accordion-content/AccordionContent.styles.js +7 -16
  36. package/lib/components/accordion/accordion-content/AccordionContent.styles.js.map +1 -1
  37. package/lib/components/accordion/accordion-group/AccordionGroup.d.ts +9 -2
  38. package/lib/components/accordion/accordion-group/AccordionGroup.js +15 -20
  39. package/lib/components/accordion/accordion-group/AccordionGroup.js.map +1 -1
  40. package/lib/components/accordion/accordion-head/AccordionHead.d.ts +2 -0
  41. package/lib/components/accordion/accordion-head/AccordionHead.js +45 -40
  42. package/lib/components/accordion/accordion-head/AccordionHead.js.map +1 -1
  43. package/lib/components/accordion/accordion-head/AccordionHead.styles.d.ts +2424 -15
  44. package/lib/components/accordion/accordion-head/AccordionHead.styles.js +70 -61
  45. package/lib/components/accordion/accordion-head/AccordionHead.styles.js.map +1 -1
  46. package/lib/components/accordion/accordion-intro/AccordionIntro.js +4 -12
  47. package/lib/components/accordion/accordion-intro/AccordionIntro.js.map +1 -1
  48. package/lib/components/accordion/accordion-intro/AccordionIntro.styles.d.ts +2 -1
  49. package/lib/components/accordion/accordion-intro/AccordionIntro.styles.js +2 -10
  50. package/lib/components/accordion/accordion-intro/AccordionIntro.styles.js.map +1 -1
  51. package/lib/components/accordion/accordion-item/AccordionItem.d.ts +9 -0
  52. package/lib/components/accordion/accordion-item/AccordionItem.js +20 -0
  53. package/lib/components/accordion/accordion-item/AccordionItem.js.map +1 -0
  54. package/lib/components/accordion/accordion-item/AccordionItem.styles.d.ts +7 -0
  55. package/lib/components/accordion/accordion-item/AccordionItem.styles.js +26 -0
  56. package/lib/components/accordion/accordion-item/AccordionItem.styles.js.map +1 -0
  57. package/lib/components/amount-control/AmountControl.d.ts +26 -0
  58. package/lib/components/amount-control/AmountControl.js +179 -0
  59. package/lib/components/amount-control/AmountControl.js.map +1 -0
  60. package/lib/components/amount-control/AmountControl.styles.d.ts +288 -0
  61. package/lib/components/amount-control/AmountControl.styles.js +50 -0
  62. package/lib/components/amount-control/AmountControl.styles.js.map +1 -0
  63. package/lib/components/badge/Badge.d.ts +5 -1
  64. package/lib/components/badge/Badge.js +12 -17
  65. package/lib/components/badge/Badge.js.map +1 -1
  66. package/lib/components/badge/Badge.styles.d.ts +9 -4
  67. package/lib/components/badge/Badge.styles.js +12 -14
  68. package/lib/components/badge/Badge.styles.js.map +1 -1
  69. package/lib/components/button/Button.d.ts +5 -1
  70. package/lib/components/button/Button.js +71 -20
  71. package/lib/components/button/Button.js.map +1 -1
  72. package/lib/components/button/Button.styles.d.ts +813 -6
  73. package/lib/components/button/Button.styles.js +44 -26
  74. package/lib/components/button/Button.styles.js.map +1 -1
  75. package/lib/components/checkbox/Checkbox.d.ts +10 -2
  76. package/lib/components/checkbox/Checkbox.js +19 -22
  77. package/lib/components/checkbox/Checkbox.js.map +1 -1
  78. package/lib/components/checkbox/Checkbox.styles.d.ts +12 -5
  79. package/lib/components/checkbox/Checkbox.styles.js +70 -63
  80. package/lib/components/checkbox/Checkbox.styles.js.map +1 -1
  81. package/lib/components/color-scheme-provider/ColorSchemeProvider.d.ts +6 -0
  82. package/lib/components/color-scheme-provider/ColorSchemeProvider.js +77 -40
  83. package/lib/components/color-scheme-provider/ColorSchemeProvider.js.map +1 -1
  84. package/lib/components/combobox/ComboBox.d.ts +44 -0
  85. package/lib/components/combobox/ComboBox.js +183 -0
  86. package/lib/components/combobox/ComboBox.js.map +1 -0
  87. package/lib/components/combobox/ComboBox.styles.d.ts +291 -0
  88. package/lib/components/combobox/ComboBox.styles.js +198 -0
  89. package/lib/components/combobox/ComboBox.styles.js.map +1 -0
  90. package/lib/components/combobox/combobox-item/ComboBoxItem.d.ts +13 -0
  91. package/lib/components/combobox/combobox-item/ComboBoxItem.js +33 -0
  92. package/lib/components/combobox/combobox-item/ComboBoxItem.js.map +1 -0
  93. package/lib/components/combobox/combobox-item/ComboBoxItem.styles.d.ts +12 -0
  94. package/lib/components/combobox/combobox-item/ComboBoxItem.styles.js +54 -0
  95. package/lib/components/combobox/combobox-item/ComboBoxItem.styles.js.map +1 -0
  96. package/lib/components/content-card/ContentCard.d.ts +13 -0
  97. package/lib/components/content-card/ContentCard.js +14 -0
  98. package/lib/components/content-card/ContentCard.js.map +1 -0
  99. package/lib/components/content-card/ContentCard.styles.d.ts +2 -0
  100. package/lib/components/content-card/ContentCard.styles.js +32 -0
  101. package/lib/components/content-card/ContentCard.styles.js.map +1 -0
  102. package/lib/components/context-menu/ContextMenu.d.ts +3 -3
  103. package/lib/components/context-menu/ContextMenu.js +43 -53
  104. package/lib/components/context-menu/ContextMenu.js.map +1 -1
  105. package/lib/components/context-menu/ContextMenu.styles.d.ts +2 -1
  106. package/lib/components/context-menu/ContextMenu.styles.js +2 -10
  107. package/lib/components/context-menu/ContextMenu.styles.js.map +1 -1
  108. package/lib/components/context-menu/context-menu-content/ContextMenuContent.d.ts +1 -1
  109. package/lib/components/context-menu/context-menu-content/ContextMenuContent.js +17 -23
  110. package/lib/components/context-menu/context-menu-content/ContextMenuContent.js.map +1 -1
  111. package/lib/components/context-menu/context-menu-content/ContextMenuContent.styles.d.ts +275 -10
  112. package/lib/components/context-menu/context-menu-content/ContextMenuContent.styles.js +25 -38
  113. package/lib/components/context-menu/context-menu-content/ContextMenuContent.styles.js.map +1 -1
  114. package/lib/components/file-input/FileInput.d.ts +29 -0
  115. package/lib/components/file-input/FileInput.js +112 -0
  116. package/lib/components/file-input/FileInput.js.map +1 -0
  117. package/lib/components/file-input/FileInput.styles.d.ts +277 -0
  118. package/lib/components/file-input/FileInput.styles.js +39 -0
  119. package/lib/components/file-input/FileInput.styles.js.map +1 -0
  120. package/lib/components/file-input/file-list/FileListItem.d.ts +9 -0
  121. package/lib/components/file-input/file-list/FileListItem.js +27 -0
  122. package/lib/components/file-input/file-list/FileListItem.js.map +1 -0
  123. package/lib/components/file-input/file-list/FileListItem.styles.d.ts +2 -0
  124. package/lib/components/file-input/file-list/FileListItem.styles.js +3 -0
  125. package/lib/components/file-input/file-list/FileListItem.styles.js.map +1 -0
  126. package/lib/components/filter-buttons/FilterButtons.d.ts +22 -0
  127. package/lib/components/filter-buttons/FilterButtons.js +79 -0
  128. package/lib/components/filter-buttons/FilterButtons.js.map +1 -0
  129. package/lib/components/filter-buttons/FilterButtons.styles.d.ts +2 -0
  130. package/lib/components/filter-buttons/FilterButtons.styles.js +7 -0
  131. package/lib/components/filter-buttons/FilterButtons.styles.js.map +1 -0
  132. package/lib/components/filter-buttons/filter-button/FilterButton.d.ts +14 -0
  133. package/lib/components/filter-buttons/filter-button/FilterButton.js +38 -0
  134. package/lib/components/filter-buttons/filter-button/FilterButton.js.map +1 -0
  135. package/lib/components/filter-buttons/filter-button/FilterButton.styles.d.ts +287 -0
  136. package/lib/components/filter-buttons/filter-button/FilterButton.styles.js +98 -0
  137. package/lib/components/filter-buttons/filter-button/FilterButton.styles.js.map +1 -0
  138. package/lib/components/grid-image/GridImage.js +20 -29
  139. package/lib/components/grid-image/GridImage.js.map +1 -1
  140. package/lib/components/grid-image/GridImage.styles.d.ts +15 -14
  141. package/lib/components/grid-image/GridImage.styles.js +21 -32
  142. package/lib/components/grid-image/GridImage.styles.js.map +1 -1
  143. package/lib/components/icon/Icon.js +22 -25
  144. package/lib/components/icon/Icon.js.map +1 -1
  145. package/lib/components/icon/Icon.styles.d.ts +13 -12
  146. package/lib/components/icon/Icon.styles.js +23 -33
  147. package/lib/components/icon/Icon.styles.js.map +1 -1
  148. package/lib/components/input/Input.d.ts +42 -2
  149. package/lib/components/input/Input.js +96 -29
  150. package/lib/components/input/Input.js.map +1 -1
  151. package/lib/components/input/Input.styles.d.ts +559 -7
  152. package/lib/components/input/Input.styles.js +118 -41
  153. package/lib/components/input/Input.styles.js.map +1 -1
  154. package/lib/components/list/List.d.ts +6 -0
  155. package/lib/components/list/List.js +24 -24
  156. package/lib/components/list/List.js.map +1 -1
  157. package/lib/components/list/list-item/ListItem.d.ts +1 -1
  158. package/lib/components/list/list-item/ListItem.js +37 -30
  159. package/lib/components/list/list-item/ListItem.js.map +1 -1
  160. package/lib/components/list/list-item/ListItem.styles.d.ts +272 -6
  161. package/lib/components/list/list-item/ListItem.styles.js +32 -39
  162. package/lib/components/list/list-item/ListItem.styles.js.map +1 -1
  163. package/lib/components/list/list-item/list-item-body/ListItemBody.d.ts +6 -2
  164. package/lib/components/list/list-item/list-item-body/ListItemBody.js +28 -15
  165. package/lib/components/list/list-item/list-item-body/ListItemBody.js.map +1 -1
  166. package/lib/components/list/list-item/list-item-body/ListItemBody.styles.d.ts +267 -1
  167. package/lib/components/list/list-item/list-item-body/ListItemBody.styles.js +3 -11
  168. package/lib/components/list/list-item/list-item-body/ListItemBody.styles.js.map +1 -1
  169. package/lib/components/list/list-item/list-item-content/ListItemContent.d.ts +8 -2
  170. package/lib/components/list/list-item/list-item-content/ListItemContent.js +4 -12
  171. package/lib/components/list/list-item/list-item-content/ListItemContent.js.map +1 -1
  172. package/lib/components/list/list-item/list-item-content/ListItemContent.styles.d.ts +2 -1
  173. package/lib/components/list/list-item/list-item-content/ListItemContent.styles.js +2 -10
  174. package/lib/components/list/list-item/list-item-content/ListItemContent.styles.js.map +1 -1
  175. package/lib/components/list/list-item/list-item-head/ListItemHead.js +25 -35
  176. package/lib/components/list/list-item/list-item-head/ListItemHead.js.map +1 -1
  177. package/lib/components/list/list-item/list-item-head/ListItemHead.styles.d.ts +546 -16
  178. package/lib/components/list/list-item/list-item-head/ListItemHead.styles.js +19 -38
  179. package/lib/components/list/list-item/list-item-head/ListItemHead.styles.js.map +1 -1
  180. package/lib/components/list/list-item/list-item-head/list-item-icon/ListItemIcon.js +5 -13
  181. package/lib/components/list/list-item/list-item-head/list-item-icon/ListItemIcon.js.map +1 -1
  182. package/lib/components/list/list-item/list-item-head/list-item-icon/ListItemIcon.styles.d.ts +2 -1
  183. package/lib/components/list/list-item/list-item-head/list-item-icon/ListItemIcon.styles.js +2 -10
  184. package/lib/components/list/list-item/list-item-head/list-item-icon/ListItemIcon.styles.js.map +1 -1
  185. package/lib/components/list/list-item/list-item-head/list-item-image/ListItemImage.js +11 -21
  186. package/lib/components/list/list-item/list-item-head/list-item-image/ListItemImage.js.map +1 -1
  187. package/lib/components/list/list-item/list-item-head/list-item-image/ListItemImage.styles.d.ts +8 -7
  188. package/lib/components/list/list-item/list-item-head/list-item-image/ListItemImage.styles.js +7 -16
  189. package/lib/components/list/list-item/list-item-head/list-item-image/ListItemImage.styles.js.map +1 -1
  190. package/lib/components/mention-finder/MentionFinder.d.ts +31 -0
  191. package/lib/components/mention-finder/MentionFinder.js +130 -0
  192. package/lib/components/mention-finder/MentionFinder.js.map +1 -0
  193. package/lib/components/mention-finder/MentionFinder.styles.d.ts +272 -0
  194. package/lib/components/mention-finder/MentionFinder.styles.js +84 -0
  195. package/lib/components/mention-finder/MentionFinder.styles.js.map +1 -0
  196. package/lib/components/mention-finder/mention-finder-item/MentionFinderItem.d.ts +10 -0
  197. package/lib/components/mention-finder/mention-finder-item/MentionFinderItem.js +23 -0
  198. package/lib/components/mention-finder/mention-finder-item/MentionFinderItem.js.map +1 -0
  199. package/lib/components/mention-finder/mention-finder-item/MentionFinderItem.styles.d.ts +11 -0
  200. package/lib/components/mention-finder/mention-finder-item/MentionFinderItem.styles.js +83 -0
  201. package/lib/components/mention-finder/mention-finder-item/MentionFinderItem.styles.js.map +1 -0
  202. package/lib/components/number-input/NumberInput.d.ts +54 -0
  203. package/lib/components/number-input/NumberInput.js +133 -0
  204. package/lib/components/number-input/NumberInput.js.map +1 -0
  205. package/lib/components/popup/Popup.d.ts +30 -0
  206. package/lib/components/popup/Popup.js +150 -0
  207. package/lib/components/popup/Popup.js.map +1 -0
  208. package/lib/components/popup/Popup.styles.d.ts +5 -0
  209. package/lib/components/popup/Popup.styles.js +21 -0
  210. package/lib/components/popup/Popup.styles.js.map +1 -0
  211. package/lib/components/popup/popup-content/PopupContent.d.ts +10 -0
  212. package/lib/components/popup/popup-content/PopupContent.js +64 -0
  213. package/lib/components/popup/popup-content/PopupContent.js.map +1 -0
  214. package/lib/components/popup/popup-content/PopupContent.styles.d.ts +274 -0
  215. package/lib/components/popup/popup-content/PopupContent.styles.js +84 -0
  216. package/lib/components/popup/popup-content/PopupContent.styles.js.map +1 -0
  217. package/lib/components/progress-bar/ProgressBar.d.ts +13 -0
  218. package/lib/components/progress-bar/ProgressBar.js +31 -0
  219. package/lib/components/progress-bar/ProgressBar.js.map +1 -0
  220. package/lib/components/progress-bar/ProgressBar.styles.d.ts +272 -0
  221. package/lib/components/progress-bar/ProgressBar.styles.js +30 -0
  222. package/lib/components/progress-bar/ProgressBar.styles.js.map +1 -0
  223. package/lib/components/radio-button/RadioButton.d.ts +30 -0
  224. package/lib/components/radio-button/RadioButton.js +92 -0
  225. package/lib/components/radio-button/RadioButton.js.map +1 -0
  226. package/lib/components/radio-button/RadioButton.styles.d.ts +287 -0
  227. package/lib/components/radio-button/RadioButton.styles.js +105 -0
  228. package/lib/components/radio-button/RadioButton.styles.js.map +1 -0
  229. package/lib/components/radio-button/radio-button-group/RadioButtonGroup.d.ts +17 -0
  230. package/lib/components/radio-button/radio-button-group/RadioButtonGroup.js +38 -0
  231. package/lib/components/radio-button/radio-button-group/RadioButtonGroup.js.map +1 -0
  232. package/lib/components/scroll-view/ScrollView.d.ts +13 -0
  233. package/lib/components/scroll-view/ScrollView.js +19 -0
  234. package/lib/components/scroll-view/ScrollView.js.map +1 -0
  235. package/lib/components/scroll-view/ScrollView.styles.d.ts +9 -0
  236. package/lib/components/scroll-view/ScrollView.styles.js +41 -0
  237. package/lib/components/scroll-view/ScrollView.styles.js.map +1 -0
  238. package/lib/components/search-box/SearchBox.d.ts +41 -0
  239. package/lib/components/search-box/SearchBox.js +271 -0
  240. package/lib/components/search-box/SearchBox.js.map +1 -0
  241. package/lib/components/search-box/SearchBox.styles.d.ts +274 -0
  242. package/lib/components/search-box/SearchBox.styles.js +71 -0
  243. package/lib/components/search-box/SearchBox.styles.js.map +1 -0
  244. package/lib/components/search-box/search-box-item/SearchBoxItem.d.ts +11 -0
  245. package/lib/components/search-box/search-box-item/SearchBoxItem.js +27 -0
  246. package/lib/components/search-box/search-box-item/SearchBoxItem.js.map +1 -0
  247. package/lib/components/search-box/search-box-item/SearchBoxItem.styles.d.ts +13 -0
  248. package/lib/components/search-box/search-box-item/SearchBoxItem.styles.js +55 -0
  249. package/lib/components/search-box/search-box-item/SearchBoxItem.styles.js.map +1 -0
  250. package/lib/components/search-input/SearchInput.d.ts +33 -0
  251. package/lib/components/search-input/SearchInput.js +93 -0
  252. package/lib/components/search-input/SearchInput.js.map +1 -0
  253. package/lib/components/search-input/SearchInput.styles.d.ts +534 -0
  254. package/lib/components/search-input/SearchInput.styles.js +19 -0
  255. package/lib/components/search-input/SearchInput.styles.js.map +1 -0
  256. package/lib/components/select-button/SelectButton.d.ts +34 -0
  257. package/lib/components/select-button/SelectButton.js +56 -0
  258. package/lib/components/select-button/SelectButton.js.map +1 -0
  259. package/lib/components/select-button/SelectButton.styles.d.ts +2 -0
  260. package/lib/components/select-button/SelectButton.styles.js +3 -0
  261. package/lib/components/select-button/SelectButton.styles.js.map +1 -0
  262. package/lib/components/setup-wizard/SetupWizard.d.ts +27 -0
  263. package/lib/components/setup-wizard/SetupWizard.js +73 -0
  264. package/lib/components/setup-wizard/SetupWizard.js.map +1 -0
  265. package/lib/components/setup-wizard/SetupWizard.styles.d.ts +2 -0
  266. package/lib/components/setup-wizard/SetupWizard.styles.js +3 -0
  267. package/lib/components/setup-wizard/SetupWizard.styles.js.map +1 -0
  268. package/lib/components/setup-wizard/setup-wizard-item/SetupWizardItem.d.ts +21 -0
  269. package/lib/components/setup-wizard/setup-wizard-item/SetupWizardItem.js +49 -0
  270. package/lib/components/setup-wizard/setup-wizard-item/SetupWizardItem.js.map +1 -0
  271. package/lib/components/setup-wizard/setup-wizard-item/SetupWizardItem.styles.d.ts +3 -0
  272. package/lib/components/setup-wizard/setup-wizard-item/SetupWizardItem.styles.js +7 -0
  273. package/lib/components/setup-wizard/setup-wizard-item/SetupWizardItem.styles.js.map +1 -0
  274. package/lib/components/sharing-bar/SharingBar.d.ts +18 -0
  275. package/lib/components/sharing-bar/SharingBar.js +101 -0
  276. package/lib/components/sharing-bar/SharingBar.js.map +1 -0
  277. package/lib/components/sharing-bar/SharingBar.styles.d.ts +6 -0
  278. package/lib/components/sharing-bar/SharingBar.styles.js +17 -0
  279. package/lib/components/sharing-bar/SharingBar.styles.js.map +1 -0
  280. package/lib/components/signature/Signature.d.ts +33 -0
  281. package/lib/components/signature/Signature.js +95 -0
  282. package/lib/components/signature/Signature.js.map +1 -0
  283. package/lib/components/signature/Signature.styles.d.ts +5 -0
  284. package/lib/components/signature/Signature.styles.js +14 -0
  285. package/lib/components/signature/Signature.styles.js.map +1 -0
  286. package/lib/components/slider/Slider.d.ts +45 -0
  287. package/lib/components/slider/Slider.js +181 -0
  288. package/lib/components/slider/Slider.js.map +1 -0
  289. package/lib/components/slider/Slider.styles.d.ts +16 -0
  290. package/lib/components/slider/Slider.styles.js +98 -0
  291. package/lib/components/slider/Slider.styles.js.map +1 -0
  292. package/lib/components/slider-button/SliderButton.d.ts +23 -0
  293. package/lib/components/slider-button/SliderButton.js +148 -0
  294. package/lib/components/slider-button/SliderButton.js.map +1 -0
  295. package/lib/components/slider-button/SliderButton.styles.d.ts +279 -0
  296. package/lib/components/slider-button/SliderButton.styles.js +62 -0
  297. package/lib/components/slider-button/SliderButton.styles.js.map +1 -0
  298. package/lib/components/small-wait-cursor/SmallWaitCursor.d.ts +31 -0
  299. package/lib/components/small-wait-cursor/SmallWaitCursor.js +36 -0
  300. package/lib/components/small-wait-cursor/SmallWaitCursor.js.map +1 -0
  301. package/lib/components/small-wait-cursor/SmallWaitCursor.styles.d.ts +19 -0
  302. package/lib/components/small-wait-cursor/SmallWaitCursor.styles.js +93 -0
  303. package/lib/components/small-wait-cursor/SmallWaitCursor.styles.js.map +1 -0
  304. package/lib/components/tag-input/TagInput.d.ts +22 -0
  305. package/lib/components/tag-input/TagInput.js +79 -0
  306. package/lib/components/tag-input/TagInput.js.map +1 -0
  307. package/lib/components/tag-input/TagInput.styles.d.ts +9 -0
  308. package/lib/components/tag-input/TagInput.styles.js +41 -0
  309. package/lib/components/tag-input/TagInput.styles.js.map +1 -0
  310. package/lib/components/text-area/TextArea.d.ts +29 -0
  311. package/lib/components/text-area/TextArea.js +49 -0
  312. package/lib/components/text-area/TextArea.js.map +1 -0
  313. package/lib/components/text-area/TextArea.styles.d.ts +16 -0
  314. package/lib/components/text-area/TextArea.styles.js +101 -0
  315. package/lib/components/text-area/TextArea.styles.js.map +1 -0
  316. package/lib/components/tooltip/Tooltip.d.ts +22 -0
  317. package/lib/components/tooltip/Tooltip.js +33 -0
  318. package/lib/components/tooltip/Tooltip.js.map +1 -0
  319. package/lib/components/tooltip/Tooltip.styles.d.ts +2 -0
  320. package/lib/components/tooltip/Tooltip.styles.js +3 -0
  321. package/lib/components/tooltip/Tooltip.styles.js.map +1 -0
  322. package/lib/components/tooltip/tooltip-item/TooltipItem.d.ts +13 -0
  323. package/lib/components/tooltip/tooltip-item/TooltipItem.js +22 -0
  324. package/lib/components/tooltip/tooltip-item/TooltipItem.js.map +1 -0
  325. package/lib/components/tooltip/tooltip-item/TooltipItem.styles.d.ts +15 -0
  326. package/lib/components/tooltip/tooltip-item/TooltipItem.styles.js +36 -0
  327. package/lib/components/tooltip/tooltip-item/TooltipItem.styles.js.map +1 -0
  328. package/lib/components/truncation/Truncation.d.ts +34 -0
  329. package/lib/components/truncation/Truncation.js +132 -0
  330. package/lib/components/truncation/Truncation.js.map +1 -0
  331. package/lib/components/truncation/Truncation.styles.d.ts +277 -0
  332. package/lib/components/truncation/Truncation.styles.js +44 -0
  333. package/lib/components/truncation/Truncation.styles.js.map +1 -0
  334. package/lib/constants/mentionFinder.d.ts +4 -0
  335. package/lib/constants/mentionFinder.js +6 -0
  336. package/lib/constants/mentionFinder.js.map +1 -0
  337. package/lib/constants/numberInput.d.ts +5 -0
  338. package/lib/constants/numberInput.js +6 -0
  339. package/lib/constants/numberInput.js.map +1 -0
  340. package/lib/constants/signature.d.ts +1 -0
  341. package/lib/constants/signature.js +2 -0
  342. package/lib/constants/signature.js.map +1 -0
  343. package/lib/hooks/useElementSize.d.ts +2 -0
  344. package/lib/hooks/useElementSize.js +9 -0
  345. package/lib/hooks/useElementSize.js.map +1 -0
  346. package/lib/hooks/uuid.js +4 -11
  347. package/lib/hooks/uuid.js.map +1 -1
  348. package/lib/index.d.ts +44 -1
  349. package/lib/index.js +49 -111
  350. package/lib/index.js.map +1 -1
  351. package/lib/types/chayns.d.ts +67 -1
  352. package/lib/types/chayns.js +3 -10
  353. package/lib/types/chayns.js.map +1 -1
  354. package/lib/types/colorSchemeProvider.d.ts +15 -0
  355. package/lib/types/colorSchemeProvider.js +9 -0
  356. package/lib/types/colorSchemeProvider.js.map +1 -0
  357. package/lib/types/comboBox.d.ts +4 -0
  358. package/lib/types/comboBox.js +6 -0
  359. package/lib/types/comboBox.js.map +1 -0
  360. package/lib/{components/context-menu/constants/alignment.js → types/contextMenu.js} +4 -11
  361. package/lib/types/contextMenu.js.map +1 -0
  362. package/lib/types/file.d.ts +46 -0
  363. package/lib/types/file.js +2 -0
  364. package/lib/types/file.js.map +1 -0
  365. package/lib/types/filterButtons.d.ts +15 -0
  366. package/lib/types/filterButtons.js +11 -0
  367. package/lib/types/filterButtons.js.map +1 -0
  368. package/lib/types/popup.d.ts +16 -0
  369. package/lib/types/popup.js +10 -0
  370. package/lib/types/popup.js.map +1 -0
  371. package/lib/types/radioButton.d.ts +4 -0
  372. package/lib/types/radioButton.js +2 -0
  373. package/lib/types/radioButton.js.map +1 -0
  374. package/lib/types/searchBox.d.ts +5 -0
  375. package/lib/types/searchBox.js +2 -0
  376. package/lib/types/searchBox.js.map +1 -0
  377. package/lib/types/selectButton.d.ts +4 -0
  378. package/lib/types/selectButton.js +2 -0
  379. package/lib/types/selectButton.js.map +1 -0
  380. package/lib/types/signature.d.ts +10 -0
  381. package/lib/types/signature.js +2 -0
  382. package/lib/types/signature.js.map +1 -0
  383. package/lib/types/slider-button.d.ts +4 -0
  384. package/lib/types/slider-button.js +2 -0
  385. package/lib/types/slider-button.js.map +1 -0
  386. package/lib/types/tagInput.d.ts +4 -0
  387. package/lib/types/tagInput.js +2 -0
  388. package/lib/types/tagInput.js.map +1 -0
  389. package/lib/types/tooltip.d.ts +9 -0
  390. package/lib/types/tooltip.js +2 -0
  391. package/lib/types/tooltip.js.map +1 -0
  392. package/lib/types/truncation.d.ts +5 -0
  393. package/lib/types/truncation.js +7 -0
  394. package/lib/types/truncation.js.map +1 -0
  395. package/lib/{components/accordion/utils.js → utils/accordion.js} +2 -9
  396. package/lib/utils/accordion.js.map +1 -0
  397. package/lib/utils/amountControl.d.ts +7 -0
  398. package/lib/utils/amountControl.js +15 -0
  399. package/lib/utils/amountControl.js.map +1 -0
  400. package/lib/utils/calculate.d.ts +6 -0
  401. package/lib/utils/calculate.js +80 -0
  402. package/lib/utils/calculate.js.map +1 -0
  403. package/lib/utils/file.d.ts +363 -0
  404. package/lib/utils/file.js +393 -0
  405. package/lib/utils/file.js.map +1 -0
  406. package/lib/utils/fileDialog.d.ts +7 -0
  407. package/lib/utils/fileDialog.js +65 -0
  408. package/lib/utils/fileDialog.js.map +1 -0
  409. package/lib/utils/font.d.ts +8 -0
  410. package/lib/utils/font.js +67 -0
  411. package/lib/utils/font.js.map +1 -0
  412. package/lib/utils/icon.js +5 -0
  413. package/lib/utils/icon.js.map +1 -0
  414. package/lib/utils/isTobitEmployee.d.ts +1 -0
  415. package/lib/utils/isTobitEmployee.js +21 -0
  416. package/lib/utils/isTobitEmployee.js.map +1 -0
  417. package/lib/utils/numberInput.d.ts +23 -0
  418. package/lib/utils/numberInput.js +83 -0
  419. package/lib/utils/numberInput.js.map +1 -0
  420. package/lib/utils/searchBox.d.ts +7 -0
  421. package/lib/utils/searchBox.js +16 -0
  422. package/lib/utils/searchBox.js.map +1 -0
  423. package/lib/utils/slider.d.ts +7 -0
  424. package/lib/utils/slider.js +28 -0
  425. package/lib/utils/slider.js.map +1 -0
  426. package/lib/utils/sliderButton.d.ts +15 -0
  427. package/lib/utils/sliderButton.js +45 -0
  428. package/lib/utils/sliderButton.js.map +1 -0
  429. package/lib/utils/truncation.d.ts +1 -0
  430. package/lib/utils/truncation.js +27 -0
  431. package/lib/utils/truncation.js.map +1 -0
  432. package/lib/utils/uploadFile.d.ts +7 -0
  433. package/lib/utils/uploadFile.js +35 -0
  434. package/lib/utils/uploadFile.js.map +1 -0
  435. package/package.json +32 -21
  436. package/lib/components/accordion/utils.js.map +0 -1
  437. package/lib/components/context-menu/constants/alignment.js.map +0 -1
  438. package/lib/components/icon/utils.js +0 -13
  439. package/lib/components/icon/utils.js.map +0 -1
  440. /package/lib/{components/context-menu/constants/alignment.d.ts → types/contextMenu.d.ts} +0 -0
  441. /package/lib/{components/accordion/utils.d.ts → utils/accordion.d.ts} +0 -0
  442. /package/lib/{components/icon/utils.d.ts → utils/icon.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Signature.js","names":["createDialog","DialogType","React","forwardRef","useCallback","useEffect","useImperativeHandle","useState","deleteUserSignature","getUserSignature","putUserSignature","Button","Icon","StyledSignature","StyledSignatureDeleteIconWrapper","StyledSignatureImage","StyledSignatureImageWrapper","Signature","_ref","ref","onEdit","onRemove","onUnsubscribe","onSubscribe","buttonText","isDisabled","signatureUrl","setSignatureUrl","undefined","hasSubscribed","setHasSubscribed","loadUserSignature","then","signature","handleCallDialog","shouldSubscribe","dialog","type","SIGNATURE","open","buttonType","result","success","handleEdit","handleDelete","handleClick","handleUnSubscribe","edit","delete","createElement","onClick","src","icons","size","displayName"],"sources":["../../../src/components/signature/Signature.tsx"],"sourcesContent":["import { createDialog, DialogType } from 'chayns-api';\nimport React, { forwardRef, useCallback, useEffect, useImperativeHandle, useState } from 'react';\nimport { deleteUserSignature } from '../../api/signature/delete';\nimport { getUserSignature } from '../../api/signature/get';\nimport { putUserSignature } from '../../api/signature/put';\nimport type { SignatureDialogResult } from '../../types/signature';\nimport Button from '../button/Button';\nimport Icon from '../icon/Icon';\nimport {\n StyledSignature,\n StyledSignatureDeleteIconWrapper,\n StyledSignatureImage,\n StyledSignatureImageWrapper,\n} from './Signature.styles';\n\nexport interface SignatureRef {\n edit: VoidFunction;\n delete: VoidFunction;\n}\n\nexport type SignatureProps = {\n /**\n * The text that should be displayed inside the button.\n */\n buttonText: string;\n /**\n * Whether the button is disabled.\n */\n isDisabled?: boolean;\n /**\n * Function to be executed when the signature is edited.\n */\n onEdit?: (signature: string) => void;\n /**\n * Function to be executed when the user deletes the signature.\n */\n onRemove?: () => void;\n /**\n * Function to be executed when the user subscribes.\n */\n onSubscribe?: () => void;\n /**\n * Function to be executed when the user unsubscribes.\n */\n onUnsubscribe?: () => void;\n};\n\nconst Signature = forwardRef<SignatureRef, SignatureProps>(\n ({ onEdit, onRemove, onUnsubscribe, onSubscribe, buttonText, isDisabled }, ref) => {\n const [signatureUrl, setSignatureUrl] = useState<string | undefined>(undefined);\n const [hasSubscribed, setHasSubscribed] = useState(false);\n\n useEffect(() => {\n const loadUserSignature = async () => {\n await getUserSignature().then((signature) => {\n setSignatureUrl(signature);\n });\n };\n\n void loadUserSignature();\n }, []);\n\n const handleCallDialog = useCallback(\n async (shouldSubscribe: boolean) => {\n const dialog = (await createDialog({\n type: DialogType.SIGNATURE,\n }).open()) as SignatureDialogResult;\n\n if (dialog.buttonType === 1 && dialog.result) {\n await putUserSignature(dialog.result).then((success) => {\n if (success) {\n setSignatureUrl(dialog.result);\n\n if (shouldSubscribe) {\n setHasSubscribed(true);\n\n if (typeof onSubscribe === 'function') {\n onSubscribe();\n }\n } else if (typeof onEdit === 'function') {\n onEdit(dialog.result);\n }\n }\n });\n }\n },\n [onEdit, onSubscribe],\n );\n\n const handleEdit = useCallback(() => {\n void handleCallDialog(false);\n }, [handleCallDialog]);\n\n const handleDelete = useCallback(async () => {\n await deleteUserSignature().then((success) => {\n if (success) {\n setSignatureUrl(undefined);\n\n if (typeof onRemove === 'function') {\n onRemove();\n }\n }\n });\n }, [onRemove]);\n\n const handleClick = useCallback(() => {\n if (signatureUrl) {\n setHasSubscribed(true);\n\n if (typeof onSubscribe === 'function') {\n onSubscribe();\n }\n } else {\n void handleCallDialog(true);\n }\n }, [handleCallDialog, onSubscribe, signatureUrl]);\n\n const handleUnSubscribe = () => {\n setHasSubscribed(false);\n setSignatureUrl(undefined);\n\n if (typeof onUnsubscribe === 'function') {\n onUnsubscribe();\n }\n };\n\n useImperativeHandle(\n ref,\n () => ({\n edit: handleEdit,\n delete: handleDelete,\n }),\n [handleDelete, handleEdit],\n );\n\n return (\n <StyledSignature>\n {!hasSubscribed ? (\n <Button isDisabled={isDisabled} onClick={handleClick}>\n {buttonText}\n </Button>\n ) : (\n <StyledSignatureImageWrapper>\n <StyledSignatureImage src={signatureUrl} />\n <StyledSignatureDeleteIconWrapper>\n <Icon icons={['ts-wrong']} size={20} onClick={handleUnSubscribe} />\n </StyledSignatureDeleteIconWrapper>\n </StyledSignatureImageWrapper>\n )}\n </StyledSignature>\n );\n },\n);\n\nSignature.displayName = 'Signature';\n\nexport default Signature;\n"],"mappings":"AAAA,SAASA,YAAY,EAAEC,UAAU,QAAQ,YAAY;AACrD,OAAOC,KAAK,IAAIC,UAAU,EAAEC,WAAW,EAAEC,SAAS,EAAEC,mBAAmB,EAAEC,QAAQ,QAAQ,OAAO;AAChG,SAASC,mBAAmB,QAAQ,4BAA4B;AAChE,SAASC,gBAAgB,QAAQ,yBAAyB;AAC1D,SAASC,gBAAgB,QAAQ,yBAAyB;AAE1D,OAAOC,MAAM,MAAM,kBAAkB;AACrC,OAAOC,IAAI,MAAM,cAAc;AAC/B,SACIC,eAAe,EACfC,gCAAgC,EAChCC,oBAAoB,EACpBC,2BAA2B,QACxB,oBAAoB;AAkC3B,MAAMC,SAAS,gBAAGd,UAAU,CACxB,CAAAe,IAAA,EAA2EC,GAAG,KAAK;EAAA,IAAlF;IAAEC,MAAM;IAAE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tC,MAAM;IAACc,UAAU,EAAEA,UAAW;IAACyB,OAAO,EAAEL;EAAY,GAChDrB,UACG,CAAC,gBAETtB,KAAA,CAAA+C,aAAA,CAACjC,2BAA2B,qBACxBd,KAAA,CAAA+C,aAAA,CAAClC,oBAAoB;IAACoC,GAAG,EAAEzB;EAAa,CAAE,CAAC,eAC3CxB,KAAA,CAAA+C,aAAA,CAACnC,gCAAgC,qBAC7BZ,KAAA,CAAA+C,aAAA,CAACrC,IAAI;IAACwC,KAAK,EAAE,CAAC,UAAU,CAAE;IAACC,IAAI,EAAE,EAAG;IAACH,OAAO,EAAEJ;EAAkB,CAAE,CACpC,CACT,CAEpB,CAAC;AAE1B,CACJ,CAAC;AAED7B,SAAS,CAACqC,WAAW,GAAG,WAAW;AAEnC,eAAerC,SAAS"}
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ export declare const StyledSignature: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>;
3
+ export declare const StyledSignatureImageWrapper: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>;
4
+ export declare const StyledSignatureImage: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("react").DetailedHTMLProps<import("react").ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, never>>;
5
+ export declare const StyledSignatureDeleteIconWrapper: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>;
@@ -0,0 +1,14 @@
1
+ import styled from 'styled-components';
2
+ export const StyledSignature = styled.div``;
3
+ export const StyledSignatureImageWrapper = styled.div`
4
+ position: relative;
5
+ aspect-ratio: 3.8;
6
+ width: 100%;
7
+ `;
8
+ export const StyledSignatureImage = styled.img``;
9
+ export const StyledSignatureDeleteIconWrapper = styled.div`
10
+ position: absolute;
11
+ top: 0;
12
+ right: 0;
13
+ `;
14
+ //# sourceMappingURL=Signature.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Signature.styles.js","names":["styled","StyledSignature","div","StyledSignatureImageWrapper","StyledSignatureImage","img","StyledSignatureDeleteIconWrapper"],"sources":["../../../src/components/signature/Signature.styles.ts"],"sourcesContent":["import styled from 'styled-components';\n\nexport const StyledSignature = styled.div``;\nexport const StyledSignatureImageWrapper = styled.div`\n position: relative;\n aspect-ratio: 3.8;\n width: 100%;\n`;\nexport const StyledSignatureImage = styled.img``;\nexport const StyledSignatureDeleteIconWrapper = styled.div`\n position: absolute;\n top: 0;\n right: 0;\n`;\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,mBAAmB;AAEtC,OAAO,MAAMC,eAAe,GAAGD,MAAM,CAACE,GAAI,EAAC;AAC3C,OAAO,MAAMC,2BAA2B,GAAGH,MAAM,CAACE,GAAI;AACtD;AACA;AACA;AACA,CAAC;AACD,OAAO,MAAME,oBAAoB,GAAGJ,MAAM,CAACK,GAAI,EAAC;AAChD,OAAO,MAAMC,gCAAgC,GAAGN,MAAM,CAACE,GAAI;AAC3D;AACA;AACA;AACA,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { FC } from 'react';
2
+ export interface SliderInterval {
3
+ maxValue: number;
4
+ minValue: number;
5
+ }
6
+ export type SliderProps = {
7
+ /**
8
+ * The range that can be selected with two thumbs..
9
+ */
10
+ interval?: SliderInterval;
11
+ /**
12
+ * The maximum value of the slider.
13
+ */
14
+ maxValue: number;
15
+ /**
16
+ * The minimum value of the slider.
17
+ */
18
+ minValue: number;
19
+ /**
20
+ *
21
+ */
22
+ onSelect?: (value?: number, interval?: SliderInterval) => void;
23
+ /**
24
+ * Function that will be executed when the value is changed.
25
+ */
26
+ onChange?: (value?: number, interval?: SliderInterval) => void;
27
+ /**
28
+ * Whether the current value should be displayed inside the slider thumb.
29
+ */
30
+ shouldShowThumbLable?: boolean;
31
+ /**
32
+ * The steps of the slider.
33
+ */
34
+ steps?: number;
35
+ /**
36
+ * A function to format the thumb label.
37
+ */
38
+ thumbLabelFormatter?: (value: number) => string;
39
+ /**
40
+ * the Value that the slider should have.
41
+ */
42
+ value?: number;
43
+ };
44
+ declare const Slider: FC<SliderProps>;
45
+ export default Slider;
@@ -0,0 +1,181 @@
1
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { useTheme } from 'styled-components';
3
+ import { fillSlider } from '../../utils/slider';
4
+ import { StyledSlider, StyledSliderInput, StyledSliderThumb, StyledSliderThumbLable } from './Slider.styles';
5
+ const Slider = _ref => {
6
+ let {
7
+ maxValue,
8
+ minValue,
9
+ value,
10
+ onSelect,
11
+ onChange,
12
+ interval,
13
+ thumbLabelFormatter,
14
+ shouldShowThumbLable = false,
15
+ steps = 1
16
+ } = _ref;
17
+ const [fromValue, setFromValue] = useState(0);
18
+ const [toValue, setToValue] = useState(maxValue);
19
+ const fromSliderRef = useRef(null);
20
+ const toSliderRef = useRef(null);
21
+ const fromSliderThumbRef = useRef(null);
22
+ const toSliderThumbRef = useRef(null);
23
+ const theme = useTheme();
24
+
25
+ /**
26
+ * This function sets the value
27
+ */
28
+ useEffect(() => {
29
+ if (typeof value !== 'number') {
30
+ return;
31
+ }
32
+ if (value >= minValue && value <= maxValue) {
33
+ setFromValue(value);
34
+ }
35
+ }, [maxValue, minValue, value]);
36
+ useEffect(() => {
37
+ if (fromValue > toValue) {
38
+ setFromValue(toValue);
39
+ }
40
+ if (toValue < fromValue) {
41
+ setToValue(fromValue);
42
+ }
43
+ }, [fromValue, toValue]);
44
+ const handleMouseUp = useCallback(() => {
45
+ const from = Number(fromSliderRef.current?.value);
46
+ const to = Number(toSliderRef.current?.value);
47
+ if (typeof onSelect === 'function') {
48
+ onSelect(interval ? undefined : from, interval ? {
49
+ maxValue: to,
50
+ minValue: from
51
+ } : undefined);
52
+ }
53
+ }, [interval, onSelect]);
54
+ const handleControlFromSlider = useCallback(event => {
55
+ if (!fromSliderRef.current || !toSliderRef.current) {
56
+ return;
57
+ }
58
+ setFromValue(Number(event.target.value));
59
+ const from = Number(fromSliderRef.current.value);
60
+ const to = Number(toSliderRef.current.value);
61
+ if (typeof onChange === 'function') {
62
+ onChange(undefined, {
63
+ maxValue: to,
64
+ minValue: from
65
+ });
66
+ }
67
+ fillSlider({
68
+ toSlider: toSliderRef.current,
69
+ fromSlider: fromSliderRef.current,
70
+ theme
71
+ });
72
+ if (from > to) {
73
+ fromSliderRef.current.value = String(to);
74
+ } else {
75
+ fromSliderRef.current.value = String(from);
76
+ }
77
+ }, [onChange, theme]);
78
+ const handleControlToSlider = useCallback(event => {
79
+ if (!fromSliderRef.current || !toSliderRef.current) {
80
+ return;
81
+ }
82
+ setToValue(Number(event.target.value));
83
+ const from = Number(fromSliderRef.current.value);
84
+ const to = Number(toSliderRef.current.value);
85
+ if (typeof onChange === 'function') {
86
+ onChange(undefined, {
87
+ maxValue: to,
88
+ minValue: from
89
+ });
90
+ }
91
+ fillSlider({
92
+ toSlider: toSliderRef.current,
93
+ fromSlider: fromSliderRef.current,
94
+ theme
95
+ });
96
+ if (from <= to) {
97
+ toSliderRef.current.value = String(to);
98
+ } else {
99
+ toSliderRef.current.value = String(from);
100
+ }
101
+ }, [onChange, theme]);
102
+ useEffect(() => {
103
+ if (!fromSliderRef.current || !toSliderRef.current || !interval) {
104
+ return;
105
+ }
106
+ setFromValue(interval.minValue);
107
+ setToValue(interval.maxValue);
108
+ fromSliderRef.current.value = String(interval.minValue);
109
+ toSliderRef.current.value = String(interval.maxValue);
110
+ fillSlider({
111
+ fromSlider: fromSliderRef.current,
112
+ toSlider: toSliderRef.current,
113
+ theme
114
+ });
115
+ // Note: interval can´t be in the deps because of rerender
116
+ // eslint-disable-next-line react-hooks/exhaustive-deps
117
+ }, [theme]);
118
+
119
+ /**
120
+ * This function updates the value
121
+ */
122
+ const handleInputChange = useCallback(event => {
123
+ const newValue = Number(event.target.value);
124
+ if (interval) {
125
+ handleControlFromSlider(event);
126
+ return;
127
+ }
128
+ setFromValue(newValue);
129
+ if (onChange) {
130
+ onChange(newValue);
131
+ }
132
+ }, [handleControlFromSlider, interval, onChange]);
133
+ const fromSliderThumbPosition = useMemo(() => {
134
+ if (fromSliderRef.current && fromSliderThumbRef.current) {
135
+ return (fromValue - minValue) / (maxValue - minValue) * (fromSliderRef.current.offsetWidth - fromSliderThumbRef.current.offsetWidth / 2);
136
+ }
137
+ return 0;
138
+ }, [fromValue, maxValue, minValue]);
139
+ const toSliderThumbPosition = useMemo(() => {
140
+ if (toSliderRef.current && toSliderThumbRef.current) {
141
+ return (toValue - minValue) / (maxValue - minValue) * (toSliderRef.current.offsetWidth - toSliderThumbRef.current.offsetWidth / 2);
142
+ }
143
+ return 0;
144
+ }, [toValue, maxValue, minValue]);
145
+ return useMemo(() => /*#__PURE__*/React.createElement(StyledSlider, null, /*#__PURE__*/React.createElement(StyledSliderInput, {
146
+ ref: fromSliderRef,
147
+ $isInterval: !!interval,
148
+ type: "range",
149
+ value: fromValue,
150
+ step: steps,
151
+ max: maxValue,
152
+ min: minValue,
153
+ onChange: handleInputChange,
154
+ onMouseUp: handleMouseUp,
155
+ $max: maxValue,
156
+ $min: minValue,
157
+ $value: fromValue
158
+ }), /*#__PURE__*/React.createElement(StyledSliderThumb, {
159
+ ref: fromSliderThumbRef,
160
+ $position: fromSliderThumbPosition
161
+ }, shouldShowThumbLable && /*#__PURE__*/React.createElement(StyledSliderThumbLable, null, typeof thumbLabelFormatter === 'function' ? thumbLabelFormatter(fromValue) : fromValue)), interval && /*#__PURE__*/React.createElement(StyledSliderThumb, {
162
+ ref: toSliderThumbRef,
163
+ $position: toSliderThumbPosition
164
+ }, shouldShowThumbLable && /*#__PURE__*/React.createElement(StyledSliderThumbLable, null, typeof thumbLabelFormatter === 'function' ? thumbLabelFormatter(toValue) : toValue)), interval && /*#__PURE__*/React.createElement(StyledSliderInput, {
165
+ $max: maxValue,
166
+ $min: minValue,
167
+ $value: toValue,
168
+ ref: toSliderRef,
169
+ $isInterval: !!interval,
170
+ type: "range",
171
+ value: toValue,
172
+ step: steps,
173
+ max: maxValue,
174
+ min: minValue,
175
+ onChange: handleControlToSlider,
176
+ onMouseUp: handleMouseUp
177
+ })), [interval, fromValue, steps, maxValue, minValue, handleInputChange, handleMouseUp, fromSliderThumbPosition, shouldShowThumbLable, thumbLabelFormatter, toSliderThumbPosition, toValue, handleControlToSlider]);
178
+ };
179
+ Slider.displayName = 'Slider';
180
+ export default Slider;
181
+ //# sourceMappingURL=Slider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Slider.js","names":["React","useCallback","useEffect","useMemo","useRef","useState","useTheme","fillSlider","StyledSlider","StyledSliderInput","StyledSliderThumb","StyledSliderThumbLable","Slider","_ref","maxValue","minValue","value","onSelect","onChange","interval","thumbLabelFormatter","shouldShowThumbLable","steps","fromValue","setFromValue","toValue","setToValue","fromSliderRef","toSliderRef","fromSliderThumbRef","toSliderThumbRef","theme","handleMouseUp","from","Number","current","to","undefined","handleControlFromSlider","event","target","toSlider","fromSlider","String","handleControlToSlider","handleInputChange","newValue","fromSliderThumbPosition","offsetWidth","toSliderThumbPosition","createElement","ref","$isInterval","type","step","max","min","onMouseUp","$max","$min","$value","$position","displayName"],"sources":["../../../src/components/slider/Slider.tsx"],"sourcesContent":["import React, { ChangeEvent, FC, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { useTheme } from 'styled-components';\nimport { fillSlider } from '../../utils/slider';\nimport {\n StyledSlider,\n StyledSliderInput,\n StyledSliderThumb,\n StyledSliderThumbLable,\n} from './Slider.styles';\n\nexport interface SliderInterval {\n maxValue: number;\n minValue: number;\n}\n\nexport type SliderProps = {\n /**\n * The range that can be selected with two thumbs..\n */\n interval?: SliderInterval;\n /**\n * The maximum value of the slider.\n */\n maxValue: number;\n /**\n * The minimum value of the slider.\n */\n minValue: number;\n /**\n *\n */\n onSelect?: (value?: number, interval?: SliderInterval) => void;\n /**\n * Function that will be executed when the value is changed.\n */\n onChange?: (value?: number, interval?: SliderInterval) => void;\n /**\n * Whether the current value should be displayed inside the slider thumb.\n */\n shouldShowThumbLable?: boolean;\n /**\n * The steps of the slider.\n */\n steps?: number;\n /**\n * A function to format the thumb label.\n */\n thumbLabelFormatter?: (value: number) => string;\n /**\n * the Value that the slider should have.\n */\n value?: number;\n};\n\nconst Slider: FC<SliderProps> = ({\n maxValue,\n minValue,\n value,\n onSelect,\n onChange,\n interval,\n thumbLabelFormatter,\n shouldShowThumbLable = false,\n steps = 1,\n}) => {\n const [fromValue, setFromValue] = useState(0);\n const [toValue, setToValue] = useState(maxValue);\n\n const fromSliderRef = useRef<HTMLInputElement>(null);\n const toSliderRef = useRef<HTMLInputElement>(null);\n const fromSliderThumbRef = useRef<HTMLDivElement>(null);\n const toSliderThumbRef = useRef<HTMLDivElement>(null);\n\n const theme = useTheme();\n\n /**\n * This function sets the value\n */\n useEffect(() => {\n if (typeof value !== 'number') {\n return;\n }\n\n if (value >= minValue && value <= maxValue) {\n setFromValue(value);\n }\n }, [maxValue, minValue, value]);\n\n useEffect(() => {\n if (fromValue > toValue) {\n setFromValue(toValue);\n }\n\n if (toValue < fromValue) {\n setToValue(fromValue);\n }\n }, [fromValue, toValue]);\n\n const handleMouseUp = useCallback(() => {\n const from = Number(fromSliderRef.current?.value);\n const to = Number(toSliderRef.current?.value);\n\n if (typeof onSelect === 'function') {\n onSelect(\n interval ? undefined : from,\n interval ? { maxValue: to, minValue: from } : undefined,\n );\n }\n }, [interval, onSelect]);\n\n const handleControlFromSlider = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n if (!fromSliderRef.current || !toSliderRef.current) {\n return;\n }\n\n setFromValue(Number(event.target.value));\n\n const from = Number(fromSliderRef.current.value);\n const to = Number(toSliderRef.current.value);\n\n if (typeof onChange === 'function') {\n onChange(undefined, { maxValue: to, minValue: from });\n }\n\n fillSlider({\n toSlider: toSliderRef.current,\n fromSlider: fromSliderRef.current,\n theme,\n });\n\n if (from > to) {\n fromSliderRef.current.value = String(to);\n } else {\n fromSliderRef.current.value = String(from);\n }\n },\n [onChange, theme],\n );\n\n const handleControlToSlider = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n if (!fromSliderRef.current || !toSliderRef.current) {\n return;\n }\n\n setToValue(Number(event.target.value));\n\n const from = Number(fromSliderRef.current.value);\n const to = Number(toSliderRef.current.value);\n\n if (typeof onChange === 'function') {\n onChange(undefined, { maxValue: to, minValue: from });\n }\n\n fillSlider({\n toSlider: toSliderRef.current,\n fromSlider: fromSliderRef.current,\n theme,\n });\n\n if (from <= to) {\n toSliderRef.current.value = String(to);\n } else {\n toSliderRef.current.value = String(from);\n }\n },\n [onChange, theme],\n );\n\n useEffect(() => {\n if (!fromSliderRef.current || !toSliderRef.current || !interval) {\n return;\n }\n\n setFromValue(interval.minValue);\n setToValue(interval.maxValue);\n\n fromSliderRef.current.value = String(interval.minValue);\n toSliderRef.current.value = String(interval.maxValue);\n\n fillSlider({\n fromSlider: fromSliderRef.current,\n toSlider: toSliderRef.current,\n theme,\n });\n // Note: interval can´t be in the deps because of rerender\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [theme]);\n\n /**\n * This function updates the value\n */\n const handleInputChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n const newValue = Number(event.target.value);\n\n if (interval) {\n handleControlFromSlider(event);\n\n return;\n }\n\n setFromValue(newValue);\n\n if (onChange) {\n onChange(newValue);\n }\n },\n [handleControlFromSlider, interval, onChange],\n );\n\n const fromSliderThumbPosition = useMemo(() => {\n if (fromSliderRef.current && fromSliderThumbRef.current) {\n return (\n ((fromValue - minValue) / (maxValue - minValue)) *\n (fromSliderRef.current.offsetWidth - fromSliderThumbRef.current.offsetWidth / 2)\n );\n }\n return 0;\n }, [fromValue, maxValue, minValue]);\n\n const toSliderThumbPosition = useMemo(() => {\n if (toSliderRef.current && toSliderThumbRef.current) {\n return (\n ((toValue - minValue) / (maxValue - minValue)) *\n (toSliderRef.current.offsetWidth - toSliderThumbRef.current.offsetWidth / 2)\n );\n }\n return 0;\n }, [toValue, maxValue, minValue]);\n\n return useMemo(\n () => (\n <StyledSlider>\n <StyledSliderInput\n ref={fromSliderRef}\n $isInterval={!!interval}\n type=\"range\"\n value={fromValue}\n step={steps}\n max={maxValue}\n min={minValue}\n onChange={handleInputChange}\n onMouseUp={handleMouseUp}\n $max={maxValue}\n $min={minValue}\n $value={fromValue}\n />\n <StyledSliderThumb ref={fromSliderThumbRef} $position={fromSliderThumbPosition}>\n {shouldShowThumbLable && (\n <StyledSliderThumbLable>\n {typeof thumbLabelFormatter === 'function'\n ? thumbLabelFormatter(fromValue)\n : fromValue}\n </StyledSliderThumbLable>\n )}\n </StyledSliderThumb>\n {interval && (\n <StyledSliderThumb ref={toSliderThumbRef} $position={toSliderThumbPosition}>\n {shouldShowThumbLable && (\n <StyledSliderThumbLable>\n {typeof thumbLabelFormatter === 'function'\n ? thumbLabelFormatter(toValue)\n : toValue}\n </StyledSliderThumbLable>\n )}\n </StyledSliderThumb>\n )}\n {interval && (\n <StyledSliderInput\n $max={maxValue}\n $min={minValue}\n $value={toValue}\n ref={toSliderRef}\n $isInterval={!!interval}\n type=\"range\"\n value={toValue}\n step={steps}\n max={maxValue}\n min={minValue}\n onChange={handleControlToSlider}\n onMouseUp={handleMouseUp}\n />\n )}\n </StyledSlider>\n ),\n [\n interval,\n fromValue,\n steps,\n maxValue,\n minValue,\n handleInputChange,\n handleMouseUp,\n fromSliderThumbPosition,\n shouldShowThumbLable,\n thumbLabelFormatter,\n toSliderThumbPosition,\n toValue,\n handleControlToSlider,\n ],\n );\n};\n\nSlider.displayName = 'Slider';\n\nexport default Slider;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAqBC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACjG,SAASC,Q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GAAG,EAAErB,gBAAiB;IAAC+B,SAAS,EAAEZ;EAAsB,GACtE5B,oBAAoB,iBACjBrB,KAAA,CAAAkD,aAAA,CAACvC,sBAAsB,QAClB,OAAOS,mBAAmB,KAAK,UAAU,GACpCA,mBAAmB,CAACK,OAAO,CAAC,GAC5BA,OACc,CAEb,CACtB,EACAN,QAAQ,iBACLnB,KAAA,CAAAkD,aAAA,CAACzC,iBAAiB;IACdiD,IAAI,EAAE5C,QAAS;IACf6C,IAAI,EAAE5C,QAAS;IACf6C,MAAM,EAAEnC,OAAQ;IAChB0B,GAAG,EAAEvB,WAAY;IACjBwB,WAAW,EAAE,CAAC,CAACjC,QAAS;IACxBkC,IAAI,EAAC,OAAO;IACZrC,KAAK,EAAES,OAAQ;IACf6B,IAAI,EAAEhC,KAAM;IACZiC,GAAG,EAAEzC,QAAS;IACd0C,GAAG,EAAEzC,QAAS;IACdG,QAAQ,EAAE0B,qBAAsB;IAChCa,SAAS,EAAEzB;EAAc,CAC5B,CAEK,CACjB,EACD,CACIb,QAAQ,EACRI,SAAS,EACTD,KAAK,EACLR,QAAQ,EACRC,QAAQ,EACR8B,iBAAiB,EACjBb,aAAa,EACbe,uBAAuB,EACvB1B,oBAAoB,EACpBD,mBAAmB,EACnB6B,qBAAqB,EACrBxB,OAAO,EACPmB,qBAAqB,CAE7B,CAAC;AACL,CAAC;AAEDhC,MAAM,CAACkD,WAAW,GAAG,QAAQ;AAE7B,eAAelD,MAAM"}
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ import type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';
3
+ export declare const StyledSlider: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>;
4
+ type StyledSliderInputProps = WithTheme<{
5
+ $min: number;
6
+ $max: number;
7
+ $value: number;
8
+ $isInterval: boolean;
9
+ }>;
10
+ export declare const StyledSliderInput: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, StyledSliderInputProps>>;
11
+ type StyledSliderThumbProps = WithTheme<{
12
+ $position: number;
13
+ }>;
14
+ export declare const StyledSliderThumb: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledSliderThumbProps>>;
15
+ export declare const StyledSliderThumbLable: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>>;
16
+ export {};
@@ -0,0 +1,98 @@
1
+ import styled, { css } from 'styled-components';
2
+ export const StyledSlider = styled.div`
3
+ width: 100%;
4
+ height: 30px;
5
+ cursor: pointer;
6
+ position: relative;
7
+ display: flex;
8
+ align-items: center;
9
+ `;
10
+ export const StyledSliderInput = styled.input`
11
+ position: absolute;
12
+ width: 100%;
13
+ border-radius: 100px;
14
+ -webkit-appearance: none;
15
+ height: 10px;
16
+ outline: none;
17
+ cursor: pointer !important;
18
+ z-index: 2;
19
+ appearance: none;
20
+ pointer-events: ${_ref => {
21
+ let {
22
+ $isInterval
23
+ } = _ref;
24
+ return $isInterval ? 'none' : 'all';
25
+ }};
26
+
27
+ ${_ref2 => {
28
+ let {
29
+ $isInterval,
30
+ theme,
31
+ $min,
32
+ $max,
33
+ $value
34
+ } = _ref2;
35
+ return !$isInterval && css`
36
+ background: ${`linear-gradient(
37
+ to right,
38
+ ${theme['409'] ?? ''} 0%,
39
+ ${theme['409'] ?? ''}
40
+ ${($value - $min) / ($max - $min) * 100}%,
41
+ ${theme['403'] ?? ''}
42
+ ${($value - $min) / ($max - $min) * 100}%,
43
+ ${theme['403'] ?? ''}
44
+ )`};
45
+ `;
46
+ }}
47
+
48
+ // Slider thumb for chrome
49
+ &::-webkit-slider-thumb {
50
+ -webkit-appearance: none;
51
+ appearance: none;
52
+ width: 20px;
53
+ height: 20px;
54
+ cursor: pointer;
55
+ pointer-events: all;
56
+ position: relative;
57
+ }
58
+
59
+ // slider thumb for firefox
60
+ &::-moz-range-thumb {
61
+ width: 20px;
62
+ height: 20px;
63
+ cursor: pointer;
64
+ pointer-events: all;
65
+ position: relative;
66
+ }
67
+ `;
68
+ export const StyledSliderThumb = styled.div`
69
+ min-width: 20px;
70
+ height: 20px;
71
+ background-color: ${_ref3 => {
72
+ let {
73
+ theme
74
+ } = _ref3;
75
+ return theme['100'];
76
+ }};
77
+ cursor: pointer;
78
+ border-radius: 100px;
79
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
80
+ pointer-events: none;
81
+ z-index: 3;
82
+ left: ${_ref4 => {
83
+ let {
84
+ $position
85
+ } = _ref4;
86
+ return $position;
87
+ }}px;
88
+ position: absolute;
89
+ display: flex;
90
+ align-items: center;
91
+ justify-content: center;
92
+ padding: 0 8px;
93
+ white-space: nowrap;
94
+ `;
95
+ export const StyledSliderThumbLable = styled.span`
96
+ pointer-events: none;
97
+ `;
98
+ //# sourceMappingURL=Slider.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Slider.styles.js","names":["styled","css","StyledSlider","div","StyledSliderInput","input","_ref","$isInterval","_ref2","theme","$min","$max","$value","StyledSliderThumb","_ref3","_ref4","$position","StyledSliderThumbLable","span"],"sources":["../../../src/components/slider/Slider.styles.ts"],"sourcesContent":["import styled, { css } from 'styled-components';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\n\nexport const StyledSlider = styled.div`\n width: 100%;\n height: 30px;\n cursor: pointer;\n position: relative;\n display: flex;\n align-items: center;\n`;\n\ntype StyledSliderInputProps = WithTheme<{\n $min: number;\n $max: number;\n $value: number;\n $isInterval: boolean;\n}>;\n\nexport const StyledSliderInput = styled.input<StyledSliderInputProps>`\n position: absolute;\n width: 100%;\n border-radius: 100px;\n -webkit-appearance: none;\n height: 10px;\n outline: none;\n cursor: pointer !important;\n z-index: 2;\n appearance: none;\n pointer-events: ${({ $isInterval }) => ($isInterval ? 'none' : 'all')};\n\n ${({ $isInterval, theme, $min, $max, $value }: StyledSliderInputProps) =>\n !$isInterval &&\n css`\n background: ${`linear-gradient(\n to right,\n ${theme['409'] ?? ''} 0%,\n ${theme['409'] ?? ''}\n ${(($value - $min) / ($max - $min)) * 100}%,\n ${theme['403'] ?? ''}\n ${(($value - $min) / ($max - $min)) * 100}%,\n ${theme['403'] ?? ''}\n )`};\n `}\n\n // Slider thumb for chrome\n &::-webkit-slider-thumb {\n -webkit-appearance: none;\n appearance: none;\n width: 20px;\n height: 20px;\n cursor: pointer;\n pointer-events: all;\n position: relative;\n }\n\n // slider thumb for firefox\n &::-moz-range-thumb {\n width: 20px;\n height: 20px;\n cursor: pointer;\n pointer-events: all;\n position: relative;\n }\n`;\n\ntype StyledSliderThumbProps = WithTheme<{ $position: number }>;\n\nexport const StyledSliderThumb = styled.div<StyledSliderThumbProps>`\n min-width: 20px;\n height: 20px;\n background-color: ${({ theme }: StyledSliderThumbProps) => theme['100']};\n cursor: pointer;\n border-radius: 100px;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);\n pointer-events: none;\n z-index: 3;\n left: ${({ $position }) => $position}px;\n position: absolute;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 0 8px;\n white-space: nowrap;\n`;\n\nexport const StyledSliderThumbLable = styled.span`\n pointer-events: none;\n`;\n"],"mappings":"AAAA,OAAOA,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAG/C,OAAO,MAAMC,YAAY,GAAGF,MAAM,CAACG,GAAI;AACvC;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AASD,OAAO,MAAMC,iBAAiB,GAAGJ,MAAM,CAACK,KAA8B;AACtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsBC,IAAA;EAAA,IAAC;IAAEC;EAAY,CAAC,GAAAD,IAAA;EAAA,OAAMC,WAAW,GAAG,MAAM,GAAG,KAAK;AAAA,CAAE;AAC1E;AACA,MAAMC,KAAA;EAAA,IAAC;IAAED,WAAW;IAAEE,KAAK;IAAEC,IAAI;IAAEC,IAAI;IAAEC;EAA+B,CAAC,GAAAJ,KAAA;EAAA,OACjE,CAACD,WAAW,IACZN,GAAI;AACZ,0BAA2B;AAC3B;AACA,cAAcQ,KAAK,CAAC,KAAK,CAAC,IAAI,EAAG;AACjC,cAAcA,KAAK,CAAC,KAAK,CAAC,IAAI,EAAG;AACjC,cAAe,CAACG,MAAM,GAAGF,IAAI,KAAKC,IAAI,GAAGD,IAAI,CAAC,GAAI,GAAI;AACtD,cAAcD,KAAK,CAAC,KAAK,CAAC,IAAI,EAAG;AACjC,cAAe,CAACG,MAAM,GAAGF,IAAI,KAAKC,IAAI,GAAGD,IAAI,CAAC,GAAI,GAAI;AACtD,cAAcD,KAAK,CAAC,KAAK,CAAC,IAAI,EAAG;AACjC,UAAW;AACX,SAAS;AAAA,CAAC;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAID,OAAO,MAAMI,iBAAiB,GAAGb,MAAM,CAACG,GAA4B;AACpE;AACA;AACA,wBAAwBW,KAAA;EAAA,IAAC;IAAEL;EAA8B,CAAC,GAAAK,KAAA;EAAA,OAAKL,KAAK,CAAC,KAAK,CAAC;AAAA,CAAC;AAC5E;AACA;AACA;AACA;AACA;AACA,YAAYM,KAAA;EAAA,IAAC;IAAEC;EAAU,CAAC,GAAAD,KAAA;EAAA,OAAKC,SAAS;AAAA,CAAC;AACzC;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMC,sBAAsB,GAAGjB,MAAM,CAACkB,IAAK;AAClD;AACA,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { FC } from 'react';
2
+ import type { SliderButtonItem } from '../../types/slider-button';
3
+ export type SliderButtonProps = {
4
+ /**
5
+ * Whether the button is disabled.
6
+ */
7
+ isDisabled?: boolean;
8
+ /**
9
+ * Function to be executed when a button is selected.
10
+ * @param id
11
+ */
12
+ onChange?: (id: string) => void;
13
+ /**
14
+ * The buttons that are slidable.
15
+ */
16
+ items: SliderButtonItem[];
17
+ /**
18
+ * The id of a button that should be selected.
19
+ */
20
+ selectedButtonId?: string;
21
+ };
22
+ declare const SliderButton: FC<SliderButtonProps>;
23
+ export default SliderButton;
@@ -0,0 +1,148 @@
1
+ import { AnimatePresence, useAnimate } from 'framer-motion';
2
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
+ import { calculateBiggestWidth } from '../../utils/calculate';
4
+ import { getNearestPoint, getThumbPosition } from '../../utils/sliderButton';
5
+ import { StyledMotionSliderButtonThumb, StyledSliderButton, StyledSliderButtonItem } from './SliderButton.styles';
6
+ const SliderButton = _ref => {
7
+ let {
8
+ selectedButtonId,
9
+ isDisabled,
10
+ items,
11
+ onChange
12
+ } = _ref;
13
+ const [selectedButton, setSelectedButton] = useState(undefined);
14
+ const [dragRange, setDragRange] = useState({
15
+ left: 0,
16
+ right: 0
17
+ });
18
+ const sliderButtonRef = useRef(null);
19
+ const [scope, animate] = useAnimate();
20
+ useEffect(() => {
21
+ if (selectedButtonId) {
22
+ setSelectedButton(selectedButtonId);
23
+ } else {
24
+ setSelectedButton(items[0]?.id);
25
+ }
26
+ }, [items, selectedButtonId]);
27
+ const itemWidth = useMemo(() => calculateBiggestWidth(items), [items]);
28
+ useEffect(() => {
29
+ if (sliderButtonRef.current) {
30
+ setDragRange({
31
+ left: 0,
32
+ right: sliderButtonRef.current.offsetWidth - itemWidth
33
+ });
34
+ }
35
+ }, [itemWidth]);
36
+ const animation = useCallback(async x => {
37
+ await animate(scope.current, {
38
+ x
39
+ }, {
40
+ type: 'tween',
41
+ duration: 0.2
42
+ });
43
+ }, [animate, scope]);
44
+ const handleClick = useCallback((id, index) => {
45
+ if (isDisabled) {
46
+ return;
47
+ }
48
+ setSelectedButton(id);
49
+ if (typeof onChange === 'function') {
50
+ onChange(id);
51
+ }
52
+ void animation(itemWidth * index);
53
+ }, [animation, isDisabled, itemWidth, onChange]);
54
+ const buttons = useMemo(() => {
55
+ const list = [];
56
+ items.forEach((_ref2, index) => {
57
+ let {
58
+ id,
59
+ text
60
+ } = _ref2;
61
+ list.push( /*#__PURE__*/React.createElement(StyledSliderButtonItem, {
62
+ $width: itemWidth,
63
+ key: `slider-button-${id}`,
64
+ onClick: () => handleClick(id, index),
65
+ $isSelected: id === selectedButton
66
+ }, text));
67
+ });
68
+ return list;
69
+ }, [handleClick, itemWidth, items, selectedButton]);
70
+ const thumbText = useMemo(() => {
71
+ const selectedItem = items.find(_ref3 => {
72
+ let {
73
+ id
74
+ } = _ref3;
75
+ return id === selectedButton;
76
+ });
77
+ return selectedItem ? selectedItem.text : '';
78
+ }, [items, selectedButton]);
79
+
80
+ /**
81
+ * Creates an array with the snap points relative to the width of the items
82
+ */
83
+ const snapPoints = useMemo(() => {
84
+ const points = [0];
85
+ for (let i = 1; i < items.length; i++) {
86
+ points.push(itemWidth * i);
87
+ }
88
+ return points;
89
+ }, [itemWidth, items.length]);
90
+ const handleDragEnd = useCallback(() => {
91
+ const position = getThumbPosition({
92
+ scope,
93
+ itemWidth
94
+ });
95
+ if (!position) {
96
+ return;
97
+ }
98
+ const {
99
+ nearestPoint,
100
+ nearestIndex
101
+ } = getNearestPoint({
102
+ snapPoints,
103
+ position
104
+ });
105
+ if (nearestPoint >= 0 && nearestIndex >= 0) {
106
+ void animation(nearestPoint);
107
+ const id = items[nearestIndex]?.id;
108
+ if (typeof onChange === 'function' && id) {
109
+ onChange(id);
110
+ }
111
+ }
112
+ }, [animation, itemWidth, items, onChange, scope, snapPoints]);
113
+ const handleWhileDrag = useCallback(() => {
114
+ const position = getThumbPosition({
115
+ scope,
116
+ itemWidth
117
+ });
118
+ if (!position) {
119
+ return;
120
+ }
121
+ const {
122
+ nearestIndex
123
+ } = getNearestPoint({
124
+ snapPoints,
125
+ position
126
+ });
127
+ if (nearestIndex >= 0) {
128
+ setSelectedButton(items[nearestIndex]?.id);
129
+ }
130
+ }, [itemWidth, items, scope, snapPoints]);
131
+ return useMemo(() => /*#__PURE__*/React.createElement(StyledSliderButton, {
132
+ $isDisabled: isDisabled,
133
+ ref: sliderButtonRef
134
+ }, /*#__PURE__*/React.createElement(AnimatePresence, null, buttons, /*#__PURE__*/React.createElement(StyledMotionSliderButtonThumb, {
135
+ ref: scope,
136
+ drag: isDisabled ? false : 'x',
137
+ dragElastic: 0,
138
+ dragConstraints: {
139
+ ...dragRange
140
+ },
141
+ $width: itemWidth,
142
+ onDrag: handleWhileDrag,
143
+ onDragEnd: handleDragEnd
144
+ }, thumbText))), [buttons, dragRange, handleDragEnd, handleWhileDrag, isDisabled, itemWidth, scope, thumbText]);
145
+ };
146
+ SliderButton.displayName = 'SliderButton';
147
+ export default SliderButton;
148
+ //# sourceMappingURL=SliderButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SliderButton.js","names":["AnimatePresence","useAnimate","React","useCallback","useEffect","useMemo","useRef","useState","calculateBiggestWidth","getNearestPoint","getThumbPosition","StyledMotionSliderButtonThumb","StyledSliderButton","StyledSliderButtonItem","SliderButton","_ref","selectedButtonId","isDisabled","items","onChange","selectedButton","setSelectedButton","undefined","dragRange","setDragRange","left","right","sliderButtonRef","scope","animate","id","itemWidth","current","offsetWidth","animation","x","type","duration","handleClick","index","buttons","list","forEach","_ref2","text","push","createElement","$width","key","onClick","$isSelected","thumbText","selectedItem","find","_ref3","snapPoints","points","i","length","handleDragEnd","position","nearestPoint","nearestIndex","handleWhileDrag","$isDisabled","ref","drag","dragElastic","dragConstraints","onDrag","onDragEnd","displayName"],"sources":["../../../src/components/slider-button/SliderButton.tsx"],"sourcesContent":["import { AnimatePresence, useAnimate } from 'framer-motion';\nimport React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactElement,\n} from 'react';\nimport type { SliderButtonItem } from '../../types/slider-button';\nimport { calculateBiggestWidth } from '../../utils/calculate';\nimport { getNearestPoint, getThumbPosition } from '../../utils/sliderButton';\nimport {\n StyledMotionSliderButtonThumb,\n StyledSliderButton,\n StyledSliderButtonItem,\n} from './SliderButton.styles';\n\nexport type SliderButtonProps = {\n /**\n * Whether the button is disabled.\n */\n isDisabled?: boolean;\n /**\n * Function to be executed when a button is selected.\n * @param id\n */\n onChange?: (id: string) => void;\n /**\n * The buttons that are slidable.\n */\n items: SliderButtonItem[];\n /**\n * The id of a button that should be selected.\n */\n selectedButtonId?: string;\n};\n\nconst SliderButton: FC<SliderButtonProps> = ({ selectedButtonId, isDisabled, items, onChange }) => {\n const [selectedButton, setSelectedButton] = useState<string | undefined>(undefined);\n const [dragRange, setDragRange] = useState({ left: 0, right: 0 });\n\n const sliderButtonRef = useRef<HTMLDivElement>(null);\n\n const [scope, animate] = useAnimate();\n\n useEffect(() => {\n if (selectedButtonId) {\n setSelectedButton(selectedButtonId);\n } else {\n setSelectedButton(items[0]?.id);\n }\n }, [items, selectedButtonId]);\n\n const itemWidth = useMemo(() => calculateBiggestWidth(items), [items]);\n\n useEffect(() => {\n if (sliderButtonRef.current) {\n setDragRange({ left: 0, right: sliderButtonRef.current.offsetWidth - itemWidth });\n }\n }, [itemWidth]);\n\n const animation = useCallback(\n async (x: number) => {\n await animate(\n scope.current,\n { x },\n {\n type: 'tween',\n duration: 0.2,\n },\n );\n },\n [animate, scope],\n );\n\n const handleClick = useCallback(\n (id: string, index: number) => {\n if (isDisabled) {\n return;\n }\n\n setSelectedButton(id);\n\n if (typeof onChange === 'function') {\n onChange(id);\n }\n\n void animation(itemWidth * index);\n },\n [animation, isDisabled, itemWidth, onChange],\n );\n\n const buttons = useMemo(() => {\n const list: ReactElement[] = [];\n\n items.forEach(({ id, text }, index) => {\n list.push(\n <StyledSliderButtonItem\n $width={itemWidth}\n key={`slider-button-${id}`}\n onClick={() => handleClick(id, index)}\n $isSelected={id === selectedButton}\n >\n {text}\n </StyledSliderButtonItem>,\n );\n });\n\n return list;\n }, [handleClick, itemWidth, items, selectedButton]);\n\n const thumbText = useMemo(() => {\n const selectedItem = items.find(({ id }) => id === selectedButton);\n\n return selectedItem ? selectedItem.text : '';\n }, [items, selectedButton]);\n\n /**\n * Creates an array with the snap points relative to the width of the items\n */\n const snapPoints = useMemo(() => {\n const points = [0];\n\n for (let i = 1; i < items.length; i++) {\n points.push(itemWidth * i);\n }\n\n return points;\n }, [itemWidth, items.length]);\n\n const handleDragEnd = useCallback(() => {\n const position = getThumbPosition({ scope, itemWidth });\n\n if (!position) {\n return;\n }\n\n const { nearestPoint, nearestIndex } = getNearestPoint({ snapPoints, position });\n\n if (nearestPoint >= 0 && nearestIndex >= 0) {\n void animation(nearestPoint);\n\n const id = items[nearestIndex]?.id;\n\n if (typeof onChange === 'function' && id) {\n onChange(id);\n }\n }\n }, [animation, itemWidth, items, onChange, scope, snapPoints]);\n\n const handleWhileDrag = useCallback(() => {\n const position = getThumbPosition({ scope, itemWidth });\n\n if (!position) {\n return;\n }\n\n const { nearestIndex } = getNearestPoint({ snapPoints, position });\n\n if (nearestIndex >= 0) {\n setSelectedButton(items[nearestIndex]?.id);\n }\n }, [itemWidth, items, scope, snapPoints]);\n\n return useMemo(\n () => (\n <StyledSliderButton $isDisabled={isDisabled} ref={sliderButtonRef}>\n <AnimatePresence>\n {buttons}\n <StyledMotionSliderButtonThumb\n ref={scope}\n drag={isDisabled ? false : 'x'}\n dragElastic={0}\n dragConstraints={{ ...dragRange }}\n $width={itemWidth}\n onDrag={handleWhileDrag}\n onDragEnd={handleDragEnd}\n >\n {thumbText}\n </StyledMotionSliderButtonThumb>\n </AnimatePresence>\n </StyledSliderButton>\n ),\n [\n buttons,\n dragRange,\n handleDragEnd,\n handleWhileDrag,\n isDisabled,\n itemWidth,\n scope,\n thumbText,\n ],\n );\n};\n\nSliderButton.displayName = 'SliderButton';\n\nexport default SliderBut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