@4alldigital/foundation-ui--core 3.0.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/LICENSE.txt +21 -0
- package/package.json +35 -0
- package/src/__mocks__/_examples/cnbc.ts +146 -0
- package/src/__mocks__/_examples/nrg.ts +222 -0
- package/src/__mocks__/empty-module.js +0 -0
- package/src/__mocks__/fileMock.js +3 -0
- package/src/__mocks__/fileTransformer.js +8 -0
- package/src/__mocks__/mockSearchData.js +511 -0
- package/src/__mocks__/nrglogo.svg +74 -0
- package/src/__mocks__/styleMock.js +3 -0
- package/src/__mocks__/tempPolyFills.js +5 -0
- package/src/components/Accordion/Accordion.stories.tsx +33 -0
- package/src/components/Accordion/Accordion.tsx +53 -0
- package/src/components/Accordion/Accordion.types.ts +8 -0
- package/src/components/Accordion/index.ts +1 -0
- package/src/components/AnimationCounter/AnimationCounter.stories.tsx +22 -0
- package/src/components/AnimationCounter/AnimationCounter.tsx +51 -0
- package/src/components/AnimationCounter/AnimationCounter.types.ts +10 -0
- package/src/components/AnimationCounter/index.ts +1 -0
- package/src/components/AnimationSet1/AnimationSet1.stories.tsx +36 -0
- package/src/components/AnimationSet1/AnimationSet1.tsx +107 -0
- package/src/components/AnimationSet1/AnimationSet1.types.ts +12 -0
- package/src/components/AnimationSet1/index.ts +1 -0
- package/src/components/Authenticator/Authenticator.stories.tsx +37 -0
- package/src/components/Authenticator/Authenticator.tsx +84 -0
- package/src/components/Authenticator/Authenticator.types.ts +7 -0
- package/src/components/Authenticator/index.ts +1 -0
- package/src/components/Avatar/Avatar.stories.tsx +26 -0
- package/src/components/Avatar/Avatar.tsx +88 -0
- package/src/components/Avatar/Avatar.types.ts +8 -0
- package/src/components/Avatar/index.ts +1 -0
- package/src/components/Banner/Banner.stories.tsx +59 -0
- package/src/components/Banner/Banner.tsx +60 -0
- package/src/components/Banner/Banner.types.ts +9 -0
- package/src/components/Banner/index.ts +1 -0
- package/src/components/Blockquote/Blockquote.stories.tsx +20 -0
- package/src/components/Blockquote/Blockquote.tsx +32 -0
- package/src/components/Blockquote/Blockquote.types.ts +8 -0
- package/src/components/Blockquote/index.ts +1 -0
- package/src/components/Button/Button.stories.tsx +50 -0
- package/src/components/Button/Button.tsx +117 -0
- package/src/components/Button/Button.types.ts +43 -0
- package/src/components/Button/index.ts +1 -0
- package/src/components/ButtonGroup/ButtonGroup.stories.tsx +59 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +35 -0
- package/src/components/ButtonGroup/ButtonGroup.types.ts +5 -0
- package/src/components/ButtonGroup/index.ts +1 -0
- package/src/components/Calendar/Calendar.stories.tsx +100 -0
- package/src/components/Calendar/Calendar.tsx +91 -0
- package/src/components/Calendar/Calendar.types.ts +10 -0
- package/src/components/Calendar/index.ts +2 -0
- package/src/components/Card/Card.stories.tsx +487 -0
- package/src/components/Card/Card.tsx +32 -0
- package/src/components/Card/Card.types.ts +79 -0
- package/src/components/Card/constants/index.ts +8 -0
- package/src/components/Card/index.ts +1 -0
- package/src/components/Card/types/CardBasic/CardBasic.tsx +262 -0
- package/src/components/Card/types/CardBasic/CardBasic.types.ts +7 -0
- package/src/components/Card/types/CardBasic/index.ts +1 -0
- package/src/components/Card/types/CardData/CardData.tsx +68 -0
- package/src/components/Card/types/CardData/CardData.types.ts +21 -0
- package/src/components/Card/types/CardData/index.ts +1 -0
- package/src/components/Card/types/CardHorz/CardHorz.tsx +80 -0
- package/src/components/Card/types/CardHorz/CardHorz.types.ts +8 -0
- package/src/components/Card/types/CardHorz/index.ts +1 -0
- package/src/components/Card/types/CardIcon/CardIcon.tsx +76 -0
- package/src/components/Card/types/CardIcon/CardIcon.types.ts +8 -0
- package/src/components/Card/types/CardIcon/index.ts +1 -0
- package/src/components/Card/types/CardMedia/CardMedia.tsx +277 -0
- package/src/components/Card/types/CardMedia/CardMedia.types.ts +5 -0
- package/src/components/Card/types/CardMedia/index.ts +1 -0
- package/src/components/Card/types/CardVideo/CardVideo.tsx +262 -0
- package/src/components/Card/types/CardVideo/CardVideo.types.ts +11 -0
- package/src/components/Card/types/CardVideo/index.ts +1 -0
- package/src/components/CardGrid/CardGrid.stories.tsx +122 -0
- package/src/components/CardGrid/CardGrid.tsx +25 -0
- package/src/components/CardGrid/CardGrid.types.ts +7 -0
- package/src/components/CardGrid/index.ts +1 -0
- package/src/components/Carousel/Carousel.stories.tsx +351 -0
- package/src/components/Carousel/Carousel.tsx +174 -0
- package/src/components/Carousel/Carousel.types.ts +32 -0
- package/src/components/Carousel/MIGRATION.md +156 -0
- package/src/components/Carousel/index.ts +1 -0
- package/src/components/Cart/Cart.stories.tsx +92 -0
- package/src/components/Cart/Cart.tsx +194 -0
- package/src/components/Cart/Cart.types.ts +4 -0
- package/src/components/Cart/index.ts +1 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +18 -0
- package/src/components/Checkbox/Checkbox.tsx +38 -0
- package/src/components/Checkbox/Checkbox.types.ts +15 -0
- package/src/components/Checkbox/index.ts +1 -0
- package/src/components/Chip/Chip.stories.tsx +37 -0
- package/src/components/Chip/Chip.tsx +104 -0
- package/src/components/Chip/Chip.types.ts +13 -0
- package/src/components/Chip/index.ts +1 -0
- package/src/components/Collapsible/Collapsible.stories.tsx +139 -0
- package/src/components/Collapsible/Collapsible.tsx +75 -0
- package/src/components/Collapsible/Collapsible.types.ts +14 -0
- package/src/components/Collapsible/index.ts +3 -0
- package/src/components/Container/Container.stories.tsx +17 -0
- package/src/components/Container/Container.tsx +51 -0
- package/src/components/Container/Container.types.ts +17 -0
- package/src/components/Container/index.ts +1 -0
- package/src/components/ContentPageLayout/ContentPageLayout.stories.tsx +17 -0
- package/src/components/ContentPageLayout/ContentPageLayout.tsx +38 -0
- package/src/components/ContentPageLayout/ContentPageLayout.types.ts +17 -0
- package/src/components/ContentPageLayout/index.ts +1 -0
- package/src/components/ContentRowsLayout/ContentRowsLayout.stories.tsx +19 -0
- package/src/components/ContentRowsLayout/ContentRowsLayout.tsx +30 -0
- package/src/components/ContentRowsLayout/ContentRowsLayout.types.ts +15 -0
- package/src/components/ContentRowsLayout/index.ts +1 -0
- package/src/components/Copy/Copy.stories.tsx +28 -0
- package/src/components/Copy/Copy.tsx +43 -0
- package/src/components/Copy/Copy.types.tsx +53 -0
- package/src/components/Copy/index.tsx +1 -0
- package/src/components/DisplayHeading/DisplayHeading.stories.tsx +17 -0
- package/src/components/DisplayHeading/DisplayHeading.tsx +43 -0
- package/src/components/DisplayHeading/DisplayHeading.types.ts +8 -0
- package/src/components/DisplayHeading/index.ts +1 -0
- package/src/components/FileUpload/FileUpload.stories.tsx +18 -0
- package/src/components/FileUpload/FileUpload.tsx +41 -0
- package/src/components/FileUpload/FileUpload.types.ts +9 -0
- package/src/components/FileUpload/index.ts +1 -0
- package/src/components/Footer/Footer.stories.tsx +17 -0
- package/src/components/Footer/Footer.tsx +78 -0
- package/src/components/Footer/Footer.types.ts +4 -0
- package/src/components/Footer/index.ts +1 -0
- package/src/components/Form/Form.stories.tsx +81 -0
- package/src/components/Form/Form.tsx +98 -0
- package/src/components/Form/Form.types.ts +34 -0
- package/src/components/Form/index.ts +1 -0
- package/src/components/FormField/FormField.stories.tsx +205 -0
- package/src/components/FormField/FormField.tsx +258 -0
- package/src/components/FormField/FormField.types.ts +89 -0
- package/src/components/FormField/index.ts +1 -0
- package/src/components/FormSelect/FormSelect.stories.tsx +27 -0
- package/src/components/FormSelect/FormSelect.tsx +46 -0
- package/src/components/FormSelect/FormSelect.types.ts +45 -0
- package/src/components/FormSelect/index.ts +1 -0
- package/src/components/FullContentBackgroundImage/FullContentBackgroundImage.stories.tsx +18 -0
- package/src/components/FullContentBackgroundImage/FullContentBackgroundImage.tsx +26 -0
- package/src/components/FullContentBackgroundImage/FullContentBackgroundImage.types.ts +6 -0
- package/src/components/FullContentBackgroundImage/index.ts +1 -0
- package/src/components/FullScreenVideoModal/FullScreenVideoModal.stories.tsx +34 -0
- package/src/components/FullScreenVideoModal/FullScreenVideoModal.tsx +41 -0
- package/src/components/FullScreenVideoModal/FullScreenVideoModal.types.ts +9 -0
- package/src/components/FullScreenVideoModal/index.ts +1 -0
- package/src/components/Header/Header.stories.tsx +51 -0
- package/src/components/Header/Header.tsx +170 -0
- package/src/components/Header/Header.types.ts +11 -0
- package/src/components/Header/index.ts +1 -0
- package/src/components/Heading/Heading.stories.tsx +57 -0
- package/src/components/Heading/Heading.tsx +47 -0
- package/src/components/Heading/Heading.types.ts +35 -0
- package/src/components/Heading/index.ts +1 -0
- package/src/components/Hero/Hero.stories.tsx +17 -0
- package/src/components/Hero/Hero.tsx +28 -0
- package/src/components/Hero/Hero.types.ts +17 -0
- package/src/components/Hero/index.ts +1 -0
- package/src/components/Hr/Hr.stories.tsx +13 -0
- package/src/components/Hr/Hr.tsx +16 -0
- package/src/components/Hr/Hr.types.ts +3 -0
- package/src/components/Hr/index.ts +1 -0
- package/src/components/HtmlContent/HtmlContent.stories.tsx +29 -0
- package/src/components/HtmlContent/HtmlContent.tsx +36 -0
- package/src/components/HtmlContent/HtmlContent.types.ts +6 -0
- package/src/components/HtmlContent/index.ts +1 -0
- package/src/components/Icon/Icon.stories.tsx +26 -0
- package/src/components/Icon/Icon.tsx +24 -0
- package/src/components/Icon/Icon.types.ts +8 -0
- package/src/components/Icon/index.ts +2 -0
- package/src/components/Image/Image.stories.tsx +32 -0
- package/src/components/Image/Image.tsx +71 -0
- package/src/components/Image/Image.types.ts +20 -0
- package/src/components/Image/index.ts +1 -0
- package/src/components/Label/Label.stories.tsx +18 -0
- package/src/components/Label/Label.tsx +17 -0
- package/src/components/Label/Label.types.ts +9 -0
- package/src/components/Label/index.ts +1 -0
- package/src/components/Link/Link.stories.tsx +25 -0
- package/src/components/Link/Link.tsx +85 -0
- package/src/components/Link/Link.types.ts +14 -0
- package/src/components/Link/index.ts +1 -0
- package/src/components/List/List.stories.tsx +38 -0
- package/src/components/List/List.tsx +17 -0
- package/src/components/List/List.types.ts +27 -0
- package/src/components/List/index.ts +1 -0
- package/src/components/ListItem/ListItem.stories.tsx +61 -0
- package/src/components/ListItem/ListItem.tsx +53 -0
- package/src/components/ListItem/ListItem.types.ts +10 -0
- package/src/components/ListItem/index.ts +1 -0
- package/src/components/Loader/Loader.stories.tsx +17 -0
- package/src/components/Loader/Loader.tsx +34 -0
- package/src/components/Loader/Loader.types.ts +5 -0
- package/src/components/Loader/index.ts +1 -0
- package/src/components/Logo/Logo.stories.tsx +17 -0
- package/src/components/Logo/Logo.tsx +17 -0
- package/src/components/Logo/Logo.types.ts +6 -0
- package/src/components/Logo/index.ts +1 -0
- package/src/components/Menu/Menu.stories.tsx +37 -0
- package/src/components/Menu/Menu.tsx +45 -0
- package/src/components/Menu/Menu.types.ts +15 -0
- package/src/components/Menu/index.ts +1 -0
- package/src/components/Notice/Notice.stories.tsx +49 -0
- package/src/components/Notice/Notice.tsx +63 -0
- package/src/components/Notice/Notice.types.ts +11 -0
- package/src/components/Notice/index.ts +1 -0
- package/src/components/OTPInput/OTPInput.stories.tsx +18 -0
- package/src/components/OTPInput/OTPInput.tsx +80 -0
- package/src/components/OTPInput/OTPInput.types.ts +8 -0
- package/src/components/OTPInput/index.ts +1 -0
- package/src/components/PanelCards/PanelCards.stories.tsx +125 -0
- package/src/components/PanelCards/PanelCards.tsx +81 -0
- package/src/components/PanelCards/PanelCards.types.ts +11 -0
- package/src/components/PanelCards/index.ts +1 -0
- package/src/components/PanelCustom/PanelCustom.stories.tsx +18 -0
- package/src/components/PanelCustom/PanelCustom.tsx +39 -0
- package/src/components/PanelCustom/PanelCustom.types.ts +20 -0
- package/src/components/PanelCustom/index.ts +1 -0
- package/src/components/PanelFeature/PanelFeature.stories.tsx +46 -0
- package/src/components/PanelFeature/PanelFeature.tsx +83 -0
- package/src/components/PanelFeature/PanelFeature.types.ts +27 -0
- package/src/components/PanelFeature/index.ts +1 -0
- package/src/components/PanelHero/PanelHero.stories.tsx +126 -0
- package/src/components/PanelHero/PanelHero.tsx +184 -0
- package/src/components/PanelHero/PanelHero.types.ts +19 -0
- package/src/components/PanelHero/index.ts +1 -0
- package/src/components/PanelIntro/PanelIntro.stories.tsx +38 -0
- package/src/components/PanelIntro/PanelIntro.tsx +139 -0
- package/src/components/PanelIntro/PanelIntro.types.ts +19 -0
- package/src/components/PanelIntro/index.ts +1 -0
- package/src/components/PanelProduct/PanelProduct.stories.tsx +24 -0
- package/src/components/PanelProduct/PanelProduct.tsx +87 -0
- package/src/components/PanelProduct/PanelProduct.types.ts +14 -0
- package/src/components/PanelProduct/index.ts +1 -0
- package/src/components/PanelScroller/PanelScroller.stories.tsx +81 -0
- package/src/components/PanelScroller/PanelScroller.tsx +58 -0
- package/src/components/PanelScroller/PanelScroller.types.ts +8 -0
- package/src/components/PanelScroller/index.ts +1 -0
- package/src/components/PanelVideo/PanelVideo.stories.tsx +42 -0
- package/src/components/PanelVideo/PanelVideo.tsx +81 -0
- package/src/components/PanelVideo/PanelVideo.types.ts +11 -0
- package/src/components/PanelVideo/index.ts +1 -0
- package/src/components/Radio/Radio.stories.tsx +24 -0
- package/src/components/Radio/Radio.tsx +44 -0
- package/src/components/Radio/Radio.types.ts +13 -0
- package/src/components/Radio/index.ts +1 -0
- package/src/components/Schedule/Schedule.stories.tsx +96 -0
- package/src/components/Schedule/Schedule.tsx +118 -0
- package/src/components/Schedule/Schedule.types.ts +64 -0
- package/src/components/Schedule/index.ts +1 -0
- package/src/components/ScheduleItem/ScheduleItem.stories.tsx +21 -0
- package/src/components/ScheduleItem/ScheduleItem.tsx +77 -0
- package/src/components/ScheduleItem/ScheduleItem.types.ts +8 -0
- package/src/components/ScheduleItem/index.ts +1 -0
- package/src/components/Screen/Screen.stories.tsx +27 -0
- package/src/components/Screen/Screen.tsx +63 -0
- package/src/components/Screen/Screen.types.ts +16 -0
- package/src/components/Screen/index.ts +1 -0
- package/src/components/ShadcnButton/ShadcnButton.tsx +57 -0
- package/src/components/ShadcnButton/index.ts +2 -0
- package/src/components/ShadcnCarousel/ShadcnCarousel.tsx +261 -0
- package/src/components/ShadcnCarousel/index.ts +9 -0
- package/src/components/Share/Share.stories.tsx +17 -0
- package/src/components/Share/Share.tsx +60 -0
- package/src/components/Share/Share.types.ts +12 -0
- package/src/components/Share/index.ts +1 -0
- package/src/components/SubscriptionManager/SubscriptionManager.stories.tsx +177 -0
- package/src/components/SubscriptionManager/SubscriptionManager.tsx +369 -0
- package/src/components/SubscriptionManager/SubscriptionManager.types.ts +36 -0
- package/src/components/SubscriptionManager/index.ts +1 -0
- package/src/components/Switch/Switch.stories.tsx +20 -0
- package/src/components/Switch/Switch.tsx +30 -0
- package/src/components/Switch/Switch.types.ts +7 -0
- package/src/components/Switch/index.ts +1 -0
- package/src/components/Tabs/Tabs.stories.tsx +34 -0
- package/src/components/Tabs/Tabs.tsx +42 -0
- package/src/components/Tabs/Tabs.types.ts +8 -0
- package/src/components/Tabs/index.ts +1 -0
- package/src/components/TextInput/TextInput.stories.tsx +18 -0
- package/src/components/TextInput/TextInput.tsx +78 -0
- package/src/components/TextInput/TextInput.types.ts +81 -0
- package/src/components/TextInput/index.ts +1 -0
- package/src/components/Video/Video.stories.tsx +75 -0
- package/src/components/Video/Video.tsx +280 -0
- package/src/components/Video/Video.types.ts +147 -0
- package/src/components/Video/index.ts +1 -0
- package/src/components/VisitUs/VisitUs.stories.tsx +32 -0
- package/src/components/VisitUs/VisitUs.tsx +56 -0
- package/src/components/VisitUs/VisitUs.types.ts +13 -0
- package/src/components/VisitUs/index.ts +1 -0
- package/src/components/index.ts +143 -0
- package/src/constants/index.ts +6 -0
- package/src/context/Amplify/index.tsx +65 -0
- package/src/context/App/index.tsx +93 -0
- package/src/context/Cart/index.tsx +64 -0
- package/src/context/ExampleContext/index.tsx +34 -0
- package/src/context/Theme/index.tsx +37 -0
- package/src/context/index.ts +18 -0
- package/src/features/Search/Search.stories.tsx +395 -0
- package/src/features/Search/Search.tsx +204 -0
- package/src/features/Search/Search.types.ts +41 -0
- package/src/features/Search/config/config-helper.ts +219 -0
- package/src/features/Search/index.ts +1 -0
- package/src/features/Search/view-helpers/appendClassName.ts +14 -0
- package/src/features/Search/view-helpers/formatResult.ts +97 -0
- package/src/features/Search/view-helpers/getFilterValueDisplay.ts +10 -0
- package/src/features/Search/view-helpers/getUrlSanitizer.ts +23 -0
- package/src/features/Search/view-helpers/index.ts +4 -0
- package/src/features/Search/views/Layout/Layout.tsx +50 -0
- package/src/features/Search/views/Layout/Layout.types.ts +13 -0
- package/src/features/Search/views/Layout/index.ts +1 -0
- package/src/features/Search/views/MultiCheckboxFacet/MultiCheckboxFacet.tsx +85 -0
- package/src/features/Search/views/MultiCheckboxFacet/MultiCheckboxFacet.types.ts +5 -0
- package/src/features/Search/views/MultiCheckboxFacet/index.ts +1 -0
- package/src/features/Search/views/Paging/Paging.tsx +35 -0
- package/src/features/Search/views/Paging/Paging.types.ts +24 -0
- package/src/features/Search/views/Paging/index.ts +1 -0
- package/src/features/Search/views/PagingInfo/PagingInfo.tsx +34 -0
- package/src/features/Search/views/PagingInfo/PagingInfo.types.ts +26 -0
- package/src/features/Search/views/PagingInfo/index.ts +1 -0
- package/src/features/Search/views/Result/Result.tsx +84 -0
- package/src/features/Search/views/Result/Result.types.ts +47 -0
- package/src/features/Search/views/Result/index.ts +1 -0
- package/src/features/Search/views/Results/Results.tsx +16 -0
- package/src/features/Search/views/Results/Results.types.ts +24 -0
- package/src/features/Search/views/Results/index.ts +1 -0
- package/src/features/Search/views/ResultsPerPage/ResultsPerPage.tsx +32 -0
- package/src/features/Search/views/ResultsPerPage/ResultsPerPage.types.ts +26 -0
- package/src/features/Search/views/ResultsPerPage/index.ts +1 -0
- package/src/features/Search/views/SearchBox/SearchBox.tsx +51 -0
- package/src/features/Search/views/SearchBox/SearchBox.types.ts +10 -0
- package/src/features/Search/views/SearchBox/index.ts +1 -0
- package/src/features/Search/views/Sidebar/Sidebar.tsx +14 -0
- package/src/features/Search/views/Sidebar/Sidebar.types.ts +3 -0
- package/src/features/Search/views/Sidebar/index.ts +1 -0
- package/src/features/Search/views/SingleLinksFacet/SingleLinksFacet.tsx +62 -0
- package/src/features/Search/views/SingleLinksFacet/SingleLinksFacet.types.ts +5 -0
- package/src/features/Search/views/SingleLinksFacet/index.ts +1 -0
- package/src/features/Search/views/SingleSelectFacet/SingleSelectFacet.tsx +34 -0
- package/src/features/Search/views/SingleSelectFacet/SingleSelectFacet.types.ts +5 -0
- package/src/features/Search/views/SingleSelectFacet/index.ts +1 -0
- package/src/features/Search/views/Sorting/Sorting.tsx +24 -0
- package/src/features/Search/views/Sorting/Sorting.types.ts +25 -0
- package/src/features/Search/views/Sorting/index.ts +1 -0
- package/src/features/index.ts +11 -0
- package/src/forms/ForgotPasswordForm/ForgotPasswordForm.stories.tsx +19 -0
- package/src/forms/ForgotPasswordForm/ForgotPasswordForm.tsx +28 -0
- package/src/forms/ForgotPasswordForm/ForgotPasswordForm.types.ts +3 -0
- package/src/forms/ForgotPasswordForm/index.ts +1 -0
- package/src/forms/LoginForm/LoginForm.stories.tsx +67 -0
- package/src/forms/LoginForm/LoginForm.tsx +112 -0
- package/src/forms/LoginForm/LoginForm.types.ts +7 -0
- package/src/forms/LoginForm/index.ts +1 -0
- package/src/forms/ProfileForm/ProfileForm.stories.tsx +23 -0
- package/src/forms/ProfileForm/ProfileForm.tsx +40 -0
- package/src/forms/ProfileForm/ProfileForm.types.ts +6 -0
- package/src/forms/ProfileForm/index.ts +1 -0
- package/src/forms/PromoCodeForm/PromoCodeForm.stories.tsx +19 -0
- package/src/forms/PromoCodeForm/PromoCodeForm.tsx +22 -0
- package/src/forms/PromoCodeForm/PromoCodeForm.types.ts +4 -0
- package/src/forms/PromoCodeForm/index.ts +1 -0
- package/src/forms/RegisterForm/RegisterForm.stories.tsx +85 -0
- package/src/forms/RegisterForm/RegisterForm.tsx +108 -0
- package/src/forms/RegisterForm/RegisterForm.types.ts +6 -0
- package/src/forms/RegisterForm/index.ts +1 -0
- package/src/forms/ResetPasswordAuthForm/ResetPasswordAuthForm.stories.tsx +23 -0
- package/src/forms/ResetPasswordAuthForm/ResetPasswordAuthForm.tsx +39 -0
- package/src/forms/ResetPasswordAuthForm/ResetPasswordAuthForm.types.ts +3 -0
- package/src/forms/ResetPasswordAuthForm/index.ts +1 -0
- package/src/forms/ResetPasswordForm/ResetPasswordForm.stories.tsx +23 -0
- package/src/forms/ResetPasswordForm/ResetPasswordForm.tsx +30 -0
- package/src/forms/ResetPasswordForm/ResetPasswordForm.types.ts +3 -0
- package/src/forms/ResetPasswordForm/index.ts +1 -0
- package/src/forms/SubscriptionForm/SubscriptionForm.stories.tsx +31 -0
- package/src/forms/SubscriptionForm/SubscriptionForm.tsx +46 -0
- package/src/forms/SubscriptionForm/SubscriptionForm.types.ts +6 -0
- package/src/forms/SubscriptionForm/index.ts +1 -0
- package/src/forms/constants/index.ts +13 -0
- package/src/forms/index.ts +17 -0
- package/src/forms/validations/index.ts +39 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useLanguage.ts +18 -0
- package/src/hooks/useTheme.ts +6 -0
- package/src/index.ts +8 -0
- package/src/react-app-env.d.ts +1 -0
- package/src/setupTests.ts +5 -0
- package/src/templates/AccountScreen/AccountScreen.stories.tsx +67 -0
- package/src/templates/AccountScreen/AccountScreen.tsx +78 -0
- package/src/templates/AccountScreen/AccountScreen.types.ts +31 -0
- package/src/templates/AccountScreen/index.ts +1 -0
- package/src/templates/AuthScreen/AuthScreen.stories.tsx +33 -0
- package/src/templates/AuthScreen/AuthScreen.tsx +21 -0
- package/src/templates/AuthScreen/AuthScreen.types.ts +8 -0
- package/src/templates/AuthScreen/index.ts +1 -0
- package/src/templates/CardGridScreen/CardGridScreen.stories.tsx +95 -0
- package/src/templates/CardGridScreen/CardGridScreen.tsx +43 -0
- package/src/templates/CardGridScreen/CardGridScreen.types.ts +11 -0
- package/src/templates/CardGridScreen/index.ts +1 -0
- package/src/templates/CatalogueScreen/CatalogueScreen.stories.tsx +31 -0
- package/src/templates/CatalogueScreen/CatalogueScreen.tsx +21 -0
- package/src/templates/CatalogueScreen/CatalogueScreen.types.ts +8 -0
- package/src/templates/CatalogueScreen/index.ts +1 -0
- package/src/templates/ChallengeLibraryScreen/ChallengeLibraryScreen.stories.tsx +171 -0
- package/src/templates/ChallengeLibraryScreen/ChallengeLibraryScreen.tsx +36 -0
- package/src/templates/ChallengeLibraryScreen/ChallengeLibraryScreen.types.ts +9 -0
- package/src/templates/ChallengeLibraryScreen/index.ts +1 -0
- package/src/templates/ChallengeScreen/ChallengeScreen.stories.tsx +65 -0
- package/src/templates/ChallengeScreen/ChallengeScreen.tsx +88 -0
- package/src/templates/ChallengeScreen/ChallengeScreen.types.ts +22 -0
- package/src/templates/ChallengeScreen/index.ts +1 -0
- package/src/templates/ContentScreen/ContentScreen.stories.tsx +71 -0
- package/src/templates/ContentScreen/ContentScreen.tsx +55 -0
- package/src/templates/ContentScreen/ContentScreen.types.ts +9 -0
- package/src/templates/ContentScreen/index.ts +1 -0
- package/src/templates/DashboardScreen/DashboardScreen.stories.tsx +490 -0
- package/src/templates/DashboardScreen/DashboardScreen.tsx +156 -0
- package/src/templates/DashboardScreen/DashboardScreen.types.ts +28 -0
- package/src/templates/DashboardScreen/index.ts +1 -0
- package/src/templates/FAQScreen/FAQScreen.stories.tsx +278 -0
- package/src/templates/FAQScreen/FAQScreen.tsx +32 -0
- package/src/templates/FAQScreen/FAQScreen.types.ts +14 -0
- package/src/templates/FAQScreen/index.ts +1 -0
- package/src/templates/HomeScreen/HomeScreen.stories.tsx +315 -0
- package/src/templates/HomeScreen/HomeScreen.tsx +50 -0
- package/src/templates/HomeScreen/HomeScreen.types.ts +23 -0
- package/src/templates/HomeScreen/index.ts +1 -0
- package/src/templates/LogoutScreen/LogoutScreen.stories.tsx +20 -0
- package/src/templates/LogoutScreen/LogoutScreen.tsx +25 -0
- package/src/templates/LogoutScreen/LogoutScreen.types.ts +4 -0
- package/src/templates/LogoutScreen/index.ts +1 -0
- package/src/templates/MenuScreen/MenuScreen.stories.tsx +36 -0
- package/src/templates/MenuScreen/MenuScreen.tsx +32 -0
- package/src/templates/MenuScreen/MenuScreen.types.ts +11 -0
- package/src/templates/MenuScreen/index.ts +1 -0
- package/src/templates/NotFoundScreen/NotFoundScreen.stories.tsx +20 -0
- package/src/templates/NotFoundScreen/NotFoundScreen.tsx +31 -0
- package/src/templates/NotFoundScreen/NotFoundScreen.types.ts +5 -0
- package/src/templates/NotFoundScreen/index.ts +1 -0
- package/src/templates/PasswordResetAuthScreen/PasswordResetAuthScreen.stories.tsx +27 -0
- package/src/templates/PasswordResetAuthScreen/PasswordResetAuthScreen.tsx +20 -0
- package/src/templates/PasswordResetAuthScreen/PasswordResetAuthScreen.types.ts +6 -0
- package/src/templates/PasswordResetAuthScreen/index.ts +1 -0
- package/src/templates/PasswordResetScreen/PasswordResetScreen.stories.tsx +22 -0
- package/src/templates/PasswordResetScreen/PasswordResetScreen.tsx +19 -0
- package/src/templates/PasswordResetScreen/PasswordResetScreen.types.ts +6 -0
- package/src/templates/PasswordResetScreen/index.ts +1 -0
- package/src/templates/ProfileScreen/ProfileScreen.stories.tsx +41 -0
- package/src/templates/ProfileScreen/ProfileScreen.tsx +30 -0
- package/src/templates/ProfileScreen/ProfileScreen.types.ts +24 -0
- package/src/templates/ProfileScreen/index.ts +1 -0
- package/src/templates/ScheduleScreen/ScheduleScreen.stories.tsx +174 -0
- package/src/templates/ScheduleScreen/ScheduleScreen.tsx +29 -0
- package/src/templates/ScheduleScreen/ScheduleScreen.types.ts +9 -0
- package/src/templates/ScheduleScreen/index.ts +1 -0
- package/src/templates/SubscriptionScreen/SubscriptionScreen.stories.tsx +98 -0
- package/src/templates/SubscriptionScreen/SubscriptionScreen.tsx +49 -0
- package/src/templates/SubscriptionScreen/SubscriptionScreen.types.ts +28 -0
- package/src/templates/SubscriptionScreen/index.ts +1 -0
- package/src/templates/WorkoutScreen/WorkoutScreen.stories.tsx +173 -0
- package/src/templates/WorkoutScreen/WorkoutScreen.tsx +230 -0
- package/src/templates/WorkoutScreen/WorkoutScreen.types.ts +34 -0
- package/src/templates/WorkoutScreen/index.ts +1 -0
- package/src/templates/index.ts +40 -0
- package/src/translations/en.ts +777 -0
- package/src/translations/fr.ts +182 -0
- package/src/translations/index.ts +2 -0
- package/src/utils/htmlParser/index.tsx +22 -0
- package/src/utils/index.ts +38 -0
- package/src/utils/parseDuration/index.ts +94 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
const strings = {
|
|
2
|
+
GLOBAL: {},
|
|
3
|
+
FORMS: {
|
|
4
|
+
LOGIN_FORM: {
|
|
5
|
+
TITLE: 'Connexion',
|
|
6
|
+
SUBMIT: 'Connexion',
|
|
7
|
+
FORGOT_PASSWORD: 'Mot de passe oublié ?',
|
|
8
|
+
REGISTER: "S'inscrire",
|
|
9
|
+
EMAIL: 'Email',
|
|
10
|
+
PASSWORD: 'Mot de passe',
|
|
11
|
+
},
|
|
12
|
+
REGISTER_FORM: {
|
|
13
|
+
TITLE: "S'inscrire",
|
|
14
|
+
SUBMIT: "S'inscrire",
|
|
15
|
+
EMAIL: 'Email',
|
|
16
|
+
PASSWORD: 'Mot de passe',
|
|
17
|
+
PASSWORD_DESCRIPTION:
|
|
18
|
+
'Le mot de passe doit comporter au moins 8 caractères et contenir au moins un chiffre, une majuscule, une minuscule et un caractère spécial.',
|
|
19
|
+
},
|
|
20
|
+
FORGOT_PASSWORD_FORM: {
|
|
21
|
+
TITLE: 'Mot de passe oublié',
|
|
22
|
+
SUBMIT: 'Envoyer un email de réinitialisation',
|
|
23
|
+
EMAIL: 'Email',
|
|
24
|
+
},
|
|
25
|
+
RESET_PASSWORD_FORM: {
|
|
26
|
+
TITLE: 'Réinitialiser le mot de passe',
|
|
27
|
+
SUBMIT: 'Réinitialiser le mot de passe',
|
|
28
|
+
PASSWORD: 'Mot de passe',
|
|
29
|
+
CONFIRM_PASSWORD: 'Confirmer le mot de passe',
|
|
30
|
+
},
|
|
31
|
+
PROFILE_FORM: {
|
|
32
|
+
TITLE: 'Profil',
|
|
33
|
+
SUBMIT: 'Enregistrer',
|
|
34
|
+
FIRST_NAME: 'Prénom',
|
|
35
|
+
LAST_NAME: 'Nom',
|
|
36
|
+
AVATAR: 'Avatar',
|
|
37
|
+
EMAIL: 'Email',
|
|
38
|
+
PASSWORD: 'Mot de passe',
|
|
39
|
+
PASSWORD_DESCRIPTION:
|
|
40
|
+
'Le mot de passe doit comporter au moins 8 caractères et contenir au moins un chiffre, une majuscule, une minuscule et un caractère spécial.',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
UI: {
|
|
44
|
+
SHOW: 'Afficher',
|
|
45
|
+
NO_IMAGE: "Pas d'image",
|
|
46
|
+
UPLOAD: 'Télécharger',
|
|
47
|
+
SAVE: 'Enregistrer',
|
|
48
|
+
CANCEL: 'Annuler',
|
|
49
|
+
DELETE: 'Supprimer',
|
|
50
|
+
CONTINUE_WITH_SOCIAL: 'Continuer avec un compte social',
|
|
51
|
+
SINGLE_SIGNON: 'Authentification unique',
|
|
52
|
+
LOGIN_WITH_GOOGLE: 'Connexion avec Google',
|
|
53
|
+
LOGIN_WITH_APPLE: 'Connexion avec Apple',
|
|
54
|
+
SIGNUP_WITH_GOOGLE: "S'inscrire avec Google",
|
|
55
|
+
SIGNUP_WITH_APPLE: "S'inscrire avec Apple",
|
|
56
|
+
BACK_TO_LOGIN: 'Retour à la connexion',
|
|
57
|
+
FORGOT_PASSWORD: 'Mot de passe oublié ?',
|
|
58
|
+
SUBMIT: 'Envoyer',
|
|
59
|
+
LOGIN: 'Connexion',
|
|
60
|
+
LOGOUT: 'Déconnexion',
|
|
61
|
+
REGISTER: "S'inscrire",
|
|
62
|
+
SOCIAL: {
|
|
63
|
+
GOOGLE: 'Google',
|
|
64
|
+
FACEBOOK: 'Facebook',
|
|
65
|
+
TWITTER: 'Twitter',
|
|
66
|
+
EMAIL: 'Email',
|
|
67
|
+
},
|
|
68
|
+
READ_MORE: 'Lire la suite',
|
|
69
|
+
READ_LESS: 'Voir moins',
|
|
70
|
+
CLOSE: 'Fermer',
|
|
71
|
+
BACK: 'Retour',
|
|
72
|
+
SHARE: 'Partager',
|
|
73
|
+
DOWNLOAD: 'Télécharger',
|
|
74
|
+
FORMAT_HOUR: '{hour}h',
|
|
75
|
+
FORMAT_HOURS: '{hours}h',
|
|
76
|
+
FORMAT_MINUTE: '{minute}min',
|
|
77
|
+
FORMAT_MINUTES: '{minutes}min',
|
|
78
|
+
LOAD_MORE_LABEL: 'Charger plus',
|
|
79
|
+
NO_MORE_RESULTS: "C'est tout, les amis.",
|
|
80
|
+
UNKNOWN_ERROR_TITLE: 'Erreur inconnue',
|
|
81
|
+
UNKNOWN_ERROR_MESSAGE: 'Désolé, quelque chose de mauvais est arrivé ! Veuillez réessayer.',
|
|
82
|
+
CONTENT_SORT_TITLE: 'Trier par',
|
|
83
|
+
CONTENT_FILTERS_TITLE: 'Filtres',
|
|
84
|
+
CONTENT_FILTERS_LABEL: 'Filtrer',
|
|
85
|
+
CLOSE_FILTERS_LABEL: 'Terminé',
|
|
86
|
+
CLEAR_ALL_FILTERS_LABEL: 'Tout effacer',
|
|
87
|
+
CLEAR_FILTERS_LABEL: 'Effacer',
|
|
88
|
+
MORE_ITEMS_LABEL: 'Éléments suivants',
|
|
89
|
+
PREVIOUS_ITEMS_LABEL: 'Éléments précédents',
|
|
90
|
+
CHOOSE_BTN_LABEL: 'Choisir',
|
|
91
|
+
ADD_BTN_LABEL: 'Ajouter',
|
|
92
|
+
SEND_BTN_LABEL: 'Envoyer',
|
|
93
|
+
CANCEL_BTN_LABEL: 'Annuler',
|
|
94
|
+
DONE_BTN_LABEL: 'Terminé',
|
|
95
|
+
EDIT_BTN_LABEL: 'Modifier',
|
|
96
|
+
CHANGE_BTN_LABEL: 'Changer',
|
|
97
|
+
REMOVE_BTN_LABEL: 'Supprimer',
|
|
98
|
+
MESSAGE_PROMPT_BTN_LABEL: 'Ajouter un',
|
|
99
|
+
SELECT_FILE_BTN_LABEL: 'Sélectionner un fichier',
|
|
100
|
+
TOO_MANY_REQUESTS_MESSAGE: 'Trop de demandes. Veuillez réessayer plus tard.',
|
|
101
|
+
COPYRIGHT: "Droits d'auteur",
|
|
102
|
+
ALL_RIGHTS_RESERVED: 'Tous droits réservés',
|
|
103
|
+
APP_CAMERA_PERMISSION: 'Autorisation de la caméra',
|
|
104
|
+
APP_CAMERA_PERMISSION_DENIED: 'Autorisation de la caméra refusée',
|
|
105
|
+
APP_NEED_ACCESS_CAMERA: "Cette application a besoin d'accéder à votre caméra",
|
|
106
|
+
ASK_ME_LATER: 'Demandez-moi plus tard',
|
|
107
|
+
PRIVACY_POLICY: 'Politique de confidentialité',
|
|
108
|
+
CREATE_ACCOUNT: 'Créer un compte',
|
|
109
|
+
COMPLETE: 'Terminer',
|
|
110
|
+
EDIT: 'Modifier',
|
|
111
|
+
PREV: 'Précédent',
|
|
112
|
+
NEXT: 'Suivant',
|
|
113
|
+
GET_STARTED: 'Commencer',
|
|
114
|
+
START_SEARCH: 'Commencer la recherche',
|
|
115
|
+
READ_MORE_LABEL: 'Lire la suite',
|
|
116
|
+
READ_LESS_LABEL: 'Voir moins',
|
|
117
|
+
CLOSE_LABEL: 'Fermer',
|
|
118
|
+
CLOSE_HINT: 'Fermer cette entrée',
|
|
119
|
+
BACK_LABEL: 'Retour',
|
|
120
|
+
SHARE_LABEL: 'Partager',
|
|
121
|
+
VIEW_MORE_LABEL: 'Voir plus',
|
|
122
|
+
VIEW_LESS_LABEL: 'Voir moins',
|
|
123
|
+
GOT_IT: 'Compris',
|
|
124
|
+
MORE: 'Plus',
|
|
125
|
+
MORE_DETAILS: 'Plus de détails',
|
|
126
|
+
MORE_INFO: "Plus d'informations",
|
|
127
|
+
LEARN_MORE: 'En savoir plus',
|
|
128
|
+
LOW: 'Bas',
|
|
129
|
+
MEDIUM: 'Moyen',
|
|
130
|
+
HIGH: 'Élevé',
|
|
131
|
+
VERY_HIGH: 'Très élevé',
|
|
132
|
+
VERY_LOW: 'Très bas',
|
|
133
|
+
GOOD: 'Bon',
|
|
134
|
+
BAD: 'Mauvais',
|
|
135
|
+
STRONG: 'Fort',
|
|
136
|
+
SAVE_CONTINUE: 'Enregistrer et continuer',
|
|
137
|
+
SAVE_FINISH: 'Enregistrer et terminer',
|
|
138
|
+
FINISH: 'Terminer',
|
|
139
|
+
SKIP: 'Passer',
|
|
140
|
+
ADD: 'Ajouter',
|
|
141
|
+
ADDED: 'Ajouté',
|
|
142
|
+
ADD_ANOTHER: 'Ajouter un autre',
|
|
143
|
+
CREATE_PROFILE: 'Créer un profil',
|
|
144
|
+
CONTINUE_NO_ACCOUNT: 'Continuer sans compte',
|
|
145
|
+
REQUIRED_MISSING: 'Champ requis manquant',
|
|
146
|
+
RESET: 'Réinitialiser',
|
|
147
|
+
APPLY_FILTER: 'Appliquer le filtre',
|
|
148
|
+
START: 'Démarrer',
|
|
149
|
+
HELP: 'Aide',
|
|
150
|
+
WHAT_IS_THIS: "Qu'est-ce que c'est ?",
|
|
151
|
+
CARD_VIEW: 'Vue en carte',
|
|
152
|
+
LIST_VIEW: 'Vue en liste',
|
|
153
|
+
FILTER: 'Filtrer',
|
|
154
|
+
NO_RESULTS: 'Aucun résultat',
|
|
155
|
+
CONTINUE: 'Continuer',
|
|
156
|
+
CONTINUE_BROWSING: 'Continuer la navigation',
|
|
157
|
+
VIEW: 'Voir',
|
|
158
|
+
INFORMATION: 'Information',
|
|
159
|
+
DELETE_HINT: 'Supprimer cette entrée',
|
|
160
|
+
VISIT_WEBSITE: 'Visiter le site web',
|
|
161
|
+
TAKE_AGAIN: 'Reprendre',
|
|
162
|
+
ADD_MORE: 'Ajouter plus',
|
|
163
|
+
REQUEST_SENT: 'Demande envoyée',
|
|
164
|
+
CUSTOMISE: 'Personnaliser',
|
|
165
|
+
SET_LOCATION: 'Définir la localisation',
|
|
166
|
+
COUNTY_NOT_FOUND: 'Comté non trouvé',
|
|
167
|
+
NO_RESOURCES_FOUND: 'Aucune ressource trouvée',
|
|
168
|
+
PATHWAY: 'Chemin',
|
|
169
|
+
CLICK_TO_NAVIGATE: 'Cliquez pour naviguer',
|
|
170
|
+
INPUT_FIELD: 'Champ de saisie',
|
|
171
|
+
GO_BACK: 'Retourner',
|
|
172
|
+
NAVIGATES_PREV: "Navigue vers l'écran précédent",
|
|
173
|
+
REMOVE: 'Supprimer',
|
|
174
|
+
NO_INTERNET_CONNECTION: 'Pas de connexion Internet',
|
|
175
|
+
CHECK_CONNECTION: 'Veuillez vérifier votre connexion Internet et réessayer.',
|
|
176
|
+
EXPLORE: 'Explorer',
|
|
177
|
+
NO_ACCOUNT: 'Pas de compte ?',
|
|
178
|
+
},
|
|
179
|
+
ERRORS: {},
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export default strings;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { attributesToProps, domToReact } from 'html-react-parser';
|
|
2
|
+
import Link from '../../components/Link';
|
|
3
|
+
import Copy from '../../components/Copy';
|
|
4
|
+
|
|
5
|
+
export const options = {
|
|
6
|
+
replace(domNode: any) {
|
|
7
|
+
// Handle a tag links.
|
|
8
|
+
if (domNode.name === 'a') {
|
|
9
|
+
const props = attributesToProps(domNode.attribs);
|
|
10
|
+
return <Link {...props}>{domToReact(domNode.children, options)}</Link>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Handle p tag copy.
|
|
14
|
+
if (domNode.attribs && domNode.name === 'p') {
|
|
15
|
+
const props = attributesToProps(domNode.attribs);
|
|
16
|
+
return <Copy {...props}>{domToReact(domNode.children, options)}</Copy>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Handle default.
|
|
20
|
+
return domNode;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Duration, parse } from 'iso8601-duration';
|
|
2
|
+
import { type ClassValue, clsx } from 'clsx';
|
|
3
|
+
import { twMerge } from 'tailwind-merge';
|
|
4
|
+
|
|
5
|
+
// Export Parse duration helper.
|
|
6
|
+
export * from './parseDuration';
|
|
7
|
+
|
|
8
|
+
// Utility function to merge Tailwind classes with clsx
|
|
9
|
+
export function cn(...inputs: ClassValue[]) {
|
|
10
|
+
return twMerge(clsx(inputs));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function truncateString(str: string, maxLen: number = 60) {
|
|
14
|
+
return str.length > maxLen ? str.slice(0, maxLen - 1).trim() + '...' : str;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Function to convert ISO 8601 duration to human-readable format
|
|
18
|
+
export function formatDuration(duration: string): string {
|
|
19
|
+
// Parse the ISO 8601 duration
|
|
20
|
+
const parsedDuration: Duration = parse(duration);
|
|
21
|
+
|
|
22
|
+
// Format the duration components to a human-readable string
|
|
23
|
+
const parts: string[] = [];
|
|
24
|
+
if (parsedDuration.years) parts.push(`${parsedDuration.years} years`);
|
|
25
|
+
if (parsedDuration.months) parts.push(`${parsedDuration.months} months`);
|
|
26
|
+
if (parsedDuration.weeks) parts.push(`${parsedDuration.weeks} weeks`);
|
|
27
|
+
if (parsedDuration.days) parts.push(`${parsedDuration.days} days`);
|
|
28
|
+
if (parsedDuration.hours) parts.push(`${parsedDuration.hours} hours`);
|
|
29
|
+
if (parsedDuration.minutes) parts.push(`${parsedDuration.minutes} minutes`);
|
|
30
|
+
if (parsedDuration.seconds) parts.push(`${parsedDuration.seconds} seconds`);
|
|
31
|
+
|
|
32
|
+
return parts.join(', ');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getRandomImageFromArray(images?: string[]): string | undefined {
|
|
36
|
+
if (!images || images.length === 0) return undefined;
|
|
37
|
+
return images?.map((image: any) => image)?.[Math.floor(Math.random() * images?.map((image: any) => image).length)];
|
|
38
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
interface DurationValues {
|
|
2
|
+
years?: number
|
|
3
|
+
months?: number
|
|
4
|
+
weeks?: number
|
|
5
|
+
days?: number
|
|
6
|
+
hours?: number
|
|
7
|
+
minutes?: number
|
|
8
|
+
seconds?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type Duration = {
|
|
12
|
+
negative?: boolean
|
|
13
|
+
} & DurationValues
|
|
14
|
+
|
|
15
|
+
export type ParseConfig = {
|
|
16
|
+
allowMultipleFractions?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const DEFAULT_PARSE_CONFIG: ParseConfig = {
|
|
20
|
+
allowMultipleFractions: true,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const units: Array<{ unit: keyof DurationValues; symbol: string }> = [
|
|
24
|
+
{ unit: 'years', symbol: 'Y' },
|
|
25
|
+
{ unit: 'months', symbol: 'M' },
|
|
26
|
+
{ unit: 'weeks', symbol: 'W' },
|
|
27
|
+
{ unit: 'days', symbol: 'D' },
|
|
28
|
+
{ unit: 'hours', symbol: 'H' },
|
|
29
|
+
{ unit: 'minutes', symbol: 'M' },
|
|
30
|
+
{ unit: 'seconds', symbol: 'S' },
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
// Construction of the duration regex
|
|
34
|
+
const r = (name: string, unit: string): string => `((?<${name}>-?\\d*[\\.,]?\\d+)${unit})?`
|
|
35
|
+
const durationRegex = new RegExp(
|
|
36
|
+
[
|
|
37
|
+
'(?<negative>-)?P',
|
|
38
|
+
r('years', 'Y'),
|
|
39
|
+
r('months', 'M'),
|
|
40
|
+
r('weeks', 'W'),
|
|
41
|
+
r('days', 'D'),
|
|
42
|
+
'(T',
|
|
43
|
+
r('hours', 'H'),
|
|
44
|
+
r('minutes', 'M'),
|
|
45
|
+
r('seconds', 'S'),
|
|
46
|
+
')?', // end optional time
|
|
47
|
+
].join(''),
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
function parseNum(s: string): number | undefined {
|
|
51
|
+
if (s === '' || s === undefined || s === null) {
|
|
52
|
+
return undefined
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return parseFloat(s.replace(',', '.'))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const InvalidDurationError = new Error('Invalid duration')
|
|
59
|
+
export const MultipleFractionsError = new Error('Multiple fractions specified')
|
|
60
|
+
|
|
61
|
+
export function parseDuration(durationStr: string, config: ParseConfig = DEFAULT_PARSE_CONFIG): Duration {
|
|
62
|
+
const match = durationRegex.exec(durationStr);
|
|
63
|
+
if (!match || !match.groups) {
|
|
64
|
+
throw InvalidDurationError;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let empty = true;
|
|
68
|
+
let decimalFractionCount = 0;
|
|
69
|
+
const values: DurationValues = {};
|
|
70
|
+
for (const { unit } of units) {
|
|
71
|
+
if (match.groups[unit]) {
|
|
72
|
+
empty = false;
|
|
73
|
+
values[unit] = parseNum(match.groups[unit]);
|
|
74
|
+
|
|
75
|
+
if (!config.allowMultipleFractions && !Number.isInteger(values[unit])) {
|
|
76
|
+
decimalFractionCount++;
|
|
77
|
+
if (decimalFractionCount > 1) {
|
|
78
|
+
throw MultipleFractionsError;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (empty) {
|
|
85
|
+
throw InvalidDurationError;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const duration: Duration = values;
|
|
89
|
+
if (match.groups.negative) {
|
|
90
|
+
duration.negative = true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return duration;
|
|
94
|
+
}
|