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,301 @@
1
+ import { Icon } from '../icon';
2
+
3
+ import { SmartTable } from './smart-table';
4
+
5
+ import type { Meta, StoryObj } from '@storybook/react';
6
+
7
+ const users = [
8
+ {
9
+ age: '25',
10
+ gender: 'male',
11
+ occupation: 'Software engineer',
12
+ hobbies: ['Reading', 'Hiking'],
13
+ email: 'john@example.com',
14
+ phone: '123-456-7890',
15
+ username: 'johnny25',
16
+ name: 'John Doe',
17
+ country: 'USA',
18
+ id: '1',
19
+ },
20
+ {
21
+ age: '30',
22
+ gender: 'female',
23
+ occupation: 'Graphic designer',
24
+ hobbies: ['Painting', 'Yoga'],
25
+ email: 'jane@example.com',
26
+ phone: '987-654-3210',
27
+ username: 'janeD30',
28
+ name: 'Jane Smith',
29
+ country: 'Canada',
30
+ id: '2',
31
+ },
32
+ {
33
+ age: '28',
34
+ gender: 'male',
35
+ occupation: 'Data analyst',
36
+ hobbies: ['Gaming', 'Cycling'],
37
+ email: 'mike@example.com',
38
+ phone: '555-123-4567',
39
+ username: 'mikeA28',
40
+ name: 'Mike Johnson',
41
+ country: 'UK',
42
+ id: '3',
43
+ },
44
+ {
45
+ age: '35',
46
+ gender: 'female',
47
+ occupation: 'Marketing manager',
48
+ hobbies: ['Traveling', 'Cooking'],
49
+ email: 'sara@example.com',
50
+ phone: '444-987-6543',
51
+ username: 'saraM35',
52
+ name: 'Sara Wilson',
53
+ country: 'Australia',
54
+ id: '4',
55
+ },
56
+ {
57
+ age: '22',
58
+ gender: 'male',
59
+ occupation: 'Web developer',
60
+ hobbies: ['Programming', 'Photography'],
61
+ email: 'alex@example.com',
62
+ phone: '333-555-1234',
63
+ username: 'alexD22',
64
+ name: 'Alex Brown',
65
+ country: 'Germany',
66
+ id: '5',
67
+ },
68
+ {
69
+ age: '27',
70
+ gender: 'female',
71
+ occupation: 'HR specialist',
72
+ hobbies: ['Dancing', 'Reading'],
73
+ email: 'lisa@example.com',
74
+ phone: '222-444-9876',
75
+ username: 'lisaS27',
76
+ name: 'Lisa Davis',
77
+ country: 'France',
78
+ id: '6',
79
+ },
80
+ {
81
+ age: '31',
82
+ gender: 'male',
83
+ occupation: 'Financial analyst',
84
+ hobbies: ['Investing', 'Golfing'],
85
+ email: 'tom@example.com',
86
+ phone: '111-333-5555',
87
+ username: 'tomA31',
88
+ name: 'Tom Miller',
89
+ country: 'Japan',
90
+ id: '7',
91
+ },
92
+ {
93
+ age: '29',
94
+ gender: 'female',
95
+ occupation: 'Sales executive',
96
+ hobbies: ['Shopping', 'Running'],
97
+ email: 'anna@example.com',
98
+ phone: '666-222-4444',
99
+ username: 'annaE29',
100
+ name: 'Anna Taylor',
101
+ country: 'Brazil',
102
+ id: '8',
103
+ },
104
+ {
105
+ age: '26',
106
+ gender: 'male',
107
+ occupation: 'IT support',
108
+ hobbies: ['Gaming', 'Watching movies'],
109
+ email: 'jake@example.com',
110
+ phone: '777-111-3333',
111
+ username: 'jakeS26',
112
+ name: 'Jake Anderson',
113
+ country: 'India',
114
+ id: '9',
115
+ },
116
+ {
117
+ age: '33',
118
+ gender: 'female',
119
+ occupation: 'Nurse',
120
+ hobbies: ['Cooking', 'Painting'],
121
+ email: 'kate@example.com',
122
+ phone: '888-666-2222',
123
+ username: 'kateN33',
124
+ name: 'Kate Thomas',
125
+ country: 'Italy',
126
+ id: '10',
127
+ },
128
+ {
129
+ age: '24',
130
+ gender: 'male',
131
+ occupation: 'Teacher',
132
+ hobbies: ['Reading', 'Traveling'],
133
+ email: 'ryan@example.com',
134
+ phone: '999-777-1111',
135
+ username: 'ryanT24',
136
+ name: 'Ryan Jackson',
137
+ country: 'Mexico',
138
+ id: '11',
139
+ },
140
+ {
141
+ age: '32',
142
+ gender: 'female',
143
+ occupation: 'Lawyer',
144
+ hobbies: ['Running', 'Yoga'],
145
+ email: 'lily@example.com',
146
+ phone: '000-888-6666',
147
+ username: 'lilyL32',
148
+ name: 'Lily White',
149
+ country: 'South Africa',
150
+ id: '12',
151
+ },
152
+ {
153
+ age: '23',
154
+ gender: 'male',
155
+ occupation: 'Mechanic',
156
+ hobbies: ['Fixing cars', 'Fishing'],
157
+ email: 'matt@example.com',
158
+ phone: '111-999-7777',
159
+ username: 'mattM23',
160
+ name: 'Matt Harris',
161
+ country: 'Russia',
162
+ id: '13',
163
+ },
164
+ {
165
+ age: '34',
166
+ gender: 'female',
167
+ occupation: 'Architect',
168
+ hobbies: ['Designing', 'Hiking'],
169
+ email: 'sophia@example.com',
170
+ phone: '222-000-8888',
171
+ username: 'sophiaA34',
172
+ name: 'Sophia Clark',
173
+ country: 'Spain',
174
+ id: '14',
175
+ },
176
+ {
177
+ age: '21',
178
+ gender: 'male',
179
+ occupation: 'Intern',
180
+ hobbies: ['Learning', 'Reading'],
181
+ email: 'chris@example.com',
182
+ phone: '333-111-9999',
183
+ username: 'chrisI21',
184
+ name: 'Chris Lewis',
185
+ country: 'Netherlands',
186
+ id: '15',
187
+ },
188
+ {
189
+ age: '36',
190
+ gender: 'female',
191
+ occupation: 'CEO',
192
+ hobbies: ['Gambling', 'Traveling'],
193
+ email: 'emily@example.com',
194
+ phone: '444-222-0000',
195
+ username: 'emilyC36',
196
+ name: 'Emily Robinson',
197
+ country: 'Sweden',
198
+ id: '16',
199
+ },
200
+ {
201
+ age: '37',
202
+ gender: 'male',
203
+ occupation: 'Doctor',
204
+ hobbies: ['Helping others', 'Running'],
205
+ email: 'david@example.com',
206
+ phone: '555-333-1111',
207
+ username: 'davidD37',
208
+ name: 'David Hall',
209
+ country: 'Norway',
210
+ id: '17',
211
+ },
212
+ {
213
+ age: '38',
214
+ gender: 'female',
215
+ occupation: 'Accountant',
216
+ hobbies: ['Calculating', 'Reading'],
217
+ email: 'olivia@example.com',
218
+ phone: '666-444-2222',
219
+ username: 'oliviaA38',
220
+ name: 'Olivia Young',
221
+ country: 'Finland',
222
+ id: '18',
223
+ },
224
+ {
225
+ age: '39',
226
+ gender: 'male',
227
+ occupation: 'Plumber',
228
+ hobbies: ['Fixing pipes', 'Fishing'],
229
+ email: 'noah@example.com',
230
+ phone: '777-555-3333',
231
+ username: 'noahP39',
232
+ name: 'Noah King',
233
+ country: 'Denmark',
234
+ id: '19',
235
+ },
236
+ {
237
+ age: '40',
238
+ gender: 'female',
239
+ occupation: 'Teacher',
240
+ hobbies: ['Teaching', 'Traveling'],
241
+ email: 'ava@example.com',
242
+ phone: '888-666-4444',
243
+ username: 'avaT40',
244
+ name: 'Ava Scott',
245
+ country: 'Belgium',
246
+ id: '20',
247
+ },
248
+ ];
249
+
250
+ const meta: Meta<typeof SmartTable> = {
251
+ title: 'Smart Table',
252
+ component: SmartTable,
253
+ argTypes: {
254
+ columns: { control: false },
255
+ data: { control: false },
256
+ width: { control: 'inline-radio', options: ['scroll', 'content'] },
257
+ selectable: { control: 'boolean' },
258
+ rowId: { control: false },
259
+ },
260
+ args: {},
261
+ decorators: [
262
+ Story => (
263
+ <div style={{ width: '100%', maxHeight: '500px', overflow: 'auto' }}>
264
+ <Story />
265
+ </div>
266
+ ),
267
+ ],
268
+ };
269
+
270
+ export default meta;
271
+ type Story = StoryObj<typeof SmartTable>;
272
+
273
+ export const Users: Story = {
274
+ args: {
275
+ // @ts-expect-error Storybook doesn't recognize the rowId prop
276
+ rowId: 'id',
277
+ data: users,
278
+ columns: [
279
+ // @ts-expect-error Storybook doesn't recognize props
280
+ { header: 'Name', field: 'name' },
281
+ // @ts-expect-error Storybook doesn't recognize props
282
+ { header: 'Age', field: 'age' },
283
+ // @ts-expect-error Storybook doesn't recognize props
284
+ { header: 'Email', field: 'email' },
285
+ // @ts-expect-error Storybook doesn't recognize props
286
+ { header: 'Username', field: 'username' },
287
+ // @ts-expect-error Storybook doesn't recognize props
288
+ { header: 'Phone', field: 'phone' },
289
+ {
290
+ header: 'Gender',
291
+ render: data => <Icon name={data.gender === 'male' ? 'user' : 'camera'} />,
292
+ // @ts-expect-error Storybook doesn't recognize props
293
+ sortBy: 'gender',
294
+ },
295
+ // @ts-expect-error Storybook doesn't recognize props
296
+ { header: 'Country', field: 'country' },
297
+ // @ts-expect-error Storybook doesn't recognize props
298
+ { header: 'Occupation', field: 'occupation' },
299
+ ],
300
+ },
301
+ };
@@ -0,0 +1,102 @@
1
+ import { styled } from 'styled-components';
2
+
3
+ export const SmartTableContainerStyle = styled.section`
4
+ border: 1px solid ${props => props.theme.colors.primary.main};
5
+ border-radius: 10px;
6
+ overflow: auto;
7
+ height: 100%;
8
+ width: 100%;
9
+ margin: auto;
10
+ `;
11
+
12
+ export const SmartTableStyle = styled.table`
13
+ border-collapse: collapse;
14
+ position: relative;
15
+
16
+ &.layout-fixed {
17
+ table-layout: fixed;
18
+ }
19
+
20
+ &.layout-scrollable {
21
+ table-layout: auto;
22
+ }
23
+ `;
24
+
25
+ export const SmartHeaderStyle = styled.thead`
26
+ position: sticky;
27
+ z-index: 10;
28
+ top: 0;
29
+ box-shadow:
30
+ 0 3px 5px 0 rgba(0, 0, 0, 0.2),
31
+ 0 1px 10px 0 rgba(0, 0, 0, 0.12);
32
+ `;
33
+
34
+ export const SmartBodyStyle = styled.tbody``;
35
+
36
+ export const SmartColumnStyle = styled.th`
37
+ padding: 0.8em 1.2em;
38
+ user-select: none;
39
+
40
+ &.sort-on-click {
41
+ cursor: pointer;
42
+ }
43
+
44
+ .sort-icon {
45
+ width: 1em;
46
+ display: block;
47
+ }
48
+
49
+ svg {
50
+ animation: fadeIn 300ms ease;
51
+ }
52
+
53
+ path {
54
+ transition: all 300ms ease;
55
+ }
56
+
57
+ &:first-child {
58
+ padding-left: 2em;
59
+ }
60
+
61
+ &:last-child {
62
+ padding-right: 2em;
63
+ }
64
+ `;
65
+
66
+ export const SmartHeaderRowStyle = styled.tr`
67
+ background: ${props => props.theme.colors.primary.main};
68
+ color: ${props => props.theme.colors.primary.contrast};
69
+ transition: all 300ms ease;
70
+ `;
71
+
72
+ export const SmartRowStyle = styled.tr`
73
+ background: ${props => props.theme.colors.background.main};
74
+ box-shadow: inset 0 0 0 0 ${props => props.theme.colors.primary.main};
75
+ transition: box-shadow 300ms ease;
76
+
77
+ &.row-selected,
78
+ &:hover {
79
+ background: ${props => props.theme.colors.background.paper};
80
+ }
81
+
82
+ &.row-selected {
83
+ box-shadow: inset 10px 0 0 -5px ${props => props.theme.colors.primary.main};
84
+ }
85
+
86
+ &:not(:last-child) {
87
+ border-bottom: 1px solid ${props => props.theme.colors.border.main};
88
+ }
89
+ `;
90
+
91
+ export const SmartCellStyle = styled.td`
92
+ transition: all 300ms ease;
93
+ padding: 0.6em 1em;
94
+
95
+ &:first-child {
96
+ padding-left: 2em;
97
+ }
98
+
99
+ &:last-child {
100
+ padding-right: 2em;
101
+ }
102
+ `;
@@ -0,0 +1,112 @@
1
+ import { useMemo, useState } from 'react';
2
+
3
+ import { KeyValuesOf } from '../../types';
4
+ import { Checkbox } from '../form';
5
+
6
+ import { SmartTableColumn } from './smart-table.column';
7
+ import { sortData } from './smart-table.helpers';
8
+ import { useSort } from './smart-table.hooks';
9
+ import { SmartTableRow } from './smart-table.row';
10
+ import {
11
+ SmartBodyStyle,
12
+ SmartHeaderStyle,
13
+ SmartTableStyle,
14
+ SmartHeaderRowStyle,
15
+ SmartTableContainerStyle,
16
+ } from './smart-table.style';
17
+ import { ColumnData, RowDataObject } from './smart-table.types';
18
+
19
+ import { useClassNames } from '@polpo/hooks';
20
+
21
+ type SmartTableProps<RowData extends RowDataObject> = {
22
+ columns: Array<ColumnData<RowData>>;
23
+ data: Array<RowData>;
24
+ width?: 'scroll' | 'content';
25
+ selectable?: boolean;
26
+ rowId: KeyValuesOf<RowData, React.Key>;
27
+ };
28
+
29
+ export const SmartTable = <RowData extends RowDataObject>({
30
+ columns: initialColumns,
31
+ data,
32
+ width,
33
+ selectable = false,
34
+ rowId,
35
+ }: SmartTableProps<RowData>) => {
36
+ const [selected, setSelected] = useState<{ [key: string]: RowData }>({});
37
+
38
+ const tableClassName = useClassNames({
39
+ 'layout-fixed': width === 'content',
40
+ 'layout-scrollable': width === 'scroll',
41
+ });
42
+
43
+ const { sortBy, order, toggleSortField } = useSort<RowData>();
44
+
45
+ const columns = useMemo(() => {
46
+ let finalColumns = [...initialColumns];
47
+
48
+ if (selectable) {
49
+ finalColumns = [
50
+ {
51
+ header: `${Object.values(selected).length}`,
52
+ render: (data, rowKey) => (
53
+ <Checkbox
54
+ name={`selected-${rowKey}`}
55
+ value={`${rowKey}` in selected}
56
+ setValue={isSelected => {
57
+ setSelected(prev => {
58
+ const copy = { ...prev };
59
+
60
+ if (isSelected) {
61
+ copy[`${rowKey}`] = data;
62
+ } else {
63
+ delete copy[`${rowKey}`];
64
+ }
65
+
66
+ return copy;
67
+ });
68
+ }}
69
+ />
70
+ ),
71
+ },
72
+ ...finalColumns,
73
+ ];
74
+ }
75
+
76
+ return finalColumns;
77
+ }, [initialColumns, selectable, selected]);
78
+
79
+ const rows = useMemo(() => sortData<RowData>(data, sortBy, order), [data, sortBy, order]);
80
+
81
+ return (
82
+ <SmartTableContainerStyle>
83
+ <SmartTableStyle className={tableClassName}>
84
+ <SmartHeaderStyle>
85
+ <SmartHeaderRowStyle>
86
+ {columns.map((column, key) => (
87
+ <SmartTableColumn
88
+ key={key}
89
+ toggleSortField={toggleSortField}
90
+ sortField={sortBy}
91
+ orderField={order}
92
+ {...column}
93
+ />
94
+ ))}
95
+ </SmartHeaderRowStyle>
96
+ </SmartHeaderStyle>
97
+ <SmartBodyStyle>
98
+ {rows.map(row => (
99
+ <SmartTableRow
100
+ key={row[rowId] as React.Key}
101
+ rowKey={row[rowId] as React.Key}
102
+ data={row}
103
+ columns={columns}
104
+ isSelected={`${row[rowId] as React.Key}` in selected}
105
+ selectable={selectable}
106
+ />
107
+ ))}
108
+ </SmartBodyStyle>
109
+ </SmartTableStyle>
110
+ </SmartTableContainerStyle>
111
+ );
112
+ };
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+
3
+ import { KeyValuesOf } from '../../types';
4
+ import { IconNameT } from '../icon';
5
+
6
+ export type Primitive = string | number | boolean;
7
+
8
+ export type RowDataObject = { [key: string]: Primitive | object };
9
+
10
+ export type Order = 'asc' | 'desc';
11
+
12
+ type ColumnDataCommon<RowData extends RowDataObject> = {
13
+ header: React.ReactNode;
14
+ sortBy?: KeyValuesOf<RowData, Primitive>;
15
+ icon?: IconNameT;
16
+ width?: `${number}px` | `${number}em` | `${number}%`;
17
+ };
18
+
19
+ type ColumnDataField<RowData extends RowDataObject> = ColumnDataCommon<RowData> & {
20
+ field: KeyValuesOf<RowData, Primitive>;
21
+ sortBy?: never;
22
+ render?: never;
23
+ Component?: never;
24
+ };
25
+
26
+ type ColumnDataRender<RowData extends RowDataObject> = ColumnDataCommon<RowData> & {
27
+ field?: never;
28
+ render: (row: RowData, rowKey: React.Key) => React.ReactNode;
29
+ Component?: never;
30
+ };
31
+
32
+ type ColumnDataComponent<RowData extends RowDataObject> = ColumnDataCommon<RowData> & {
33
+ field?: never;
34
+ render?: never;
35
+ Component: React.FC<{ data: RowData; rowKey: React.Key }>;
36
+ };
37
+
38
+ export type ColumnData<RowData extends RowDataObject> =
39
+ | ColumnDataField<RowData>
40
+ | ColumnDataRender<RowData>
41
+ | ColumnDataComponent<RowData>;
@@ -0,0 +1 @@
1
+ export * from './tabs';