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,44 @@
1
+ import { HTMLAttributes } from 'react';
2
+
3
+ import { RadiusVariants, SizeVariants, useRadiusClassName, useSizeClassName } from '../../core/variants';
4
+
5
+ import { TagStyle } from './tag.style';
6
+
7
+ import { useClassNames } from '@polpo/hooks';
8
+
9
+ export enum TagSize {
10
+ SMALL = 'small',
11
+ REGULAR = 'regular',
12
+ LARGE = 'large',
13
+ }
14
+
15
+ type TagProps = HTMLAttributes<HTMLElement> & {
16
+ children: React.ReactNode;
17
+ isSelected?: boolean;
18
+ size?: `${SizeVariants}`;
19
+ radius?: `${RadiusVariants}`;
20
+ };
21
+
22
+ export const Tag = ({
23
+ children,
24
+ className: customClassName = '',
25
+ isSelected = false,
26
+ size = SizeVariants.Medium,
27
+ radius = RadiusVariants.Medium,
28
+ ...props
29
+ }: TagProps) => {
30
+ const tagSize = useSizeClassName(size);
31
+ const tagRadius = useRadiusClassName(radius);
32
+ const className = useClassNames({
33
+ [customClassName]: !!customClassName,
34
+ [tagRadius]: true,
35
+ [tagSize]: true,
36
+ 'tag-selected': isSelected,
37
+ });
38
+
39
+ return (
40
+ <TagStyle className={className} {...props}>
41
+ {children}
42
+ </TagStyle>
43
+ );
44
+ };
@@ -0,0 +1,39 @@
1
+ import TooltipStory from '../tooltip/tooltip.stories';
2
+
3
+ import { ClickToCopy } from './click-to-copy';
4
+
5
+ import type { Meta, StoryObj } from '@storybook/react';
6
+
7
+ const meta: Meta<typeof ClickToCopy> = {
8
+ title: 'Tooltips/ClickToCopy',
9
+ component: ClickToCopy,
10
+ argTypes: {
11
+ position: TooltipStory.argTypes?.position,
12
+ offset: TooltipStory.argTypes?.offset,
13
+ children: { control: 'text' },
14
+ value: { control: 'text' },
15
+ tooltipText: { control: 'text' },
16
+ tooltipCopiedText: { control: 'text' },
17
+ copiedTextTimeout: { control: { type: 'range', min: 100, max: 2000, step: 100 } },
18
+ },
19
+ args: {
20
+ tooltipText: 'Copy to clipboard',
21
+ tooltipCopiedText: 'Copied!',
22
+ value: 'Hello world',
23
+ },
24
+ render: (args, { children }) => <ClickToCopy {...args}>{children}</ClickToCopy>,
25
+ decorators: [
26
+ Story => (
27
+ <Story>
28
+ <span>Hello world</span>
29
+ </Story>
30
+ ),
31
+ ],
32
+ };
33
+
34
+ export default meta;
35
+ type Story = StoryObj<typeof ClickToCopy>;
36
+
37
+ export const Default: Story = {
38
+ args: {},
39
+ };
@@ -0,0 +1,41 @@
1
+ import { useState } from 'react';
2
+
3
+ import { Tooltip, TooltipProps } from '../tooltip';
4
+
5
+ type ClickToCopyProps = {
6
+ children?: React.ReactNode;
7
+ position?: TooltipProps['position'];
8
+ offset?: TooltipProps['offset'];
9
+ value: string;
10
+ tooltipText: string;
11
+ tooltipCopiedText?: string;
12
+ copiedTextTimeout?: number;
13
+ };
14
+
15
+ export const ClickToCopy = ({
16
+ children,
17
+ value,
18
+ position,
19
+ offset,
20
+ tooltipText,
21
+ tooltipCopiedText,
22
+ copiedTextTimeout = 500,
23
+ }: ClickToCopyProps) => {
24
+ const [justCopied, setJustCopied] = useState(false);
25
+
26
+ const handleCopy = () => {
27
+ setJustCopied(true);
28
+ navigator.clipboard.writeText(value);
29
+ setTimeout(() => setJustCopied(false), copiedTextTimeout);
30
+ };
31
+
32
+ return (
33
+ <Tooltip
34
+ content={justCopied && tooltipCopiedText ? tooltipCopiedText : tooltipText}
35
+ position={position}
36
+ offset={offset}
37
+ >
38
+ <span onClick={handleCopy}>{children}</span>
39
+ </Tooltip>
40
+ );
41
+ };
@@ -0,0 +1 @@
1
+ export * from './click-to-copy';
@@ -0,0 +1,2 @@
1
+ export * from './click-to-copy';
2
+ export * from './tooltip';
@@ -0,0 +1 @@
1
+ export * from './tooltip';
@@ -0,0 +1,35 @@
1
+ import { Tooltip } from './tooltip';
2
+
3
+ import { POSITION } from '@polpo/helpers';
4
+
5
+ import type { Meta, StoryObj } from '@storybook/react';
6
+
7
+ const meta: Meta<typeof Tooltip> = {
8
+ title: 'Tooltips/Tooltip',
9
+ component: Tooltip,
10
+ argTypes: {
11
+ position: { control: 'inline-radio', options: Object.values(POSITION) },
12
+ offset: { control: { type: 'range', min: 0, max: 200, step: 1 } },
13
+ disabled: { control: 'boolean' },
14
+ content: { control: 'text' },
15
+ children: { control: false },
16
+ },
17
+ args: {
18
+ content: 'Tooltip content',
19
+ },
20
+ render: (args, { children }) => <Tooltip {...args}>{children}</Tooltip>,
21
+ decorators: [
22
+ Story => (
23
+ <Story>
24
+ <span>Hello world</span>
25
+ </Story>
26
+ ),
27
+ ],
28
+ };
29
+
30
+ export default meta;
31
+ type Story = StoryObj<typeof Tooltip>;
32
+
33
+ export const Default: Story = {
34
+ args: {},
35
+ };
@@ -0,0 +1,62 @@
1
+ import styled from 'styled-components';
2
+
3
+ export const TooltipStyle = styled.span`
4
+ background: ${props => props.theme.colors.background.main};
5
+ color: ${props => props.theme.colors.text.main};
6
+ font-size: ${props => props.theme.constants.typography.small.fontSize};
7
+ line-height: 1em;
8
+ border-radius: 5px;
9
+ position: fixed;
10
+ padding: 0.5em 1em;
11
+ z-index: 1000;
12
+ display: block;
13
+ animation: fadeIn 250ms ease-out;
14
+ border: 1px solid;
15
+
16
+ &::before {
17
+ content: '';
18
+ display: block;
19
+ background: ${props => props.theme.colors.background.main};
20
+ position: absolute;
21
+ z-index: 1;
22
+ width: 10px;
23
+ height: 10px;
24
+ border-left: 1px solid transparent;
25
+ border-top: 1px solid transparent;
26
+ border-right: 1px solid ${props => props.theme.colors.text.main};
27
+ border-bottom: 1px solid ${props => props.theme.colors.text.main};
28
+ border-radius: 0 0 3px 0;
29
+ }
30
+
31
+ &.left {
32
+ &::before {
33
+ top: 50%;
34
+ left: 100%;
35
+ transform: translate(-50%, -50%) rotate(-45deg);
36
+ }
37
+ }
38
+
39
+ &.right {
40
+ &::before {
41
+ top: 50%;
42
+ right: 100%;
43
+ transform: translate(50%, -50%) rotate(135deg);
44
+ }
45
+ }
46
+
47
+ &.top {
48
+ &::before {
49
+ top: 100%;
50
+ left: 50%;
51
+ transform: translate(-50%, -50%) rotate(45deg);
52
+ }
53
+ }
54
+
55
+ &.bottom {
56
+ &::before {
57
+ left: 50%;
58
+ bottom: 100%;
59
+ transform: translate(-50%, 50%) rotate(-135deg);
60
+ }
61
+ }
62
+ `;
@@ -0,0 +1,45 @@
1
+ import React, { cloneElement, ReactElement } from 'react';
2
+
3
+ import { Modal } from '../../modals';
4
+
5
+ import { TooltipStyle } from './tooltip.style';
6
+
7
+ import { POSITION } from '@polpo/helpers';
8
+ import { useClassNames, useEventListener, useModalInContainer } from '@polpo/hooks';
9
+
10
+ export type TooltipProps = {
11
+ position?: `${POSITION}`;
12
+ offset?: number | `${number}`;
13
+ disabled?: boolean;
14
+ children: React.ReactElement;
15
+ content: React.ReactNode;
16
+ };
17
+
18
+ export const Tooltip = ({ position = POSITION.top, children, content, offset = 5, disabled = false }: TooltipProps) => {
19
+ const { modalRef, containerRef, isVisible, setIsVisible, modalStyle } = useModalInContainer({
20
+ closeOnClickOutside: false,
21
+ position,
22
+ offset: 6 + +offset,
23
+ windowOffset: 10,
24
+ });
25
+
26
+ const classNames = useClassNames({
27
+ [position]: true,
28
+ });
29
+
30
+ useEventListener('mouseenter', () => setIsVisible(true), containerRef);
31
+ useEventListener('mouseleave', () => setIsVisible(false), containerRef);
32
+
33
+ if (disabled) return children;
34
+
35
+ return (
36
+ <>
37
+ {cloneElement(children as ReactElement, { ref: containerRef })}
38
+ <Modal isOpen={isVisible} id='tooltip' backdrop='none'>
39
+ <TooltipStyle ref={modalRef} style={modalStyle} className={classNames}>
40
+ <span className='tooltip-content'>{content}</span>
41
+ </TooltipStyle>
42
+ </Modal>
43
+ </>
44
+ );
45
+ };
@@ -0,0 +1,2 @@
1
+ export * from './typography.constants';
2
+ export * from './typography';
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+
3
+ export enum TypographyVariant {
4
+ HERO = 'hero',
5
+ HEADER1 = 'header1',
6
+ HEADER2 = 'header2',
7
+ HEADER3 = 'header3',
8
+ HEADER4 = 'header4',
9
+ BODY = 'body',
10
+ LABEL = 'label',
11
+ LABEL_FORM = 'label-form',
12
+ SMALL = 'small',
13
+ }
14
+
15
+ export const TypographyVariantsElements: Record<TypographyVariant, keyof React.ReactHTML> = {
16
+ [TypographyVariant.HERO]: 'h1',
17
+ [TypographyVariant.HEADER1]: 'h1',
18
+ [TypographyVariant.HEADER2]: 'h2',
19
+ [TypographyVariant.HEADER3]: 'h3',
20
+ [TypographyVariant.HEADER4]: 'h4',
21
+ [TypographyVariant.BODY]: 'p',
22
+ [TypographyVariant.LABEL]: 'span',
23
+ [TypographyVariant.LABEL_FORM]: 'label',
24
+ [TypographyVariant.SMALL]: 'small',
25
+ };
26
+
27
+ export const TypographyVariantsClassNames: Record<TypographyVariant, string> = {
28
+ [TypographyVariant.HERO]: 'hero',
29
+ [TypographyVariant.HEADER1]: 'header1',
30
+ [TypographyVariant.HEADER2]: 'header2',
31
+ [TypographyVariant.HEADER3]: 'header3',
32
+ [TypographyVariant.HEADER4]: 'header4',
33
+ [TypographyVariant.BODY]: 'body',
34
+ [TypographyVariant.LABEL]: 'label',
35
+ [TypographyVariant.LABEL_FORM]: 'label',
36
+ [TypographyVariant.SMALL]: 'small',
37
+ };
38
+
39
+ export enum TypographyWeight {
40
+ LIGHT = 'light',
41
+ REGULAR = 'regular',
42
+ BOLD = 'bold',
43
+ }
@@ -0,0 +1,106 @@
1
+ import { Grid } from '../../layouts';
2
+
3
+ import { Typography } from './typography';
4
+ import { TypographyVariant, TypographyWeight } from './typography.constants';
5
+
6
+ import type { Meta, StoryObj } from '@storybook/react';
7
+
8
+ const meta: Meta<typeof Typography> = {
9
+ title: 'Typography',
10
+ component: Typography,
11
+ argTypes: {
12
+ variant: { control: 'inline-radio', options: Object.values(TypographyVariant) },
13
+ weight: { control: 'inline-radio', options: Object.values(TypographyWeight) },
14
+ nowrap: { control: 'boolean' },
15
+ recommendedWith: { control: 'boolean' },
16
+ as: { control: false },
17
+ children: { control: 'text' },
18
+ noPadding: { control: 'boolean' },
19
+ align: { control: 'inline-radio', options: ['left', 'center', 'right'] },
20
+ family: { control: 'inline-radio', options: ['primary', 'code'] },
21
+ className: { control: false },
22
+ style: { control: false },
23
+ htmlFor: { control: false },
24
+ },
25
+ args: {
26
+ children: 'Hello world',
27
+ },
28
+ };
29
+
30
+ export default meta;
31
+ type Story = StoryObj<typeof Typography>;
32
+
33
+ export const Default: Story = {
34
+ args: {},
35
+ decorators: [
36
+ Story => (
37
+ <Grid gap={16} gtc='500px'>
38
+ <Story />
39
+ <Typography>
40
+ Sample text to compare, lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa cumque dolores
41
+ doloribus, eaque earum eligendi est excepturi explicabo inventore, perferendis, quisquam recusandae ullam
42
+ voluptatum. Dolores?
43
+ </Typography>
44
+ </Grid>
45
+ ),
46
+ ],
47
+ };
48
+
49
+ export const Paragraph: Story = {
50
+ args: {
51
+ weight: 'light',
52
+ },
53
+ argTypes: {
54
+ children: { control: false },
55
+ variant: { control: false },
56
+ },
57
+ decorators: [],
58
+ render: args => (
59
+ <Grid gtc='500px'>
60
+ <Typography {...args} variant='body'>
61
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad at deserunt, dolorum eum necessitatibus, nihil
62
+ nobis placeat qui quidem repellat, temporibus totam voluptates. Accusamus amet aspernatur atque dolorum eligendi
63
+ est fugiat, illum labore, nam nobis obcaecati perferendis quod recusandae sed?
64
+ </Typography>
65
+ </Grid>
66
+ ),
67
+ };
68
+
69
+ export const Variants: Story = {
70
+ args: {
71
+ weight: 'light',
72
+ },
73
+ argTypes: {
74
+ children: { control: false },
75
+ variant: { control: false },
76
+ },
77
+ decorators: [],
78
+ render: args => (
79
+ <Grid>
80
+ <Typography {...args} variant='hero'>
81
+ Hero
82
+ </Typography>
83
+ <Typography {...args} variant='header1'>
84
+ Header1
85
+ </Typography>
86
+ <Typography {...args} variant='header2'>
87
+ Header2
88
+ </Typography>
89
+ <Typography {...args} variant='header3'>
90
+ Header3
91
+ </Typography>
92
+ <Typography {...args} variant='header4'>
93
+ Header4
94
+ </Typography>
95
+ <Typography {...args} variant='body'>
96
+ Body
97
+ </Typography>
98
+ <Typography {...args} variant='label'>
99
+ Label
100
+ </Typography>
101
+ <Typography {...args} variant='small'>
102
+ Small
103
+ </Typography>
104
+ </Grid>
105
+ ),
106
+ };
@@ -0,0 +1,76 @@
1
+ import { createGlobalStyle, css } from 'styled-components';
2
+
3
+ export const TypographyStyle = createGlobalStyle(({ theme: { constants } }) =>
4
+ Object.entries(constants.typography).map(
5
+ ([key, { breakpoints, fontSize, lineHeight, defaultWeight, weights }]) => css`
6
+ .${key} {
7
+ font-size: ${fontSize};
8
+ line-height: ${lineHeight};
9
+ font-weight: ${defaultWeight};
10
+ margin: 0;
11
+ padding: 0.5em 0 0.4em;
12
+
13
+ &.recommended-width {
14
+ max-width: 70ch;
15
+ }
16
+
17
+ &.code-family {
18
+ font-family: monospace;
19
+ }
20
+
21
+ &.no-padding {
22
+ padding: 0;
23
+ }
24
+
25
+ &.nowrap {
26
+ overflow: hidden;
27
+ text-overflow: ellipsis;
28
+ white-space: nowrap;
29
+ }
30
+
31
+ &.nowrap-max-lines {
32
+ overflow: hidden;
33
+ display: -webkit-box;
34
+ -webkit-box-orient: vertical;
35
+ }
36
+
37
+ &.nowrap-max-lines-2 {
38
+ -webkit-line-clamp: 2;
39
+ line-clamp: 2;
40
+ }
41
+
42
+ &.nowrap-max-lines-3 {
43
+ -webkit-line-clamp: 3;
44
+ line-clamp: 3;
45
+ }
46
+
47
+ &.nowrap-max-lines-4 {
48
+ -webkit-line-clamp: 4;
49
+ line-clamp: 4;
50
+ }
51
+
52
+ &.nowrap-max-lines-5 {
53
+ -webkit-line-clamp: 5;
54
+ line-clamp: 5;
55
+ }
56
+
57
+ ${Object.entries(weights).map(
58
+ ([fontWeight, weight]) => css`
59
+ &.${fontWeight} {
60
+ font-weight: ${weight};
61
+ }
62
+ `,
63
+ )}
64
+
65
+ ${breakpoints.map(
66
+ ({ fontSize, lineHeight, from }) => css`
67
+ @media all and (min-width: ${constants.breakpoints[from as keyof typeof constants.breakpoints]}) {
68
+ font-size: ${fontSize};
69
+ line-height: ${lineHeight};
70
+ }
71
+ `,
72
+ )}
73
+ }
74
+ `,
75
+ ),
76
+ );
@@ -0,0 +1,79 @@
1
+ import React, { HTMLAttributes, createElement, forwardRef, useMemo } from 'react';
2
+
3
+ import {
4
+ TypographyVariant,
5
+ TypographyVariantsClassNames,
6
+ TypographyVariantsElements,
7
+ TypographyWeight,
8
+ } from './typography.constants';
9
+
10
+ import { useClassNames } from '@polpo/hooks';
11
+
12
+ type TypographyProps = HTMLAttributes<HTMLElement | HTMLLabelElement> & {
13
+ variant?: `${TypographyVariant}`;
14
+ nowrap?: boolean | number;
15
+ as?: keyof React.ReactHTML;
16
+ weight?: `${TypographyWeight}`;
17
+ children: React.ReactNode;
18
+ noPadding?: boolean;
19
+ htmlFor?: string;
20
+ align?: React.CSSProperties['textAlign'];
21
+ family?: 'primary' | 'code';
22
+ recommendedWidth?: boolean;
23
+ };
24
+
25
+ export const TypographyComponent = (
26
+ {
27
+ variant = 'body',
28
+ nowrap = false,
29
+ className: customClassname = '',
30
+ style = {},
31
+ children,
32
+ as,
33
+ weight,
34
+ family = 'primary',
35
+ noPadding = false,
36
+ align,
37
+ htmlFor,
38
+ recommendedWidth = false,
39
+ ...props
40
+ }: TypographyProps,
41
+ ref: React.ForwardedRef<unknown>,
42
+ ) => {
43
+ const className = useClassNames({
44
+ [TypographyVariantsClassNames[variant]]: TypographyVariantsClassNames[variant] !== undefined,
45
+ [customClassname]: !!customClassname,
46
+ [weight ?? '']: !!weight,
47
+ 'no-padding': noPadding,
48
+ 'code-family': family === 'code',
49
+ 'recommended-width': recommendedWidth,
50
+ 'nowrap-max-lines': typeof nowrap === 'number',
51
+ 'nowrap-max-lines-2': nowrap === 2,
52
+ 'nowrap-max-lines-3': nowrap === 3,
53
+ 'nowrap-max-lines-4': nowrap === 4,
54
+ 'nowrap-max-lines-5': nowrap === 5,
55
+ nowrap: nowrap === true,
56
+ });
57
+
58
+ const component = useMemo(
59
+ () => TypographyVariantsElements[variant] ?? TypographyVariantsElements[TypographyVariant.BODY],
60
+ [variant],
61
+ );
62
+
63
+ return createElement(
64
+ as ?? component,
65
+ {
66
+ ...props,
67
+ className,
68
+ ref,
69
+ htmlFor,
70
+ style: {
71
+ textAlign: align,
72
+ ...style,
73
+ },
74
+ },
75
+ children,
76
+ );
77
+ };
78
+
79
+ export const Typography = forwardRef(TypographyComponent);