@open-pioneer/react-utils 4.5.0-dev-css-prop.20260210113101 → 4.5.0-dev-css-prop.20260210120105
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @open-pioneer/react-utils
|
|
2
2
|
|
|
3
|
-
## 4.5.0-dev-css-prop.
|
|
3
|
+
## 4.5.0-dev-css-prop.20260210120105
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
### Patch Changes
|
|
25
25
|
|
|
26
26
|
- Updated dependencies [4e76893]
|
|
27
|
-
- @open-pioneer/core@4.5.0-dev-css-prop.
|
|
28
|
-
- @open-pioneer/reactivity@4.5.0-dev-css-prop.
|
|
27
|
+
- @open-pioneer/core@4.5.0-dev-css-prop.20260210120105
|
|
28
|
+
- @open-pioneer/reactivity@4.5.0-dev-css-prop.20260210120105
|
|
29
29
|
|
|
30
30
|
## 4.4.0
|
|
31
31
|
|
package/mergeChakraProps.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
7
7
|
* If multiple `css` objects are defined, their values are combined into an array.
|
|
8
8
|
* This way, multiple css rules may match and will not override each other.
|
|
9
9
|
*/
|
|
10
|
-
export declare function mergeChakraProps<T extends
|
|
10
|
+
export declare function mergeChakraProps<T extends {}>(...args: T[]): Omit<UnionToIntersection<T>, "css"> & {
|
|
11
11
|
css?: SystemStyleObject | SystemStyleObject[];
|
|
12
12
|
};
|
|
13
13
|
export {};
|
package/mergeChakraProps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeChakraProps.js","sources":["mergeChakraProps.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { mergeProps, SystemStyleObject } from \"@chakra-ui/react\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void\n ? I\n : never;\n\n/**\n * Merges multiple `props` objects from left to right.\n *\n * This function works like Chakra's {@link mergeProps}, but has additional support for Chakra's `css` property.\n * If multiple `css` objects are defined, their values are combined into an array.\n * This way, multiple css rules may match and will not override each other.\n */\nexport function mergeChakraProps<T extends
|
|
1
|
+
{"version":3,"file":"mergeChakraProps.js","sources":["mergeChakraProps.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { mergeProps, SystemStyleObject } from \"@chakra-ui/react\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void\n ? I\n : never;\n\n/**\n * Merges multiple `props` objects from left to right.\n *\n * This function works like Chakra's {@link mergeProps}, but has additional support for Chakra's `css` property.\n * If multiple `css` objects are defined, their values are combined into an array.\n * This way, multiple css rules may match and will not override each other.\n */\nexport function mergeChakraProps<T extends {}>(\n ...args: T[]\n): Omit<UnionToIntersection<T>, \"css\"> & { css?: SystemStyleObject | SystemStyleObject[] } {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const mergedProps = mergeProps(...args) as Record<string, any>;\n\n // mergeProps handles plain html attributes only; merge chakra css on our own.\n let mergedCss: SystemStyleObject | SystemStyleObject[] | undefined;\n for (const props of args) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const localCss = (props as any).css as SystemStyleObject | SystemStyleObject[] | undefined;\n if (!localCss || typeof localCss !== \"object\") {\n continue;\n }\n\n if (!mergedCss) {\n if (Array.isArray(localCss)) {\n mergedCss = [...localCss];\n } else {\n mergedCss = localCss;\n }\n } else if (!Array.isArray(mergedCss)) {\n mergedCss = [mergedCss, ...wrap(localCss)];\n } else {\n mergedCss.push(...wrap(localCss));\n }\n }\n if (mergedCss) {\n mergedProps.css = mergedCss;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return mergedProps as any;\n}\n\nfunction wrap<T>(v: T | T[]): T[] {\n if (Array.isArray(v)) {\n return v;\n }\n return [v];\n}\n"],"names":[],"mappings":";;AAgBO,SAAS,oBACT,IAAA,EACoF;AAEvF,EAAA,MAAM,WAAA,GAAc,UAAA,CAAW,GAAG,IAAI,CAAA;AAGtC,EAAA,IAAI,SAAA;AACJ,EAAA,KAAA,MAAW,SAAS,IAAA,EAAM;AAEtB,IAAA,MAAM,WAAY,KAAA,CAAc,GAAA;AAChC,IAAA,IAAI,CAAC,QAAA,IAAY,OAAO,QAAA,KAAa,QAAA,EAAU;AAC3C,MAAA;AAAA,IACJ;AAEA,IAAA,IAAI,CAAC,SAAA,EAAW;AACZ,MAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,QAAQ,CAAA,EAAG;AACzB,QAAA,SAAA,GAAY,CAAC,GAAG,QAAQ,CAAA;AAAA,MAC5B,CAAA,MAAO;AACH,QAAA,SAAA,GAAY,QAAA;AAAA,MAChB;AAAA,IACJ,CAAA,MAAA,IAAW,CAAC,KAAA,CAAM,OAAA,CAAQ,SAAS,CAAA,EAAG;AAClC,MAAA,SAAA,GAAY,CAAC,SAAA,EAAW,GAAG,IAAA,CAAK,QAAQ,CAAC,CAAA;AAAA,IAC7C,CAAA,MAAO;AACH,MAAA,SAAA,CAAU,IAAA,CAAK,GAAG,IAAA,CAAK,QAAQ,CAAC,CAAA;AAAA,IACpC;AAAA,EACJ;AACA,EAAA,IAAI,SAAA,EAAW;AACX,IAAA,WAAA,CAAY,GAAA,GAAM,SAAA;AAAA,EACtB;AAEA,EAAA,OAAO,WAAA;AACX;AAEA,SAAS,KAAQ,CAAA,EAAiB;AAC9B,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,CAAC,CAAA,EAAG;AAClB,IAAA,OAAO,CAAA;AAAA,EACX;AACA,EAAA,OAAO,CAAC,CAAC,CAAA;AACb;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/react-utils",
|
|
4
|
-
"version": "4.5.0-dev-css-prop.
|
|
4
|
+
"version": "4.5.0-dev-css-prop.20260210120105",
|
|
5
5
|
"description": "Contains common react utilities used by the open pioneer trails project",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"@conterra/reactivity-core": "^0.8.1",
|
|
19
19
|
"classnames": "^2.5.1",
|
|
20
20
|
"react": "^19.2.4",
|
|
21
|
-
"@open-pioneer/
|
|
22
|
-
"@open-pioneer/
|
|
21
|
+
"@open-pioneer/core": "4.5.0-dev-css-prop.20260210120105",
|
|
22
|
+
"@open-pioneer/reactivity": "4.5.0-dev-css-prop.20260210120105"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
"./package.json": "./package.json",
|
|
@@ -41,8 +41,9 @@ export interface CommonComponentProps extends AriaAttributes {
|
|
|
41
41
|
/**
|
|
42
42
|
* @group Common component props
|
|
43
43
|
*/
|
|
44
|
-
export interface CommonComponentContainerProps extends HTMLAttributes<HTMLElement
|
|
44
|
+
export interface CommonComponentContainerProps extends Pick<HTMLAttributes<HTMLElement>, "className" | "role">, AriaAttributes {
|
|
45
45
|
css?: SystemStyleObject | SystemStyleObject[];
|
|
46
|
+
[key: `data-${string}`]: unknown;
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
49
|
* A helper hook that computes react properties for the topmost container in a public react component.
|
|
@@ -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 \"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
|
|
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;;;;"}
|