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,41 @@
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 { Input } from './input';
7
+
8
+ import type { Meta, StoryObj } from '@storybook/react';
9
+
10
+ const meta: Meta<typeof Input> = {
11
+ title: 'Form/Input',
12
+ component: Input,
13
+ argTypes: {
14
+ ...FieldSharedArgTypes,
15
+ ...UnControlledComponentArgTypes,
16
+ type: { control: 'select', options: ['email', 'number', 'search', 'tel', 'text', 'url'] },
17
+ min: { control: { type: 'range' }, if: { arg: 'type', eq: 'number' } },
18
+ max: { control: { type: 'range' }, if: { arg: 'type', eq: 'number' } },
19
+ },
20
+ args: {
21
+ label: 'Input',
22
+ type: 'text',
23
+ min: 0,
24
+ max: 0,
25
+ placeholder: 'Input',
26
+ ...FieldSharedArgs,
27
+ },
28
+ decorators: [ContainerDecorator],
29
+ render: args => {
30
+ const [value, setValue] = useState('');
31
+
32
+ return <Input {...args} value={value} setValue={setValue} />;
33
+ },
34
+ };
35
+
36
+ export default meta;
37
+ type Story = StoryObj<typeof Input>;
38
+
39
+ export const Default: Story = {
40
+ args: {},
41
+ };
@@ -0,0 +1,73 @@
1
+ import { useMemo } from 'react';
2
+
3
+ import { Controller } from '../controller';
4
+ import { Field, InputFieldProps } from '../field';
5
+ import { ControllerGeneratorProps, UnControlledComponentProps } from '../form.types';
6
+
7
+ import { useInputHandlers } from '@polpo/hooks';
8
+
9
+ type IProps = InputFieldProps<{
10
+ type?: 'email' | 'number' | 'search' | 'tel' | 'text' | 'url';
11
+ min?: number;
12
+ max?: number;
13
+ }>;
14
+
15
+ export const Input = ({
16
+ name,
17
+ value,
18
+ setValue,
19
+ onBlur,
20
+ onFocus,
21
+ type = 'text',
22
+ className = '',
23
+ style = {},
24
+ autoFocus = false,
25
+ readOnly = false,
26
+ disabled = false,
27
+ placeholder = '',
28
+ autoComplete = 'off',
29
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
+ isDirty = false,
31
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
+ isTouched = false,
33
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
34
+ invalid = false,
35
+ error,
36
+ min,
37
+ max,
38
+ ...fieldProps
39
+ }: UnControlledComponentProps<IProps, string>) => {
40
+ const id = useMemo(() => crypto.randomUUID(), []);
41
+ const { handlers, isFocus } = useInputHandlers({
42
+ onChange: e => setValue(e.target.value),
43
+ onBlur: onBlur,
44
+ onFocus: onFocus,
45
+ });
46
+
47
+ return (
48
+ <Field id={id} error={error} isFocus={isFocus} {...fieldProps}>
49
+ <input
50
+ id={id}
51
+ type={type}
52
+ name={name}
53
+ className={className}
54
+ style={style}
55
+ value={value}
56
+ autoFocus={autoFocus}
57
+ autoComplete={autoComplete}
58
+ placeholder={placeholder}
59
+ disabled={disabled}
60
+ readOnly={readOnly}
61
+ min={min}
62
+ max={max}
63
+ {...handlers}
64
+ />
65
+ </Field>
66
+ );
67
+ };
68
+
69
+ const InputController = ({ rules, ...props }: ControllerGeneratorProps<IProps, string>) => {
70
+ return <Controller Component={Input} defaultValue='' inputProps={props} rules={rules} />;
71
+ };
72
+
73
+ Input.Controller = InputController;
@@ -0,0 +1 @@
1
+ export * from './input-color';
@@ -0,0 +1,46 @@
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 { InputColor } from './input-color';
7
+
8
+ import type { Meta, StoryObj } from '@storybook/react';
9
+
10
+ const meta: Meta<typeof InputColor> = {
11
+ title: 'Form/InputColor',
12
+ component: InputColor,
13
+ argTypes: {
14
+ ...FieldSharedArgTypes,
15
+ ...UnControlledComponentArgTypes,
16
+ showValueText: { control: 'boolean' },
17
+ },
18
+ args: {
19
+ label: 'Input Color',
20
+ showValueText: true,
21
+ rightIcon: undefined,
22
+ leftIcon: undefined,
23
+ ...FieldSharedArgs,
24
+ },
25
+ decorators: [ContainerDecorator],
26
+ render: args => {
27
+ const [value, setValue] = useState('#147EFB');
28
+
29
+ return <InputColor {...args} value={value} setValue={setValue} />;
30
+ },
31
+ };
32
+
33
+ export default meta;
34
+ type Story = StoryObj<typeof InputColor>;
35
+
36
+ export const Default: Story = {
37
+ args: {},
38
+ };
39
+
40
+ export const Box: Story = {
41
+ args: {
42
+ label: '',
43
+ showValueText: false,
44
+ variant: undefined,
45
+ },
46
+ };
@@ -0,0 +1,93 @@
1
+ import styled from 'styled-components';
2
+
3
+ export const InputColorStyle = styled.section`
4
+ display: grid;
5
+ grid-auto-flow: column;
6
+ align-items: center;
7
+ justify-content: start;
8
+
9
+ .input-color-value {
10
+ margin-left: 10px;
11
+ }
12
+
13
+ .color-input {
14
+ padding: 0 1em;
15
+ border-radius: inherit;
16
+ width: 100%;
17
+ font-size: ${props => props.theme.constants.typography.label.fontSize};
18
+ font-family: ${props => props.theme.constants.fontFamily};
19
+ }
20
+ `;
21
+
22
+ export const InputColorBoxStyle = styled.section`
23
+ background: white;
24
+ border-radius: 5px;
25
+ border: 2px solid;
26
+ width: 25px;
27
+ height: 25px;
28
+ position: relative;
29
+ cursor: pointer;
30
+
31
+ &::before {
32
+ content: '';
33
+ position: absolute;
34
+ border-radius: inherit;
35
+ top: 0;
36
+ left: 0;
37
+ width: 100%;
38
+ height: 100%;
39
+ background: repeating-conic-gradient(#cccccc 0% 25%, white 0% 50%) 50% / 8px 8px;
40
+ z-index: -1;
41
+ }
42
+ `;
43
+
44
+ export const InputColorSelectorStyle = styled.section`
45
+ position: fixed;
46
+ z-index: 1;
47
+ display: grid;
48
+ gap: 10px;
49
+ background: ${props => props.theme.colors.background.main};
50
+ color: ${props => props.theme.colors.text.main};
51
+ padding: 10px;
52
+ border-radius: 0 18px 18px 18px;
53
+ border: 1px solid;
54
+ box-shadow: 0 5px 30px -5px ${props => props.theme.colors.gray1};
55
+
56
+ .react-colorful__pointer {
57
+ width: 1em;
58
+ height: 1em;
59
+ border-radius: 50%;
60
+ }
61
+
62
+ .react-colorful__hue-pointer,
63
+ .react-colorful__alpha-pointer {
64
+ width: 8px;
65
+ height: 100%;
66
+ border-radius: 4px;
67
+ border-width: 2px;
68
+ }
69
+
70
+ .color-input-container {
71
+ display: grid;
72
+ grid-template-columns: 16px 1fr 16px;
73
+ align-items: center;
74
+ gap: 10px;
75
+ border: 1px solid;
76
+ border-radius: 8px;
77
+ padding: 0.5em;
78
+ width: 100%;
79
+ max-width: 200px;
80
+ }
81
+
82
+ .color-input {
83
+ padding: 0;
84
+ border-radius: inherit;
85
+ background: ${props => props.theme.colors.background.main};
86
+ color: ${props => props.theme.colors.text.main};
87
+ width: 100%;
88
+ font-size: ${props => props.theme.constants.typography.label.fontSize};
89
+ font-family: ${props => props.theme.constants.fontFamily};
90
+ letter-spacing: 2px;
91
+ text-align: center;
92
+ }
93
+ `;
@@ -0,0 +1,159 @@
1
+ import Color from 'color';
2
+ import { useCallback, useEffect, useMemo, useState } from 'react';
3
+ import { HexAlphaColorPicker, HexColorInput } from 'react-colorful';
4
+ import useEyeDropper from 'use-eye-dropper';
5
+
6
+ import { Icon } from '../../icon';
7
+ import { Modal } from '../../modals';
8
+ import { Controller } from '../controller';
9
+ import { Field, InputFieldProps } from '../field';
10
+ import { ControllerGeneratorProps, UnControlledComponentProps } from '../form.types';
11
+
12
+ import { InputColorBoxStyle, InputColorSelectorStyle, InputColorStyle } from './input-color.style';
13
+
14
+ import { useInputHandlers, useModalInContainer } from '@polpo/hooks';
15
+
16
+ type ColorProps = InputFieldProps<{
17
+ showValueText?: boolean;
18
+ }>;
19
+
20
+ export const InputColor = ({
21
+ name,
22
+ value,
23
+ setValue,
24
+ onBlur,
25
+ onFocus,
26
+ showValueText = false,
27
+ className = '',
28
+ style = {},
29
+ autoFocus = false,
30
+ readOnly = false,
31
+ disabled = false,
32
+ placeholder = '',
33
+ autoComplete = 'off',
34
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
35
+ isDirty = false,
36
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
37
+ isTouched = false,
38
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
39
+ invalid = false,
40
+ error,
41
+ ...fieldProps
42
+ }: UnControlledComponentProps<ColorProps, string>) => {
43
+ const { open, isSupported } = useEyeDropper();
44
+ const [inputValue, setInputValue] = useState<string>(value);
45
+ const id = useMemo(() => crypto.randomUUID(), []);
46
+ const { handlers, isFocus } = useInputHandlers({
47
+ onChange: e => setInputValue(e.target.value),
48
+ onBlur: e => {
49
+ setInputColor();
50
+ onBlur && onBlur(e);
51
+ },
52
+ onFocus: e => {
53
+ setInputColor();
54
+ onFocus && onFocus(e);
55
+ },
56
+ });
57
+ const { modalRef, isVisible, setIsVisible, modalStyle, containerRef } = useModalInContainer({
58
+ position: 'bottom',
59
+ distancePercentage: 0,
60
+ });
61
+
62
+ const borderColor = useMemo(() => {
63
+ const color = Color(value === '' ? '#000000' : value);
64
+
65
+ if (color.isLight() || color.alpha() < 0.5) {
66
+ return '#000000';
67
+ }
68
+
69
+ return '#FFFFFF';
70
+ }, [value]);
71
+
72
+ const openEyeDropper = async () => {
73
+ const { sRGBHex } = await open();
74
+ setValue(sRGBHex);
75
+ };
76
+
77
+ useEffect(() => {
78
+ setInputValue(value);
79
+ }, [value]);
80
+
81
+ const setInputColor = useCallback(() => {
82
+ if (inputValue.match(/^#(?:(?:[\da-f]{3}){1,2}|(?:[\da-f]{4}){1,2})$/i)) {
83
+ setValue(inputValue);
84
+ } else {
85
+ setInputValue(value);
86
+ }
87
+ }, [inputValue, setValue, value]);
88
+
89
+ return (
90
+ <Field id={id} error={error} isFocus={isFocus} {...fieldProps}>
91
+ <InputColorStyle
92
+ onClick={e => {
93
+ e.stopPropagation();
94
+ setIsVisible(true);
95
+ }}
96
+ ref={containerRef}
97
+ >
98
+ <InputColorBoxStyle
99
+ className={className}
100
+ style={{
101
+ borderColor,
102
+ background: value,
103
+ color: value,
104
+ ...style,
105
+ }}
106
+ >
107
+ <Modal id='input-color' isOpen={isVisible}>
108
+ <InputColorSelectorStyle ref={modalRef} style={modalStyle}>
109
+ <HexAlphaColorPicker id={id} color={value} onChange={setValue} />
110
+ <section className='color-input-container'>
111
+ {isSupported() ? (
112
+ <Icon
113
+ name='dropper'
114
+ onClick={() => {
115
+ void openEyeDropper();
116
+ }}
117
+ />
118
+ ) : (
119
+ <span />
120
+ )}
121
+ <HexColorInput
122
+ className='color-input'
123
+ id={id}
124
+ name={name}
125
+ color={value}
126
+ placeholder='Type a color'
127
+ prefixed
128
+ alpha
129
+ onChange={setValue}
130
+ />
131
+ <span />
132
+ </section>
133
+ </InputColorSelectorStyle>
134
+ </Modal>
135
+ </InputColorBoxStyle>
136
+ {showValueText ? (
137
+ <input
138
+ id={id}
139
+ name={name}
140
+ value={inputValue}
141
+ placeholder={placeholder}
142
+ readOnly={readOnly}
143
+ autoFocus={autoFocus}
144
+ disabled={disabled}
145
+ autoComplete={autoComplete}
146
+ className='color-input'
147
+ {...handlers}
148
+ />
149
+ ) : null}
150
+ </InputColorStyle>
151
+ </Field>
152
+ );
153
+ };
154
+
155
+ const InputColorController = ({ rules, ...props }: ControllerGeneratorProps<ColorProps, string>) => {
156
+ return <Controller Component={InputColor} defaultValue='#147EFB' inputProps={props} rules={rules} />;
157
+ };
158
+
159
+ InputColor.Controller = InputColorController;
@@ -0,0 +1 @@
1
+ export * from './input-file';
@@ -0,0 +1,40 @@
1
+ import { useState } from 'react';
2
+
3
+ import { ContainerDecorator, UnControlledComponentArgTypes } from '../form.stories.types';
4
+
5
+ import { InputFile } from './input-file';
6
+
7
+ import type { Meta, StoryObj } from '@storybook/react';
8
+
9
+ const meta: Meta<typeof InputFile> = {
10
+ title: 'Form/InputFile',
11
+ component: InputFile,
12
+ argTypes: {
13
+ ...UnControlledComponentArgTypes,
14
+ label: { control: 'text' },
15
+ accept: { control: 'text' },
16
+ multiple: { control: 'boolean' },
17
+ limitSize: { control: 'number' },
18
+ errorTimeout: { control: 'number' },
19
+ },
20
+ args: {
21
+ label: 'Input File',
22
+ accept: 'image/*',
23
+ multiple: false,
24
+ limitSize: 5000000,
25
+ errorTimeout: 3000,
26
+ },
27
+ decorators: [ContainerDecorator],
28
+ render: args => {
29
+ const [value, setValue] = useState<{ [key: string]: File }>({});
30
+
31
+ return <InputFile {...args} value={value} setValue={setValue} />;
32
+ },
33
+ };
34
+
35
+ export default meta;
36
+ type Story = StoryObj<typeof InputFile>;
37
+
38
+ export const Default: Story = {
39
+ args: {},
40
+ };
@@ -0,0 +1,143 @@
1
+ import styled from 'styled-components';
2
+
3
+ export const InputFileContainerStyle = styled.section`
4
+ display: grid;
5
+ gap: 10px;
6
+
7
+ .input-file--box {
8
+ border: 1px solid;
9
+ border-radius: 5px;
10
+ position: relative;
11
+ transition: all 0.3s ease;
12
+ display: grid;
13
+ grid-template-columns: 32px 1fr;
14
+ padding: 10px;
15
+ gap: 10px;
16
+ background: ${props => props.theme.colors.secondary.main};
17
+ color: ${props => props.theme.colors.secondary.contrast};
18
+ align-items: center;
19
+
20
+ &--icon {
21
+ width: 32px;
22
+ height: 32px;
23
+ border-radius: 5px;
24
+ background: ${props => props.theme.colors.primary.contrast};
25
+ color: ${props => props.theme.colors.primary.main};
26
+ display: grid;
27
+ place-content: center;
28
+ }
29
+
30
+ input {
31
+ position: absolute;
32
+ top: 0;
33
+ left: 0;
34
+ width: 100%;
35
+ height: 100%;
36
+ cursor: copy;
37
+ opacity: 0;
38
+ }
39
+
40
+ &:hover {
41
+ background: ${props => props.theme.colors.primary.contrast};
42
+ color: ${props => props.theme.colors.primary.main};
43
+
44
+ .input-file--box--icon {
45
+ background: ${props => props.theme.colors.primary.main};
46
+ color: ${props => props.theme.colors.primary.contrast};
47
+ }
48
+ }
49
+ }
50
+
51
+ .input-file--files {
52
+ max-height: 280px;
53
+ overflow-y: auto;
54
+ border: 1px solid;
55
+ border-radius: 5px;
56
+
57
+ &--content {
58
+ display: grid;
59
+ }
60
+ }
61
+
62
+ .error {
63
+ color: tomato;
64
+ }
65
+
66
+ .total-info {
67
+ font-size: 1em;
68
+ display: grid;
69
+ grid-auto-flow: column;
70
+ justify-content: end;
71
+ align-items: center;
72
+ gap: 0.5em;
73
+
74
+ &--delete {
75
+ display: grid;
76
+ place-content: center;
77
+ height: 100%;
78
+ background: transparent;
79
+ cursor: pointer;
80
+ transition: all 0.3s ease;
81
+ aspect-ratio: 1 / 1;
82
+ border-radius: 50%;
83
+ width: 2em;
84
+ font-size: 0.8em;
85
+
86
+ &:hover {
87
+ background: ${props => props.theme.colors.primary.main};
88
+ color: ${props => props.theme.colors.primary.contrast};
89
+ }
90
+ }
91
+ }
92
+ `;
93
+
94
+ export const FileCardStyle = styled.section`
95
+ display: grid;
96
+ grid-template-columns: 35px 1fr 35px;
97
+ gap: 1em;
98
+ align-items: center;
99
+ padding: 10px;
100
+ background: ${props => props.theme.colors.background.main};
101
+
102
+ &:not(:last-child) {
103
+ border-bottom: 1px dashed;
104
+ }
105
+
106
+ &:hover {
107
+ .file-card--delete {
108
+ color: ${props => props.theme.colors.primary.main};
109
+ }
110
+ }
111
+
112
+ .file-card--image {
113
+ background: ${props => props.theme.colors.primary.main};
114
+ color: ${props => props.theme.colors.primary.contrast};
115
+ width: 32px;
116
+ height: 32px;
117
+ border-radius: 5px;
118
+ display: grid;
119
+ place-content: center;
120
+ border: 1px solid;
121
+ }
122
+
123
+ .file-card--data {
124
+ display: grid;
125
+ font-size: 0.7em;
126
+ justify-content: start;
127
+ }
128
+
129
+ .file-card--delete {
130
+ border-radius: 5px;
131
+ display: grid;
132
+ place-content: center;
133
+ width: 32px;
134
+ height: 32px;
135
+ cursor: pointer;
136
+ transition: all 0.3s ease;
137
+
138
+ &:hover {
139
+ background: ${props => props.theme.colors.primary.main};
140
+ color: ${props => props.theme.colors.primary.contrast};
141
+ }
142
+ }
143
+ `;