@hitachivantara/uikit-react-core 5.66.12 → 5.66.14
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/dist/cjs/ActionsGeneric/ActionsGeneric.cjs +1 -2
- package/dist/cjs/AvatarGroup/AvatarGroup.cjs +1 -2
- package/dist/cjs/BaseDropdown/BaseDropdown.cjs +2 -4
- package/dist/cjs/Box/Box.cjs +13 -14
- package/dist/cjs/Button/Button.cjs +3 -6
- package/dist/cjs/Calendar/CalendarHeader/CalendarHeader.cjs +2 -4
- package/dist/cjs/Calendar/SingleCalendar/CalendarCell.cjs +1 -2
- package/dist/cjs/Calendar/SingleCalendar/SingleCalendar.cjs +4 -8
- package/dist/cjs/Calendar/utils.cjs +4 -8
- package/dist/cjs/Carousel/Carousel.cjs +26 -11
- package/dist/cjs/Carousel/CarouselControls.cjs +9 -2
- package/dist/cjs/ColorPicker/Fields/Fields.cjs +4 -8
- package/dist/cjs/DatePicker/DatePicker.cjs +6 -12
- package/dist/cjs/Dialog/Dialog.cjs +2 -4
- package/dist/cjs/Drawer/Drawer.cjs +1 -2
- package/dist/cjs/DropDownMenu/DropDownMenu.cjs +2 -4
- package/dist/cjs/Dropdown/Dropdown.cjs +1 -2
- package/dist/cjs/Dropdown/List/List.cjs +2 -4
- package/dist/cjs/Dropdown/utils.cjs +1 -2
- package/dist/cjs/FileUploader/DropZone/DropZone.cjs +3 -6
- package/dist/cjs/FileUploader/FileList/FileList.cjs +1 -2
- package/dist/cjs/FilterGroup/FilterContent/FilterContent.cjs +2 -4
- package/dist/cjs/Focus/Focus.cjs +7 -14
- package/dist/cjs/Forms/FormElement/utils/FormUtils.cjs +6 -4
- package/dist/cjs/GlobalActions/GlobalActions.styles.cjs +1 -2
- package/dist/cjs/Grid/Grid.cjs +7 -4
- package/dist/cjs/Header/Navigation/useSelectionPath.cjs +1 -2
- package/dist/cjs/Input/Input.cjs +2 -4
- package/dist/cjs/Link/Link.cjs +1 -2
- package/dist/cjs/List/List.cjs +12 -15
- package/dist/cjs/List/utils.cjs +1 -2
- package/dist/cjs/ListContainer/ListContainer.cjs +1 -2
- package/dist/cjs/ListContainer/ListContext/ListContext.cjs +1 -2
- package/dist/cjs/ListContainer/ListItem/ListItem.cjs +3 -6
- package/dist/cjs/LoadingContainer/LoadingContainer.cjs +2 -1
- package/dist/cjs/Pagination/Select.cjs +1 -2
- package/dist/cjs/QueryBuilder/Rule/Attribute/Attribute.cjs +1 -2
- package/dist/cjs/QueryBuilder/Rule/Value/NumericValue/NumericValue.cjs +2 -2
- package/dist/cjs/QueryBuilder/utils/reducer.cjs +1 -2
- package/dist/cjs/ScrollTo/Horizontal/ScrollToHorizontal.cjs +2 -2
- package/dist/cjs/ScrollTo/Vertical/ScrollToVertical.cjs +2 -2
- package/dist/cjs/Select/Select.cjs +2 -2
- package/dist/cjs/Skeleton/Skeleton.cjs +1 -2
- package/dist/cjs/Slider/Slider.cjs +1 -2
- package/dist/cjs/Slider/SliderInput/SliderInput.cjs +1 -2
- package/dist/cjs/Slider/utils.cjs +4 -8
- package/dist/cjs/Stack/Stack.cjs +1 -2
- package/dist/cjs/Table/TableContext.cjs +1 -2
- package/dist/cjs/Table/TableSectionContext.cjs +1 -2
- package/dist/cjs/Table/hooks/useBulkActions.cjs +1 -2
- package/dist/cjs/Table/hooks/useRowExpand.cjs +5 -1
- package/dist/cjs/Table/utils/fallbacks.cjs +1 -2
- package/dist/cjs/Tag/Tag.cjs +2 -4
- package/dist/cjs/TagsInput/TagsInput.cjs +2 -3
- package/dist/cjs/TextArea/TextArea.cjs +1 -2
- package/dist/cjs/TimeAgo/TimeAgo.cjs +1 -2
- package/dist/cjs/TimeAgo/useTimeout.cjs +1 -2
- package/dist/cjs/TimePicker/Placeholder.cjs +3 -6
- package/dist/cjs/TimePicker/TimePicker.cjs +3 -6
- package/dist/cjs/TreeView/TreeItem/TreeItem.cjs +2 -1
- package/dist/cjs/TreeView/TreeItem/useHvTreeItem.cjs +3 -6
- package/dist/cjs/TreeView/internals/DescendantProvider.cjs +1 -2
- package/dist/cjs/TreeView/internals/hooks/plugins/useTreeViewExpansion.cjs +1 -2
- package/dist/cjs/TreeView/internals/hooks/plugins/useTreeViewFocus.cjs +1 -2
- package/dist/cjs/TreeView/internals/hooks/plugins/useTreeViewKeyboardNavigation.cjs +1 -2
- package/dist/cjs/TreeView/internals/hooks/plugins/useTreeViewNodes.cjs +1 -2
- package/dist/cjs/TreeView/internals/hooks/plugins/useTreeViewSelection.cjs +1 -2
- package/dist/cjs/TreeView/internals/hooks/useInstanceEventHandler.cjs +1 -2
- package/dist/cjs/TreeView/internals/hooks/useTreeView.cjs +1 -2
- package/dist/cjs/TreeView/internals/hooks/useTreeViewInstanceEvents.cjs +1 -2
- package/dist/cjs/TreeView/internals/hooks/useTreeViewModels.cjs +1 -2
- package/dist/cjs/Typography/utils.cjs +1 -2
- package/dist/cjs/VerticalNavigation/Header/Header.cjs +1 -2
- package/dist/cjs/VerticalNavigation/Navigation/Navigation.cjs +2 -4
- package/dist/cjs/VerticalNavigation/TreeView/TreeView.cjs +3 -6
- package/dist/cjs/VerticalNavigation/TreeView/TreeViewItem.cjs +4 -8
- package/dist/cjs/hooks/useForkRef.cjs +1 -2
- package/dist/cjs/hooks/useUniqueId.cjs +2 -4
- package/dist/cjs/providers/Provider.cjs +2 -4
- package/dist/cjs/utils/classes.cjs +6 -3
- package/dist/cjs/utils/deepMerge.cjs +2 -1
- package/dist/cjs/utils/helpers.cjs +1 -2
- package/dist/cjs/utils/theme.cjs +1 -2
- package/dist/cjs/utils/useSavedState.cjs +1 -2
- package/dist/esm/ActionsGeneric/ActionsGeneric.js +1 -2
- package/dist/esm/ActionsGeneric/ActionsGeneric.js.map +1 -1
- package/dist/esm/AvatarGroup/AvatarGroup.js +1 -2
- package/dist/esm/AvatarGroup/AvatarGroup.js.map +1 -1
- package/dist/esm/BaseDropdown/BaseDropdown.js +2 -4
- package/dist/esm/BaseDropdown/BaseDropdown.js.map +1 -1
- package/dist/esm/Box/Box.js +13 -14
- package/dist/esm/Box/Box.js.map +1 -1
- package/dist/esm/Button/Button.js +3 -6
- package/dist/esm/Button/Button.js.map +1 -1
- package/dist/esm/Button/Button.styles.js.map +1 -1
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.js +2 -4
- package/dist/esm/Calendar/CalendarHeader/CalendarHeader.js.map +1 -1
- package/dist/esm/Calendar/SingleCalendar/CalendarCell.js +1 -2
- package/dist/esm/Calendar/SingleCalendar/CalendarCell.js.map +1 -1
- package/dist/esm/Calendar/SingleCalendar/SingleCalendar.js +4 -8
- package/dist/esm/Calendar/SingleCalendar/SingleCalendar.js.map +1 -1
- package/dist/esm/Calendar/utils.js +4 -8
- package/dist/esm/Calendar/utils.js.map +1 -1
- package/dist/esm/Card/Card.js.map +1 -1
- package/dist/esm/Carousel/Carousel.js +26 -11
- package/dist/esm/Carousel/Carousel.js.map +1 -1
- package/dist/esm/Carousel/CarouselControls.js +9 -2
- package/dist/esm/Carousel/CarouselControls.js.map +1 -1
- package/dist/esm/ColorPicker/Fields/Fields.js +3 -6
- package/dist/esm/ColorPicker/Fields/Fields.js.map +1 -1
- package/dist/esm/DatePicker/DatePicker.js +6 -12
- package/dist/esm/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/Dialog/Dialog.js +2 -4
- package/dist/esm/Dialog/Dialog.js.map +1 -1
- package/dist/esm/Drawer/Drawer.js +1 -2
- package/dist/esm/Drawer/Drawer.js.map +1 -1
- package/dist/esm/DropDownMenu/DropDownMenu.js +2 -4
- package/dist/esm/DropDownMenu/DropDownMenu.js.map +1 -1
- package/dist/esm/Dropdown/Dropdown.js +1 -2
- package/dist/esm/Dropdown/Dropdown.js.map +1 -1
- package/dist/esm/Dropdown/List/List.js +2 -4
- package/dist/esm/Dropdown/List/List.js.map +1 -1
- package/dist/esm/Dropdown/utils.js +1 -2
- package/dist/esm/Dropdown/utils.js.map +1 -1
- package/dist/esm/FileUploader/DropZone/DropZone.js +3 -6
- package/dist/esm/FileUploader/DropZone/DropZone.js.map +1 -1
- package/dist/esm/FileUploader/FileList/FileList.js +1 -2
- package/dist/esm/FileUploader/FileList/FileList.js.map +1 -1
- package/dist/esm/FilterGroup/FilterContent/FilterContent.js +2 -4
- package/dist/esm/FilterGroup/FilterContent/FilterContent.js.map +1 -1
- package/dist/esm/Focus/Focus.js +7 -14
- package/dist/esm/Focus/Focus.js.map +1 -1
- package/dist/esm/Forms/FormElement/FormElement.js.map +1 -1
- package/dist/esm/Forms/FormElement/context/FormElementContext.js.map +1 -1
- package/dist/esm/Forms/FormElement/context/FormElementDescriptorsContext.js.map +1 -1
- package/dist/esm/Forms/FormElement/utils/FormUtils.js +6 -4
- package/dist/esm/Forms/FormElement/utils/FormUtils.js.map +1 -1
- package/dist/esm/GlobalActions/GlobalActions.styles.js +1 -2
- package/dist/esm/GlobalActions/GlobalActions.styles.js.map +1 -1
- package/dist/esm/Grid/Grid.js +7 -4
- package/dist/esm/Grid/Grid.js.map +1 -1
- package/dist/esm/Header/Navigation/useSelectionPath.js +1 -2
- package/dist/esm/Header/Navigation/useSelectionPath.js.map +1 -1
- package/dist/esm/Input/Input.js +2 -4
- package/dist/esm/Input/Input.js.map +1 -1
- package/dist/esm/Link/Link.js +1 -2
- package/dist/esm/Link/Link.js.map +1 -1
- package/dist/esm/List/List.js +12 -15
- package/dist/esm/List/List.js.map +1 -1
- package/dist/esm/List/utils.js +1 -2
- package/dist/esm/List/utils.js.map +1 -1
- package/dist/esm/ListContainer/ListContainer.js +4 -5
- package/dist/esm/ListContainer/ListContainer.js.map +1 -1
- package/dist/esm/ListContainer/ListContext/ListContext.js +1 -2
- package/dist/esm/ListContainer/ListContext/ListContext.js.map +1 -1
- package/dist/esm/ListContainer/ListItem/ListItem.js +5 -8
- package/dist/esm/ListContainer/ListItem/ListItem.js.map +1 -1
- package/dist/esm/Loading/Loading.js.map +1 -1
- package/dist/esm/LoadingContainer/LoadingContainer.js +2 -1
- package/dist/esm/LoadingContainer/LoadingContainer.js.map +1 -1
- package/dist/esm/MultiButton/MultiButton.js.map +1 -1
- package/dist/esm/Pagination/Select.js +1 -2
- package/dist/esm/Pagination/Select.js.map +1 -1
- package/dist/esm/QueryBuilder/Rule/Attribute/Attribute.js +1 -2
- package/dist/esm/QueryBuilder/Rule/Attribute/Attribute.js.map +1 -1
- package/dist/esm/QueryBuilder/Rule/Operator/Operator.js.map +1 -1
- package/dist/esm/QueryBuilder/Rule/Value/NumericValue/NumericValue.js +2 -2
- package/dist/esm/QueryBuilder/Rule/Value/NumericValue/NumericValue.js.map +1 -1
- package/dist/esm/QueryBuilder/utils/index.js.map +1 -1
- package/dist/esm/QueryBuilder/utils/reducer.js +1 -2
- package/dist/esm/QueryBuilder/utils/reducer.js.map +1 -1
- package/dist/esm/ScrollTo/Horizontal/ScrollToHorizontal.js +2 -2
- package/dist/esm/ScrollTo/Horizontal/ScrollToHorizontal.js.map +1 -1
- package/dist/esm/ScrollTo/Vertical/ScrollToVertical.js +2 -2
- package/dist/esm/ScrollTo/Vertical/ScrollToVertical.js.map +1 -1
- package/dist/esm/Section/Section.js.map +1 -1
- package/dist/esm/Select/Select.js +2 -2
- package/dist/esm/Select/Select.js.map +1 -1
- package/dist/esm/SimpleGrid/SimpleGrid.styles.js.map +1 -1
- package/dist/esm/Skeleton/Skeleton.js +1 -2
- package/dist/esm/Skeleton/Skeleton.js.map +1 -1
- package/dist/esm/Slider/Slider.js +1 -2
- package/dist/esm/Slider/Slider.js.map +1 -1
- package/dist/esm/Slider/SliderInput/SliderInput.js +1 -2
- package/dist/esm/Slider/SliderInput/SliderInput.js.map +1 -1
- package/dist/esm/Slider/utils.js +4 -8
- package/dist/esm/Slider/utils.js.map +1 -1
- package/dist/esm/Snackbar/Snackbar.js.map +1 -1
- package/dist/esm/Stack/Stack.js +1 -2
- package/dist/esm/Stack/Stack.js.map +1 -1
- package/dist/esm/Table/TableCell/TableCell.js.map +1 -1
- package/dist/esm/Table/TableContext.js +1 -2
- package/dist/esm/Table/TableContext.js.map +1 -1
- package/dist/esm/Table/TableHeader/TableHeader.js.map +1 -1
- package/dist/esm/Table/TableRow/TableRow.js.map +1 -1
- package/dist/esm/Table/TableSectionContext.js +1 -2
- package/dist/esm/Table/TableSectionContext.js.map +1 -1
- package/dist/esm/Table/hooks/useBulkActions.js +1 -2
- package/dist/esm/Table/hooks/useBulkActions.js.map +1 -1
- package/dist/esm/Table/hooks/useHeaderGroups.js.map +1 -1
- package/dist/esm/Table/hooks/usePagination.js.map +1 -1
- package/dist/esm/Table/hooks/useResizeColumns.js.map +1 -1
- package/dist/esm/Table/hooks/useRowExpand.js +5 -1
- package/dist/esm/Table/hooks/useRowExpand.js.map +1 -1
- package/dist/esm/Table/hooks/useRowSelection.js.map +1 -1
- package/dist/esm/Table/hooks/useSortBy.js.map +1 -1
- package/dist/esm/Table/hooks/useSticky.js.map +1 -1
- package/dist/esm/Table/hooks/useTableStyles.js.map +1 -1
- package/dist/esm/Table/utils/fallbacks.js +1 -2
- package/dist/esm/Table/utils/fallbacks.js.map +1 -1
- package/dist/esm/Tag/Tag.js +2 -4
- package/dist/esm/Tag/Tag.js.map +1 -1
- package/dist/esm/TagsInput/TagsInput.js +2 -3
- package/dist/esm/TagsInput/TagsInput.js.map +1 -1
- package/dist/esm/TextArea/TextArea.js +1 -2
- package/dist/esm/TextArea/TextArea.js.map +1 -1
- package/dist/esm/TimeAgo/TimeAgo.js +1 -2
- package/dist/esm/TimeAgo/TimeAgo.js.map +1 -1
- package/dist/esm/TimeAgo/useTimeout.js +1 -2
- package/dist/esm/TimeAgo/useTimeout.js.map +1 -1
- package/dist/esm/TimePicker/Placeholder.js +3 -6
- package/dist/esm/TimePicker/Placeholder.js.map +1 -1
- package/dist/esm/TimePicker/TimePicker.js +3 -6
- package/dist/esm/TimePicker/TimePicker.js.map +1 -1
- package/dist/esm/TreeView/TreeItem/TreeItem.js +2 -1
- package/dist/esm/TreeView/TreeItem/TreeItem.js.map +1 -1
- package/dist/esm/TreeView/TreeItem/useHvTreeItem.js +2 -4
- package/dist/esm/TreeView/TreeItem/useHvTreeItem.js.map +1 -1
- package/dist/esm/Typography/utils.js +1 -2
- package/dist/esm/Typography/utils.js.map +1 -1
- package/dist/esm/VerticalNavigation/Header/Header.js +1 -2
- package/dist/esm/VerticalNavigation/Header/Header.js.map +1 -1
- package/dist/esm/VerticalNavigation/Navigation/Navigation.js +2 -4
- package/dist/esm/VerticalNavigation/Navigation/Navigation.js.map +1 -1
- package/dist/esm/VerticalNavigation/NavigationSlider/utils/NavigationSlider.utils.js.map +1 -1
- package/dist/esm/VerticalNavigation/TreeView/TreeView.js +3 -6
- package/dist/esm/VerticalNavigation/TreeView/TreeView.js.map +1 -1
- package/dist/esm/VerticalNavigation/TreeView/TreeViewContext.js.map +1 -1
- package/dist/esm/VerticalNavigation/TreeView/TreeViewItem.js +4 -8
- package/dist/esm/VerticalNavigation/TreeView/TreeViewItem.js.map +1 -1
- package/dist/esm/VerticalNavigation/VerticalNavigation.js.map +1 -1
- package/dist/esm/VerticalNavigation/VerticalNavigationContext.js.map +1 -1
- package/dist/esm/hocs/withTooltip.js.map +1 -1
- package/dist/esm/hooks/useComputation.js.map +1 -1
- package/dist/esm/hooks/useCss.js.map +1 -1
- package/dist/esm/hooks/useForkRef.js.map +1 -1
- package/dist/esm/hooks/useUniqueId.js +1 -2
- package/dist/esm/hooks/useUniqueId.js.map +1 -1
- package/dist/esm/providers/Provider.js +2 -4
- package/dist/esm/providers/Provider.js.map +1 -1
- package/dist/esm/types/generic.js.map +1 -1
- package/dist/esm/utils/classes.js +6 -3
- package/dist/esm/utils/classes.js.map +1 -1
- package/dist/esm/utils/deepMerge.js +2 -1
- package/dist/esm/utils/deepMerge.js.map +1 -1
- package/dist/esm/utils/helpers.js +1 -2
- package/dist/esm/utils/helpers.js.map +1 -1
- package/dist/esm/utils/theme.js +1 -2
- package/dist/esm/utils/theme.js.map +1 -1
- package/dist/esm/utils/useSavedState.js +1 -2
- package/dist/esm/utils/useSavedState.js.map +1 -1
- package/dist/types/index.d.ts +299 -365
- package/package.json +4 -4
|
@@ -6,8 +6,7 @@ import { fixedForwardRef } from "../types/generic.js";
|
|
|
6
6
|
import { useClasses, getIconSizeStyles, getSizeStyles, getColoringStyle, getRadiusStyles, getOverrideColors } from "./Button.styles.js";
|
|
7
7
|
import { staticClasses } from "./Button.styles.js";
|
|
8
8
|
const mapVariant = (variant, theme) => {
|
|
9
|
-
if (theme === "ds3")
|
|
10
|
-
return variant;
|
|
9
|
+
if (theme === "ds3") return variant;
|
|
11
10
|
const deprecatedVariantMap = {
|
|
12
11
|
secondary: "secondarySubtle",
|
|
13
12
|
ghost: "primaryGhost"
|
|
@@ -44,13 +43,11 @@ const HvButton = fixedForwardRef(function HvButton2(props, ref) {
|
|
|
44
43
|
activeTheme?.name
|
|
45
44
|
);
|
|
46
45
|
const handleClick = (e) => {
|
|
47
|
-
if (disabled)
|
|
48
|
-
return;
|
|
46
|
+
if (disabled) return;
|
|
49
47
|
onClickProp?.(e);
|
|
50
48
|
};
|
|
51
49
|
const handleMouseDown = (e) => {
|
|
52
|
-
if (disabled)
|
|
53
|
-
return;
|
|
50
|
+
if (disabled) return;
|
|
54
51
|
onMouseDownProp?.(e);
|
|
55
52
|
};
|
|
56
53
|
const [color, type] = useMemo(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","sources":["../../../src/Button/Button.tsx"],"sourcesContent":["import { useMemo } from \"react\";\n\nimport { useDefaultProps } from \"../hooks/useDefaultProps\";\nimport { useTheme } from \"../hooks/useTheme\";\nimport {\n fixedForwardRef,\n PolymorphicComponentRef,\n PolymorphicRef,\n} from \"../types/generic\";\nimport { ExtractNames } from \"../utils/classes\";\nimport {\n staticClasses as buttonClasses,\n getColoringStyle,\n getIconSizeStyles,\n getOverrideColors,\n getRadiusStyles,\n getSizeStyles,\n useClasses,\n} from \"./Button.styles\";\nimport { HvButtonRadius, HvButtonSize, HvButtonVariant } from \"./types\";\n\nexport { buttonClasses };\n\nexport type HvButtonClasses = ExtractNames<typeof useClasses>;\n\nexport type HvButtonProps<C extends React.ElementType = \"button\"> =\n PolymorphicComponentRef<\n C,\n {\n /** Use the variant prop to change the visual style of the button. */\n variant?: HvButtonVariant;\n /** Whether the button is an icon-only button. */\n icon?: boolean;\n /** Whether the button is disabled or not. */\n disabled?: boolean;\n /** Class names to be applied. */\n className?: string;\n /** Element placed before the children. */\n startIcon?: React.ReactNode;\n /** Element placed after the children. */\n endIcon?: React.ReactNode;\n /** Button size. */\n size?: HvButtonSize;\n /** Button border radius. */\n radius?: HvButtonRadius;\n /** Defines the default colors of the button are forced into the icon. */\n overrideIconColors?: boolean;\n /** A Jss Object used to override or extend the styles applied. */\n classes?: HvButtonClasses;\n /** Whether the button is selected or not. */\n selected?: boolean;\n /**\n * Whether the button is focusable when disabled.\n * Without this property, the accessibility of the button decreases when disabled since it's not read by screen readers.\n * Set this property to `true` when you need the button to still be focusable when disabled for accessibility purposes.\n */\n focusableWhenDisabled?: boolean;\n }\n >;\n\n/**\n * Normalize the button variant. It's meant to give us some retro-compatibility with\n * the DS 3.6 API.\n * @returns the normalized variant in DS 5 API\n */\nconst mapVariant = (\n variant: HvButtonVariant,\n theme?: string,\n): HvButtonVariant => {\n if (theme === \"ds3\") return variant;\n\n const deprecatedVariantMap: Record<string, HvButtonVariant> = {\n secondary: \"secondarySubtle\",\n ghost: \"primaryGhost\",\n };\n\n const mappedVariant = deprecatedVariantMap[variant];\n\n if (import.meta.env.DEV && mappedVariant) {\n // eslint-disable-next-line no-console\n console.warn(\n `Button variant '${variant}' is deprecated. Please use '${mappedVariant}'.`,\n );\n }\n\n return mappedVariant || variant;\n};\n\n/**\n * Button component is used to trigger an action or event.\n */\nexport const HvButton = fixedForwardRef(function HvButton<\n C extends React.ElementType = \"button\",\n>(props: HvButtonProps<C>, ref: PolymorphicRef<C>) {\n const {\n classes: classesProp,\n children,\n variant: variantProp, // TODO - should we split into two props (color and type) in v6?\n disabled = false,\n className,\n startIcon,\n endIcon,\n icon = false,\n size,\n radius,\n overrideIconColors = true,\n component: Component = \"button\",\n focusableWhenDisabled,\n onClick: onClickProp,\n onMouseDown: onMouseDownProp,\n selected,\n style,\n ...others\n } = useDefaultProps(\"HvButton\", props);\n const { classes, css, cx } = useClasses(classesProp);\n const { activeTheme } = useTheme();\n const variant = mapVariant(\n variantProp ?? (icon ? \"secondaryGhost\" : \"primary\"),\n activeTheme?.name,\n );\n\n const handleClick: HvButtonProps[\"onClick\"] = (e) => {\n if (disabled) return;\n onClickProp?.(e);\n };\n\n const handleMouseDown: HvButtonProps[\"onMouseDown\"] = (e) => {\n if (disabled) return;\n onMouseDownProp?.(e);\n };\n\n const [color, type] = useMemo(() => {\n const result = variant.split(/(?=[A-Z])/);\n if (\n result[0] === \"ghost\" ||\n result[0] === \"semantic\" ||\n (result[0] === \"secondary\" && !result[1])\n )\n return [];\n return result.map((x) => x.toLowerCase());\n }, [variant]);\n\n const sizeStyles = useMemo(\n () =>\n size ? (icon ? getIconSizeStyles(size) : getSizeStyles(size)) : undefined,\n [size, icon],\n );\n\n return (\n <Component\n ref={ref}\n style={{\n ...style,\n \"--HvButton-height\": sizeStyles ? sizeStyles.height : \"32px\",\n }}\n className={cx(\n classes.root,\n type && classes[type],\n color && css(getColoringStyle(color, type)),\n classes[variant], // Placed after type and color CSS for DS3 override\n radius && css(getRadiusStyles(radius)),\n overrideIconColors && css(getOverrideColors()),\n {\n [classes.icon]: icon,\n [classes.disabled]: disabled,\n },\n sizeStyles && css(sizeStyles),\n className,\n )}\n onClick={handleClick}\n onMouseDown={handleMouseDown}\n {...(Component === \"button\" && { type: \"button\" })}\n {...(disabled && {\n disabled: !focusableWhenDisabled,\n tabIndex: focusableWhenDisabled ? 0 : -1,\n \"aria-disabled\": true,\n })}\n {...(selected && { \"aria-pressed\": selected })}\n {...others}\n >\n {startIcon && <span className={classes.startIcon}>{startIcon}</span>}\n {children}\n {endIcon && <span className={classes.endIcon}>{endIcon}</span>}\n </Component>\n );\n});\n"],"names":["HvButton"],"mappings":";;;;;;;AAiEA,MAAM,aAAa,CACjB,SACA,UACoB;
|
|
1
|
+
{"version":3,"file":"Button.js","sources":["../../../src/Button/Button.tsx"],"sourcesContent":["import { useMemo } from \"react\";\n\nimport { useDefaultProps } from \"../hooks/useDefaultProps\";\nimport { useTheme } from \"../hooks/useTheme\";\nimport {\n fixedForwardRef,\n PolymorphicComponentRef,\n PolymorphicRef,\n} from \"../types/generic\";\nimport { ExtractNames } from \"../utils/classes\";\nimport {\n staticClasses as buttonClasses,\n getColoringStyle,\n getIconSizeStyles,\n getOverrideColors,\n getRadiusStyles,\n getSizeStyles,\n useClasses,\n} from \"./Button.styles\";\nimport { HvButtonRadius, HvButtonSize, HvButtonVariant } from \"./types\";\n\nexport { buttonClasses };\n\nexport type HvButtonClasses = ExtractNames<typeof useClasses>;\n\nexport type HvButtonProps<C extends React.ElementType = \"button\"> =\n PolymorphicComponentRef<\n C,\n {\n /** Use the variant prop to change the visual style of the button. */\n variant?: HvButtonVariant;\n /** Whether the button is an icon-only button. */\n icon?: boolean;\n /** Whether the button is disabled or not. */\n disabled?: boolean;\n /** Class names to be applied. */\n className?: string;\n /** Element placed before the children. */\n startIcon?: React.ReactNode;\n /** Element placed after the children. */\n endIcon?: React.ReactNode;\n /** Button size. */\n size?: HvButtonSize;\n /** Button border radius. */\n radius?: HvButtonRadius;\n /** Defines the default colors of the button are forced into the icon. */\n overrideIconColors?: boolean;\n /** A Jss Object used to override or extend the styles applied. */\n classes?: HvButtonClasses;\n /** Whether the button is selected or not. */\n selected?: boolean;\n /**\n * Whether the button is focusable when disabled.\n * Without this property, the accessibility of the button decreases when disabled since it's not read by screen readers.\n * Set this property to `true` when you need the button to still be focusable when disabled for accessibility purposes.\n */\n focusableWhenDisabled?: boolean;\n }\n >;\n\n/**\n * Normalize the button variant. It's meant to give us some retro-compatibility with\n * the DS 3.6 API.\n * @returns the normalized variant in DS 5 API\n */\nconst mapVariant = (\n variant: HvButtonVariant,\n theme?: string,\n): HvButtonVariant => {\n if (theme === \"ds3\") return variant;\n\n const deprecatedVariantMap: Record<string, HvButtonVariant> = {\n secondary: \"secondarySubtle\",\n ghost: \"primaryGhost\",\n };\n\n const mappedVariant = deprecatedVariantMap[variant];\n\n if (import.meta.env.DEV && mappedVariant) {\n // eslint-disable-next-line no-console\n console.warn(\n `Button variant '${variant}' is deprecated. Please use '${mappedVariant}'.`,\n );\n }\n\n return mappedVariant || variant;\n};\n\n/**\n * Button component is used to trigger an action or event.\n */\nexport const HvButton = fixedForwardRef(function HvButton<\n C extends React.ElementType = \"button\",\n>(props: HvButtonProps<C>, ref: PolymorphicRef<C>) {\n const {\n classes: classesProp,\n children,\n variant: variantProp, // TODO - should we split into two props (color and type) in v6?\n disabled = false,\n className,\n startIcon,\n endIcon,\n icon = false,\n size,\n radius,\n overrideIconColors = true,\n component: Component = \"button\",\n focusableWhenDisabled,\n onClick: onClickProp,\n onMouseDown: onMouseDownProp,\n selected,\n style,\n ...others\n } = useDefaultProps(\"HvButton\", props);\n const { classes, css, cx } = useClasses(classesProp);\n const { activeTheme } = useTheme();\n const variant = mapVariant(\n variantProp ?? (icon ? \"secondaryGhost\" : \"primary\"),\n activeTheme?.name,\n );\n\n const handleClick: HvButtonProps[\"onClick\"] = (e) => {\n if (disabled) return;\n onClickProp?.(e);\n };\n\n const handleMouseDown: HvButtonProps[\"onMouseDown\"] = (e) => {\n if (disabled) return;\n onMouseDownProp?.(e);\n };\n\n const [color, type] = useMemo(() => {\n const result = variant.split(/(?=[A-Z])/);\n if (\n result[0] === \"ghost\" ||\n result[0] === \"semantic\" ||\n (result[0] === \"secondary\" && !result[1])\n )\n return [];\n return result.map((x) => x.toLowerCase());\n }, [variant]);\n\n const sizeStyles = useMemo(\n () =>\n size ? (icon ? getIconSizeStyles(size) : getSizeStyles(size)) : undefined,\n [size, icon],\n );\n\n return (\n <Component\n ref={ref}\n style={{\n ...style,\n \"--HvButton-height\": sizeStyles ? sizeStyles.height : \"32px\",\n }}\n className={cx(\n classes.root,\n type && classes[type as keyof HvButtonClasses],\n color && css(getColoringStyle(color, type)),\n classes[variant as keyof HvButtonClasses], // Placed after type and color CSS for DS3 override\n radius && css(getRadiusStyles(radius)),\n overrideIconColors && css(getOverrideColors()),\n {\n [classes.icon]: icon,\n [classes.disabled]: disabled,\n },\n sizeStyles && css(sizeStyles),\n className,\n )}\n onClick={handleClick}\n onMouseDown={handleMouseDown}\n {...(Component === \"button\" && { type: \"button\" })}\n {...(disabled && {\n disabled: !focusableWhenDisabled,\n tabIndex: focusableWhenDisabled ? 0 : -1,\n \"aria-disabled\": true,\n })}\n {...(selected && { \"aria-pressed\": selected })}\n {...others}\n >\n {startIcon && <span className={classes.startIcon}>{startIcon}</span>}\n {children}\n {endIcon && <span className={classes.endIcon}>{endIcon}</span>}\n </Component>\n );\n});\n"],"names":["HvButton"],"mappings":";;;;;;;AAiEA,MAAM,aAAa,CACjB,SACA,UACoB;AAChB,MAAA,UAAU,MAAc,QAAA;AAE5B,QAAM,uBAAwD;AAAA,IAC5D,WAAW;AAAA,IACX,OAAO;AAAA,EAAA;AAGH,QAAA,gBAAgB,qBAAqB,OAAO;AASlD,SAAO,iBAAiB;AAC1B;AAKO,MAAM,WAAW,gBAAgB,SAASA,UAE/C,OAAyB,KAAwB;AAC3C,QAAA;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA,SAAS;AAAA;AAAA,IACT,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA,qBAAqB;AAAA,IACrB,WAAW,YAAY;AAAA,IACvB;AAAA,IACA,SAAS;AAAA,IACT,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD,gBAAgB,YAAY,KAAK;AACrC,QAAM,EAAE,SAAS,KAAK,GAAG,IAAI,WAAW,WAAW;AAC7C,QAAA,EAAE,gBAAg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c,YAAY,EAAE,MAAM,SAAS;AAAA,MAC/C,GAAI,YAAY;AAAA,QACf,UAAU,CAAC;AAAA,QACX,UAAU,wBAAwB,IAAI;AAAA,QACtC,iBAAiB;AAAA,MACnB;AAAA,MACC,GAAI,YAAY,EAAE,gBAAgB,SAAS;AAAA,MAC3C,GAAG;AAAA,MAEH,UAAA;AAAA,QAAA,aAAc,oBAAA,QAAA,EAAK,WAAW,QAAQ,WAAY,UAAU,WAAA;AAAA,QAC5D;AAAA,QACA,WAAY,oBAAA,QAAA,EAAK,WAAW,QAAQ,SAAU,UAAQ,SAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAG7D,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.styles.js","sources":["../../../src/Button/Button.styles.ts"],"sourcesContent":["import { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { createClasses } from \"../utils/classes\";\nimport { outlineStyles } from \"../utils/focusUtils\";\nimport { HvButtonRadius, HvButtonSize } from \"./types\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvButton\", {\n root: {\n display: \"inline-flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n textTransform: \"none\",\n cursor: \"pointer\",\n whiteSpace: \"nowrap\",\n\n // Background color common for almost all variants\n \"&:hover\": {\n backgroundColor: theme.colors.containerBackgroundHover,\n },\n \"&:focus-visible\": {\n ...outlineStyles,\n backgroundColor: theme.colors.containerBackgroundHover,\n },\n\n // Default button - no size specified\n fontFamily: theme.fontFamily.body,\n ...theme.typography.label,\n height: \"var(--HvButton-height)\",\n border: \"1px solid currentcolor\",\n borderRadius: theme.radii.base,\n padding: theme.spacing(0, \"sm\"),\n },\n startIcon: {\n marginLeft: `calc(-1 * ${theme.space.xs})`,\n },\n endIcon: {\n marginRight: `calc(-1 * ${theme.space.xs})`,\n },\n focusVisible: {},\n disabled: {\n cursor: \"not-allowed\",\n color: theme.colors.secondary_60,\n borderColor: theme.colors.atmo3,\n backgroundColor: theme.colors.atmo3,\n \"&:hover, &:focus-visible\": {\n backgroundColor: theme.colors.atmo3,\n borderColor: theme.colors.atmo3,\n },\n },\n icon: {\n margin: 0,\n padding: 0,\n height: \"fit-content\",\n \"& > *\": {\n margin: -1,\n },\n },\n subtle: {\n backgroundColor: \"transparent\",\n \"&$disabled\": {\n backgroundColor: \"transparent\",\n \"&:hover, &:focus-visible\": {\n backgroundColor: \"transparent\",\n },\n },\n },\n ghost: {\n borderColor: \"transparent\",\n backgroundColor: \"transparent\",\n \"&$disabled\": {\n borderColor: \"transparent\",\n backgroundColor: \"transparent\",\n \"&:hover, &:focus-visible\": {\n borderColor: \"transparent\",\n backgroundColor: \"transparent\",\n },\n },\n },\n semantic: {\n color: theme.colors.base_dark,\n backgroundColor: \"transparent\",\n borderColor: \"transparent\",\n \"&:hover, &:focus-visible\": {\n backgroundColor: \"rgba(251, 252, 252, 0.3)\",\n },\n \"&$disabled\": {\n backgroundColor: \"rgba(251, 252, 252, 0.1)\",\n },\n },\n\n // TODO - remove in v6\n primary: {},\n primarySubtle: {},\n primaryGhost: {},\n secondarySubtle: {},\n secondaryGhost: {},\n\n // Deprecated (DS3)\n secondary: {},\n});\n\nexport const getColoringStyle = (color: string, type?: string) => {\n if (type)\n return {\n color
|
|
1
|
+
{"version":3,"file":"Button.styles.js","sources":["../../../src/Button/Button.styles.ts"],"sourcesContent":["import { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { createClasses } from \"../utils/classes\";\nimport { outlineStyles } from \"../utils/focusUtils\";\nimport { HvButtonRadius, HvButtonSize } from \"./types\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvButton\", {\n root: {\n display: \"inline-flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n textTransform: \"none\",\n cursor: \"pointer\",\n whiteSpace: \"nowrap\",\n\n // Background color common for almost all variants\n \"&:hover\": {\n backgroundColor: theme.colors.containerBackgroundHover,\n },\n \"&:focus-visible\": {\n ...outlineStyles,\n backgroundColor: theme.colors.containerBackgroundHover,\n },\n\n // Default button - no size specified\n fontFamily: theme.fontFamily.body,\n ...theme.typography.label,\n height: \"var(--HvButton-height)\",\n border: \"1px solid currentcolor\",\n borderRadius: theme.radii.base,\n padding: theme.spacing(0, \"sm\"),\n },\n startIcon: {\n marginLeft: `calc(-1 * ${theme.space.xs})`,\n },\n endIcon: {\n marginRight: `calc(-1 * ${theme.space.xs})`,\n },\n focusVisible: {},\n disabled: {\n cursor: \"not-allowed\",\n color: theme.colors.secondary_60,\n borderColor: theme.colors.atmo3,\n backgroundColor: theme.colors.atmo3,\n \"&:hover, &:focus-visible\": {\n backgroundColor: theme.colors.atmo3,\n borderColor: theme.colors.atmo3,\n },\n },\n icon: {\n margin: 0,\n padding: 0,\n height: \"fit-content\",\n \"& > *\": {\n margin: -1,\n },\n },\n subtle: {\n backgroundColor: \"transparent\",\n \"&$disabled\": {\n backgroundColor: \"transparent\",\n \"&:hover, &:focus-visible\": {\n backgroundColor: \"transparent\",\n },\n },\n },\n ghost: {\n borderColor: \"transparent\",\n backgroundColor: \"transparent\",\n \"&$disabled\": {\n borderColor: \"transparent\",\n backgroundColor: \"transparent\",\n \"&:hover, &:focus-visible\": {\n borderColor: \"transparent\",\n backgroundColor: \"transparent\",\n },\n },\n },\n semantic: {\n color: theme.colors.base_dark,\n backgroundColor: \"transparent\",\n borderColor: \"transparent\",\n \"&:hover, &:focus-visible\": {\n backgroundColor: \"rgba(251, 252, 252, 0.3)\",\n },\n \"&$disabled\": {\n backgroundColor: \"rgba(251, 252, 252, 0.1)\",\n },\n },\n\n // TODO - remove in v6\n primary: {},\n primarySubtle: {},\n primaryGhost: {},\n secondarySubtle: {},\n secondaryGhost: {},\n\n // Deprecated (DS3)\n secondary: {},\n});\n\nexport const getColoringStyle = (color: string, type?: string) => {\n if (type)\n return {\n color:\n theme.colors[\n (color !== \"warning\"\n ? color\n : `${color}_140`) as keyof typeof theme.colors\n ],\n };\n\n const bg =\n theme.colors[\n (color !== \"warning\"\n ? color\n : `${color}_120`) as keyof typeof theme.colors\n ];\n const hoverBg =\n theme.colors[\n (color !== \"warning\"\n ? `${color}_80`\n : `${color}_140`) as keyof typeof theme.colors\n ];\n return {\n color: theme.colors.atmo1,\n backgroundColor: bg,\n borderColor: bg,\n \"&:hover, &:focus-visible\": {\n backgroundColor: hoverBg,\n borderColor: hoverBg,\n },\n };\n};\n\nexport const getRadiusStyles = (radius: HvButtonRadius) => ({\n borderRadius: theme.radii[radius],\n});\n\n// TODO - remove xs and xl in v6 since they are not DS spec\nconst sizes = {\n xs: { height: \"24px\", space: \"sm\", typography: \"captionLabel\" },\n sm: { height: \"24px\", space: \"sm\", typography: \"captionLabel\" },\n md: { height: \"32px\", space: \"sm\", typography: \"label\" },\n lg: { height: \"48px\", space: \"md\", typography: \"label\" },\n xl: { height: \"48px\", space: \"md\", typography: \"label\" },\n};\n\nexport const getSizeStyles = (size: HvButtonSize) => {\n const { height, space, typography } = sizes[size];\n const { color, ...typoProps } =\n theme.typography[typography as keyof typeof theme.typography];\n return {\n height,\n padding: theme.spacing(0, space),\n ...typoProps,\n };\n};\n\nexport const getIconSizeStyles = (size: HvButtonSize) => {\n const { height } = sizes[size];\n return {\n height,\n width: height,\n };\n};\n\nexport const getOverrideColors = () => ({\n \"& svg .color0\": {\n fill: \"currentcolor\",\n },\n});\n"],"names":[],"mappings":";;;AAMO,MAAM,EAAE,eAAe,eAAe,cAAc,YAAY;AAAA,EACrE,MAAM;AAAA,IACJ,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,YAAY;AAAA;AAAA,IAGZ,WAAW;AAAA,MACT,iBAAiB,MAAM,OAAO;AAAA,IAChC;AAAA,IACA,mBAAmB;AAAA,MACjB,GAAG;AAAA,MACH,iBAAiB,MAAM,OAAO;AAAA,IAChC;AAAA;AAAA,IAGA,YAAY,MAAM,WAAW;AAAA,IAC7B,GAAG,MAAM,WAAW;AAAA,I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AEP;AAEa,MAAA,oBAAoB,CAAC,SAAuB;AACvD,QAAM,EAAE,OAAA,IAAW,MAAM,IAAI;AACtB,SAAA;AAAA,IACL;AAAA,IACA,OAAO;AAAA,EAAA;AAEX;AAEO,MAAM,oBAAoB,OAAO;AAAA,EACtC,iBAAiB;AAAA,IACf,MAAM;AAAA,EACR;AACF;"}
|
|
@@ -81,8 +81,7 @@ const HvCalendarHeader = (props) => {
|
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
const onBlurHandler = (event) => {
|
|
84
|
-
if (editedValue == null)
|
|
85
|
-
return;
|
|
84
|
+
if (editedValue == null) return;
|
|
86
85
|
if (editedValue === "") {
|
|
87
86
|
setIsValidValue(true);
|
|
88
87
|
setEditedValue(null);
|
|
@@ -97,8 +96,7 @@ const HvCalendarHeader = (props) => {
|
|
|
97
96
|
handleNewDate(event, editedValue);
|
|
98
97
|
};
|
|
99
98
|
const onFocusHandler = (event) => {
|
|
100
|
-
if (!localValue)
|
|
101
|
-
return;
|
|
99
|
+
if (!localValue) return;
|
|
102
100
|
const formattedDate = isValidValue && isDate(localValue) ? dayjs(localValue).locale(locale).format("L") : editedValue;
|
|
103
101
|
setEditedValue(formattedDate);
|
|
104
102
|
onFocus?.(event, formattedDate);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CalendarHeader.js","sources":["../../../../src/Calendar/CalendarHeader/CalendarHeader.tsx"],"sourcesContent":["import { useContext, useEffect, useState } from \"react\";\nimport dayjs from \"dayjs\";\nimport customParseFormat from \"dayjs/plugin/customParseFormat\";\nimport localeData from \"dayjs/plugin/localeData\";\nimport localizedFormat from \"dayjs/plugin/localizedFormat\";\n\nimport {\n HvFormElementContext,\n HvFormElementDescriptorsContext,\n HvFormElementValueContext,\n} from \"../../Forms\";\nimport { useDefaultProps } from \"../../hooks/useDefaultProps\";\nimport { HvInput, HvInputProps } from \"../../Input\";\nimport { HvTypography } from \"../../Typography\";\nimport { ExtractNames } from \"../../utils/classes\";\nimport { isKey } from \"../../utils/keyboardUtils\";\nimport { setId } from \"../../utils/setId\";\nimport { DateRangeProp } from \"../types\";\nimport { formatToLocale, isDate, isRange, isSameDay } from \"../utils\";\nimport { staticClasses, useClasses } from \"./CalendarHeader.styles\";\n\nexport { staticClasses as calendarHeaderClasses };\n\nexport type HvCalendarHeaderClasses = ExtractNames<typeof useClasses>;\n\ndayjs.extend(localeData);\ndayjs.extend(localizedFormat);\ndayjs.extend(customParseFormat);\n\nexport const HvCalendarHeader = (props: HvCalendarHeaderProps) => {\n const {\n id,\n value,\n locale = \"en-US\",\n classes: classesProp,\n onChange,\n showEndDate,\n showDayOfWeek = false,\n onFocus,\n invalidDateLabel = \"Invalid Date\",\n } = useDefaultProps(\"HvCalendarHeader\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const { elementId } = useContext(HvFormElementContext);\n const elementValue = useContext(HvFormElementValueContext);\n const { label } = useContext(HvFormElementDescriptorsContext);\n\n let localValue: string | Date | DateRangeProp | undefined =\n value ?? elementValue ?? \"\";\n if (isRange(localValue)) {\n localValue = showEndDate ? localValue.endDate : localValue.startDate;\n }\n\n const [dateValue, setDateValue] = useState<\n string | Date | DateRangeProp | undefined\n >(localValue);\n const [editedValue, setEditedValue] = useState<string | null>(null);\n const [displayValue, setDisplayValue] = useState(\"\");\n const [weekdayDisplay, setWeekdayDisplay] = useState(\"\");\n\n const localId = id ?? setId(elementId, \"calendarHeader\");\n\n const inputValue = editedValue ?? displayValue;\n const localeFormat = dayjs().locale(locale).localeData().longDateFormat(\"L\");\n\n const [isValidValue, setIsValidValue] = useState(\n inputValue.length === 0 || (!!inputValue && dayjs(localValue).isValid()),\n );\n\n const validateInput = (incomingValid: any) =>\n incomingValid === undefined || dayjs(incomingValid).isValid();\n\n useEffect(() => {\n const valid = validateInput(localValue);\n setIsValidValue(valid);\n if (valid) {\n if (!localValue) {\n setDisplayValue(\"\");\n setEditedValue(null);\n setWeekdayDisplay(\"\");\n return;\n }\n const weekday = new Intl.DateTimeFormat(locale, {\n weekday: \"short\",\n }).format(isDate(localValue) ? localValue : 0);\n setDisplayValue(formatToLocale(localValue, locale));\n setEditedValue(null);\n setWeekdayDisplay(weekday);\n }\n }, [localValue, locale]);\n\n const handleNewDate = (event: any, date: string) => {\n // attempt to format in locale data, or fallback to default\n const localeParsedDate = dayjs(date, localeFormat);\n\n const isValidInput = localeParsedDate.isValid();\n const dateParsed = isValidInput\n ? localeParsedDate.toDate()\n : dayjs(date).toDate();\n // prevent extra updates\n if (!isSameDay(dateParsed, dateValue)) {\n setDateValue(dateParsed);\n onChange?.(event, dateParsed);\n }\n\n setIsValidValue(isValidInput);\n if (isValidInput) {\n setEditedValue(null);\n }\n };\n\n const onBlurHandler: HvInputProps[\"onBlur\"] = (event) => {\n if (editedValue == null) return;\n if (editedValue === \"\") {\n setIsValidValue(true);\n setEditedValue(null);\n return;\n }\n handleNewDate(event, editedValue);\n };\n\n const keyDownHandler: HvInputProps[\"onKeyDown\"] = (event) => {\n if (!isKey(event, \"Enter\") || editedValue == null || editedValue === \"\")\n return;\n event.preventDefault();\n\n handleNewDate(event, editedValue);\n };\n\n const onFocusHandler: HvInputProps[\"onFocus\"] = (event) => {\n if (!localValue) return;\n const formattedDate =\n isValidValue && isDate(localValue)\n ? dayjs(localValue).locale(locale).format(\"L\")\n : editedValue;\n setEditedValue(formattedDate);\n onFocus?.(event, formattedDate);\n };\n\n const onChangeHandler: HvInputProps[\"onChange\"] = (event, val) => {\n setEditedValue(val);\n };\n\n const isInvalid = !isValidValue && inputValue !== \"\";\n\n // This component needs to be further refactored\n // It's not possible to clear the date\n // In a new major there's no need for all these classes\n return (\n <div\n id={localId}\n className={cx(classes.root, {\n [classes.invalid]: isInvalid,\n })}\n >\n {showDayOfWeek && (\n <HvTypography className={classes.headerDayOfWeek}>\n {weekdayDisplay || \"\\u00A0\"}\n </HvTypography>\n )}\n <HvInput\n type=\"text\"\n id={setId(localId, \"header-input\")}\n className={classes.headerDate}\n classes={{\n input: classes.input,\n inputBorderContainer: classes.inputBorderContainer,\n error: classes.invalidMessageStyling,\n }}\n placeholder={localeFormat}\n value={inputValue}\n aria-labelledby={label?.[0]?.id}\n onBlur={onBlurHandler}\n onFocus={onFocusHandler}\n onChange={onChangeHandler}\n onKeyDown={keyDownHandler}\n status={isInvalid ? \"invalid\" : \"valid\"}\n statusMessage={invalidDateLabel}\n />\n </div>\n );\n};\n\n// TODO: refactor this out\nHvCalendarHeader.formElementType = \"HvCalendarHeader\";\n\nexport interface HvCalendarHeaderProps {\n /**\n * A Jss Object used to override or extend the component styles.\n */\n classes?: HvCalendarHeaderClasses;\n /**\n * Identifier.\n */\n id?: string;\n /**\n * The text to be shown on the main part of the header.\n */\n value?: string | Date | DateRangeProp;\n /**\n * Locale to be used by the calendar.\n */\n locale?: string;\n /**\n * Callback to define the input date.\n */\n onChange?: (\n event:\n | React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>\n | undefined,\n value: Date | DateRangeProp,\n ) => void;\n /**\n * Callback to handle input onFocus.\n */\n onFocus?: (\n event: React.FocusEvent<HTMLTextAreaElement | HTMLInputElement>,\n formattedDate: string | null,\n ) => void;\n /**\n * Indicates if header should display end date in a date range.\n */\n showEndDate?: boolean;\n /**\n * Indicates if header should display the day of week.\n */\n showDayOfWeek?: boolean;\n /**\n * Label shown when date is invalid.\n */\n invalidDateLabel?: string;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAyBA,MAAM,OAAO,UAAU;AACvB,MAAM,OAAO,eAAe;AAC5B,MAAM,OAAO,iBAAiB;AAEjB,MAAA,mBAAmB,CAAC,UAAiC;AAC1D,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IACA,mBAAmB;AAAA,EAAA,IACjB,gBAAgB,oBAAoB,KAAK;AAE7C,QAAM,EAAE,SAAS,GAAG,IAAI,WAAW,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EF;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,MAAK;AAAA,YACL,IAAI,MAAM,SAAS,cAAc;AAAA,YACjC,WAAW,QAAQ;AAAA,YACnB,SAAS;AAAA,cACP,OAAO,QAAQ;AAAA,cACf,sBAAsB,QAAQ;AAAA,cAC9B,OAAO,QAAQ;AAAA,YACjB;AAAA,YACA,aAAa;AAAA,YACb,OAAO;AAAA,YACP,mBAAiB,QAAQ,CAAC,GAAG;AAAA,YAC7B,QAAQ;AAAA,YACR,SAAS;AAAA,YACT,UAAU;AAAA,YACV,WAAW;AAAA,YACX,QAAQ,YAAY,YAAY;AAAA,YAChC,eAAe;AAAA,UAAA;AAAA,QACjB;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGN;AAGA,iBAAiB,kBAAkB;"}
|
|
1
|
+
{"version":3,"file":"CalendarHeader.js","sources":["../../../../src/Calendar/CalendarHeader/CalendarHeader.tsx"],"sourcesContent":["import { useContext, useEffect, useState } from \"react\";\nimport dayjs from \"dayjs\";\nimport customParseFormat from \"dayjs/plugin/customParseFormat\";\nimport localeData from \"dayjs/plugin/localeData\";\nimport localizedFormat from \"dayjs/plugin/localizedFormat\";\n\nimport {\n HvFormElementContext,\n HvFormElementDescriptorsContext,\n HvFormElementValueContext,\n} from \"../../Forms\";\nimport { useDefaultProps } from \"../../hooks/useDefaultProps\";\nimport { HvInput, HvInputProps } from \"../../Input\";\nimport { HvTypography } from \"../../Typography\";\nimport { ExtractNames } from \"../../utils/classes\";\nimport { isKey } from \"../../utils/keyboardUtils\";\nimport { setId } from \"../../utils/setId\";\nimport { DateRangeProp } from \"../types\";\nimport { formatToLocale, isDate, isRange, isSameDay } from \"../utils\";\nimport { staticClasses, useClasses } from \"./CalendarHeader.styles\";\n\nexport { staticClasses as calendarHeaderClasses };\n\nexport type HvCalendarHeaderClasses = ExtractNames<typeof useClasses>;\n\ndayjs.extend(localeData);\ndayjs.extend(localizedFormat);\ndayjs.extend(customParseFormat);\n\nexport const HvCalendarHeader = (props: HvCalendarHeaderProps) => {\n const {\n id,\n value,\n locale = \"en-US\",\n classes: classesProp,\n onChange,\n showEndDate,\n showDayOfWeek = false,\n onFocus,\n invalidDateLabel = \"Invalid Date\",\n } = useDefaultProps(\"HvCalendarHeader\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const { elementId } = useContext(HvFormElementContext);\n const elementValue = useContext(HvFormElementValueContext);\n const { label } = useContext(HvFormElementDescriptorsContext);\n\n let localValue: string | Date | DateRangeProp | undefined =\n value ?? elementValue ?? \"\";\n if (isRange(localValue)) {\n localValue = showEndDate ? localValue.endDate : localValue.startDate;\n }\n\n const [dateValue, setDateValue] = useState<\n string | Date | DateRangeProp | undefined\n >(localValue);\n const [editedValue, setEditedValue] = useState<string | null>(null);\n const [displayValue, setDisplayValue] = useState(\"\");\n const [weekdayDisplay, setWeekdayDisplay] = useState(\"\");\n\n const localId = id ?? setId(elementId, \"calendarHeader\");\n\n const inputValue = editedValue ?? displayValue;\n const localeFormat = dayjs().locale(locale).localeData().longDateFormat(\"L\");\n\n const [isValidValue, setIsValidValue] = useState(\n inputValue.length === 0 || (!!inputValue && dayjs(localValue).isValid()),\n );\n\n const validateInput = (incomingValid: any) =>\n incomingValid === undefined || dayjs(incomingValid).isValid();\n\n useEffect(() => {\n const valid = validateInput(localValue);\n setIsValidValue(valid);\n if (valid) {\n if (!localValue) {\n setDisplayValue(\"\");\n setEditedValue(null);\n setWeekdayDisplay(\"\");\n return;\n }\n const weekday = new Intl.DateTimeFormat(locale, {\n weekday: \"short\",\n }).format(isDate(localValue) ? localValue : 0);\n setDisplayValue(formatToLocale(localValue, locale));\n setEditedValue(null);\n setWeekdayDisplay(weekday);\n }\n }, [localValue, locale]);\n\n const handleNewDate = (event: any, date: string) => {\n // attempt to format in locale data, or fallback to default\n const localeParsedDate = dayjs(date, localeFormat);\n\n const isValidInput = localeParsedDate.isValid();\n const dateParsed = isValidInput\n ? localeParsedDate.toDate()\n : dayjs(date).toDate();\n // prevent extra updates\n if (!isSameDay(dateParsed, dateValue)) {\n setDateValue(dateParsed);\n onChange?.(event, dateParsed);\n }\n\n setIsValidValue(isValidInput);\n if (isValidInput) {\n setEditedValue(null);\n }\n };\n\n const onBlurHandler: HvInputProps[\"onBlur\"] = (event) => {\n if (editedValue == null) return;\n if (editedValue === \"\") {\n setIsValidValue(true);\n setEditedValue(null);\n return;\n }\n handleNewDate(event, editedValue);\n };\n\n const keyDownHandler: HvInputProps[\"onKeyDown\"] = (event) => {\n if (!isKey(event, \"Enter\") || editedValue == null || editedValue === \"\")\n return;\n event.preventDefault();\n\n handleNewDate(event, editedValue);\n };\n\n const onFocusHandler: HvInputProps[\"onFocus\"] = (event) => {\n if (!localValue) return;\n const formattedDate =\n isValidValue && isDate(localValue)\n ? dayjs(localValue).locale(locale).format(\"L\")\n : editedValue;\n setEditedValue(formattedDate);\n onFocus?.(event, formattedDate);\n };\n\n const onChangeHandler: HvInputProps[\"onChange\"] = (event, val) => {\n setEditedValue(val);\n };\n\n const isInvalid = !isValidValue && inputValue !== \"\";\n\n // This component needs to be further refactored\n // It's not possible to clear the date\n // In a new major there's no need for all these classes\n return (\n <div\n id={localId}\n className={cx(classes.root, {\n [classes.invalid]: isInvalid,\n })}\n >\n {showDayOfWeek && (\n <HvTypography className={classes.headerDayOfWeek}>\n {weekdayDisplay || \"\\u00A0\"}\n </HvTypography>\n )}\n <HvInput\n type=\"text\"\n id={setId(localId, \"header-input\")}\n className={classes.headerDate}\n classes={{\n input: classes.input,\n inputBorderContainer: classes.inputBorderContainer,\n error: classes.invalidMessageStyling,\n }}\n placeholder={localeFormat}\n value={inputValue}\n aria-labelledby={label?.[0]?.id}\n onBlur={onBlurHandler}\n onFocus={onFocusHandler}\n onChange={onChangeHandler}\n onKeyDown={keyDownHandler}\n status={isInvalid ? \"invalid\" : \"valid\"}\n statusMessage={invalidDateLabel}\n />\n </div>\n );\n};\n\n// TODO: refactor this out\nHvCalendarHeader.formElementType = \"HvCalendarHeader\";\n\nexport interface HvCalendarHeaderProps {\n /**\n * A Jss Object used to override or extend the component styles.\n */\n classes?: HvCalendarHeaderClasses;\n /**\n * Identifier.\n */\n id?: string;\n /**\n * The text to be shown on the main part of the header.\n */\n value?: string | Date | DateRangeProp;\n /**\n * Locale to be used by the calendar.\n */\n locale?: string;\n /**\n * Callback to define the input date.\n */\n onChange?: (\n event:\n | React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>\n | undefined,\n value: Date | DateRangeProp,\n ) => void;\n /**\n * Callback to handle input onFocus.\n */\n onFocus?: (\n event: React.FocusEvent<HTMLTextAreaElement | HTMLInputElement>,\n formattedDate: string | null,\n ) => void;\n /**\n * Indicates if header should display end date in a date range.\n */\n showEndDate?: boolean;\n /**\n * Indicates if header should display the day of week.\n */\n showDayOfWeek?: boolean;\n /**\n * Label shown when date is invalid.\n */\n invalidDateLabel?: string;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAyBA,MAAM,OAAO,UAAU;AACvB,MAAM,OAAO,eAAe;AAC5B,MAAM,OAAO,iBAAiB;AAEjB,MAAA,mBAAmB,CAAC,UAAiC;AAC1D,QAAA;AAAA,IACJ;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IACA,mBAAmB;AAAA,EAAA,IACjB,gBAAgB,oBAAoB,KAAK;AAE7C,QAAM,EAAE,SAAS,GAAG,IAAI,WAAW,WAAW;AAE9C,QAAM,EAAE,UAAA,IAAc,WAAW,oBAAoB;AAC/C,QAAA,eAAe,WAAW,yBAAyB;AACzD,QAAM,EAAE,MAAA,IAAU,WAAW,+BAA+B;AAExD,MAAA,aACF,SAAS,gBAAgB;AACvB,MAAA,QAAQ,UAAU,GAAG;AACV,iBAAA,cAAc,WAAW,UAAU,WAAW;AAAA,EAC7D;AAEA,QAAM,CAAC,WAAW,YAAY,IAAI,SAEhC,UAAU;AACZ,QAAM,CAAC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A,YACR,SAAS;AAAA,YACT,UAAU;AAAA,YACV,WAAW;AAAA,YACX,QAAQ,YAAY,YAAY;AAAA,YAChC,eAAe;AAAA,UAAA;AAAA,QACjB;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGN;AAGA,iBAAiB,kBAAkB;"}
|
|
@@ -38,8 +38,7 @@ const HvCalendarCell = (props) => {
|
|
|
38
38
|
const handleClick = (event) => {
|
|
39
39
|
if (value) {
|
|
40
40
|
onChange?.(event, value);
|
|
41
|
-
if (buttonEl.current)
|
|
42
|
-
setTimeout(() => buttonEl?.current?.focus());
|
|
41
|
+
if (buttonEl.current) setTimeout(() => buttonEl?.current?.focus());
|
|
43
42
|
}
|
|
44
43
|
};
|
|
45
44
|
const handleKeyDown = (event) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CalendarCell.js","sources":["../../../../src/Calendar/SingleCalendar/CalendarCell.tsx"],"sourcesContent":["import { useRef } from \"react\";\n\nimport { useDefaultProps } from \"../../hooks/useDefaultProps\";\nimport { HvTypography } from \"../../Typography\";\nimport { ExtractNames } from \"../../utils/classes\";\nimport CalendarModel from \"../model\";\nimport { DateRangeProp } from \"../types\";\nimport {\n checkIfDateIsDisabled,\n dateInProvidedValueRange,\n isDateRangeProp,\n isSameDay,\n isSameMonth,\n} from \"../utils\";\nimport { staticClasses, useClasses } from \"./CalendarCell.styles\";\n\nexport { staticClasses as calendarCellClasses };\n\nexport type HvCalendarCellClasses = ExtractNames<typeof useClasses>;\n\nexport const HvCalendarCell = (props: HvCalendarCellProps) => {\n const {\n classes: classesProp,\n onChange,\n onKeyDown,\n calendarValue,\n firstDayOfCurrentMonth,\n value,\n isDateSelectionMode,\n today,\n locale,\n minimumDate,\n maximumDate,\n rangeMode = false,\n ...others\n } = useDefaultProps(\"HvCalendarCell\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const buttonEl = useRef<HTMLButtonElement>(null);\n\n const startDate = isDateRangeProp(calendarValue)\n ? calendarValue.startDate\n : undefined;\n const endDate = isDateRangeProp(calendarValue)\n ? calendarValue.endDate\n : undefined;\n const isCellToday = isSameDay(value, today);\n const isCellSelected = isSameDay(calendarValue, value);\n const inMonth = isSameMonth(value, firstDayOfCurrentMonth);\n const isCellAfterStartingDate =\n rangeMode && value && startDate ? value >= startDate : false;\n const isCellStartingDate = rangeMode ? isSameDay(value, startDate) : false;\n const isDateInSelectionRange =\n calendarValue && rangeMode\n ? dateInProvidedValueRange(value, calendarValue)\n : false;\n const isDateDisabled = checkIfDateIsDisabled(value, minimumDate, maximumDate);\n const startBookend = isSameDay(startDate, value);\n const endBookend = isSameDay(endDate, value);\n const isSelecting = isDateSelectionMode && isCellAfterStartingDate;\n\n const handleClick = (event: React.SyntheticEvent) => {\n if (value) {\n onChange?.(event, value);\n if (buttonEl.current) setTimeout(() => buttonEl?.current?.focus());\n }\n };\n\n const handleKeyDown = (event: any) => {\n onKeyDown?.(event);\n };\n\n const renderDate = () => (\n <button\n ref={buttonEl}\n type=\"button\"\n className={cx(classes.cellContainer, {\n [classes.focusSelection]: inMonth,\n })}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n disabled={isDateDisabled || !inMonth}\n data-in-month={inMonth}\n {...others}\n >\n <HvTypography\n variant={isCellToday ? \"label\" : \"body\"}\n className={cx(classes.calendarDate, {\n [classes.calendarDateSelected]: inMonth && isCellSelected,\n [classes.calendarDateNotInMonth]: !inMonth,\n [classes.calendarDateInSelectionRange]:\n inMonth && rangeMode && isDateInSelectionRange,\n [classes.calendarDateDisabled]: isDateDisabled,\n [classes.startBookend]:\n inMonth &&\n ((startBookend && rangeMode) ||\n (isCellStartingDate && isDateSelectionMode)),\n [classes.endBookend]: inMonth && endBookend && rangeMode,\n })}\n >\n {value?.getDate()}\n </HvTypography>\n </button>\n );\n\n return (\n <div\n className={cx(classes.dateWrapper, {\n [classes.cellsInRange]: inMonth && rangeMode && isSelecting,\n [classes.cellsOutsideRange]: rangeMode && !isSelecting,\n })}\n data-calendar-cell=\"calendarCell\"\n >\n {renderDate()}\n </div>\n );\n};\n\nexport interface HvCalendarCellProps {\n /**\n * A Jss Object used to override or extend the component styles.\n */\n classes?: HvCalendarCellClasses;\n /**\n * Identifier.\n */\n id?: string;\n /**\n * The text to be shown on the main part of the header.\n */\n calendarValue?: string | Date | DateRangeProp;\n /**\n * The text to be shown on the main part of the header.\n */\n value?: Date;\n /**\n * Locale to be used by the calendar.\n */\n locale?: string;\n /**\n * Callback to define the input date.\n */\n onChange?: (event: React.SyntheticEvent, value: Date | DateRangeProp) => void;\n /**\n * Callback to handle input onFocus.\n */\n onFocus?: React.FocusEventHandler<any>;\n\n calendarModel?: CalendarModel;\n onKeyDown?: (event: KeyboardEvent) => void;\n\n today?: Date;\n minimumDate?: Date;\n maximumDate?: Date;\n firstDayOfCurrentMonth?: Date;\n isDateSelectionMode?: boolean;\n rangeMode?: boolean;\n tabIndex?: number;\n}\n\nexport default HvCalendarCell;\n"],"names":[],"mappings":";;;;;;;AAoBa,MAAA,iBAAiB,CAAC,UAA+B;AACtD,QAAA;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ,GAAG;AAAA,EAAA,IACD,gBAAgB,kBAAkB,KAAK;AAE3C,QAAM,EAAE,SAAS,GAAG,IAAI,WAAW,WAAW;AAExC,QAAA,WAAW,OAA0B,IAAI;AAE/C,QAAM,YAAY,gBAAgB,aAAa,IAC3C,cAAc,YACd;AACJ,QAAM,UAAU,gBAAgB,aAAa,IACzC,cAAc,UACd;AACE,QAAA,cAAc,UAAU,OAAO,KAAK;AACpC,QAAA,iBAAiB,UAAU,eAAe,KAAK;AAC/C,QAAA,UAAU,YAAY,OAAO,sBAAsB;AACzD,QAAM,0BACJ,aAAa,SAAS,YAAY,SAAS,YAAY;AACzD,QAAM,qBAAqB,YAAY,UAAU,OAAO,SAAS,IAAI;AACrE,QAAM,yBACJ,iBAAiB,YACb,yBAAyB,OAAO,aAAa,IAC7C;AACN,QAAM,iBAAiB,sBAAsB,OAAO,aAAa,WAAW;AACtE,QAAA,eAAe,UAAU,WAAW,KAAK;AACzC,QAAA,aAAa,UAAU,SAAS,KAAK;AAC3C,QAAM,cAAc,uBAAuB;AAErC,QAAA,cAAc,CAAC,UAAgC;AACnD,QAAI,OAAO;AACT,iBAAW,OAAO,KAAK;AACvB,UAAI,SAAS
|
|
1
|
+
{"version":3,"file":"CalendarCell.js","sources":["../../../../src/Calendar/SingleCalendar/CalendarCell.tsx"],"sourcesContent":["import { useRef } from \"react\";\n\nimport { useDefaultProps } from \"../../hooks/useDefaultProps\";\nimport { HvTypography } from \"../../Typography\";\nimport { ExtractNames } from \"../../utils/classes\";\nimport CalendarModel from \"../model\";\nimport { DateRangeProp } from \"../types\";\nimport {\n checkIfDateIsDisabled,\n dateInProvidedValueRange,\n isDateRangeProp,\n isSameDay,\n isSameMonth,\n} from \"../utils\";\nimport { staticClasses, useClasses } from \"./CalendarCell.styles\";\n\nexport { staticClasses as calendarCellClasses };\n\nexport type HvCalendarCellClasses = ExtractNames<typeof useClasses>;\n\nexport const HvCalendarCell = (props: HvCalendarCellProps) => {\n const {\n classes: classesProp,\n onChange,\n onKeyDown,\n calendarValue,\n firstDayOfCurrentMonth,\n value,\n isDateSelectionMode,\n today,\n locale,\n minimumDate,\n maximumDate,\n rangeMode = false,\n ...others\n } = useDefaultProps(\"HvCalendarCell\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const buttonEl = useRef<HTMLButtonElement>(null);\n\n const startDate = isDateRangeProp(calendarValue)\n ? calendarValue.startDate\n : undefined;\n const endDate = isDateRangeProp(calendarValue)\n ? calendarValue.endDate\n : undefined;\n const isCellToday = isSameDay(value, today);\n const isCellSelected = isSameDay(calendarValue, value);\n const inMonth = isSameMonth(value, firstDayOfCurrentMonth);\n const isCellAfterStartingDate =\n rangeMode && value && startDate ? value >= startDate : false;\n const isCellStartingDate = rangeMode ? isSameDay(value, startDate) : false;\n const isDateInSelectionRange =\n calendarValue && rangeMode\n ? dateInProvidedValueRange(value, calendarValue)\n : false;\n const isDateDisabled = checkIfDateIsDisabled(value, minimumDate, maximumDate);\n const startBookend = isSameDay(startDate, value);\n const endBookend = isSameDay(endDate, value);\n const isSelecting = isDateSelectionMode && isCellAfterStartingDate;\n\n const handleClick = (event: React.SyntheticEvent) => {\n if (value) {\n onChange?.(event, value);\n if (buttonEl.current) setTimeout(() => buttonEl?.current?.focus());\n }\n };\n\n const handleKeyDown = (event: any) => {\n onKeyDown?.(event);\n };\n\n const renderDate = () => (\n <button\n ref={buttonEl}\n type=\"button\"\n className={cx(classes.cellContainer, {\n [classes.focusSelection]: inMonth,\n })}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n disabled={isDateDisabled || !inMonth}\n data-in-month={inMonth}\n {...others}\n >\n <HvTypography\n variant={isCellToday ? \"label\" : \"body\"}\n className={cx(classes.calendarDate, {\n [classes.calendarDateSelected]: inMonth && isCellSelected,\n [classes.calendarDateNotInMonth]: !inMonth,\n [classes.calendarDateInSelectionRange]:\n inMonth && rangeMode && isDateInSelectionRange,\n [classes.calendarDateDisabled]: isDateDisabled,\n [classes.startBookend]:\n inMonth &&\n ((startBookend && rangeMode) ||\n (isCellStartingDate && isDateSelectionMode)),\n [classes.endBookend]: inMonth && endBookend && rangeMode,\n })}\n >\n {value?.getDate()}\n </HvTypography>\n </button>\n );\n\n return (\n <div\n className={cx(classes.dateWrapper, {\n [classes.cellsInRange]: inMonth && rangeMode && isSelecting,\n [classes.cellsOutsideRange]: rangeMode && !isSelecting,\n })}\n data-calendar-cell=\"calendarCell\"\n >\n {renderDate()}\n </div>\n );\n};\n\nexport interface HvCalendarCellProps {\n /**\n * A Jss Object used to override or extend the component styles.\n */\n classes?: HvCalendarCellClasses;\n /**\n * Identifier.\n */\n id?: string;\n /**\n * The text to be shown on the main part of the header.\n */\n calendarValue?: string | Date | DateRangeProp;\n /**\n * The text to be shown on the main part of the header.\n */\n value?: Date;\n /**\n * Locale to be used by the calendar.\n */\n locale?: string;\n /**\n * Callback to define the input date.\n */\n onChange?: (event: React.SyntheticEvent, value: Date | DateRangeProp) => void;\n /**\n * Callback to handle input onFocus.\n */\n onFocus?: React.FocusEventHandler<any>;\n\n calendarModel?: CalendarModel;\n onKeyDown?: (event: KeyboardEvent) => void;\n\n today?: Date;\n minimumDate?: Date;\n maximumDate?: Date;\n firstDayOfCurrentMonth?: Date;\n isDateSelectionMode?: boolean;\n rangeMode?: boolean;\n tabIndex?: number;\n}\n\nexport default HvCalendarCell;\n"],"names":[],"mappings":";;;;;;;AAoBa,MAAA,iBAAiB,CAAC,UAA+B;AACtD,QAAA;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ,GAAG;AAAA,EAAA,IACD,gBAAgB,kBAAkB,KAAK;AAE3C,QAAM,EAAE,SAAS,GAAG,IAAI,WAAW,WAAW;AAExC,QAAA,WAAW,OAA0B,IAAI;AAE/C,QAAM,YAAY,gBAAgB,aAAa,IAC3C,cAAc,YACd;AACJ,QAAM,UAAU,gBAAgB,aAAa,IACzC,cAAc,UACd;AACE,QAAA,cAAc,UAAU,OAAO,KAAK;AACpC,QAAA,iBAAiB,UAAU,eAAe,KAAK;AAC/C,QAAA,UAAU,YAAY,OAAO,sBAAsB;AACzD,QAAM,0BACJ,aAAa,SAAS,YAAY,SAAS,YAAY;AACzD,QAAM,qBAAqB,YAAY,UAAU,OAAO,SAAS,IAAI;AACrE,QAAM,yBACJ,iBAAiB,YACb,yBAAyB,OAAO,aAAa,IAC7C;AACN,QAAM,iBAAiB,sBAAsB,OAAO,aAAa,WAAW;AACtE,QAAA,eAAe,UAAU,WAAW,KAAK;AACzC,Q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AAA,CAC5C;AAAA,MACD,sBAAmB;AAAA,MAElB,UAAW,WAAA;AAAA,IAAA;AAAA,EAAA;AAGlB;"}
|
|
@@ -49,14 +49,10 @@ const HvSingleCalendar = ({
|
|
|
49
49
|
onInputChange?.(event, date);
|
|
50
50
|
};
|
|
51
51
|
const getNavChild = (event, siblings, i) => {
|
|
52
|
-
if (isKey(event, "ArrowLeft"))
|
|
53
|
-
|
|
54
|
-
if (isKey(event, "
|
|
55
|
-
|
|
56
|
-
if (isKey(event, "ArrowUp"))
|
|
57
|
-
return siblings[i - 7];
|
|
58
|
-
if (isKey(event, "ArrowDown"))
|
|
59
|
-
return siblings[i + 7];
|
|
52
|
+
if (isKey(event, "ArrowLeft")) return siblings[i - 1];
|
|
53
|
+
if (isKey(event, "ArrowRight")) return siblings[i + 1];
|
|
54
|
+
if (isKey(event, "ArrowUp")) return siblings[i - 7];
|
|
55
|
+
if (isKey(event, "ArrowDown")) return siblings[i + 7];
|
|
60
56
|
return void 0;
|
|
61
57
|
};
|
|
62
58
|
const handleKeyDown = (event) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SingleCalendar.js","sources":["../../../../src/Calendar/SingleCalendar/SingleCalendar.tsx"],"sourcesContent":["import { useMemo, useState } from \"react\";\n\nimport { HvTypography } from \"../../Typography\";\nimport { ExtractNames } from \"../../utils/classes\";\nimport { isKey } from \"../../utils/keyboardUtils\";\nimport { setId } from \"../../utils/setId\";\nimport { HvCalendarHeader } from \"../CalendarHeader/CalendarHeader\";\nimport { HvComposedNavigation, HvMonthSelector } from \"../CalendarNavigation\";\nimport { ViewMode } from \"../enums\";\nimport { generateCalendarModel } from \"../model\";\nimport { DateRangeProp, VisibilitySelectorActions } from \"../types\";\nimport { getWeekdayNamesList, isDate, isRange } from \"../utils\";\nimport { HvCalendarCell } from \"./CalendarCell\";\nimport { staticClasses, useClasses } from \"./SingleCalendar.styles\";\n\nexport { staticClasses as singleCalendarClasses };\n\nexport type HvSingleCalendarClasses = ExtractNames<typeof useClasses>;\n\nexport const HvSingleCalendar = ({\n classes: classesProp,\n className,\n id,\n locale = \"en-US\",\n value,\n visibleMonth,\n visibleYear,\n minimumDate,\n maximumDate,\n onChange,\n onInputChange,\n onVisibleDateChange,\n showEndDate,\n showDayOfWeek,\n invalidDateLabel,\n children,\n ...others\n}: HvSingleCalendarProps) => {\n // TODO: refactor this out\n // const { HvCalendarHeader } = useContext(HvFormElementDescriptorsContext);\n\n const { classes, cx } = useClasses(classesProp);\n\n const today = new Date();\n const localValue = value ?? today;\n\n const [calViewMode, setCalViewMode] = useState<ViewMode>(\"calendar\");\n\n const rangeMode = isRange(localValue);\n const isDateSelectionMode = rangeMode && !isDate(localValue.endDate);\n const calModel = rangeMode\n ? generateCalendarModel(localValue.startDate, visibleMonth, visibleYear)\n : generateCalendarModel(localValue, visibleMonth, visibleYear);\n const firstDayOfCurrentMonth = new Date(calModel.year, calModel.month - 1, 1);\n const firstDayOfCurrentMonthTime = firstDayOfCurrentMonth.getTime();\n\n const listWeekdayNames = useMemo(() => getWeekdayNamesList(locale), [locale]);\n\n const handleChange = (event: any, date: Date | DateRangeProp) => {\n event?.preventDefault();\n onChange?.(event, date);\n };\n\n const handleInputChange = (event: any, date: any) => {\n event?.preventDefault();\n onInputChange?.(event, date);\n };\n\n const getNavChild = (event: KeyboardEvent, siblings: any, i: number) => {\n if (isKey(event, \"ArrowLeft\")) return siblings[i - 1];\n if (isKey(event, \"ArrowRight\")) return siblings[i + 1];\n if (isKey(event, \"ArrowUp\")) return siblings[i - 7];\n if (isKey(event, \"ArrowDown\")) return siblings[i + 7];\n return undefined;\n };\n\n const handleKeyDown = (event: any) => {\n // This code is very brittle and should be managed with the focus wrapper\n const el = document?.activeElement;\n const parent = el?.parentElement?.parentElement;\n const siblings =\n parent != null\n ? Array.from(\n parent.getElementsByClassName(classes.cellContainer as string),\n )\n : [];\n const elIndex = el ? siblings.indexOf(el) : 0;\n\n if (isKey(event, \"Enter\")) {\n (el as HTMLElement).focus();\n return;\n }\n\n const child = getNavChild(event, siblings, elIndex);\n\n if (child) {\n const inMonth = child.getAttribute(\"data-in-month\");\n if (inMonth === \"true\") {\n event?.preventDefault();\n child?.focus();\n }\n }\n };\n\n const renderWeekLabel = (dayName: string, index: number) => (\n <HvTypography key={index} variant=\"label\" className={classes.calendarDay}>\n {dayName}\n </HvTypography>\n );\n\n /** Renders the element representing the received date. */\n const renderCalendarDate = (currentDate: Date) => {\n return (\n <HvCalendarCell\n classes={classes}\n key={currentDate.toString()}\n tabIndex={currentDate.getTime() === firstDayOfCurrentMonthTime ? 0 : -1}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n value={currentDate}\n today={today}\n calendarValue={localValue}\n rangeMode={rangeMode}\n isDateSelectionMode={isDateSelectionMode}\n locale={locale}\n firstDayOfCurrentMonth={firstDayOfCurrentMonth}\n maximumDate={maximumDate}\n minimumDate={minimumDate}\n />\n );\n };\n\n return (\n <div className={cx(classes.calendarContainer, className)} {...others}>\n <div id={id} className={classes.calendarWrapper}>\n <HvCalendarHeader\n id={setId(id, \"header\")}\n locale={locale}\n onChange={handleInputChange}\n showEndDate={showEndDate && !isDateSelectionMode}\n showDayOfWeek={showDayOfWeek}\n invalidDateLabel={invalidDateLabel}\n />\n {calViewMode === \"calendar\" && (\n <div>\n <HvComposedNavigation\n id={id}\n locale={locale}\n onChange={onVisibleDateChange}\n onViewModeChange={setCalViewMode}\n visibleYear={visibleYear || today.getFullYear()}\n visibleMonth={visibleMonth || today.getMonth() + 1}\n />\n <div\n className={classes.calendarGrid}\n // @ts-ignore TODO: review\n aria-controls={HvCalendarHeader?.[0]?.id}\n >\n {listWeekdayNames.map(renderWeekLabel)}\n {calModel.dates.map(renderCalendarDate)}\n </div>\n </div>\n )}\n {calViewMode === \"monthly\" && (\n <HvMonthSelector\n id={id}\n locale={locale}\n onChange={onVisibleDateChange}\n onViewModeChange={setCalViewMode}\n visibleMonth={visibleMonth || today.getMonth() + 1}\n rangeMode={rangeMode}\n />\n )}\n </div>\n </div>\n );\n};\n\nexport interface HvSingleCalendarProps {\n /**\n * Styles applied from the theme.\n */\n classes?: HvSingleCalendarClasses;\n /**\n * Identifier.\n */\n id?: string;\n /**\n * The class name to add at the root of the single calendar\n */\n className?: string;\n /**\n * The calendar locale.\n *\n */\n locale: string;\n /**\n * Date that the calendar would show.\n */\n value?: string | Date | DateRangeProp;\n /**\n * Date that will be used to know which month and year should be displayed on the calendar. The value of the day is\n * irrelevant.\n */\n visibleDate?: Date;\n /**\n * Controls the visible month of the Calendar\n */\n visibleMonth?: number;\n /**\n * Controls the visible month of the Calendar\n */\n visibleYear?: number;\n /**\n * Callback function to be triggered when the selected date has changed.\n */\n onChange?: (\n event:\n | React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>\n | undefined,\n value: Date | DateRangeProp,\n ) => void;\n /**\n * Callback function to be triggered when the selected date input has changed.\n */\n onInputChange?: (\n event:\n | React.ChangeEvent<\n HTMLTextAreaElement | HTMLInputElement | HTMLButtonElement\n >\n | undefined,\n value: Date | DateRangeProp,\n position?: \"left\" | \"right\",\n ) => void;\n /**\n * Callback function to be triggered when visible date has changed.\n */\n onVisibleDateChange?: (\n event:\n | React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>\n | undefined,\n action: VisibilitySelectorActions,\n value?: Date | DateRangeProp | number,\n ) => void;\n /**\n * The maximum selectable date after this all values are disabled.\n */\n maximumDate?: Date;\n /**\n * The minimum selectable date before this all values are disabled.\n */\n minimumDate?: Date;\n /**\n * Indicates if header should display end date in a date range.\n */\n showEndDate?: boolean;\n /**\n * Indicates if header should display the day of week.\n */\n showDayOfWeek?: boolean;\n /**\n * Content on the upper part of the calendar.\n */\n children?: React.ReactNode;\n /**\n * Label shown when date is invalid.\n */\n invalidDateLabel?: string;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAmBO,MAAM,mBAAmB,CAAC;AAAA,EAC/B,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA,SAA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AAA;AAAA,MAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA,UAAU;AAAA,UACV,kBAAkB;AAAA,UAClB,aAAa,eAAe,MAAM,YAAY;AAAA,UAC9C,cAAc,gBAAgB,MAAM,SAAa,IAAA;AAAA,QAAA;AAAA,MACnD;AAAA,MACA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAW,QAAQ;AAAA,UAEnB,iBAAe,mBAAmB,CAAC,GAAG;AAAA,UAErC,UAAA;AAAA,YAAA,iBAAiB,IAAI,eAAe;AAAA,YACpC,SAAS,MAAM,IAAI,kBAAkB;AAAA,UAAA;AAAA,QAAA;AAAA,MACxC;AAAA,IAAA,GACF;AAAA,IAED,gBAAgB,aACf;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,UAAU;AAAA,QACV,kBAAkB;AAAA,QAClB,cAAc,gBAAgB,MAAM,SAAa,IAAA;AAAA,QACjD;AAAA,MAAA;AAAA,IACF;AAAA,EAAA,EAEJ,CAAA,EACF,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"SingleCalendar.js","sources":["../../../../src/Calendar/SingleCalendar/SingleCalendar.tsx"],"sourcesContent":["import { useMemo, useState } from \"react\";\n\nimport { HvTypography } from \"../../Typography\";\nimport { ExtractNames } from \"../../utils/classes\";\nimport { isKey } from \"../../utils/keyboardUtils\";\nimport { setId } from \"../../utils/setId\";\nimport { HvCalendarHeader } from \"../CalendarHeader/CalendarHeader\";\nimport { HvComposedNavigation, HvMonthSelector } from \"../CalendarNavigation\";\nimport { ViewMode } from \"../enums\";\nimport { generateCalendarModel } from \"../model\";\nimport { DateRangeProp, VisibilitySelectorActions } from \"../types\";\nimport { getWeekdayNamesList, isDate, isRange } from \"../utils\";\nimport { HvCalendarCell } from \"./CalendarCell\";\nimport { staticClasses, useClasses } from \"./SingleCalendar.styles\";\n\nexport { staticClasses as singleCalendarClasses };\n\nexport type HvSingleCalendarClasses = ExtractNames<typeof useClasses>;\n\nexport const HvSingleCalendar = ({\n classes: classesProp,\n className,\n id,\n locale = \"en-US\",\n value,\n visibleMonth,\n visibleYear,\n minimumDate,\n maximumDate,\n onChange,\n onInputChange,\n onVisibleDateChange,\n showEndDate,\n showDayOfWeek,\n invalidDateLabel,\n children,\n ...others\n}: HvSingleCalendarProps) => {\n // TODO: refactor this out\n // const { HvCalendarHeader } = useContext(HvFormElementDescriptorsContext);\n\n const { classes, cx } = useClasses(classesProp);\n\n const today = new Date();\n const localValue = value ?? today;\n\n const [calViewMode, setCalViewMode] = useState<ViewMode>(\"calendar\");\n\n const rangeMode = isRange(localValue);\n const isDateSelectionMode = rangeMode && !isDate(localValue.endDate);\n const calModel = rangeMode\n ? generateCalendarModel(localValue.startDate, visibleMonth, visibleYear)\n : generateCalendarModel(localValue, visibleMonth, visibleYear);\n const firstDayOfCurrentMonth = new Date(calModel.year, calModel.month - 1, 1);\n const firstDayOfCurrentMonthTime = firstDayOfCurrentMonth.getTime();\n\n const listWeekdayNames = useMemo(() => getWeekdayNamesList(locale), [locale]);\n\n const handleChange = (event: any, date: Date | DateRangeProp) => {\n event?.preventDefault();\n onChange?.(event, date);\n };\n\n const handleInputChange = (event: any, date: any) => {\n event?.preventDefault();\n onInputChange?.(event, date);\n };\n\n const getNavChild = (event: KeyboardEvent, siblings: any, i: number) => {\n if (isKey(event, \"ArrowLeft\")) return siblings[i - 1];\n if (isKey(event, \"ArrowRight\")) return siblings[i + 1];\n if (isKey(event, \"ArrowUp\")) return siblings[i - 7];\n if (isKey(event, \"ArrowDown\")) return siblings[i + 7];\n return undefined;\n };\n\n const handleKeyDown = (event: any) => {\n // This code is very brittle and should be managed with the focus wrapper\n const el = document?.activeElement;\n const parent = el?.parentElement?.parentElement;\n const siblings =\n parent != null\n ? Array.from(\n parent.getElementsByClassName(classes.cellContainer as string),\n )\n : [];\n const elIndex = el ? siblings.indexOf(el) : 0;\n\n if (isKey(event, \"Enter\")) {\n (el as HTMLElement).focus();\n return;\n }\n\n const child = getNavChild(event, siblings, elIndex);\n\n if (child) {\n const inMonth = child.getAttribute(\"data-in-month\");\n if (inMonth === \"true\") {\n event?.preventDefault();\n child?.focus();\n }\n }\n };\n\n const renderWeekLabel = (dayName: string, index: number) => (\n <HvTypography key={index} variant=\"label\" className={classes.calendarDay}>\n {dayName}\n </HvTypography>\n );\n\n /** Renders the element representing the received date. */\n const renderCalendarDate = (currentDate: Date) => {\n return (\n <HvCalendarCell\n classes={classes}\n key={currentDate.toString()}\n tabIndex={currentDate.getTime() === firstDayOfCurrentMonthTime ? 0 : -1}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n value={currentDate}\n today={today}\n calendarValue={localValue}\n rangeMode={rangeMode}\n isDateSelectionMode={isDateSelectionMode}\n locale={locale}\n firstDayOfCurrentMonth={firstDayOfCurrentMonth}\n maximumDate={maximumDate}\n minimumDate={minimumDate}\n />\n );\n };\n\n return (\n <div className={cx(classes.calendarContainer, className)} {...others}>\n <div id={id} className={classes.calendarWrapper}>\n <HvCalendarHeader\n id={setId(id, \"header\")}\n locale={locale}\n onChange={handleInputChange}\n showEndDate={showEndDate && !isDateSelectionMode}\n showDayOfWeek={showDayOfWeek}\n invalidDateLabel={invalidDateLabel}\n />\n {calViewMode === \"calendar\" && (\n <div>\n <HvComposedNavigation\n id={id}\n locale={locale}\n onChange={onVisibleDateChange}\n onViewModeChange={setCalViewMode}\n visibleYear={visibleYear || today.getFullYear()}\n visibleMonth={visibleMonth || today.getMonth() + 1}\n />\n <div\n className={classes.calendarGrid}\n // @ts-ignore TODO: review\n aria-controls={HvCalendarHeader?.[0]?.id}\n >\n {listWeekdayNames.map(renderWeekLabel)}\n {calModel.dates.map(renderCalendarDate)}\n </div>\n </div>\n )}\n {calViewMode === \"monthly\" && (\n <HvMonthSelector\n id={id}\n locale={locale}\n onChange={onVisibleDateChange}\n onViewModeChange={setCalViewMode}\n visibleMonth={visibleMonth || today.getMonth() + 1}\n rangeMode={rangeMode}\n />\n )}\n </div>\n </div>\n );\n};\n\nexport interface HvSingleCalendarProps {\n /**\n * Styles applied from the theme.\n */\n classes?: HvSingleCalendarClasses;\n /**\n * Identifier.\n */\n id?: string;\n /**\n * The class name to add at the root of the single calendar\n */\n className?: string;\n /**\n * The calendar locale.\n *\n */\n locale: string;\n /**\n * Date that the calendar would show.\n */\n value?: string | Date | DateRangeProp;\n /**\n * Date that will be used to know which month and year should be displayed on the calendar. The value of the day is\n * irrelevant.\n */\n visibleDate?: Date;\n /**\n * Controls the visible month of the Calendar\n */\n visibleMonth?: number;\n /**\n * Controls the visible month of the Calendar\n */\n visibleYear?: number;\n /**\n * Callback function to be triggered when the selected date has changed.\n */\n onChange?: (\n event:\n | React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>\n | undefined,\n value: Date | DateRangeProp,\n ) => void;\n /**\n * Callback function to be triggered when the selected date input has changed.\n */\n onInputChange?: (\n event:\n | React.ChangeEvent<\n HTMLTextAreaElement | HTMLInputElement | HTMLButtonElement\n >\n | undefined,\n value: Date | DateRangeProp,\n position?: \"left\" | \"right\",\n ) => void;\n /**\n * Callback function to be triggered when visible date has changed.\n */\n onVisibleDateChange?: (\n event:\n | React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>\n | undefined,\n action: VisibilitySelectorActions,\n value?: Date | DateRangeProp | number,\n ) => void;\n /**\n * The maximum selectable date after this all values are disabled.\n */\n maximumDate?: Date;\n /**\n * The minimum selectable date before this all values are disabled.\n */\n minimumDate?: Date;\n /**\n * Indicates if header should display end date in a date range.\n */\n showEndDate?: boolean;\n /**\n * Indicates if header should display the day of week.\n */\n showDayOfWeek?: boolean;\n /**\n * Content on the upper part of the calendar.\n */\n children?: React.ReactNode;\n /**\n * Label shown when date is invalid.\n */\n invalidDateLabel?: string;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAmBO,MAAM,mBAAmB,CAAC;AAAA,EAC/B,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA,SAAS;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;AAAA,MAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA,UAAU;AAAA,UACV,kBAAkB;AAAA,UAClB,aAAa,eAAe,MAAM,YAAY;AAAA,UAC9C,cAAc,gBAAgB,MAAM,SAAa,IAAA;AAAA,QAAA;AAAA,MACnD;AAAA,MACA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAW,QAAQ;AAAA,UAEnB,iBAAe,mBAAmB,CAAC,GAAG;AAAA,UAErC,UAAA;AAAA,YAAA,iBAAiB,IAAI,eAAe;AAAA,YACpC,SAAS,MAAM,IAAI,kBAAkB;AAAA,UAAA;AAAA,QAAA;AAAA,MACxC;AAAA,IAAA,GACF;AAAA,IAED,gBAAgB,aACf;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,UAAU;AAAA,QACV,kBAAkB;AAAA,QAClB,cAAc,gBAAgB,MAAM,SAAa,IAAA;AAAA,QACjD;AAAA,MAAA;AAAA,IACF;AAAA,EAAA,EAEJ,CAAA,EACF,CAAA;AAEJ;"}
|
|
@@ -7,13 +7,11 @@ const makeUTCDate = (year, monthIndex, day, hour = 1) => new Date(Date.UTC(year,
|
|
|
7
7
|
const isDate = (date) => Object.prototype.toString.call(date) === "[object Date]" && !Number.isNaN(date.valueOf());
|
|
8
8
|
const isDateRangeProp = (date) => "startDate" in date;
|
|
9
9
|
const isSameMonth = (date1, date2) => {
|
|
10
|
-
if (!(isDate(date1) && isDate(date2)))
|
|
11
|
-
return false;
|
|
10
|
+
if (!(isDate(date1) && isDate(date2))) return false;
|
|
12
11
|
return date1.getMonth() === date2.getMonth() && date1.getFullYear() === date2.getFullYear();
|
|
13
12
|
};
|
|
14
13
|
const isSameDay = (date1, date2) => {
|
|
15
|
-
if (!(isDate(date1) && isDate(date2)))
|
|
16
|
-
return false;
|
|
14
|
+
if (!(isDate(date1) && isDate(date2))) return false;
|
|
17
15
|
return date1.getDate() === date2.getDate() && date1.getMonth() === date2.getMonth() && date1.getFullYear() === date2.getFullYear();
|
|
18
16
|
};
|
|
19
17
|
const getPreviousMonth = (month, year) => {
|
|
@@ -68,8 +66,7 @@ const createDatesArray = (month, year) => {
|
|
|
68
66
|
const isRange = (date) => date != null && typeof date === "object" && "startDate" in date;
|
|
69
67
|
const dateInProvidedValueRange = (date, providedValueRange) => {
|
|
70
68
|
const { startDate, endDate } = providedValueRange;
|
|
71
|
-
if (!isRange(providedValueRange) || endDate == null)
|
|
72
|
-
return false;
|
|
69
|
+
if (!isRange(providedValueRange) || endDate == null) return false;
|
|
73
70
|
const localEndDate = endDate;
|
|
74
71
|
const modStartDate = dayjs(startDate).format("YYYY-MM-DD");
|
|
75
72
|
const modEndDate = dayjs(localEndDate).format("YYYY-MM-DD");
|
|
@@ -77,8 +74,7 @@ const dateInProvidedValueRange = (date, providedValueRange) => {
|
|
|
77
74
|
return convertedDate >= modStartDate && convertedDate <= modEndDate;
|
|
78
75
|
};
|
|
79
76
|
const checkIfDateIsDisabled = (date, minimumDate, maximumDate) => {
|
|
80
|
-
if (!minimumDate && !maximumDate)
|
|
81
|
-
return false;
|
|
77
|
+
if (!minimumDate && !maximumDate) return false;
|
|
82
78
|
const modStartDate = minimumDate ? dayjs(minimumDate).format("YYYY-MM-DD") : void 0;
|
|
83
79
|
const modEndDate = maximumDate ? dayjs(maximumDate).format("YYYY-MM-DD") : void 0;
|
|
84
80
|
const convertedDate = dayjs(date).format("YYYY-MM-DD");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/Calendar/utils.tsx"],"sourcesContent":["import dayjs from \"dayjs\";\n\nimport { capitalize } from \"../utils/helpers\";\nimport { DateRangeProp } from \"./types\";\n\n/**\n * Constant with the number of weeks to be displayed on the calendar.\n */\nexport const CALENDAR_WEEKS = 6;\n\n/**\n * Constant with the default locale that should be used as the default.\n */\nexport const DEFAULT_LOCALE = \"en\";\n\n/**\n * Pads a string value with leading zeroes(0) until length is reached.\n *\n * @param value - Value to be padded.\n * @param length - Length of the value after the padding is added.\n * @returns The value as a string with the received amount of padding.\n *\n * @example zeroPad(5, 2) => \"05\"\n */\nexport const zeroPad = (value: number, length: number) =>\n `${value}`.padStart(length, \"0\");\n\n/**\n * Returns the number of days in the month given a month and year.\n *\n * @param month - Number of the month (1 to 12).\n * @param year - Number of the year.\n * @returns The number of days in a month for the received year.\n */\nexport const getMonthDays = (month: number, year: number) =>\n new Date(year, month, 0).getDate();\n\n/**\n * Gets the week day of the first day of a given month and year.\n * From 0 (Sunday) to 6 (Saturday).\n *\n * @param month - Number of the month (1 to 12).\n * @param year - Number of the year.\n * @returns The zero indexed week day where 0 is Sunday (0 to 6).\n */\nexport const getMonthFirstWeekday = (month: number, year: number) =>\n new Date(year, month - 1, 1).getDay();\n\n/**\n * Creates a `Date` instance in UTC timezone.\n *\n * @param year - The year of the date.\n * @param monthIndex - The zero indexed month of the year (0 to 11).\n * @param day - The day of the month.\n * @param [hour=1] - The hour of the day.\n * @returns A `Date` instance in UTC timezone.\n */\nexport const makeUTCDate = (\n year: number,\n monthIndex: number,\n day: number,\n hour = 1,\n) => new Date(Date.UTC(year, monthIndex, day, hour));\n\n/**\n * Checks if the received date is a valid date.\n *\n * @param date - The date to be validated.\n * @returns A flag stating if the date is valid or not.\n */\nexport const isDate = (date: any): date is Date =>\n Object.prototype.toString.call(date) === \"[object Date]\" &&\n !Number.isNaN(date.valueOf());\n\nexport const isDateRangeProp = (date: any): date is DateRangeProp =>\n \"startDate\" in date;\n\n/**\n * Checks if two dates are in the same month and year.\n *\n * @param date1 - First date.\n * @param date2 - Second date.\n * @returns A flag stating if the dates are in the same month and year or not.\n */\nexport const isSameMonth = (date1: any, date2: any) => {\n if (!(isDate(date1) && isDate(date2))) return false;\n\n return (\n date1.getMonth() === date2.getMonth() &&\n date1.getFullYear() === date2.getFullYear()\n );\n};\n\n/**\n * Checks if two dates are on the same day.\n *\n * @param date1 - First date.\n * @param date2 - Second date.\n * @returns A flag stating if the dates are in the same day or not.\n */\nexport const isSameDay = (date1: any, date2: any) => {\n if (!(isDate(date1) && isDate(date2))) return false;\n\n return (\n date1.getDate() === date2.getDate() &&\n date1.getMonth() === date2.getMonth() &&\n date1.getFullYear() === date2.getFullYear()\n );\n};\n\n/**\n * Formats the received date using the ISO format (YYYY-MM-DD).\n *\n * @param date - The date to be formatted.\n * @returns The formatted date in ISO format.\n */\nexport const getDateISO = (date?: Date) => {\n if (!isDate(date)) return null;\n\n return [\n date.getFullYear(),\n zeroPad(date.getMonth() + 1, 2),\n zeroPad(date.getDate(), 2),\n ].join(\"-\");\n};\n\n/**\n * Returns an object with the previous month taking also into consideration the year.\n * For example the previous month of January 2000 will be December 1999.\n *\n * @param month - Number of the month.\n * @param year - Number of the year.\n * @returns Object with new month and year defined.\n */\nexport const getPreviousMonth = (month: number, year: number) => {\n const prevMonth = month > 1 ? month - 1 : 12;\n const prevMonthYear = month > 1 ? year : year - 1;\n\n return { month: prevMonth, year: prevMonthYear };\n};\n\n/**\n * Returns an object with the next month taking also into consideration the year.\n * For example the next month of December 2000 will be January 2001.\n *\n * @param month - Number of the month.\n * @param year - Number of the year.\n * @returns Object with new month and year defined.\n */\nexport const getNextMonth = (month: number, year: number) => {\n const nextMonth = month < 12 ? month + 1 : 1;\n const nextMonthYear = month < 12 ? year : year + 1;\n\n return { month: nextMonth, year: nextMonthYear };\n};\n\n/**\n * Returns a list with the names of all the months localized in the received locale and representation value.\n *\n * @param locale - The locale to be applied to the Intl format.\n * @param representationValue - The representation value for the month.\n * @returns An array with all the months names.\n */\nexport const getMonthNamesList = (\n locale: string | undefined,\n representationValue: Intl.DateTimeFormatOptions[\"month\"] = \"long\",\n) => {\n const options = { month: representationValue, timeZone: \"UTC\" };\n\n return [...new Array(12)].map((n, index) => {\n const auxDate = makeUTCDate(1970, index, 1);\n return capitalize(Intl.DateTimeFormat(locale, options).format(auxDate));\n });\n};\n\n/**\n * Returns a list with the names of all the weekdays localized in the received locale and representation value.\n *\n * @param locale - The locale to be applied.\n * @returns An array with all the weekday names.\n */\nexport const getWeekdayNamesList = (locale: string) => {\n const formatter = new Intl.DateTimeFormat(locale, {\n weekday: \"narrow\",\n timeZone: \"UTC\",\n });\n\n return [...new Array(7)].map((n, index) => {\n return formatter.format(makeUTCDate(1970, 0, 4 + index));\n });\n};\n\n/**\n * Returns the name of the month for the supplied month localized in the received locale and representation value.\n *\n * @param date - The date from which the month name is extracted.\n * @param locale - The locale to be applied to the Intl format.\n * @param representationValue - The locale to be applied to the Intl format.\n * @returns The name of the month.\n */\nexport const getMonthName = (\n date: Date,\n locale: string,\n representationValue: Intl.DateTimeFormatOptions[\"month\"] = \"long\",\n) =>\n new Intl.DateTimeFormat(locale, { month: representationValue }).format(date);\n\n/**\n * Formats the received date according to Design System specifications.\n * Currently: day month, year => `14 Aug, 2019`.\n *\n * @param date - UTC date to be formatted.\n * @param locale - The locale to be applied to the Intl format.\n * @returns The formatted date as a string.\n */\nexport const getFormattedDate = (\n // TODO: fix this\n date: any,\n locale: any,\n rep: Intl.DateTimeFormatOptions[\"month\"] = \"short\",\n) =>\n `${date.getDate()} ${getMonthName(date, locale, rep)} ${date.getFullYear()}`;\n\n/**\n * Creates an array of 42 days. The complete current month and enough days from the previous and next months to fill\n * the 42 positions.\n *\n * @param month - The number of the month (1 to 12).\n * @param year - The number of the year.\n * @returns The array of dates.\n */\nexport const createDatesArray = (month: number, year: number) => {\n // Initializes the variables needed to calculate the dates for the received month and year\n const monthDays = getMonthDays(month, year);\n const daysFromPrevMonth = getMonthFirstWeekday(month, year);\n const daysFromNextMonth =\n CALENDAR_WEEKS * 7 - (daysFromPrevMonth + monthDays);\n const prevMonthYear = getPreviousMonth(month, year);\n const nextMonthYear = getNextMonth(month, year);\n const prevMonthDays = getMonthDays(prevMonthYear.month, prevMonthYear.year);\n\n // Creates the arrays for the dates for previous, current and next months\n const prevMonthDates = [...new Array(daysFromPrevMonth)].map((n, index) => {\n const day = index + 1 + (prevMonthDays - daysFromPrevMonth);\n return new Date(prevMonthYear.year, prevMonthYear.month - 1, day);\n });\n const currentMonthDates = [...new Array(monthDays)].map((n, index) => {\n const day = index + 1;\n return new Date(year, month - 1, day);\n });\n const nextMonthDates = [...new Array(daysFromNextMonth)].map((n, index) => {\n const day = index + 1;\n return new Date(nextMonthYear.year, nextMonthYear.month - 1, day);\n });\n\n return [...prevMonthDates, ...currentMonthDates, ...nextMonthDates];\n};\n\nexport const isRange = (date: any): date is DateRangeProp =>\n date != null && typeof date === \"object\" && \"startDate\" in date;\n\n/**\n * Checks if the date falls within a specified date range.\n *\n * @param date - The date to be evaluated.\n * @param providedValueRange - Provided selection range.\n * @returns - True if the date falls within the range, false otherwise.\n */\nexport const dateInProvidedValueRange = (\n date: any,\n providedValueRange: any,\n) => {\n const { startDate, endDate } = providedValueRange;\n\n if (!isRange(providedValueRange) || endDate == null) return false;\n const localEndDate = endDate;\n\n const modStartDate = dayjs(startDate).format(\"YYYY-MM-DD\");\n const modEndDate = dayjs(localEndDate).format(\"YYYY-MM-DD\");\n\n const convertedDate = dayjs(date).format(\"YYYY-MM-DD\");\n\n return convertedDate >= modStartDate && convertedDate <= modEndDate;\n};\n\nexport const checkIfDateIsDisabled = (\n date?: string | number | Date | dayjs.Dayjs,\n minimumDate?: string | number | Date | dayjs.Dayjs,\n maximumDate?: string | number | Date | dayjs.Dayjs,\n) => {\n if (!minimumDate && !maximumDate) return false;\n const modStartDate = minimumDate\n ? dayjs(minimumDate).format(\"YYYY-MM-DD\")\n : undefined;\n const modEndDate = maximumDate\n ? dayjs(maximumDate).format(\"YYYY-MM-DD\")\n : undefined;\n\n const convertedDate = dayjs(date).format(\"YYYY-MM-DD\");\n\n return (\n (modStartDate !== undefined && convertedDate < modStartDate) ||\n (modEndDate !== undefined && convertedDate > modEndDate)\n );\n};\n\nexport const formatToLocale = (date: any, locale: any) => {\n return new Intl.DateTimeFormat(locale, {\n day: \"numeric\",\n month: \"short\",\n year: \"numeric\",\n }).format(date);\n};\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AgB,gBAC9C,eAAe,UAAa,gBAAgB;AAEjD;AAEa,MAAA,iBAAiB,CAAC,MAAW,WAAgB;AACjD,SAAA,IAAI,KAAK,eAAe,QAAQ;AAAA,IACrC,KAAK;AAAA,IACL,OAAO;AAAA,IACP,MAAM;AAAA,EAAA,CACP,EAAE,OAAO,IAAI;AAChB;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/Calendar/utils.tsx"],"sourcesContent":["import dayjs from \"dayjs\";\n\nimport { capitalize } from \"../utils/helpers\";\nimport { DateRangeProp } from \"./types\";\n\n/**\n * Constant with the number of weeks to be displayed on the calendar.\n */\nexport const CALENDAR_WEEKS = 6;\n\n/**\n * Constant with the default locale that should be used as the default.\n */\nexport const DEFAULT_LOCALE = \"en\";\n\n/**\n * Pads a string value with leading zeroes(0) until length is reached.\n *\n * @param value - Value to be padded.\n * @param length - Length of the value after the padding is added.\n * @returns The value as a string with the received amount of padding.\n *\n * @example zeroPad(5, 2) => \"05\"\n */\nexport const zeroPad = (value: number, length: number) =>\n `${value}`.padStart(length, \"0\");\n\n/**\n * Returns the number of days in the month given a month and year.\n *\n * @param month - Number of the month (1 to 12).\n * @param year - Number of the year.\n * @returns The number of days in a month for the received year.\n */\nexport const getMonthDays = (month: number, year: number) =>\n new Date(year, month, 0).getDate();\n\n/**\n * Gets the week day of the first day of a given month and year.\n * From 0 (Sunday) to 6 (Saturday).\n *\n * @param month - Number of the month (1 to 12).\n * @param year - Number of the year.\n * @returns The zero indexed week day where 0 is Sunday (0 to 6).\n */\nexport const getMonthFirstWeekday = (month: number, year: number) =>\n new Date(year, month - 1, 1).getDay();\n\n/**\n * Creates a `Date` instance in UTC timezone.\n *\n * @param year - The year of the date.\n * @param monthIndex - The zero indexed month of the year (0 to 11).\n * @param day - The day of the month.\n * @param [hour=1] - The hour of the day.\n * @returns A `Date` instance in UTC timezone.\n */\nexport const makeUTCDate = (\n year: number,\n monthIndex: number,\n day: number,\n hour = 1,\n) => new Date(Date.UTC(year, monthIndex, day, hour));\n\n/**\n * Checks if the received date is a valid date.\n *\n * @param date - The date to be validated.\n * @returns A flag stating if the date is valid or not.\n */\nexport const isDate = (date: any): date is Date =>\n Object.prototype.toString.call(date) === \"[object Date]\" &&\n !Number.isNaN(date.valueOf());\n\nexport const isDateRangeProp = (date: any): date is DateRangeProp =>\n \"startDate\" in date;\n\n/**\n * Checks if two dates are in the same month and year.\n *\n * @param date1 - First date.\n * @param date2 - Second date.\n * @returns A flag stating if the dates are in the same month and year or not.\n */\nexport const isSameMonth = (date1: any, date2: any) => {\n if (!(isDate(date1) && isDate(date2))) return false;\n\n return (\n date1.getMonth() === date2.getMonth() &&\n date1.getFullYear() === date2.getFullYear()\n );\n};\n\n/**\n * Checks if two dates are on the same day.\n *\n * @param date1 - First date.\n * @param date2 - Second date.\n * @returns A flag stating if the dates are in the same day or not.\n */\nexport const isSameDay = (date1: any, date2: any) => {\n if (!(isDate(date1) && isDate(date2))) return false;\n\n return (\n date1.getDate() === date2.getDate() &&\n date1.getMonth() === date2.getMonth() &&\n date1.getFullYear() === date2.getFullYear()\n );\n};\n\n/**\n * Formats the received date using the ISO format (YYYY-MM-DD).\n *\n * @param date - The date to be formatted.\n * @returns The formatted date in ISO format.\n */\nexport const getDateISO = (date?: Date) => {\n if (!isDate(date)) return null;\n\n return [\n date.getFullYear(),\n zeroPad(date.getMonth() + 1, 2),\n zeroPad(date.getDate(), 2),\n ].join(\"-\");\n};\n\n/**\n * Returns an object with the previous month taking also into consideration the year.\n * For example the previous month of January 2000 will be December 1999.\n *\n * @param month - Number of the month.\n * @param year - Number of the year.\n * @returns Object with new month and year defined.\n */\nexport const getPreviousMonth = (month: number, year: number) => {\n const prevMonth = month > 1 ? month - 1 : 12;\n const prevMonthYear = month > 1 ? year : year - 1;\n\n return { month: prevMonth, year: prevMonthYear };\n};\n\n/**\n * Returns an object with the next month taking also into consideration the year.\n * For example the next month of December 2000 will be January 2001.\n *\n * @param month - Number of the month.\n * @param year - Number of the year.\n * @returns Object with new month and year defined.\n */\nexport const getNextMonth = (month: number, year: number) => {\n const nextMonth = month < 12 ? month + 1 : 1;\n const nextMonthYear = month < 12 ? year : year + 1;\n\n return { month: nextMonth, year: nextMonthYear };\n};\n\n/**\n * Returns a list with the names of all the months localized in the received locale and representation value.\n *\n * @param locale - The locale to be applied to the Intl format.\n * @param representationValue - The representation value for the month.\n * @returns An array with all the months names.\n */\nexport const getMonthNamesList = (\n locale: string | undefined,\n representationValue: Intl.DateTimeFormatOptions[\"month\"] = \"long\",\n) => {\n const options = { month: representationValue, timeZone: \"UTC\" };\n\n return [...new Array(12)].map((n, index) => {\n const auxDate = makeUTCDate(1970, index, 1);\n return capitalize(Intl.DateTimeFormat(locale, options).format(auxDate));\n });\n};\n\n/**\n * Returns a list with the names of all the weekdays localized in the received locale and representation value.\n *\n * @param locale - The locale to be applied.\n * @returns An array with all the weekday names.\n */\nexport const getWeekdayNamesList = (locale: string) => {\n const formatter = new Intl.DateTimeFormat(locale, {\n weekday: \"narrow\",\n timeZone: \"UTC\",\n });\n\n return [...new Array(7)].map((n, index) => {\n return formatter.format(makeUTCDate(1970, 0, 4 + index));\n });\n};\n\n/**\n * Returns the name of the month for the supplied month localized in the received locale and representation value.\n *\n * @param date - The date from which the month name is extracted.\n * @param locale - The locale to be applied to the Intl format.\n * @param representationValue - The locale to be applied to the Intl format.\n * @returns The name of the month.\n */\nexport const getMonthName = (\n date: Date,\n locale: string,\n representationValue: Intl.DateTimeFormatOptions[\"month\"] = \"long\",\n) =>\n new Intl.DateTimeFormat(locale, { month: representationValue }).format(date);\n\n/**\n * Formats the received date according to Design System specifications.\n * Currently: day month, year => `14 Aug, 2019`.\n *\n * @param date - UTC date to be formatted.\n * @param locale - The locale to be applied to the Intl format.\n * @returns The formatted date as a string.\n */\nexport const getFormattedDate = (\n // TODO: fix this\n date: any,\n locale: any,\n rep: Intl.DateTimeFormatOptions[\"month\"] = \"short\",\n) =>\n `${date.getDate()} ${getMonthName(date, locale, rep)} ${date.getFullYear()}`;\n\n/**\n * Creates an array of 42 days. The complete current month and enough days from the previous and next months to fill\n * the 42 positions.\n *\n * @param month - The number of the month (1 to 12).\n * @param year - The number of the year.\n * @returns The array of dates.\n */\nexport const createDatesArray = (month: number, year: number) => {\n // Initializes the variables needed to calculate the dates for the received month and year\n const monthDays = getMonthDays(month, year);\n const daysFromPrevMonth = getMonthFirstWeekday(month, year);\n const daysFromNextMonth =\n CALENDAR_WEEKS * 7 - (daysFromPrevMonth + monthDays);\n const prevMonthYear = getPreviousMonth(month, year);\n const nextMonthYear = getNextMonth(month, year);\n const prevMonthDays = getMonthDays(prevMonthYear.month, prevMonthYear.year);\n\n // Creates the arrays for the dates for previous, current and next months\n const prevMonthDates = [...new Array(daysFromPrevMonth)].map((n, index) => {\n const day = index + 1 + (prevMonthDays - daysFromPrevMonth);\n return new Date(prevMonthYear.year, prevMonthYear.month - 1, day);\n });\n const currentMonthDates = [...new Array(monthDays)].map((n, index) => {\n const day = index + 1;\n return new Date(year, month - 1, day);\n });\n const nextMonthDates = [...new Array(daysFromNextMonth)].map((n, index) => {\n const day = index + 1;\n return new Date(nextMonthYear.year, nextMonthYear.month - 1, day);\n });\n\n return [...prevMonthDates, ...currentMonthDates, ...nextMonthDates];\n};\n\nexport const isRange = (date: any): date is DateRangeProp =>\n date != null && typeof date === \"object\" && \"startDate\" in date;\n\n/**\n * Checks if the date falls within a specified date range.\n *\n * @param date - The date to be evaluated.\n * @param providedValueRange - Provided selection range.\n * @returns - True if the date falls within the range, false otherwise.\n */\nexport const dateInProvidedValueRange = (\n date: any,\n providedValueRange: any,\n) => {\n const { startDate, endDate } = providedValueRange;\n\n if (!isRange(providedValueRange) || endDate == null) return false;\n const localEndDate = endDate;\n\n const modStartDate = dayjs(startDate).format(\"YYYY-MM-DD\");\n const modEndDate = dayjs(localEndDate).format(\"YYYY-MM-DD\");\n\n const convertedDate = dayjs(date).format(\"YYYY-MM-DD\");\n\n return convertedDate >= modStartDate && convertedDate <= modEndDate;\n};\n\nexport const checkIfDateIsDisabled = (\n date?: string | number | Date | dayjs.Dayjs,\n minimumDate?: string | number | Date | dayjs.Dayjs,\n maximumDate?: string | number | Date | dayjs.Dayjs,\n) => {\n if (!minimumDate && !maximumDate) return false;\n const modStartDate = minimumDate\n ? dayjs(minimumDate).format(\"YYYY-MM-DD\")\n : undefined;\n const modEndDate = maximumDate\n ? dayjs(maximumDate).format(\"YYYY-MM-DD\")\n : undefined;\n\n const convertedDate = dayjs(date).format(\"YYYY-MM-DD\");\n\n return (\n (modStartDate !== undefined && convertedDate < modStartDate) ||\n (modEndDate !== undefined && convertedDate > modEndDate)\n );\n};\n\nexport const formatToLocale = (date: any, locale: any) => {\n return new Intl.DateTimeFormat(locale, {\n day: \"numeric\",\n month: \"short\",\n year: \"numeric\",\n }).format(date);\n};\n"],"names":[],"mappings":";;AAQO,MAAM,iBAAiB;AA0BjB,MAAA,eAAe,CAAC,OAAe,SAC1C,IAAI,KAAK,MAAM,OAAO,CAAC,EAAE,QAAQ;AAUtB,MAAA,uBAAuB,CAAC,OAAe,SAClD,IAAI,KAAK,MAAM,QAAQ,GAAG,CAAC,EAAE,OAAO;AAW/B,MAAM,cAAc,CACzB,MACA,YACA,KACA,OAAO,MACJ,IAAI,KAAK,KAAK,IAAI,MAAM,YAAY,KAAK,IAAI,CAAC;AAQ5C,MAAM,SAAS,CAAC,SACrB,OAAO,UAAU,SAAS,KAAK,IAAI,MAAM,mBACzC,CAAC,OAAO,MAAM,KAAK,SAAS;AAEjB,MAAA,kBAAkB,CAAC,SAC9B,eAAe;AASJ,MAAA,cAAc,CAAC,OAAY,UAAe;AACrD,MAAI,EAAE,OAAO,KAAK,KAAK,OAAO,KAAK,GAAW,QAAA;AAG5C,SAAA,MAAM,eAAe,MAAM,SAAA,KAC3B,MAAM,YAAkB,MAAA,MAAM;AAElC;AASa,MAAA,YAAY,CAAC,OAAY,UAAe;AACnD,MAAI,EAAE,OAAO,KAAK,KAAK,OAAO,KAAK,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AAW,KAAa,QAAA;AAC5D,QAAM,eAAe;AAErB,QAAM,eAAe,MAAM,SAAS,EAAE,OAAO,YAAY;AACzD,QAAM,aAAa,MAAM,YAAY,EAAE,OAAO,YAAY;AAE1D,QAAM,gBAAgB,MAAM,IAAI,EAAE,OAAO,YAAY;AAE9C,SAAA,iBAAiB,gBAAgB,iBAAiB;AAC3D;AAEO,MAAM,wBAAwB,CACnC,MACA,aACA,gBACG;AACH,MAAI,CAAC,eAAe,CAAC,YAAoB,QAAA;AACzC,QAAM,eAAe,cACjB,MAAM,WAAW,EAAE,OAAO,YAAY,IACtC;AACJ,QAAM,aAAa,cACf,MAAM,WAAW,EAAE,OAAO,YAAY,IACtC;AAEJ,QAAM,gBAAgB,MAAM,IAAI,EAAE,OAAO,YAAY;AAErD,SACG,iBAAiB,UAAa,gBAAgB,gBAC9C,eAAe,UAAa,gBAAgB;AAEjD;AAEa,MAAA,iBAAiB,CAAC,MAAW,WAAgB;AACjD,SAAA,IAAI,KAAK,eAAe,QAAQ;AAAA,IACrC,KAAK;AAAA,IACL,OAAO;AAAA,IACP,MAAM;AAAA,EAAA,CACP,EAAE,OAAO,IAAI;AAChB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Card.js","sources":["../../../src/Card/Card.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Card.js","sources":["../../../src/Card/Card.tsx"],"sourcesContent":["import {\n getColor,\n HvColor,\n HvColorAny,\n theme,\n} from \"@hitachivantara/uikit-styles\";\n\nimport { useDefaultProps } from \"../hooks/useDefaultProps\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { ExtractNames } from \"../utils/classes\";\nimport { staticClasses, useClasses } from \"./Card.styles\";\n\nexport { staticClasses as cardClasses };\n\nexport type HvCardClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvCardProps extends HvBaseProps {\n /** The renderable content inside the icon slot of the header. */\n icon?: React.ReactNode;\n /** Whether the card is selectable. */\n selectable?: boolean;\n /** Whether the card is currently selected. */\n selected?: boolean;\n /** The background color of the card. */\n bgcolor?: \"sema0\" | HvColorAny;\n /**\n * The border color at the top of the card. Must be one of palette semantic or atmosphere colors.\n * To set another color, the borderTop should be override.\n */\n statusColor?: \"sema0\" | HvColorAny;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvCardClasses;\n}\n\n/**\n * A card is a container for a few short and related pieces of content.\n * It roughly resembles a playing card in size and shape and is intended as a\n * linked short representation of a conceptual unit. For that reason,\n * this pattern must be used as an entry-point for further information.\n */\nexport const HvCard = (props: HvCardProps) => {\n const {\n classes: classesProp,\n className,\n children,\n icon,\n selectable = false,\n selected = false,\n statusColor = \"sema0\",\n bgcolor,\n ...others\n } = useDefaultProps(\"HvCard\", props);\n\n const { classes, css, cx } = useClasses(classesProp);\n\n return (\n <div\n className={cx(\n \"HvIsCardGridElement\",\n classes.root,\n css({\n backgroundColor: getColor(bgcolor),\n }),\n {\n [classes.selectable]: selectable,\n [classes.selected]: selected,\n },\n className,\n )}\n {...others}\n >\n <div className={classes.semanticContainer}>\n <div\n className={cx(\n css({\n height: selected ? 4 : 2,\n backgroundColor:\n statusColor === \"sema0\"\n ? selected\n ? theme.colors.secondary\n : theme.colors.atmo4\n : theme.colors[statusColor as HvColor],\n }),\n classes.semanticBar,\n )}\n />\n <div className={classes.icon}>{icon}</div>\n </div>\n {children}\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;AAwCa,MAAA,SAAS,CAAC,UAAuB;AACtC,QAAA;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,WAAW;AAAA,IACX,cAAc;AAAA,IACd;AAAA,IACA,GAAG;AAAA,EAAA,IACD,gBAAgB,UAAU,KAAK;AAEnC,QAAM,EAAE,SAAS,KAAK,GAAG,IAAI,WAAW,WAAW;AAGjD,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAW;AAAA,QACT;AAAA,QACA,QAAQ;AAAA,QACR,IAAI;AAAA,UACF,iBAAiB,SAAS,OAAO;AAAA,QAAA,CAClC;AAAA,QACD;AAAA,UACE,CAAC,QAAQ,UAAU,GAAG;AAAA,UACtB,CAAC,QAAQ,QAAQ,GAAG;AAAA,QACtB;AAAA,QACA;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEJ,UAAA;AAAA,QAAC,qBAAA,OAAA,EAAI,WAAW,QAAQ,mBACtB,UAAA;AAAA,UAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,WAAW;AAAA,gBACT,IAAI;AAAA,kBACF,QAAQ,WAAW,IAAI;AAAA,kBACvB,iBACE,gBAAgB,UACZ,WACE,MAAM,OAAO,YACb,MAAM,OAAO,QACf,MAAM,OAAO,WAAsB;AAAA,gBAAA,CAC1C;AAAA,gBACD,QAAQ;AAAA,cACV;AAAA,YAAA;AAAA,UACF;AAAA,UACC,oBAAA,OAAA,EAAI,WAAW,QAAQ,MAAO,UAAK,MAAA;AAAA,QAAA,GACtC;AAAA,QACC;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGP;"}
|
|
@@ -3,6 +3,7 @@ import { useRef, useState, Children, useCallback, useEffect } from "react";
|
|
|
3
3
|
import useCarousel from "embla-carousel-react";
|
|
4
4
|
import { Close, Fullscreen, Backwards, Forwards } from "@hitachivantara/uikit-react-icons";
|
|
5
5
|
import { useDefaultProps } from "../hooks/useDefaultProps.js";
|
|
6
|
+
import { useLabels } from "../hooks/useLabels.js";
|
|
6
7
|
import { useTheme } from "../hooks/useTheme.js";
|
|
7
8
|
import { clamp } from "../utils/helpers.js";
|
|
8
9
|
import { useClasses } from "./Carousel.styles.js";
|
|
@@ -13,6 +14,12 @@ import { HvContainer } from "../Container/Container.js";
|
|
|
13
14
|
import { HvButton } from "../Button/Button.js";
|
|
14
15
|
import { HvIconButton } from "../IconButton/IconButton.js";
|
|
15
16
|
import { HvTypography } from "../Typography/Typography.js";
|
|
17
|
+
const DEFAULT_LABELS = {
|
|
18
|
+
close: "Close",
|
|
19
|
+
fullscreen: "Fullscreen",
|
|
20
|
+
backwards: "Backwards",
|
|
21
|
+
forwards: "Forwards"
|
|
22
|
+
};
|
|
16
23
|
const HvCarousel = (props) => {
|
|
17
24
|
const {
|
|
18
25
|
className,
|
|
@@ -30,13 +37,16 @@ const HvCarousel = (props) => {
|
|
|
30
37
|
hideThumbnails: hideThumbnailsProp,
|
|
31
38
|
controlsPosition: controlsPositionProp,
|
|
32
39
|
thumbnailsPosition: thumbnailsPositionProp,
|
|
40
|
+
labels: labelsProps,
|
|
33
41
|
carouselOptions,
|
|
34
42
|
renderThumbnail,
|
|
35
43
|
onChange,
|
|
44
|
+
onFullscreen,
|
|
36
45
|
...others
|
|
37
46
|
} = useDefaultProps("HvCarousel", props);
|
|
38
47
|
const { activeTheme } = useTheme();
|
|
39
48
|
const { classes, css, cx } = useClasses(classesProp);
|
|
49
|
+
const labels = useLabels(DEFAULT_LABELS, labelsProps);
|
|
40
50
|
const thumbnailsRef = useRef(null);
|
|
41
51
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
42
52
|
const isDs3 = activeTheme?.name === "ds3";
|
|
@@ -62,8 +72,7 @@ const HvCarousel = (props) => {
|
|
|
62
72
|
controller?.scrollTo(index);
|
|
63
73
|
};
|
|
64
74
|
const handleSelect = useCallback(() => {
|
|
65
|
-
if (!controller)
|
|
66
|
-
return;
|
|
75
|
+
if (!controller) return;
|
|
67
76
|
const slideIndex = controller.selectedScrollSnap();
|
|
68
77
|
setSelectedIndex(slideIndex);
|
|
69
78
|
thumbnailsRef.current?.querySelectorAll("button")?.[slideIndex]?.scrollIntoView({
|
|
@@ -73,19 +82,21 @@ const HvCarousel = (props) => {
|
|
|
73
82
|
onChange?.(slideIndex);
|
|
74
83
|
}, [controller, onChange]);
|
|
75
84
|
useEffect(() => {
|
|
76
|
-
if (!controller)
|
|
77
|
-
return;
|
|
85
|
+
if (!controller) return;
|
|
78
86
|
controller.on("select", handleSelect);
|
|
79
87
|
return () => {
|
|
80
88
|
controller.off("select", handleSelect);
|
|
81
89
|
};
|
|
82
90
|
}, [controller, handleSelect]);
|
|
83
91
|
useEffect(() => {
|
|
84
|
-
if (!controller)
|
|
85
|
-
return;
|
|
92
|
+
if (!controller) return;
|
|
86
93
|
controller.reInit();
|
|
87
94
|
setSelectedIndex((currentIndex) => clamp(currentIndex, numSlides));
|
|
88
95
|
}, [numSlides, controller]);
|
|
96
|
+
const handleFullscreen = (event) => {
|
|
97
|
+
onFullscreen?.(event, !isFullscreen);
|
|
98
|
+
setIsFullscreen((curr) => !curr);
|
|
99
|
+
};
|
|
89
100
|
const canPrev = controller?.canScrollPrev() ?? false;
|
|
90
101
|
const canNext = controller?.canScrollNext() ?? false;
|
|
91
102
|
const showTitle = !!title && (!xs || isFullscreen);
|
|
@@ -107,8 +118,8 @@ const HvCarousel = (props) => {
|
|
|
107
118
|
showFullscreen && /* @__PURE__ */ jsx(
|
|
108
119
|
HvIconButton,
|
|
109
120
|
{
|
|
110
|
-
title: isFullscreen ?
|
|
111
|
-
onClick:
|
|
121
|
+
title: isFullscreen ? labels.close : labels.fullscreen,
|
|
122
|
+
onClick: handleFullscreen,
|
|
112
123
|
className: classes.closeButton,
|
|
113
124
|
children: isFullscreen ? /* @__PURE__ */ jsx(Close, {}) : /* @__PURE__ */ jsx(Fullscreen, {})
|
|
114
125
|
}
|
|
@@ -127,7 +138,11 @@ const HvCarousel = (props) => {
|
|
|
127
138
|
canNext,
|
|
128
139
|
onPreviousClick: handlePrevious,
|
|
129
140
|
onNextClick: handleNext,
|
|
130
|
-
actions: actionsPosition === "controls" && actions
|
|
141
|
+
actions: actionsPosition === "controls" && actions,
|
|
142
|
+
labels: {
|
|
143
|
+
backwards: labels.backwards,
|
|
144
|
+
forwards: labels.forwards
|
|
145
|
+
}
|
|
131
146
|
}
|
|
132
147
|
);
|
|
133
148
|
const thumbnails = showThumbnails && /* @__PURE__ */ jsx(
|
|
@@ -171,7 +186,7 @@ const HvCarousel = (props) => {
|
|
|
171
186
|
icon: true,
|
|
172
187
|
disabled: !canPrev,
|
|
173
188
|
variant: "secondarySubtle",
|
|
174
|
-
"aria-label":
|
|
189
|
+
"aria-label": labels.backwards,
|
|
175
190
|
onClick: handlePrevious,
|
|
176
191
|
children: /* @__PURE__ */ jsx(Backwards, { iconSize: "XS" })
|
|
177
192
|
}
|
|
@@ -182,7 +197,7 @@ const HvCarousel = (props) => {
|
|
|
182
197
|
icon: true,
|
|
183
198
|
disabled: !canNext,
|
|
184
199
|
variant: "secondarySubtle",
|
|
185
|
-
"aria-label":
|
|
200
|
+
"aria-label": labels.forwards,
|
|
186
201
|
onClick: handleNext,
|
|
187
202
|
children: /* @__PURE__ */ jsx(Forwards, { iconSize: "XS" })
|
|
188
203
|
}
|