@open-pioneer/react-utils 4.6.0-dev.20260518102806 → 4.6.0-dev.20260519113011
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -1
- package/classNames.d.ts +10 -0
- package/classNames.js +26 -0
- package/classNames.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +3 -4
- package/useCommonComponentProps.js +1 -1
- package/useCommonComponentProps.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# @open-pioneer/react-utils
|
|
2
2
|
|
|
3
|
-
## 4.6.0-dev.
|
|
3
|
+
## 4.6.0-dev.20260519113011
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
+
- 27f5f1e: Add a new `classnames` function to replace the `classnames` package.
|
|
7
8
|
- 4b207f4: Added a `required` option to `useHeadingLevel` hook to make it return `undefined` instead of throwing an error when used outside of a `TitledSection`.
|
|
8
9
|
|
|
9
10
|
This allows to use the hook in components which do not necessarily need to be used inside a `TitledSection`.
|
package/classNames.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ClassValue = string | number | boolean | null | undefined | ClassDictionary | ClassValue[];
|
|
2
|
+
export interface ClassDictionary {
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Joins arguments into a single string.
|
|
7
|
+
* Accepts strings, numbers, arrays and plain objects (recursively).
|
|
8
|
+
* For objects, each key is included when its value is true.
|
|
9
|
+
*/
|
|
10
|
+
export declare function classNames(...args: ClassValue[]): string;
|
package/classNames.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function classNames(...args) {
|
|
2
|
+
const parts = [];
|
|
3
|
+
for (const arg of args) {
|
|
4
|
+
if (!arg) {
|
|
5
|
+
continue;
|
|
6
|
+
}
|
|
7
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
8
|
+
parts.push(String(arg));
|
|
9
|
+
} else if (Array.isArray(arg)) {
|
|
10
|
+
const inner = classNames(...arg);
|
|
11
|
+
if (inner) {
|
|
12
|
+
parts.push(inner);
|
|
13
|
+
}
|
|
14
|
+
} else if (typeof arg === "object") {
|
|
15
|
+
for (const key of Object.keys(arg)) {
|
|
16
|
+
if (arg[key]) {
|
|
17
|
+
parts.push(key);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return parts.join(" ");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { classNames };
|
|
26
|
+
//# sourceMappingURL=classNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classNames.js","sources":["classNames.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nexport type ClassValue =\n | string\n | number\n | boolean\n | null\n | undefined\n | ClassDictionary\n | ClassValue[];\nexport interface ClassDictionary {\n [key: string]: unknown;\n}\n\n/**\n * Joins arguments into a single string.\n * Accepts strings, numbers, arrays and plain objects (recursively).\n * For objects, each key is included when its value is true.\n */\nexport function classNames(...args: ClassValue[]): string {\n const parts: string[] = [];\n for (const arg of args) {\n if (!arg) {\n continue;\n }\n if (typeof arg === \"string\" || typeof arg === \"number\") {\n parts.push(String(arg));\n } else if (Array.isArray(arg)) {\n const inner = classNames(...arg);\n if (inner) {\n parts.push(inner);\n }\n } else if (typeof arg === \"object\") {\n for (const key of Object.keys(arg)) {\n // only include keys with truthy values\n if (arg[key]) {\n parts.push(key);\n }\n }\n }\n }\n return parts.join(\" \");\n}\n"],"names":[],"mappings":"AAoBO,SAAS,cAAc,IAAA,EAA4B;AACtD,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,KAAA,MAAW,OAAO,IAAA,EAAM;AACpB,IAAA,IAAI,CAAC,GAAA,EAAK;AACN,MAAA;AAAA,IACJ;AACA,IAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,OAAO,QAAQ,QAAA,EAAU;AACpD,MAAA,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,GAAG,CAAC,CAAA;AAAA,IAC1B,CAAA,MAAA,IAAW,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA,EAAG;AAC3B,MAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,GAAG,GAAG,CAAA;AAC/B,MAAA,IAAI,KAAA,EAAO;AACP,QAAA,KAAA,CAAM,KAAK,KAAK,CAAA;AAAA,MACpB;AAAA,IACJ,CAAA,MAAA,IAAW,OAAO,GAAA,KAAQ,QAAA,EAAU;AAChC,MAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK,GAAG,CAAA,EAAG;AAEhC,QAAA,IAAI,GAAA,CAAI,GAAG,CAAA,EAAG;AACV,UAAA,KAAA,CAAM,KAAK,GAAG,CAAA;AAAA,QAClB;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACA,EAAA,OAAO,KAAA,CAAM,KAAK,GAAG,CAAA;AACzB;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -22,3 +22,4 @@ export { useRovingMenu, type RovingMenuProps, type RovingMenuResult, useNestedRo
|
|
|
22
22
|
export { useRovingMenuItem, type RovingMenuItemProps, type RovingMenuItemResult } from "./roving-menu/useRovingMenuItem";
|
|
23
23
|
export { type RovingMenuState } from "./roving-menu/RovingMenuState";
|
|
24
24
|
export { mergeChakraProps } from "./mergeChakraProps";
|
|
25
|
+
export { classNames, type ClassValue, type ClassDictionary } from "./classNames";
|
package/index.js
CHANGED
|
@@ -5,4 +5,5 @@ export { RovingMenuRoot } from './roving-menu/RovingMenuRoot.js';
|
|
|
5
5
|
export { useNestedRovingMenu, useRovingMenu } from './roving-menu/useRovingMenu.js';
|
|
6
6
|
export { useRovingMenuItem } from './roving-menu/useRovingMenuItem.js';
|
|
7
7
|
export { mergeChakraProps } from './mergeChakraProps.js';
|
|
8
|
+
export { classNames } from './classNames.js';
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/react-utils",
|
|
4
|
-
"version": "4.6.0-dev.
|
|
4
|
+
"version": "4.6.0-dev.20260519113011",
|
|
5
5
|
"description": "Contains common react utilities used by the open pioneer trails project",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -16,10 +16,9 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@chakra-ui/react": "^3.34.0",
|
|
18
18
|
"@conterra/reactivity-core": "^0.8.5",
|
|
19
|
-
"classnames": "^2.5.1",
|
|
20
19
|
"react": "^19.2.6",
|
|
21
|
-
"@open-pioneer/core": "4.6.0-dev.
|
|
22
|
-
"@open-pioneer/reactivity": "4.6.0-dev.
|
|
20
|
+
"@open-pioneer/core": "4.6.0-dev.20260519113011",
|
|
21
|
+
"@open-pioneer/reactivity": "4.6.0-dev.20260519113011"
|
|
23
22
|
},
|
|
24
23
|
"exports": {
|
|
25
24
|
"./package.json": "./package.json",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCommonComponentProps.js","sources":["useCommonComponentProps.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemStyleObject } from \"@chakra-ui/react\";\nimport classNames from \"
|
|
1
|
+
{"version":3,"file":"useCommonComponentProps.js","sources":["useCommonComponentProps.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { SystemStyleObject } from \"@chakra-ui/react\";\nimport { classNames } from \"./classNames\";\nimport { HTMLAttributes, AriaAttributes, useMemo, AriaRole } from \"react\";\n\n/**\n * Common properties supported by all public react components.\n *\n * This type allows for the customization of\n * - the css `className`\n * - a Chakra `css` property\n * - \"role\" and `aria-*` properties\n * - arbitrary `data-*` properties\n *\n * Prop types for react components typically inherit from this interface.\n *\n * @group Common component props\n */\nexport interface CommonComponentProps extends AriaAttributes {\n /**\n * Additional class name(s).\n */\n className?: string;\n\n /**\n * Custom style rules using Chakra's style objects.\n */\n css?: SystemStyleObject | SystemStyleObject[];\n\n /**\n * Custom ARIA role.\n */\n role?: AriaRole;\n\n /**\n * Used for testing.\n */\n \"data-testid\"?: string;\n\n /**\n * Arbitrary data attributes.\n *\n * NOTE: The component may use data properties for its own behavior.\n * Make sure not to overwrite required attributes.\n */\n [key: `data-${string}`]: unknown;\n}\n\nconst COPY_PROP_RE = /^(data|aria)-/;\n\n/**\n * @group Common component props\n */\nexport interface CommonComponentContainerProps\n extends Pick<HTMLAttributes<HTMLElement>, \"className\" | \"role\">, AriaAttributes {\n css?: SystemStyleObject | SystemStyleObject[];\n [key: `data-${string}`]: unknown;\n}\n\n/**\n * A helper hook that computes react properties for the topmost container in a public react component.\n *\n * Example:\n *\n * ```jsx\n * function MyComponent(props) {\n * const { containerProps } = useCommonComponentProps(\"my-component\", props);\n * // automatically applies css classes and testid\n * return <Box {...containerProps}>Content</Box>;\n * }\n * ```\n *\n * @group Common component props\n * @expandType CommonComponentProps\n */\nexport function useCommonComponentProps(\n componentClassName: string,\n props: CommonComponentProps\n): { containerProps: CommonComponentContainerProps } {\n const result = useMemo(() => {\n const containerProps: Record<string, unknown> = {\n className: classNames(componentClassName, props.className)\n };\n if (props.role) {\n containerProps.role = props.role;\n }\n if (props.css) {\n containerProps.css = props.css;\n }\n for (const k in props) {\n if (!Object.hasOwn(props, k)) {\n continue;\n }\n if (COPY_PROP_RE.test(k)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n containerProps[k] = (props as any)[k];\n }\n }\n return { containerProps };\n }, [componentClassName, props]);\n return result;\n}\n"],"names":[],"mappings":";;;AAiDA,MAAM,YAAA,GAAe,eAAA;AA2Bd,SAAS,uBAAA,CACZ,oBACA,KAAA,EACiD;AACjD,EAAA,MAAM,MAAA,GAAS,QAAQ,MAAM;AACzB,IAAA,MAAM,cAAA,GAA0C;AAAA,MAC5C,SAAA,EAAW,UAAA,CAAW,kBAAA,EAAoB,KAAA,CAAM,SAAS;AAAA,KAC7D;AACA,IAAA,IAAI,MAAM,IAAA,EAAM;AACZ,MAAA,cAAA,CAAe,OAAO,KAAA,CAAM,IAAA;AAAA,IAChC;AACA,IAAA,IAAI,MAAM,GAAA,EAAK;AACX,MAAA,cAAA,CAAe,MAAM,KAAA,CAAM,GAAA;AAAA,IAC/B;AACA,IAAA,KAAA,MAAW,KAAK,KAAA,EAAO;AACnB,MAAA,IAAI,CAAC,MAAA,CAAO,MAAA,CAAO,KAAA,EAAO,CAAC,CAAA,EAAG;AAC1B,QAAA;AAAA,MACJ;AACA,MAAA,IAAI,YAAA,CAAa,IAAA,CAAK,CAAC,CAAA,EAAG;AAEtB,QAAA,cAAA,CAAe,CAAC,CAAA,GAAK,KAAA,CAAc,CAAC,CAAA;AAAA,MACxC;AAAA,IACJ;AACA,IAAA,OAAO,EAAE,cAAA,EAAe;AAAA,EAC5B,CAAA,EAAG,CAAC,kBAAA,EAAoB,KAAK,CAAC,CAAA;AAC9B,EAAA,OAAO,MAAA;AACX;;;;"}
|