@okam/stack-ui 1.25.2 → 1.25.3
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.js +32 -0
- package/.storybook/.eslintrc.js +29 -0
- package/.storybook/main.ts +33 -0
- package/.storybook/preview.js +56 -0
- package/.storybook/tsconfig.json +17 -0
- package/CHANGELOG.md +574 -0
- package/README.md +8 -0
- package/package.json +1 -1
- package/postcss.config.js +15 -0
- package/project.json +77 -0
- package/src/_stories/icons/code-brackets.svg +1 -0
- package/src/_stories/icons/colors.svg +1 -0
- package/src/_stories/icons/comments.svg +1 -0
- package/src/_stories/icons/direction.svg +1 -0
- package/src/_stories/icons/flow.svg +1 -0
- package/src/_stories/icons/plugin.svg +1 -0
- package/src/_stories/icons/repo.svg +1 -0
- package/src/_stories/icons/stackalt.svg +1 -0
- package/src/components/Accordion/accordion.stories.mdx +240 -0
- package/src/components/Accordion/components/AccordionItem.tsx +53 -0
- package/src/components/Accordion/components/AriaAccordionItem.tsx +76 -0
- package/src/components/Accordion/hooks/useAccordionState.ts +46 -0
- package/src/components/Accordion/index.tsx +38 -0
- package/{components/Accordion/interface.d.ts → src/components/Accordion/interface.ts} +23 -17
- package/src/components/Alerts/alerts.stories.mdx +282 -0
- package/src/components/Alerts/components/AlertsCloseButton.tsx +20 -0
- package/src/components/Alerts/components/AlertsItem.tsx +39 -0
- package/src/components/Alerts/components/AlertsNavigationButton.tsx +71 -0
- package/src/components/Alerts/components/AlertsSwiper.tsx +125 -0
- package/src/components/Alerts/components/pagination/AlertsPagination.tsx +32 -0
- package/src/components/Alerts/components/pagination/AlertsPaginationBullet.tsx +61 -0
- package/src/components/Alerts/index.tsx +54 -0
- package/src/components/Alerts/interface.ts +51 -0
- package/src/components/Box/box.stories.mdx +27 -0
- package/src/components/Box/index.tsx +36 -0
- package/src/components/Box/interface.ts +10 -0
- package/src/components/Button/button.stories.mdx +99 -0
- package/src/components/Button/index.tsx +92 -0
- package/src/components/Button/interface.ts +22 -0
- package/src/components/Calendar/RangeCalendar.tsx +61 -0
- package/src/components/Calendar/calendar.stories.mdx +28 -0
- package/src/components/Calendar/components/CalendarCell.tsx +60 -0
- package/src/components/Calendar/components/CalendarGrid.tsx +44 -0
- package/src/components/Calendar/index.tsx +63 -0
- package/src/components/Calendar/interface.ts +37 -0
- package/src/components/Carousel/carousel.stories.mdx +182 -0
- package/src/components/Carousel/index.tsx +99 -0
- package/src/components/Carousel/interface.ts +26 -0
- package/src/components/Date/date.stories.mdx +122 -0
- package/src/components/Date/index.tsx +35 -0
- package/src/components/Date/interface.ts +7 -0
- package/src/components/Dialog/index.tsx +14 -0
- package/src/components/Dialog/interface.ts +6 -0
- package/src/components/DirectusImg/index.tsx +59 -0
- package/src/components/DirectusImg/interface.ts +19 -0
- package/src/components/Icon/index.tsx +40 -0
- package/src/components/Icon/interface.ts +8 -0
- package/src/components/Img/img.stories.mdx +28 -0
- package/src/components/Img/index.tsx +30 -0
- package/src/components/Img/interface.ts +9 -0
- package/src/components/Lightbox/hooks/overlay/index.tsx +36 -0
- package/src/components/Lightbox/index.tsx +82 -0
- package/src/components/Lightbox/interface.ts +28 -0
- package/src/components/Lightbox/lightbox.stories.mdx +79 -0
- package/src/components/Menu/Menu.tsx +43 -0
- package/src/components/Menu/MenuSidePanel.tsx +41 -0
- package/src/components/Menu/components/InnerContent.tsx +26 -0
- package/src/components/Menu/components/MenuItems.tsx +133 -0
- package/src/components/Menu/components/TabContainer.tsx +13 -0
- package/src/components/Menu/interface.ts +41 -0
- package/src/components/Menu/menu.stories.mdx +23 -0
- package/src/components/Modal/components/ModalDialog.tsx +31 -0
- package/src/components/Modal/components/ModalOverlay.tsx +21 -0
- package/src/components/Modal/index.tsx +32 -0
- package/{components/Modal/interface.d.ts → src/components/Modal/interface.ts} +14 -11
- package/src/components/Popover/index.tsx +138 -0
- package/src/components/Popover/interface.ts +25 -0
- package/src/components/Popover/popover.stories.mdx +66 -0
- package/src/components/ShareButton/index.tsx +172 -0
- package/src/components/ShareButton/interface.ts +29 -0
- package/src/components/ShareButton/share-button.stories.mdx +48 -0
- package/src/components/ShareButton/utils/generateUtmTags.ts +4 -0
- package/src/components/ShareButton/utils/useFacebookShareUrl.ts +15 -0
- package/src/components/ShareButton/utils/useMailToShareUrl.ts +15 -0
- package/src/components/ShareButton/utils/useTwitterShareUrl.ts +15 -0
- package/src/components/ShareButton/utils/useWindow.ts +17 -0
- package/src/components/SidePanel/index.tsx +43 -0
- package/src/components/SidePanel/interface.ts +16 -0
- package/src/components/SidePanel/side-panel.stories.mdx +44 -0
- package/src/components/TabList/components/Tab/Tab.tsx +19 -0
- package/src/components/TabList/components/TabPanel/TabPanel.tsx +27 -0
- package/src/components/TabList/index.tsx +44 -0
- package/src/components/TabList/interface.ts +23 -0
- package/src/components/Typography/index.tsx +35 -0
- package/src/components/Typography/interface.ts +9 -0
- package/src/components/Typography/typo.stories.mdx +157 -0
- package/src/components/WysiwygBlock/index.tsx +20 -0
- package/src/components/WysiwygBlock/interface.ts +7 -0
- package/src/components/WysiwygBlock/wysiwyg.stories.mdx +53 -0
- package/src/components/fields/Checkbox/Checkbox.interface.ts +21 -0
- package/src/components/fields/Checkbox/Checkbox.stories.mdx +127 -0
- package/src/components/fields/Checkbox/index.tsx +62 -0
- package/src/components/fields/CheckboxGroup/checkbox-group.stories.mdx +59 -0
- package/src/components/fields/CheckboxGroup/components/CheckboxGroupItem/index.tsx +66 -0
- package/src/components/fields/CheckboxGroup/index.tsx +49 -0
- package/src/components/fields/CheckboxGroup/interface.ts +17 -0
- package/src/components/fields/DatePicker/DateRangePicker.tsx +73 -0
- package/src/components/fields/DatePicker/components/CalendarPopover.tsx +31 -0
- package/src/components/fields/DatePicker/components/DateField.tsx +61 -0
- package/src/components/fields/DatePicker/date-picker.stories.mdx +55 -0
- package/src/components/fields/DatePicker/index.tsx +71 -0
- package/src/components/fields/DatePicker/interface.ts +69 -0
- package/src/components/fields/Radio/Radio.interface.ts +30 -0
- package/src/components/fields/Radio/index.tsx +63 -0
- package/src/components/fields/RadioGroup/index.tsx +33 -0
- package/src/components/fields/RadioGroup/interface.ts +10 -0
- package/src/components/fields/RadioGroup/radio-group.stories.mdx +56 -0
- package/src/components/fields/SearchField/index.tsx +59 -0
- package/src/components/fields/SearchField/interface.ts +10 -0
- package/src/components/fields/SearchField/search.stories.mdx +91 -0
- package/src/components/fields/Select/Select.interface.ts +24 -0
- package/src/components/fields/Select/Select.stories.mdx +53 -0
- package/src/components/fields/Select/Select.tsx +108 -0
- package/{components/fields/Select/components/Listbox.interface.d.ts → src/components/fields/Select/components/Listbox.interface.ts} +11 -8
- package/src/components/fields/Select/components/Listbox.tsx +40 -0
- package/src/components/fields/Select/components/Popover.interface.ts +14 -0
- package/src/components/fields/Select/components/Popover.tsx +32 -0
- package/{components/fields/SelectItem/SelectItem.interface.d.ts → src/components/fields/SelectItem/SelectItem.interface.ts} +4 -3
- package/src/components/fields/SelectItem/SelectItem.tsx +10 -0
- package/src/components/fields/TextArea/index.tsx +105 -0
- package/src/components/fields/TextArea/textArea.stories.mdx +60 -0
- package/src/components/fields/TextInputField/index.tsx +107 -0
- package/src/components/fields/TextInputField/interface.ts +30 -0
- package/src/components/fields/TextInputField/text-input-field.stories.mdx +64 -0
- package/src/components/icons/ArrowDown.tsx +11 -0
- package/src/components/icons/ArrowLeft.tsx +18 -0
- package/src/components/icons/ArrowRight.tsx +18 -0
- package/src/components/icons/Check.tsx +11 -0
- package/src/components/icons/ChevronLeft.tsx +11 -0
- package/src/components/icons/ChevronRight.tsx +11 -0
- package/src/components/icons/CloseBtn.tsx +11 -0
- package/src/components/icons/Facebook.tsx +14 -0
- package/src/components/icons/FacebookColored.tsx +16 -0
- package/src/components/icons/FacebookRounded.tsx +16 -0
- package/src/components/icons/Globe.tsx +38 -0
- package/src/components/icons/IconFallback.tsx +8 -0
- package/src/components/icons/Instagram.tsx +14 -0
- package/src/components/icons/InstagramColored.tsx +59 -0
- package/src/components/icons/Link.tsx +14 -0
- package/src/components/icons/LinkedIn.tsx +16 -0
- package/src/components/icons/Mail.tsx +16 -0
- package/src/components/icons/Plus.tsx +18 -0
- package/src/components/icons/Search.tsx +19 -0
- package/src/components/icons/Share.tsx +16 -0
- package/src/components/icons/Twitter.tsx +16 -0
- package/src/components/icons/TwitterColored.tsx +16 -0
- package/src/components/icons/Upload.tsx +14 -0
- package/src/components/icons/X.tsx +14 -0
- package/src/components/icons/YouTube.tsx +16 -0
- package/src/components/icons/YouTubeColored.tsx +17 -0
- package/src/components/icons/index.ts +24 -0
- package/src/examples/PageLayout/index.tsx +61 -0
- package/src/examples/PageLayout/layout.stories.mdx +35 -0
- package/{index.d.ts → src/index.ts} +72 -57
- package/src/message.tsx +8 -0
- package/src/providers/Accordion/index.tsx +15 -0
- package/src/providers/Accordion/interface.ts +14 -0
- package/src/providers/Alerts/index.tsx +15 -0
- package/src/providers/Alerts/interface.ts +11 -0
- package/src/providers/CheckboxGroup/index.tsx +22 -0
- package/{providers/CheckboxGroup/interface.d.ts → src/providers/CheckboxGroup/interface.ts} +5 -4
- package/src/providers/Client/index.tsx +21 -0
- package/src/providers/Client/interface.ts +13 -0
- package/src/providers/Menu/index.tsx +43 -0
- package/src/providers/Menu/interface.ts +32 -0
- package/src/providers/RadioGroup/RadioGroup.interface.ts +8 -0
- package/src/providers/RadioGroup/RadioGroup.tsx +25 -0
- package/src/providers/SidePanel/index.tsx +55 -0
- package/src/providers/SidePanel/interface.ts +26 -0
- package/src/providers/Theme/hooks.ts +25 -0
- package/src/providers/Theme/index.tsx +40 -0
- package/src/providers/Theme/interface.ts +28 -0
- package/src/providers/Theme/utils.ts +3 -0
- package/src/providers/UserSearchQuery/index.tsx +20 -0
- package/src/providers/UserSearchQuery/interface.ts +12 -0
- package/src/storybook/Lightbox/LightboxControlledState.tsx +28 -0
- package/src/storybook/Menu/Menu.tsx +177 -0
- package/src/storybook/Menu/NestedMenu.tsx +24 -0
- package/src/storybook/Menu/mock.tsx +84 -0
- package/src/storybook/SelectField/index.tsx +57 -0
- package/src/storybook/ShareButtonExample/index.tsx +66 -0
- package/src/tailwind.css +3 -0
- package/src/theme/Accordion/index.tsx +101 -0
- package/src/theme/Alerts/index.ts +97 -0
- package/src/theme/Box/index.ts +45 -0
- package/src/theme/Button/index.tsx +72 -0
- package/src/theme/Calendar/index.tsx +167 -0
- package/src/theme/Carousel/index.ts +36 -0
- package/src/theme/Checkbox/index.ts +49 -0
- package/src/theme/CheckboxGroup/index.ts +14 -0
- package/src/theme/DatePicker/index.tsx +42 -0
- package/src/theme/Image/index.ts +8 -0
- package/src/theme/LightBox/index.ts +56 -0
- package/src/theme/Radio/index.ts +31 -0
- package/src/theme/RadioGroup/index.ts +14 -0
- package/src/theme/Search/index.ts +20 -0
- package/src/theme/ShareButton/index.tsx +76 -0
- package/src/theme/SidePanel/index.ts +9 -0
- package/src/theme/TextArea/index.ts +25 -0
- package/src/theme/Typography/index.tsx +44 -0
- package/src/theme/index.tsx +178 -0
- package/src/transitions/AccordionTransition.tsx +26 -0
- package/src/transitions/ModalTransition.tsx +38 -0
- package/src/transitions/RenderWithOpacity.tsx +25 -0
- package/src/transitions/RenderWithSlide.tsx +21 -0
- package/src/transitions/SidePanelTransition.tsx +30 -0
- package/src/types/components.ts +34 -0
- package/static/images/image.png +0 -0
- package/tailwind.config.js +14 -0
- package/tsconfig.json +20 -0
- package/tsconfig.lib.json +25 -0
- package/vite.config.ts +58 -0
- package/components/Accordion/components/AccordionItem.d.ts +0 -3
- package/components/Accordion/components/AriaAccordionItem.d.ts +0 -3
- package/components/Accordion/hooks/useAccordionState.d.ts +0 -10
- package/components/Accordion/index.d.ts +0 -3
- package/components/Alerts/components/AlertsCloseButton.d.ts +0 -4
- package/components/Alerts/components/AlertsItem.d.ts +0 -3
- package/components/Alerts/components/AlertsNavigationButton.d.ts +0 -8
- package/components/Alerts/components/AlertsSwiper.d.ts +0 -3
- package/components/Alerts/components/pagination/AlertsPagination.d.ts +0 -3
- package/components/Alerts/components/pagination/AlertsPaginationBullet.d.ts +0 -3
- package/components/Alerts/index.d.ts +0 -3
- package/components/Alerts/interface.d.ts +0 -41
- package/components/Box/index.d.ts +0 -5
- package/components/Box/interface.d.ts +0 -10
- package/components/Button/index.d.ts +0 -6
- package/components/Button/interface.d.ts +0 -20
- package/components/Calendar/RangeCalendar.d.ts +0 -3
- package/components/Calendar/components/CalendarCell.d.ts +0 -3
- package/components/Calendar/components/CalendarGrid.d.ts +0 -3
- package/components/Calendar/index.d.ts +0 -3
- package/components/Calendar/interface.d.ts +0 -32
- package/components/Carousel/index.d.ts +0 -3
- package/components/Carousel/interface.d.ts +0 -24
- package/components/Date/index.d.ts +0 -3
- package/components/Date/interface.d.ts +0 -6
- package/components/Dialog/index.d.ts +0 -2
- package/components/Dialog/interface.d.ts +0 -6
- package/components/DirectusImg/index.d.ts +0 -3
- package/components/DirectusImg/interface.d.ts +0 -13
- package/components/Icon/index.d.ts +0 -3
- package/components/Icon/interface.d.ts +0 -7
- package/components/Img/index.d.ts +0 -3
- package/components/Img/interface.d.ts +0 -6
- package/components/Lightbox/index.d.ts +0 -3
- package/components/Lightbox/interface.d.ts +0 -25
- package/components/Menu/Menu.d.ts +0 -3
- package/components/Menu/MenuSidePanel.d.ts +0 -3
- package/components/Menu/components/InnerContent.d.ts +0 -3
- package/components/Menu/components/MenuItems.d.ts +0 -3
- package/components/Menu/components/TabContainer.d.ts +0 -3
- package/components/Menu/interface.d.ts +0 -31
- package/components/Modal/components/ModalDialog.d.ts +0 -3
- package/components/Modal/components/ModalOverlay.d.ts +0 -3
- package/components/Modal/index.d.ts +0 -3
- package/components/Popover/index.d.ts +0 -3
- package/components/Popover/interface.d.ts +0 -21
- package/components/ShareButton/index.d.ts +0 -4
- package/components/ShareButton/interface.d.ts +0 -26
- package/components/ShareButton/utils/generateUtmTags.d.ts +0 -2
- package/components/ShareButton/utils/useFacebookShareUrl.d.ts +0 -2
- package/components/ShareButton/utils/useMailToShareUrl.d.ts +0 -2
- package/components/ShareButton/utils/useTwitterShareUrl.d.ts +0 -2
- package/components/ShareButton/utils/useWindow.d.ts +0 -5
- package/components/SidePanel/index.d.ts +0 -4
- package/components/SidePanel/interface.d.ts +0 -12
- package/components/TabList/components/TabPanel/TabPanel.d.ts +0 -4
- package/components/TabList/interface.d.ts +0 -18
- package/components/Typography/index.d.ts +0 -5
- package/components/Typography/interface.d.ts +0 -9
- package/components/WysiwygBlock/index.d.ts +0 -3
- package/components/WysiwygBlock/interface.d.ts +0 -5
- package/components/fields/Checkbox/Checkbox.interface.d.ts +0 -18
- package/components/fields/Checkbox/index.d.ts +0 -3
- package/components/fields/CheckboxGroup/components/CheckboxGroupItem/index.d.ts +0 -3
- package/components/fields/CheckboxGroup/index.d.ts +0 -3
- package/components/fields/CheckboxGroup/interface.d.ts +0 -13
- package/components/fields/DatePicker/DateRangePicker.d.ts +0 -3
- package/components/fields/DatePicker/components/CalendarPopover.d.ts +0 -2
- package/components/fields/DatePicker/components/DateField.d.ts +0 -4
- package/components/fields/DatePicker/index.d.ts +0 -3
- package/components/fields/DatePicker/interface.d.ts +0 -37
- package/components/fields/Radio/Radio.interface.d.ts +0 -26
- package/components/fields/Radio/index.d.ts +0 -4
- package/components/fields/RadioGroup/index.d.ts +0 -3
- package/components/fields/RadioGroup/interface.d.ts +0 -9
- package/components/fields/SearchField/index.d.ts +0 -3
- package/components/fields/SearchField/interface.d.ts +0 -9
- package/components/fields/Select/Select.d.ts +0 -4
- package/components/fields/Select/Select.interface.d.ts +0 -26
- package/components/fields/Select/components/Listbox.d.ts +0 -4
- package/components/fields/Select/components/Popover.d.ts +0 -3
- package/components/fields/Select/components/Popover.interface.d.ts +0 -13
- package/components/fields/SelectItem/SelectItem.d.ts +0 -3
- package/components/fields/TextArea/index.d.ts +0 -4
- package/components/fields/TextInputField/index.d.ts +0 -4
- package/components/fields/TextInputField/interface.d.ts +0 -24
- package/components/icons/ArrowDown.d.ts +0 -3
- package/components/icons/ArrowLeft.d.ts +0 -3
- package/components/icons/ArrowRight.d.ts +0 -3
- package/components/icons/Check.d.ts +0 -3
- package/components/icons/ChevronLeft.d.ts +0 -3
- package/components/icons/ChevronRight.d.ts +0 -3
- package/components/icons/CloseBtn.d.ts +0 -3
- package/components/icons/Facebook.d.ts +0 -3
- package/components/icons/FacebookColored.d.ts +0 -3
- package/components/icons/FacebookRounded.d.ts +0 -3
- package/components/icons/Globe.d.ts +0 -3
- package/components/icons/IconFallback.d.ts +0 -3
- package/components/icons/Instagram.d.ts +0 -3
- package/components/icons/InstagramColored.d.ts +0 -3
- package/components/icons/Link.d.ts +0 -3
- package/components/icons/LinkedIn.d.ts +0 -3
- package/components/icons/Mail.d.ts +0 -3
- package/components/icons/Plus.d.ts +0 -3
- package/components/icons/Search.d.ts +0 -3
- package/components/icons/Share.d.ts +0 -3
- package/components/icons/Twitter.d.ts +0 -3
- package/components/icons/TwitterColored.d.ts +0 -3
- package/components/icons/Upload.d.ts +0 -3
- package/components/icons/X.d.ts +0 -3
- package/components/icons/YouTube.d.ts +0 -3
- package/components/icons/YouTubeColored.d.ts +0 -3
- package/components/icons/index.d.ts +0 -24
- package/index.js +0 -110
- package/index.mjs +0 -12897
- package/providers/Accordion/index.d.ts +0 -4
- package/providers/Accordion/interface.d.ts +0 -12
- package/providers/Alerts/index.d.ts +0 -4
- package/providers/Alerts/interface.d.ts +0 -9
- package/providers/CheckboxGroup/index.d.ts +0 -5
- package/providers/Client/index.d.ts +0 -4
- package/providers/Client/interface.d.ts +0 -10
- package/providers/Menu/index.d.ts +0 -4
- package/providers/Menu/interface.d.ts +0 -28
- package/providers/RadioGroup/RadioGroup.d.ts +0 -5
- package/providers/RadioGroup/RadioGroup.interface.d.ts +0 -7
- package/providers/SidePanel/index.d.ts +0 -4
- package/providers/SidePanel/interface.d.ts +0 -23
- package/providers/Theme/hooks.d.ts +0 -3
- package/providers/Theme/index.d.ts +0 -10
- package/providers/Theme/interface.d.ts +0 -24
- package/providers/Theme/utils.d.ts +0 -2
- package/providers/UserSearchQuery/index.d.ts +0 -4
- package/providers/UserSearchQuery/interface.d.ts +0 -10
- package/style.css +0 -1
- package/theme/Accordion/index.d.ts +0 -274
- package/theme/Alerts/index.d.ts +0 -1167
- package/theme/Box/index.d.ts +0 -214
- package/theme/Button/index.d.ts +0 -121
- package/theme/Calendar/index.d.ts +0 -366
- package/theme/Carousel/index.d.ts +0 -9
- package/theme/Checkbox/index.d.ts +0 -159
- package/theme/CheckboxGroup/index.d.ts +0 -30
- package/theme/DatePicker/index.d.ts +0 -43
- package/theme/Image/index.d.ts +0 -3
- package/theme/LightBox/index.d.ts +0 -455
- package/theme/Radio/index.d.ts +0 -108
- package/theme/RadioGroup/index.d.ts +0 -30
- package/theme/Search/index.d.ts +0 -30
- package/theme/ShareButton/index.d.ts +0 -174
- package/theme/SidePanel/index.d.ts +0 -3
- package/theme/TextArea/index.d.ts +0 -29
- package/theme/Typography/index.d.ts +0 -233
- package/theme/index.d.ts +0 -5
- package/transitions/AccordionTransition.d.ts +0 -3
- package/transitions/ModalTransition.d.ts +0 -7
- package/transitions/RenderWithOpacity.d.ts +0 -3
- package/transitions/RenderWithSlide.d.ts +0 -7
- package/transitions/SidePanelTransition.d.ts +0 -7
- package/types/components.d.ts +0 -28
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
/* eslint-disable react/display-name */
|
|
4
|
+
import type { FocusableElement } from '@react-types/shared'
|
|
5
|
+
import type { RefObject } from 'react'
|
|
6
|
+
import React from 'react'
|
|
7
|
+
import {
|
|
8
|
+
DismissButton,
|
|
9
|
+
FocusRing,
|
|
10
|
+
FocusScope,
|
|
11
|
+
mergeProps,
|
|
12
|
+
OverlayContainer,
|
|
13
|
+
useDialog,
|
|
14
|
+
useModal,
|
|
15
|
+
useOverlay,
|
|
16
|
+
useOverlayPosition,
|
|
17
|
+
useOverlayTrigger,
|
|
18
|
+
} from 'react-aria'
|
|
19
|
+
import { useOverlayTriggerState } from 'react-stately'
|
|
20
|
+
import useThemeContext from '../../providers/Theme/hooks'
|
|
21
|
+
import { BoxWithForwardRef } from '../Box'
|
|
22
|
+
import { ButtonWithForwardRef } from '../Button'
|
|
23
|
+
import type { IPopoverProps, TPopoverButtonProps } from './interface'
|
|
24
|
+
|
|
25
|
+
const Popover = React.forwardRef((props: IPopoverProps, ref: React.Ref<HTMLElement>) => {
|
|
26
|
+
const {
|
|
27
|
+
isOpen,
|
|
28
|
+
onClose,
|
|
29
|
+
children,
|
|
30
|
+
positionProps,
|
|
31
|
+
themeName = 'popover',
|
|
32
|
+
tokens,
|
|
33
|
+
customTheme,
|
|
34
|
+
isDismissable,
|
|
35
|
+
shouldCloseOnBlur,
|
|
36
|
+
...rest
|
|
37
|
+
} = props
|
|
38
|
+
|
|
39
|
+
// Handle events that should cause the popup to close,
|
|
40
|
+
// e.g. blur, clicking outside, or pressing the escape key.
|
|
41
|
+
const { overlayProps } = useOverlay(
|
|
42
|
+
{
|
|
43
|
+
isDismissable,
|
|
44
|
+
shouldCloseOnBlur,
|
|
45
|
+
isOpen,
|
|
46
|
+
onClose,
|
|
47
|
+
},
|
|
48
|
+
ref as RefObject<Element>,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
const { modalProps } = useModal()
|
|
52
|
+
const { dialogProps } = useDialog({}, ref as RefObject<FocusableElement>)
|
|
53
|
+
|
|
54
|
+
const theme = useThemeContext(`${themeName}.popover`, tokens, customTheme)
|
|
55
|
+
|
|
56
|
+
// Add a hidden <DismissButton> component at the end of the popover
|
|
57
|
+
// to allow screen reader users to dismiss the popup easily.
|
|
58
|
+
return (
|
|
59
|
+
<FocusScope autoFocus restoreFocus contain>
|
|
60
|
+
<BoxWithForwardRef
|
|
61
|
+
customTheme={theme}
|
|
62
|
+
{...mergeProps(overlayProps, modalProps, dialogProps)}
|
|
63
|
+
ref={ref}
|
|
64
|
+
{...positionProps}
|
|
65
|
+
{...rest}
|
|
66
|
+
>
|
|
67
|
+
{React.Children.map(children, (child) => (
|
|
68
|
+
<FocusRing focusRingClass="has-focus-ring">{child}</FocusRing>
|
|
69
|
+
))}
|
|
70
|
+
<DismissButton onDismiss={onClose} />
|
|
71
|
+
</BoxWithForwardRef>
|
|
72
|
+
</FocusScope>
|
|
73
|
+
)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
function PopoverButton(props: TPopoverButtonProps) {
|
|
77
|
+
const {
|
|
78
|
+
children,
|
|
79
|
+
buttonProps,
|
|
80
|
+
placement = 'right',
|
|
81
|
+
offset = 5,
|
|
82
|
+
themeName = 'popover',
|
|
83
|
+
tokens,
|
|
84
|
+
customTheme,
|
|
85
|
+
...rest
|
|
86
|
+
} = props
|
|
87
|
+
const state = useOverlayTriggerState({})
|
|
88
|
+
|
|
89
|
+
const triggerRef = React.useRef(null)
|
|
90
|
+
const overlayRef = React.useRef<HTMLDivElement>(null)
|
|
91
|
+
|
|
92
|
+
// Get props for the trigger and overlay. This also handles
|
|
93
|
+
// hiding the overlay when a parent element of the trigger scrolls
|
|
94
|
+
// (which invalidates the popover positioning).
|
|
95
|
+
const { triggerProps, overlayProps } = useOverlayTrigger({ type: 'dialog' }, state, triggerRef)
|
|
96
|
+
|
|
97
|
+
// Get popover positioning props relative to the trigger
|
|
98
|
+
const { overlayProps: positionProps } = useOverlayPosition({
|
|
99
|
+
targetRef: triggerRef,
|
|
100
|
+
overlayRef,
|
|
101
|
+
placement,
|
|
102
|
+
offset,
|
|
103
|
+
isOpen: state.isOpen,
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
const { onPress: handlePress, ...triggerButtonProps } = triggerProps
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<>
|
|
110
|
+
<ButtonWithForwardRef
|
|
111
|
+
themeName={`${themeName}.button`}
|
|
112
|
+
handlePress={handlePress}
|
|
113
|
+
{...buttonProps}
|
|
114
|
+
{...triggerButtonProps}
|
|
115
|
+
ref={triggerRef}
|
|
116
|
+
/>
|
|
117
|
+
{state.isOpen && (
|
|
118
|
+
<OverlayContainer>
|
|
119
|
+
<Popover
|
|
120
|
+
themeName={themeName}
|
|
121
|
+
tokens={tokens}
|
|
122
|
+
customTheme={customTheme}
|
|
123
|
+
{...overlayProps}
|
|
124
|
+
{...rest}
|
|
125
|
+
positionProps={positionProps}
|
|
126
|
+
ref={overlayRef}
|
|
127
|
+
isOpen={state.isOpen}
|
|
128
|
+
onClose={state.close}
|
|
129
|
+
>
|
|
130
|
+
{children}
|
|
131
|
+
</Popover>
|
|
132
|
+
</OverlayContainer>
|
|
133
|
+
)}
|
|
134
|
+
</>
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export default PopoverButton
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DOMAttributes } from '@react-types/shared'
|
|
2
|
+
import type React from 'react'
|
|
3
|
+
import type { Placement } from 'react-aria'
|
|
4
|
+
import type { TDefaultComponent } from '../../types/components'
|
|
5
|
+
import type { TButtonProps } from '../Button/interface'
|
|
6
|
+
|
|
7
|
+
export interface IPopoverProps extends TDefaultComponent {
|
|
8
|
+
isOpen?: boolean
|
|
9
|
+
onClose?: () => void
|
|
10
|
+
children: React.ReactElement | React.ReactElement[]
|
|
11
|
+
positionProps?: DOMAttributes
|
|
12
|
+
isDismissable?: boolean
|
|
13
|
+
shouldCloseOnBlur?: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TPopoverButtonProps extends TDefaultComponent, IPopoverProps {
|
|
17
|
+
offset?: number
|
|
18
|
+
buttonProps: TButtonProps
|
|
19
|
+
placement?: Placement
|
|
20
|
+
children: React.ReactElement | React.ReactElement[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type TPopoverProps = DOMAttributes & IPopoverProps
|
|
24
|
+
|
|
25
|
+
export type PopoverOrientation = 'left' | 'right'
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{/* typo.stories.mdx */}
|
|
2
|
+
|
|
3
|
+
import { Canvas, Meta, Story } from '@storybook/addon-docs'
|
|
4
|
+
import { OverlayProvider } from 'react-aria'
|
|
5
|
+
import Popover from './index'
|
|
6
|
+
|
|
7
|
+
<Meta
|
|
8
|
+
title="BASE COMPONENTS/Popover"
|
|
9
|
+
component={Popover}
|
|
10
|
+
args={{
|
|
11
|
+
as: 'span',
|
|
12
|
+
buttonProps: {
|
|
13
|
+
children: 'Open popover',
|
|
14
|
+
},
|
|
15
|
+
}}
|
|
16
|
+
/>
|
|
17
|
+
|
|
18
|
+
export const Template = (args) => (
|
|
19
|
+
<div>
|
|
20
|
+
<OverlayProvider>
|
|
21
|
+
<Popover {...args}>
|
|
22
|
+
<a href="#" className={`focus-ring-black`}>
|
|
23
|
+
Hello world!
|
|
24
|
+
</a>
|
|
25
|
+
<a href="#" className={`focus-ring-black`}>
|
|
26
|
+
Hello world! 2
|
|
27
|
+
</a>
|
|
28
|
+
<a href="#" className={`focus-ring-black`}>
|
|
29
|
+
Hello world! 3
|
|
30
|
+
</a>
|
|
31
|
+
</Popover>
|
|
32
|
+
</OverlayProvider>
|
|
33
|
+
</div>
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# Popover
|
|
37
|
+
|
|
38
|
+
## Default
|
|
39
|
+
|
|
40
|
+
<Canvas>
|
|
41
|
+
<Story
|
|
42
|
+
name="Default"
|
|
43
|
+
args={{
|
|
44
|
+
variant: 'p',
|
|
45
|
+
offset: 20,
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
{Template.bind({})}
|
|
49
|
+
</Story>
|
|
50
|
+
</Canvas>
|
|
51
|
+
|
|
52
|
+
## Closes when interacting outside
|
|
53
|
+
|
|
54
|
+
<Canvas>
|
|
55
|
+
<Story
|
|
56
|
+
name="Closes when inteacting outside"
|
|
57
|
+
args={{
|
|
58
|
+
variant: 'p',
|
|
59
|
+
offset: 20,
|
|
60
|
+
isDismissable: true,
|
|
61
|
+
shouldCloseOnBlur: true,
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
{Template.bind({})}
|
|
65
|
+
</Story>
|
|
66
|
+
</Canvas>
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { PressEvent } from '@react-types/shared'
|
|
4
|
+
import React, { useState } from 'react'
|
|
5
|
+
import { FocusScope, useFocusManager } from 'react-aria'
|
|
6
|
+
import useThemeContext from '../../providers/Theme/hooks'
|
|
7
|
+
import Button, { ButtonWithForwardRef } from '../Button'
|
|
8
|
+
import Icon from '../Icon'
|
|
9
|
+
import type { TIconsContainerProps, TShareButtonProps } from './interface'
|
|
10
|
+
|
|
11
|
+
export const IconsContainer = (props: TIconsContainerProps) => {
|
|
12
|
+
const { sharingLinksList, id, isOpen, setIsOpen, onShare, themeName = 'shareButton', tokens, customTheme } = props
|
|
13
|
+
|
|
14
|
+
const linksListTheme = useThemeContext(`${themeName}.linksList`, { ...tokens, isOpen }, customTheme)
|
|
15
|
+
|
|
16
|
+
const focusManager = useFocusManager()
|
|
17
|
+
|
|
18
|
+
const handleKeyDown: React.KeyboardEventHandler = (e) => {
|
|
19
|
+
if (e.key === 'Escape') {
|
|
20
|
+
setIsOpen(false)
|
|
21
|
+
}
|
|
22
|
+
const { listDirection } = tokens ?? {}
|
|
23
|
+
|
|
24
|
+
if (listDirection === 'row') {
|
|
25
|
+
if (e.key === 'ArrowRight') {
|
|
26
|
+
focusManager?.focusNext({ wrap: true })
|
|
27
|
+
e.preventDefault()
|
|
28
|
+
}
|
|
29
|
+
if (e.key === 'ArrowLeft') {
|
|
30
|
+
focusManager?.focusPrevious({ wrap: true })
|
|
31
|
+
e.preventDefault()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (listDirection === 'column') {
|
|
35
|
+
if (e.key === 'ArrowDown') {
|
|
36
|
+
focusManager?.focusNext({ wrap: true })
|
|
37
|
+
e.preventDefault()
|
|
38
|
+
}
|
|
39
|
+
if (e.key === 'ArrowUp') {
|
|
40
|
+
focusManager?.focusPrevious({ wrap: true })
|
|
41
|
+
e.preventDefault()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div className={linksListTheme} id={id} role="listbox" tabIndex={-1} onKeyDown={handleKeyDown}>
|
|
48
|
+
{sharingLinksList?.map((link) => {
|
|
49
|
+
const { ariaLabel, onClick, href, icon, key } = link
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Button
|
|
53
|
+
key={key}
|
|
54
|
+
themeName={`${themeName}.link`}
|
|
55
|
+
tokens={{ ...tokens, isOpen }}
|
|
56
|
+
handlePress={() => {
|
|
57
|
+
onShare?.(key)
|
|
58
|
+
onClick?.(key)
|
|
59
|
+
}}
|
|
60
|
+
aria-label={ariaLabel}
|
|
61
|
+
{...(href ? { href, rel: 'noopener noreferrer', target: '_blank', as: 'a' } : {})}
|
|
62
|
+
role="option"
|
|
63
|
+
>
|
|
64
|
+
<Icon themeName={`${themeName}.linkIcons`} icon={icon} />
|
|
65
|
+
</Button>
|
|
66
|
+
)
|
|
67
|
+
})}
|
|
68
|
+
</div>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const ShareButton = (props: TShareButtonProps) => {
|
|
73
|
+
const {
|
|
74
|
+
ariaLabel,
|
|
75
|
+
icon,
|
|
76
|
+
id,
|
|
77
|
+
sharingLinksList,
|
|
78
|
+
onShare,
|
|
79
|
+
customTheme,
|
|
80
|
+
themeName = 'shareButton',
|
|
81
|
+
tokens,
|
|
82
|
+
...rest
|
|
83
|
+
} = props
|
|
84
|
+
|
|
85
|
+
const [isOpen, setIsOpen] = useState(false)
|
|
86
|
+
|
|
87
|
+
const containerTheme = useThemeContext(`${themeName}.container`, tokens, customTheme)
|
|
88
|
+
|
|
89
|
+
const handleClick = (e: PressEvent) => {
|
|
90
|
+
setIsOpen(!isOpen)
|
|
91
|
+
if (isOpen) {
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
const firstOption = e.target.parentElement?.lastChild?.firstChild as HTMLElement
|
|
96
|
+
firstOption?.focus()
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const handleKeyDown: React.KeyboardEventHandler = (e) => {
|
|
101
|
+
const openShareButton = e.currentTarget.firstChild as HTMLElement
|
|
102
|
+
const listBox = e.currentTarget.lastChild as HTMLElement
|
|
103
|
+
const firstOption = listBox.firstChild as HTMLElement
|
|
104
|
+
|
|
105
|
+
const lastOption = listBox.lastChild as HTMLElement
|
|
106
|
+
|
|
107
|
+
const { listDirection } = tokens ?? {}
|
|
108
|
+
|
|
109
|
+
if (listDirection === 'row') {
|
|
110
|
+
if (e.key === 'ArrowRight' && e.target === openShareButton) {
|
|
111
|
+
firstOption?.focus()
|
|
112
|
+
e.preventDefault()
|
|
113
|
+
}
|
|
114
|
+
if (e.key === 'ArrowLeft' && e.target === openShareButton) {
|
|
115
|
+
lastOption.focus()
|
|
116
|
+
e.preventDefault()
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (listDirection === 'column') {
|
|
121
|
+
if (e.key === 'ArrowDown' && e.target === openShareButton) {
|
|
122
|
+
firstOption?.focus()
|
|
123
|
+
e.preventDefault()
|
|
124
|
+
}
|
|
125
|
+
if (e.key === 'ArrowUp' && e.target === openShareButton) {
|
|
126
|
+
lastOption.focus()
|
|
127
|
+
e.preventDefault()
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (e.key === 'Escape') {
|
|
132
|
+
setIsOpen(false)
|
|
133
|
+
openShareButton?.focus()
|
|
134
|
+
}
|
|
135
|
+
if (document.activeElement === listBox) {
|
|
136
|
+
openShareButton?.focus()
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<FocusScope autoFocus restoreFocus contain={isOpen}>
|
|
142
|
+
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
|
|
143
|
+
<div className={containerTheme} onKeyDown={handleKeyDown}>
|
|
144
|
+
<ButtonWithForwardRef
|
|
145
|
+
themeName={`${themeName}.button`}
|
|
146
|
+
tokens={{ ...tokens, isOpen }}
|
|
147
|
+
aria-label={ariaLabel}
|
|
148
|
+
aria-haspopup="listbox"
|
|
149
|
+
aria-expanded={isOpen ? 'true' : 'false'}
|
|
150
|
+
aria-controls="share-buttons"
|
|
151
|
+
handlePress={handleClick}
|
|
152
|
+
{...rest}
|
|
153
|
+
>
|
|
154
|
+
<Icon themeName={`${themeName}.icon`} icon={icon ?? 'Share'} />
|
|
155
|
+
</ButtonWithForwardRef>
|
|
156
|
+
{isOpen && (
|
|
157
|
+
<IconsContainer
|
|
158
|
+
id={id}
|
|
159
|
+
sharingLinksList={sharingLinksList}
|
|
160
|
+
onShare={onShare}
|
|
161
|
+
isOpen={isOpen}
|
|
162
|
+
setIsOpen={setIsOpen}
|
|
163
|
+
themeName={themeName}
|
|
164
|
+
customTheme={customTheme}
|
|
165
|
+
tokens={tokens}
|
|
166
|
+
/>
|
|
167
|
+
)}
|
|
168
|
+
</div>
|
|
169
|
+
</FocusScope>
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
export default ShareButton
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type React from 'react'
|
|
2
|
+
import type { TToken } from '../../providers/Theme/interface'
|
|
3
|
+
import type { TDefaultComponent } from '../../types/components'
|
|
4
|
+
|
|
5
|
+
export interface TShareButtonProps extends TDefaultComponent<TShareButtonTokens> {
|
|
6
|
+
id: string
|
|
7
|
+
icon?: React.ReactNode
|
|
8
|
+
ariaLabel: string
|
|
9
|
+
sharingLinksList: TShareButtonLink[]
|
|
10
|
+
onShare?: (sharingMedium: string) => void
|
|
11
|
+
offset?: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface TShareButtonTokens extends TToken {
|
|
15
|
+
listDirection: 'row' | 'column'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface TIconsContainerProps extends Omit<TShareButtonProps, 'ariaLabel' | 'icon'> {
|
|
19
|
+
isOpen: boolean
|
|
20
|
+
setIsOpen: (isOpen: boolean) => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TShareButtonLink {
|
|
24
|
+
ariaLabel: string
|
|
25
|
+
icon?: React.ReactNode
|
|
26
|
+
key: string
|
|
27
|
+
onClick?: (linkKey: string) => void
|
|
28
|
+
href?: string
|
|
29
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Canvas, Meta, Story } from '@storybook/addon-docs'
|
|
2
|
+
import { ArgTypes } from '@storybook/blocks'
|
|
3
|
+
import ShareButtonExample from '../../storybook/ShareButtonExample'
|
|
4
|
+
|
|
5
|
+
<Meta title="Base Components/Share Button" component={ShareButtonExample} onShare={() => console.log('shared')} />
|
|
6
|
+
|
|
7
|
+
export const Template = (args) => <ShareButtonExample {...args} />
|
|
8
|
+
|
|
9
|
+
# ShareButton
|
|
10
|
+
|
|
11
|
+
#### Share button component. Can be used to display sharing links to other social media platforms or other medias (email, links, etc.)
|
|
12
|
+
|
|
13
|
+
## Props
|
|
14
|
+
|
|
15
|
+
<ArgTypes />
|
|
16
|
+
|
|
17
|
+
## Showcase
|
|
18
|
+
|
|
19
|
+
## Column share button
|
|
20
|
+
|
|
21
|
+
<Canvas>
|
|
22
|
+
<Story
|
|
23
|
+
name="Column Share Button"
|
|
24
|
+
args={{
|
|
25
|
+
tokens: {
|
|
26
|
+
listDirection: 'column',
|
|
27
|
+
},
|
|
28
|
+
offset: 20,
|
|
29
|
+
}}
|
|
30
|
+
>
|
|
31
|
+
{Template.bind({})}
|
|
32
|
+
</Story>
|
|
33
|
+
</Canvas>
|
|
34
|
+
|
|
35
|
+
## Row share button
|
|
36
|
+
|
|
37
|
+
<Canvas>
|
|
38
|
+
<Story
|
|
39
|
+
name="Row Share Button"
|
|
40
|
+
args={{
|
|
41
|
+
tokens: {
|
|
42
|
+
listDirection: 'row',
|
|
43
|
+
},
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
{Template.bind({})}
|
|
47
|
+
</Story>
|
|
48
|
+
</Canvas>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import generateUtmTags from './generateUtmTags'
|
|
4
|
+
import useWindow from './useWindow'
|
|
5
|
+
|
|
6
|
+
const useFacebookShareUrl = (media: string, medium: string, urlToShare: string) => {
|
|
7
|
+
const { windowLocation, windowTitle } = useWindow()
|
|
8
|
+
|
|
9
|
+
const currentURL = urlToShare ?? windowLocation
|
|
10
|
+
const utm = generateUtmTags(media, medium)
|
|
11
|
+
const fullUrl = `${currentURL}${utm}`
|
|
12
|
+
return `https://www.facebook.com/sharer.php?u=${fullUrl}&t=${windowTitle}`
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default useFacebookShareUrl
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import generateUtmTags from './generateUtmTags'
|
|
4
|
+
import useWindow from './useWindow'
|
|
5
|
+
|
|
6
|
+
const useMailToShareUrl = (media: string, medium: string, urlToShare: string) => {
|
|
7
|
+
const { windowLocation, windowTitle } = useWindow()
|
|
8
|
+
|
|
9
|
+
const currentURL = urlToShare ?? windowLocation
|
|
10
|
+
const utm = generateUtmTags(media, medium)
|
|
11
|
+
const fullUrl = `${currentURL}${utm}`
|
|
12
|
+
return `mailto:?to=&body=${windowTitle}%20${fullUrl}`
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default useMailToShareUrl
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import generateUtmTags from './generateUtmTags'
|
|
4
|
+
import useWindow from './useWindow'
|
|
5
|
+
|
|
6
|
+
const useTwitterShareUrl = (media: string, medium: string, urlToShare: string) => {
|
|
7
|
+
const { windowLocation } = useWindow()
|
|
8
|
+
|
|
9
|
+
const currentURL = urlToShare ?? windowLocation
|
|
10
|
+
const utm = generateUtmTags(media, medium)
|
|
11
|
+
const fullUrl = `${currentURL}${utm}`
|
|
12
|
+
return `https://twitter.com/intent/tweet?text=${fullUrl}`
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default useTwitterShareUrl
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from 'react'
|
|
4
|
+
|
|
5
|
+
const useWindow = () => {
|
|
6
|
+
const [windowLocation, setWindowLocation] = useState<string>()
|
|
7
|
+
const [windowTitle, setWindowTitle] = useState<string>()
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
setWindowLocation(window.location.href)
|
|
11
|
+
setWindowTitle(window.document.title)
|
|
12
|
+
}, [])
|
|
13
|
+
|
|
14
|
+
return { windowLocation, windowTitle }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default useWindow
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import Div100vh from 'react-div-100vh'
|
|
5
|
+
import { useSidePanel } from '../../providers/SidePanel'
|
|
6
|
+
import useThemeContext from '../../providers/Theme/hooks'
|
|
7
|
+
import RenderWithSlide from '../../transitions/RenderWithSlide'
|
|
8
|
+
import SidePanelTransition from '../../transitions/SidePanelTransition'
|
|
9
|
+
import Modal from '../Modal'
|
|
10
|
+
import type { TSidePanelProps } from './interface'
|
|
11
|
+
|
|
12
|
+
const SidePanel = (props: TSidePanelProps) => {
|
|
13
|
+
const {
|
|
14
|
+
children,
|
|
15
|
+
closeBtnRender,
|
|
16
|
+
themeName = 'sidePanel',
|
|
17
|
+
tokens,
|
|
18
|
+
TransitionAnimation = RenderWithSlide,
|
|
19
|
+
PanelTransition = SidePanelTransition,
|
|
20
|
+
customTheme,
|
|
21
|
+
} = props
|
|
22
|
+
|
|
23
|
+
const wrapperTheme = useThemeContext(`${themeName}.wrapper`, tokens, customTheme)
|
|
24
|
+
const containerTheme = useThemeContext(`${themeName}.container`, tokens, customTheme)
|
|
25
|
+
const innerContainerTheme = useThemeContext(`${themeName}.innerContainer`, tokens, customTheme)
|
|
26
|
+
|
|
27
|
+
const { overlayState, overlayProps } = useSidePanel()
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Modal state={overlayState} {...overlayProps} transitionComponent={PanelTransition} isDismissable>
|
|
31
|
+
<Div100vh className={wrapperTheme}>
|
|
32
|
+
{closeBtnRender && closeBtnRender()}
|
|
33
|
+
<TransitionAnimation isVisible={overlayState.isOpen}>
|
|
34
|
+
<div className={containerTheme}>
|
|
35
|
+
<div className={innerContainerTheme}>{children}</div>
|
|
36
|
+
</div>
|
|
37
|
+
</TransitionAnimation>
|
|
38
|
+
</Div100vh>
|
|
39
|
+
</Modal>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default React.memo(SidePanel)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react'
|
|
2
|
+
import type React from 'react'
|
|
3
|
+
import type { TDefaultComponent } from '../../types/components'
|
|
4
|
+
|
|
5
|
+
export interface ISidePanelProps extends HTMLAttributes<HTMLElement> {
|
|
6
|
+
id: string
|
|
7
|
+
children?: React.ReactNode
|
|
8
|
+
closeBtnRender?: () => React.ReactNode
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10
|
+
TransitionAnimation?: (props: unknown) => JSX.Element
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
12
|
+
PanelTransition?: (props: unknown) => JSX.Element
|
|
13
|
+
onCloseCallBack?: () => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type TSidePanelProps = ISidePanelProps & TDefaultComponent
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{/* side-panel.stories.mdx */}
|
|
2
|
+
|
|
3
|
+
import { Canvas, Meta, Story } from '@storybook/addon-docs'
|
|
4
|
+
import { ButtonWithForwardRef } from '../Button'
|
|
5
|
+
import SidePanel from './'
|
|
6
|
+
import { SidePanelContextProvider, useSidePanel } from '../../providers/SidePanel'
|
|
7
|
+
|
|
8
|
+
<Meta
|
|
9
|
+
title="BASE COMPONENTS/Side Panel"
|
|
10
|
+
component={SidePanel}
|
|
11
|
+
args={{
|
|
12
|
+
|
|
13
|
+
}}
|
|
14
|
+
/>
|
|
15
|
+
|
|
16
|
+
export const SidePanelControl = () => {
|
|
17
|
+
const { buttonProps } = useSidePanel()
|
|
18
|
+
if (buttonProps == null) {
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
return (
|
|
22
|
+
<ButtonWithForwardRef variant="black" {...buttonProps?.openButtonProps} ref={buttonProps?.openButtonRef}>
|
|
23
|
+
Open
|
|
24
|
+
</ButtonWithForwardRef>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const Template = (args) => (
|
|
29
|
+
<SidePanelContextProvider
|
|
30
|
+
onOpenCallback={() => console.log('Side panel is now opened!')}
|
|
31
|
+
onCloseCallback={() => console.log('Side panel is now closed!')}
|
|
32
|
+
>
|
|
33
|
+
<SidePanelControl />
|
|
34
|
+
<SidePanel {...args}>
|
|
35
|
+
<div>Hello world!</div>
|
|
36
|
+
</SidePanel>
|
|
37
|
+
</SidePanelContextProvider>
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# Side Panel
|
|
41
|
+
|
|
42
|
+
<Canvas>
|
|
43
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
44
|
+
</Canvas>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useTab } from '@react-aria/tabs'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { ButtonWithForwardRef } from '../../../Button'
|
|
4
|
+
import type { TTab } from '../../interface'
|
|
5
|
+
|
|
6
|
+
function Tab({ item, state }: TTab) {
|
|
7
|
+
const { key, rendered } = item
|
|
8
|
+
const ref = React.useRef(null)
|
|
9
|
+
const { tabProps } = useTab({ key }, state, ref)
|
|
10
|
+
const isDisabled = state.disabledKeys.has(key)
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<ButtonWithForwardRef {...tabProps} ref={ref} disabled={isDisabled}>
|
|
14
|
+
{rendered}
|
|
15
|
+
</ButtonWithForwardRef>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default Tab
|