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,34 @@
1
+ import { useState } from 'react';
2
+
3
+ import { IconNames } from '../../icon';
4
+ import { UnControlledComponentArgTypes } from '../form.stories.types';
5
+
6
+ import { Checkbox } from './checkbox';
7
+
8
+ import type { Meta, StoryObj } from '@storybook/react';
9
+
10
+ const meta: Meta<typeof Checkbox> = {
11
+ title: 'Form/Checkbox',
12
+ component: Checkbox,
13
+ argTypes: {
14
+ ...UnControlledComponentArgTypes,
15
+ placeholder: { table: { disable: true } },
16
+ label: { control: 'text' },
17
+ icon: { options: [undefined, ...IconNames.toSorted()] },
18
+ },
19
+ args: {
20
+ label: 'Checkbox',
21
+ },
22
+ render: args => {
23
+ const [value, setValue] = useState(false);
24
+
25
+ return <Checkbox {...args} value={value} setValue={setValue} />;
26
+ },
27
+ };
28
+
29
+ export default meta;
30
+ type Story = StoryObj<typeof Checkbox>;
31
+
32
+ export const Default: Story = {
33
+ args: {},
34
+ };
@@ -0,0 +1,75 @@
1
+ import styled from 'styled-components';
2
+
3
+ export const CheckboxStyle = styled.section`
4
+ border-radius: 42%;
5
+ background: ${props => props.theme.colors.background.paper};
6
+ color: ${props => props.theme.colors.primary.main};
7
+ transition: all 300ms ease;
8
+ position: relative;
9
+ padding: 2px;
10
+ width: 1.4em;
11
+ height: 1.4em;
12
+ border: 1px solid;
13
+
14
+ .checkbox-icon {
15
+ position: absolute;
16
+ top: 50%;
17
+ left: 50%;
18
+ transform: translate(-50%, -50%);
19
+ color: ${props => props.theme.colors.primary.contrast};
20
+ font-size: 0.7em;
21
+ z-index: 1;
22
+ opacity: 0;
23
+ transition: opacity 300ms ease;
24
+
25
+ path {
26
+ filter: drop-shadow(0px 0 3px rgba(0, 0, 0, 1));
27
+ }
28
+ }
29
+
30
+ &.is-checked {
31
+ background: ${props => props.theme.colors.primary.main};
32
+ color: ${props => props.theme.colors.primary.main};
33
+
34
+ .checkbox-icon {
35
+ opacity: 1;
36
+ }
37
+
38
+ &:hover {
39
+ background: ${props => props.theme.colors.primary.light};
40
+ }
41
+ }
42
+
43
+ .checkbox-input {
44
+ position: absolute;
45
+ top: 0;
46
+ left: 0;
47
+ width: 100%;
48
+ height: 100%;
49
+ cursor: pointer;
50
+ opacity: 0;
51
+ z-index: 2;
52
+ }
53
+ `;
54
+
55
+ export const CheckboxContainerStyle = styled.section`
56
+ display: flex;
57
+ align-items: center;
58
+ gap: 1em;
59
+ width: fit-content;
60
+
61
+ .checkbox-label {
62
+ cursor: pointer;
63
+ user-select: none;
64
+ }
65
+
66
+ ${CheckboxStyle}:hover,
67
+ &:has(.checkbox-label:hover) ${CheckboxStyle} {
68
+ box-shadow: 0 0 0 0.4em ${props => props.theme.colors.primary.main}88;
69
+ }
70
+
71
+ ${CheckboxStyle}:active,
72
+ &:has(.checkbox-label:active) ${CheckboxStyle} {
73
+ transform: scale(0.95);
74
+ }
75
+ `;
@@ -0,0 +1,76 @@
1
+ import { useMemo } from 'react';
2
+
3
+ import { Icon, IconNameT } from '../../icon';
4
+ import { Typography } from '../../typography';
5
+ import { Controller } from '../controller';
6
+ import { ControllerGeneratorProps, UnControlledComponentProps } from '../form.types';
7
+
8
+ import { CheckboxContainerStyle, CheckboxStyle } from './checkbox.style';
9
+
10
+ import { useInputHandlers } from '@polpo/hooks';
11
+
12
+ type CheckboxProps = {
13
+ label?: string;
14
+ placeholder?: never;
15
+ icon?: IconNameT;
16
+ };
17
+
18
+ export const Checkbox = ({
19
+ name,
20
+ value,
21
+ setValue,
22
+ onBlur,
23
+ onFocus,
24
+ className = '',
25
+ style = {},
26
+ autoFocus = false,
27
+ readOnly = false,
28
+ disabled = false,
29
+ autoComplete = 'off',
30
+ icon = 'checkmark',
31
+ label,
32
+ /*
33
+ * isDirty = false,
34
+ * isTouched = false,
35
+ * invalid = false,
36
+ * error,
37
+ */
38
+ }: UnControlledComponentProps<CheckboxProps, boolean>) => {
39
+ const id = useMemo(() => crypto.randomUUID(), []);
40
+ const { handlers } = useInputHandlers<HTMLInputElement>({
41
+ onChange: e => setValue(e.target.checked),
42
+ onBlur: onBlur,
43
+ onFocus: onFocus,
44
+ });
45
+
46
+ return (
47
+ <CheckboxContainerStyle className={className} style={style}>
48
+ <CheckboxStyle className={value ? 'is-checked' : ''}>
49
+ <Icon name={icon} className='checkbox-icon' />
50
+ <input
51
+ id={id}
52
+ type='checkbox'
53
+ name={name}
54
+ className={`checkbox-input ${className}`}
55
+ style={style}
56
+ checked={value}
57
+ autoFocus={autoFocus}
58
+ autoComplete={autoComplete}
59
+ disabled={disabled || readOnly}
60
+ {...handlers}
61
+ />
62
+ </CheckboxStyle>
63
+ {label ? (
64
+ <Typography variant='label-form' htmlFor={id} className='checkbox-label'>
65
+ {label}
66
+ </Typography>
67
+ ) : null}
68
+ </CheckboxContainerStyle>
69
+ );
70
+ };
71
+
72
+ const CheckboxController = ({ rules, ...props }: ControllerGeneratorProps<CheckboxProps, boolean>) => {
73
+ return <Controller Component={Checkbox} defaultValue={false} inputProps={props} rules={rules} />;
74
+ };
75
+
76
+ Checkbox.Controller = CheckboxController;
@@ -0,0 +1 @@
1
+ export * from './checkbox';
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import { Controller as RHFController, useFormContext, UseControllerProps } from 'react-hook-form';
3
+
4
+ import { ControlledComponentProps, Props, UnControlledComponentProps } from '../form.types';
5
+
6
+ type ControllerProps<T extends Props, V> = {
7
+ inputProps: ControlledComponentProps<T, V>;
8
+ Component: React.FC<UnControlledComponentProps<T, V>>;
9
+ rules?: UseControllerProps['rules'];
10
+ defaultValue: V;
11
+ };
12
+
13
+ export const Controller = <T extends Props, V>({
14
+ Component,
15
+ inputProps,
16
+ defaultValue: fieldDefaultValue,
17
+ rules,
18
+ }: ControllerProps<T, V>) => {
19
+ const { control, setValue } = useFormContext();
20
+ const { name, defaultValue } = inputProps;
21
+
22
+ return (
23
+ <RHFController
24
+ name={name}
25
+ control={control}
26
+ rules={rules}
27
+ defaultValue={defaultValue ?? fieldDefaultValue}
28
+ render={({ field: { onBlur, value }, fieldState }) => (
29
+ <Component
30
+ value={value}
31
+ error={fieldState.error?.message}
32
+ invalid={fieldState.invalid}
33
+ isTouched={fieldState.isTouched}
34
+ isDirty={fieldState.isDirty}
35
+ setValue={value => setValue(name, value)}
36
+ onBlur={onBlur}
37
+ {...inputProps}
38
+ />
39
+ )}
40
+ />
41
+ );
42
+ };
@@ -0,0 +1 @@
1
+ export * from './controller';
@@ -0,0 +1,38 @@
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 { DatePicker } from './date-picker';
7
+
8
+ import type { Meta, StoryObj } from '@storybook/react';
9
+
10
+ const meta: Meta<typeof DatePicker> = {
11
+ title: 'Form/DatePicker',
12
+ component: DatePicker,
13
+ argTypes: {
14
+ ...FieldSharedArgTypes,
15
+ ...UnControlledComponentArgTypes,
16
+ type: { control: 'select', options: ['date', 'datetime-local', 'month', 'time', 'week'] },
17
+ },
18
+ args: {
19
+ type: 'date',
20
+ label: 'DatePicker',
21
+ rightIcon: undefined,
22
+ leftIcon: undefined,
23
+ ...FieldSharedArgs,
24
+ },
25
+ decorators: [ContainerDecorator],
26
+ render: args => {
27
+ const [value, setValue] = useState('');
28
+
29
+ return <DatePicker {...args} value={value} setValue={setValue} />;
30
+ },
31
+ };
32
+
33
+ export default meta;
34
+ type Story = StoryObj<typeof DatePicker>;
35
+
36
+ export const Default: Story = {
37
+ args: {},
38
+ };
@@ -0,0 +1,67 @@
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 DatePickerProps = InputFieldProps<{
10
+ type?: 'date' | 'datetime-local' | 'month' | 'time' | 'week';
11
+ }>;
12
+
13
+ export const DatePicker = ({
14
+ name,
15
+ value,
16
+ setValue,
17
+ onBlur,
18
+ onFocus,
19
+ type = 'date',
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<DatePickerProps, string>) => {
36
+ const id = useMemo(() => crypto.randomUUID(), []);
37
+ const { isFocus, handlers } = useInputHandlers({
38
+ onBlur: onBlur,
39
+ onChange: e => setValue(e.target.value),
40
+ onFocus: onFocus,
41
+ });
42
+
43
+ return (
44
+ <Field id={id} error={error} isFocus={isFocus} {...fieldProps}>
45
+ <input
46
+ id={id}
47
+ type={type}
48
+ name={name}
49
+ className={className}
50
+ style={style}
51
+ value={value}
52
+ autoFocus={autoFocus}
53
+ autoComplete={autoComplete}
54
+ placeholder={placeholder}
55
+ disabled={disabled}
56
+ readOnly={readOnly}
57
+ {...handlers}
58
+ />
59
+ </Field>
60
+ );
61
+ };
62
+
63
+ const DatePickerController = ({ rules, ...props }: ControllerGeneratorProps<DatePickerProps, string>) => {
64
+ return <Controller Component={DatePicker} defaultValue='' inputProps={props} rules={rules} />;
65
+ };
66
+
67
+ DatePicker.Controller = DatePickerController;
@@ -0,0 +1 @@
1
+ export * from './date-picker';
@@ -0,0 +1,49 @@
1
+ import { IconNames } from '../../icon';
2
+ import { ContainerDecorator } from '../form.stories.types';
3
+
4
+ import { Field } from './field';
5
+
6
+ import type { Meta, StoryObj } from '@storybook/react';
7
+
8
+ export const FieldSharedArgTypes: Meta<typeof Field>['argTypes'] = {
9
+ label: { control: 'text' },
10
+ rightIcon: { options: [undefined, ...IconNames.toSorted()] },
11
+ leftIcon: { options: [undefined, ...IconNames.toSorted()] },
12
+ errorIcon: { options: [undefined, ...IconNames.toSorted()] },
13
+ variant: { control: 'select', options: [undefined, 'full-border', 'content-border', 'line'] },
14
+ };
15
+
16
+ export const FieldSharedArgs: StoryObj<typeof Field>['args'] = {
17
+ variant: 'full-border',
18
+ };
19
+
20
+ const meta: Meta<typeof Field> = {
21
+ title: 'Form/Field',
22
+ component: Field,
23
+ includeStories: ['Default'],
24
+ excludeStories: /.*Shared*$/,
25
+ argTypes: {
26
+ ...FieldSharedArgTypes,
27
+ id: { control: false },
28
+ error: { control: 'text' },
29
+ isFocus: { control: 'boolean' },
30
+ children: { control: 'text' },
31
+ },
32
+ args: {
33
+ label: 'Field label',
34
+ children: 'Hello world',
35
+ isFocus: false,
36
+ error: '',
37
+ ...FieldSharedArgs,
38
+ leftIcon: 'facebook',
39
+ rightIcon: 'airplane',
40
+ },
41
+ decorators: [ContainerDecorator],
42
+ };
43
+
44
+ export default meta;
45
+ type Story = StoryObj<typeof Field>;
46
+
47
+ export const Default: Story = {
48
+ args: {},
49
+ };
@@ -0,0 +1,79 @@
1
+ import styled from 'styled-components';
2
+
3
+ export const FieldStyle = styled.section`
4
+ display: grid;
5
+ gap: 0.5em;
6
+
7
+ .field-content {
8
+ display: grid;
9
+ grid-template-columns: auto 1fr auto;
10
+ align-items: center;
11
+ }
12
+
13
+ .field-left-icon,
14
+ .field-right-icon {
15
+ font-size: 1em;
16
+ }
17
+
18
+ .field-left-icon {
19
+ margin-right: 1em;
20
+ }
21
+
22
+ .field-right-icon {
23
+ margin-left: 1em;
24
+ }
25
+
26
+ .field-message {
27
+ display: grid;
28
+ grid-auto-flow: column;
29
+ gap: 5px;
30
+ align-items: center;
31
+ justify-content: start;
32
+ }
33
+
34
+ &.error {
35
+ color: ${props => props.theme.colors.alert.main};
36
+ }
37
+
38
+ &.focus {
39
+ color: ${props => props.theme.colors.info.main};
40
+ }
41
+
42
+ &.error,
43
+ &.focus {
44
+ .field-left-icon,
45
+ .field-right-icon,
46
+ .field-children {
47
+ color: ${props => props.theme.colors.text.main};
48
+ }
49
+ }
50
+
51
+ &.variant-content-border {
52
+ .field-content {
53
+ border: 1px solid;
54
+ border-radius: 4px;
55
+ padding: 1em;
56
+ background: ${props => props.theme.colors.background.main};
57
+ }
58
+ }
59
+
60
+ &.variant-content-line {
61
+ .field-content {
62
+ border-bottom: 1px solid;
63
+ padding: 0.5em 0;
64
+ }
65
+ }
66
+
67
+ &.variant-full-border {
68
+ border: 1px solid;
69
+ border-radius: 4px;
70
+ padding: 0.5em 0;
71
+ background: ${props => props.theme.colors.background.main};
72
+
73
+ .field-label,
74
+ .field-content,
75
+ .field-message {
76
+ padding: 0 1em;
77
+ }
78
+ }
79
+ `;
@@ -0,0 +1,83 @@
1
+ import React, { ForwardedRef } from 'react';
2
+
3
+ import { Icon, IconNameT } from '../../icon';
4
+ import { Typography } from '../../typography';
5
+
6
+ import { FieldStyle } from './field.style';
7
+ import { FieldProps, FieldVariant } from './field.types';
8
+
9
+ import { useClassNames } from '@polpo/hooks';
10
+
11
+ type GetIconParams = {
12
+ iconName?: IconNameT;
13
+ onClick: (e: React.MouseEvent) => void;
14
+ className: string;
15
+ };
16
+
17
+ const getIcon = ({ iconName, className, onClick }: GetIconParams) =>
18
+ iconName ? <Icon className={className} name={iconName} onClick={onClick} /> : <span />;
19
+
20
+ const FieldComponent = (
21
+ {
22
+ id,
23
+ label,
24
+ leftIcon,
25
+ rightIcon,
26
+ errorIcon = 'cross',
27
+ error,
28
+ onClickLeftIcon,
29
+ onClickRightIcon,
30
+ children,
31
+ isFocus = false,
32
+ variant,
33
+ }: FieldProps,
34
+ ref: ForwardedRef<HTMLElement>,
35
+ ) => {
36
+ const fieldClassName = useClassNames({
37
+ focus: isFocus,
38
+ error: !!error,
39
+ 'variant-content-border': variant === FieldVariant.CONTENT_BORDER,
40
+ 'variant-content-line': variant === FieldVariant.CONTENT_LINE,
41
+ 'variant-full-border': variant === FieldVariant.FULL_BORDER,
42
+ });
43
+
44
+ const handleClick = (callback?: () => void) => (e: React.MouseEvent) => {
45
+ e.stopPropagation();
46
+ const input = document.getElementById(id);
47
+ input?.focus();
48
+ callback && callback();
49
+ };
50
+
51
+ return (
52
+ <FieldStyle className={fieldClassName} ref={ref}>
53
+ {label ? (
54
+ <Typography className='field-label' noPadding variant='label-form' htmlFor={id}>
55
+ {label}
56
+ </Typography>
57
+ ) : null}
58
+ <section className='field-content'>
59
+ {getIcon({
60
+ className: 'field-left-icon',
61
+ iconName: leftIcon,
62
+ onClick: handleClick(onClickLeftIcon),
63
+ })}
64
+ <section className='field-children'>{children}</section>
65
+ {getIcon({
66
+ className: 'field-right-icon',
67
+ iconName: rightIcon,
68
+ onClick: handleClick(onClickRightIcon),
69
+ })}
70
+ </section>
71
+ {Boolean(error) && (
72
+ <section className='field-message'>
73
+ {errorIcon ? <Icon name={errorIcon} size={10} /> : <span />}
74
+ <Typography noPadding variant='small'>
75
+ {error}
76
+ </Typography>
77
+ </section>
78
+ )}
79
+ </FieldStyle>
80
+ );
81
+ };
82
+
83
+ export const Field = React.forwardRef(FieldComponent);
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+
3
+ import { IconNameT } from '../../icon';
4
+
5
+ export enum FieldVariant {
6
+ FULL_BORDER = 'full-border',
7
+ CONTENT_BORDER = 'content-border',
8
+ CONTENT_LINE = 'line',
9
+ }
10
+
11
+ type FieldSharedProps = {
12
+ rightIcon?: IconNameT;
13
+ leftIcon?: IconNameT;
14
+ errorIcon?: IconNameT;
15
+ onClickLeftIcon?: () => void;
16
+ onClickRightIcon?: () => void;
17
+ label?: string;
18
+ variant?: `${FieldVariant}`;
19
+ };
20
+
21
+ export type FieldProps = FieldSharedProps & {
22
+ children: React.ReactNode;
23
+ id: string;
24
+ error?: string;
25
+ isFocus?: boolean;
26
+ };
27
+
28
+ export type InputFieldProps<T> = T & FieldSharedProps;
@@ -0,0 +1,2 @@
1
+ export * from './field';
2
+ export * from './field.types';
@@ -0,0 +1,50 @@
1
+ import { Meta, StoryFn } from '@storybook/react';
2
+
3
+ import { Grid } from '../../layouts';
4
+
5
+ import {
6
+ ControlledComponentProps,
7
+ ControlledProps,
8
+ SharedProps,
9
+ UnControlledComponentProps,
10
+ UnControlledProps,
11
+ } from './form.types';
12
+
13
+ export const SharedArgTypes: Meta<SharedProps>['argTypes'] = {
14
+ name: { control: false },
15
+ className: { control: false },
16
+ style: { control: false },
17
+ autoComplete: { control: false },
18
+ autoFocus: { control: 'boolean' },
19
+ placeholder: { control: 'text' },
20
+ disabled: { control: 'boolean' },
21
+ readOnly: { control: 'boolean' },
22
+ };
23
+
24
+ export const UnControlledArgTypes: Meta<UnControlledProps<unknown>>['argTypes'] = {
25
+ value: { control: false },
26
+ invalid: { control: 'boolean' },
27
+ isTouched: { control: 'boolean' },
28
+ isDirty: { control: 'boolean' },
29
+ error: { control: 'text' },
30
+ };
31
+
32
+ export const ControlledArgTypes: Meta<ControlledProps<unknown>>['argTypes'] = {
33
+ defaultValue: { control: false },
34
+ };
35
+
36
+ export const UnControlledComponentArgTypes: Meta<UnControlledComponentProps<{}, unknown>>['argTypes'] = {
37
+ ...SharedArgTypes,
38
+ ...UnControlledArgTypes,
39
+ };
40
+
41
+ export const ControlledComponentArgTypes: Meta<ControlledComponentProps<{}, unknown>>['argTypes'] = {
42
+ ...SharedArgTypes,
43
+ ...ControlledArgTypes,
44
+ };
45
+
46
+ export const ContainerDecorator = (Story: StoryFn) => (
47
+ <Grid gtc='300px'>
48
+ <Story />
49
+ </Grid>
50
+ );
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { UseControllerProps } from 'react-hook-form';
3
+
4
+ export type Props = { [key: string]: unknown };
5
+
6
+ export type SharedProps = {
7
+ name: string;
8
+ className?: string;
9
+ style?: React.CSSProperties;
10
+ autoComplete?: string;
11
+ autoFocus?: boolean;
12
+ placeholder?: string;
13
+ disabled?: boolean;
14
+ readOnly?: boolean;
15
+ onBlur?: (e: React.FocusEvent<unknown>) => void;
16
+ onFocus?: (e: React.FocusEvent<unknown>) => void;
17
+ };
18
+
19
+ export type UnControlledProps<V> = {
20
+ value: V;
21
+ setValue: (value: V) => void;
22
+ invalid?: boolean;
23
+ isTouched?: boolean;
24
+ isDirty?: boolean;
25
+ error?: string;
26
+ };
27
+
28
+ export type ControlledProps<V> = {
29
+ defaultValue?: V;
30
+ };
31
+
32
+ export type UnControlledComponentProps<T extends Props, V> = T & SharedProps & UnControlledProps<V>;
33
+
34
+ export type ControlledComponentProps<T extends Props, V> = T & SharedProps & ControlledProps<V>;
35
+
36
+ export type ControllerGeneratorProps<T extends Props, V> = ControlledComponentProps<T, V> &
37
+ Partial<Pick<UseControllerProps, 'rules'>>;
@@ -0,0 +1,14 @@
1
+ export * from './checkbox';
2
+ export * from './controller';
3
+ export * from './date-picker';
4
+ export * from './field';
5
+ export * from './input';
6
+ export * from './input-password';
7
+ export * from './input-color';
8
+ export * from './input-file';
9
+ export * from './field';
10
+ export * from './radio';
11
+ export * from './select';
12
+ export * from './slider';
13
+ export * from './textarea';
14
+ export * from './switch';
@@ -0,0 +1 @@
1
+ export * from './input';