@hitachivantara/uikit-react-core 5.72.1 → 5.73.1
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/Button/Button.cjs +1 -0
- package/dist/cjs/Pagination/Pagination.cjs +7 -7
- package/dist/cjs/TableSection/TableSection.styles.cjs +1 -1
- package/dist/cjs/TimeAgo/TimeAgo.cjs +1 -2
- package/dist/cjs/TimeAgo/formatUtils.cjs +65 -98
- package/dist/cjs/TimeAgo/useTimeAgo.cjs +7 -5
- package/dist/esm/Button/Button.js +1 -0
- package/dist/esm/Button/Button.js.map +1 -1
- package/dist/esm/Pagination/Pagination.js +7 -5
- package/dist/esm/Pagination/Pagination.js.map +1 -1
- package/dist/esm/TableSection/TableSection.styles.js +1 -1
- package/dist/esm/TimeAgo/TimeAgo.js +1 -2
- package/dist/esm/TimeAgo/TimeAgo.js.map +1 -1
- package/dist/esm/TimeAgo/formatUtils.js +66 -91
- package/dist/esm/TimeAgo/formatUtils.js.map +1 -1
- package/dist/esm/TimeAgo/useTimeAgo.js +7 -5
- package/dist/esm/TimeAgo/useTimeAgo.js.map +1 -1
- package/dist/esm/TreeView/TreeItem/useHvTreeItem.js.map +1 -1
- package/dist/esm/types/generic.js.map +1 -1
- package/dist/types/index.d.ts +58 -58
- package/package.json +6 -6
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
@@ -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
|
|
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
|
|
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
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
75
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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(
|
|
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(
|
|
13
|
-
|
|
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
|
|
24
|
+
return timeAgo;
|
|
23
25
|
}
|
|
24
26
|
exports.default = useTimeAgo;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","sources":["../../../src/Button/Button.tsx"],"sourcesContent":["import { useMemo } from \"react\";\nimport {\n useDefaultProps,\n useTheme,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\nimport { HvBaseTheme } from \"@hitachivantara/uikit-styles\";\n\nimport {\n fixedForwardRef,\n PolymorphicComponentRef,\n PolymorphicRef,\n} from \"../types/generic\";\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?: HvBaseTheme,\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?.base,\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":";;;;;;AAoEA,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,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AQ,QAAQ,GAAG;AAAA,QACtB;AAAA,QACA,cAAc,IAAI,UAAU;AAAA,QAC5B;AAAA,MACF;AAAA,MACA,SAAS;AAAA,MACT,aAAa;AAAA,MACZ,GAAI,cAAc,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
|
+
{"version":3,"file":"Button.js","sources":["../../../src/Button/Button.tsx"],"sourcesContent":["import { useMemo } from \"react\";\nimport {\n useDefaultProps,\n useTheme,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\nimport { HvBaseTheme } from \"@hitachivantara/uikit-styles\";\n\nimport {\n fixedForwardRef,\n PolymorphicComponentRef,\n PolymorphicRef,\n} from \"../types/generic\";\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?: HvBaseTheme,\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?.base,\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 data-color={color}\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":";;;;;;AAoEA,MAAM,aAAa,CACjB,SACA,UACoB;AAChB,MAAA,UAAU,MAAc,QAAA;AAE5B,QAAM,uBAAwD;AAAA,IAC5D,WAAW;AAAA,IACX,OAAO;AAAA,EAAA;AAGH,QAAA,gBAAgB,q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G;AAAA,QACH,qBAAqB,aAAa,WAAW,SAAS;AAAA,MACxD;AAAA,MACA,WAAW;AAAA,QACT,QAAQ;AAAA,QACR,QAAQ,QAAQ,IAA6B;AAAA,QAC7C,SAAS,IAAI,iBAAiB,OAAO,IAAI,CAAC;AAAA,QAC1C,QAAQ,OAAgC;AAAA;AAAA,QACxC,UAAU,IAAI,gBAAgB,MAAM,CAAC;AAAA,QACrC,sBAAsB,IAAI,mBAAmB;AAAA,QAC7C;AAAA,UACE,CAAC,QAAQ,IAAI,GAAG;AAAA,UAChB,CAAC,QAAQ,QAAQ,GAAG;AAAA,QACtB;AAAA,QACA,cAAc,IAAI,UAAU;AAAA,QAC5B;AAAA,MACF;AAAA,MACA,cAAY;AAAA,MACZ,SAAS;AAAA,MACT,aAAa;AAAA,MACZ,GAAI,cAAc,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,6 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useCallback, useEffect } from "react";
|
|
3
|
-
import
|
|
3
|
+
import { useTheme, useMediaQuery } from "@mui/material";
|
|
4
4
|
import { Start, Backwards, Forwards, End } from "@hitachivantara/uikit-react-icons";
|
|
5
5
|
import { useDefaultProps, clamp } from "@hitachivantara/uikit-react-utils";
|
|
6
6
|
import { useLabels } from "../hooks/useLabels.js";
|
|
@@ -63,6 +63,8 @@ const HvPagination = (props) => {
|
|
|
63
63
|
} = useDefaultProps("HvPagination", props);
|
|
64
64
|
const { classes, cx } = useClasses(classesProp);
|
|
65
65
|
const labels = useLabels(DEFAULT_LABELS, labelsProp);
|
|
66
|
+
const muiTheme = useTheme();
|
|
67
|
+
const isXsDown = useMediaQuery(muiTheme.breakpoints.down("xs"));
|
|
66
68
|
const [pageInput, setPageInput] = useState(page);
|
|
67
69
|
const changePage = useCallback(
|
|
68
70
|
(newPage) => {
|
|
@@ -106,14 +108,14 @@ const HvPagination = (props) => {
|
|
|
106
108
|
) });
|
|
107
109
|
return /* @__PURE__ */ jsxs("div", { id, className: cx(classes.root, className), ...others, children: [
|
|
108
110
|
/* @__PURE__ */ jsx("div", { className: classes.pageSizeOptions, ...showPageProps, children: showPageSizeOptions && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
109
|
-
|
|
111
|
+
!isXsDown && /* @__PURE__ */ jsx(
|
|
110
112
|
HvTypography,
|
|
111
113
|
{
|
|
112
114
|
component: "span",
|
|
113
115
|
className: classes?.pageSizeTextContainer,
|
|
114
116
|
children: labels?.pageSizePrev
|
|
115
117
|
}
|
|
116
|
-
)
|
|
118
|
+
),
|
|
117
119
|
/* @__PURE__ */ jsx(
|
|
118
120
|
HvSelect,
|
|
119
121
|
{
|
|
@@ -130,14 +132,14 @@ const HvPagination = (props) => {
|
|
|
130
132
|
children: pageSizeOptions.map((option) => /* @__PURE__ */ jsx(Option, { value: option, children: option }, option))
|
|
131
133
|
}
|
|
132
134
|
),
|
|
133
|
-
|
|
135
|
+
!isXsDown && /* @__PURE__ */ jsx(
|
|
134
136
|
HvTypography,
|
|
135
137
|
{
|
|
136
138
|
component: "span",
|
|
137
139
|
className: classes.pageSizeTextContainer,
|
|
138
140
|
children: labels?.pageSizeEntryName
|
|
139
141
|
}
|
|
140
|
-
)
|
|
142
|
+
)
|
|
141
143
|
] }) }),
|
|
142
144
|
/* @__PURE__ */ jsxs("div", { className: classes.pageNavigator, ...navigationProps, children: [
|
|
143
145
|
/* @__PURE__ */ jsx(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination.js","sources":["../../../src/Pagination/Pagination.tsx"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport Hidden from \"@mui/material/Hidden\";\nimport {\n Backwards,\n End,\n Forwards,\n Start,\n} from \"@hitachivantara/uikit-react-icons\";\nimport {\n clamp,\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { useLabels } from \"../hooks/useLabels\";\nimport { HvIconButton } from \"../IconButton\";\nimport { HvInput, HvInputProps } from \"../Input\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./Pagination.styles\";\nimport HvSelect, { Option } from \"./Select\";\n\nexport { staticClasses as paginationClasses };\n\nexport type HvPaginationClasses = ExtractNames<typeof useClasses>;\n\nconst defaultPageSizeOptions = [5, 10, 20, 25, 50, 100];\n\nconst DEFAULT_LABELS = {\n /** The show label. */\n pageSizePrev: \"Show\",\n /** Indicate the units of the page size selection. */\n pageSizeEntryName: \"rows\",\n /** Used for the aria-label of the selection of number of unit.s */\n pageSizeSelectorDescription: \"Select how many to display\",\n /** Separator of current page and total pages. */\n pagesSeparator: \"/\",\n /** Title of button `firstPage`. @deprecated Use `firstPage` instead. */\n paginationFirstPageTitle: \"First page\",\n /** Title of button `previousPage`. @deprecated Use `previousPage` instead. */\n paginationPreviousPageTitle: \"Previous page\",\n /** Title of button `nextPage`. @deprecated Use `nextPage` instead. */\n paginationNextPageTitle: \"Next page\",\n /** Title of button `lastPage`. @deprecated Use `lastPage` instead. */\n paginationLastPageTitle: \"Last page\",\n /** Aria-label passed to the page input. */\n paginationInputLabel: \"Current page\",\n /** Label of the first page button */\n firstPage: \"First Page\",\n /** Label of the previous page button */\n previousPage: \"Previous Page\",\n /** Label of the next page button */\n nextPage: \"Next Page\",\n /** Label of the last page button */\n lastPage: \"Last Page\",\n};\n\nexport type HvPaginationLabels = Partial<typeof DEFAULT_LABELS>;\n\nexport interface HvPaginationProps extends HvBaseProps {\n /** The number of pages the component has. */\n pages?: number;\n /** The currently selected page (0-indexed). */\n page?: number;\n /** Controls whether the left page size mechanism should be visible. */\n showPageSizeOptions?: boolean;\n /** The array of possible page sizes for the dropdown. */\n pageSizeOptions?: number[];\n /** The currently selected page size. */\n pageSize?: number;\n /** Controls whether the central page changing mechanism should be visible. */\n showPageJump?: boolean;\n /** Controls whether the previous/first page buttons are enabled. */\n canPrevious?: boolean;\n /** Controls whether the next/last page buttons are enabled. */\n canNext?: boolean;\n /** Function called when the page changes. */\n onPageChange?: (page: number) => void;\n /** Function called when the page size changes. */\n onPageSizeChange?: (pageSize: number) => void;\n /** An object containing all the labels for the component. */\n labels?: HvPaginationLabels;\n /** Other props to show page component. */\n showPageProps?: React.HTMLAttributes<HTMLDivElement>;\n /** Other props to pagination component. */\n navigationProps?: React.HTMLAttributes<HTMLDivElement>;\n /** Extra properties passed to the input component representing the current pages. */\n currentPageInputProps?: HvInputProps;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvPaginationClasses;\n}\n\n/**\n * Pagination is the process of dividing a document into discrete pages. It relates to how users interact\n * with structured content on a website or application.\n */\nexport const HvPagination = (props: HvPaginationProps) => {\n const {\n classes: classesProp,\n className,\n id,\n pages = 1,\n page = 0,\n showPageSizeOptions = true,\n pageSizeOptions = defaultPageSizeOptions,\n pageSize = defaultPageSizeOptions[1],\n showPageJump = true,\n canPrevious = false,\n canNext = false,\n onPageChange,\n onPageSizeChange,\n labels: labelsProp,\n showPageProps,\n navigationProps,\n currentPageInputProps,\n ...others\n } = useDefaultProps(\"HvPagination\", props);\n const { classes, cx } = useClasses(classesProp);\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const [pageInput, setPageInput] = useState(page);\n\n const changePage = useCallback(\n (newPage: number) => {\n const safePage = Number.isNaN(newPage) ? page : clamp(newPage, pages - 1);\n\n onPageChange?.(safePage);\n setPageInput(safePage);\n },\n [page, pages, onPageChange],\n );\n\n useEffect(() => {\n if (page >= pages && pages > 0) {\n changePage(page);\n }\n }, [changePage, page, pages]);\n\n useEffect(() => {\n setPageInput(page);\n }, [page]);\n\n const renderPageJump = () => (\n <div className={classes.pageJump}>\n <HvInput\n id={setId(id, \"currentPage\")}\n labels={labels}\n inputProps={{\n \"aria-label\": labels?.paginationInputLabel,\n // We really want the native number input\n type: \"number\",\n }}\n classes={{\n root: classes?.pageSizeInputContainer,\n input: classes?.pageSizeInput,\n inputRoot: classes?.pageSizeInputRoot,\n }}\n value={String(pageInput + 1)}\n onChange={(event, value) => setPageInput(Number(value) - 1)}\n onBlur={(evt, value) => changePage(Math.round(Number(value)) - 1)}\n onEnter={(evt, value) => changePage(Math.round(Number(value)) - 1)}\n disabled={pageSize === 0}\n disableClear\n {...currentPageInputProps}\n />\n </div>\n );\n\n return (\n <div id={id} className={cx(classes.root, className)} {...others}>\n <div className={classes.pageSizeOptions} {...showPageProps}>\n {showPageSizeOptions && (\n <>\n <Hidden xsDown>\n <HvTypography\n component=\"span\"\n className={classes?.pageSizeTextContainer}\n >\n {labels?.pageSizePrev}\n </HvTypography>\n </Hidden>\n <HvSelect\n id={setId(id, \"pageSize\")}\n disabled={pageSize === 0}\n className={classes.pageSizeOptionsSelect}\n aria-label={labels?.pageSizeSelectorDescription}\n onChange={(_: any, val: number) => onPageSizeChange?.(val)}\n value={pageSize}\n classes={{\n header: classes.pageSizeHeader,\n root: classes.pageSizeRoot,\n }}\n >\n {pageSizeOptions.map((option) => (\n <Option key={option} value={option}>\n {option}\n </Option>\n ))}\n </HvSelect>\n <Hidden xsDown>\n <HvTypography\n component=\"span\"\n className={classes.pageSizeTextContainer}\n >\n {labels?.pageSizeEntryName}\n </HvTypography>\n </Hidden>\n </>\n )}\n </div>\n <div className={classes.pageNavigator} {...navigationProps}>\n <HvIconButton\n id={setId(id, \"firstPage-button\")}\n className={classes.iconContainer}\n disabled={!canPrevious}\n onClick={() => changePage(0)}\n title={labels?.firstPage || labels?.paginationFirstPageTitle}\n >\n <Start className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n <HvIconButton\n id={setId(id, \"previousPage-button\")}\n className={classes.iconContainer}\n disabled={!canPrevious}\n onClick={() => changePage(page - 1)}\n title={labels?.previousPage || labels?.paginationPreviousPageTitle}\n >\n <Backwards className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n <div className={classes.pageInfo}>\n {showPageJump ? (\n renderPageJump()\n ) : (\n <HvTypography variant=\"caption2\" component=\"span\">{`${\n page + 1\n }`}</HvTypography>\n )}\n <HvTypography component=\"span\">{`${labels?.pagesSeparator} `}</HvTypography>\n <HvTypography\n component=\"span\"\n id={setId(id, \"totalPages\")}\n className={classes.totalPagesTextContainer}\n >\n {pages}\n </HvTypography>\n </div>\n <HvIconButton\n id={setId(id, \"nextPage-button\")}\n className={classes.iconContainer}\n disabled={!canNext}\n onClick={() => changePage(page + 1)}\n title={labels?.nextPage || labels?.paginationNextPageTitle}\n >\n <Forwards className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n <HvIconButton\n id={setId(id, \"lastPage-button\")}\n className={classes.iconContainer}\n disabled={!canNext}\n onClick={() => changePage(pages - 1)}\n title={labels?.lastPage || labels?.paginationLastPageTitle}\n >\n <End className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n </div>\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AA2BA,MAAM,yBAAyB,CAAC,GAAG,IAAI,IAAI,IAAI,IAAI,GAAG;AAEtD,MAAM,iBAAiB;AAAA;AAAA,EAErB,cAAc;AAAA;AAAA,EAEd,mBAAmB;AAAA;AAAA,EAEnB,6BAA6B;AAAA;AAAA,EAE7B,gBAAgB;AAAA;AAAA,EAEhB,0BAA0B;AAAA;AAAA,EAE1B,6BAA6B;AAAA;AA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,WAAU;AAAA,YACV,IAAI,MAAM,IAAI,YAAY;AAAA,YAC1B,WAAW,QAAQ;AAAA,YAElB,UAAA;AAAA,UAAA;AAAA,QACH;AAAA,MAAA,GACF;AAAA,MACA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,IAAI,MAAM,IAAI,iBAAiB;AAAA,UAC/B,WAAW,QAAQ;AAAA,UACnB,UAAU,CAAC;AAAA,UACX,SAAS,MAAM,WAAW,OAAO,CAAC;AAAA,UAClC,OAAO,QAAQ,YAAY,QAAQ;AAAA,UAEnC,8BAAC,UAAS,EAAA,WAAW,QAAQ,MAAM,UAAS,MAAK;AAAA,QAAA;AAAA,MACnD;AAAA,MACA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,IAAI,MAAM,IAAI,iBAAiB;AAAA,UAC/B,WAAW,QAAQ;AAAA,UACnB,UAAU,CAAC;AAAA,UACX,SAAS,MAAM,WAAW,QAAQ,CAAC;AAAA,UACnC,OAAO,QAAQ,YAAY,QAAQ;AAAA,UAEnC,8BAAC,KAAI,EAAA,WAAW,QAAQ,MAAM,UAAS,MAAK;AAAA,QAAA;AAAA,MAC9C;AAAA,IAAA,GACF;AAAA,EACF,EAAA,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"Pagination.js","sources":["../../../src/Pagination/Pagination.tsx"],"sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\nimport { useMediaQuery, useTheme } from \"@mui/material\";\nimport {\n Backwards,\n End,\n Forwards,\n Start,\n} from \"@hitachivantara/uikit-react-icons\";\nimport {\n clamp,\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { useLabels } from \"../hooks/useLabels\";\nimport { HvIconButton } from \"../IconButton\";\nimport { HvInput, HvInputProps } from \"../Input\";\nimport { HvBaseProps } from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { setId } from \"../utils/setId\";\nimport { staticClasses, useClasses } from \"./Pagination.styles\";\nimport HvSelect, { Option } from \"./Select\";\n\nexport { staticClasses as paginationClasses };\n\nexport type HvPaginationClasses = ExtractNames<typeof useClasses>;\n\nconst defaultPageSizeOptions = [5, 10, 20, 25, 50, 100];\n\nconst DEFAULT_LABELS = {\n /** The show label. */\n pageSizePrev: \"Show\",\n /** Indicate the units of the page size selection. */\n pageSizeEntryName: \"rows\",\n /** Used for the aria-label of the selection of number of unit.s */\n pageSizeSelectorDescription: \"Select how many to display\",\n /** Separator of current page and total pages. */\n pagesSeparator: \"/\",\n /** Title of button `firstPage`. @deprecated Use `firstPage` instead. */\n paginationFirstPageTitle: \"First page\",\n /** Title of button `previousPage`. @deprecated Use `previousPage` instead. */\n paginationPreviousPageTitle: \"Previous page\",\n /** Title of button `nextPage`. @deprecated Use `nextPage` instead. */\n paginationNextPageTitle: \"Next page\",\n /** Title of button `lastPage`. @deprecated Use `lastPage` instead. */\n paginationLastPageTitle: \"Last page\",\n /** Aria-label passed to the page input. */\n paginationInputLabel: \"Current page\",\n /** Label of the first page button */\n firstPage: \"First Page\",\n /** Label of the previous page button */\n previousPage: \"Previous Page\",\n /** Label of the next page button */\n nextPage: \"Next Page\",\n /** Label of the last page button */\n lastPage: \"Last Page\",\n};\n\nexport type HvPaginationLabels = Partial<typeof DEFAULT_LABELS>;\n\nexport interface HvPaginationProps extends HvBaseProps {\n /** The number of pages the component has. */\n pages?: number;\n /** The currently selected page (0-indexed). */\n page?: number;\n /** Controls whether the left page size mechanism should be visible. */\n showPageSizeOptions?: boolean;\n /** The array of possible page sizes for the dropdown. */\n pageSizeOptions?: number[];\n /** The currently selected page size. */\n pageSize?: number;\n /** Controls whether the central page changing mechanism should be visible. */\n showPageJump?: boolean;\n /** Controls whether the previous/first page buttons are enabled. */\n canPrevious?: boolean;\n /** Controls whether the next/last page buttons are enabled. */\n canNext?: boolean;\n /** Function called when the page changes. */\n onPageChange?: (page: number) => void;\n /** Function called when the page size changes. */\n onPageSizeChange?: (pageSize: number) => void;\n /** An object containing all the labels for the component. */\n labels?: HvPaginationLabels;\n /** Other props to show page component. */\n showPageProps?: React.HTMLAttributes<HTMLDivElement>;\n /** Other props to pagination component. */\n navigationProps?: React.HTMLAttributes<HTMLDivElement>;\n /** Extra properties passed to the input component representing the current pages. */\n currentPageInputProps?: HvInputProps;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvPaginationClasses;\n}\n\n/**\n * Pagination is the process of dividing a document into discrete pages. It relates to how users interact\n * with structured content on a website or application.\n */\nexport const HvPagination = (props: HvPaginationProps) => {\n const {\n classes: classesProp,\n className,\n id,\n pages = 1,\n page = 0,\n showPageSizeOptions = true,\n pageSizeOptions = defaultPageSizeOptions,\n pageSize = defaultPageSizeOptions[1],\n showPageJump = true,\n canPrevious = false,\n canNext = false,\n onPageChange,\n onPageSizeChange,\n labels: labelsProp,\n showPageProps,\n navigationProps,\n currentPageInputProps,\n ...others\n } = useDefaultProps(\"HvPagination\", props);\n const { classes, cx } = useClasses(classesProp);\n const labels = useLabels(DEFAULT_LABELS, labelsProp);\n\n const muiTheme = useTheme();\n const isXsDown = useMediaQuery(muiTheme.breakpoints.down(\"xs\"));\n\n const [pageInput, setPageInput] = useState(page);\n\n const changePage = useCallback(\n (newPage: number) => {\n const safePage = Number.isNaN(newPage) ? page : clamp(newPage, pages - 1);\n\n onPageChange?.(safePage);\n setPageInput(safePage);\n },\n [page, pages, onPageChange],\n );\n\n useEffect(() => {\n if (page >= pages && pages > 0) {\n changePage(page);\n }\n }, [changePage, page, pages]);\n\n useEffect(() => {\n setPageInput(page);\n }, [page]);\n\n const renderPageJump = () => (\n <div className={classes.pageJump}>\n <HvInput\n id={setId(id, \"currentPage\")}\n labels={labels}\n inputProps={{\n \"aria-label\": labels?.paginationInputLabel,\n // We really want the native number input\n type: \"number\",\n }}\n classes={{\n root: classes?.pageSizeInputContainer,\n input: classes?.pageSizeInput,\n inputRoot: classes?.pageSizeInputRoot,\n }}\n value={String(pageInput + 1)}\n onChange={(event, value) => setPageInput(Number(value) - 1)}\n onBlur={(evt, value) => changePage(Math.round(Number(value)) - 1)}\n onEnter={(evt, value) => changePage(Math.round(Number(value)) - 1)}\n disabled={pageSize === 0}\n disableClear\n {...currentPageInputProps}\n />\n </div>\n );\n\n return (\n <div id={id} className={cx(classes.root, className)} {...others}>\n <div className={classes.pageSizeOptions} {...showPageProps}>\n {showPageSizeOptions && (\n <>\n {!isXsDown && (\n <HvTypography\n component=\"span\"\n className={classes?.pageSizeTextContainer}\n >\n {labels?.pageSizePrev}\n </HvTypography>\n )}\n <HvSelect\n id={setId(id, \"pageSize\")}\n disabled={pageSize === 0}\n className={classes.pageSizeOptionsSelect}\n aria-label={labels?.pageSizeSelectorDescription}\n onChange={(_: any, val: number) => onPageSizeChange?.(val)}\n value={pageSize}\n classes={{\n header: classes.pageSizeHeader,\n root: classes.pageSizeRoot,\n }}\n >\n {pageSizeOptions.map((option) => (\n <Option key={option} value={option}>\n {option}\n </Option>\n ))}\n </HvSelect>\n {!isXsDown && (\n <HvTypography\n component=\"span\"\n className={classes.pageSizeTextContainer}\n >\n {labels?.pageSizeEntryName}\n </HvTypography>\n )}\n </>\n )}\n </div>\n <div className={classes.pageNavigator} {...navigationProps}>\n <HvIconButton\n id={setId(id, \"firstPage-button\")}\n className={classes.iconContainer}\n disabled={!canPrevious}\n onClick={() => changePage(0)}\n title={labels?.firstPage || labels?.paginationFirstPageTitle}\n >\n <Start className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n <HvIconButton\n id={setId(id, \"previousPage-button\")}\n className={classes.iconContainer}\n disabled={!canPrevious}\n onClick={() => changePage(page - 1)}\n title={labels?.previousPage || labels?.paginationPreviousPageTitle}\n >\n <Backwards className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n <div className={classes.pageInfo}>\n {showPageJump ? (\n renderPageJump()\n ) : (\n <HvTypography variant=\"caption2\" component=\"span\">{`${\n page + 1\n }`}</HvTypography>\n )}\n <HvTypography component=\"span\">{`${labels?.pagesSeparator} `}</HvTypography>\n <HvTypography\n component=\"span\"\n id={setId(id, \"totalPages\")}\n className={classes.totalPagesTextContainer}\n >\n {pages}\n </HvTypography>\n </div>\n <HvIconButton\n id={setId(id, \"nextPage-button\")}\n className={classes.iconContainer}\n disabled={!canNext}\n onClick={() => changePage(page + 1)}\n title={labels?.nextPage || labels?.paginationNextPageTitle}\n >\n <Forwards className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n <HvIconButton\n id={setId(id, \"lastPage-button\")}\n className={classes.iconContainer}\n disabled={!canNext}\n onClick={() => changePage(pages - 1)}\n title={labels?.lastPage || labels?.paginationLastPageTitle}\n >\n <End className={classes.icon} iconSize=\"XS\" />\n </HvIconButton>\n </div>\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AA2BA,MAAM,yBAAyB,CAAC,GAAG,IAAI,IAAI,IAAI,IAAI,GAAG;AAEtD,MAAM,iBAAiB;AAAA;AAAA,EAErB,cAAc;AAAA;AAAA,EAEd,mBAAmB;AAAA;AAAA,EAEnB,6BAA6B;AAAA;AAAA,EAE7B,gBAAgB;AAAA;AAAA,EAEhB,0BAA0B;AAAA;AAAA,EAE1B,6BAA6B;AAAA;AAAA,EAE7B,yBAAyB;AAAA;AAAA,EAEzB,yBAAyB;AAAA;AAAA,EAEzB,sBAAsB;AAAA;AAAA,EAEtB,WAAW;AAAA;AAAA,EAEX,cAAc;AAAA;AAAA,EAEd,UAAU;AAAA;AAAA,EAEV,UAAU;AACZ;AAyCa,MAAA,eAAe,CAAC,UAA6B;AAClD,QAAA;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,sBAAsB;AAAA,IACtB,kBAAkB;AAAA,IAClB,WAAW,uBAAuB,CAAC;AAAA,IACnC,eAAe;AAAA,IACf,cAAc;AAAA,IACd,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;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,WAAW,QAAQ;AAAA,UACnB,UAAU,CAAC;AAAA,UACX,SAAS,MAAM,WAAW,QAAQ,CAAC;AAAA,UACnC,OAAO,QAAQ,YAAY,QAAQ;AAAA,UAEnC,8BAAC,KAAI,EAAA,WAAW,QAAQ,MAAM,UAAS,MAAK;AAAA,QAAA;AAAA,MAC9C;AAAA,IAAA,GACF;AAAA,EACF,EAAA,CAAA;AAEJ;"}
|
|
@@ -12,7 +12,7 @@ import { staticClasses as staticClasses$5 } from "../BulkActions/BulkActions.sty
|
|
|
12
12
|
import "react/jsx-runtime";
|
|
13
13
|
import { staticClasses as staticClasses$6 } from "../Pagination/Pagination.styles.js";
|
|
14
14
|
import "react";
|
|
15
|
-
import "@mui/material
|
|
15
|
+
import "@mui/material";
|
|
16
16
|
import "@hitachivantara/uikit-react-icons";
|
|
17
17
|
const { staticClasses, useClasses } = createClasses("HvTableSection", {
|
|
18
18
|
root: {},
|
|
@@ -10,7 +10,7 @@ const HvTimeAgo = fixedForwardRef(function HvTimeAgo2(props, ref) {
|
|
|
10
10
|
classes: classesProp,
|
|
11
11
|
className,
|
|
12
12
|
timestamp,
|
|
13
|
-
locale
|
|
13
|
+
locale = "en",
|
|
14
14
|
component: Component = HvTypography,
|
|
15
15
|
emptyElement = "—",
|
|
16
16
|
disableRefresh = false,
|
|
@@ -19,7 +19,6 @@ const HvTimeAgo = fixedForwardRef(function HvTimeAgo2(props, ref) {
|
|
|
19
19
|
...others
|
|
20
20
|
} = useDefaultProps("HvTimeAgo", props);
|
|
21
21
|
const { classes, cx } = useClasses(classesProp);
|
|
22
|
-
const locale = localeProp || "en";
|
|
23
22
|
const timeAgo = useTimeAgo(timestamp, {
|
|
24
23
|
locale,
|
|
25
24
|
disableRefresh,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeAgo.js","sources":["../../../src/TimeAgo/TimeAgo.tsx"],"sourcesContent":["import {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport {\n fixedForwardRef,\n PolymorphicComponentRef,\n PolymorphicRef,\n} from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { staticClasses, useClasses } from \"./TimeAgo.styles\";\nimport useTimeAgo from \"./useTimeAgo\";\n\nexport { staticClasses as timeAgoClasses };\n\nexport type HvTimeAgoClasses = ExtractNames<typeof useClasses>;\n\nexport type HvTimeAgoProps<C extends React.ElementType = \"p\"> =\n PolymorphicComponentRef<\n C,\n {\n /**\n * The timestamp to format, in seconds or milliseconds.\n * Defaults to `emptyElement` if value is null or 0\n */\n timestamp?: number;\n /**\n * The locale to be used. Should be on of the
|
|
1
|
+
{"version":3,"file":"TimeAgo.js","sources":["../../../src/TimeAgo/TimeAgo.tsx"],"sourcesContent":["import {\n useDefaultProps,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport {\n fixedForwardRef,\n PolymorphicComponentRef,\n PolymorphicRef,\n} from \"../types/generic\";\nimport { HvTypography } from \"../Typography\";\nimport { staticClasses, useClasses } from \"./TimeAgo.styles\";\nimport useTimeAgo from \"./useTimeAgo\";\n\nexport { staticClasses as timeAgoClasses };\n\nexport type HvTimeAgoClasses = ExtractNames<typeof useClasses>;\n\nexport type HvTimeAgoProps<C extends React.ElementType = \"p\"> =\n PolymorphicComponentRef<\n C,\n {\n /**\n * The timestamp to format, in seconds or milliseconds.\n * Defaults to `emptyElement` if value is null or 0\n */\n timestamp?: number;\n /**\n * The locale to be used. Should be on of the JS supported locales\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument\n */\n locale?: Intl.LocalesArgument;\n /**\n * The element to render when the timestamp is null or 0\n * Defaults to `—` (Em Dash)\n */\n emptyElement?: React.ReactNode;\n /** Disables periodic date refreshes */\n disableRefresh?: boolean;\n /** Whether to show seconds in the rendered time */\n showSeconds?: boolean;\n /**\n * Whether the component should render just the string\n * Consider using `useTimeAgo` instead\n */\n justText?: boolean;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvTimeAgoClasses;\n }\n >;\n\n/**\n * The HvTimeAgo component implements the Design System relative time format guidelines.\n */\nexport const HvTimeAgo = fixedForwardRef(function HvTimeAgo<\n C extends React.ElementType = \"p\",\n>(props: HvTimeAgoProps<C>, ref: PolymorphicRef<C>) {\n const {\n classes: classesProp,\n className,\n timestamp,\n locale = \"en\",\n component: Component = HvTypography,\n emptyElement = \"—\",\n disableRefresh = false,\n showSeconds = false,\n justText = false,\n ...others\n } = useDefaultProps(\"HvTimeAgo\", props);\n\n const { classes, cx } = useClasses(classesProp);\n const timeAgo = useTimeAgo(timestamp, {\n locale,\n disableRefresh,\n showSeconds,\n });\n\n if (justText && timestamp) return <>{timeAgo}</>;\n\n return (\n <Component ref={ref} className={cx(classes.root, className)} {...others}>\n {!timestamp ? emptyElement : timeAgo}\n </Component>\n );\n});\n"],"names":["HvTimeAgo"],"mappings":";;;;;;;AAsDO,MAAM,YAAY,gBAAgB,SAASA,WAEhD,OAA0B,KAAwB;AAC5C,QAAA;AAAA,IACJ,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT,WAAW,YAAY;AAAA,IACvB,eAAe;AAAA,IACf,iBAAiB;AAAA,IACjB,cAAc;AAAA,IACd,WAAW;AAAA,IACX,GAAG;AAAA,EAAA,IACD,gBAAgB,aAAa,KAAK;AAEtC,QAAM,EAAE,SAAS,GAAG,IAAI,WAAW,WAAW;AACxC,QAAA,UAAU,WAAW,WAAW;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAED,MAAI,YAAY,UAAkB,QAAA,oBAAA,UAAA,EAAG,UAAQ,QAAA,CAAA;AAE7C,SACG,oBAAA,WAAA,EAAU,KAAU,WAAW,GAAG,QAAQ,MAAM,SAAS,GAAI,GAAG,QAC9D,UAAC,CAAA,YAAY,eAAe,QAC/B,CAAA;AAEJ,CAAC;"}
|