@hitachivantara/uikit-react-core 5.72.0 → 5.73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/cjs/Button/Button.cjs +1 -0
  2. package/dist/cjs/Header/Actions/Actions.cjs +4 -3
  3. package/dist/cjs/Header/Brand/Brand.cjs +4 -3
  4. package/dist/cjs/Header/Navigation/MenuItem/MenuItem.cjs +13 -28
  5. package/dist/cjs/Header/Navigation/MenuItem/MenuItem.styles.cjs +11 -43
  6. package/dist/cjs/Header/Navigation/Navigation.cjs +4 -3
  7. package/dist/cjs/Pagination/Pagination.cjs +7 -7
  8. package/dist/cjs/SimpleGrid/SimpleGrid.cjs +2 -2
  9. package/dist/cjs/SimpleGrid/SimpleGrid.styles.cjs +17 -22
  10. package/dist/cjs/TableSection/TableSection.styles.cjs +1 -1
  11. package/dist/cjs/TimeAgo/TimeAgo.cjs +1 -2
  12. package/dist/cjs/TimeAgo/formatUtils.cjs +65 -98
  13. package/dist/cjs/TimeAgo/useTimeAgo.cjs +7 -5
  14. package/dist/esm/Button/Button.js +1 -0
  15. package/dist/esm/Button/Button.js.map +1 -1
  16. package/dist/esm/Header/Actions/Actions.js +4 -3
  17. package/dist/esm/Header/Actions/Actions.js.map +1 -1
  18. package/dist/esm/Header/Brand/Brand.js +4 -3
  19. package/dist/esm/Header/Brand/Brand.js.map +1 -1
  20. package/dist/esm/Header/Navigation/MenuItem/MenuItem.js +13 -28
  21. package/dist/esm/Header/Navigation/MenuItem/MenuItem.js.map +1 -1
  22. package/dist/esm/Header/Navigation/MenuItem/MenuItem.styles.js +11 -43
  23. package/dist/esm/Header/Navigation/MenuItem/MenuItem.styles.js.map +1 -1
  24. package/dist/esm/Header/Navigation/Navigation.js +4 -3
  25. package/dist/esm/Header/Navigation/Navigation.js.map +1 -1
  26. package/dist/esm/Pagination/Pagination.js +7 -5
  27. package/dist/esm/Pagination/Pagination.js.map +1 -1
  28. package/dist/esm/SimpleGrid/SimpleGrid.js +2 -2
  29. package/dist/esm/SimpleGrid/SimpleGrid.js.map +1 -1
  30. package/dist/esm/SimpleGrid/SimpleGrid.styles.js +17 -22
  31. package/dist/esm/SimpleGrid/SimpleGrid.styles.js.map +1 -1
  32. package/dist/esm/TableSection/TableSection.styles.js +1 -1
  33. package/dist/esm/TimeAgo/TimeAgo.js +1 -2
  34. package/dist/esm/TimeAgo/TimeAgo.js.map +1 -1
  35. package/dist/esm/TimeAgo/formatUtils.js +66 -91
  36. package/dist/esm/TimeAgo/formatUtils.js.map +1 -1
  37. package/dist/esm/TimeAgo/useTimeAgo.js +7 -5
  38. package/dist/esm/TimeAgo/useTimeAgo.js.map +1 -1
  39. package/dist/esm/TreeView/TreeItem/useHvTreeItem.js.map +1 -1
  40. package/dist/types/index.d.ts +75 -81
  41. package/package.json +6 -6
@@ -83,6 +83,7 @@ const HvButton = generic.fixedForwardRef(function HvButton2(props, ref) {
83
83
  sizeStyles && css(sizeStyles),
84
84
  className
85
85
  ),
86
+ "data-color": color,
86
87
  onClick: handleClick,
87
88
  onMouseDown: handleMouseDown,
88
89
  ...Component === "button" && { type: "button" },
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
4
5
  const uikitReactUtils = require("@hitachivantara/uikit-react-utils");
5
6
  const Actions_styles = require("./Actions.styles.cjs");
6
- const HvHeaderActions = (props) => {
7
+ const HvHeaderActions = React.forwardRef((props, ref) => {
7
8
  const {
8
9
  classes: classesProp,
9
10
  className,
@@ -11,7 +12,7 @@ const HvHeaderActions = (props) => {
11
12
  ...others
12
13
  } = uikitReactUtils.useDefaultProps("HvHeaderActions", props);
13
14
  const { classes, cx } = Actions_styles.useClasses(classesProp);
14
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cx(classes.root, className), ...others, children });
15
- };
15
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cx(classes.root, className), ...others, children });
16
+ });
16
17
  exports.headerActionsClasses = Actions_styles.staticClasses;
17
18
  exports.HvHeaderActions = HvHeaderActions;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
4
5
  const uikitReactUtils = require("@hitachivantara/uikit-react-utils");
5
6
  const Brand_styles = require("./Brand.styles.cjs");
6
7
  const Typography = require("../../Typography/Typography.cjs");
7
- const HvHeaderBrand = (props) => {
8
+ const HvHeaderBrand = React.forwardRef((props, ref) => {
8
9
  const {
9
10
  classes: classesProp,
10
11
  logo,
@@ -13,11 +14,11 @@ const HvHeaderBrand = (props) => {
13
14
  ...others
14
15
  } = uikitReactUtils.useDefaultProps("HvHeaderBrand", props);
15
16
  const { classes, cx } = Brand_styles.useClasses(classesProp);
16
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx(classes.root, className), ...others, children: [
17
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref, className: cx(classes.root, className), ...others, children: [
17
18
  logo,
18
19
  logo && name && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.separator }),
19
20
  name && /* @__PURE__ */ jsxRuntime.jsx(Typography.HvTypography, { className: classes.brandName, variant: "label", children: name })
20
21
  ] });
21
- };
22
+ });
22
23
  exports.headerBrandClasses = Brand_styles.staticClasses;
23
24
  exports.HvHeaderBrand = HvHeaderBrand;
@@ -59,11 +59,6 @@ const HvHeaderMenuItem = (props) => {
59
59
  const handleFocus = (event) => {
60
60
  dispatch?.({ type: "setItemFocused", itemFocused: event.currentTarget });
61
61
  };
62
- const itemProps = {
63
- onClick: actionHandler,
64
- onKeyDown: actionHandler,
65
- onFocus: handleFocus
66
- };
67
62
  const label = /* @__PURE__ */ jsxRuntime.jsx(
68
63
  Typography.HvTypography,
69
64
  {
@@ -80,6 +75,8 @@ const HvHeaderMenuItem = (props) => {
80
75
  itemHref = href;
81
76
  itemTarget = target;
82
77
  }
78
+ const ItemComponent = itemHref ? "a" : "div";
79
+ const itemProps = itemHref ? { href: itemHref, target: itemTarget, "aria-label": item.label } : { role: "button", tabIndex: 0 };
83
80
  return /* @__PURE__ */ jsxRuntime.jsxs(
84
81
  "li",
85
82
  {
@@ -94,31 +91,20 @@ const HvHeaderMenuItem = (props) => {
94
91
  className
95
92
  ),
96
93
  children: [
97
- itemHref ? /* @__PURE__ */ jsxRuntime.jsx(
98
- "a",
94
+ /* @__PURE__ */ jsxRuntime.jsx(
95
+ ItemComponent,
99
96
  {
100
- className: classes.link,
101
- href: itemHref,
102
- target: itemTarget,
103
- ...itemProps,
97
+ className: cx(classes.item, {
98
+ [classes.link]: itemHref,
99
+ [classes.button]: !itemHref
100
+ }),
101
+ onFocus: handleFocus,
102
+ onClick: actionHandler,
103
+ onKeyDown: actionHandler,
104
104
  "aria-current": isCurrent,
105
- "aria-label": item.label,
105
+ ...itemProps,
106
106
  children: label
107
107
  }
108
- ) : (
109
- // keeping this code path for backwards compatibility, but
110
- // shouldn't really be used as it's not accessible
111
- /* @__PURE__ */ jsxRuntime.jsx(
112
- "div",
113
- {
114
- className: classes.button,
115
- role: "button",
116
- ...itemProps,
117
- tabIndex: 0,
118
- "aria-current": isCurrent,
119
- children: label
120
- }
121
- )
122
108
  ),
123
109
  hasSubLevel && currentLevel < levels && currentLevel < 2 && /* @__PURE__ */ jsxRuntime.jsx(Bar.Bar, { data, type: "menu", children: data.map((itm) => /* @__PURE__ */ jsxRuntime.jsx(
124
110
  HvHeaderMenuItem,
@@ -132,8 +118,7 @@ const HvHeaderMenuItem = (props) => {
132
118
  itm.id
133
119
  )) })
134
120
  ]
135
- },
136
- item.label
121
+ }
137
122
  );
138
123
  };
139
124
  exports.headerMenuItemClasses = MenuItem_styles.staticClasses;
@@ -21,6 +21,7 @@ const item = {
21
21
  },
22
22
  "& span": {
23
23
  display: "inline-flex",
24
+ color: "inherit",
24
25
  flexDirection: "column",
25
26
  alignItems: "center",
26
27
  justifyContent: "space-between"
@@ -43,57 +44,24 @@ const { staticClasses, useClasses } = uikitReactUtils.createClasses(
43
44
  {
44
45
  root: {
45
46
  display: "inline",
46
- "&:hover": {
47
- backgroundColor: uikitStyles.theme.colors.containerBackgroundHover
48
- },
49
- "&:focus-within": {
47
+ height: "100%",
48
+ borderBottom: "4px solid transparent",
49
+ ":hover, :focus-within": {
50
50
  backgroundColor: uikitStyles.theme.colors.containerBackgroundHover
51
51
  }
52
52
  },
53
- menu: {
54
- marginTop: 0,
55
- paddingBottom: "4px",
56
- paddingTop: "4px",
57
- height: "100%",
58
- borderTop: "none",
59
- borderBottom: `4px solid ${uikitStyles.theme.colors.atmo2}`
60
- },
61
- menubar: {
62
- marginTop: "0px",
63
- paddingBottom: "4px",
64
- paddingTop: "4px",
65
- height: "100%",
66
- borderTop: `0px solid ${uikitStyles.theme.colors.atmo1}`,
67
- borderBottom: `${"4px"} solid ${uikitStyles.theme.colors.atmo1}`
68
- },
53
+ menu: {},
54
+ menubar: {},
69
55
  selected: {
70
- "&$menu": {
71
- marginTop: 0,
72
- paddingBottom: 0,
73
- borderTop: "none",
74
- borderBottom: `4px solid ${uikitStyles.theme.colors.secondary}`,
75
- paddingTop: "4px",
76
- height: "100%",
77
- "& > * > span": {
78
- color: uikitStyles.theme.colors.secondary
79
- }
80
- },
81
- "&$menubar": {
82
- marginTop: 0,
83
- paddingBottom: 0,
84
- borderTop: "none",
85
- borderBottom: `4px solid ${uikitStyles.theme.colors.secondary}`,
86
- paddingTop: "4px",
87
- height: "100%"
88
- }
56
+ borderColor: uikitStyles.theme.colors.secondary,
57
+ color: uikitStyles.theme.colors.secondary
89
58
  },
59
+ item,
90
60
  link: {
91
- textDecoration: "none",
92
- ...item
61
+ textDecoration: "none"
93
62
  },
94
63
  button: {
95
- color: "inherit",
96
- ...item
64
+ color: "inherit"
97
65
  }
98
66
  }
99
67
  );
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
4
5
  const uikitReactUtils = require("@hitachivantara/uikit-react-utils");
5
6
  const Navigation_styles = require("./Navigation.styles.cjs");
6
7
  const useSelectionPath = require("./useSelectionPath.cjs");
7
8
  const FocusContext = require("./utils/FocusContext.cjs");
8
9
  const SelectionContext = require("./utils/SelectionContext.cjs");
9
10
  const MenuBar = require("./MenuBar/MenuBar.cjs");
10
- const HvHeaderNavigation = (props) => {
11
+ const HvHeaderNavigation = React.forwardRef((props, ref) => {
11
12
  const {
12
13
  data,
13
14
  selected,
@@ -23,7 +24,7 @@ const HvHeaderNavigation = (props) => {
23
24
  event.preventDefault();
24
25
  onClick?.(event, selection);
25
26
  };
26
- return /* @__PURE__ */ jsxRuntime.jsx(SelectionContext.SelectionContext.Provider, { value: selectionPath, children: /* @__PURE__ */ jsxRuntime.jsx(FocusContext.FocusProvider, { children: /* @__PURE__ */ jsxRuntime.jsx("nav", { className: cx(classes.root, className), ...others, children: /* @__PURE__ */ jsxRuntime.jsx(
27
+ return /* @__PURE__ */ jsxRuntime.jsx(SelectionContext.SelectionContext.Provider, { value: selectionPath, children: /* @__PURE__ */ jsxRuntime.jsx(FocusContext.FocusProvider, { children: /* @__PURE__ */ jsxRuntime.jsx("nav", { ref, className: cx(classes.root, className), ...others, children: /* @__PURE__ */ jsxRuntime.jsx(
27
28
  MenuBar.HvHeaderMenuBar,
28
29
  {
29
30
  data,
@@ -33,6 +34,6 @@ const HvHeaderNavigation = (props) => {
33
34
  currentLevel: 1
34
35
  }
35
36
  ) }) }) });
36
- };
37
+ });
37
38
  exports.headerNavigationClasses = Navigation_styles.staticClasses;
38
39
  exports.HvHeaderNavigation = HvHeaderNavigation;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
- const Hidden = require("@mui/material/Hidden");
5
+ const material = require("@mui/material");
6
6
  const uikitReactIcons = require("@hitachivantara/uikit-react-icons");
7
7
  const uikitReactUtils = require("@hitachivantara/uikit-react-utils");
8
8
  const useLabels = require("../hooks/useLabels.cjs");
@@ -12,8 +12,6 @@ const Select = require("./Select.cjs");
12
12
  const Typography = require("../Typography/Typography.cjs");
13
13
  const IconButton = require("../IconButton/IconButton.cjs");
14
14
  const Input = require("../Input/Input.cjs");
15
- const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
16
- const Hidden__default = /* @__PURE__ */ _interopDefault(Hidden);
17
15
  const defaultPageSizeOptions = [5, 10, 20, 25, 50, 100];
18
16
  const DEFAULT_LABELS = {
19
17
  /** The show label. */
@@ -66,6 +64,8 @@ const HvPagination = (props) => {
66
64
  } = uikitReactUtils.useDefaultProps("HvPagination", props);
67
65
  const { classes, cx } = Pagination_styles.useClasses(classesProp);
68
66
  const labels = useLabels.useLabels(DEFAULT_LABELS, labelsProp);
67
+ const muiTheme = material.useTheme();
68
+ const isXsDown = material.useMediaQuery(muiTheme.breakpoints.down("xs"));
69
69
  const [pageInput, setPageInput] = React.useState(page);
70
70
  const changePage = React.useCallback(
71
71
  (newPage) => {
@@ -109,14 +109,14 @@ const HvPagination = (props) => {
109
109
  ) });
110
110
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { id, className: cx(classes.root, className), ...others, children: [
111
111
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.pageSizeOptions, ...showPageProps, children: showPageSizeOptions && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
112
- /* @__PURE__ */ jsxRuntime.jsx(Hidden__default.default, { xsDown: true, children: /* @__PURE__ */ jsxRuntime.jsx(
112
+ !isXsDown && /* @__PURE__ */ jsxRuntime.jsx(
113
113
  Typography.HvTypography,
114
114
  {
115
115
  component: "span",
116
116
  className: classes?.pageSizeTextContainer,
117
117
  children: labels?.pageSizePrev
118
118
  }
119
- ) }),
119
+ ),
120
120
  /* @__PURE__ */ jsxRuntime.jsx(
121
121
  Select.default,
122
122
  {
@@ -133,14 +133,14 @@ const HvPagination = (props) => {
133
133
  children: pageSizeOptions.map((option) => /* @__PURE__ */ jsxRuntime.jsx(Select.Option, { value: option, children: option }, option))
134
134
  }
135
135
  ),
136
- /* @__PURE__ */ jsxRuntime.jsx(Hidden__default.default, { xsDown: true, children: /* @__PURE__ */ jsxRuntime.jsx(
136
+ !isXsDown && /* @__PURE__ */ jsxRuntime.jsx(
137
137
  Typography.HvTypography,
138
138
  {
139
139
  component: "span",
140
140
  className: classes.pageSizeTextContainer,
141
141
  children: labels?.pageSizeEntryName
142
142
  }
143
- ) })
143
+ )
144
144
  ] }) }),
145
145
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.pageNavigator, ...navigationProps, children: [
146
146
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -7,14 +7,14 @@ const HvSimpleGrid = (props) => {
7
7
  const {
8
8
  children,
9
9
  breakpoints,
10
- spacing = "sm",
10
+ spacing,
11
11
  cols,
12
12
  className,
13
13
  classes: classesProp,
14
14
  ...others
15
15
  } = uikitReactUtils.useDefaultProps("HvSimpleGrid", props);
16
16
  const { classes, cx, css } = SimpleGrid_styles.useClasses(classesProp);
17
- const containerStyle = SimpleGrid_styles.getContainerStyle({ breakpoints, spacing, cols });
17
+ const containerStyle = SimpleGrid_styles.getContainerStyle(breakpoints, spacing, cols);
18
18
  return /* @__PURE__ */ jsxRuntime.jsx(
19
19
  "div",
20
20
  {
@@ -3,13 +3,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const uikitReactUtils = require("@hitachivantara/uikit-react-utils");
4
4
  const uikitStyles = require("@hitachivantara/uikit-styles");
5
5
  const { staticClasses, useClasses } = uikitReactUtils.createClasses("HvSimpleGrid", {
6
- root: {}
7
- });
8
- function size(props) {
9
- if (typeof props.size === "number") {
10
- return props.size;
6
+ root: {
7
+ display: "grid",
8
+ boxSizing: "border-box",
9
+ gridTemplateColumns: `repeat(var(--cols, 1), minmax(0, 1fr))`
11
10
  }
12
- return props.sizes[props.size] || props.size || props.sizes.md;
11
+ });
12
+ function getSize(size) {
13
+ return size || Number(uikitStyles.theme.breakpoints.values.md);
13
14
  }
14
15
  function getSortedBreakpoints(breakpoints) {
15
16
  if (breakpoints.length === 0) {
@@ -17,29 +18,23 @@ function getSortedBreakpoints(breakpoints) {
17
18
  }
18
19
  const property = "maxWidth" in breakpoints[0] ? "maxWidth" : "minWidth";
19
20
  const sorted = [...breakpoints].sort(
20
- (a, b) => size({ size: b[property], sizes: uikitStyles.theme.breakpoints }) - size({ size: a[property], sizes: uikitStyles.theme.breakpoints })
21
+ (a, b) => getSize(b[property]) - getSize(a[property])
21
22
  );
22
23
  return property === "minWidth" ? sorted.reverse() : sorted;
23
24
  }
24
- const getContainerStyle = ({
25
- breakpoints,
26
- spacing,
27
- cols
28
- }) => {
25
+ const getContainerStyle = (breakpoints, spacing = "sm", cols = 1) => {
29
26
  return {
30
- boxSizing: "border-box",
31
- display: "grid",
32
- gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))`,
27
+ // TODO: review/document precedence of cols/spacing vs breakpoints[cols/spacing]
28
+ "--cols": cols,
33
29
  gap: uikitStyles.theme.space[spacing],
34
30
  ...breakpoints && getSortedBreakpoints(breakpoints).reduce((acc, breakpoint) => {
35
31
  const property = "maxWidth" in breakpoint ? "max-width" : "min-width";
36
- const breakpointSize = size({
37
- size: property === "max-width" ? breakpoint.maxWidth : breakpoint.minWidth,
38
- sizes: uikitStyles.theme.breakpoints
39
- });
40
- acc[`@media (${property}: ${breakpointSize + (property === "max-width" ? 0 : 1)}px)`] = {
41
- gridTemplateColumns: `repeat(${breakpoint.cols}, minmax(0, 1fr))`,
42
- gap: uikitStyles.theme.space[spacing]
32
+ const breakpointSize = getSize(
33
+ property === "max-width" ? breakpoint.maxWidth : breakpoint.minWidth
34
+ );
35
+ acc[`@media (${property}: ${breakpointSize}px)`] = {
36
+ ["--cols"]: breakpoint.cols,
37
+ gap: uikitStyles.theme.space[breakpoint.spacing || spacing]
43
38
  };
44
39
  return acc;
45
40
  }, {})
@@ -14,7 +14,7 @@ const BulkActions_styles = require("../BulkActions/BulkActions.styles.cjs");
14
14
  require("react/jsx-runtime");
15
15
  const Pagination_styles = require("../Pagination/Pagination.styles.cjs");
16
16
  require("react");
17
- require("@mui/material/Hidden");
17
+ require("@mui/material");
18
18
  require("@hitachivantara/uikit-react-icons");
19
19
  const { staticClasses, useClasses } = uikitReactUtils.createClasses("HvTableSection", {
20
20
  root: {},
@@ -11,7 +11,7 @@ const HvTimeAgo = generic.fixedForwardRef(function HvTimeAgo2(props, ref) {
11
11
  classes: classesProp,
12
12
  className,
13
13
  timestamp,
14
- locale: localeProp = "en",
14
+ locale = "en",
15
15
  component: Component = Typography.HvTypography,
16
16
  emptyElement = "—",
17
17
  disableRefresh = false,
@@ -20,7 +20,6 @@ const HvTimeAgo = generic.fixedForwardRef(function HvTimeAgo2(props, ref) {
20
20
  ...others
21
21
  } = uikitReactUtils.useDefaultProps("HvTimeAgo", props);
22
22
  const { classes, cx } = TimeAgo_styles.useClasses(classesProp);
23
- const locale = localeProp || "en";
24
23
  const timeAgo = useTimeAgo.default(timestamp, {
25
24
  locale,
26
25
  disableRefresh,
@@ -1,105 +1,72 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const dayjs = require("dayjs");
4
- const calendar = require("dayjs/plugin/calendar");
5
- const duration = require("dayjs/plugin/duration");
6
- const localeData = require("dayjs/plugin/localeData");
7
- const localizedFormat = require("dayjs/plugin/localizedFormat");
8
- const relativeTime = require("dayjs/plugin/relativeTime");
9
- const updateLocale = require("dayjs/plugin/updateLocale");
10
- const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
11
- const dayjs__default = /* @__PURE__ */ _interopDefault(dayjs);
12
- const calendar__default = /* @__PURE__ */ _interopDefault(calendar);
13
- const duration__default = /* @__PURE__ */ _interopDefault(duration);
14
- const localeData__default = /* @__PURE__ */ _interopDefault(localeData);
15
- const localizedFormat__default = /* @__PURE__ */ _interopDefault(localizedFormat);
16
- const relativeTime__default = /* @__PURE__ */ _interopDefault(relativeTime);
17
- const updateLocale__default = /* @__PURE__ */ _interopDefault(updateLocale);
18
- const thresholds = [
19
- { l: "s", r: 119, d: "second" },
20
- { l: "m", r: 1 },
21
- { l: "mm", r: 59, d: "minute" },
22
- { l: "h", r: 1 },
23
- { l: "hh", r: 23, d: "hour" },
24
- { l: "d", r: 1 },
25
- { l: "dd", r: 29, d: "day" },
26
- { l: "M", r: 1 },
27
- { l: "MM", r: 11, d: "month" },
28
- { l: "y", r: 17 },
29
- { l: "yy", d: "year" }
30
- ];
31
- dayjs__default.default.extend(localeData__default.default);
32
- dayjs__default.default.extend(duration__default.default);
33
- dayjs__default.default.extend(calendar__default.default);
34
- dayjs__default.default.extend(localizedFormat__default.default);
35
- dayjs__default.default.extend(relativeTime__default.default, { thresholds });
36
- dayjs__default.default.extend(updateLocale__default.default);
37
- const secondsUntilNextDay = (date = /* @__PURE__ */ new Date()) => {
38
- const midnight = new Date(date.getTime());
39
- midnight.setDate(midnight.getDate() + 1);
40
- midnight.setHours(0);
41
- midnight.setMinutes(0);
42
- midnight.setSeconds(0);
43
- midnight.setMilliseconds(0);
44
- return (midnight.getTime() - date.getTime()) / 1e3;
45
- };
46
- const secondsUntilNextWeek = (date = /* @__PURE__ */ new Date()) => {
47
- const firstMonthDayOfWeek = date.getDate() - date.getDay();
48
- const firstMonthDayOfNextWeek = firstMonthDayOfWeek + 7;
49
- const firstDayNextWeek = new Date(date.getTime());
50
- firstDayNextWeek.setDate(firstMonthDayOfNextWeek);
51
- firstDayNextWeek.setHours(0);
52
- firstDayNextWeek.setMinutes(0);
53
- firstDayNextWeek.setSeconds(0);
54
- firstDayNextWeek.setMilliseconds(0);
55
- return (firstDayNextWeek.getTime() - date.getTime()) / 1e3;
56
- };
57
- const formatTimeAgo = (date, locale, showSeconds = false, referenceDate = /* @__PURE__ */ new Date()) => {
58
- const dayReferenceDate = dayjs__default.default(referenceDate);
59
- const dayDate = dayjs__default.default(date).locale(locale);
60
- const dayDiffSeconds = dayReferenceDate.diff(dayDate, "second");
61
- const formatUseSeconds = showSeconds ? "LTS" : "LT";
62
- if (date.getTime() > referenceDate.getTime()) {
63
- return {
64
- timeAgo: dayDate.format(`L ${formatUseSeconds}`),
65
- delay: (date.getTime() - referenceDate.getTime()) / 1e3
66
- };
67
- }
68
- if (dayDiffSeconds < 120) {
69
- return {
70
- timeAgo: dayjs__default.default.duration(dayDiffSeconds, "second").locale(locale).humanize(),
71
- delay: 120 - dayDiffSeconds
72
- };
3
+ const isDateInPeriod = (timeAgoMs, period, referenceDate = /* @__PURE__ */ new Date()) => {
4
+ const date = new Date(timeAgoMs);
5
+ const startOfToday = new Date(referenceDate);
6
+ startOfToday.setHours(0, 0, 0, 0);
7
+ const startOfTomorrow = new Date(startOfToday);
8
+ startOfTomorrow.setDate(startOfToday.getDate() + 1);
9
+ const startOfDayAfterTomorrow = new Date(startOfTomorrow);
10
+ startOfDayAfterTomorrow.setDate(startOfTomorrow.getDate() + 1);
11
+ if (period === "tomorrow") {
12
+ return date >= startOfTomorrow && date < startOfDayAfterTomorrow;
73
13
  }
74
- const dayDiffMinutes = dayReferenceDate.diff(dayDate, "minute");
75
- if (dayDiffMinutes < 60) {
76
- return {
77
- timeAgo: dayjs__default.default.duration(-dayDiffMinutes, "minute").locale(locale).humanize(true),
78
- delay: 60 * (dayDiffMinutes + 1) - dayDiffSeconds
79
- };
14
+ if (period === "afterTomorrow") {
15
+ return date >= startOfDayAfterTomorrow;
80
16
  }
81
- if (dayReferenceDate.isSame(dayDate, "day")) {
82
- return {
83
- timeAgo: `${dayDate.calendar(dayReferenceDate)}`,
84
- delay: secondsUntilNextDay(referenceDate)
85
- };
86
- }
87
- if (dayReferenceDate.subtract(1, "day").isSame(dayDate, "day")) {
88
- return {
89
- timeAgo: `${dayDate.calendar(dayReferenceDate)}`,
90
- delay: secondsUntilNextDay(referenceDate)
91
- };
92
- }
93
- if (dayDate.isSame(dayReferenceDate, "week")) {
94
- return {
95
- timeAgo: dayDate.format(`ddd, ${formatUseSeconds}`),
96
- delay: secondsUntilNextWeek(date)
97
- };
17
+ return false;
18
+ };
19
+ const formatTimeAgo = (timeAgoMs, locale, showSeconds = false, referenceDate = /* @__PURE__ */ new Date()) => {
20
+ const relFormatter = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
21
+ const dayFormatter = new Intl.DateTimeFormat(locale, {
22
+ hour: "numeric",
23
+ minute: "numeric",
24
+ second: showSeconds ? "numeric" : void 0
25
+ });
26
+ const weekFormatter = new Intl.DateTimeFormat(locale, {
27
+ weekday: "short",
28
+ hour: "numeric",
29
+ minute: "numeric",
30
+ second: showSeconds ? "numeric" : void 0
31
+ });
32
+ const fullFormatter = new Intl.DateTimeFormat(locale, {
33
+ year: "numeric",
34
+ month: "short",
35
+ day: "numeric",
36
+ hour: "numeric",
37
+ minute: "numeric",
38
+ second: showSeconds ? "numeric" : void 0
39
+ });
40
+ const date = new Date(timeAgoMs);
41
+ const secsInDay = date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds();
42
+ const secsInWeek = date.getDay() * 86400 + secsInDay;
43
+ const secsAgo = Math.floor((referenceDate.getTime() - timeAgoMs) / 1e3);
44
+ const minsAgo = Math.floor(secsAgo / 60);
45
+ switch (true) {
46
+ case isDateInPeriod(timeAgoMs, "afterTomorrow", referenceDate):
47
+ return fullFormatter.format(date);
48
+ case isDateInPeriod(timeAgoMs, "tomorrow", referenceDate):
49
+ return `${relFormatter.format(1, "days")}, ${dayFormatter.format(date)}`;
50
+ case minsAgo < -60:
51
+ return `${relFormatter.format(0, "days")}, ${dayFormatter.format(date)}`;
52
+ case minsAgo < -2:
53
+ return relFormatter.format(-minsAgo, "minutes");
54
+ case secsAgo < 0:
55
+ return `${relFormatter.format(Math.abs(secsAgo), "seconds")}`;
56
+ case secsAgo < 20:
57
+ return relFormatter.format(0, "seconds");
58
+ case minsAgo < 2:
59
+ return relFormatter.format(-secsAgo, "seconds");
60
+ case minsAgo < 60:
61
+ return relFormatter.format(-minsAgo, "minutes");
62
+ case secsAgo < secsInDay:
63
+ return `${relFormatter.format(0, "days")}, ${dayFormatter.format(date)}`;
64
+ case secsAgo < secsInDay + 86400:
65
+ return `${relFormatter.format(-1, "days")}, ${dayFormatter.format(date)}`;
66
+ case secsAgo < secsInWeek:
67
+ return weekFormatter.format(date);
68
+ default:
69
+ return fullFormatter.format(date);
98
70
  }
99
- return {
100
- timeAgo: dayDate.format(`L ${formatUseSeconds}`),
101
- delay: 0
102
- };
103
71
  };
104
72
  exports.formatTimeAgo = formatTimeAgo;
105
- exports.secondsUntilNextDay = secondsUntilNextDay;
@@ -5,12 +5,14 @@ const formatUtils = require("./formatUtils.cjs");
5
5
  const useTimeout = require("./useTimeout.cjs");
6
6
  const fmt = (timestamp, locale, showSeconds) => {
7
7
  const timestampMs = String(timestamp).length > 11 ? timestamp : timestamp * 1e3;
8
- return formatUtils.formatTimeAgo(new Date(timestampMs), locale, showSeconds);
8
+ return formatUtils.formatTimeAgo(timestampMs, locale, showSeconds);
9
9
  };
10
- function useTimeAgo(timestamp, options) {
10
+ function useTimeAgo(timestamp = Date.now(), options) {
11
11
  const { locale, disableRefresh = false, showSeconds = false } = options || {};
12
- const [timeAgo, setTimeAgo] = React.useState(fmt(timestamp, locale, showSeconds));
13
- const refreshTime = disableRefresh ? 0 : timeAgo.delay * 1e3;
12
+ const [timeAgo, setTimeAgo] = React.useState(
13
+ () => fmt(timestamp, locale, showSeconds)
14
+ );
15
+ const refreshTime = disableRefresh ? 0 : 1e4;
14
16
  React.useEffect(() => {
15
17
  const newTimeAgo = fmt(timestamp, locale, showSeconds);
16
18
  setTimeAgo(newTimeAgo);
@@ -19,6 +21,6 @@ function useTimeAgo(timestamp, options) {
19
21
  const newTimeAgo = fmt(timestamp, locale, showSeconds);
20
22
  setTimeAgo(newTimeAgo);
21
23
  }, refreshTime);
22
- return timeAgo.timeAgo;
24
+ return timeAgo;
23
25
  }
24
26
  exports.default = useTimeAgo;
@@ -82,6 +82,7 @@ const HvButton = fixedForwardRef(function HvButton2(props, ref) {
82
82
  sizeStyles && css(sizeStyles),
83
83
  className
84
84
  ),
85
+ "data-color": color,
85
86
  onClick: handleClick,
86
87
  onMouseDown: handleMouseDown,
87
88
  ...Component === "button" && { type: "button" },