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.
- package/.eslintrc.cjs +9 -0
- package/.storybook/decorators.tsx +61 -0
- package/.storybook/main.ts +47 -0
- package/.storybook/manager-head.html +2 -0
- package/.storybook/manager.ts +7 -0
- package/.storybook/preview-head.html +2 -0
- package/.storybook/preview.ts +38 -0
- package/.storybook/theme.ts +47 -0
- package/.turbo/daemon/f5c5c8fb195b01d0-turbo.log.2024-05-26 +0 -0
- package/.turbo/turbo-build$colon$watch.log +96 -0
- package/.turbo/turbo-build-storybook.log +0 -0
- package/.turbo/turbo-build.log +77 -0
- package/.turbo/turbo-lint$colon$fix.log +2 -0
- package/.turbo/turbo-lint.log +4 -0
- package/README.md +68 -0
- package/dist/chunk-M4KRSYE7.js +3 -0
- package/dist/chunk-M4KRSYE7.js.map +1 -0
- package/dist/chunk-U5XSMSKZ.js +3 -0
- package/dist/chunk-U5XSMSKZ.js.map +1 -0
- package/dist/get-modal-position-DPftPoU2.d.cts +28 -0
- package/dist/get-modal-position-DPftPoU2.d.ts +28 -0
- package/dist/helpers.cjs +3 -0
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.d.cts +15 -0
- package/dist/helpers.d.ts +15 -0
- package/dist/helpers.js +3 -0
- package/dist/helpers.js.map +1 -0
- package/dist/hooks.cjs +3 -0
- package/dist/hooks.cjs.map +1 -0
- package/dist/hooks.d.cts +121 -0
- package/dist/hooks.d.ts +121 -0
- package/dist/hooks.js +3 -0
- package/dist/hooks.js.map +1 -0
- package/dist/ui.cjs +1987 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.cts +3932 -0
- package/dist/ui.d.ts +3932 -0
- package/dist/ui.js +1987 -0
- package/dist/ui.js.map +1 -0
- package/package.json +98 -0
- package/src/components/accordion/accordion-item.stories.tsx +128 -0
- package/src/components/accordion/accordion-item.tsx +119 -0
- package/src/components/accordion/accordion.stories.tsx +74 -0
- package/src/components/accordion/accordion.style.ts +42 -0
- package/src/components/accordion/accordion.tsx +56 -0
- package/src/components/accordion/index.ts +2 -0
- package/src/components/buttons/button/button.stories.tsx +103 -0
- package/src/components/buttons/button/button.style.ts +147 -0
- package/src/components/buttons/button/button.tsx +119 -0
- package/src/components/buttons/button/index.ts +1 -0
- package/src/components/buttons/index.ts +1 -0
- package/src/components/cards/flip-card/flip-card.stories.tsx +61 -0
- package/src/components/cards/flip-card/flip-card.style.ts +45 -0
- package/src/components/cards/flip-card/flip-card.tsx +55 -0
- package/src/components/cards/flip-card/index.ts +1 -0
- package/src/components/cards/hover-card/hover-card.stories.tsx +45 -0
- package/src/components/cards/hover-card/hover-card.style.ts +13 -0
- package/src/components/cards/hover-card/hover-card.tsx +71 -0
- package/src/components/cards/hover-card/index.ts +1 -0
- package/src/components/cards/index.ts +3 -0
- package/src/components/cards/slide-card/index.ts +1 -0
- package/src/components/cards/slide-card/slide-card.stories.tsx +47 -0
- package/src/components/cards/slide-card/slide-card.tsx +42 -0
- package/src/components/form/checkbox/checkbox.stories.tsx +34 -0
- package/src/components/form/checkbox/checkbox.style.ts +75 -0
- package/src/components/form/checkbox/checkbox.tsx +76 -0
- package/src/components/form/checkbox/index.ts +1 -0
- package/src/components/form/controller/controller.tsx +42 -0
- package/src/components/form/controller/index.ts +1 -0
- package/src/components/form/date-picker/date-picker.stories.tsx +38 -0
- package/src/components/form/date-picker/date-picker.tsx +67 -0
- package/src/components/form/date-picker/index.ts +1 -0
- package/src/components/form/field/field.stories.tsx +49 -0
- package/src/components/form/field/field.style.ts +79 -0
- package/src/components/form/field/field.tsx +83 -0
- package/src/components/form/field/field.types.ts +28 -0
- package/src/components/form/field/index.ts +2 -0
- package/src/components/form/form.stories.types.tsx +50 -0
- package/src/components/form/form.types.ts +37 -0
- package/src/components/form/index.ts +14 -0
- package/src/components/form/input/index.ts +1 -0
- package/src/components/form/input/input.stories.tsx +41 -0
- package/src/components/form/input/input.tsx +73 -0
- package/src/components/form/input-color/index.ts +1 -0
- package/src/components/form/input-color/input-color.stories.tsx +46 -0
- package/src/components/form/input-color/input-color.style.ts +93 -0
- package/src/components/form/input-color/input-color.tsx +159 -0
- package/src/components/form/input-file/index.ts +1 -0
- package/src/components/form/input-file/input-file.stories.tsx +40 -0
- package/src/components/form/input-file/input-file.style.ts +143 -0
- package/src/components/form/input-file/input-file.tsx +214 -0
- package/src/components/form/input-password/index.ts +1 -0
- package/src/components/form/input-password/input-password.stories.tsx +37 -0
- package/src/components/form/input-password/input-password.tsx +83 -0
- package/src/components/form/radio/index.ts +1 -0
- package/src/components/form/radio/radio.stories.tsx +43 -0
- package/src/components/form/radio/radio.style.ts +58 -0
- package/src/components/form/radio/radio.tsx +76 -0
- package/src/components/form/select/index.ts +1 -0
- package/src/components/form/select/options.tsx +140 -0
- package/src/components/form/select/select-option.tsx +84 -0
- package/src/components/form/select/select.stories.tsx +89 -0
- package/src/components/form/select/select.style.ts +164 -0
- package/src/components/form/select/select.tsx +327 -0
- package/src/components/form/select/select.types.ts +93 -0
- package/src/components/form/slider/index.ts +1 -0
- package/src/components/form/slider/slider.stories.tsx +40 -0
- package/src/components/form/slider/slider.style.ts +90 -0
- package/src/components/form/slider/slider.tsx +108 -0
- package/src/components/form/switch/index.ts +1 -0
- package/src/components/form/switch/switch.stories.tsx +38 -0
- package/src/components/form/switch/switch.style.ts +120 -0
- package/src/components/form/switch/switch.tsx +111 -0
- package/src/components/form/textarea/index.ts +1 -0
- package/src/components/form/textarea/textarea.stories.tsx +43 -0
- package/src/components/form/textarea/textarea.style.ts +7 -0
- package/src/components/form/textarea/textarea.tsx +76 -0
- package/src/components/icon/icon.stories.tsx +63 -0
- package/src/components/icon/icon.tsx +64 -0
- package/src/components/icon/icons/index.ts +18 -0
- package/src/components/icon/icons/object.tsx +482 -0
- package/src/components/icon/icons/social.tsx +72 -0
- package/src/components/icon/icons/symbol.tsx +776 -0
- package/src/components/icon/index.ts +5 -0
- package/src/components/image/image.stories.tsx +25 -0
- package/src/components/image/image.tsx +7 -0
- package/src/components/image/index.ts +1 -0
- package/src/components/index.ts +16 -0
- package/src/components/infinity-scroll/index.ts +1 -0
- package/src/components/infinity-scroll/infinity-scroll.stories.tsx +75 -0
- package/src/components/infinity-scroll/infinity-scroll.style.ts +30 -0
- package/src/components/infinity-scroll/infinity-scroll.tsx +56 -0
- package/src/components/line/index.ts +1 -0
- package/src/components/line/line.stories.tsx +67 -0
- package/src/components/line/line.style.ts +57 -0
- package/src/components/line/line.tsx +76 -0
- package/src/components/loaders/index.ts +1 -0
- package/src/components/loaders/simple-loader/index.ts +1 -0
- package/src/components/loaders/simple-loader/simple-loader.stories.tsx +21 -0
- package/src/components/loaders/simple-loader/simple-loader.style.ts +13 -0
- package/src/components/loaders/simple-loader/simple-loader.tsx +15 -0
- package/src/components/modals/action-modal/action-modal.stories.tsx +134 -0
- package/src/components/modals/action-modal/action-modal.style.ts +129 -0
- package/src/components/modals/action-modal/action-modal.tsx +150 -0
- package/src/components/modals/action-modal/index.ts +1 -0
- package/src/components/modals/aside-modal/aside-modal.stories.tsx +82 -0
- package/src/components/modals/aside-modal/aside-modal.style.ts +108 -0
- package/src/components/modals/aside-modal/aside-modal.tsx +66 -0
- package/src/components/modals/aside-modal/index.ts +1 -0
- package/src/components/modals/confirmation-modal/confirmation-modal.stories.tsx +50 -0
- package/src/components/modals/confirmation-modal/confirmation-modal.style.ts +17 -0
- package/src/components/modals/confirmation-modal/confirmation-modal.tsx +43 -0
- package/src/components/modals/confirmation-modal/index.ts +1 -0
- package/src/components/modals/index.ts +4 -0
- package/src/components/modals/modal/index.ts +1 -0
- package/src/components/modals/modal/modal.style.ts +10 -0
- package/src/components/modals/modal/modal.tsx +132 -0
- package/src/components/ripple/index.ts +1 -0
- package/src/components/ripple/ripple.stories.tsx +38 -0
- package/src/components/ripple/ripple.style.ts +33 -0
- package/src/components/ripple/ripple.tsx +63 -0
- package/src/components/smart-table/index.ts +1 -0
- package/src/components/smart-table/smart-table.column.tsx +63 -0
- package/src/components/smart-table/smart-table.helpers.tsx +59 -0
- package/src/components/smart-table/smart-table.hooks.ts +27 -0
- package/src/components/smart-table/smart-table.row.tsx +29 -0
- package/src/components/smart-table/smart-table.stories.tsx +301 -0
- package/src/components/smart-table/smart-table.style.ts +102 -0
- package/src/components/smart-table/smart-table.tsx +112 -0
- package/src/components/smart-table/smart-table.types.ts +41 -0
- package/src/components/tabs/index.ts +1 -0
- package/src/components/tabs/tabs-container.stories.tsx +159 -0
- package/src/components/tabs/tabs-list.tsx +131 -0
- package/src/components/tabs/tabs.stories.tsx +68 -0
- package/src/components/tabs/tabs.style.ts +132 -0
- package/src/components/tabs/tabs.tsx +117 -0
- package/src/components/tag/index.ts +1 -0
- package/src/components/tag/tag.stories.tsx +49 -0
- package/src/components/tag/tag.style.ts +24 -0
- package/src/components/tag/tag.tsx +44 -0
- package/src/components/tooltips/click-to-copy/click-to-copy.stories.tsx +39 -0
- package/src/components/tooltips/click-to-copy/click-to-copy.tsx +41 -0
- package/src/components/tooltips/click-to-copy/index.ts +1 -0
- package/src/components/tooltips/index.ts +2 -0
- package/src/components/tooltips/tooltip/index.ts +1 -0
- package/src/components/tooltips/tooltip/tooltip.stories.tsx +35 -0
- package/src/components/tooltips/tooltip/tooltip.style.ts +62 -0
- package/src/components/tooltips/tooltip/tooltip.tsx +45 -0
- package/src/components/typography/index.ts +2 -0
- package/src/components/typography/typography.constants.ts +43 -0
- package/src/components/typography/typography.stories.tsx +106 -0
- package/src/components/typography/typography.style.ts +76 -0
- package/src/components/typography/typography.tsx +79 -0
- package/src/contexts/fetch-context/fetch-context.tsx +114 -0
- package/src/contexts/fetch-context/index.ts +1 -0
- package/src/contexts/form-context/form-context.tsx +43 -0
- package/src/contexts/form-context/index.ts +1 -0
- package/src/contexts/index.ts +3 -0
- package/src/contexts/theme-context/index.ts +3 -0
- package/src/contexts/theme-context/theme-context.tsx +158 -0
- package/src/contexts/theme-context/theme.animations.ts +180 -0
- package/src/contexts/theme-context/theme.defaults.ts +205 -0
- package/src/contexts/theme-context/theme.style.ts +78 -0
- package/src/contexts/theme-context/themes.ts +96 -0
- package/src/core/http-client.d.ts +11 -0
- package/src/core/http-client.d.ts.map +1 -0
- package/src/core/http-client.ts +47 -0
- package/src/core/index.d.ts +2 -0
- package/src/core/index.d.ts.map +1 -0
- package/src/core/index.ts +1 -0
- package/src/core/variants/color.ts +36 -0
- package/src/core/variants/index.ts +3 -0
- package/src/core/variants/radius.ts +56 -0
- package/src/core/variants/size.ts +44 -0
- package/src/helpers/format-bytes.ts +11 -0
- package/src/helpers/format-dates.ts +11 -0
- package/src/helpers/get-modal-position.ts +66 -0
- package/src/helpers/index.ts +4 -0
- package/src/helpers/text/index.ts +1 -0
- package/src/helpers/text/to-capitalize.ts +17 -0
- package/src/hooks/index.ts +23 -0
- package/src/hooks/use-async.ts +88 -0
- package/src/hooks/use-classnames.ts +13 -0
- package/src/hooks/use-constant.ts +3 -0
- package/src/hooks/use-debounce.ts +15 -0
- package/src/hooks/use-dimensions.ts +22 -0
- package/src/hooks/use-event-listener.ts +71 -0
- package/src/hooks/use-file-reader.ts +69 -0
- package/src/hooks/use-hover.ts +17 -0
- package/src/hooks/use-in-view.ts +20 -0
- package/src/hooks/use-input-handlers.ts +49 -0
- package/src/hooks/use-media-query.ts +25 -0
- package/src/hooks/use-modal-in-container.ts +94 -0
- package/src/hooks/use-mouse-position.ts +16 -0
- package/src/hooks/use-observer.ts +18 -0
- package/src/hooks/use-on-click-outside-ref.ts +17 -0
- package/src/hooks/use-online-status.ts +12 -0
- package/src/hooks/use-render-count.ts +11 -0
- package/src/hooks/use-safe-dispatch.ts +22 -0
- package/src/hooks/use-scroll.ts +31 -0
- package/src/hooks/use-state-history.ts +22 -0
- package/src/hooks/use-toggle-values.ts +14 -0
- package/src/hooks/use-toggle.ts +11 -0
- package/src/hooks/use-viewport.ts +38 -0
- package/src/index.ts +5 -0
- package/src/layouts/flex/flex.tsx +75 -0
- package/src/layouts/flex/index.ts +1 -0
- package/src/layouts/grid/grid.tsx +86 -0
- package/src/layouts/grid/index.ts +1 -0
- package/src/layouts/index.ts +3 -0
- package/src/layouts/section-layout/index.ts +1 -0
- package/src/layouts/section-layout/section-layout.stories.tsx +55 -0
- package/src/layouts/section-layout/section-layout.style.ts +21 -0
- package/src/layouts/section-layout/section-layout.tsx +46 -0
- package/src/stories/GettingStarted.mdx +66 -0
- package/src/types/generics.ts +68 -0
- package/src/types/index.ts +1 -0
- package/svg/Name=airplane, Category=object.svg +3 -0
- package/svg/Name=arrow-circle, Category=symbol.svg +3 -0
- package/svg/Name=arrow-down, Category=symbol.svg +3 -0
- package/svg/Name=arrow-left, Category=symbol.svg +3 -0
- package/svg/Name=arrow-right, Category=symbol.svg +3 -0
- package/svg/Name=arrow-up, Category=symbol.svg +3 -0
- package/svg/Name=bell, Category=object.svg +3 -0
- package/svg/Name=bicycle, Category=object.svg +3 -0
- package/svg/Name=book-open, Category=object.svg +3 -0
- package/svg/Name=book-solid, Category=object.svg +6 -0
- package/svg/Name=box-shadow, Category=symbol.svg +5 -0
- package/svg/Name=calendar, Category=object.svg +3 -0
- package/svg/Name=camera, Category=object.svg +3 -0
- package/svg/Name=caret-down, Category=symbol.svg +3 -0
- package/svg/Name=caret-left, Category=symbol.svg +3 -0
- package/svg/Name=caret-right, Category=symbol.svg +3 -0
- package/svg/Name=caret-up, Category=symbol.svg +3 -0
- package/svg/Name=checkmark, Category=symbol.svg +3 -0
- package/svg/Name=clean-computer, Category=object.svg +10 -0
- package/svg/Name=codepen, Category=social.svg +3 -0
- package/svg/Name=creative, Category=symbol.svg +5 -0
- package/svg/Name=cross, Category=symbol.svg +4 -0
- package/svg/Name=crossed-flags, Category=object.svg +4 -0
- package/svg/Name=cv, Category=symbol.svg +5 -0
- package/svg/Name=design-ui, Category=symbol.svg +9 -0
- package/svg/Name=document, Category=object.svg +3 -0
- package/svg/Name=door-closed, Category=object.svg +3 -0
- package/svg/Name=door-open, Category=object.svg +3 -0
- package/svg/Name=double-caret-down, Category=symbol.svg +4 -0
- package/svg/Name=double-caret-left, Category=symbol.svg +4 -0
- package/svg/Name=double-caret-righ, Category=symbol.svg +4 -0
- package/svg/Name=double-caret-up, Category=symbol.svg +4 -0
- package/svg/Name=download, Category=symbol.svg +5 -0
- package/svg/Name=dropper, Category=object.svg +5 -0
- package/svg/Name=envelope, Category=object.svg +3 -0
- package/svg/Name=exclamation-close, Category=symbol.svg +4 -0
- package/svg/Name=exclamation-open, Category=symbol.svg +4 -0
- package/svg/Name=external-link, Category=symbol.svg +3 -0
- package/svg/Name=eye, Category=object.svg +4 -0
- package/svg/Name=eye-hidden, Category=object.svg +7 -0
- package/svg/Name=facebook, Category=social.svg +3 -0
- package/svg/Name=form, Category=symbol.svg +8 -0
- package/svg/Name=game-control, Category=object.svg +3 -0
- package/svg/Name=gear, Category=object.svg +3 -0
- package/svg/Name=github, Category=social.svg +3 -0
- package/svg/Name=house, Category=object.svg +3 -0
- package/svg/Name=hyphen, Category=symbol.svg +3 -0
- package/svg/Name=info, Category=symbol.svg +3 -0
- package/svg/Name=instagram, Category=social.svg +3 -0
- package/svg/Name=link, Category=symbol.svg +5 -0
- package/svg/Name=linkedin, Category=social.svg +3 -0
- package/svg/Name=magnifying-glass, Category=object.svg +3 -0
- package/svg/Name=message, Category=symbol.svg +4 -0
- package/svg/Name=moon, Category=object.svg +5 -0
- package/svg/Name=order-list, Category=symbol.svg +7 -0
- package/svg/Name=pencil, Category=object.svg +3 -0
- package/svg/Name=pin-location, Category=symbol.svg +3 -0
- package/svg/Name=question-mark-close, Category=symbol.svg +3 -0
- package/svg/Name=question-mark-open, Category=symbol.svg +3 -0
- package/svg/Name=share, Category=symbol.svg +5 -0
- package/svg/Name=spinner, Category=symbol.svg +9 -0
- package/svg/Name=star, Category=object.svg +3 -0
- package/svg/Name=star-empty, Category=object.svg +3 -0
- package/svg/Name=sun, Category=object.svg +11 -0
- package/svg/Name=text-shadow, Category=symbol.svg +4 -0
- package/svg/Name=thinking, Category=symbol.svg +3 -0
- package/svg/Name=trash-can, Category=object.svg +4 -0
- package/svg/Name=upload, Category=symbol.svg +5 -0
- package/svg/Name=user, Category=symbol.svg +4 -0
- package/svg/Name=warning, Category=symbol.svg +5 -0
- package/svg/Name=whatsapp, Category=social.svg +3 -0
- package/svgconfig.json +4 -0
- package/tsconfig.json +14 -0
- package/tsup.config.cjs +21 -0
- package/vite.config.ts +13 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import styled, { createGlobalStyle } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export const ThemeStyle = styled.main`
|
|
4
|
+
height: 100dvh;
|
|
5
|
+
overflow: auto;
|
|
6
|
+
background: ${props => props.theme.colors.background.main};
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
export const GlobalStyles = createGlobalStyle`
|
|
10
|
+
*, *::before, *::after {
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* width */
|
|
15
|
+
::-webkit-scrollbar {
|
|
16
|
+
width: 0;
|
|
17
|
+
height: 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* Track */
|
|
21
|
+
::-webkit-scrollbar-track {
|
|
22
|
+
border-radius: 10px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* Handle */
|
|
26
|
+
::-webkit-scrollbar-thumb {
|
|
27
|
+
background: #cecece;
|
|
28
|
+
border-radius: 10px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/* Handle on hover */
|
|
32
|
+
::-webkit-scrollbar-thumb:hover {
|
|
33
|
+
background: #cecece;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
:root {
|
|
37
|
+
color-scheme: light dark;
|
|
38
|
+
font-synthesis: none;
|
|
39
|
+
text-rendering: optimizeLegibility;
|
|
40
|
+
-webkit-font-smoothing: antialiased;
|
|
41
|
+
-moz-osx-font-smoothing: grayscale;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
*, *::after, *::before {
|
|
45
|
+
box-sizing: border-box;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
html {
|
|
49
|
+
scroll-behavior: smooth;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
a {
|
|
53
|
+
text-decoration: none;
|
|
54
|
+
color: inherit;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
input, textarea {
|
|
58
|
+
color: currentColor;
|
|
59
|
+
font-family: inherit;
|
|
60
|
+
padding: 0;
|
|
61
|
+
margin: 0;
|
|
62
|
+
width: 100%;
|
|
63
|
+
background: transparent;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
input {
|
|
67
|
+
border: 0;
|
|
68
|
+
outline: 0;
|
|
69
|
+
padding: 0;
|
|
70
|
+
width: 100%;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
body, ${ThemeStyle} {
|
|
74
|
+
min-width: ${props => props.theme.constants.breakpoints.mobile};
|
|
75
|
+
font-family: ${props => props.theme.constants.fontFamily};
|
|
76
|
+
color: ${props => props.theme.colors.text.main};
|
|
77
|
+
}
|
|
78
|
+
`;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export enum TypographyVariants {
|
|
4
|
+
HERO = 'hero',
|
|
5
|
+
HEADER1 = 'header1',
|
|
6
|
+
HEADER2 = 'header2',
|
|
7
|
+
HEADER3 = 'header3',
|
|
8
|
+
HEADER4 = 'header4',
|
|
9
|
+
BODY = 'body',
|
|
10
|
+
LABEL = 'label',
|
|
11
|
+
SMALL = 'small',
|
|
12
|
+
}
|
|
13
|
+
export enum Breakpoints {
|
|
14
|
+
MOBILE = 'mobile',
|
|
15
|
+
MOBILE_L = 'mobileL',
|
|
16
|
+
TABLET = 'tablet',
|
|
17
|
+
LAPTOPS = 'laptopS',
|
|
18
|
+
LAPTOP_M = 'laptopM',
|
|
19
|
+
LAPTOP_L = 'laptopL',
|
|
20
|
+
DESKTOP = 'desktop',
|
|
21
|
+
LARGE = 'large',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type TypographyEntity = {
|
|
25
|
+
fontSize: string;
|
|
26
|
+
lineHeight: string;
|
|
27
|
+
defaultWeight: React.CSSProperties['fontWeight'];
|
|
28
|
+
weights: Record<string, React.CSSProperties['fontWeight']>;
|
|
29
|
+
breakpoints: Array<{
|
|
30
|
+
from: `${Breakpoints}`;
|
|
31
|
+
fontSize: string;
|
|
32
|
+
lineHeight: string;
|
|
33
|
+
}>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type ThemeConstantsEntity = {
|
|
37
|
+
fontFamily: string;
|
|
38
|
+
sectionMinHeight: string;
|
|
39
|
+
breakpoints: Record<`${Breakpoints}`, string>;
|
|
40
|
+
typography: Record<`${TypographyVariants}`, TypographyEntity>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type ThemeColor = {
|
|
44
|
+
main: string;
|
|
45
|
+
contrast: string;
|
|
46
|
+
light: string;
|
|
47
|
+
dark: string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type CommonThemeEntity = {
|
|
51
|
+
black: string;
|
|
52
|
+
white: string;
|
|
53
|
+
gray1: string;
|
|
54
|
+
gray2: string;
|
|
55
|
+
gray3: string;
|
|
56
|
+
gray4: string;
|
|
57
|
+
gray5: string;
|
|
58
|
+
gray6: string;
|
|
59
|
+
gray7: string;
|
|
60
|
+
gray8: string;
|
|
61
|
+
gray9: string;
|
|
62
|
+
info: ThemeColor;
|
|
63
|
+
active: ThemeColor;
|
|
64
|
+
warning: ThemeColor;
|
|
65
|
+
alert: ThemeColor;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type PaletteThemeEntity = {
|
|
69
|
+
background: {
|
|
70
|
+
main: string;
|
|
71
|
+
paper: string;
|
|
72
|
+
disabled: string;
|
|
73
|
+
};
|
|
74
|
+
text: {
|
|
75
|
+
main: string;
|
|
76
|
+
light: string;
|
|
77
|
+
dark: string;
|
|
78
|
+
disabled: string;
|
|
79
|
+
};
|
|
80
|
+
border: {
|
|
81
|
+
main: string;
|
|
82
|
+
};
|
|
83
|
+
primary: ThemeColor;
|
|
84
|
+
secondary: ThemeColor;
|
|
85
|
+
tertiary: ThemeColor;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type ThemeEntity = PaletteThemeEntity & CommonThemeEntity;
|
|
89
|
+
|
|
90
|
+
declare module 'styled-components' {
|
|
91
|
+
export interface DefaultTheme {
|
|
92
|
+
name: string;
|
|
93
|
+
colors: ThemeEntity;
|
|
94
|
+
constants: ThemeConstantsEntity;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
export declare class HttpClient {
|
|
3
|
+
private _instance;
|
|
4
|
+
private _token;
|
|
5
|
+
logout: () => void;
|
|
6
|
+
constructor(baseURL: string);
|
|
7
|
+
get instance(): AxiosInstance;
|
|
8
|
+
get token(): string;
|
|
9
|
+
set token(token: string);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=http-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["http-client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE7C,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,MAAM,CAAS;IAEhB,MAAM,aAA0C;gBAE3C,OAAO,EAAE,MAAM;IA0B3B,IAAW,QAAQ,IAAI,aAAa,CAEnC;IAED,IAAW,KAAK,IAIQ,MAAM,CAF7B;IAED,IAAW,KAAK,CAAC,KAAK,EAAE,MAAM,EAG7B;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import axios, { AxiosInstance } from 'axios';
|
|
2
|
+
|
|
3
|
+
export class HttpClient {
|
|
4
|
+
private _instance: AxiosInstance;
|
|
5
|
+
private _token: string;
|
|
6
|
+
|
|
7
|
+
public logout = () => localStorage.removeItem('token');
|
|
8
|
+
|
|
9
|
+
constructor(baseURL: string) {
|
|
10
|
+
this._token = localStorage.getItem('token') ?? '';
|
|
11
|
+
|
|
12
|
+
this._instance = axios.create({
|
|
13
|
+
baseURL: baseURL,
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
this._instance.interceptors.request.use(req => {
|
|
20
|
+
const token = this.token;
|
|
21
|
+
token !== null && req.headers.setAuthorization(`Bearer ${token}`);
|
|
22
|
+
|
|
23
|
+
return req;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
this._instance.interceptors.response.use(
|
|
27
|
+
response => Promise.resolve(response),
|
|
28
|
+
error => {
|
|
29
|
+
error.response.status === 401 && this.logout();
|
|
30
|
+
Promise.reject(error);
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public get instance(): AxiosInstance {
|
|
36
|
+
return this._instance;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public get token() {
|
|
40
|
+
return this._token;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public set token(token: string) {
|
|
44
|
+
this._token = token;
|
|
45
|
+
localStorage.setItem('token', token);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './http-client';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useClassNames } from '@polpo/hooks';
|
|
2
|
+
|
|
3
|
+
export enum ColorVariants {
|
|
4
|
+
Primary = 'small',
|
|
5
|
+
Secondary = 'medium',
|
|
6
|
+
Tertiary = 'large',
|
|
7
|
+
Info = 'info',
|
|
8
|
+
Active = 'active',
|
|
9
|
+
Warning = 'warning',
|
|
10
|
+
Alert = 'alert',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const getColorVariantClassName = (size: `${ColorVariants}`) => {
|
|
14
|
+
return `${size}-color`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const ColorClassNames: Record<keyof typeof ColorVariants, string> = {
|
|
18
|
+
Primary: getColorVariantClassName(ColorVariants.Primary),
|
|
19
|
+
Secondary: getColorVariantClassName(ColorVariants.Secondary),
|
|
20
|
+
Tertiary: getColorVariantClassName(ColorVariants.Tertiary),
|
|
21
|
+
Info: getColorVariantClassName(ColorVariants.Info),
|
|
22
|
+
Active: getColorVariantClassName(ColorVariants.Active),
|
|
23
|
+
Warning: getColorVariantClassName(ColorVariants.Warning),
|
|
24
|
+
Alert: getColorVariantClassName(ColorVariants.Alert),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const useColorClassName = (size: `${ColorVariants}`) =>
|
|
28
|
+
useClassNames(
|
|
29
|
+
Object.entries(ColorVariants).reduce(
|
|
30
|
+
(object, [key, value]) => ({
|
|
31
|
+
...object,
|
|
32
|
+
[ColorClassNames[key as keyof typeof ColorVariants]]: size === value,
|
|
33
|
+
}),
|
|
34
|
+
{},
|
|
35
|
+
),
|
|
36
|
+
);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { css } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
import { useClassNames } from '@polpo/hooks';
|
|
4
|
+
|
|
5
|
+
export enum RadiusVariants {
|
|
6
|
+
None = 'none',
|
|
7
|
+
Small = 'small',
|
|
8
|
+
Medium = 'medium',
|
|
9
|
+
Large = 'large',
|
|
10
|
+
Full = 'full',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const getRadiusVariantClassName = (size: `${RadiusVariants}`) => {
|
|
14
|
+
return `${size}-radius`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const RadiusClassNames: Record<keyof typeof RadiusVariants, string> = {
|
|
18
|
+
None: getRadiusVariantClassName(RadiusVariants.None),
|
|
19
|
+
Small: getRadiusVariantClassName(RadiusVariants.Small),
|
|
20
|
+
Medium: getRadiusVariantClassName(RadiusVariants.Medium),
|
|
21
|
+
Large: getRadiusVariantClassName(RadiusVariants.Large),
|
|
22
|
+
Full: getRadiusVariantClassName(RadiusVariants.Full),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const useRadiusClassName = (size: `${RadiusVariants}`) =>
|
|
26
|
+
useClassNames(
|
|
27
|
+
Object.entries(RadiusVariants).reduce(
|
|
28
|
+
(object, [key, value]) => ({
|
|
29
|
+
...object,
|
|
30
|
+
[RadiusClassNames[key as keyof typeof RadiusVariants]]: size === value,
|
|
31
|
+
}),
|
|
32
|
+
{},
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const RadiusStyles = css`
|
|
37
|
+
&.${RadiusClassNames.None} {
|
|
38
|
+
border-radius: 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&.${RadiusClassNames.Small} {
|
|
42
|
+
border-radius: 0.5em;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&.${RadiusClassNames.Medium} {
|
|
46
|
+
border-radius: 1em;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
&.${RadiusClassNames.Large} {
|
|
50
|
+
border-radius: 1.5em;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
&.${RadiusClassNames.Full} {
|
|
54
|
+
border-radius: 100em;
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { css } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
import { useClassNames } from '@polpo/hooks';
|
|
4
|
+
|
|
5
|
+
export enum SizeVariants {
|
|
6
|
+
Small = 'small',
|
|
7
|
+
Medium = 'medium',
|
|
8
|
+
Large = 'large',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const getSizeVariantClassName = (size: `${SizeVariants}`) => {
|
|
12
|
+
return `${size}-size`;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const SizeClassNames: Record<keyof typeof SizeVariants, string> = {
|
|
16
|
+
Small: getSizeVariantClassName(SizeVariants.Small),
|
|
17
|
+
Medium: getSizeVariantClassName(SizeVariants.Medium),
|
|
18
|
+
Large: getSizeVariantClassName(SizeVariants.Large),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const useSizeClassName = (size: `${SizeVariants}`) =>
|
|
22
|
+
useClassNames(
|
|
23
|
+
Object.entries(SizeVariants).reduce(
|
|
24
|
+
(object, [key, value]) => ({
|
|
25
|
+
...object,
|
|
26
|
+
[SizeClassNames[key as keyof typeof SizeVariants]]: size === value,
|
|
27
|
+
}),
|
|
28
|
+
{},
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export const SizeStyles = css`
|
|
33
|
+
&.${SizeClassNames.Small} {
|
|
34
|
+
font-size: ${props => props.theme.constants.typography.small.fontSize};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&.${SizeClassNames.Medium} {
|
|
38
|
+
font-size: ${props => props.theme.constants.typography.label.fontSize};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&.${SizeClassNames.Large} {
|
|
42
|
+
font-size: ${props => props.theme.constants.typography.body.fontSize};
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const formatBytes = (bytes: number, decimals = 2) => {
|
|
2
|
+
if (bytes === 0) return '0 Bytes';
|
|
3
|
+
|
|
4
|
+
const k = 1000;
|
|
5
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
6
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
7
|
+
|
|
8
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
9
|
+
|
|
10
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import moment from 'moment/moment';
|
|
2
|
+
|
|
3
|
+
export const formatDate = (date: string) => {
|
|
4
|
+
return Date.parse(date) ? moment(date, 'YYYY-MM-DD').format('MMM YYYY') : date;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const timeBetween = (date_start: string, date_end: string) => {
|
|
8
|
+
const momentStart = moment(date_start);
|
|
9
|
+
|
|
10
|
+
return Date.parse(date_end) ? moment(date_end).from(momentStart, true) : momentStart.fromNow();
|
|
11
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export enum POSITION {
|
|
2
|
+
top = 'top',
|
|
3
|
+
left = 'left',
|
|
4
|
+
right = 'right',
|
|
5
|
+
bottom = 'bottom',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type PositionObject = {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
top: number;
|
|
12
|
+
left: number;
|
|
13
|
+
w: number;
|
|
14
|
+
h: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type GetModalPositionParams = {
|
|
18
|
+
c: PositionObject;
|
|
19
|
+
m: PositionObject;
|
|
20
|
+
offset: number;
|
|
21
|
+
windowOffset: number;
|
|
22
|
+
position?: `${POSITION}`;
|
|
23
|
+
distancePercentage?: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const getModalPosition = ({
|
|
27
|
+
c,
|
|
28
|
+
m,
|
|
29
|
+
offset,
|
|
30
|
+
windowOffset,
|
|
31
|
+
position,
|
|
32
|
+
distancePercentage = 50,
|
|
33
|
+
}: GetModalPositionParams) => {
|
|
34
|
+
// Default bottom
|
|
35
|
+
let top = c.y + c.h + offset;
|
|
36
|
+
let left = c.x - (m.w - c.w);
|
|
37
|
+
|
|
38
|
+
switch (position) {
|
|
39
|
+
case POSITION.top:
|
|
40
|
+
top = c.y - m.h - offset;
|
|
41
|
+
left = c.x - (m.w - c.w) * (distancePercentage / 100);
|
|
42
|
+
|
|
43
|
+
break;
|
|
44
|
+
case POSITION.bottom:
|
|
45
|
+
top = c.y + c.h + offset;
|
|
46
|
+
left = c.x - (m.w - c.w) * (distancePercentage / 100);
|
|
47
|
+
|
|
48
|
+
break;
|
|
49
|
+
case POSITION.left:
|
|
50
|
+
top = c.y - (m.h - c.h) * (distancePercentage / 100);
|
|
51
|
+
left = c.x - m.w - offset;
|
|
52
|
+
|
|
53
|
+
break;
|
|
54
|
+
case POSITION.right:
|
|
55
|
+
top = c.y - (m.h - c.h) * (distancePercentage / 100);
|
|
56
|
+
left = c.x + c.w + offset;
|
|
57
|
+
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
left:
|
|
63
|
+
left + m.w + windowOffset > window.innerWidth ? c.left - (left + m.w - window.innerWidth) - windowOffset : left,
|
|
64
|
+
top: top + m.h + windowOffset > window.innerHeight ? c.top - (top + m.h - window.innerHeight) - windowOffset : top,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './to-capitalize';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type ToCapitalizeOptions = Partial<{
|
|
2
|
+
separator: string;
|
|
3
|
+
join: string;
|
|
4
|
+
variant: 'first-word' | 'each-word';
|
|
5
|
+
}>;
|
|
6
|
+
|
|
7
|
+
export const toCapitalize = (text: string, options: ToCapitalizeOptions = {}) => {
|
|
8
|
+
const { separator = ' ', variant = 'each-word', join = separator } = options;
|
|
9
|
+
|
|
10
|
+
if (variant === 'first-word') {
|
|
11
|
+
return text[0].toUpperCase() + text.slice(1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const words = text.split(separator);
|
|
15
|
+
|
|
16
|
+
return words.map(word => word[0].toUpperCase() + word.slice(1)).join(join);
|
|
17
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from './use-async';
|
|
2
|
+
export * from './use-async';
|
|
3
|
+
export * from './use-classnames';
|
|
4
|
+
export * from './use-constant';
|
|
5
|
+
export * from './use-debounce';
|
|
6
|
+
export * from './use-dimensions';
|
|
7
|
+
export * from './use-event-listener';
|
|
8
|
+
export * from './use-file-reader';
|
|
9
|
+
export * from './use-in-view';
|
|
10
|
+
export * from './use-input-handlers';
|
|
11
|
+
export * from './use-media-query';
|
|
12
|
+
export * from './use-modal-in-container';
|
|
13
|
+
export * from './use-mouse-position';
|
|
14
|
+
export * from './use-observer';
|
|
15
|
+
export * from './use-on-click-outside-ref';
|
|
16
|
+
export * from './use-online-status';
|
|
17
|
+
export * from './use-render-count';
|
|
18
|
+
export * from './use-safe-dispatch';
|
|
19
|
+
export * from './use-scroll';
|
|
20
|
+
export * from './use-state-history';
|
|
21
|
+
export * from './use-toggle';
|
|
22
|
+
export * from './use-toggle-values';
|
|
23
|
+
export * from './use-viewport';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React, { useCallback, useMemo, useReducer } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useSafeDispatch } from './use-safe-dispatch';
|
|
4
|
+
|
|
5
|
+
type AsyncState<T> =
|
|
6
|
+
| {
|
|
7
|
+
status: 'idle' | 'pending';
|
|
8
|
+
data?: null;
|
|
9
|
+
error?: null;
|
|
10
|
+
}
|
|
11
|
+
| {
|
|
12
|
+
status: 'resolved';
|
|
13
|
+
data: T;
|
|
14
|
+
error: null;
|
|
15
|
+
}
|
|
16
|
+
| {
|
|
17
|
+
status: 'rejected';
|
|
18
|
+
data: null;
|
|
19
|
+
error: Error;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type AsyncAction<T> =
|
|
23
|
+
| { type: 'reset' }
|
|
24
|
+
| { type: 'pending' }
|
|
25
|
+
| { type: 'resolved'; data: T }
|
|
26
|
+
| { type: 'rejected'; error: Error };
|
|
27
|
+
|
|
28
|
+
const asyncReducer = <T>(_state: AsyncState<T>, action: AsyncAction<T>): AsyncState<T> => {
|
|
29
|
+
switch (action.type) {
|
|
30
|
+
case 'pending': {
|
|
31
|
+
return { status: 'pending' as const, data: null, error: null };
|
|
32
|
+
}
|
|
33
|
+
case 'resolved': {
|
|
34
|
+
return { status: 'resolved' as const, data: action.data, error: null };
|
|
35
|
+
}
|
|
36
|
+
case 'rejected': {
|
|
37
|
+
return { status: 'rejected' as const, data: null, error: action.error };
|
|
38
|
+
}
|
|
39
|
+
default: {
|
|
40
|
+
throw new Error(`Unhandled action: ${JSON.stringify(action)}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const useAsync = <T>(
|
|
46
|
+
initialState?: AsyncState<T>,
|
|
47
|
+
): AsyncState<T> & {
|
|
48
|
+
setData: (data: T) => void;
|
|
49
|
+
setError: (error: Error) => void;
|
|
50
|
+
run: (promise: Promise<T>) => void;
|
|
51
|
+
} => {
|
|
52
|
+
const [asyncState, unsafeDispatch] = useReducer<React.Reducer<AsyncState<T>, AsyncAction<T>>>(asyncReducer, {
|
|
53
|
+
status: 'idle',
|
|
54
|
+
data: null,
|
|
55
|
+
error: null,
|
|
56
|
+
...initialState,
|
|
57
|
+
});
|
|
58
|
+
const dispatch = useSafeDispatch(unsafeDispatch);
|
|
59
|
+
|
|
60
|
+
const run = useCallback(
|
|
61
|
+
(promise: Promise<T>) => {
|
|
62
|
+
dispatch({ type: 'pending' });
|
|
63
|
+
promise.then(
|
|
64
|
+
data => {
|
|
65
|
+
dispatch({ type: 'resolved', data });
|
|
66
|
+
},
|
|
67
|
+
(error: Error) => {
|
|
68
|
+
dispatch({ type: 'rejected', error });
|
|
69
|
+
},
|
|
70
|
+
);
|
|
71
|
+
},
|
|
72
|
+
[dispatch],
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const setData = useCallback((data: T) => dispatch({ type: 'resolved', data }), [dispatch]);
|
|
76
|
+
|
|
77
|
+
const setError = useCallback((error: Error) => dispatch({ type: 'rejected', error }), [dispatch]);
|
|
78
|
+
|
|
79
|
+
return useMemo(
|
|
80
|
+
() => ({
|
|
81
|
+
setData,
|
|
82
|
+
setError,
|
|
83
|
+
run,
|
|
84
|
+
...asyncState,
|
|
85
|
+
}),
|
|
86
|
+
[asyncState, run, setData, setError],
|
|
87
|
+
);
|
|
88
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
export const useClassNames = (classes: Record<string, boolean>): string =>
|
|
4
|
+
useMemo<string>(
|
|
5
|
+
() =>
|
|
6
|
+
Object.entries(classes)
|
|
7
|
+
.reduce<Array<string>>(
|
|
8
|
+
(compiledClassNames, [classname, value]) => (value ? [...compiledClassNames, classname] : compiledClassNames),
|
|
9
|
+
[],
|
|
10
|
+
)
|
|
11
|
+
.join(' '),
|
|
12
|
+
[classes],
|
|
13
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export const useDebounce = <T>(value: T, delay: number = 500): T => {
|
|
4
|
+
const [debouncedValue, setDebouncedValue] = useState<T>(value);
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const timer = setTimeout(() => setDebouncedValue(value), delay);
|
|
8
|
+
|
|
9
|
+
return () => {
|
|
10
|
+
clearTimeout(timer);
|
|
11
|
+
};
|
|
12
|
+
}, [value, delay]);
|
|
13
|
+
|
|
14
|
+
return debouncedValue;
|
|
15
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useEventListener } from './use-event-listener';
|
|
4
|
+
import { useObserver } from './use-observer';
|
|
5
|
+
|
|
6
|
+
export const useDimensions = (ref: React.RefObject<HTMLElement>) => {
|
|
7
|
+
const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
|
|
8
|
+
|
|
9
|
+
const getSize = () => {
|
|
10
|
+
setDimensions({
|
|
11
|
+
width: ref.current?.offsetWidth ?? 0,
|
|
12
|
+
height: ref.current?.offsetHeight ?? 0,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
useEventListener('resize', getSize);
|
|
17
|
+
useObserver(ref, getSize);
|
|
18
|
+
|
|
19
|
+
useEffect(getSize, [ref]);
|
|
20
|
+
|
|
21
|
+
return dimensions;
|
|
22
|
+
};
|