polpo 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. package/.eslintrc.cjs +9 -0
  2. package/.storybook/decorators.tsx +61 -0
  3. package/.storybook/main.ts +47 -0
  4. package/.storybook/manager-head.html +2 -0
  5. package/.storybook/manager.ts +7 -0
  6. package/.storybook/preview-head.html +2 -0
  7. package/.storybook/preview.ts +38 -0
  8. package/.storybook/theme.ts +47 -0
  9. package/.turbo/daemon/f5c5c8fb195b01d0-turbo.log.2024-05-26 +0 -0
  10. package/.turbo/turbo-build$colon$watch.log +96 -0
  11. package/.turbo/turbo-build-storybook.log +0 -0
  12. package/.turbo/turbo-build.log +77 -0
  13. package/.turbo/turbo-lint$colon$fix.log +2 -0
  14. package/.turbo/turbo-lint.log +4 -0
  15. package/README.md +68 -0
  16. package/dist/chunk-M4KRSYE7.js +3 -0
  17. package/dist/chunk-M4KRSYE7.js.map +1 -0
  18. package/dist/chunk-U5XSMSKZ.js +3 -0
  19. package/dist/chunk-U5XSMSKZ.js.map +1 -0
  20. package/dist/get-modal-position-DPftPoU2.d.cts +28 -0
  21. package/dist/get-modal-position-DPftPoU2.d.ts +28 -0
  22. package/dist/helpers.cjs +3 -0
  23. package/dist/helpers.cjs.map +1 -0
  24. package/dist/helpers.d.cts +15 -0
  25. package/dist/helpers.d.ts +15 -0
  26. package/dist/helpers.js +3 -0
  27. package/dist/helpers.js.map +1 -0
  28. package/dist/hooks.cjs +3 -0
  29. package/dist/hooks.cjs.map +1 -0
  30. package/dist/hooks.d.cts +121 -0
  31. package/dist/hooks.d.ts +121 -0
  32. package/dist/hooks.js +3 -0
  33. package/dist/hooks.js.map +1 -0
  34. package/dist/ui.cjs +1987 -0
  35. package/dist/ui.cjs.map +1 -0
  36. package/dist/ui.d.cts +3932 -0
  37. package/dist/ui.d.ts +3932 -0
  38. package/dist/ui.js +1987 -0
  39. package/dist/ui.js.map +1 -0
  40. package/package.json +98 -0
  41. package/src/components/accordion/accordion-item.stories.tsx +128 -0
  42. package/src/components/accordion/accordion-item.tsx +119 -0
  43. package/src/components/accordion/accordion.stories.tsx +74 -0
  44. package/src/components/accordion/accordion.style.ts +42 -0
  45. package/src/components/accordion/accordion.tsx +56 -0
  46. package/src/components/accordion/index.ts +2 -0
  47. package/src/components/buttons/button/button.stories.tsx +103 -0
  48. package/src/components/buttons/button/button.style.ts +147 -0
  49. package/src/components/buttons/button/button.tsx +119 -0
  50. package/src/components/buttons/button/index.ts +1 -0
  51. package/src/components/buttons/index.ts +1 -0
  52. package/src/components/cards/flip-card/flip-card.stories.tsx +61 -0
  53. package/src/components/cards/flip-card/flip-card.style.ts +45 -0
  54. package/src/components/cards/flip-card/flip-card.tsx +55 -0
  55. package/src/components/cards/flip-card/index.ts +1 -0
  56. package/src/components/cards/hover-card/hover-card.stories.tsx +45 -0
  57. package/src/components/cards/hover-card/hover-card.style.ts +13 -0
  58. package/src/components/cards/hover-card/hover-card.tsx +71 -0
  59. package/src/components/cards/hover-card/index.ts +1 -0
  60. package/src/components/cards/index.ts +3 -0
  61. package/src/components/cards/slide-card/index.ts +1 -0
  62. package/src/components/cards/slide-card/slide-card.stories.tsx +47 -0
  63. package/src/components/cards/slide-card/slide-card.tsx +42 -0
  64. package/src/components/form/checkbox/checkbox.stories.tsx +34 -0
  65. package/src/components/form/checkbox/checkbox.style.ts +75 -0
  66. package/src/components/form/checkbox/checkbox.tsx +76 -0
  67. package/src/components/form/checkbox/index.ts +1 -0
  68. package/src/components/form/controller/controller.tsx +42 -0
  69. package/src/components/form/controller/index.ts +1 -0
  70. package/src/components/form/date-picker/date-picker.stories.tsx +38 -0
  71. package/src/components/form/date-picker/date-picker.tsx +67 -0
  72. package/src/components/form/date-picker/index.ts +1 -0
  73. package/src/components/form/field/field.stories.tsx +49 -0
  74. package/src/components/form/field/field.style.ts +79 -0
  75. package/src/components/form/field/field.tsx +83 -0
  76. package/src/components/form/field/field.types.ts +28 -0
  77. package/src/components/form/field/index.ts +2 -0
  78. package/src/components/form/form.stories.types.tsx +50 -0
  79. package/src/components/form/form.types.ts +37 -0
  80. package/src/components/form/index.ts +14 -0
  81. package/src/components/form/input/index.ts +1 -0
  82. package/src/components/form/input/input.stories.tsx +41 -0
  83. package/src/components/form/input/input.tsx +73 -0
  84. package/src/components/form/input-color/index.ts +1 -0
  85. package/src/components/form/input-color/input-color.stories.tsx +46 -0
  86. package/src/components/form/input-color/input-color.style.ts +93 -0
  87. package/src/components/form/input-color/input-color.tsx +159 -0
  88. package/src/components/form/input-file/index.ts +1 -0
  89. package/src/components/form/input-file/input-file.stories.tsx +40 -0
  90. package/src/components/form/input-file/input-file.style.ts +143 -0
  91. package/src/components/form/input-file/input-file.tsx +214 -0
  92. package/src/components/form/input-password/index.ts +1 -0
  93. package/src/components/form/input-password/input-password.stories.tsx +37 -0
  94. package/src/components/form/input-password/input-password.tsx +83 -0
  95. package/src/components/form/radio/index.ts +1 -0
  96. package/src/components/form/radio/radio.stories.tsx +43 -0
  97. package/src/components/form/radio/radio.style.ts +58 -0
  98. package/src/components/form/radio/radio.tsx +76 -0
  99. package/src/components/form/select/index.ts +1 -0
  100. package/src/components/form/select/options.tsx +140 -0
  101. package/src/components/form/select/select-option.tsx +84 -0
  102. package/src/components/form/select/select.stories.tsx +89 -0
  103. package/src/components/form/select/select.style.ts +164 -0
  104. package/src/components/form/select/select.tsx +327 -0
  105. package/src/components/form/select/select.types.ts +93 -0
  106. package/src/components/form/slider/index.ts +1 -0
  107. package/src/components/form/slider/slider.stories.tsx +40 -0
  108. package/src/components/form/slider/slider.style.ts +90 -0
  109. package/src/components/form/slider/slider.tsx +108 -0
  110. package/src/components/form/switch/index.ts +1 -0
  111. package/src/components/form/switch/switch.stories.tsx +38 -0
  112. package/src/components/form/switch/switch.style.ts +120 -0
  113. package/src/components/form/switch/switch.tsx +111 -0
  114. package/src/components/form/textarea/index.ts +1 -0
  115. package/src/components/form/textarea/textarea.stories.tsx +43 -0
  116. package/src/components/form/textarea/textarea.style.ts +7 -0
  117. package/src/components/form/textarea/textarea.tsx +76 -0
  118. package/src/components/icon/icon.stories.tsx +63 -0
  119. package/src/components/icon/icon.tsx +64 -0
  120. package/src/components/icon/icons/index.ts +18 -0
  121. package/src/components/icon/icons/object.tsx +482 -0
  122. package/src/components/icon/icons/social.tsx +72 -0
  123. package/src/components/icon/icons/symbol.tsx +776 -0
  124. package/src/components/icon/index.ts +5 -0
  125. package/src/components/image/image.stories.tsx +25 -0
  126. package/src/components/image/image.tsx +7 -0
  127. package/src/components/image/index.ts +1 -0
  128. package/src/components/index.ts +16 -0
  129. package/src/components/infinity-scroll/index.ts +1 -0
  130. package/src/components/infinity-scroll/infinity-scroll.stories.tsx +75 -0
  131. package/src/components/infinity-scroll/infinity-scroll.style.ts +30 -0
  132. package/src/components/infinity-scroll/infinity-scroll.tsx +56 -0
  133. package/src/components/line/index.ts +1 -0
  134. package/src/components/line/line.stories.tsx +67 -0
  135. package/src/components/line/line.style.ts +57 -0
  136. package/src/components/line/line.tsx +76 -0
  137. package/src/components/loaders/index.ts +1 -0
  138. package/src/components/loaders/simple-loader/index.ts +1 -0
  139. package/src/components/loaders/simple-loader/simple-loader.stories.tsx +21 -0
  140. package/src/components/loaders/simple-loader/simple-loader.style.ts +13 -0
  141. package/src/components/loaders/simple-loader/simple-loader.tsx +15 -0
  142. package/src/components/modals/action-modal/action-modal.stories.tsx +134 -0
  143. package/src/components/modals/action-modal/action-modal.style.ts +129 -0
  144. package/src/components/modals/action-modal/action-modal.tsx +150 -0
  145. package/src/components/modals/action-modal/index.ts +1 -0
  146. package/src/components/modals/aside-modal/aside-modal.stories.tsx +82 -0
  147. package/src/components/modals/aside-modal/aside-modal.style.ts +108 -0
  148. package/src/components/modals/aside-modal/aside-modal.tsx +66 -0
  149. package/src/components/modals/aside-modal/index.ts +1 -0
  150. package/src/components/modals/confirmation-modal/confirmation-modal.stories.tsx +50 -0
  151. package/src/components/modals/confirmation-modal/confirmation-modal.style.ts +17 -0
  152. package/src/components/modals/confirmation-modal/confirmation-modal.tsx +43 -0
  153. package/src/components/modals/confirmation-modal/index.ts +1 -0
  154. package/src/components/modals/index.ts +4 -0
  155. package/src/components/modals/modal/index.ts +1 -0
  156. package/src/components/modals/modal/modal.style.ts +10 -0
  157. package/src/components/modals/modal/modal.tsx +132 -0
  158. package/src/components/ripple/index.ts +1 -0
  159. package/src/components/ripple/ripple.stories.tsx +38 -0
  160. package/src/components/ripple/ripple.style.ts +33 -0
  161. package/src/components/ripple/ripple.tsx +63 -0
  162. package/src/components/smart-table/index.ts +1 -0
  163. package/src/components/smart-table/smart-table.column.tsx +63 -0
  164. package/src/components/smart-table/smart-table.helpers.tsx +59 -0
  165. package/src/components/smart-table/smart-table.hooks.ts +27 -0
  166. package/src/components/smart-table/smart-table.row.tsx +29 -0
  167. package/src/components/smart-table/smart-table.stories.tsx +301 -0
  168. package/src/components/smart-table/smart-table.style.ts +102 -0
  169. package/src/components/smart-table/smart-table.tsx +112 -0
  170. package/src/components/smart-table/smart-table.types.ts +41 -0
  171. package/src/components/tabs/index.ts +1 -0
  172. package/src/components/tabs/tabs-container.stories.tsx +159 -0
  173. package/src/components/tabs/tabs-list.tsx +131 -0
  174. package/src/components/tabs/tabs.stories.tsx +68 -0
  175. package/src/components/tabs/tabs.style.ts +132 -0
  176. package/src/components/tabs/tabs.tsx +117 -0
  177. package/src/components/tag/index.ts +1 -0
  178. package/src/components/tag/tag.stories.tsx +49 -0
  179. package/src/components/tag/tag.style.ts +24 -0
  180. package/src/components/tag/tag.tsx +44 -0
  181. package/src/components/tooltips/click-to-copy/click-to-copy.stories.tsx +39 -0
  182. package/src/components/tooltips/click-to-copy/click-to-copy.tsx +41 -0
  183. package/src/components/tooltips/click-to-copy/index.ts +1 -0
  184. package/src/components/tooltips/index.ts +2 -0
  185. package/src/components/tooltips/tooltip/index.ts +1 -0
  186. package/src/components/tooltips/tooltip/tooltip.stories.tsx +35 -0
  187. package/src/components/tooltips/tooltip/tooltip.style.ts +62 -0
  188. package/src/components/tooltips/tooltip/tooltip.tsx +45 -0
  189. package/src/components/typography/index.ts +2 -0
  190. package/src/components/typography/typography.constants.ts +43 -0
  191. package/src/components/typography/typography.stories.tsx +106 -0
  192. package/src/components/typography/typography.style.ts +76 -0
  193. package/src/components/typography/typography.tsx +79 -0
  194. package/src/contexts/fetch-context/fetch-context.tsx +114 -0
  195. package/src/contexts/fetch-context/index.ts +1 -0
  196. package/src/contexts/form-context/form-context.tsx +43 -0
  197. package/src/contexts/form-context/index.ts +1 -0
  198. package/src/contexts/index.ts +3 -0
  199. package/src/contexts/theme-context/index.ts +3 -0
  200. package/src/contexts/theme-context/theme-context.tsx +158 -0
  201. package/src/contexts/theme-context/theme.animations.ts +180 -0
  202. package/src/contexts/theme-context/theme.defaults.ts +205 -0
  203. package/src/contexts/theme-context/theme.style.ts +78 -0
  204. package/src/contexts/theme-context/themes.ts +96 -0
  205. package/src/core/http-client.d.ts +11 -0
  206. package/src/core/http-client.d.ts.map +1 -0
  207. package/src/core/http-client.ts +47 -0
  208. package/src/core/index.d.ts +2 -0
  209. package/src/core/index.d.ts.map +1 -0
  210. package/src/core/index.ts +1 -0
  211. package/src/core/variants/color.ts +36 -0
  212. package/src/core/variants/index.ts +3 -0
  213. package/src/core/variants/radius.ts +56 -0
  214. package/src/core/variants/size.ts +44 -0
  215. package/src/helpers/format-bytes.ts +11 -0
  216. package/src/helpers/format-dates.ts +11 -0
  217. package/src/helpers/get-modal-position.ts +66 -0
  218. package/src/helpers/index.ts +4 -0
  219. package/src/helpers/text/index.ts +1 -0
  220. package/src/helpers/text/to-capitalize.ts +17 -0
  221. package/src/hooks/index.ts +23 -0
  222. package/src/hooks/use-async.ts +88 -0
  223. package/src/hooks/use-classnames.ts +13 -0
  224. package/src/hooks/use-constant.ts +3 -0
  225. package/src/hooks/use-debounce.ts +15 -0
  226. package/src/hooks/use-dimensions.ts +22 -0
  227. package/src/hooks/use-event-listener.ts +71 -0
  228. package/src/hooks/use-file-reader.ts +69 -0
  229. package/src/hooks/use-hover.ts +17 -0
  230. package/src/hooks/use-in-view.ts +20 -0
  231. package/src/hooks/use-input-handlers.ts +49 -0
  232. package/src/hooks/use-media-query.ts +25 -0
  233. package/src/hooks/use-modal-in-container.ts +94 -0
  234. package/src/hooks/use-mouse-position.ts +16 -0
  235. package/src/hooks/use-observer.ts +18 -0
  236. package/src/hooks/use-on-click-outside-ref.ts +17 -0
  237. package/src/hooks/use-online-status.ts +12 -0
  238. package/src/hooks/use-render-count.ts +11 -0
  239. package/src/hooks/use-safe-dispatch.ts +22 -0
  240. package/src/hooks/use-scroll.ts +31 -0
  241. package/src/hooks/use-state-history.ts +22 -0
  242. package/src/hooks/use-toggle-values.ts +14 -0
  243. package/src/hooks/use-toggle.ts +11 -0
  244. package/src/hooks/use-viewport.ts +38 -0
  245. package/src/index.ts +5 -0
  246. package/src/layouts/flex/flex.tsx +75 -0
  247. package/src/layouts/flex/index.ts +1 -0
  248. package/src/layouts/grid/grid.tsx +86 -0
  249. package/src/layouts/grid/index.ts +1 -0
  250. package/src/layouts/index.ts +3 -0
  251. package/src/layouts/section-layout/index.ts +1 -0
  252. package/src/layouts/section-layout/section-layout.stories.tsx +55 -0
  253. package/src/layouts/section-layout/section-layout.style.ts +21 -0
  254. package/src/layouts/section-layout/section-layout.tsx +46 -0
  255. package/src/stories/GettingStarted.mdx +66 -0
  256. package/src/types/generics.ts +68 -0
  257. package/src/types/index.ts +1 -0
  258. package/svg/Name=airplane, Category=object.svg +3 -0
  259. package/svg/Name=arrow-circle, Category=symbol.svg +3 -0
  260. package/svg/Name=arrow-down, Category=symbol.svg +3 -0
  261. package/svg/Name=arrow-left, Category=symbol.svg +3 -0
  262. package/svg/Name=arrow-right, Category=symbol.svg +3 -0
  263. package/svg/Name=arrow-up, Category=symbol.svg +3 -0
  264. package/svg/Name=bell, Category=object.svg +3 -0
  265. package/svg/Name=bicycle, Category=object.svg +3 -0
  266. package/svg/Name=book-open, Category=object.svg +3 -0
  267. package/svg/Name=book-solid, Category=object.svg +6 -0
  268. package/svg/Name=box-shadow, Category=symbol.svg +5 -0
  269. package/svg/Name=calendar, Category=object.svg +3 -0
  270. package/svg/Name=camera, Category=object.svg +3 -0
  271. package/svg/Name=caret-down, Category=symbol.svg +3 -0
  272. package/svg/Name=caret-left, Category=symbol.svg +3 -0
  273. package/svg/Name=caret-right, Category=symbol.svg +3 -0
  274. package/svg/Name=caret-up, Category=symbol.svg +3 -0
  275. package/svg/Name=checkmark, Category=symbol.svg +3 -0
  276. package/svg/Name=clean-computer, Category=object.svg +10 -0
  277. package/svg/Name=codepen, Category=social.svg +3 -0
  278. package/svg/Name=creative, Category=symbol.svg +5 -0
  279. package/svg/Name=cross, Category=symbol.svg +4 -0
  280. package/svg/Name=crossed-flags, Category=object.svg +4 -0
  281. package/svg/Name=cv, Category=symbol.svg +5 -0
  282. package/svg/Name=design-ui, Category=symbol.svg +9 -0
  283. package/svg/Name=document, Category=object.svg +3 -0
  284. package/svg/Name=door-closed, Category=object.svg +3 -0
  285. package/svg/Name=door-open, Category=object.svg +3 -0
  286. package/svg/Name=double-caret-down, Category=symbol.svg +4 -0
  287. package/svg/Name=double-caret-left, Category=symbol.svg +4 -0
  288. package/svg/Name=double-caret-righ, Category=symbol.svg +4 -0
  289. package/svg/Name=double-caret-up, Category=symbol.svg +4 -0
  290. package/svg/Name=download, Category=symbol.svg +5 -0
  291. package/svg/Name=dropper, Category=object.svg +5 -0
  292. package/svg/Name=envelope, Category=object.svg +3 -0
  293. package/svg/Name=exclamation-close, Category=symbol.svg +4 -0
  294. package/svg/Name=exclamation-open, Category=symbol.svg +4 -0
  295. package/svg/Name=external-link, Category=symbol.svg +3 -0
  296. package/svg/Name=eye, Category=object.svg +4 -0
  297. package/svg/Name=eye-hidden, Category=object.svg +7 -0
  298. package/svg/Name=facebook, Category=social.svg +3 -0
  299. package/svg/Name=form, Category=symbol.svg +8 -0
  300. package/svg/Name=game-control, Category=object.svg +3 -0
  301. package/svg/Name=gear, Category=object.svg +3 -0
  302. package/svg/Name=github, Category=social.svg +3 -0
  303. package/svg/Name=house, Category=object.svg +3 -0
  304. package/svg/Name=hyphen, Category=symbol.svg +3 -0
  305. package/svg/Name=info, Category=symbol.svg +3 -0
  306. package/svg/Name=instagram, Category=social.svg +3 -0
  307. package/svg/Name=link, Category=symbol.svg +5 -0
  308. package/svg/Name=linkedin, Category=social.svg +3 -0
  309. package/svg/Name=magnifying-glass, Category=object.svg +3 -0
  310. package/svg/Name=message, Category=symbol.svg +4 -0
  311. package/svg/Name=moon, Category=object.svg +5 -0
  312. package/svg/Name=order-list, Category=symbol.svg +7 -0
  313. package/svg/Name=pencil, Category=object.svg +3 -0
  314. package/svg/Name=pin-location, Category=symbol.svg +3 -0
  315. package/svg/Name=question-mark-close, Category=symbol.svg +3 -0
  316. package/svg/Name=question-mark-open, Category=symbol.svg +3 -0
  317. package/svg/Name=share, Category=symbol.svg +5 -0
  318. package/svg/Name=spinner, Category=symbol.svg +9 -0
  319. package/svg/Name=star, Category=object.svg +3 -0
  320. package/svg/Name=star-empty, Category=object.svg +3 -0
  321. package/svg/Name=sun, Category=object.svg +11 -0
  322. package/svg/Name=text-shadow, Category=symbol.svg +4 -0
  323. package/svg/Name=thinking, Category=symbol.svg +3 -0
  324. package/svg/Name=trash-can, Category=object.svg +4 -0
  325. package/svg/Name=upload, Category=symbol.svg +5 -0
  326. package/svg/Name=user, Category=symbol.svg +4 -0
  327. package/svg/Name=warning, Category=symbol.svg +5 -0
  328. package/svg/Name=whatsapp, Category=social.svg +3 -0
  329. package/svgconfig.json +4 -0
  330. package/tsconfig.json +14 -0
  331. package/tsup.config.cjs +21 -0
  332. package/vite.config.ts +13 -0
@@ -0,0 +1,214 @@
1
+ import { useEffect, useMemo, useState } from 'react';
2
+
3
+ import { Grid } from '../../../layouts';
4
+ import { Icon, IconNameT } from '../../icon';
5
+ import { Typography } from '../../typography';
6
+ import { Controller } from '../controller';
7
+ import { ControllerGeneratorProps, UnControlledComponentProps } from '../form.types';
8
+
9
+ import { FileCardStyle, InputFileContainerStyle } from './input-file.style';
10
+
11
+ import { formatBytes } from '@polpo/helpers';
12
+ import { FileTypeEnum, useInputHandlers } from '@polpo/hooks';
13
+
14
+ type InputFileProps = {
15
+ label?: string;
16
+ accept?: string;
17
+ multiple?: boolean;
18
+ limitSize?: number;
19
+ errorTimeout?: number;
20
+ };
21
+
22
+ type InputFileValue = { [key: string]: File };
23
+
24
+ export const InputFile = ({
25
+ name,
26
+ value = {},
27
+ setValue,
28
+ onBlur,
29
+ onFocus,
30
+ className = '',
31
+ style = {},
32
+ autoFocus = false,
33
+ readOnly = false,
34
+ disabled = false,
35
+ placeholder = 'Click to upload or drag and drop',
36
+ autoComplete = 'off',
37
+ accept,
38
+ multiple = false,
39
+ limitSize = 5000000,
40
+ errorTimeout = 3000,
41
+ label,
42
+ /*
43
+ * isDirty = false,
44
+ * isTouched = false,
45
+ * invalid = false,
46
+ * error,
47
+ */
48
+ }: UnControlledComponentProps<InputFileProps, InputFileValue>) => {
49
+ const [error, setError] = useState<string | null>(null);
50
+ const id = useMemo(() => crypto.randomUUID(), []);
51
+ const { handlers } = useInputHandlers<HTMLInputElement>({
52
+ onBlur,
53
+ onFocus,
54
+ onChange: e => {
55
+ const { files } = e.target;
56
+ files && saveFiles(files);
57
+ },
58
+ });
59
+
60
+ useEffect(() => {
61
+ let intervalId: ReturnType<typeof setTimeout> | null = null;
62
+
63
+ if (error !== null) {
64
+ intervalId = setTimeout(() => {
65
+ setError(null);
66
+ }, errorTimeout);
67
+ }
68
+
69
+ return () => {
70
+ if (intervalId !== null) {
71
+ clearTimeout(intervalId);
72
+ }
73
+ };
74
+ }, [error, errorTimeout]);
75
+
76
+ const saveFiles = (files: FileList) => {
77
+ const finalFiles = multiple ? { ...value } : {};
78
+
79
+ const filesToCheck = multiple ? files.length : 1;
80
+
81
+ for (let i = 0; i < filesToCheck; i++) {
82
+ const file = files.item(i);
83
+
84
+ if (!file) {
85
+ continue;
86
+ }
87
+
88
+ if (file.size < limitSize) {
89
+ finalFiles[file.name] = file;
90
+ } else {
91
+ setError(`File '${file.name}' size is larger than ${formatBytes(limitSize)}`);
92
+ }
93
+ }
94
+
95
+ setValue(finalFiles);
96
+ };
97
+
98
+ const handleDrop = (e: React.DragEvent<HTMLInputElement>) => {
99
+ e.preventDefault();
100
+ e.stopPropagation();
101
+
102
+ if (e.dataTransfer.files && e.dataTransfer.files.length) {
103
+ saveFiles(e.dataTransfer.files);
104
+ }
105
+ };
106
+
107
+ const getIconType = (type: FileTypeEnum): IconNameT => {
108
+ const iconTypes: Record<FileTypeEnum, IconNameT> = {
109
+ [FileTypeEnum.PNG]: 'download',
110
+ [FileTypeEnum.PDF]: 'download',
111
+ };
112
+
113
+ return iconTypes[type] ?? 'warning';
114
+ };
115
+
116
+ const deleteFile = (file: File) => {
117
+ const prevValue = { ...value };
118
+ delete prevValue[file.name];
119
+ setValue(prevValue);
120
+ };
121
+
122
+ const deleteAll = () => {
123
+ setValue({});
124
+ };
125
+
126
+ const totalSize = useMemo(() => Object.values(value).reduce((prev, { size }) => prev + size, 0), [value]);
127
+
128
+ const renderFileToCard = (file: File, key: number) => (
129
+ <FileCardStyle key={key}>
130
+ <section className='file-card--image'>
131
+ <Icon name={getIconType(file.type as FileTypeEnum)} />
132
+ </section>
133
+ <Grid>
134
+ <Typography variant='label' noPadding nowrap>
135
+ {file.name}
136
+ </Typography>
137
+ <Typography noPadding variant='small'>
138
+ {formatBytes(file.size)}
139
+ </Typography>
140
+ </Grid>
141
+ <section className='file-card--delete' onClick={() => deleteFile(file)}>
142
+ <Icon name='trash-can' />
143
+ </section>
144
+ </FileCardStyle>
145
+ );
146
+
147
+ return (
148
+ <InputFileContainerStyle>
149
+ {Boolean(label) && (
150
+ <Typography variant='label-form' htmlFor={id} noPadding>
151
+ {label}
152
+ </Typography>
153
+ )}
154
+ <section className='input-file--box' onDrop={handleDrop}>
155
+ <section className='input-file--box--icon'>
156
+ <Icon name='magnifying-glass' />
157
+ </section>
158
+ <Grid>
159
+ <Typography variant='label-form' htmlFor={id} noPadding weight='bold'>
160
+ {placeholder}
161
+ </Typography>
162
+ <Typography variant='small' noPadding>
163
+ Max size ({formatBytes(limitSize)})
164
+ </Typography>
165
+ </Grid>
166
+ <input
167
+ id={id}
168
+ type='file'
169
+ name={name}
170
+ value=''
171
+ placeholder={placeholder}
172
+ readOnly={readOnly}
173
+ autoFocus={autoFocus}
174
+ disabled={disabled}
175
+ autoComplete={autoComplete}
176
+ className={className}
177
+ style={style}
178
+ accept={accept}
179
+ multiple={multiple}
180
+ title=''
181
+ {...handlers}
182
+ />
183
+ </section>
184
+ {error !== null && (
185
+ <Typography variant='small' noPadding className='error'>
186
+ {error}
187
+ </Typography>
188
+ )}
189
+ {Object.keys(value).length > 0 && (
190
+ <>
191
+ {multiple && (
192
+ <span className='total-info'>
193
+ <Typography variant='small' noPadding>
194
+ {Object.keys(value).length} files - {formatBytes(totalSize)}
195
+ </Typography>
196
+ <span className='total-info--delete' onClick={deleteAll}>
197
+ <Icon name='trash-can' />
198
+ </span>
199
+ </span>
200
+ )}
201
+ <section className='input-file--files'>
202
+ <section className='input-file--files--content'>{Object.values(value).map(renderFileToCard)}</section>
203
+ </section>
204
+ </>
205
+ )}
206
+ </InputFileContainerStyle>
207
+ );
208
+ };
209
+
210
+ const InputFileController = ({ rules, ...props }: ControllerGeneratorProps<InputFileProps, InputFileValue>) => {
211
+ return <Controller Component={InputFile} defaultValue={{}} inputProps={props} rules={rules} />;
212
+ };
213
+
214
+ InputFile.Controller = InputFileController;
@@ -0,0 +1 @@
1
+ export * from './input-password';
@@ -0,0 +1,37 @@
1
+ import { useState } from 'react';
2
+
3
+ import { FieldSharedArgs, FieldSharedArgTypes } from '../field/field.stories';
4
+ import { ContainerDecorator, UnControlledComponentArgTypes } from '../form.stories.types';
5
+
6
+ import { InputPassword } from './input-password';
7
+
8
+ import type { Meta, StoryObj } from '@storybook/react';
9
+
10
+ const meta: Meta<typeof InputPassword> = {
11
+ title: 'Form/InputPassword',
12
+ component: InputPassword,
13
+ argTypes: {
14
+ ...FieldSharedArgTypes,
15
+ ...UnControlledComponentArgTypes,
16
+ rightIcon: { table: { disable: true } },
17
+ },
18
+ args: {
19
+ label: 'Password',
20
+ placeholder: 'Password',
21
+ ...FieldSharedArgs,
22
+ rightIcon: undefined,
23
+ },
24
+ decorators: [ContainerDecorator],
25
+ render: args => {
26
+ const [value, setValue] = useState('');
27
+
28
+ return <InputPassword {...args} value={value} setValue={setValue} />;
29
+ },
30
+ };
31
+
32
+ export default meta;
33
+ type Story = StoryObj<typeof InputPassword>;
34
+
35
+ export const Default: Story = {
36
+ args: {},
37
+ };
@@ -0,0 +1,83 @@
1
+ import { useMemo } from 'react';
2
+
3
+ import { Controller, InputFieldProps } from '..';
4
+ import { IconNameT } from '../../icon';
5
+ import { Field } from '../field';
6
+ import { ControllerGeneratorProps, UnControlledComponentProps } from '../form.types';
7
+
8
+ import { useInputHandlers, useToggleValues } from '@polpo/hooks';
9
+
10
+ type InputPasswordProps = InputFieldProps<{
11
+ rightIcon?: never;
12
+ }>;
13
+
14
+ export const InputPassword = ({
15
+ name,
16
+ value,
17
+ setValue,
18
+ onBlur,
19
+ onFocus,
20
+ className = '',
21
+ style = {},
22
+ autoFocus = false,
23
+ readOnly = false,
24
+ disabled = false,
25
+ placeholder = '',
26
+ autoComplete = 'off',
27
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28
+ isDirty = false,
29
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
+ isTouched = false,
31
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
+ invalid = false,
33
+ error,
34
+ ...fieldProps
35
+ }: UnControlledComponentProps<InputPasswordProps, string>) => {
36
+ const id = useMemo(() => crypto.randomUUID(), []);
37
+ const [type, toggle] = useToggleValues<'password' | 'text'>(['password', 'text']);
38
+ const { isFocus, handlers } = useInputHandlers({
39
+ onBlur: onBlur,
40
+ onChange: e => setValue(e.target.value),
41
+ onFocus: onFocus,
42
+ });
43
+
44
+ const iconName = useMemo<IconNameT>(() => {
45
+ if (type === 'password') return 'eye' as IconNameT;
46
+
47
+ if (type === 'text') return 'eye-hidden' as IconNameT;
48
+
49
+ return 'warning' as IconNameT;
50
+ }, [type]);
51
+
52
+ return (
53
+ <Field
54
+ id={id}
55
+ error={error}
56
+ isFocus={isFocus}
57
+ {...fieldProps}
58
+ rightIcon={iconName}
59
+ onClickRightIcon={() => toggle()}
60
+ >
61
+ <input
62
+ id={id}
63
+ type={type}
64
+ name={name}
65
+ className={className}
66
+ style={style}
67
+ value={value}
68
+ autoFocus={autoFocus}
69
+ autoComplete={autoComplete}
70
+ placeholder={placeholder}
71
+ disabled={disabled}
72
+ readOnly={readOnly}
73
+ {...handlers}
74
+ />
75
+ </Field>
76
+ );
77
+ };
78
+
79
+ const InputPasswordController = ({ rules, ...props }: ControllerGeneratorProps<InputPasswordProps, string>) => {
80
+ return <Controller Component={InputPassword} defaultValue='' inputProps={props} rules={rules} />;
81
+ };
82
+
83
+ InputPassword.Controller = InputPasswordController;
@@ -0,0 +1 @@
1
+ export * from './radio';
@@ -0,0 +1,43 @@
1
+ import { useState } from 'react';
2
+
3
+ import { Grid } from '../../../layouts';
4
+ import { UnControlledComponentArgTypes } from '../form.stories.types';
5
+
6
+ import { Radio } from './radio';
7
+
8
+ import type { Meta, StoryObj } from '@storybook/react';
9
+
10
+ const meta: Meta<typeof Radio> = {
11
+ title: 'Form/Radio',
12
+ component: Radio,
13
+ argTypes: {
14
+ ...UnControlledComponentArgTypes,
15
+ label: { control: 'text' },
16
+ radioValue: { control: false },
17
+ placeholder: { table: { disable: true } },
18
+ },
19
+ args: {
20
+ label: 'Option A',
21
+ placeholder: undefined,
22
+ },
23
+ render: args => {
24
+ const [value, setValue] = useState('A');
25
+
26
+ return (
27
+ <Grid gap='0.4em'>
28
+ <Radio {...args} name='radio' value={value} radioValue='A' setValue={setValue} />
29
+ <Radio name='radio' value={value} label='Option B' radioValue='B' setValue={setValue} />
30
+ <Radio name='radio' value={value} label='Option C' radioValue='C' setValue={setValue} />
31
+ <Radio name='radio' value={value} label='Option D' radioValue='D' setValue={setValue} />
32
+ <Radio name='radio' value={value} label='Option E' radioValue='E' setValue={setValue} />
33
+ </Grid>
34
+ );
35
+ },
36
+ };
37
+
38
+ export default meta;
39
+ type Story = StoryObj<typeof Radio>;
40
+
41
+ export const Default: Story = {
42
+ args: {},
43
+ };
@@ -0,0 +1,58 @@
1
+ import styled from 'styled-components';
2
+
3
+ export const RadioStyle = styled.section`
4
+ border-radius: 50%;
5
+ background: ${props => props.theme.colors.gray9};
6
+ color: ${props => props.theme.colors.gray6};
7
+ border: 2px solid;
8
+ transition: all 300ms ease;
9
+ position: relative;
10
+ padding: 2px;
11
+
12
+ .radio-dot {
13
+ width: 1em;
14
+ height: 1em;
15
+ border-radius: 50%;
16
+ display: block;
17
+ opacity: 0;
18
+ transition: opacity 300ms ease;
19
+ background: ${props => props.theme.colors.primary.main};
20
+ }
21
+
22
+ &.is-checked {
23
+ background: ${props => props.theme.colors.primary.contrast};
24
+ color: ${props => props.theme.colors.primary.main};
25
+
26
+ .radio-dot {
27
+ opacity: 1;
28
+ }
29
+ }
30
+
31
+ .radio-input {
32
+ position: absolute;
33
+ top: 0;
34
+ left: 0;
35
+ width: 100%;
36
+ height: 100%;
37
+ cursor: pointer;
38
+ opacity: 0;
39
+ z-index: 1;
40
+ }
41
+ `;
42
+
43
+ export const RadioContainerStyle = styled.section`
44
+ display: flex;
45
+ align-items: center;
46
+ gap: 1em;
47
+ width: fit-content;
48
+
49
+ .radio-label {
50
+ cursor: pointer;
51
+ user-select: none;
52
+ }
53
+
54
+ ${RadioStyle}:hover,
55
+ &:has(.radio-label:hover) ${RadioStyle} {
56
+ box-shadow: 0 0 0 0.4em ${props => props.theme.colors.primary.main}88;
57
+ }
58
+ `;
@@ -0,0 +1,76 @@
1
+ import { useMemo } from 'react';
2
+
3
+ import { Typography } from '../../typography';
4
+ import { Controller } from '../controller';
5
+ import { ControllerGeneratorProps, UnControlledComponentProps } from '../form.types';
6
+
7
+ import { RadioContainerStyle, RadioStyle } from './radio.style';
8
+
9
+ import { useInputHandlers } from '@polpo/hooks';
10
+
11
+ type RadioProps = {
12
+ label?: string;
13
+ radioValue: string;
14
+ placeholder?: never;
15
+ };
16
+
17
+ export const Radio = ({
18
+ name,
19
+ value,
20
+ setValue,
21
+ onBlur,
22
+ onFocus,
23
+ className = '',
24
+ style = {},
25
+ autoFocus = false,
26
+ readOnly = false,
27
+ disabled = false,
28
+ autoComplete = 'off',
29
+ radioValue,
30
+ label,
31
+ /*
32
+ * isDirty = false,
33
+ * isTouched = false,
34
+ * invalid = false,
35
+ * error,
36
+ */
37
+ }: UnControlledComponentProps<RadioProps, string>) => {
38
+ const id = useMemo(() => crypto.randomUUID(), []);
39
+ const { handlers } = useInputHandlers({
40
+ onChange: e => setValue(e.target.value),
41
+ onBlur: onBlur,
42
+ onFocus: onFocus,
43
+ });
44
+
45
+ return (
46
+ <RadioContainerStyle className={className} style={style}>
47
+ <RadioStyle className={radioValue === value ? 'is-checked' : ''}>
48
+ <span className='radio-dot' />
49
+ <input
50
+ id={id}
51
+ type='radio'
52
+ name={name}
53
+ className={`radio-input ${className}`}
54
+ style={style}
55
+ value={radioValue}
56
+ checked={radioValue === value}
57
+ autoFocus={autoFocus}
58
+ autoComplete={autoComplete}
59
+ disabled={disabled || readOnly}
60
+ {...handlers}
61
+ />
62
+ </RadioStyle>
63
+ {label ? (
64
+ <Typography variant='label-form' htmlFor={id} className='radio-label'>
65
+ {label}
66
+ </Typography>
67
+ ) : null}
68
+ </RadioContainerStyle>
69
+ );
70
+ };
71
+
72
+ const RadioController = ({ rules, ...props }: ControllerGeneratorProps<RadioProps, string>) => {
73
+ return <Controller Component={Radio} defaultValue='' inputProps={props} rules={rules} />;
74
+ };
75
+
76
+ Radio.Controller = RadioController;
@@ -0,0 +1 @@
1
+ export * from './select';
@@ -0,0 +1,140 @@
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { useTheme } from 'styled-components';
3
+
4
+ import { InfinityScroll } from '../../infinity-scroll';
5
+ import { Modal } from '../../modals';
6
+ import { Typography } from '../../typography';
7
+
8
+ import { SelectOption } from './select-option';
9
+ import { OptionsHeaderStyle, OptionsStyle } from './select.style';
10
+ import { OptionsProps, SelectItem } from './select.types';
11
+
12
+ import { useEventListener, useMediaQuery } from '@polpo/hooks';
13
+
14
+ export const Options = <T extends SelectItem>({
15
+ onSearchQuery,
16
+ searchQueryValue,
17
+ value,
18
+ compareValueOrValuesAreEqual,
19
+ searchQueryPlaceholder = 'Search option',
20
+ multiselect = false,
21
+ selectOption,
22
+ unselectOption,
23
+ isOpen,
24
+ style,
25
+ options,
26
+ loadMore = () => null,
27
+ isLoading = false,
28
+ hasNextPage = false,
29
+ modalRef,
30
+ Component,
31
+ variant,
32
+ }: OptionsProps<T>) => {
33
+ const theme = useTheme();
34
+ const isMobile = useMediaQuery(`(min-width: ${theme.constants.breakpoints.mobileL})`);
35
+ const [internalSearchQuery, setInternalSearchQuery] = useState('');
36
+ const searchInputRef = useRef<HTMLInputElement>(null);
37
+
38
+ const handleSearchQuery = useCallback(
39
+ (e: React.ChangeEvent<HTMLInputElement>) => {
40
+ const { value } = e.target;
41
+ onSearchQuery && onSearchQuery(value);
42
+ setInternalSearchQuery(value);
43
+ },
44
+ [onSearchQuery],
45
+ );
46
+
47
+ useEventListener('keydown', e => {
48
+ if (['ArrowDown', 'ArrowUp'].includes(e.code)) {
49
+ e.preventDefault();
50
+ const focusedItem = document.activeElement;
51
+ const isListItem = focusedItem?.tagName === 'LI';
52
+
53
+ if (isOpen && isListItem) {
54
+ switch (e.code) {
55
+ case 'ArrowDown':
56
+ (focusedItem?.nextSibling as HTMLElement)?.focus();
57
+
58
+ break;
59
+ case 'ArrowUp':
60
+ (focusedItem?.previousElementSibling as HTMLElement)?.focus();
61
+
62
+ break;
63
+ }
64
+ }
65
+ }
66
+ });
67
+
68
+ useEffect(() => {
69
+ if (isOpen) {
70
+ if (searchInputRef.current) {
71
+ searchInputRef.current.focus();
72
+ } else {
73
+ modalRef.current?.focus();
74
+ }
75
+ }
76
+ }, [isOpen, modalRef]);
77
+
78
+ const renderInternalOption = useCallback(
79
+ (option: T, key: number) => (
80
+ <SelectOption
81
+ key={key}
82
+ id={`${key}`}
83
+ selected={!!value && value !== '' && compareValueOrValuesAreEqual(option, value)}
84
+ data={option}
85
+ multiselect={multiselect}
86
+ unselectOption={unselectOption}
87
+ selectOption={selectOption}
88
+ Component={Component}
89
+ variant={variant}
90
+ />
91
+ ),
92
+ [value, compareValueOrValuesAreEqual, multiselect, unselectOption, selectOption, Component, variant],
93
+ );
94
+
95
+ return (
96
+ <Modal
97
+ isOpen={isOpen}
98
+ id='form-select'
99
+ backdrop={isMobile ? 'transparent' : 'blur'}
100
+ opacity={isMobile ? 0 : 0.8}
101
+ zIndex={150}
102
+ >
103
+ <OptionsStyle ref={modalRef} style={{ ...style, zIndex: 150 }} tabIndex={-1}>
104
+ {onSearchQuery && (
105
+ <OptionsHeaderStyle>
106
+ <input
107
+ name='query'
108
+ className='input-search'
109
+ value={searchQueryValue ?? internalSearchQuery}
110
+ onChange={handleSearchQuery}
111
+ placeholder={searchQueryPlaceholder}
112
+ onClick={e => e.stopPropagation()}
113
+ ref={searchInputRef}
114
+ autoFocus
115
+ />
116
+ </OptionsHeaderStyle>
117
+ )}
118
+ <section className='options-list-container' tabIndex={-1}>
119
+ <ul className='options-list' role='listbox'>
120
+ {options.length === 0 ? (
121
+ <li className='option option-empty' tabIndex={-1}>
122
+ <Typography noPadding variant='label'>
123
+ No options to select
124
+ </Typography>
125
+ </li>
126
+ ) : (
127
+ <InfinityScroll
128
+ isLoading={isLoading}
129
+ hasNextPage={hasNextPage}
130
+ loadMore={loadMore}
131
+ data={options}
132
+ renderItem={renderInternalOption}
133
+ />
134
+ )}
135
+ </ul>
136
+ </section>
137
+ </OptionsStyle>
138
+ </Modal>
139
+ );
140
+ };