@hitachivantara/uikit-react-core 5.91.0 → 5.91.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/BaseRadio/BaseRadio.styles.cjs +3 -3
- package/dist/cjs/Button/Button.styles.cjs +2 -2
- package/dist/cjs/DotPagination/DotPagination.styles.cjs +3 -2
- package/dist/cjs/Focus/Focus.cjs +10 -25
- package/dist/cjs/Focus/Focus.styles.cjs +0 -17
- package/dist/cjs/InlineEditor/InlineEditor.cjs +1 -1
- package/dist/esm/BaseRadio/BaseRadio.styles.js +3 -3
- package/dist/esm/BaseRadio/BaseRadio.styles.js.map +1 -1
- package/dist/esm/Button/Button.styles.js +2 -2
- package/dist/esm/Button/Button.styles.js.map +1 -1
- package/dist/esm/DotPagination/DotPagination.styles.js +3 -2
- package/dist/esm/DotPagination/DotPagination.styles.js.map +1 -1
- package/dist/esm/Focus/Focus.js +10 -25
- package/dist/esm/Focus/Focus.js.map +1 -1
- package/dist/esm/Focus/Focus.styles.js +0 -17
- package/dist/esm/Focus/Focus.styles.js.map +1 -1
- package/dist/esm/InlineEditor/InlineEditor.js +1 -1
- package/dist/esm/InlineEditor/InlineEditor.js.map +1 -1
- package/dist/types/index.d.ts +4 -6
- package/package.json +6 -6
- package/dist/cjs/utils/ConditionalWrapper.cjs +0 -8
- package/dist/esm/utils/ConditionalWrapper.js +0 -8
- package/dist/esm/utils/ConditionalWrapper.js.map +0 -1
|
@@ -10,6 +10,7 @@ const { staticClasses, useClasses } = uikitReactUtils.createClasses("HvBaseRadio
|
|
|
10
10
|
minWidth: 32,
|
|
11
11
|
height: 32,
|
|
12
12
|
cursor: "pointer",
|
|
13
|
+
borderRadius: "inherit",
|
|
13
14
|
"& svg": {
|
|
14
15
|
width: 16,
|
|
15
16
|
height: 16,
|
|
@@ -17,9 +18,8 @@ const { staticClasses, useClasses } = uikitReactUtils.createClasses("HvBaseRadio
|
|
|
17
18
|
border: `1px solid ${uikitStyles.theme.colors.borderStrong}`,
|
|
18
19
|
backgroundColor: uikitStyles.theme.colors.bgContainer
|
|
19
20
|
},
|
|
20
|
-
"
|
|
21
|
-
backgroundColor: uikitStyles.theme.colors.bgHover
|
|
22
|
-
borderRadius: uikitStyles.theme.radii.round
|
|
21
|
+
":hover": {
|
|
22
|
+
backgroundColor: uikitStyles.theme.colors.bgHover
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
disabled: {
|
|
@@ -70,10 +70,10 @@ const { staticClasses, useClasses } = uikitReactUtils.createClasses("HvButton",
|
|
|
70
70
|
backgroundColor: "var(--color)",
|
|
71
71
|
":where(:not($disabled))": {
|
|
72
72
|
":hover, :focus-visible": {
|
|
73
|
-
backgroundColor:
|
|
73
|
+
backgroundColor: uikitStyles.theme.mix("var(--color)", 0.8, "black")
|
|
74
74
|
},
|
|
75
75
|
":active": {
|
|
76
|
-
backgroundColor:
|
|
76
|
+
backgroundColor: uikitStyles.theme.mix("var(--color)", 0.7, "black")
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
},
|
|
@@ -19,8 +19,9 @@ const { useClasses, staticClasses } = uikitReactUtils.createClasses("HvDotPagina
|
|
|
19
19
|
minWidth: 24,
|
|
20
20
|
minHeight: 24,
|
|
21
21
|
color: "inherit",
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
borderRadius: uikitStyles.theme.radii.full,
|
|
23
|
+
":hover,:focus-within": {
|
|
24
|
+
backgroundColor: uikitStyles.theme.colors.bgHover
|
|
24
25
|
}
|
|
25
26
|
},
|
|
26
27
|
icon: {
|
package/dist/cjs/Focus/Focus.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
4
3
|
const React = require("react");
|
|
5
4
|
const browser = require("../utils/browser.cjs");
|
|
6
|
-
const ConditionalWrapper = require("../utils/ConditionalWrapper.cjs");
|
|
7
5
|
const keyboardUtils = require("../utils/keyboardUtils.cjs");
|
|
8
6
|
const Focus_styles = require("./Focus.styles.cjs");
|
|
9
7
|
const utils = require("./utils.cjs");
|
|
@@ -18,11 +16,9 @@ const HvFocus = ({
|
|
|
18
16
|
focusOnClick = false,
|
|
19
17
|
focusDisabled = true,
|
|
20
18
|
strategy = "listbox",
|
|
21
|
-
useFalseFocus = false,
|
|
22
19
|
filterClass,
|
|
23
20
|
navigationJump = 4
|
|
24
21
|
}) => {
|
|
25
|
-
const [showFocus, setShowFocus] = React.useState(false);
|
|
26
22
|
const [childFocus, setChildFocus] = React.useState();
|
|
27
23
|
const [hasRunConfig, setHasRunConfig] = React.useState(false);
|
|
28
24
|
const { classes, cx } = Focus_styles.useClasses(classesProp);
|
|
@@ -88,29 +84,23 @@ const HvFocus = ({
|
|
|
88
84
|
setHasRunConfig(true);
|
|
89
85
|
};
|
|
90
86
|
const addFocusClass = (evt) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
classes?.focus?.split(" ").forEach((c) => evt.currentTarget.classList.add(c));
|
|
95
|
-
}
|
|
87
|
+
classes.focused.split(" ").forEach((c) => evt.currentTarget.classList.add(c));
|
|
88
|
+
evt.currentTarget.classList.add("HvIsFocused");
|
|
89
|
+
classes?.focus?.split(" ").forEach((c) => evt.currentTarget.classList.add(c));
|
|
96
90
|
};
|
|
97
91
|
const removeFocusClass = () => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
-
}
|
|
92
|
+
getFocuses().forEach((element) => {
|
|
93
|
+
classes.focused.split(" ").forEach((c) => element.classList.remove(c));
|
|
94
|
+
element.classList.remove("HvIsFocused");
|
|
95
|
+
classes?.focus?.split(" ").forEach((c) => element.classList.remove(c));
|
|
96
|
+
});
|
|
105
97
|
};
|
|
106
98
|
const onFocus = (evt) => {
|
|
107
99
|
addFocusClass(evt);
|
|
108
|
-
setShowFocus(true);
|
|
109
100
|
childFocus?.focus?.();
|
|
110
101
|
onFocusStrategy(evt);
|
|
111
102
|
};
|
|
112
103
|
const onBlur = () => {
|
|
113
|
-
setShowFocus(false);
|
|
114
104
|
removeFocusClass();
|
|
115
105
|
onBlurStrategy();
|
|
116
106
|
};
|
|
@@ -121,7 +111,6 @@ const HvFocus = ({
|
|
|
121
111
|
setTabIndex(evt.currentTarget, 0);
|
|
122
112
|
if (!focusOnClick) {
|
|
123
113
|
removeFocusClass();
|
|
124
|
-
setShowFocus(false);
|
|
125
114
|
}
|
|
126
115
|
};
|
|
127
116
|
const focusAndUpdateIndex = (nextFocus, previousFocus, focusesList) => {
|
|
@@ -297,11 +286,7 @@ const HvFocus = ({
|
|
|
297
286
|
if (browser.isBrowser("firefox")) evt.preventDefault();
|
|
298
287
|
};
|
|
299
288
|
if (disabled) return children;
|
|
300
|
-
|
|
301
|
-
childrenToWrap,
|
|
302
|
-
showFocus && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.falseFocus })
|
|
303
|
-
] });
|
|
304
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ConditionalWrapper.ConditionalWrapper, { condition: useFalseFocus, wrapper: focusWrapper, children: React.cloneElement(children, {
|
|
289
|
+
return React.cloneElement(children, {
|
|
305
290
|
className: cx(
|
|
306
291
|
[classes.root, filterClass],
|
|
307
292
|
{
|
|
@@ -318,7 +303,7 @@ const HvFocus = ({
|
|
|
318
303
|
onKeyDown,
|
|
319
304
|
onKeyUp,
|
|
320
305
|
selected
|
|
321
|
-
})
|
|
306
|
+
});
|
|
322
307
|
};
|
|
323
308
|
exports.focusClasses = Focus_styles.staticClasses;
|
|
324
309
|
exports.HvFocus = HvFocus;
|
|
@@ -21,23 +21,6 @@ const { staticClasses, useClasses } = uikitReactUtils.createClasses("HvFocus", {
|
|
|
21
21
|
...focusUtils.outlineStyles
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
externalReference: {
|
|
25
|
-
position: "relative"
|
|
26
|
-
},
|
|
27
|
-
falseFocus: {
|
|
28
|
-
width: "98%",
|
|
29
|
-
height: "98%",
|
|
30
|
-
position: "absolute",
|
|
31
|
-
zIndex: "1",
|
|
32
|
-
...focusUtils.outlineStyles,
|
|
33
|
-
"@media (-webkit-min-device-pixel-ratio:0)": {
|
|
34
|
-
...focusUtils.outlineStyles
|
|
35
|
-
},
|
|
36
|
-
top: 0,
|
|
37
|
-
left: "0.5%",
|
|
38
|
-
backgroundColor: "transparent",
|
|
39
|
-
pointerEvents: "none"
|
|
40
|
-
},
|
|
41
24
|
focus: {}
|
|
42
25
|
});
|
|
43
26
|
exports.staticClasses = staticClasses;
|
|
@@ -8,6 +8,7 @@ const { staticClasses, useClasses } = createClasses("HvBaseRadio", {
|
|
|
8
8
|
minWidth: 32,
|
|
9
9
|
height: 32,
|
|
10
10
|
cursor: "pointer",
|
|
11
|
+
borderRadius: "inherit",
|
|
11
12
|
"& svg": {
|
|
12
13
|
width: 16,
|
|
13
14
|
height: 16,
|
|
@@ -15,9 +16,8 @@ const { staticClasses, useClasses } = createClasses("HvBaseRadio", {
|
|
|
15
16
|
border: `1px solid ${theme.colors.borderStrong}`,
|
|
16
17
|
backgroundColor: theme.colors.bgContainer
|
|
17
18
|
},
|
|
18
|
-
"
|
|
19
|
-
backgroundColor: theme.colors.bgHover
|
|
20
|
-
borderRadius: theme.radii.round
|
|
19
|
+
":hover": {
|
|
20
|
+
backgroundColor: theme.colors.bgHover
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
disabled: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseRadio.styles.js","sources":["../../../src/BaseRadio/BaseRadio.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { outlineStyles } from \"../utils/focusUtils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvBaseRadio\", {\n root: {\n padding: 0,\n width: 32,\n minWidth: 32,\n height: 32,\n cursor: \"pointer\",\n \"& svg\": {\n width: 16,\n height: 16,\n borderRadius: theme.radii.full,\n border: `1px solid ${theme.colors.borderStrong}`,\n backgroundColor: theme.colors.bgContainer,\n },\n \"
|
|
1
|
+
{"version":3,"file":"BaseRadio.styles.js","sources":["../../../src/BaseRadio/BaseRadio.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nimport { outlineStyles } from \"../utils/focusUtils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvBaseRadio\", {\n root: {\n padding: 0,\n width: 32,\n minWidth: 32,\n height: 32,\n cursor: \"pointer\",\n borderRadius: \"inherit\",\n \"& svg\": {\n width: 16,\n height: 16,\n borderRadius: theme.radii.full,\n border: `1px solid ${theme.colors.borderStrong}`,\n backgroundColor: theme.colors.bgContainer,\n },\n \":hover\": {\n backgroundColor: theme.colors.bgHover,\n },\n },\n disabled: {\n cursor: \"not-allowed\",\n pointerEvents: \"initial\",\n \"& svg\": {\n borderColor: theme.colors.textDisabled,\n backgroundColor: theme.colors.bgDisabled,\n },\n },\n focusVisible: {\n \"& svg\": {\n borderRadius: theme.radii.full,\n ...outlineStyles,\n },\n },\n icon: {},\n checked: {\n \"& svg\": {\n borderColor: \"transparent\",\n backgroundColor: theme.colors.primaryStrong,\n color: theme.colors.bgContainer,\n },\n \"&$disabled\": {\n \"& svg\": {\n borderColor: \"transparent\",\n backgroundColor: theme.colors.borderDisabled,\n color: theme.colors.bgDisabled,\n },\n },\n },\n semantic: {},\n});\n"],"names":[],"mappings":";;;AAKO,MAAM,EAAE,eAAe,eAAe,cAAc,eAAe;AAAA,EACxE,MAAM;AAAA,IACJ,SAAS;AAAA,IACT,OAAO;AAAA,IACP,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,cAAc;AAAA,IACd,SAAS;AAAA,MACP,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,cAAc,MAAM,MAAM;AAAA,MAC1B,QAAQ,aAAa,MAAM,OAAO,YAAY;AAAA,MAC9C,iBAAiB,MAAM,OAAO;AAAA,IAChC;AAAA,IACA,UAAU;AAAA,MACR,iBAAiB,MAAM,OAAO;AAAA,IAAA;AAAA,EAElC;AAAA,EACA,UAAU;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,SAAS;AAAA,MACP,aAAa,MAAM,OAAO;AAAA,MAC1B,iBAAiB,MAAM,OAAO;AAAA,IAAA;AAAA,EAElC;AAAA,EACA,cAAc;AAAA,IACZ,SAAS;AAAA,MACP,cAAc,MAAM,MAAM;AAAA,MAC1B,GAAG;AAAA,IAAA;AAAA,EAEP;AAAA,EACA,MAAM,CAAC;AAAA,EACP,SAAS;AAAA,IACP,SAAS;AAAA,MACP,aAAa;AAAA,MACb,iBAAiB,MAAM,OAAO;AAAA,MAC9B,OAAO,MAAM,OAAO;AAAA,IACtB;AAAA,IACA,cAAc;AAAA,MACZ,SAAS;AAAA,QACP,aAAa;AAAA,QACb,iBAAiB,MAAM,OAAO;AAAA,QAC9B,OAAO,MAAM,OAAO;AAAA,MAAA;AAAA,IACtB;AAAA,EAEJ;AAAA,EACA,UAAU,CAAA;AACZ,CAAC;"}
|
|
@@ -68,10 +68,10 @@ const { staticClasses, useClasses } = createClasses("HvButton", {
|
|
|
68
68
|
backgroundColor: "var(--color)",
|
|
69
69
|
":where(:not($disabled))": {
|
|
70
70
|
":hover, :focus-visible": {
|
|
71
|
-
backgroundColor:
|
|
71
|
+
backgroundColor: theme.mix("var(--color)", 0.8, "black")
|
|
72
72
|
},
|
|
73
73
|
":active": {
|
|
74
|
-
backgroundColor:
|
|
74
|
+
backgroundColor: theme.mix("var(--color)", 0.7, "black")
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.styles.js","sources":["../../../src/Button/Button.styles.ts"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme, type HvSize } from \"@hitachivantara/uikit-styles\";\n\nimport { outlineStyles } from \"../utils/focusUtils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvButton\", {\n /** applied to the root element */\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 \":where(:not($disabled))\": {\n \":hover, :focus-visible\": {\n backgroundColor: theme.colors.bgHover,\n },\n },\n \":focus-visible\": {\n ...outlineStyles,\n },\n\n // Default button - no size specified\n fontFamily: theme.fontFamily.body,\n ...theme.typography.label,\n color: \"var(--color, currentcolor)\",\n backgroundColor: \"transparent\",\n height: \"var(--HvButton-height, fit-content)\",\n border: \"1px solid transparent\",\n borderRadius: `var(--radius, ${theme.radii.base})`,\n padding: theme.spacing(0, \"sm\"),\n\n \"& $startIcon, & $endIcon\": {\n flexShrink: 0,\n lineHeight: 0,\n marginTop: -1,\n marginBottom: -1,\n },\n },\n /** applied to the _left_ icon container */\n startIcon: {\n marginLeft: theme.spacing(-1),\n },\n /** applied to the _right_ icon container */\n endIcon: {\n marginRight: theme.spacing(-1),\n },\n focusVisible: {},\n /** applied to the root element when disabled */\n disabled: {\n cursor: \"not-allowed\",\n color: theme.colors.textDisabled,\n backgroundColor: \"transparent\",\n borderColor: \"transparent\",\n \":hover, :focus-visible\": {\n backgroundColor: \"transparent\",\n borderColor: \"transparent\",\n },\n },\n /** applied to the root element when is icon-only */\n icon: {\n margin: 0,\n padding: 0,\n width: \"var(--HvButton-height, fit-content)\",\n },\n /** applied to the root element when using the `contained` variant */\n contained: {\n color: theme.colors.textDimmed, // `color-contrast(var(--color) vs ${colors.textDimmed}, ${colors.textLight}, ${colors.textDark})`,\n backgroundColor: \"var(--color)\",\n \":where(:not($disabled))\": {\n \":hover, :focus-visible\": {\n backgroundColor: \"
|
|
1
|
+
{"version":3,"file":"Button.styles.js","sources":["../../../src/Button/Button.styles.ts"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme, type HvSize } from \"@hitachivantara/uikit-styles\";\n\nimport { outlineStyles } from \"../utils/focusUtils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvButton\", {\n /** applied to the root element */\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 \":where(:not($disabled))\": {\n \":hover, :focus-visible\": {\n backgroundColor: theme.colors.bgHover,\n },\n },\n \":focus-visible\": {\n ...outlineStyles,\n },\n\n // Default button - no size specified\n fontFamily: theme.fontFamily.body,\n ...theme.typography.label,\n color: \"var(--color, currentcolor)\",\n backgroundColor: \"transparent\",\n height: \"var(--HvButton-height, fit-content)\",\n border: \"1px solid transparent\",\n borderRadius: `var(--radius, ${theme.radii.base})`,\n padding: theme.spacing(0, \"sm\"),\n\n \"& $startIcon, & $endIcon\": {\n flexShrink: 0,\n lineHeight: 0,\n marginTop: -1,\n marginBottom: -1,\n },\n },\n /** applied to the _left_ icon container */\n startIcon: {\n marginLeft: theme.spacing(-1),\n },\n /** applied to the _right_ icon container */\n endIcon: {\n marginRight: theme.spacing(-1),\n },\n focusVisible: {},\n /** applied to the root element when disabled */\n disabled: {\n cursor: \"not-allowed\",\n color: theme.colors.textDisabled,\n backgroundColor: \"transparent\",\n borderColor: \"transparent\",\n \":hover, :focus-visible\": {\n backgroundColor: \"transparent\",\n borderColor: \"transparent\",\n },\n },\n /** applied to the root element when is icon-only */\n icon: {\n margin: 0,\n padding: 0,\n width: \"var(--HvButton-height, fit-content)\",\n },\n /** applied to the root element when using the `contained` variant */\n contained: {\n color: theme.colors.textDimmed, // `color-contrast(var(--color) vs ${colors.textDimmed}, ${colors.textLight}, ${colors.textDark})`,\n backgroundColor: \"var(--color)\",\n \":where(:not($disabled))\": {\n \":hover, :focus-visible\": {\n backgroundColor: theme.mix(\"var(--color)\", 0.8, \"black\"),\n },\n \":active\": {\n backgroundColor: theme.mix(\"var(--color)\", 0.7, \"black\"),\n },\n },\n },\n /** applied to the root element when using the `subtle` variant */\n subtle: {\n borderColor: \"currentcolor\",\n },\n /** applied to the root element when using the `ghost` variant */\n ghost: {},\n /** applied to the root element when using the `semantic` variant */\n semantic: {\n color: theme.colors.textDark,\n backgroundColor: \"transparent\",\n borderColor: \"transparent\",\n \"&:hover, &:focus-visible\": {\n backgroundColor: theme.alpha(\"textLight\", 0.3),\n },\n \"&:active\": {\n backgroundColor: theme.alpha(\"textLight\", 0.5),\n },\n \"&$disabled\": {\n backgroundColor: theme.alpha(\"textLight\", 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\n// TODO - remove xs and xl in v6 since they are not DS spec\nconst sizes: Record<\n HvSize,\n { height: string; space?: HvSize; fontSize?: keyof typeof theme.fontSizes }\n> = {\n xs: { height: \"24px\", fontSize: \"sm\" },\n sm: { height: \"24px\", fontSize: \"sm\" },\n md: { height: \"32px\" },\n lg: { height: \"48px\", space: \"md\" },\n xl: { height: \"48px\", space: \"md\" },\n};\n\nexport const getSizeStyles = (size: HvSize) => {\n const { height, space = \"sm\", fontSize } = sizes[size];\n return {\n height,\n padding: theme.spacing(0, space),\n fontSize: fontSize && theme.fontSizes[fontSize],\n };\n};\n\nexport const getIconSizeStyles = (size: HvSize) => {\n const { height } = sizes[size];\n return {\n height,\n width: height,\n };\n};\n"],"names":[],"mappings":";;;AAKO,MAAM,EAAE,eAAe,eAAe,cAAc,YAAY;AAAA;AAAA,EAErE,MAAM;AAAA,IACJ,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,eAAe;AAAA,IACf,QAAQ;AAAA,IAC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17,8 +17,9 @@ const { useClasses, staticClasses } = createClasses("HvDotPagination", {
|
|
|
17
17
|
minWidth: 24,
|
|
18
18
|
minHeight: 24,
|
|
19
19
|
color: "inherit",
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
borderRadius: theme.radii.full,
|
|
21
|
+
":hover,:focus-within": {
|
|
22
|
+
backgroundColor: theme.colors.bgHover
|
|
22
23
|
}
|
|
23
24
|
},
|
|
24
25
|
icon: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DotPagination.styles.js","sources":["../../../src/DotPagination/DotPagination.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { useClasses, staticClasses } = createClasses(\"HvDotPagination\", {\n root: {\n display: \"flex\",\n justifyContent: \"center\",\n },\n\n horizontal: {\n width: \"auto\",\n gap: theme.space.xs,\n },\n /** @deprecated use `classes.radio` instead */\n radioRoot: {},\n\n radio: {\n height: 16,\n width: 16,\n minWidth: 24,\n minHeight: 24,\n color: \"inherit\",\n\n \"
|
|
1
|
+
{"version":3,"file":"DotPagination.styles.js","sources":["../../../src/DotPagination/DotPagination.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { useClasses, staticClasses } = createClasses(\"HvDotPagination\", {\n root: {\n display: \"flex\",\n justifyContent: \"center\",\n },\n\n horizontal: {\n width: \"auto\",\n gap: theme.space.xs,\n },\n /** @deprecated use `classes.radio` instead */\n radioRoot: {},\n\n radio: {\n height: 16,\n width: 16,\n minWidth: 24,\n minHeight: 24,\n color: \"inherit\",\n borderRadius: theme.radii.full,\n\n \":hover,:focus-within\": {\n backgroundColor: theme.colors.bgHover,\n },\n },\n\n icon: {\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n minWidth: 0,\n width: 16,\n height: 16,\n color: \"inherit\",\n \"&& svg\": {\n color: \"inherit\",\n border: \"none\",\n width: \"unset\",\n height: \"unset\",\n },\n \"& > div\": {\n color: theme.colors.text,\n backgroundColor: \"currentcolor\",\n width: \"1em\",\n height: \"1em\",\n borderRadius: \"50%\",\n },\n },\n});\n"],"names":[],"mappings":";;AAGO,MAAM,EAAE,YAAY,kBAAkB,cAAc,mBAAmB;AAAA,EAC5E,MAAM;AAAA,IACJ,SAAS;AAAA,IACT,gBAAgB;AAAA,EAClB;AAAA,EAEA,YAAY;AAAA,IACV,OAAO;AAAA,IACP,KAAK,MAAM,MAAM;AAAA,EACnB;AAAA;AAAA,EAEA,WAAW,CAAC;AAAA,EAEZ,OAAO;AAAA,IACL,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,UAAU;AAAA,IACV,WAAW;AAAA,IACX,OAAO;AAAA,IACP,cAAc,MAAM,MAAM;AAAA,IAE1B,wBAAwB;AAAA,MACtB,iBAAiB,MAAM,OAAO;AAAA,IAAA;AAAA,EAElC;AAAA,EAEA,MAAM;AAAA,IACJ,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,UAAU;AAAA,IACV,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,UAAU;AAAA,MACR,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,QAAQ;AAAA,IACV;AAAA,IACA,WAAW;AAAA,MACT,OAAO,MAAM,OAAO;AAAA,MACpB,iBAAiB;AAAA,MACjB,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,cAAc;AAAA,IAAA;AAAA,EAChB;AAEJ,CAAC;"}
|
package/dist/esm/Focus/Focus.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { useState, cloneElement } from "react";
|
|
3
2
|
import { isBrowser } from "../utils/browser.js";
|
|
4
|
-
import { ConditionalWrapper } from "../utils/ConditionalWrapper.js";
|
|
5
3
|
import { isOneOfKeys, isKey } from "../utils/keyboardUtils.js";
|
|
6
4
|
import { useClasses, staticClasses } from "./Focus.styles.js";
|
|
7
5
|
import { setFocusTo, getFocusableChildren } from "./utils.js";
|
|
@@ -16,11 +14,9 @@ const HvFocus = ({
|
|
|
16
14
|
focusOnClick = false,
|
|
17
15
|
focusDisabled = true,
|
|
18
16
|
strategy = "listbox",
|
|
19
|
-
useFalseFocus = false,
|
|
20
17
|
filterClass,
|
|
21
18
|
navigationJump = 4
|
|
22
19
|
}) => {
|
|
23
|
-
const [showFocus, setShowFocus] = useState(false);
|
|
24
20
|
const [childFocus, setChildFocus] = useState();
|
|
25
21
|
const [hasRunConfig, setHasRunConfig] = useState(false);
|
|
26
22
|
const { classes, cx } = useClasses(classesProp);
|
|
@@ -86,29 +82,23 @@ const HvFocus = ({
|
|
|
86
82
|
setHasRunConfig(true);
|
|
87
83
|
};
|
|
88
84
|
const addFocusClass = (evt) => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
classes?.focus?.split(" ").forEach((c) => evt.currentTarget.classList.add(c));
|
|
93
|
-
}
|
|
85
|
+
classes.focused.split(" ").forEach((c) => evt.currentTarget.classList.add(c));
|
|
86
|
+
evt.currentTarget.classList.add("HvIsFocused");
|
|
87
|
+
classes?.focus?.split(" ").forEach((c) => evt.currentTarget.classList.add(c));
|
|
94
88
|
};
|
|
95
89
|
const removeFocusClass = () => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
}
|
|
90
|
+
getFocuses().forEach((element) => {
|
|
91
|
+
classes.focused.split(" ").forEach((c) => element.classList.remove(c));
|
|
92
|
+
element.classList.remove("HvIsFocused");
|
|
93
|
+
classes?.focus?.split(" ").forEach((c) => element.classList.remove(c));
|
|
94
|
+
});
|
|
103
95
|
};
|
|
104
96
|
const onFocus = (evt) => {
|
|
105
97
|
addFocusClass(evt);
|
|
106
|
-
setShowFocus(true);
|
|
107
98
|
childFocus?.focus?.();
|
|
108
99
|
onFocusStrategy(evt);
|
|
109
100
|
};
|
|
110
101
|
const onBlur = () => {
|
|
111
|
-
setShowFocus(false);
|
|
112
102
|
removeFocusClass();
|
|
113
103
|
onBlurStrategy();
|
|
114
104
|
};
|
|
@@ -119,7 +109,6 @@ const HvFocus = ({
|
|
|
119
109
|
setTabIndex(evt.currentTarget, 0);
|
|
120
110
|
if (!focusOnClick) {
|
|
121
111
|
removeFocusClass();
|
|
122
|
-
setShowFocus(false);
|
|
123
112
|
}
|
|
124
113
|
};
|
|
125
114
|
const focusAndUpdateIndex = (nextFocus, previousFocus, focusesList) => {
|
|
@@ -295,11 +284,7 @@ const HvFocus = ({
|
|
|
295
284
|
if (isBrowser("firefox")) evt.preventDefault();
|
|
296
285
|
};
|
|
297
286
|
if (disabled) return children;
|
|
298
|
-
|
|
299
|
-
childrenToWrap,
|
|
300
|
-
showFocus && /* @__PURE__ */ jsx("div", { className: classes.falseFocus })
|
|
301
|
-
] });
|
|
302
|
-
return /* @__PURE__ */ jsx(ConditionalWrapper, { condition: useFalseFocus, wrapper: focusWrapper, children: cloneElement(children, {
|
|
287
|
+
return cloneElement(children, {
|
|
303
288
|
className: cx(
|
|
304
289
|
[classes.root, filterClass],
|
|
305
290
|
{
|
|
@@ -316,7 +301,7 @@ const HvFocus = ({
|
|
|
316
301
|
onKeyDown,
|
|
317
302
|
onKeyUp,
|
|
318
303
|
selected
|
|
319
|
-
})
|
|
304
|
+
});
|
|
320
305
|
};
|
|
321
306
|
export {
|
|
322
307
|
HvFocus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Focus.js","sources":["../../../src/Focus/Focus.tsx"],"sourcesContent":["import { cloneElement, useState } from \"react\";\nimport { type ExtractNames } from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseProps } from \"../types/generic\";\nimport { isBrowser } from \"../utils/browser\";\nimport { ConditionalWrapper } from \"../utils/ConditionalWrapper\";\nimport { isKey, isOneOfKeys } from \"../utils/keyboardUtils\";\nimport { staticClasses, useClasses } from \"./Focus.styles\";\nimport { getFocusableChildren, setFocusTo } from \"./utils\";\n\nexport { staticClasses as focusClasses };\nexport type HvFocusClasses = ExtractNames<typeof useClasses>;\n\nexport type HvFocusStrategies = \"listbox\" | \"menu\" | \"card\" | \"grid\";\n\nexport interface HvFocusProps extends HvBaseProps<HTMLElement, \"children\"> {\n children: React.ReactElement;\n /** Extra configuration for the child element. */\n configuration?: {\n tabIndex?: number;\n };\n /** Indicates that the disabled class should be applied. */\n disabledClass?: boolean;\n /** Whether the focus is selected. */\n selected?: boolean;\n /** Whether the focus is disabled. */\n disabled?: boolean;\n /** The reference to the root element to hold all Focus' context. */\n rootRef?: React.RefObject<HTMLElement>;\n /** Show focus when click element. v */\n focusOnClick?: boolean;\n /** Show focus when click element. v */\n focusDisabled?: boolean;\n /** Focus and navigation strategy to be used. v */\n strategy?: HvFocusStrategies;\n /** Uses an absolute positioned div as a focus. v */\n useFalseFocus?: boolean;\n /** Narrows the results of the focus to only theses class v */\n filterClass?: string;\n /** How much the navigation will skip when using the arrows. v */\n navigationJump?: number;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFocusClasses;\n}\n\ninterface Focuses {\n first: Element;\n last: Element;\n previous: Element;\n next: Element;\n fall: Element;\n jump: Element;\n}\n\n/** @deprecated internal use only. this component has navigation issues. */\nexport const HvFocus = ({\n classes: classesProp,\n children,\n configuration = {},\n disabledClass = false,\n selected = false,\n disabled = false,\n rootRef = undefined,\n focusOnClick = false,\n focusDisabled = true,\n strategy = \"listbox\",\n useFalseFocus = false,\n filterClass,\n navigationJump = 4,\n}: HvFocusProps) => {\n const [showFocus, setShowFocus] = useState<boolean>(false);\n const [childFocus, setChildFocus] = useState<any>();\n const [hasRunConfig, setHasRunConfig] = useState(false);\n const { classes, cx } = useClasses(classesProp);\n\n const getFocuses = () => {\n const focuses = rootRef?.current\n ? Array.from(\n rootRef.current.getElementsByClassName(\n filterClass || staticClasses.root || \"root\",\n ),\n )\n : [];\n return focuses;\n };\n\n const setTabIndex = (el: any, tabIndex = 0) => {\n if (!el) return;\n const elChildFocus = getFocusableChildren(el)[0];\n if (elChildFocus) {\n el.tabIndex = -1;\n elChildFocus.tabIndex = tabIndex;\n } else {\n el.tabIndex = tabIndex;\n }\n };\n\n const setSelectedTabIndex = () => {\n const focuses = getFocuses();\n const firstSelected = focuses.find((focus) =>\n focus.classList.contains(classes.selected || \"selected\"),\n );\n\n if (!firstSelected) return;\n focuses.forEach((focus) => setTabIndex(focus, -1));\n setTabIndex(firstSelected, 0);\n };\n\n const clearTabSiblings = (el: any) => {\n getFocuses().forEach((focus) => setTabIndex(focus, -1));\n setTabIndex(el, 0);\n };\n\n const onFocusStrategy = (evt: any) => {\n if (strategy === \"listbox\") {\n clearTabSiblings(evt.currentTarget);\n }\n };\n\n const onBlurStrategy = () => {\n if (\n strategy === \"listbox\" &&\n rootRef &&\n rootRef.current &&\n !rootRef.current.contains(document.activeElement)\n ) {\n setTimeout(() => {\n setSelectedTabIndex();\n }, 10);\n }\n };\n\n const config = (el: any) => {\n const { tabIndex } = configuration;\n if (!el || hasRunConfig) return;\n if (strategy === \"card\") {\n setChildFocus(children);\n return;\n }\n\n if (strategy === \"grid\") {\n return;\n }\n\n const focusableChildren = getFocusableChildren(el);\n if (focusableChildren.length) {\n focusableChildren.forEach((child: any) => setTabIndex(child, -1));\n setChildFocus(focusableChildren[0]);\n }\n\n if (tabIndex != null) setTabIndex(el, tabIndex);\n setHasRunConfig(true);\n };\n\n const addFocusClass = (evt: any) => {\n if (!useFalseFocus) {\n // evt.currentTarget.classList.add(classes.focused);\n classes.focused\n .split(\" \")\n .forEach((c) => evt.currentTarget.classList.add(c));\n // add global class HvIsFocused as a marker\n // not to be styled directly, only as helper in specific css queries\n evt.currentTarget.classList.add(\"HvIsFocused\");\n classes?.focus\n ?.split(\" \")\n .forEach((c) => evt.currentTarget.classList.add(c));\n }\n };\n\n const removeFocusClass = () => {\n if (!useFalseFocus) {\n getFocuses().forEach((element) => {\n // element.classList.remove(classes.focused);\n classes.focused.split(\" \").forEach((c) => element.classList.remove(c));\n // remove the global class HvIsFocused\n element.classList.remove(\"HvIsFocused\");\n classes?.focus?.split(\" \").forEach((c) => element.classList.remove(c));\n });\n }\n };\n\n const onFocus = (evt: any) => {\n addFocusClass(evt);\n setShowFocus(true);\n // give focus to child element if any focusable\n\n childFocus?.focus?.();\n onFocusStrategy(evt);\n };\n\n const onBlur = () => {\n setShowFocus(false);\n removeFocusClass();\n onBlurStrategy();\n };\n\n const onMouseDown = (evt: any) => {\n const hasCard = !!evt.currentTarget?.querySelector(\".HvIsCardGridElement\");\n if (strategy === \"grid\" && hasCard) return;\n\n setFocusTo(evt.currentTarget);\n setTabIndex(evt.currentTarget, 0);\n // remove focus outline unless explicitly enabled\n if (!focusOnClick) {\n // TODO this piece of code works only because onMouseDown is happening after the focus event\n // There is nothing in here that guarantees the order of these events, so it may present a problem in the future\n removeFocusClass();\n setShowFocus(false);\n }\n };\n\n const focusAndUpdateIndex = (\n nextFocus: Element,\n previousFocus: any,\n focusesList: Element[],\n ) => {\n if (focusesList?.includes(previousFocus)) {\n setTabIndex(previousFocus, -1);\n }\n setTabIndex(nextFocus, 0);\n setFocusTo(nextFocus);\n };\n\n const getEnabledKeys = (\n currentFocusIndex: number,\n jump: number,\n listSize: number,\n ) => ({\n right:\n (currentFocusIndex + 1) % jump === 0 ||\n currentFocusIndex + 1 > listSize - 1,\n left: currentFocusIndex % jump === 0,\n up: currentFocusIndex - jump < 0,\n down:\n currentFocusIndex + jump > listSize ||\n currentFocusIndex + jump > listSize - 1,\n });\n\n const onGridKeyDownHandler = (\n evt: any,\n focuses: Focuses,\n focusesList: Element[],\n currentFocusIndex: number,\n jump: number,\n ) => {\n const childFocusIsInput = childFocus && childFocus.nodeName === \"INPUT\";\n\n if (\n !isOneOfKeys(evt, [\n \"ArrowUp\",\n \"ArrowDown\",\n \"ArrowLeft\",\n \"ArrowRight\",\n \"Home\",\n \"End\",\n \"Space\",\n \"Enter\",\n ]) ||\n (childFocusIsInput && isKey(evt, \"Enter\"))\n ) {\n // nothing to do\n return;\n }\n\n // we'll do something with the key so prevent default and stop propagation\n // except for Enter and SpaceBar\n if (!isOneOfKeys(evt, [\"Enter\", \"Space\"])) {\n evt.preventDefault();\n evt.stopPropagation();\n }\n\n const blockedKeys = getEnabledKeys(\n currentFocusIndex,\n jump,\n focusesList.length,\n );\n\n switch (evt.code) {\n case \"Space\":\n case \"Enter\":\n if (isBrowser(\"firefox\")) {\n evt.target.click();\n } else {\n evt.currentTarget.click();\n }\n break;\n case \"ArrowUp\":\n if (!blockedKeys.up) {\n focusAndUpdateIndex(\n focuses.jump || focuses.last,\n evt.current,\n focusesList,\n );\n }\n break;\n case \"ArrowDown\":\n if (!blockedKeys.down) {\n focusAndUpdateIndex(\n focuses.fall || focuses.first,\n evt.current,\n focusesList,\n );\n }\n break;\n case \"ArrowLeft\":\n if (!blockedKeys.left) {\n focusAndUpdateIndex(\n focuses.previous || focuses.last,\n evt.current,\n focusesList,\n );\n }\n break;\n case \"ArrowRight\":\n if (!blockedKeys.right) {\n focusAndUpdateIndex(\n focuses.next || focuses.first,\n evt.current,\n focusesList,\n );\n }\n break;\n case \"Home\":\n focusAndUpdateIndex(focuses.first, evt.current, focusesList);\n break;\n case \"End\":\n focusAndUpdateIndex(focuses.last, evt.current, focusesList);\n break;\n default:\n }\n };\n\n const onVerticalArrangementHandler = (\n evt: any,\n focuses: Focuses,\n focusesList: Element[],\n ) => {\n const childFocusIsInput = childFocus && childFocus.nodeName === \"INPUT\";\n\n if (\n !isOneOfKeys(evt, [\n \"ArrowUp\",\n \"ArrowDown\",\n \"Home\",\n \"End\",\n \"Space\",\n \"Enter\",\n ]) ||\n (childFocusIsInput && isKey(evt, \"Enter\"))\n ) {\n // nothing to do\n return;\n }\n\n // we'll do something with the key so prevent default and stop propagation\n evt.preventDefault();\n evt.stopPropagation();\n\n switch (evt.code) {\n case \"Space\":\n case \"Enter\":\n evt.target.click();\n break;\n case \"ArrowUp\":\n focusAndUpdateIndex(\n focuses.previous || focuses.last,\n evt.current,\n focusesList,\n );\n break;\n case \"ArrowDown\":\n focusAndUpdateIndex(\n focuses.next || focuses.first,\n evt.current,\n focusesList,\n );\n break;\n case \"Home\":\n focusAndUpdateIndex(focuses.first, evt.current, focusesList);\n break;\n case \"End\":\n focusAndUpdateIndex(focuses.last, evt.current, focusesList);\n break;\n default:\n }\n };\n\n const onSingleHandler = (evt: any) => {\n const childFocusIsInput = childFocus && childFocus.nodeName === \"INPUT\";\n\n if (\n !isOneOfKeys(evt, [\"Space\", \"Enter\"]) ||\n (childFocusIsInput && isKey(evt, \"Enter\"))\n ) {\n // nothing to do\n return;\n }\n\n // we'll do something with the key so prevent default and stop propagation\n evt.preventDefault();\n evt.stopPropagation();\n\n evt.currentTarget.click();\n };\n\n const onKeyDown = (evt: any) => {\n if (rootRef?.current == null) {\n // operating outside of a composite widget\n // nothing to manage, just style and trigger clicks\n onSingleHandler(evt);\n return;\n }\n\n // TODO keep the smart default, but allow to explicitly override if disabled elements should be focusable\n const isDisabledFocusable = strategy === \"menu\";\n const focusesList = getFocuses().filter(\n (el) =>\n isDisabledFocusable ||\n !el.classList.contains(classes?.disabled as string),\n );\n\n const currentFocus = focusesList.indexOf(evt.currentTarget);\n\n const focuses: Focuses = {\n first: focusesList[0],\n last: focusesList[focusesList.length - 1],\n previous: focusesList[currentFocus - 1],\n next: focusesList[currentFocus + 1],\n fall: focusesList[currentFocus + navigationJump],\n jump: focusesList[currentFocus - navigationJump],\n };\n\n if (strategy === \"grid\") {\n onGridKeyDownHandler(\n evt,\n focuses,\n focusesList,\n currentFocus,\n navigationJump,\n );\n return;\n }\n\n // TODO add property for specifying the composite widget orientation\n // TODO implement handler for horizontal orientation\n onVerticalArrangementHandler(evt, focuses, focusesList);\n };\n\n const onKeyUp = (evt: any) => {\n if (isBrowser(\"firefox\")) evt.preventDefault();\n };\n\n if (disabled) return children;\n\n const focusWrapper = (childrenToWrap: React.ReactNode) => (\n <div className={classes.externalReference}>\n {childrenToWrap}\n {showFocus && <div className={classes.falseFocus} />}\n </div>\n );\n\n return (\n <ConditionalWrapper condition={useFalseFocus} wrapper={focusWrapper}>\n {cloneElement(children, {\n className: cx(\n [classes.root, filterClass],\n {\n [classes.selected]: selected,\n [classes.disabled]: disabledClass,\n [classes.focusDisabled]: focusDisabled,\n },\n children.props.className,\n ),\n ref: config,\n onFocus,\n onBlur,\n onMouseDown,\n onKeyDown,\n onKeyUp,\n selected,\n })}\n </ConditionalWrapper>\n );\n};\n"],"names":[],"mappings":";;;;;;;AAuDO,MAAM,UAAU,CAAC;AAAA,EACtB,SAAS;AAAA,EACT;AAAA,EACA,gBAAgB,CAAC;AAAA,EACjB,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,EACV,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB;AAAA,EACA,iBAAiB;AACnB,MAAoB;AAClB,QAAM,CAAC,WAAW,YAAY,IAAI,SAAkB,KAAK;AACzD,QAAM,CAAC,YAAY,aAAa,IAAI,SAAc;AAClD,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,KAAK;AACtD,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAE9C,QAAM,aAAa,MAAM;AACjB,UAAA,UAAU,SAAS,UACrB,MAAM;AAAA,MACJ,QAAQ,QAAQ;AAAA,QACd,eAAe,cAAc,QAAQ;AAAA,MAAA;AAAA,IACvC,IAEF,CAAC;AACE,WAAA;AAAA,EACT;AAEA,QAAM,cAAc,CAAC,IAAS,WAAW,MAAM;AAC7C,QAAI,CAAC,GAAI;AACT,UAAM,eAAe,qBAAqB,EAAE,EAAE,CAAC;AAC/C,QAAI,cAAc;AAChB,SAAG,WAAW;AACd,mBAAa,WAAW;AAAA,IAAA,OACnB;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,QAAQ,QAAQ,GAAG;AAAA,QACpB,CAAC,QAAQ,QAAQ,GAAG;AAAA,QACpB,CAAC,QAAQ,aAAa,GAAG;AAAA,MAC3B;AAAA,MACA,SAAS,MAAM;AAAA,IACjB;AAAA,IACA,KAAK;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAA,GACH;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"Focus.js","sources":["../../../src/Focus/Focus.tsx"],"sourcesContent":["import { cloneElement, useState } from \"react\";\nimport { type ExtractNames } from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvBaseProps } from \"../types/generic\";\nimport { isBrowser } from \"../utils/browser\";\nimport { isKey, isOneOfKeys } from \"../utils/keyboardUtils\";\nimport { staticClasses, useClasses } from \"./Focus.styles\";\nimport { getFocusableChildren, setFocusTo } from \"./utils\";\n\nexport { staticClasses as focusClasses };\nexport type HvFocusClasses = ExtractNames<typeof useClasses>;\n\nexport type HvFocusStrategies = \"listbox\" | \"menu\" | \"card\" | \"grid\";\n\nexport interface HvFocusProps extends HvBaseProps<HTMLElement, \"children\"> {\n children: React.ReactElement;\n /** Extra configuration for the child element. */\n configuration?: {\n tabIndex?: number;\n };\n /** Indicates that the disabled class should be applied. */\n disabledClass?: boolean;\n /** Whether the focus is selected. */\n selected?: boolean;\n /** Whether the focus is disabled. */\n disabled?: boolean;\n /** The reference to the root element to hold all Focus' context. */\n rootRef?: React.RefObject<HTMLElement>;\n /** Show focus when click element. v */\n focusOnClick?: boolean;\n /** Show focus when click element. v */\n focusDisabled?: boolean;\n /** Focus and navigation strategy to be used. v */\n strategy?: HvFocusStrategies;\n /** Uses an absolute positioned div as a focus. v */\n useFalseFocus?: boolean;\n /** Narrows the results of the focus to only theses class v */\n filterClass?: string;\n /** How much the navigation will skip when using the arrows. v */\n navigationJump?: number;\n /** A Jss Object used to override or extend the styles applied to the component. */\n classes?: HvFocusClasses;\n}\n\ninterface Focuses {\n first: Element;\n last: Element;\n previous: Element;\n next: Element;\n fall: Element;\n jump: Element;\n}\n\n/** @deprecated internal use only. this component has navigation issues. */\nexport const HvFocus = ({\n classes: classesProp,\n children,\n configuration = {},\n disabledClass = false,\n selected = false,\n disabled = false,\n rootRef = undefined,\n focusOnClick = false,\n focusDisabled = true,\n strategy = \"listbox\",\n filterClass,\n navigationJump = 4,\n}: HvFocusProps) => {\n const [childFocus, setChildFocus] = useState<any>();\n const [hasRunConfig, setHasRunConfig] = useState(false);\n const { classes, cx } = useClasses(classesProp);\n\n const getFocuses = () => {\n const focuses = rootRef?.current\n ? Array.from(\n rootRef.current.getElementsByClassName(\n filterClass || staticClasses.root || \"root\",\n ),\n )\n : [];\n return focuses;\n };\n\n const setTabIndex = (el: any, tabIndex = 0) => {\n if (!el) return;\n const elChildFocus = getFocusableChildren(el)[0];\n if (elChildFocus) {\n el.tabIndex = -1;\n elChildFocus.tabIndex = tabIndex;\n } else {\n el.tabIndex = tabIndex;\n }\n };\n\n const setSelectedTabIndex = () => {\n const focuses = getFocuses();\n const firstSelected = focuses.find((focus) =>\n focus.classList.contains(classes.selected || \"selected\"),\n );\n\n if (!firstSelected) return;\n focuses.forEach((focus) => setTabIndex(focus, -1));\n setTabIndex(firstSelected, 0);\n };\n\n const clearTabSiblings = (el: any) => {\n getFocuses().forEach((focus) => setTabIndex(focus, -1));\n setTabIndex(el, 0);\n };\n\n const onFocusStrategy = (evt: any) => {\n if (strategy === \"listbox\") {\n clearTabSiblings(evt.currentTarget);\n }\n };\n\n const onBlurStrategy = () => {\n if (\n strategy === \"listbox\" &&\n rootRef &&\n rootRef.current &&\n !rootRef.current.contains(document.activeElement)\n ) {\n setTimeout(() => {\n setSelectedTabIndex();\n }, 10);\n }\n };\n\n const config = (el: any) => {\n const { tabIndex } = configuration;\n if (!el || hasRunConfig) return;\n if (strategy === \"card\") {\n setChildFocus(children);\n return;\n }\n\n if (strategy === \"grid\") {\n return;\n }\n\n const focusableChildren = getFocusableChildren(el);\n if (focusableChildren.length) {\n focusableChildren.forEach((child: any) => setTabIndex(child, -1));\n setChildFocus(focusableChildren[0]);\n }\n\n if (tabIndex != null) setTabIndex(el, tabIndex);\n setHasRunConfig(true);\n };\n\n const addFocusClass = (evt: any) => {\n // evt.currentTarget.classList.add(classes.focused);\n classes.focused\n .split(\" \")\n .forEach((c) => evt.currentTarget.classList.add(c));\n // add global class HvIsFocused as a marker\n // not to be styled directly, only as helper in specific css queries\n evt.currentTarget.classList.add(\"HvIsFocused\");\n classes?.focus\n ?.split(\" \")\n .forEach((c) => evt.currentTarget.classList.add(c));\n };\n\n const removeFocusClass = () => {\n getFocuses().forEach((element) => {\n // element.classList.remove(classes.focused);\n classes.focused.split(\" \").forEach((c) => element.classList.remove(c));\n // remove the global class HvIsFocused\n element.classList.remove(\"HvIsFocused\");\n classes?.focus?.split(\" \").forEach((c) => element.classList.remove(c));\n });\n };\n\n const onFocus = (evt: any) => {\n addFocusClass(evt);\n // give focus to child element if any focusable\n\n childFocus?.focus?.();\n onFocusStrategy(evt);\n };\n\n const onBlur = () => {\n removeFocusClass();\n onBlurStrategy();\n };\n\n const onMouseDown = (evt: any) => {\n const hasCard = !!evt.currentTarget?.querySelector(\".HvIsCardGridElement\");\n if (strategy === \"grid\" && hasCard) return;\n\n setFocusTo(evt.currentTarget);\n setTabIndex(evt.currentTarget, 0);\n // remove focus outline unless explicitly enabled\n if (!focusOnClick) {\n // TODO this piece of code works only because onMouseDown is happening after the focus event\n // There is nothing in here that guarantees the order of these events, so it may present a problem in the future\n removeFocusClass();\n }\n };\n\n const focusAndUpdateIndex = (\n nextFocus: Element,\n previousFocus: any,\n focusesList: Element[],\n ) => {\n if (focusesList?.includes(previousFocus)) {\n setTabIndex(previousFocus, -1);\n }\n setTabIndex(nextFocus, 0);\n setFocusTo(nextFocus);\n };\n\n const getEnabledKeys = (\n currentFocusIndex: number,\n jump: number,\n listSize: number,\n ) => ({\n right:\n (currentFocusIndex + 1) % jump === 0 ||\n currentFocusIndex + 1 > listSize - 1,\n left: currentFocusIndex % jump === 0,\n up: currentFocusIndex - jump < 0,\n down:\n currentFocusIndex + jump > listSize ||\n currentFocusIndex + jump > listSize - 1,\n });\n\n const onGridKeyDownHandler = (\n evt: any,\n focuses: Focuses,\n focusesList: Element[],\n currentFocusIndex: number,\n jump: number,\n ) => {\n const childFocusIsInput = childFocus && childFocus.nodeName === \"INPUT\";\n\n if (\n !isOneOfKeys(evt, [\n \"ArrowUp\",\n \"ArrowDown\",\n \"ArrowLeft\",\n \"ArrowRight\",\n \"Home\",\n \"End\",\n \"Space\",\n \"Enter\",\n ]) ||\n (childFocusIsInput && isKey(evt, \"Enter\"))\n ) {\n // nothing to do\n return;\n }\n\n // we'll do something with the key so prevent default and stop propagation\n // except for Enter and SpaceBar\n if (!isOneOfKeys(evt, [\"Enter\", \"Space\"])) {\n evt.preventDefault();\n evt.stopPropagation();\n }\n\n const blockedKeys = getEnabledKeys(\n currentFocusIndex,\n jump,\n focusesList.length,\n );\n\n switch (evt.code) {\n case \"Space\":\n case \"Enter\":\n if (isBrowser(\"firefox\")) {\n evt.target.click();\n } else {\n evt.currentTarget.click();\n }\n break;\n case \"ArrowUp\":\n if (!blockedKeys.up) {\n focusAndUpdateIndex(\n focuses.jump || focuses.last,\n evt.current,\n focusesList,\n );\n }\n break;\n case \"ArrowDown\":\n if (!blockedKeys.down) {\n focusAndUpdateIndex(\n focuses.fall || focuses.first,\n evt.current,\n focusesList,\n );\n }\n break;\n case \"ArrowLeft\":\n if (!blockedKeys.left) {\n focusAndUpdateIndex(\n focuses.previous || focuses.last,\n evt.current,\n focusesList,\n );\n }\n break;\n case \"ArrowRight\":\n if (!blockedKeys.right) {\n focusAndUpdateIndex(\n focuses.next || focuses.first,\n evt.current,\n focusesList,\n );\n }\n break;\n case \"Home\":\n focusAndUpdateIndex(focuses.first, evt.current, focusesList);\n break;\n case \"End\":\n focusAndUpdateIndex(focuses.last, evt.current, focusesList);\n break;\n default:\n }\n };\n\n const onVerticalArrangementHandler = (\n evt: any,\n focuses: Focuses,\n focusesList: Element[],\n ) => {\n const childFocusIsInput = childFocus && childFocus.nodeName === \"INPUT\";\n\n if (\n !isOneOfKeys(evt, [\n \"ArrowUp\",\n \"ArrowDown\",\n \"Home\",\n \"End\",\n \"Space\",\n \"Enter\",\n ]) ||\n (childFocusIsInput && isKey(evt, \"Enter\"))\n ) {\n // nothing to do\n return;\n }\n\n // we'll do something with the key so prevent default and stop propagation\n evt.preventDefault();\n evt.stopPropagation();\n\n switch (evt.code) {\n case \"Space\":\n case \"Enter\":\n evt.target.click();\n break;\n case \"ArrowUp\":\n focusAndUpdateIndex(\n focuses.previous || focuses.last,\n evt.current,\n focusesList,\n );\n break;\n case \"ArrowDown\":\n focusAndUpdateIndex(\n focuses.next || focuses.first,\n evt.current,\n focusesList,\n );\n break;\n case \"Home\":\n focusAndUpdateIndex(focuses.first, evt.current, focusesList);\n break;\n case \"End\":\n focusAndUpdateIndex(focuses.last, evt.current, focusesList);\n break;\n default:\n }\n };\n\n const onSingleHandler = (evt: any) => {\n const childFocusIsInput = childFocus && childFocus.nodeName === \"INPUT\";\n\n if (\n !isOneOfKeys(evt, [\"Space\", \"Enter\"]) ||\n (childFocusIsInput && isKey(evt, \"Enter\"))\n ) {\n // nothing to do\n return;\n }\n\n // we'll do something with the key so prevent default and stop propagation\n evt.preventDefault();\n evt.stopPropagation();\n\n evt.currentTarget.click();\n };\n\n const onKeyDown = (evt: any) => {\n if (rootRef?.current == null) {\n // operating outside of a composite widget\n // nothing to manage, just style and trigger clicks\n onSingleHandler(evt);\n return;\n }\n\n // TODO keep the smart default, but allow to explicitly override if disabled elements should be focusable\n const isDisabledFocusable = strategy === \"menu\";\n const focusesList = getFocuses().filter(\n (el) =>\n isDisabledFocusable ||\n !el.classList.contains(classes?.disabled as string),\n );\n\n const currentFocus = focusesList.indexOf(evt.currentTarget);\n\n const focuses: Focuses = {\n first: focusesList[0],\n last: focusesList[focusesList.length - 1],\n previous: focusesList[currentFocus - 1],\n next: focusesList[currentFocus + 1],\n fall: focusesList[currentFocus + navigationJump],\n jump: focusesList[currentFocus - navigationJump],\n };\n\n if (strategy === \"grid\") {\n onGridKeyDownHandler(\n evt,\n focuses,\n focusesList,\n currentFocus,\n navigationJump,\n );\n return;\n }\n\n // TODO add property for specifying the composite widget orientation\n // TODO implement handler for horizontal orientation\n onVerticalArrangementHandler(evt, focuses, focusesList);\n };\n\n const onKeyUp = (evt: any) => {\n if (isBrowser(\"firefox\")) evt.preventDefault();\n };\n\n if (disabled) return children;\n\n return cloneElement(children, {\n className: cx(\n [classes.root, filterClass],\n {\n [classes.selected]: selected,\n [classes.disabled]: disabledClass,\n [classes.focusDisabled]: focusDisabled,\n },\n children.props.className,\n ),\n ref: config,\n onFocus,\n onBlur,\n onMouseDown,\n onKeyDown,\n onKeyUp,\n selected,\n });\n};\n"],"names":[],"mappings":";;;;;AAsDO,MAAM,UAAU,CAAC;AAAA,EACtB,SAAS;AAAA,EACT;AAAA,EACA,gBAAgB,CAAC;AAAA,EACjB,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,EACV,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX;AAAA,EACA,iBAAiB;AACnB,MAAoB;AAClB,QAAM,CAAC,YAAY,aAAa,IAAI,SAAc;AAClD,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,KAAK;AACtD,QAAM,EAAE,SAAS,OAAO,WAAW,WAAW;AAE9C,QAAM,aAAa,MAAM;AACjB,UAAA,UAAU,SAAS,UACrB,MAAM;AAAA,MACJ,QAAQ,QAAQ;AAAA,QACd,eAAe,cAAc,QAAQ;AAAA,MAAA;AAAA,IACvC,IAEF,CAAC;AACE,WAAA;AAAA,EACT;AAEA,QAAM,cAAc,CAAC,IAAS,WAAW,MAAM;AAC7C,QAAI,CAAC,GAAI;AACT,UAAM,eAAe,qBAAqB,EAAE,EAAE,CAAC;AA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 +19,6 @@ const { staticClasses, useClasses } = createClasses("HvFocus", {
|
|
|
19
19
|
...outlineStyles
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
|
-
externalReference: {
|
|
23
|
-
position: "relative"
|
|
24
|
-
},
|
|
25
|
-
falseFocus: {
|
|
26
|
-
width: "98%",
|
|
27
|
-
height: "98%",
|
|
28
|
-
position: "absolute",
|
|
29
|
-
zIndex: "1",
|
|
30
|
-
...outlineStyles,
|
|
31
|
-
"@media (-webkit-min-device-pixel-ratio:0)": {
|
|
32
|
-
...outlineStyles
|
|
33
|
-
},
|
|
34
|
-
top: 0,
|
|
35
|
-
left: "0.5%",
|
|
36
|
-
backgroundColor: "transparent",
|
|
37
|
-
pointerEvents: "none"
|
|
38
|
-
},
|
|
39
22
|
focus: {}
|
|
40
23
|
});
|
|
41
24
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Focus.styles.js","sources":["../../../src/Focus/Focus.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\n\nimport { outlineStyles } from \"../utils/focusUtils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFocus\", {\n root: {},\n selected: {},\n disabled: {},\n focusDisabled: {\n outline: \"none\",\n \"& *:focus\": {\n outline: \"none\",\n },\n \"& *\": {\n outline: \"none !important\",\n },\n },\n focused: {\n ...outlineStyles,\n \"@media (-webkit-min-device-pixel-ratio:0)\": {\n ...outlineStyles,\n },\n },\n
|
|
1
|
+
{"version":3,"file":"Focus.styles.js","sources":["../../../src/Focus/Focus.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-utils\";\n\nimport { outlineStyles } from \"../utils/focusUtils\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvFocus\", {\n root: {},\n selected: {},\n disabled: {},\n focusDisabled: {\n outline: \"none\",\n \"& *:focus\": {\n outline: \"none\",\n },\n \"& *\": {\n outline: \"none !important\",\n },\n },\n focused: {\n ...outlineStyles,\n \"@media (-webkit-min-device-pixel-ratio:0)\": {\n ...outlineStyles,\n },\n },\n focus: {},\n});\n"],"names":[],"mappings":";;AAIO,MAAM,EAAE,eAAe,eAAe,cAAc,WAAW;AAAA,EACpE,MAAM,CAAC;AAAA,EACP,UAAU,CAAC;AAAA,EACX,UAAU,CAAC;AAAA,EACX,eAAe;AAAA,IACb,SAAS;AAAA,IACT,aAAa;AAAA,MACX,SAAS;AAAA,IACX;AAAA,IACA,OAAO;AAAA,MACL,SAAS;AAAA,IAAA;AAAA,EAEb;AAAA,EACA,SAAS;AAAA,IACP,GAAG;AAAA,IACH,6CAA6C;AAAA,MAC3C,GAAG;AAAA,IAAA;AAAA,EAEP;AAAA,EACA,OAAO,CAAA;AACT,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InlineEditor.js","sources":["../../../src/InlineEditor/InlineEditor.tsx"],"sourcesContent":["import { useRef, useState } from \"react\";\nimport { Edit } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n useTheme,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvButton, HvButtonProps } from \"../Button\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useEnhancedEffect } from \"../hooks/useEnhancedEffect\";\nimport { HvInput, HvInputProps } from \"../Input\";\nimport { HvTooltip } from \"../Tooltip\";\nimport {\n fixedForwardRef,\n PolymorphicComponentRef,\n PolymorphicRef,\n} from \"../types/generic\";\nimport {\n HvTypography,\n HvTypographyProps,\n HvTypographyVariants,\n} from \"../Typography\";\nimport { isKey } from \"../utils/keyboardUtils\";\nimport { staticClasses, useClasses } from \"./InlineEditor.styles\";\n\nexport { staticClasses as inlineEditorClasses };\n\nexport type HvInlineEditorClasses = ExtractNames<typeof useClasses>;\n\nexport type HvInlineEditorProps<C extends React.ElementType = typeof HvInput> =\n PolymorphicComponentRef<\n C,\n {\n /** The value of the form element. */\n value?: string;\n /** The default value of the form element. */\n defaultValue?: string;\n /** Whether the Edit icon should always be visible */\n showIcon?: boolean;\n /** Variant of the HvTypography to display */\n variant?: HvTypographyVariants;\n /** Called when the input is blurred. */\n onBlur?: (\n event: React.FocusEvent<HTMLTextAreaElement | HTMLInputElement>,\n value: string,\n ) => void;\n /** Called when the input value changes. */\n onChange?: (event: React.SyntheticEvent, value: string) => void;\n /** Called when there's a keydown event on the input. */\n onKeyDown?: (\n event:\n | React.KeyboardEvent<HTMLTextAreaElement | HTMLInputElement>\n | React.MouseEvent,\n value: string,\n ) => void;\n /** Props passed to the HvButton component */\n buttonProps?: HvButtonProps;\n /** Props passed to the HvTypography text component */\n typographyProps?: HvTypographyProps;\n /** Whether the editor is disabled or not. */\n disabled?: boolean;\n /** A Jss Object used to override or extend the styles applied to the empty state component. */\n classes?: HvInlineEditorClasses;\n /** The placeholder value of the input. */\n placeholder?: string;\n }\n >;\n\n/**\n * An Inline Editor allows the user to edit a record without making a major switch\n * between viewing and editing, making it an efficient method of updating a record.\n */\nexport const HvInlineEditor = fixedForwardRef(function HvInlineEditor<\n C extends React.ElementType = typeof HvInput,\n>(props: HvInlineEditorProps<C>, ref: PolymorphicRef<C>) {\n const {\n className,\n classes: classesProp,\n value: valueProp,\n defaultValue = \"\",\n showIcon,\n component: InputComponent = HvInput,\n variant = \"body\",\n placeholder = \"Enter text\",\n onBlur,\n onChange,\n onKeyDown,\n buttonProps,\n typographyProps,\n disabled,\n ...others\n } = useDefaultProps(\"HvInlineEditor\", props);\n\n const { classes, cx } = useClasses(classesProp);\n const [value, setValue] = useControlled(valueProp, defaultValue);\n const [editMode, setEditMode] = useState(false);\n const [cachedValue, setCachedValue] = useState(value);\n const inputRef = useRef<HTMLInputElement>();\n const { activeTheme } = useTheme();\n const [isOverflowing, setIsOverflowing] = useState(false);\n\n const typographyStyles = activeTheme?.typography[variant] || {};\n const { lineHeight } = typographyStyles;\n\n const checkOverflow = (el: HTMLElement | null) => {\n if (!el) return;\n setIsOverflowing(el.scrollWidth > el.clientWidth);\n };\n\n useEnhancedEffect(() => {\n const input = inputRef.current;\n if (editMode && input) {\n input.focus();\n input.select();\n }\n }, [editMode]);\n\n const handleClick = () => {\n setEditMode(true);\n setCachedValue(value);\n };\n\n const handleBlur: HvInputProps[\"onBlur\"] = (event) => {\n setEditMode(false);\n\n const newValue = value || cachedValue; // empty values should be ignored\n setValue(newValue);\n onBlur?.(event, newValue);\n };\n\n const handleKeyDown: HvInputProps[\"onKeyDown\"] = (event) => {\n let newValue = value;\n if (isKey(event, \"Esc\")) {\n newValue = cachedValue;\n setEditMode(false);\n setValue(newValue);\n }\n onKeyDown?.(event, newValue);\n };\n\n const handleChange: HvInputProps[\"onChange\"] = (event, val) => {\n setValue(val);\n onChange?.(event, val);\n };\n\n return (\n <div className={cx(classes.root, className)}>\n {editMode && !disabled ? (\n <InputComponent\n ref={ref}\n inputRef={inputRef}\n classes={{\n
|
|
1
|
+
{"version":3,"file":"InlineEditor.js","sources":["../../../src/InlineEditor/InlineEditor.tsx"],"sourcesContent":["import { useRef, useState } from \"react\";\nimport { Edit } from \"@hitachivantara/uikit-react-icons\";\nimport {\n useDefaultProps,\n useTheme,\n type ExtractNames,\n} from \"@hitachivantara/uikit-react-utils\";\n\nimport { HvButton, HvButtonProps } from \"../Button\";\nimport { useControlled } from \"../hooks/useControlled\";\nimport { useEnhancedEffect } from \"../hooks/useEnhancedEffect\";\nimport { HvInput, HvInputProps } from \"../Input\";\nimport { HvTooltip } from \"../Tooltip\";\nimport {\n fixedForwardRef,\n PolymorphicComponentRef,\n PolymorphicRef,\n} from \"../types/generic\";\nimport {\n HvTypography,\n HvTypographyProps,\n HvTypographyVariants,\n} from \"../Typography\";\nimport { isKey } from \"../utils/keyboardUtils\";\nimport { staticClasses, useClasses } from \"./InlineEditor.styles\";\n\nexport { staticClasses as inlineEditorClasses };\n\nexport type HvInlineEditorClasses = ExtractNames<typeof useClasses>;\n\nexport type HvInlineEditorProps<C extends React.ElementType = typeof HvInput> =\n PolymorphicComponentRef<\n C,\n {\n /** The value of the form element. */\n value?: string;\n /** The default value of the form element. */\n defaultValue?: string;\n /** Whether the Edit icon should always be visible */\n showIcon?: boolean;\n /** Variant of the HvTypography to display */\n variant?: HvTypographyVariants;\n /** Called when the input is blurred. */\n onBlur?: (\n event: React.FocusEvent<HTMLTextAreaElement | HTMLInputElement>,\n value: string,\n ) => void;\n /** Called when the input value changes. */\n onChange?: (event: React.SyntheticEvent, value: string) => void;\n /** Called when there's a keydown event on the input. */\n onKeyDown?: (\n event:\n | React.KeyboardEvent<HTMLTextAreaElement | HTMLInputElement>\n | React.MouseEvent,\n value: string,\n ) => void;\n /** Props passed to the HvButton component */\n buttonProps?: HvButtonProps;\n /** Props passed to the HvTypography text component */\n typographyProps?: HvTypographyProps;\n /** Whether the editor is disabled or not. */\n disabled?: boolean;\n /** A Jss Object used to override or extend the styles applied to the empty state component. */\n classes?: HvInlineEditorClasses;\n /** The placeholder value of the input. */\n placeholder?: string;\n }\n >;\n\n/**\n * An Inline Editor allows the user to edit a record without making a major switch\n * between viewing and editing, making it an efficient method of updating a record.\n */\nexport const HvInlineEditor = fixedForwardRef(function HvInlineEditor<\n C extends React.ElementType = typeof HvInput,\n>(props: HvInlineEditorProps<C>, ref: PolymorphicRef<C>) {\n const {\n className,\n classes: classesProp,\n value: valueProp,\n defaultValue = \"\",\n showIcon,\n component: InputComponent = HvInput,\n variant = \"body\",\n placeholder = \"Enter text\",\n onBlur,\n onChange,\n onKeyDown,\n buttonProps,\n typographyProps,\n disabled,\n ...others\n } = useDefaultProps(\"HvInlineEditor\", props);\n\n const { classes, cx } = useClasses(classesProp);\n const [value, setValue] = useControlled(valueProp, defaultValue);\n const [editMode, setEditMode] = useState(false);\n const [cachedValue, setCachedValue] = useState(value);\n const inputRef = useRef<HTMLInputElement>();\n const { activeTheme } = useTheme();\n const [isOverflowing, setIsOverflowing] = useState(false);\n\n const typographyStyles = activeTheme?.typography[variant] || {};\n const { lineHeight } = typographyStyles;\n\n const checkOverflow = (el: HTMLElement | null) => {\n if (!el) return;\n setIsOverflowing(el.scrollWidth > el.clientWidth);\n };\n\n useEnhancedEffect(() => {\n const input = inputRef.current;\n if (editMode && input) {\n input.focus();\n input.select();\n }\n }, [editMode]);\n\n const handleClick = () => {\n setEditMode(true);\n setCachedValue(value);\n };\n\n const handleBlur: HvInputProps[\"onBlur\"] = (event) => {\n setEditMode(false);\n\n const newValue = value || cachedValue; // empty values should be ignored\n setValue(newValue);\n onBlur?.(event, newValue);\n };\n\n const handleKeyDown: HvInputProps[\"onKeyDown\"] = (event) => {\n let newValue = value;\n if (isKey(event, \"Esc\")) {\n newValue = cachedValue;\n setEditMode(false);\n setValue(newValue);\n }\n onKeyDown?.(event, newValue);\n };\n\n const handleChange: HvInputProps[\"onChange\"] = (event, val) => {\n setValue(val);\n onChange?.(event, val);\n };\n\n return (\n <div className={cx(classes.root, className)}>\n {editMode && !disabled ? (\n <InputComponent\n ref={ref}\n inputRef={inputRef}\n classes={{\n inputRoot: classes.inputRoot,\n input: classes.input,\n }}\n inputProps={{\n style: {\n ...typographyStyles,\n height: InputComponent === HvInput ? lineHeight : undefined,\n },\n }}\n value={value}\n onBlur={handleBlur}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n {...others}\n />\n ) : (\n <HvButton\n variant=\"secondaryGhost\"\n endIcon={\n <Edit\n color=\"textDisabled\"\n className={cx(classes.icon, {\n [classes.iconVisible]: showIcon,\n })}\n />\n }\n className={cx(classes.button, {\n [classes.largeText]: parseInt(lineHeight as string, 10) >= 28,\n })}\n onClick={handleClick}\n disabled={disabled}\n {...buttonProps}\n >\n <HvTooltip title={isOverflowing && value}>\n <HvTypography\n component=\"div\"\n ref={checkOverflow}\n variant={variant}\n noWrap\n className={cx(classes.text, { [classes.textEmpty]: !value })}\n {...typographyProps}\n >\n {value || placeholder}\n </HvTypography>\n </HvTooltip>\n </HvButton>\n )}\n </div>\n );\n});\n"],"names":["HvInlineEditor"],"mappings":";;;;;;;;;;;;;;AAyEO,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,EAAE,CAAC,QAAQ,SAAS,GAAG,CAAC,OAAO;AAAA,UAC1D,GAAG;AAAA,UAEH,UAAS,SAAA;AAAA,QAAA;AAAA,MAAA,EAEd,CAAA;AAAA,IAAA;AAAA,EAAA,GAGN;AAEJ,CAAC;"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ import { IconBaseProps } from '@hitachivantara/uikit-react-icons';
|
|
|
57
57
|
import { IdType as IdType_2 } from 'react-table';
|
|
58
58
|
import { InputBaseProps } from '@mui/material/InputBase';
|
|
59
59
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
60
|
+
import { JSXElementConstructor } from 'react';
|
|
60
61
|
import { MutableRefObject } from 'react';
|
|
61
62
|
import { OptionGroupProps } from '@mui/base/OptionGroup';
|
|
62
63
|
import { OptionOwnProps } from '@mui/base/Option';
|
|
@@ -68,6 +69,7 @@ import { PropGetter } from 'react-table';
|
|
|
68
69
|
import { PropsWithoutRef } from 'react';
|
|
69
70
|
import { RadioProps } from '@mui/material/Radio';
|
|
70
71
|
import * as React_2 from 'react';
|
|
72
|
+
import { ReactElement } from 'react';
|
|
71
73
|
import { ReactNode } from 'react';
|
|
72
74
|
import { ReducerTableState } from 'react-table';
|
|
73
75
|
import { RefAttributes } from 'react';
|
|
@@ -928,8 +930,6 @@ export declare const focusClasses: {
|
|
|
928
930
|
disabled: string;
|
|
929
931
|
focusDisabled: string;
|
|
930
932
|
focused: string;
|
|
931
|
-
externalReference: string;
|
|
932
|
-
falseFocus: string;
|
|
933
933
|
focus: string;
|
|
934
934
|
};
|
|
935
935
|
|
|
@@ -3617,7 +3617,7 @@ export declare interface HvFilterGroupProps extends Omit<HvFormElementProps, "cl
|
|
|
3617
3617
|
export declare type HvFilterGroupValue = (string | number)[][];
|
|
3618
3618
|
|
|
3619
3619
|
/** @deprecated internal use only. this component has navigation issues. */
|
|
3620
|
-
export declare const HvFocus: ({ classes: classesProp, children, configuration, disabledClass, selected, disabled, rootRef, focusOnClick, focusDisabled, strategy,
|
|
3620
|
+
export declare const HvFocus: ({ classes: classesProp, children, configuration, disabledClass, selected, disabled, rootRef, focusOnClick, focusDisabled, strategy, filterClass, navigationJump, }: HvFocusProps) => ReactElement<any, string | JSXElementConstructor<any>>;
|
|
3621
3621
|
|
|
3622
3622
|
export declare type HvFocusClasses = ExtractNames<typeof useClasses_4>;
|
|
3623
3623
|
|
|
@@ -9320,15 +9320,13 @@ declare const useClasses_39: (classesProp?: Partial<Record<"root" | "invalid" |
|
|
|
9320
9320
|
readonly cx: (...args: any) => string;
|
|
9321
9321
|
};
|
|
9322
9322
|
|
|
9323
|
-
declare const useClasses_4: (classesProp?: Partial<Record<"root" | "disabled" | "focused" | "selected" | "focus" | "focusDisabled"
|
|
9323
|
+
declare const useClasses_4: (classesProp?: Partial<Record<"root" | "disabled" | "focused" | "selected" | "focus" | "focusDisabled", string>>, addStatic?: boolean) => {
|
|
9324
9324
|
readonly classes: {
|
|
9325
9325
|
root: string;
|
|
9326
9326
|
selected: string;
|
|
9327
9327
|
disabled: string;
|
|
9328
9328
|
focusDisabled: string;
|
|
9329
9329
|
focused: string;
|
|
9330
|
-
externalReference: string;
|
|
9331
|
-
falseFocus: string;
|
|
9332
9330
|
focus: string;
|
|
9333
9331
|
};
|
|
9334
9332
|
readonly css: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitachivantara/uikit-react-core",
|
|
3
|
-
"version": "5.91.
|
|
3
|
+
"version": "5.91.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Hitachi Vantara UI Kit Team",
|
|
6
6
|
"description": "Core React components for the NEXT Design System.",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@emotion/cache": "^11.11.0",
|
|
34
34
|
"@emotion/serialize": "^1.1.2",
|
|
35
|
-
"@hitachivantara/uikit-react-icons": "^5.14.
|
|
36
|
-
"@hitachivantara/uikit-react-shared": "^5.3.
|
|
37
|
-
"@hitachivantara/uikit-react-utils": "^0.2.
|
|
38
|
-
"@hitachivantara/uikit-styles": "^5.44.
|
|
35
|
+
"@hitachivantara/uikit-react-icons": "^5.14.3",
|
|
36
|
+
"@hitachivantara/uikit-react-shared": "^5.3.28",
|
|
37
|
+
"@hitachivantara/uikit-react-utils": "^0.2.29",
|
|
38
|
+
"@hitachivantara/uikit-styles": "^5.44.1",
|
|
39
39
|
"@internationalized/date": "^3.2.0",
|
|
40
40
|
"@mui/base": "5.0.0-beta.68",
|
|
41
41
|
"@popperjs/core": "^2.11.8",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"access": "public",
|
|
63
63
|
"directory": "package"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "f5d115c12ef1f285c3ddcb34c0e7fbfd8df3666f",
|
|
66
66
|
"exports": {
|
|
67
67
|
".": {
|
|
68
68
|
"types": "./dist/types/index.d.ts",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionalWrapper.js","sources":["../../../src/utils/ConditionalWrapper.tsx"],"sourcesContent":["export const ConditionalWrapper = ({\n condition,\n wrapper,\n children,\n}: {\n condition?: boolean;\n wrapper: any;\n children: React.ReactNode;\n}) => (condition ? wrapper(children) : children);\n"],"names":[],"mappings":"AAAO,MAAM,qBAAqB,CAAC;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AACF,MAIO,YAAY,QAAQ,QAAQ,IAAI;"}
|