@coinbase/cds-common 0.0.0 → 8.13.2
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/CHANGELOG.md +37 -0
- package/README.md +3 -0
- package/dts/accordion/AccordionProvider.d.ts +30 -0
- package/dts/accordion/AccordionProvider.d.ts.map +1 -0
- package/dts/animation/accordion.d.ts +4 -0
- package/dts/animation/accordion.d.ts.map +1 -0
- package/dts/animation/border.d.ts +10 -0
- package/dts/animation/border.d.ts.map +1 -0
- package/dts/animation/carousel.d.ts +8 -0
- package/dts/animation/carousel.d.ts.map +1 -0
- package/dts/animation/collapsible.d.ts +15 -0
- package/dts/animation/collapsible.d.ts.map +1 -0
- package/dts/animation/dot.d.ts +6 -0
- package/dts/animation/dot.d.ts.map +1 -0
- package/dts/animation/drawer.d.ts +20 -0
- package/dts/animation/drawer.d.ts.map +1 -0
- package/dts/animation/dropdown.d.ts +27 -0
- package/dts/animation/dropdown.d.ts.map +1 -0
- package/dts/animation/fullscreenModal.d.ts +12 -0
- package/dts/animation/fullscreenModal.d.ts.map +1 -0
- package/dts/animation/likeButton.d.ts +6 -0
- package/dts/animation/likeButton.d.ts.map +1 -0
- package/dts/animation/menu.d.ts +29 -0
- package/dts/animation/menu.d.ts.map +1 -0
- package/dts/animation/modal.d.ts +10 -0
- package/dts/animation/modal.d.ts.map +1 -0
- package/dts/animation/overlay.d.ts +6 -0
- package/dts/animation/overlay.d.ts.map +1 -0
- package/dts/animation/paddle.d.ts +7 -0
- package/dts/animation/paddle.d.ts.map +1 -0
- package/dts/animation/progress.d.ts +3 -0
- package/dts/animation/progress.d.ts.map +1 -0
- package/dts/animation/rotate.d.ts +3 -0
- package/dts/animation/rotate.d.ts.map +1 -0
- package/dts/animation/select.d.ts +4 -0
- package/dts/animation/select.d.ts.map +1 -0
- package/dts/animation/sparkline.d.ts +7 -0
- package/dts/animation/sparkline.d.ts.map +1 -0
- package/dts/animation/tabs.d.ts +5 -0
- package/dts/animation/tabs.d.ts.map +1 -0
- package/dts/animation/toast.d.ts +12 -0
- package/dts/animation/toast.d.ts.map +1 -0
- package/dts/animation/tooltip.d.ts +21 -0
- package/dts/animation/tooltip.d.ts.map +1 -0
- package/dts/cards/getCardBodySpacingProps.d.ts +17 -0
- package/dts/cards/getCardBodySpacingProps.d.ts.map +1 -0
- package/dts/color/blendColors.d.ts +24 -0
- package/dts/color/blendColors.d.ts.map +1 -0
- package/dts/color/colorToHex.d.ts +7 -0
- package/dts/color/colorToHex.d.ts.map +1 -0
- package/dts/color/darkenColor.d.ts +2 -0
- package/dts/color/darkenColor.d.ts.map +1 -0
- package/dts/color/getAccessibleForegroundGradient.d.ts +18 -0
- package/dts/color/getAccessibleForegroundGradient.d.ts.map +1 -0
- package/dts/color/getBlendedColor.d.ts +121 -0
- package/dts/color/getBlendedColor.d.ts.map +1 -0
- package/dts/color/getContrastRatio.d.ts +6 -0
- package/dts/color/getContrastRatio.d.ts.map +1 -0
- package/dts/color/getLuminance.d.ts +13 -0
- package/dts/color/getLuminance.d.ts.map +1 -0
- package/dts/color/isAccessibleColor.d.ts +23 -0
- package/dts/color/isAccessibleColor.d.ts.map +1 -0
- package/dts/color/isLightOrDarkColor.d.ts +2 -0
- package/dts/color/isLightOrDarkColor.d.ts.map +1 -0
- package/dts/color/overrideAlpha.d.ts +8 -0
- package/dts/color/overrideAlpha.d.ts.map +1 -0
- package/dts/core/theme.d.ts +285 -0
- package/dts/core/theme.d.ts.map +1 -0
- package/dts/dates/DateInputValidationError.d.ts +6 -0
- package/dts/dates/DateInputValidationError.d.ts.map +1 -0
- package/dts/dates/IntlDateFormat.d.ts +42 -0
- package/dts/dates/IntlDateFormat.d.ts.map +1 -0
- package/dts/dates/generateCalendarMonth.d.ts +5 -0
- package/dts/dates/generateCalendarMonth.d.ts.map +1 -0
- package/dts/dates/getISOStringLocal.d.ts +5 -0
- package/dts/dates/getISOStringLocal.d.ts.map +1 -0
- package/dts/dates/getMidnightDate.d.ts +5 -0
- package/dts/dates/getMidnightDate.d.ts.map +1 -0
- package/dts/dates/getTimesFromDatesAndRanges.d.ts +7 -0
- package/dts/dates/getTimesFromDatesAndRanges.d.ts.map +1 -0
- package/dts/dates/useDateInput.d.ts +39 -0
- package/dts/dates/useDateInput.d.ts.map +1 -0
- package/dts/dates/useDateInputValidation.d.ts +55 -0
- package/dts/dates/useDateInputValidation.d.ts.map +1 -0
- package/dts/hooks/useEventHandler.d.ts +12 -0
- package/dts/hooks/useEventHandler.d.ts.map +1 -0
- package/dts/hooks/useFallbackShape.d.ts +14 -0
- package/dts/hooks/useFallbackShape.d.ts.map +1 -0
- package/dts/hooks/useGroupToggler.d.ts +26 -0
- package/dts/hooks/useGroupToggler.d.ts.map +1 -0
- package/dts/hooks/useHasMounted.d.ts +2 -0
- package/dts/hooks/useHasMounted.d.ts.map +1 -0
- package/dts/hooks/useIndexCounter.d.ts +25 -0
- package/dts/hooks/useIndexCounter.d.ts.map +1 -0
- package/dts/hooks/useInputVariant.d.ts +3 -0
- package/dts/hooks/useInputVariant.d.ts.map +1 -0
- package/dts/hooks/useLogo.d.ts +26 -0
- package/dts/hooks/useLogo.d.ts.map +1 -0
- package/dts/hooks/useMergeRefs.d.ts +4 -0
- package/dts/hooks/useMergeRefs.d.ts.map +1 -0
- package/dts/hooks/usePrefixedId.d.ts +18 -0
- package/dts/hooks/usePrefixedId.d.ts.map +1 -0
- package/dts/hooks/usePreviousValue.d.ts +2 -0
- package/dts/hooks/usePreviousValue.d.ts.map +1 -0
- package/dts/hooks/usePreviousValues.d.ts +5 -0
- package/dts/hooks/usePreviousValues.d.ts.map +1 -0
- package/dts/hooks/useRefMap.d.ts +15 -0
- package/dts/hooks/useRefMap.d.ts.map +1 -0
- package/dts/hooks/useSort.d.ts +19 -0
- package/dts/hooks/useSort.d.ts.map +1 -0
- package/dts/hooks/useSubBrandLogo.d.ts +70 -0
- package/dts/hooks/useSubBrandLogo.d.ts.map +1 -0
- package/dts/hooks/useTimer.d.ts +7 -0
- package/dts/hooks/useTimer.d.ts.map +1 -0
- package/dts/hooks/useToggler.d.ts +10 -0
- package/dts/hooks/useToggler.d.ts.map +1 -0
- package/dts/hooks/useValueChanges.d.ts +8 -0
- package/dts/hooks/useValueChanges.d.ts.map +1 -0
- package/dts/index.d.ts +8 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/internal/data/accounts.d.ts +369 -0
- package/dts/internal/data/accounts.d.ts.map +1 -0
- package/dts/internal/data/announcementCards.d.ts +10 -0
- package/dts/internal/data/announcementCards.d.ts.map +1 -0
- package/dts/internal/data/asset.d.ts +171 -0
- package/dts/internal/data/asset.d.ts.map +1 -0
- package/dts/internal/data/assets.d.ts +81 -0
- package/dts/internal/data/assets.d.ts.map +1 -0
- package/dts/internal/data/avatars.d.ts +6 -0
- package/dts/internal/data/avatars.d.ts.map +1 -0
- package/dts/internal/data/dataCards.d.ts +27 -0
- package/dts/internal/data/dataCards.d.ts.map +1 -0
- package/dts/internal/data/featureEntryCards.d.ts +20 -0
- package/dts/internal/data/featureEntryCards.d.ts.map +1 -0
- package/dts/internal/data/feedImages.d.ts +2 -0
- package/dts/internal/data/feedImages.d.ts.map +1 -0
- package/dts/internal/data/iconData.d.ts +2 -0
- package/dts/internal/data/iconData.d.ts.map +1 -0
- package/dts/internal/data/loremIpsum.d.ts +3 -0
- package/dts/internal/data/loremIpsum.d.ts.map +1 -0
- package/dts/internal/data/navigation.d.ts +7 -0
- package/dts/internal/data/navigation.d.ts.map +1 -0
- package/dts/internal/data/prices.d.ts +7 -0
- package/dts/internal/data/prices.d.ts.map +1 -0
- package/dts/internal/data/product.d.ts +33 -0
- package/dts/internal/data/product.d.ts.map +1 -0
- package/dts/internal/data/tabs.d.ts +18 -0
- package/dts/internal/data/tabs.d.ts.map +1 -0
- package/dts/internal/data/users.d.ts +13 -0
- package/dts/internal/data/users.d.ts.map +1 -0
- package/dts/internal/utils/storyBuilder.d.ts +154 -0
- package/dts/internal/utils/storyBuilder.d.ts.map +1 -0
- package/dts/internal/visualizations/SparklineInteractiveData.d.ts +13 -0
- package/dts/internal/visualizations/SparklineInteractiveData.d.ts.map +1 -0
- package/dts/jest/timeTravel.d.ts +15 -0
- package/dts/jest/timeTravel.d.ts.map +1 -0
- package/dts/lottie/lottieUtils.d.ts +14 -0
- package/dts/lottie/lottieUtils.d.ts.map +1 -0
- package/dts/lottie/useStatusAnimationPoller.d.ts +35 -0
- package/dts/lottie/useStatusAnimationPoller.d.ts.map +1 -0
- package/dts/media/getAvatarFallbackColor.d.ts +9 -0
- package/dts/media/getAvatarFallbackColor.d.ts.map +1 -0
- package/dts/media/remoteImageFallbackSrc.d.ts +8 -0
- package/dts/media/remoteImageFallbackSrc.d.ts.map +1 -0
- package/dts/motion/animatedCaret.d.ts +3 -0
- package/dts/motion/animatedCaret.d.ts.map +1 -0
- package/dts/motion/checkbox.d.ts +89 -0
- package/dts/motion/checkbox.d.ts.map +1 -0
- package/dts/motion/dot.d.ts +89 -0
- package/dts/motion/dot.d.ts.map +1 -0
- package/dts/motion/hint.d.ts +52 -0
- package/dts/motion/hint.d.ts.map +1 -0
- package/dts/motion/switch.d.ts +7 -0
- package/dts/motion/switch.d.ts.map +1 -0
- package/dts/motion/tokens.d.ts +904 -0
- package/dts/motion/tokens.d.ts.map +1 -0
- package/dts/motion/utils.d.ts +33 -0
- package/dts/motion/utils.d.ts.map +1 -0
- package/dts/numbers/IntlNumberFormat.d.ts +129 -0
- package/dts/numbers/IntlNumberFormat.d.ts.map +1 -0
- package/dts/numbers/subscript.d.ts +7 -0
- package/dts/numbers/subscript.d.ts.map +1 -0
- package/dts/overlays/ModalContext.d.ts +25 -0
- package/dts/overlays/ModalContext.d.ts.map +1 -0
- package/dts/overlays/OverlayContentContext.d.ts +13 -0
- package/dts/overlays/OverlayContentContext.d.ts.map +1 -0
- package/dts/overlays/PortalContext.d.ts +8 -0
- package/dts/overlays/PortalContext.d.ts.map +1 -0
- package/dts/overlays/ToastProvider.d.ts +82 -0
- package/dts/overlays/ToastProvider.d.ts.map +1 -0
- package/dts/overlays/useAlert.d.ts +8 -0
- package/dts/overlays/useAlert.d.ts.map +1 -0
- package/dts/overlays/useModal.d.ts +8 -0
- package/dts/overlays/useModal.d.ts.map +1 -0
- package/dts/overlays/useOverlay.d.ts +6 -0
- package/dts/overlays/useOverlay.d.ts.map +1 -0
- package/dts/overlays/usePortal.d.ts +2 -0
- package/dts/overlays/usePortal.d.ts.map +1 -0
- package/dts/overlays/usePortalState.d.ts +24 -0
- package/dts/overlays/usePortalState.d.ts.map +1 -0
- package/dts/overlays/useToastQueue.d.ts +11 -0
- package/dts/overlays/useToastQueue.d.ts.map +1 -0
- package/dts/stepper/useStepper.d.ts +45 -0
- package/dts/stepper/useStepper.d.ts.map +1 -0
- package/dts/stepper/utils.d.ts +29 -0
- package/dts/stepper/utils.d.ts.map +1 -0
- package/dts/system/EventHandlerProvider.d.ts +33 -0
- package/dts/system/EventHandlerProvider.d.ts.map +1 -0
- package/dts/system/LocaleProvider.d.ts +15 -0
- package/dts/system/LocaleProvider.d.ts.map +1 -0
- package/dts/system/RefMapContext.d.ts +10 -0
- package/dts/system/RefMapContext.d.ts.map +1 -0
- package/dts/tabs/TabsContext.d.ts +5 -0
- package/dts/tabs/TabsContext.d.ts.map +1 -0
- package/dts/tabs/useTabs.d.ts +34 -0
- package/dts/tabs/useTabs.d.ts.map +1 -0
- package/dts/tokens/accordion.d.ts +7 -0
- package/dts/tokens/accordion.d.ts.map +1 -0
- package/dts/tokens/appSwitcher.d.ts +4 -0
- package/dts/tokens/appSwitcher.d.ts.map +1 -0
- package/dts/tokens/avatar.d.ts +14 -0
- package/dts/tokens/avatar.d.ts.map +1 -0
- package/dts/tokens/banner.d.ts +15 -0
- package/dts/tokens/banner.d.ts.map +1 -0
- package/dts/tokens/borderRadius.d.ts +3 -0
- package/dts/tokens/borderRadius.d.ts.map +1 -0
- package/dts/tokens/button.d.ts +65 -0
- package/dts/tokens/button.d.ts.map +1 -0
- package/dts/tokens/card.d.ts +29 -0
- package/dts/tokens/card.d.ts.map +1 -0
- package/dts/tokens/cell.d.ts +30 -0
- package/dts/tokens/cell.d.ts.map +1 -0
- package/dts/tokens/chip.d.ts +2 -0
- package/dts/tokens/chip.d.ts.map +1 -0
- package/dts/tokens/dot.d.ts +12 -0
- package/dts/tokens/dot.d.ts.map +1 -0
- package/dts/tokens/drawer.d.ts +12 -0
- package/dts/tokens/drawer.d.ts.map +1 -0
- package/dts/tokens/illustrations.d.ts +28 -0
- package/dts/tokens/illustrations.d.ts.map +1 -0
- package/dts/tokens/input.d.ts +6 -0
- package/dts/tokens/input.d.ts.map +1 -0
- package/dts/tokens/interactable.d.ts +5 -0
- package/dts/tokens/interactable.d.ts.map +1 -0
- package/dts/tokens/interactableHeight.d.ts +5 -0
- package/dts/tokens/interactableHeight.d.ts.map +1 -0
- package/dts/tokens/menu.d.ts +3 -0
- package/dts/tokens/menu.d.ts.map +1 -0
- package/dts/tokens/multiContentModule.d.ts +2 -0
- package/dts/tokens/multiContentModule.d.ts.map +1 -0
- package/dts/tokens/navigation.d.ts +2 -0
- package/dts/tokens/navigation.d.ts.map +1 -0
- package/dts/tokens/overlays.d.ts +3 -0
- package/dts/tokens/overlays.d.ts.map +1 -0
- package/dts/tokens/page.d.ts +3 -0
- package/dts/tokens/page.d.ts.map +1 -0
- package/dts/tokens/select.d.ts +7 -0
- package/dts/tokens/select.d.ts.map +1 -0
- package/dts/tokens/sidebar.d.ts +3 -0
- package/dts/tokens/sidebar.d.ts.map +1 -0
- package/dts/tokens/sizing.d.ts +3 -0
- package/dts/tokens/sizing.d.ts.map +1 -0
- package/dts/tokens/sparkline.d.ts +11 -0
- package/dts/tokens/sparkline.d.ts.map +1 -0
- package/dts/tokens/tags.d.ts +18 -0
- package/dts/tokens/tags.d.ts.map +1 -0
- package/dts/tokens/tile.d.ts +4 -0
- package/dts/tokens/tile.d.ts.map +1 -0
- package/dts/tokens/toast.d.ts +5 -0
- package/dts/tokens/toast.d.ts.map +1 -0
- package/dts/tokens/tooltip.d.ts +4 -0
- package/dts/tokens/tooltip.d.ts.map +1 -0
- package/dts/tokens/zIndex.d.ts +14 -0
- package/dts/tokens/zIndex.d.ts.map +1 -0
- package/dts/tour/TourContext.d.ts +6 -0
- package/dts/tour/TourContext.d.ts.map +1 -0
- package/dts/tour/useTour.d.ts +104 -0
- package/dts/tour/useTour.d.ts.map +1 -0
- package/dts/types/AvatarBaseProps.d.ts +6 -0
- package/dts/types/AvatarBaseProps.d.ts.map +1 -0
- package/dts/types/AvatarSize.d.ts +2 -0
- package/dts/types/AvatarSize.d.ts.map +1 -0
- package/dts/types/BannerBaseProps.d.ts +3 -0
- package/dts/types/BannerBaseProps.d.ts.map +1 -0
- package/dts/types/BoxBaseProps.d.ts +75 -0
- package/dts/types/BoxBaseProps.d.ts.map +1 -0
- package/dts/types/ButtonBaseProps.d.ts +8 -0
- package/dts/types/ButtonBaseProps.d.ts.map +1 -0
- package/dts/types/CardHeaderProps.d.ts +12 -0
- package/dts/types/CardHeaderProps.d.ts.map +1 -0
- package/dts/types/CardMediaProps.d.ts +33 -0
- package/dts/types/CardMediaProps.d.ts.map +1 -0
- package/dts/types/CardRemoteImageProps.d.ts +22 -0
- package/dts/types/CardRemoteImageProps.d.ts.map +1 -0
- package/dts/types/CdsPlatform.d.ts +2 -0
- package/dts/types/CdsPlatform.d.ts.map +1 -0
- package/dts/types/CellBaseProps.d.ts +8 -0
- package/dts/types/CellBaseProps.d.ts.map +1 -0
- package/dts/types/Chart.d.ts +29 -0
- package/dts/types/Chart.d.ts.map +1 -0
- package/dts/types/CollapsibleBaseProps.d.ts +2 -0
- package/dts/types/CollapsibleBaseProps.d.ts.map +1 -0
- package/dts/types/Color.d.ts +6 -0
- package/dts/types/Color.d.ts.map +1 -0
- package/dts/types/ComponentEventHandlerProps.d.ts +6 -0
- package/dts/types/ComponentEventHandlerProps.d.ts.map +1 -0
- package/dts/types/DimensionStyles.d.ts +24 -0
- package/dts/types/DimensionStyles.d.ts.map +1 -0
- package/dts/types/Display.d.ts +9 -0
- package/dts/types/Display.d.ts.map +1 -0
- package/dts/types/DotBaseProps.d.ts +5 -0
- package/dts/types/DotBaseProps.d.ts.map +1 -0
- package/dts/types/DotCountBaseProps.d.ts +5 -0
- package/dts/types/DotCountBaseProps.d.ts.map +1 -0
- package/dts/types/ElevationLevels.d.ts +7 -0
- package/dts/types/ElevationLevels.d.ts.map +1 -0
- package/dts/types/FallbackBaseProps.d.ts +10 -0
- package/dts/types/FallbackBaseProps.d.ts.map +1 -0
- package/dts/types/Grid.d.ts +2 -0
- package/dts/types/Grid.d.ts.map +1 -0
- package/dts/types/Helpers.d.ts +8 -0
- package/dts/types/Helpers.d.ts.map +1 -0
- package/dts/types/IconButtonBaseProps.d.ts +3 -0
- package/dts/types/IconButtonBaseProps.d.ts.map +1 -0
- package/dts/types/IconName.d.ts +3 -0
- package/dts/types/IconName.d.ts.map +1 -0
- package/dts/types/IconSize.d.ts +3 -0
- package/dts/types/IconSize.d.ts.map +1 -0
- package/dts/types/IllustrationNames.d.ts +19 -0
- package/dts/types/IllustrationNames.d.ts.map +1 -0
- package/dts/types/IllustrationProps.d.ts +27 -0
- package/dts/types/IllustrationProps.d.ts.map +1 -0
- package/dts/types/InputBaseProps.d.ts +25 -0
- package/dts/types/InputBaseProps.d.ts.map +1 -0
- package/dts/types/LottiePlayer.d.ts +12 -0
- package/dts/types/LottiePlayer.d.ts.map +1 -0
- package/dts/types/LottieSource.d.ts +30 -0
- package/dts/types/LottieSource.d.ts.map +1 -0
- package/dts/types/LottieStatusAnimationProps.d.ts +30 -0
- package/dts/types/LottieStatusAnimationProps.d.ts.map +1 -0
- package/dts/types/Motion.d.ts +71 -0
- package/dts/types/Motion.d.ts.map +1 -0
- package/dts/types/OverlayLifecycleProps.d.ts +19 -0
- package/dts/types/OverlayLifecycleProps.d.ts.map +1 -0
- package/dts/types/Palette.d.ts +5 -0
- package/dts/types/Palette.d.ts.map +1 -0
- package/dts/types/Placement.d.ts +3 -0
- package/dts/types/Placement.d.ts.map +1 -0
- package/dts/types/Position.d.ts +2 -0
- package/dts/types/Position.d.ts.map +1 -0
- package/dts/types/ProgressContainerWithButtonsProps.d.ts +8 -0
- package/dts/types/ProgressContainerWithButtonsProps.d.ts.map +1 -0
- package/dts/types/PulseBaseProps.d.ts +2 -0
- package/dts/types/PulseBaseProps.d.ts.map +1 -0
- package/dts/types/React.d.ts +3 -0
- package/dts/types/React.d.ts.map +1 -0
- package/dts/types/Rect.d.ts +8 -0
- package/dts/types/Rect.d.ts.map +1 -0
- package/dts/types/Responsive.d.ts +10 -0
- package/dts/types/Responsive.d.ts.map +1 -0
- package/dts/types/ResponsiveProps.d.ts +31 -0
- package/dts/types/ResponsiveProps.d.ts.map +1 -0
- package/dts/types/SectionHeaderProps.d.ts +20 -0
- package/dts/types/SectionHeaderProps.d.ts.map +1 -0
- package/dts/types/Shape.d.ts +3 -0
- package/dts/types/Shape.d.ts.map +1 -0
- package/dts/types/SharedAccessibilityProps.d.ts +34 -0
- package/dts/types/SharedAccessibilityProps.d.ts.map +1 -0
- package/dts/types/SharedProps.d.ts +9 -0
- package/dts/types/SharedProps.d.ts.map +1 -0
- package/dts/types/SpacingProps.d.ts +46 -0
- package/dts/types/SpacingProps.d.ts.map +1 -0
- package/dts/types/SparklineInteractiveHeaderBaseProps.d.ts +8 -0
- package/dts/types/SparklineInteractiveHeaderBaseProps.d.ts.map +1 -0
- package/dts/types/SpreadPropsSafely.d.ts +28 -0
- package/dts/types/SpreadPropsSafely.d.ts.map +1 -0
- package/dts/types/StickyFooterProps.d.ts +24 -0
- package/dts/types/StickyFooterProps.d.ts.map +1 -0
- package/dts/types/TagBaseProps.d.ts +7 -0
- package/dts/types/TagBaseProps.d.ts.map +1 -0
- package/dts/types/TextBaseProps.d.ts +10 -0
- package/dts/types/TextBaseProps.d.ts.map +1 -0
- package/dts/types/TooltipBaseProps.d.ts +2 -0
- package/dts/types/TooltipBaseProps.d.ts.map +1 -0
- package/dts/types/TypeOrNumber.d.ts +3 -0
- package/dts/types/TypeOrNumber.d.ts.map +1 -0
- package/dts/types/Visibility.d.ts +5 -0
- package/dts/types/Visibility.d.ts.map +1 -0
- package/dts/types/Weight.d.ts +2 -0
- package/dts/types/Weight.d.ts.map +1 -0
- package/dts/types/index.d.ts +57 -0
- package/dts/types/index.d.ts.map +1 -0
- package/dts/utils/cell.d.ts +6 -0
- package/dts/utils/cell.d.ts.map +1 -0
- package/dts/utils/chart.d.ts +2 -0
- package/dts/utils/chart.d.ts.map +1 -0
- package/dts/utils/circle.d.ts +4 -0
- package/dts/utils/circle.d.ts.map +1 -0
- package/dts/utils/convertDimensionToAspectRatio.d.ts +14 -0
- package/dts/utils/convertDimensionToAspectRatio.d.ts.map +1 -0
- package/dts/utils/convertDimensionToSize.d.ts +8 -0
- package/dts/utils/convertDimensionToSize.d.ts.map +1 -0
- package/dts/utils/convertSizeWithMultiplier.d.ts +12 -0
- package/dts/utils/convertSizeWithMultiplier.d.ts.map +1 -0
- package/dts/utils/debounce.d.ts +5 -0
- package/dts/utils/debounce.d.ts.map +1 -0
- package/dts/utils/delay.d.ts +5 -0
- package/dts/utils/delay.d.ts.map +1 -0
- package/dts/utils/flattenNodes.d.ts +9 -0
- package/dts/utils/flattenNodes.d.ts.map +1 -0
- package/dts/utils/formatCount.d.ts +26 -0
- package/dts/utils/formatCount.d.ts.map +1 -0
- package/dts/utils/getAccessibleColor.d.ts +33 -0
- package/dts/utils/getAccessibleColor.d.ts.map +1 -0
- package/dts/utils/getButtonSpacingProps.d.ts +19 -0
- package/dts/utils/getButtonSpacingProps.d.ts.map +1 -0
- package/dts/utils/getDefaultAspectRatioForIllustration.d.ts +11 -0
- package/dts/utils/getDefaultAspectRatioForIllustration.d.ts.map +1 -0
- package/dts/utils/getDefaultSizeObjectForIllustration.d.ts +6 -0
- package/dts/utils/getDefaultSizeObjectForIllustration.d.ts.map +1 -0
- package/dts/utils/getRectWidthVariant.d.ts +5 -0
- package/dts/utils/getRectWidthVariant.d.ts.map +1 -0
- package/dts/utils/getWidthInEm.d.ts +6 -0
- package/dts/utils/getWidthInEm.d.ts.map +1 -0
- package/dts/utils/join.d.ts +9 -0
- package/dts/utils/join.d.ts.map +1 -0
- package/dts/utils/mergeProps.d.ts +3 -0
- package/dts/utils/mergeProps.d.ts.map +1 -0
- package/dts/utils/mockUtils.d.ts +2 -0
- package/dts/utils/mockUtils.d.ts.map +1 -0
- package/dts/utils/modulate.d.ts +12 -0
- package/dts/utils/modulate.d.ts.map +1 -0
- package/dts/utils/parseDotCountMaxOverflow.d.ts +3 -0
- package/dts/utils/parseDotCountMaxOverflow.d.ts.map +1 -0
- package/dts/visualizations/getProgressCircleParams.d.ts +19 -0
- package/dts/visualizations/getProgressCircleParams.d.ts.map +1 -0
- package/dts/visualizations/getSparklineRange.d.ts +13 -0
- package/dts/visualizations/getSparklineRange.d.ts.map +1 -0
- package/dts/visualizations/getSparklineTransform.d.ts +8 -0
- package/dts/visualizations/getSparklineTransform.d.ts.map +1 -0
- package/dts/visualizations/largestTriangleThreeBucket.d.ts +16 -0
- package/dts/visualizations/largestTriangleThreeBucket.d.ts.map +1 -0
- package/dts/visualizations/useCounter.d.ts +11 -0
- package/dts/visualizations/useCounter.d.ts.map +1 -0
- package/dts/visualizations/useDateLookup.d.ts +12 -0
- package/dts/visualizations/useDateLookup.d.ts.map +1 -0
- package/dts/visualizations/useProgressSize.d.ts +3 -0
- package/dts/visualizations/useProgressSize.d.ts.map +1 -0
- package/dts/visualizations/useSparklineArea.d.ts +3 -0
- package/dts/visualizations/useSparklineArea.d.ts.map +1 -0
- package/dts/visualizations/useSparklineAreaOpacity.d.ts +2 -0
- package/dts/visualizations/useSparklineAreaOpacity.d.ts.map +1 -0
- package/dts/visualizations/useSparklineCoordinates.d.ts +28 -0
- package/dts/visualizations/useSparklineCoordinates.d.ts.map +1 -0
- package/dts/visualizations/useSparklinePath.d.ts +3 -0
- package/dts/visualizations/useSparklinePath.d.ts.map +1 -0
- package/dts/visualizations/useSparklinePathGenerator.d.ts +24 -0
- package/dts/visualizations/useSparklinePathGenerator.d.ts.map +1 -0
- package/dts/visualizations/useTimeseriesPaths.d.ts +11 -0
- package/dts/visualizations/useTimeseriesPaths.d.ts.map +1 -0
- package/dts/visualizations/useVisualizationDimensions.d.ts +20 -0
- package/dts/visualizations/useVisualizationDimensions.d.ts.map +1 -0
- package/esm/accordion/AccordionProvider.js +38 -0
- package/esm/animation/accordion.js +3 -0
- package/esm/animation/border.js +10 -0
- package/esm/animation/carousel.js +21 -0
- package/esm/animation/collapsible.js +75 -0
- package/esm/animation/dot.js +15 -0
- package/esm/animation/drawer.js +19 -0
- package/esm/animation/dropdown.js +31 -0
- package/esm/animation/fullscreenModal.js +39 -0
- package/esm/animation/likeButton.js +18 -0
- package/esm/animation/menu.js +31 -0
- package/esm/animation/modal.js +32 -0
- package/esm/animation/overlay.js +16 -0
- package/esm/animation/paddle.js +17 -0
- package/esm/animation/progress.js +4 -0
- package/esm/animation/rotate.js +5 -0
- package/esm/animation/select.js +16 -0
- package/esm/animation/sparkline.js +8 -0
- package/esm/animation/tabs.js +5 -0
- package/esm/animation/toast.js +36 -0
- package/esm/animation/tooltip.js +87 -0
- package/esm/cards/getCardBodySpacingProps.js +25 -0
- package/esm/color/blendColors.js +44 -0
- package/esm/color/colorToHex.js +11 -0
- package/esm/color/darkenColor.js +5 -0
- package/esm/color/getAccessibleForegroundGradient.js +32 -0
- package/esm/color/getBlendedColor.js +202 -0
- package/esm/color/getContrastRatio.js +11 -0
- package/esm/color/getLuminance.js +28 -0
- package/esm/color/isAccessibleColor.js +31 -0
- package/esm/color/isLightOrDarkColor.js +21 -0
- package/esm/color/overrideAlpha.js +15 -0
- package/esm/core/theme.js +26 -0
- package/esm/dates/DateInputValidationError.js +7 -0
- package/esm/dates/IntlDateFormat.js +66 -0
- package/esm/dates/generateCalendarMonth.js +22 -0
- package/esm/dates/getISOStringLocal.js +8 -0
- package/esm/dates/getMidnightDate.js +4 -0
- package/esm/dates/getTimesFromDatesAndRanges.js +16 -0
- package/esm/dates/useDateInput.js +105 -0
- package/esm/dates/useDateInputValidation.js +50 -0
- package/esm/hooks/useEventHandler.js +54 -0
- package/esm/hooks/useFallbackShape.js +29 -0
- package/esm/hooks/useGroupToggler.js +105 -0
- package/esm/hooks/useHasMounted.js +6 -0
- package/esm/hooks/useIndexCounter.js +47 -0
- package/esm/hooks/useInputVariant.js +4 -0
- package/esm/hooks/useLogo.js +60 -0
- package/esm/hooks/useMergeRefs.js +14 -0
- package/esm/hooks/usePrefixedId.js +25 -0
- package/esm/hooks/usePreviousValue.js +16 -0
- package/esm/hooks/usePreviousValues.js +26 -0
- package/esm/hooks/useRefMap.js +17 -0
- package/esm/hooks/useSort.js +26 -0
- package/esm/hooks/useSubBrandLogo.js +244 -0
- package/esm/hooks/useTimer.js +51 -0
- package/esm/hooks/useToggler.js +24 -0
- package/esm/hooks/useValueChanges.js +15 -0
- package/esm/index.js +7 -0
- package/esm/internal/data/accounts.js +1838 -0
- package/esm/internal/data/announcementCards.js +23 -0
- package/esm/internal/data/asset.js +6345 -0
- package/esm/internal/data/assets.js +82 -0
- package/esm/internal/data/avatars.js +2 -0
- package/esm/internal/data/dataCards.js +22 -0
- package/esm/internal/data/featureEntryCards.js +28 -0
- package/esm/internal/data/feedImages.js +1 -0
- package/esm/internal/data/iconData.js +1 -0
- package/esm/internal/data/loremIpsum.js +1 -0
- package/esm/internal/data/navigation.js +11 -0
- package/esm/internal/data/prices.js +7 -0
- package/esm/internal/data/product.js +24 -0
- package/esm/internal/data/tabs.js +58 -0
- package/esm/internal/data/users.js +9 -0
- package/esm/internal/utils/storyBuilder.js +102 -0
- package/esm/internal/visualizations/SparklineInteractiveData.js +67 -0
- package/esm/jest/timeTravel.js +42 -0
- package/esm/lottie/lottieUtils.js +20 -0
- package/esm/lottie/lottieUtils.test.js +44 -0
- package/esm/lottie/useStatusAnimationPoller.js +67 -0
- package/esm/media/getAvatarFallbackColor.js +50 -0
- package/esm/media/remoteImageFallbackSrc.js +11 -0
- package/esm/motion/animatedCaret.js +6 -0
- package/esm/motion/checkbox.js +9 -0
- package/esm/motion/dot.js +9 -0
- package/esm/motion/hint.js +19 -0
- package/esm/motion/switch.js +8 -0
- package/esm/motion/tokens.js +71 -0
- package/esm/motion/utils.js +17 -0
- package/esm/numbers/IntlNumberFormat.js +204 -0
- package/esm/numbers/subscript.js +53 -0
- package/esm/overlays/ModalContext.js +8 -0
- package/esm/overlays/OverlayContentContext.js +24 -0
- package/esm/overlays/PortalContext.js +6 -0
- package/esm/overlays/ToastProvider.js +51 -0
- package/esm/overlays/useAlert.js +8 -0
- package/esm/overlays/useModal.js +16 -0
- package/esm/overlays/useOverlay.js +28 -0
- package/esm/overlays/usePortal.js +10 -0
- package/esm/overlays/usePortalState.js +55 -0
- package/esm/overlays/useToastQueue.js +67 -0
- package/esm/stepper/useStepper.js +124 -0
- package/esm/stepper/utils.js +45 -0
- package/esm/system/EventHandlerProvider.js +24 -0
- package/esm/system/LocaleProvider.js +19 -0
- package/esm/system/RefMapContext.js +7 -0
- package/esm/tabs/TabsContext.js +7 -0
- package/esm/tabs/useTabs.js +43 -0
- package/esm/tokens/accordion.js +6 -0
- package/esm/tokens/appSwitcher.js +3 -0
- package/esm/tokens/avatar.js +13 -0
- package/esm/tokens/banner.js +39 -0
- package/esm/tokens/borderRadius.js +7 -0
- package/esm/tokens/button.js +64 -0
- package/esm/tokens/card.js +29 -0
- package/esm/tokens/cell.js +40 -0
- package/esm/tokens/chip.js +1 -0
- package/esm/tokens/dot.js +31 -0
- package/esm/tokens/drawer.js +11 -0
- package/esm/tokens/illustrations.js +28 -0
- package/esm/tokens/input.js +5 -0
- package/esm/tokens/interactable.js +4 -0
- package/esm/tokens/interactableHeight.js +4 -0
- package/esm/tokens/menu.js +2 -0
- package/esm/tokens/multiContentModule.js +1 -0
- package/esm/tokens/navigation.js +1 -0
- package/esm/tokens/overlays.js +1 -0
- package/esm/tokens/page.js +2 -0
- package/esm/tokens/select.js +26 -0
- package/esm/tokens/sidebar.js +2 -0
- package/esm/tokens/sizing.js +2 -0
- package/esm/tokens/sparkline.js +24 -0
- package/esm/tokens/tags.js +66 -0
- package/esm/tokens/tile.js +9 -0
- package/esm/tokens/toast.js +4 -0
- package/esm/tokens/tooltip.js +5 -0
- package/esm/tokens/zIndex.js +15 -0
- package/esm/tour/TourContext.js +7 -0
- package/esm/tour/useTour.js +84 -0
- package/esm/types/AvatarBaseProps.js +1 -0
- package/esm/types/AvatarSize.js +1 -0
- package/esm/types/BannerBaseProps.js +1 -0
- package/esm/types/BoxBaseProps.js +1 -0
- package/esm/types/ButtonBaseProps.js +1 -0
- package/esm/types/CardHeaderProps.js +1 -0
- package/esm/types/CardMediaProps.js +1 -0
- package/esm/types/CardRemoteImageProps.js +1 -0
- package/esm/types/CdsPlatform.js +1 -0
- package/esm/types/CellBaseProps.js +1 -0
- package/esm/types/Chart.js +1 -0
- package/esm/types/CollapsibleBaseProps.js +1 -0
- package/esm/types/Color.js +1 -0
- package/esm/types/ComponentEventHandlerProps.js +1 -0
- package/esm/types/DimensionStyles.js +1 -0
- package/esm/types/Display.js +1 -0
- package/esm/types/DotBaseProps.js +1 -0
- package/esm/types/DotCountBaseProps.js +1 -0
- package/esm/types/ElevationLevels.js +1 -0
- package/esm/types/FallbackBaseProps.js +1 -0
- package/esm/types/Grid.js +1 -0
- package/esm/types/Helpers.js +1 -0
- package/esm/types/IconButtonBaseProps.js +1 -0
- package/esm/types/IconName.js +1 -0
- package/esm/types/IconSize.js +1 -0
- package/esm/types/IllustrationNames.js +1 -0
- package/esm/types/IllustrationProps.js +1 -0
- package/esm/types/InputBaseProps.js +1 -0
- package/esm/types/LottiePlayer.js +1 -0
- package/esm/types/LottieSource.js +1 -0
- package/esm/types/LottieStatusAnimationProps.js +1 -0
- package/esm/types/Motion.js +1 -0
- package/esm/types/OverlayLifecycleProps.js +1 -0
- package/esm/types/Palette.js +1 -0
- package/esm/types/Placement.js +1 -0
- package/esm/types/Position.js +1 -0
- package/esm/types/ProgressContainerWithButtonsProps.js +1 -0
- package/esm/types/PulseBaseProps.js +1 -0
- package/esm/types/React.js +1 -0
- package/esm/types/Rect.js +6 -0
- package/esm/types/Responsive.js +1 -0
- package/esm/types/ResponsiveProps.js +1 -0
- package/esm/types/SectionHeaderProps.js +1 -0
- package/esm/types/Shape.js +1 -0
- package/esm/types/SharedAccessibilityProps.js +1 -0
- package/esm/types/SharedProps.js +1 -0
- package/esm/types/SpacingProps.js +1 -0
- package/esm/types/SparklineInteractiveHeaderBaseProps.js +1 -0
- package/esm/types/SpreadPropsSafely.js +1 -0
- package/esm/types/StickyFooterProps.js +1 -0
- package/esm/types/TagBaseProps.js +1 -0
- package/esm/types/TextBaseProps.js +1 -0
- package/esm/types/TooltipBaseProps.js +1 -0
- package/esm/types/TypeOrNumber.js +1 -0
- package/esm/types/Visibility.js +1 -0
- package/esm/types/Weight.js +1 -0
- package/esm/types/index.js +58 -0
- package/esm/utils/cell.js +5 -0
- package/esm/utils/chart.js +14 -0
- package/esm/utils/circle.js +12 -0
- package/esm/utils/convertDimensionToAspectRatio.js +5 -0
- package/esm/utils/convertDimensionToSize.js +9 -0
- package/esm/utils/convertSizeWithMultiplier.js +7 -0
- package/esm/utils/debounce.js +16 -0
- package/esm/utils/delay.js +6 -0
- package/esm/utils/flattenNodes.js +33 -0
- package/esm/utils/formatCount.js +43 -0
- package/esm/utils/getAccessibleColor.js +50 -0
- package/esm/utils/getButtonSpacingProps.js +24 -0
- package/esm/utils/getDefaultAspectRatioForIllustration.js +6 -0
- package/esm/utils/getDefaultSizeObjectForIllustration.js +7 -0
- package/esm/utils/getRectWidthVariant.js +1 -0
- package/esm/utils/getWidthInEm.js +13 -0
- package/esm/utils/join.js +11 -0
- package/esm/utils/mergeProps.js +25 -0
- package/esm/utils/mockUtils.js +1 -0
- package/esm/utils/modulate.js +32 -0
- package/esm/utils/parseDotCountMaxOverflow.js +7 -0
- package/esm/visualizations/getProgressCircleParams.js +18 -0
- package/esm/visualizations/getSparklineRange.js +13 -0
- package/esm/visualizations/getSparklineTransform.js +19 -0
- package/esm/visualizations/largestTriangleThreeBucket.js +57 -0
- package/esm/visualizations/useCounter.js +52 -0
- package/esm/visualizations/useDateLookup.js +18 -0
- package/esm/visualizations/useProgressSize.js +15 -0
- package/esm/visualizations/useSparklineArea.js +30 -0
- package/esm/visualizations/useSparklineAreaOpacity.js +3 -0
- package/esm/visualizations/useSparklineCoordinates.js +73 -0
- package/esm/visualizations/useSparklinePath.js +22 -0
- package/esm/visualizations/useSparklinePathGenerator.js +38 -0
- package/esm/visualizations/useTimeseriesPaths.js +41 -0
- package/esm/visualizations/useVisualizationDimensions.js +27 -0
- package/package.json +62 -6
- package/index.js +0 -1
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { color } from 'd3-color';
|
|
2
|
+
import { blendColors } from './blendColors';
|
|
3
|
+
import { getLuminance } from './getLuminance';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for the color scheme.
|
|
7
|
+
*
|
|
8
|
+
* For each color scheme, it has an underlay color and a high contrast luminance threshold.
|
|
9
|
+
* The underlay color is the color that is used to blend with the overlay color.
|
|
10
|
+
* The high contrast luminance threshold is the luminance value, above (in dark color scheme)
|
|
11
|
+
* or below (in light color scheme) which the overlay color is considered in high contrast to the underlay color.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const defaultColorBlendConfigByColorScheme = {
|
|
15
|
+
light: {
|
|
16
|
+
underlayColor: '#fff',
|
|
17
|
+
highContrastLuminanceThreshold: 0.11
|
|
18
|
+
},
|
|
19
|
+
dark: {
|
|
20
|
+
underlayColor: '#000',
|
|
21
|
+
highContrastLuminanceThreshold: 0.4
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The type of easing function to use for opacity adjustment.
|
|
27
|
+
* - `linear`: A straight linear progression.
|
|
28
|
+
* - `ease-out`: An "ease-out" curve, where the adjustment starts fast and slows down as the luminance delta gets larger. This is the default.
|
|
29
|
+
* - `ease-in`: An "ease-in" curve, where the adjustment starts slow and speeds up as the luminance delta.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Configuration for fine-tuning the automatic blend opacity adjustment.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
const defaultBlendOpacityAdjustmentConfig = {
|
|
37
|
+
noAdjustmentLuminanceDelta: 0.2,
|
|
38
|
+
adjustmentStrengthRatio: 0.75,
|
|
39
|
+
adjustmentEasingFunction: 'ease-out'
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Adjusts the blend opacity based on the luminance difference between the overlay and underlay colors.
|
|
44
|
+
* When the luminance difference is large (e.g., a light overlay color on a dark underlay color), the blending
|
|
45
|
+
* effect is toned down (opacity of the overlay color is increased). This makes the resulting color variation more subtle
|
|
46
|
+
* and preserves the overlay color's character.
|
|
47
|
+
*
|
|
48
|
+
* Conversely, when the luminance difference is small (less than the `noAdjustmentLuminanceDelta`), the original blend opacity is used to allow
|
|
49
|
+
* for a more pronounced blending effect. This ensures that colors with similar brightness to the
|
|
50
|
+
* background still produce a noticeable visual change.
|
|
51
|
+
*/
|
|
52
|
+
const getAdjustedBlendOpacity = _ref => {
|
|
53
|
+
let {
|
|
54
|
+
overlayColorLuminance,
|
|
55
|
+
underlayColorLuminance,
|
|
56
|
+
blendOpacity,
|
|
57
|
+
blendOpacityAdjustmentConfig: {
|
|
58
|
+
noAdjustmentLuminanceDelta,
|
|
59
|
+
adjustmentStrengthRatio,
|
|
60
|
+
adjustmentEasingFunction
|
|
61
|
+
} = defaultBlendOpacityAdjustmentConfig
|
|
62
|
+
} = _ref;
|
|
63
|
+
// Calculate absolute difference in luminance (0 to 1)
|
|
64
|
+
const luminanceDelta = Math.abs(overlayColorLuminance - underlayColorLuminance);
|
|
65
|
+
|
|
66
|
+
// If luminance difference is below threshold, return original blend opacity unchanged
|
|
67
|
+
if (luminanceDelta < noAdjustmentLuminanceDelta) {
|
|
68
|
+
return blendOpacity;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Normalize the luminance difference to a 0-to-1 scale. This ensures the adjustment
|
|
72
|
+
// starts from 0 and increases smoothly and predictably as the luminance difference
|
|
73
|
+
// surpasses the threshold.
|
|
74
|
+
// Example: if noAdjustmentLuminanceDelta is 0.2 and luminanceDelta is 0.6,
|
|
75
|
+
// the raw difference is 0.4. The total possible adjustment range is 0.8 (from 0.2 to 1.0).
|
|
76
|
+
// The normalizedDiff is 0.4 / 0.8 = 0.5, meaning we are 50% of the way through the adjustable range.
|
|
77
|
+
// This provides a consistent 0-1 scale for the easing curve.
|
|
78
|
+
const normalizedDiff = (luminanceDelta - noAdjustmentLuminanceDelta) / (1 - noAdjustmentLuminanceDelta);
|
|
79
|
+
|
|
80
|
+
// Apply the selected easing to the normalized difference for gentler scaling
|
|
81
|
+
let scaleFactor;
|
|
82
|
+
switch (adjustmentEasingFunction) {
|
|
83
|
+
case 'linear':
|
|
84
|
+
scaleFactor = normalizedDiff;
|
|
85
|
+
break;
|
|
86
|
+
case 'ease-in':
|
|
87
|
+
scaleFactor = Math.pow(normalizedDiff, 2);
|
|
88
|
+
break;
|
|
89
|
+
case 'ease-out':
|
|
90
|
+
default:
|
|
91
|
+
scaleFactor = Math.pow(normalizedDiff, 0.5);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
const scale = scaleFactor * adjustmentStrengthRatio;
|
|
95
|
+
|
|
96
|
+
// Calculate how much we can increase the blendOpacity (cannot exceed 1.0)
|
|
97
|
+
const maxIncrease = 1 - blendOpacity;
|
|
98
|
+
const blendStrengthIncrease = maxIncrease * scale;
|
|
99
|
+
|
|
100
|
+
// Return adjusted blend opacity, increased based on luminance difference
|
|
101
|
+
return blendOpacity + blendStrengthIncrease;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Configuration for the `getBlendedColor` function.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Creates subtle color variations by blending overlay color with underlay color based on the input color's luminance
|
|
110
|
+
* and current theme. Automatically optimizes for contrast unless disabled.
|
|
111
|
+
*
|
|
112
|
+
* @param config - The configuration for the function.
|
|
113
|
+
* @returns CSS color string with the blended result.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* // Light theme
|
|
118
|
+
* const lightVariation = getBlendedColor({
|
|
119
|
+
* overlayColor: '#0052ff',
|
|
120
|
+
* blendOpacity: 0.88,
|
|
121
|
+
* colorScheme: 'light'
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* // Dark theme
|
|
125
|
+
* const darkVariation = getBlendedColor({
|
|
126
|
+
* overlayColor: '#0052ff',
|
|
127
|
+
* blendOpacity: 0.82,
|
|
128
|
+
* colorScheme: 'dark'
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* // Skip contrast optimization
|
|
132
|
+
* const simpleVariation = getBlendedColor({
|
|
133
|
+
* overlayColor: '#0052ff',.
|
|
134
|
+
* blendOpacity: 0.75,
|
|
135
|
+
* colorScheme: 'light',
|
|
136
|
+
* skipContrastOptimization: true
|
|
137
|
+
* });
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export const getBlendedColor = _ref2 => {
|
|
141
|
+
var _getLuminance, _getLuminance2;
|
|
142
|
+
let {
|
|
143
|
+
overlayColor,
|
|
144
|
+
blendOpacity,
|
|
145
|
+
blendOpacityAdjustmentConfig,
|
|
146
|
+
colorScheme,
|
|
147
|
+
configByColorScheme = defaultColorBlendConfigByColorScheme,
|
|
148
|
+
skipContrastOptimization = false
|
|
149
|
+
} = _ref2;
|
|
150
|
+
// Special cases: these color values cannot be analyzed or blended, return as-is
|
|
151
|
+
if (overlayColor === 'currentColor' || overlayColor === 'transparent') {
|
|
152
|
+
return overlayColor;
|
|
153
|
+
}
|
|
154
|
+
const overlayColorRgba = color(overlayColor);
|
|
155
|
+
if (overlayColorRgba === null) {
|
|
156
|
+
return overlayColor;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Preserve original opacity for semi-transparent overlay colors (e.g., bgLine, bgLineHeavy),
|
|
160
|
+
// which will be re-applied post-blending.
|
|
161
|
+
const overlayColorOpacity = overlayColorRgba.opacity;
|
|
162
|
+
// Handle fully transparent colors (alpha = 0)
|
|
163
|
+
if (overlayColorOpacity === 0) {
|
|
164
|
+
return 'transparent';
|
|
165
|
+
}
|
|
166
|
+
const overlayColorLuminance = (_getLuminance = getLuminance(overlayColor)) !== null && _getLuminance !== void 0 ? _getLuminance : 1;
|
|
167
|
+
const oppositeColorScheme = colorScheme === 'dark' ? 'light' : 'dark';
|
|
168
|
+
|
|
169
|
+
// Determine if overlay color has high contrast with the theme background
|
|
170
|
+
// High contrast overlays use current scheme underlay, low contrast overlays use opposite scheme underlay
|
|
171
|
+
const isHighContrast = colorScheme === 'dark' ? overlayColorLuminance >= configByColorScheme.dark.highContrastLuminanceThreshold // Light overlays on dark background = high contrast
|
|
172
|
+
: overlayColorLuminance <= configByColorScheme.light.highContrastLuminanceThreshold; // Dark overlays on light background = high contrast
|
|
173
|
+
|
|
174
|
+
const shouldUseCurrentColorScheme = skipContrastOptimization || isHighContrast;
|
|
175
|
+
// Choose underlay color from the current scheme when skipping optimization or high-contrast,
|
|
176
|
+
// otherwise use the one from the opposite scheme.
|
|
177
|
+
const underlayColor = shouldUseCurrentColorScheme ? configByColorScheme[colorScheme].underlayColor : configByColorScheme[oppositeColorScheme].underlayColor;
|
|
178
|
+
const underlayColorLuminance = (_getLuminance2 = getLuminance(underlayColor)) !== null && _getLuminance2 !== void 0 ? _getLuminance2 : 1;
|
|
179
|
+
|
|
180
|
+
// Automatically adjust blend opacity based on luminance difference for optimal visual contrast
|
|
181
|
+
const adjustedBlendOpacity = getAdjustedBlendOpacity({
|
|
182
|
+
overlayColorLuminance,
|
|
183
|
+
underlayColorLuminance,
|
|
184
|
+
blendOpacity,
|
|
185
|
+
blendOpacityAdjustmentConfig
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Create adjusted overlay color with the calculated blend strength
|
|
189
|
+
const overlayColorWithAdjustedBlendOpacity = overlayColorRgba.copy({
|
|
190
|
+
opacity: adjustedBlendOpacity
|
|
191
|
+
});
|
|
192
|
+
const blendedRgb = blendColors({
|
|
193
|
+
underlayColor,
|
|
194
|
+
overlayColor: overlayColorWithAdjustedBlendOpacity
|
|
195
|
+
});
|
|
196
|
+
if (overlayColorOpacity < 1) {
|
|
197
|
+
return blendedRgb.copy({
|
|
198
|
+
opacity: overlayColorOpacity
|
|
199
|
+
}).formatRgb();
|
|
200
|
+
}
|
|
201
|
+
return blendedRgb.formatRgb();
|
|
202
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getLuminance } from './getLuminance';
|
|
2
|
+
/**
|
|
3
|
+
* The Web Content Accessibility Guidelines (WCAG) include convenient quantitative recommendations for making text and graphics accessible based on the minimum acceptable contrast of foreground against background.
|
|
4
|
+
* For example, black on yellow has a high contrast ratio (19.56) and therefore should be easier to read, whereas blue on blue is low contrast (2.31) and harder to read.
|
|
5
|
+
*/
|
|
6
|
+
export const getContrastRatio = (background, foreground) => {
|
|
7
|
+
const backgroundLuminance = getLuminance(background);
|
|
8
|
+
const foregroundLuminance = getLuminance(foreground);
|
|
9
|
+
if (backgroundLuminance === undefined || foregroundLuminance === undefined) return 1;
|
|
10
|
+
return (Math.max(backgroundLuminance, foregroundLuminance) + 0.05) / (Math.min(backgroundLuminance, foregroundLuminance) + 0.05);
|
|
11
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { color } from 'd3-color';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Relative luminance is the relative brightness of any point in an RGB colorspace, normalized to 0 for darkest black and 1 for lightest white.
|
|
5
|
+
*
|
|
6
|
+
* Edge cases:
|
|
7
|
+
* - Returns undefined for invalid color values or non-parseable color strings
|
|
8
|
+
* - HSL colors outside the RGB gamut will have their RGB components clamped to [0,255], which may not preserve the original color relationships
|
|
9
|
+
* - Special color keywords like 'currentColor' or 'transparent' will return undefined
|
|
10
|
+
* - CSS Variables or dynamic values cannot be calculated
|
|
11
|
+
*
|
|
12
|
+
* @see https://contrastchecker.online/color-relative-luminance-calculator
|
|
13
|
+
*/
|
|
14
|
+
export const getLuminance = value => {
|
|
15
|
+
var _color;
|
|
16
|
+
const rgbObject = (_color = color(value)) === null || _color === void 0 ? void 0 : _color.rgb();
|
|
17
|
+
if (!rgbObject) return undefined;
|
|
18
|
+
const {
|
|
19
|
+
r,
|
|
20
|
+
g,
|
|
21
|
+
b
|
|
22
|
+
} = rgbObject;
|
|
23
|
+
const red = Number.isNaN(r) ? 0 : r;
|
|
24
|
+
const green = Number.isNaN(g) ? 0 : g;
|
|
25
|
+
const blue = Number.isNaN(b) ? 0 : b;
|
|
26
|
+
const [redLinear, greenLinear, blueLinear] = [red / 255, green / 255, blue / 255].map(item => item <= 0.04045 ? item / 12.92 : ((item + 0.055) / 1.055) ** 2.4);
|
|
27
|
+
return 0.2126 * redLinear + 0.7152 * greenLinear + 0.0722 * blueLinear;
|
|
28
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getContrastRatio } from './getContrastRatio';
|
|
2
|
+
const contrastRatioMap = {
|
|
3
|
+
minimum: {
|
|
4
|
+
normalText: 4.5,
|
|
5
|
+
largeText: 3,
|
|
6
|
+
graphic: 3
|
|
7
|
+
},
|
|
8
|
+
enhanced: {
|
|
9
|
+
normalText: 7,
|
|
10
|
+
largeText: 4.5,
|
|
11
|
+
graphic: 3
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* isAccessibleColor will default to using "minimum" contrast ratios
|
|
16
|
+
* Contrast ratios can range from 1 to 21 (commonly written 1:1 to 21:1).
|
|
17
|
+
* 7 - "enhanced" contrast for regular sized text under WCAG 2.0 1.4.6 (Level AAA)
|
|
18
|
+
* 4.5 - minimum contrast for regular sized text under WCAG 2.0 1.4.3 (Level AA)
|
|
19
|
+
* 3 - minimum contrast for "large scale" text (18 pt or 14 pt bold, or larger) under WCAG 2.0 1.4.3 (Level AA)
|
|
20
|
+
* https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html
|
|
21
|
+
*/
|
|
22
|
+
export const isAccessibleColor = _ref => {
|
|
23
|
+
let {
|
|
24
|
+
background,
|
|
25
|
+
foreground,
|
|
26
|
+
usage,
|
|
27
|
+
enhanced
|
|
28
|
+
} = _ref;
|
|
29
|
+
const ratio = getContrastRatio(background, foreground);
|
|
30
|
+
return ratio >= contrastRatioMap[enhanced ? 'enhanced' : 'minimum'][usage];
|
|
31
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { color } from 'd3-color';
|
|
2
|
+
export const isLightOrDarkColor = value => {
|
|
3
|
+
var _color;
|
|
4
|
+
const rgbObject = (_color = color(value)) === null || _color === void 0 ? void 0 : _color.rgb();
|
|
5
|
+
if (rgbObject) {
|
|
6
|
+
const {
|
|
7
|
+
r: red,
|
|
8
|
+
g: green,
|
|
9
|
+
b: blue
|
|
10
|
+
} = rgbObject;
|
|
11
|
+
// HSP (Highly Sensitive Poo) equation from http://alienryderflex.com/hsp.html
|
|
12
|
+
const hsp = Math.sqrt(0.299 * (red * red) + 0.587 * (green * green) + 0.114 * (blue * blue));
|
|
13
|
+
// Using the HSP value, determine whether the color is light or dark
|
|
14
|
+
if (hsp > 127.5) {
|
|
15
|
+
return 'light';
|
|
16
|
+
}
|
|
17
|
+
return 'dark';
|
|
18
|
+
}
|
|
19
|
+
// Fallback to light luminosity
|
|
20
|
+
return 'light';
|
|
21
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { color } from 'd3-color';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Modify the alpha value of an rgba string
|
|
5
|
+
* @param color - valid color value, i.e. `#ffffff` or`rgba(255, 255, 255, 1)`
|
|
6
|
+
* @param newOpacity - 0.5
|
|
7
|
+
* @returns rgbaString - `rgba(255, 255, 255, 0.5)`
|
|
8
|
+
*/
|
|
9
|
+
export const overrideAlpha = (value, opacity) => {
|
|
10
|
+
var _d3Color$copy$formatR;
|
|
11
|
+
const d3Color = color(value);
|
|
12
|
+
return (_d3Color$copy$formatR = d3Color === null || d3Color === void 0 ? void 0 : d3Color.copy({
|
|
13
|
+
opacity
|
|
14
|
+
}).formatRgb()) !== null && _d3Color$copy$formatR !== void 0 ? _d3Color$copy$formatR : value;
|
|
15
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* These are the core CDS Theme variable types used across mobile and web.
|
|
3
|
+
*/
|
|
4
|
+
/* eslint-disable no-restricted-syntax, @typescript-eslint/no-empty-object-type */
|
|
5
|
+
/**
|
|
6
|
+
* This utility type makes the final intellisense into human-redable literal values.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* This is the default set of Theme variables available to all CDS components.
|
|
10
|
+
* Only the interface keys are used to define the available Theme variables.
|
|
11
|
+
* The interface values are not used.
|
|
12
|
+
* @danger You probably don't want to use this namespace directly, unless you are
|
|
13
|
+
* referring explicitly to ONLY the default CDS variables. Otherwise, you probably
|
|
14
|
+
* want to use the ThemeVars namespace instead, which inherits from this namespace.
|
|
15
|
+
* @docs http://cds.coinbase.com/getting-started/theming/#themevars-namespace
|
|
16
|
+
*/
|
|
17
|
+
export let ThemeVarsDefault;
|
|
18
|
+
/**
|
|
19
|
+
* This is the complete set of Theme variables available to all CDS components.
|
|
20
|
+
* Combines all variables from the ThemeVarsDefault and ThemeVarsExtended
|
|
21
|
+
* namespaces. You can use this namespace to read all available Theme variables.
|
|
22
|
+
* You can use the ThemeVarsExtended namespace to extend this namespace with new
|
|
23
|
+
* variables.
|
|
24
|
+
* @docs http://cds.coinbase.com/getting-started/theming/#themevars-namespace
|
|
25
|
+
*/
|
|
26
|
+
export let ThemeVars;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
|
+
/**
|
|
5
|
+
* IntlDateFormat is a utility class that uses the Intl.DateTimeFormat API to determine the date format for a given locale.
|
|
6
|
+
* It can be used to parse and format date strings based on the locale's date format.
|
|
7
|
+
* @param locale A valid JavaScript Intl locale used to determine the date format.
|
|
8
|
+
* @param separator Character used to separate values in the date format, e.g. the forward slash in "MM/DD/YYYY".
|
|
9
|
+
* @example
|
|
10
|
+
* const intlDateFormat = new IntlDateFormat({ locale: 'en-US', separator: '/' });
|
|
11
|
+
* const date = intlDateFormat.date('12/31/2020');
|
|
12
|
+
* const dateString = intlDateFormat.format(new Date());
|
|
13
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
|
|
14
|
+
*/
|
|
15
|
+
export class IntlDateFormat {
|
|
16
|
+
constructor(props) {
|
|
17
|
+
this.locale = props.locale;
|
|
18
|
+
this.separator = props.separator;
|
|
19
|
+
this.invalidDateFormatRegex = new RegExp("[^0-9".concat(this.separator, "]"));
|
|
20
|
+
this.duplicateSeparatorRegex = new RegExp("".concat(this.separator, "{2,}"), 'g');
|
|
21
|
+
this.dateTimeFormat = new Intl.DateTimeFormat(props.locale);
|
|
22
|
+
this.dateTimeFormatParts = this.dateTimeFormat.formatToParts(new Date());
|
|
23
|
+
this.dateStringFormat = this.dateTimeFormatParts.map(part => IntlDateFormat.datePartTypeMap[part.type]).filter(Boolean).join(this.separator);
|
|
24
|
+
this.separatorIndices = this.dateStringFormat.split('').map((char, index) => char === this.separator ? index : undefined).filter(Boolean);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Converts a valid date string to a Date object based on the locale's date format.
|
|
29
|
+
*/
|
|
30
|
+
date(dateString) {
|
|
31
|
+
const dateValues = dateString.split(this.separator);
|
|
32
|
+
const {
|
|
33
|
+
year,
|
|
34
|
+
month,
|
|
35
|
+
day
|
|
36
|
+
} = this.dateTimeFormatParts.filter(part => part.type !== 'literal').reduce((acc, part, index) => {
|
|
37
|
+
acc[part.type] = parseInt(dateValues[index], 10);
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
const date = new Date(year, month - 1, day);
|
|
41
|
+
|
|
42
|
+
// Ignore technically valid date inputs like `30/30/2015` that would cause the month or year to roll over
|
|
43
|
+
if (date.getMonth() !== month - 1 || date.getFullYear() !== year) return null;
|
|
44
|
+
return date;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Converts a Date object to a date string based on the locale's date format.
|
|
49
|
+
*/
|
|
50
|
+
format(date) {
|
|
51
|
+
return this.dateTimeFormat.formatToParts(date).map(part => part.type === 'literal' ? this.separator : part.type === 'year' ? date.getFullYear() : part.value.padStart(2, '0')).join('');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** A valid JavaScript Intl locale used to determine the date format. */
|
|
55
|
+
/** Character used to separate values in the date format, e.g. the forward slash in "MM/DD/YYYY". */
|
|
56
|
+
/** The indices of the separator characters in the date format. */
|
|
57
|
+
/** Matches any character except digits and the separator character. */
|
|
58
|
+
/** Matches two or more consecutive separator characters. */
|
|
59
|
+
/** Intl.DateTimeFormat class for the locale. */
|
|
60
|
+
/** Array of Intl.DateTimeFormatParts - including day, month, year, and separators. */
|
|
61
|
+
/** The date format, based on the locale and including separator characters, e.g. "MM/DD/YYYY". */
|
|
62
|
+
_defineProperty(IntlDateFormat, "datePartTypeMap", {
|
|
63
|
+
day: 'dd',
|
|
64
|
+
month: 'mm',
|
|
65
|
+
year: 'yyyy'
|
|
66
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates an array of Dates for a calendar month. Not localized with Intl. Assumes a Gregorian calendar with "en-US" DateTimeFormat. Treats Sunday as the first day of the week.
|
|
3
|
+
*/
|
|
4
|
+
export const generateCalendarMonth = seedDate => {
|
|
5
|
+
const firstOfMonth = new Date(seedDate.getFullYear(), seedDate.getMonth(), 1);
|
|
6
|
+
const firstOfCalendar = new Date(firstOfMonth.getFullYear(), firstOfMonth.getMonth(), 1 - firstOfMonth.getDay());
|
|
7
|
+
const daysInMonth = new Date(firstOfMonth.getFullYear(), firstOfMonth.getMonth() + 1, 0).getDate();
|
|
8
|
+
const daysFromNextMonth = 7 - (daysInMonth + firstOfMonth.getDay()) % 7;
|
|
9
|
+
const month = [];
|
|
10
|
+
for (let i = 0; i < firstOfMonth.getDay(); i++) {
|
|
11
|
+
month.push(new Date(firstOfCalendar.getFullYear(), firstOfCalendar.getMonth(), firstOfCalendar.getDate() + i));
|
|
12
|
+
}
|
|
13
|
+
for (let i = 1; i <= daysInMonth; i++) {
|
|
14
|
+
month.push(new Date(firstOfMonth.getFullYear(), firstOfMonth.getMonth(), i));
|
|
15
|
+
}
|
|
16
|
+
if (daysFromNextMonth !== 7) {
|
|
17
|
+
for (let i = 1; i <= daysFromNextMonth; i++) {
|
|
18
|
+
month.push(new Date(firstOfMonth.getFullYear(), firstOfMonth.getMonth() + 1, i));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return month;
|
|
22
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a Date to an ISO 8601 string (YYYY-MM-DD) in the local timezone (not UTC)
|
|
3
|
+
*/
|
|
4
|
+
export const getISOStringLocal = date => {
|
|
5
|
+
const day = date.getDate().toString().padStart(2, '0');
|
|
6
|
+
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
7
|
+
return "".concat(date.getFullYear(), "-").concat(month, "-").concat(day);
|
|
8
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getMidnightDate } from './getMidnightDate';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Takes an array of Dates and Date tuples for date ranges, and generates a flattened array of corresponding Date.getTime() numbers, with the time set to midnight. A number will be generated for every individual date within a date range.
|
|
5
|
+
*/
|
|
6
|
+
export const getTimesFromDatesAndRanges = datesAndRanges => datesAndRanges.flatMap(value => {
|
|
7
|
+
if (value instanceof Date) return getMidnightDate(value).getTime();
|
|
8
|
+
const [startDate, endDate] = value;
|
|
9
|
+
const startDisabledDate = getMidnightDate(startDate);
|
|
10
|
+
const endDisabledDate = getMidnightDate(endDate);
|
|
11
|
+
const times = [];
|
|
12
|
+
for (let date = startDisabledDate; date <= endDisabledDate; date.setDate(date.getDate() + 1)) {
|
|
13
|
+
times.push(date.getTime());
|
|
14
|
+
}
|
|
15
|
+
return times;
|
|
16
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { useDateInputValidation } from './useDateInputValidation';
|
|
3
|
+
/** Accepts DateInputOptions and returns a DateInputApi, which can be used to control a custom DateInput component. */
|
|
4
|
+
export const useDateInput = _ref => {
|
|
5
|
+
let {
|
|
6
|
+
date,
|
|
7
|
+
onChangeDate,
|
|
8
|
+
error,
|
|
9
|
+
onErrorDate,
|
|
10
|
+
intlDateFormat,
|
|
11
|
+
required,
|
|
12
|
+
disabledDates,
|
|
13
|
+
minDate,
|
|
14
|
+
maxDate,
|
|
15
|
+
requiredError,
|
|
16
|
+
invalidDateError,
|
|
17
|
+
disabledDateError
|
|
18
|
+
} = _ref;
|
|
19
|
+
const [previousDateProp, setPreviousDateProp] = useState(date);
|
|
20
|
+
const [inputValue, setInputValue] = useState(date ? intlDateFormat.format(date) : '');
|
|
21
|
+
const hadCompleteDateString = useRef(Boolean(date));
|
|
22
|
+
|
|
23
|
+
// Sync internal inputValue state with external date prop state
|
|
24
|
+
if (previousDateProp !== date) {
|
|
25
|
+
hadCompleteDateString.current = Boolean(date);
|
|
26
|
+
setPreviousDateProp(date);
|
|
27
|
+
// Only resync the inputValue state if the new date prop is non-null.
|
|
28
|
+
// This allows the user to backspace a completed date input, without
|
|
29
|
+
// the inputValue being overridden by the date prop changing to null.
|
|
30
|
+
if (date) setInputValue(intlDateFormat.format(date));
|
|
31
|
+
}
|
|
32
|
+
const placeholder = " ".concat(intlDateFormat.separator, " ").concat(intlDateFormat.separator);
|
|
33
|
+
const {
|
|
34
|
+
validateDateInput,
|
|
35
|
+
disabledTimes,
|
|
36
|
+
minTime,
|
|
37
|
+
maxTime
|
|
38
|
+
} = useDateInputValidation({
|
|
39
|
+
intlDateFormat,
|
|
40
|
+
required,
|
|
41
|
+
disabledDates,
|
|
42
|
+
minDate,
|
|
43
|
+
maxDate,
|
|
44
|
+
requiredError,
|
|
45
|
+
invalidDateError,
|
|
46
|
+
disabledDateError
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Be careful to preserve the correct event orders
|
|
51
|
+
* 1. Typing a date in a blank DateInput: onChange -> onChange -> ... -> onChangeDate -> onErrorDate
|
|
52
|
+
* 2. Typing a date in a DateInput that already had a date: onChange -> onChangeDate -> onChange -> onChange -> ... -> onChangeDate -> onErrorDate
|
|
53
|
+
*/
|
|
54
|
+
const onChangeDateInput = useCallback(newDateString => {
|
|
55
|
+
let dateString = newDateString;
|
|
56
|
+
const newStringLength = dateString.length;
|
|
57
|
+
const maxLength = intlDateFormat.dateStringFormat.length;
|
|
58
|
+
if (newStringLength > maxLength || intlDateFormat.invalidDateFormatRegex.test(dateString)) return;
|
|
59
|
+
const newLastChar = dateString.charAt(newStringLength - 1);
|
|
60
|
+
const isDeletion = newStringLength < inputValue.length;
|
|
61
|
+
if (!isDeletion) {
|
|
62
|
+
const expectSeparator = intlDateFormat.separatorIndices.includes(newStringLength - 1);
|
|
63
|
+
|
|
64
|
+
// Add a separator as the user is typing if they miss one
|
|
65
|
+
if (expectSeparator && newLastChar !== intlDateFormat.separator) {
|
|
66
|
+
dateString = "".concat(dateString.slice(0, -1)).concat(intlDateFormat.separator).concat(dateString.slice(-1));
|
|
67
|
+
}
|
|
68
|
+
const separatorCount = dateString.split(intlDateFormat.separator).length - 1;
|
|
69
|
+
|
|
70
|
+
// Don't allow the user to type a separator unless we expect one
|
|
71
|
+
if (!expectSeparator && newLastChar === intlDateFormat.separator) return;
|
|
72
|
+
// Don't allow the user to type a duplicate separator or more than 2 separators
|
|
73
|
+
if (intlDateFormat.duplicateSeparatorRegex.test(dateString) || separatorCount > intlDateFormat.separatorIndices.length) return;
|
|
74
|
+
}
|
|
75
|
+
const isCompleteDateString = dateString.length === maxLength;
|
|
76
|
+
|
|
77
|
+
// If we have a complete date string, generate a date and validate it
|
|
78
|
+
if (isCompleteDateString) {
|
|
79
|
+
const date = intlDateFormat.date(dateString);
|
|
80
|
+
const newError = validateDateInput(dateString);
|
|
81
|
+
onChangeDate(newError ? null : date);
|
|
82
|
+
if (newError) onErrorDate(newError);else if (error && error.type !== 'custom') onErrorDate(null);
|
|
83
|
+
} else {
|
|
84
|
+
// If it's not a complete date string, but it was on the previous render, we can clear the date
|
|
85
|
+
if (hadCompleteDateString.current) onChangeDate(null);
|
|
86
|
+
// If we had an error with the previous complete date string, we can clear it now
|
|
87
|
+
if (error && error.type !== 'custom') onErrorDate(null);
|
|
88
|
+
}
|
|
89
|
+
hadCompleteDateString.current = isCompleteDateString;
|
|
90
|
+
|
|
91
|
+
// Update the input value with the coerced date string
|
|
92
|
+
setInputValue(dateString);
|
|
93
|
+
}, [inputValue, intlDateFormat, error, validateDateInput, onChangeDate, onErrorDate]);
|
|
94
|
+
const api = useMemo(() => ({
|
|
95
|
+
inputValue,
|
|
96
|
+
onChangeDateInput,
|
|
97
|
+
intlDateFormat,
|
|
98
|
+
placeholder,
|
|
99
|
+
validateDateInput,
|
|
100
|
+
disabledTimes,
|
|
101
|
+
minTime,
|
|
102
|
+
maxTime
|
|
103
|
+
}), [inputValue, onChangeDateInput, intlDateFormat, placeholder, validateDateInput, disabledTimes, minTime, maxTime]);
|
|
104
|
+
return api;
|
|
105
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { DateInputValidationError } from './DateInputValidationError';
|
|
3
|
+
import { getMidnightDate } from './getMidnightDate';
|
|
4
|
+
import { getTimesFromDatesAndRanges } from './getTimesFromDatesAndRanges';
|
|
5
|
+
const oneHundredYearsInMs = 3.156e12;
|
|
6
|
+
export const useDateInputValidation = _ref => {
|
|
7
|
+
let {
|
|
8
|
+
intlDateFormat,
|
|
9
|
+
required,
|
|
10
|
+
disabledDates,
|
|
11
|
+
minDate,
|
|
12
|
+
maxDate,
|
|
13
|
+
requiredError = 'This field is required',
|
|
14
|
+
invalidDateError = 'Please enter a valid date',
|
|
15
|
+
disabledDateError = 'Date unavailable'
|
|
16
|
+
} = _ref;
|
|
17
|
+
const disabledTimes = useMemo(() => getTimesFromDatesAndRanges(disabledDates || []), [disabledDates]);
|
|
18
|
+
const minTime = useMemo(() => minDate && getMidnightDate(minDate).getTime(), [minDate]);
|
|
19
|
+
const maxTime = useMemo(() => maxDate && getMidnightDate(maxDate).getTime(), [maxDate]);
|
|
20
|
+
const validateDateInput = useCallback(dateString => {
|
|
21
|
+
// First evaluate the date string for any errors
|
|
22
|
+
const date = intlDateFormat.date(dateString);
|
|
23
|
+
const time = date === null || date === void 0 ? void 0 : date.getTime();
|
|
24
|
+
let errorType;
|
|
25
|
+
|
|
26
|
+
// Check if date string is fully formed if it's required
|
|
27
|
+
if (required && dateString.length !== intlDateFormat.dateStringFormat.length) errorType = 'required';
|
|
28
|
+
// Check if date is valid
|
|
29
|
+
else if (!date || Number.isNaN(date)) errorType = 'invalid';else if (time && (minTime && time < minTime - oneHundredYearsInMs || maxTime && time > maxTime + oneHundredYearsInMs)) errorType = 'invalid';
|
|
30
|
+
// Check if date is disabled
|
|
31
|
+
else if (time && (minTime && time < minTime || maxTime && time > maxTime || disabledTimes.includes(time))) errorType = 'disabled';
|
|
32
|
+
|
|
33
|
+
// Now assign the error message based on the error type and create the DateInputValidationError
|
|
34
|
+
const defaultError = intlDateFormat.dateStringFormat;
|
|
35
|
+
const errorMessages = {
|
|
36
|
+
required: requiredError,
|
|
37
|
+
invalid: invalidDateError,
|
|
38
|
+
disabled: disabledDateError
|
|
39
|
+
};
|
|
40
|
+
const error = errorType ? new DateInputValidationError(errorType, errorMessages[errorType] || defaultError) : null;
|
|
41
|
+
return error;
|
|
42
|
+
}, [intlDateFormat, required, disabledTimes, minTime, maxTime, requiredError, invalidDateError, disabledDateError]);
|
|
43
|
+
const api = useMemo(() => ({
|
|
44
|
+
validateDateInput,
|
|
45
|
+
disabledTimes,
|
|
46
|
+
minTime,
|
|
47
|
+
maxTime
|
|
48
|
+
}), [validateDateInput, disabledTimes, minTime, maxTime]);
|
|
49
|
+
return api;
|
|
50
|
+
};
|