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,132 @@
|
|
|
1
|
+
import React, { ForwardedRef, forwardRef, useEffect, useMemo } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { useTheme } from 'styled-components';
|
|
4
|
+
|
|
5
|
+
import { ModalOverlayStyle } from './modal.style';
|
|
6
|
+
|
|
7
|
+
import { useConstant } from '@polpo/hooks';
|
|
8
|
+
|
|
9
|
+
export enum ModalBackdrop {
|
|
10
|
+
OPAQUE = 'opaque',
|
|
11
|
+
TRANSPARENT = 'transparent',
|
|
12
|
+
BLUR = 'blur',
|
|
13
|
+
NONE = 'none',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type ModalCommonProps = {
|
|
17
|
+
isOpen: boolean;
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type ModalNoOverlayProps = ModalCommonProps & {
|
|
23
|
+
opacity?: never;
|
|
24
|
+
backdrop?: never;
|
|
25
|
+
onClick?: never;
|
|
26
|
+
zIndex?: never;
|
|
27
|
+
className?: never;
|
|
28
|
+
style?: never;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type ModalOverlayProps = ModalCommonProps & {
|
|
32
|
+
opacity?: number;
|
|
33
|
+
backdrop?: `${ModalBackdrop}`;
|
|
34
|
+
onClick?: () => void;
|
|
35
|
+
zIndex?: React.CSSProperties['zIndex'];
|
|
36
|
+
className?: string;
|
|
37
|
+
style?: React.CSSProperties;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type ModalProps = ModalOverlayProps | ModalNoOverlayProps;
|
|
41
|
+
|
|
42
|
+
export const ModalComponent = (
|
|
43
|
+
{
|
|
44
|
+
isOpen,
|
|
45
|
+
children,
|
|
46
|
+
id,
|
|
47
|
+
opacity = 0.6,
|
|
48
|
+
backdrop = ModalBackdrop.BLUR,
|
|
49
|
+
onClick,
|
|
50
|
+
zIndex,
|
|
51
|
+
className = '',
|
|
52
|
+
style = {},
|
|
53
|
+
}: ModalProps,
|
|
54
|
+
ref: ForwardedRef<HTMLElement>,
|
|
55
|
+
) => {
|
|
56
|
+
const containerID = useConstant(`modal-${id}`);
|
|
57
|
+
const theme = useTheme();
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
let modalContainer = document.getElementById(containerID);
|
|
61
|
+
|
|
62
|
+
if (!modalContainer) {
|
|
63
|
+
modalContainer = document.createElement('div');
|
|
64
|
+
modalContainer.setAttribute('id', containerID);
|
|
65
|
+
|
|
66
|
+
if (typeof ref === 'function') {
|
|
67
|
+
ref(modalContainer);
|
|
68
|
+
} else if (ref) {
|
|
69
|
+
ref.current = modalContainer;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
document.body.appendChild(modalContainer);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/*
|
|
76
|
+
* return () => {
|
|
77
|
+
* if (modalContainer.parentNode === document.body) {
|
|
78
|
+
* document.body.removeChild(modalContainer);
|
|
79
|
+
* }
|
|
80
|
+
* };
|
|
81
|
+
*/
|
|
82
|
+
}, [containerID, ref]);
|
|
83
|
+
|
|
84
|
+
const backgroundStyles = useMemo(() => {
|
|
85
|
+
switch (backdrop) {
|
|
86
|
+
case ModalBackdrop.OPAQUE:
|
|
87
|
+
return {
|
|
88
|
+
background: `${theme.colors.background.paper}${(opacity * 255)?.toString(16)}`,
|
|
89
|
+
};
|
|
90
|
+
case ModalBackdrop.TRANSPARENT:
|
|
91
|
+
return {
|
|
92
|
+
background: 'transparent',
|
|
93
|
+
};
|
|
94
|
+
case ModalBackdrop.BLUR:
|
|
95
|
+
return {
|
|
96
|
+
background: `${theme.colors.background.paper}${(opacity * 255)?.toString(16)}`,
|
|
97
|
+
backdropFilter: 'blur(5px)',
|
|
98
|
+
};
|
|
99
|
+
case ModalBackdrop.NONE:
|
|
100
|
+
return {
|
|
101
|
+
display: 'none',
|
|
102
|
+
};
|
|
103
|
+
default:
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
}, [backdrop, theme.colors.background.paper, opacity]);
|
|
107
|
+
|
|
108
|
+
const root = document.getElementById(containerID);
|
|
109
|
+
|
|
110
|
+
if (!isOpen || !root) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return ReactDOM.createPortal(
|
|
115
|
+
<>
|
|
116
|
+
<ModalOverlayStyle
|
|
117
|
+
tabIndex={-1}
|
|
118
|
+
onClick={onClick}
|
|
119
|
+
className={className}
|
|
120
|
+
style={{
|
|
121
|
+
zIndex,
|
|
122
|
+
...backgroundStyles,
|
|
123
|
+
...style,
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
{children}
|
|
127
|
+
</>,
|
|
128
|
+
root,
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const Modal = forwardRef(ModalComponent);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ripple';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Ripple } from './ripple';
|
|
2
|
+
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Ripple> = {
|
|
6
|
+
title: 'Ripple',
|
|
7
|
+
component: Ripple,
|
|
8
|
+
argTypes: {
|
|
9
|
+
color: { control: 'color' },
|
|
10
|
+
duration: { control: { type: 'range', min: 500, max: 5000, step: 100 } },
|
|
11
|
+
timingFunction: { options: ['ease', 'ease-out', 'ease-in', 'ease-in-out', 'cubic-bezier(0.81, -0.52, 0.42, 2.5)'] },
|
|
12
|
+
times: { control: { type: 'range', min: 1, max: 5 } },
|
|
13
|
+
className: { control: false },
|
|
14
|
+
style: { control: false },
|
|
15
|
+
},
|
|
16
|
+
args: {
|
|
17
|
+
color: '#FFFFFF',
|
|
18
|
+
},
|
|
19
|
+
render: args => (
|
|
20
|
+
<section
|
|
21
|
+
style={{
|
|
22
|
+
background: 'linear-gradient(35deg, rgba(230,96,255,1) 0%, rgba(91,170,255,1) 100%)',
|
|
23
|
+
width: '300px',
|
|
24
|
+
height: '300px',
|
|
25
|
+
borderRadius: '10px',
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
<Ripple {...args} />
|
|
29
|
+
</section>
|
|
30
|
+
),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default meta;
|
|
34
|
+
type Story = StoryObj<typeof Ripple>;
|
|
35
|
+
|
|
36
|
+
export const Default: Story = {
|
|
37
|
+
args: {},
|
|
38
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export const RippleStyle = styled.span`
|
|
4
|
+
position: absolute;
|
|
5
|
+
display: block;
|
|
6
|
+
top: 0;
|
|
7
|
+
left: 0;
|
|
8
|
+
right: 0;
|
|
9
|
+
bottom: 0;
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
border-radius: inherit;
|
|
12
|
+
z-index: 1;
|
|
13
|
+
|
|
14
|
+
.ripple-effect {
|
|
15
|
+
position: absolute;
|
|
16
|
+
transform: translate(-50%, -50%);
|
|
17
|
+
border-radius: 50%;
|
|
18
|
+
width: 0;
|
|
19
|
+
height: 0;
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
animation: ripple-effect infinite;
|
|
22
|
+
opacity: 0.4;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@keyframes ripple-effect {
|
|
26
|
+
to {
|
|
27
|
+
width: 300px;
|
|
28
|
+
height: 300px;
|
|
29
|
+
opacity: 0;
|
|
30
|
+
filter: blur(5px);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import { RippleStyle } from './ripple.style';
|
|
4
|
+
|
|
5
|
+
type RippleProps = {
|
|
6
|
+
color?: string;
|
|
7
|
+
duration?: number;
|
|
8
|
+
timingFunction?: React.CSSProperties['animationTimingFunction'];
|
|
9
|
+
times?: number;
|
|
10
|
+
className?: string;
|
|
11
|
+
style?: React.CSSProperties;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const Ripple = ({
|
|
15
|
+
color,
|
|
16
|
+
duration = 1000,
|
|
17
|
+
timingFunction = 'ease-out',
|
|
18
|
+
times = 1,
|
|
19
|
+
className = '',
|
|
20
|
+
style = {},
|
|
21
|
+
}: RippleProps) => {
|
|
22
|
+
const ref = useRef<HTMLSpanElement>(null);
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!ref.current?.parentElement) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const computedPosition = getComputedStyle(ref.current.parentElement).position;
|
|
30
|
+
|
|
31
|
+
if (!['absolute', 'fixed', 'sticky', 'relative'].includes(computedPosition)) {
|
|
32
|
+
ref.current.parentElement.style.position = 'relative';
|
|
33
|
+
}
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
const handleClick = (e: React.MouseEvent<HTMLSpanElement>) => {
|
|
37
|
+
const { pageX, pageY, currentTarget } = e;
|
|
38
|
+
|
|
39
|
+
const rect = currentTarget.getBoundingClientRect();
|
|
40
|
+
|
|
41
|
+
const x = ((pageX - rect.left) * 100) / rect.width;
|
|
42
|
+
const y = ((pageY - rect.top) * 100) / rect.height;
|
|
43
|
+
|
|
44
|
+
const ripple = document.createElement('span');
|
|
45
|
+
ripple.classList.add('ripple-effect');
|
|
46
|
+
color && (ripple.style.background = color);
|
|
47
|
+
ripple.style.animationDuration = `${duration}ms`;
|
|
48
|
+
ripple.style.animationTimingFunction = timingFunction;
|
|
49
|
+
ripple.style.left = `${x}%`;
|
|
50
|
+
ripple.style.top = `${y}%`;
|
|
51
|
+
|
|
52
|
+
currentTarget.appendChild(ripple);
|
|
53
|
+
|
|
54
|
+
setTimeout(
|
|
55
|
+
() => {
|
|
56
|
+
ripple.remove();
|
|
57
|
+
},
|
|
58
|
+
Math.max(duration, 500) * Math.max(times, 1),
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return <RippleStyle ref={ref} onMouseDown={handleClick} className={className} style={style} />;
|
|
63
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './smart-table';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useTheme } from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import { Grid } from '../../layouts';
|
|
5
|
+
import { Icon } from '../icon';
|
|
6
|
+
import { Ripple } from '../ripple';
|
|
7
|
+
import { Typography } from '../typography';
|
|
8
|
+
|
|
9
|
+
import { SmartColumnStyle } from './smart-table.style';
|
|
10
|
+
import { ColumnData, Order, RowDataObject } from './smart-table.types';
|
|
11
|
+
|
|
12
|
+
import { useClassNames } from '@polpo/hooks';
|
|
13
|
+
|
|
14
|
+
type SmartTableColumnProps<RowData extends RowDataObject> = ColumnData<RowData> & {
|
|
15
|
+
toggleSortField: (field: ColumnData<RowData>['sortBy']) => void;
|
|
16
|
+
sortField: ColumnData<RowData>['sortBy'] | null;
|
|
17
|
+
orderField: Order | null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const SmartTableColumn = <RowData extends RowDataObject>({
|
|
21
|
+
header,
|
|
22
|
+
sortBy,
|
|
23
|
+
icon,
|
|
24
|
+
width,
|
|
25
|
+
field,
|
|
26
|
+
toggleSortField,
|
|
27
|
+
sortField,
|
|
28
|
+
orderField,
|
|
29
|
+
}: SmartTableColumnProps<RowData>) => {
|
|
30
|
+
const theme = useTheme();
|
|
31
|
+
const sortByKey = sortBy || field;
|
|
32
|
+
|
|
33
|
+
const columnClassName = useClassNames({
|
|
34
|
+
'sort-on-click': Boolean(sortByKey),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const columnOnClick = sortByKey && (() => toggleSortField(sortByKey));
|
|
38
|
+
|
|
39
|
+
const sortIcon = useMemo(() => {
|
|
40
|
+
if (!sortByKey) return null;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<span className='sort-icon'>
|
|
44
|
+
{Boolean(sortField) && sortField === sortByKey && (
|
|
45
|
+
<Icon name={orderField === 'asc' ? 'arrow-down' : 'arrow-up'} />
|
|
46
|
+
)}
|
|
47
|
+
</span>
|
|
48
|
+
);
|
|
49
|
+
}, [sortByKey, sortField, orderField]);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<SmartColumnStyle style={{ width }} className={columnClassName} onClick={columnOnClick}>
|
|
53
|
+
<Grid flow='column' gap='0.5em' jc='space-between' ai='center'>
|
|
54
|
+
{icon && <Icon name={icon} />}
|
|
55
|
+
<Typography variant='label' noPadding>
|
|
56
|
+
{header}
|
|
57
|
+
</Typography>
|
|
58
|
+
{sortIcon}
|
|
59
|
+
</Grid>
|
|
60
|
+
<Ripple color={theme.colors.text.main} />
|
|
61
|
+
</SmartColumnStyle>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Typography } from '../typography';
|
|
4
|
+
|
|
5
|
+
import { SmartCellStyle } from './smart-table.style';
|
|
6
|
+
import { ColumnData, Order, Primitive, RowDataObject } from './smart-table.types';
|
|
7
|
+
|
|
8
|
+
const renderRowColumn = <RowData extends RowDataObject>(
|
|
9
|
+
data: RowData,
|
|
10
|
+
{ field, render, Component }: ColumnData<RowData>,
|
|
11
|
+
rowKey: React.Key,
|
|
12
|
+
): React.ReactNode => {
|
|
13
|
+
if (field && data[field])
|
|
14
|
+
return (
|
|
15
|
+
<Typography noPadding nowrap>
|
|
16
|
+
{data[field] as Primitive}
|
|
17
|
+
</Typography>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
if (render) return render(data, rowKey);
|
|
21
|
+
|
|
22
|
+
if (Component) return <Component data={data} rowKey={rowKey} />;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const renderRow = <RowData extends RowDataObject>(
|
|
26
|
+
data: RowData,
|
|
27
|
+
columns: Array<ColumnData<RowData>>,
|
|
28
|
+
rowKey: React.Key,
|
|
29
|
+
) => columns.map((column, key) => <SmartCellStyle key={key}>{renderRowColumn(data, column, rowKey)}</SmartCellStyle>);
|
|
30
|
+
|
|
31
|
+
export const sortData = <RowData extends RowDataObject>(
|
|
32
|
+
data: Array<RowData>,
|
|
33
|
+
sortBy: ColumnData<RowData>['sortBy'] | null,
|
|
34
|
+
order: Order | null,
|
|
35
|
+
) => {
|
|
36
|
+
if (sortBy) {
|
|
37
|
+
return data.toSorted((a, b) => {
|
|
38
|
+
const fieldA = a[sortBy];
|
|
39
|
+
const fieldB = b[sortBy];
|
|
40
|
+
|
|
41
|
+
if (
|
|
42
|
+
['number', 'boolean', 'string'].includes(typeof fieldA) &&
|
|
43
|
+
['number', 'boolean', 'string'].includes(typeof fieldB)
|
|
44
|
+
) {
|
|
45
|
+
if (fieldA === fieldB) return 0;
|
|
46
|
+
|
|
47
|
+
if (order === 'asc') {
|
|
48
|
+
return fieldA > fieldB ? 1 : -1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return fieldA > fieldB ? -1 : 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return 0;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return data;
|
|
59
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ColumnData, Order, RowDataObject } from './smart-table.types';
|
|
4
|
+
|
|
5
|
+
export const useSort = <RowData extends RowDataObject>() => {
|
|
6
|
+
const [[sortBy, order], setSortField] = useState<[ColumnData<RowData>['sortBy'] | null, Order | null]>([null, null]);
|
|
7
|
+
|
|
8
|
+
const toggleSortField = useCallback((sortByField: ColumnData<RowData>['sortBy']) => {
|
|
9
|
+
setSortField(([sortBy, order]) => {
|
|
10
|
+
if (sortByField !== sortBy) {
|
|
11
|
+
return [sortByField, 'asc'];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (order === 'asc') {
|
|
15
|
+
return [sortByField, 'desc'];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return [null, null];
|
|
19
|
+
});
|
|
20
|
+
}, []);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
sortBy,
|
|
24
|
+
order,
|
|
25
|
+
toggleSortField,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { renderRow } from './smart-table.helpers';
|
|
4
|
+
import { SmartRowStyle } from './smart-table.style';
|
|
5
|
+
import { ColumnData, RowDataObject } from './smart-table.types';
|
|
6
|
+
|
|
7
|
+
import { useClassNames } from '@polpo/hooks';
|
|
8
|
+
|
|
9
|
+
type SmartTableRowProps<RowData extends RowDataObject> = {
|
|
10
|
+
data: RowData;
|
|
11
|
+
columns: Array<ColumnData<RowData>>;
|
|
12
|
+
isSelected: boolean;
|
|
13
|
+
selectable: boolean;
|
|
14
|
+
rowKey: React.Key;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const SmartTableRow = <RowData extends RowDataObject>({
|
|
18
|
+
data,
|
|
19
|
+
columns,
|
|
20
|
+
isSelected = false,
|
|
21
|
+
selectable = false,
|
|
22
|
+
rowKey,
|
|
23
|
+
}: SmartTableRowProps<RowData>) => {
|
|
24
|
+
const rowClassName = useClassNames({
|
|
25
|
+
'row-selected': selectable && isSelected,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return <SmartRowStyle className={rowClassName}>{renderRow(data, columns, rowKey)}</SmartRowStyle>;
|
|
29
|
+
};
|