@open-pioneer/react-utils 4.5.1-dev.20260327142931 → 4.6.0-dev-classnames.20260519092818
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 +12 -1
- package/TitledSection.d.ts +8 -0
- package/TitledSection.js +4 -1
- package/TitledSection.js.map +1 -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 +6 -7
- package/useCommonComponentProps.js +1 -1
- package/useCommonComponentProps.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
# @open-pioneer/react-utils
|
|
2
2
|
|
|
3
|
-
## 4.
|
|
3
|
+
## 4.6.0-dev-classnames.20260519092818
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 24b29e0: classnames dependency removed with own solution
|
|
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`.
|
|
9
|
+
|
|
10
|
+
This allows to use the hook in components which do not necessarily need to be used inside a `TitledSection`.
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
const currentHeading: number | undefined = useHeadingLevel({ required: false });
|
|
14
|
+
```
|
|
4
15
|
|
|
5
16
|
## 4.5.0
|
|
6
17
|
|
package/TitledSection.d.ts
CHANGED
|
@@ -169,7 +169,15 @@ export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
|
169
169
|
* Returns the current heading level.
|
|
170
170
|
*
|
|
171
171
|
* This hook should be used in the `title` property of a {@link TitledSection} or in that component's children.
|
|
172
|
+
* If you use it outside of a TitledSection, it will throw an error by default.
|
|
173
|
+
* You can set `required: false` to make it return `undefined` instead of throwing an error
|
|
172
174
|
*
|
|
173
175
|
* @group Headings
|
|
174
176
|
*/
|
|
175
177
|
export declare function useHeadingLevel(): HeadingLevel;
|
|
178
|
+
export declare function useHeadingLevel(props: {
|
|
179
|
+
required: false;
|
|
180
|
+
}): HeadingLevel | undefined;
|
|
181
|
+
export declare function useHeadingLevel(props: {
|
|
182
|
+
required?: true;
|
|
183
|
+
}): HeadingLevel;
|
package/TitledSection.js
CHANGED
|
@@ -23,9 +23,12 @@ const ConfigureTitledSection = (props) => {
|
|
|
23
23
|
const level = props.level - 1;
|
|
24
24
|
return /* @__PURE__ */ jsx(LevelContext, { value: level, children: props.children });
|
|
25
25
|
};
|
|
26
|
-
function useHeadingLevel() {
|
|
26
|
+
function useHeadingLevel(props) {
|
|
27
27
|
const level = useContext(LevelContext);
|
|
28
28
|
if (level == null) {
|
|
29
|
+
if (props?.required === false) {
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
29
32
|
throw new Error("useHeadingLevel() must be used within a <TitledSection />");
|
|
30
33
|
}
|
|
31
34
|
return Math.max(1, Math.min(level, 6));
|
package/TitledSection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TitledSection.js","sources":["TitledSection.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Heading, HeadingProps } from \"@chakra-ui/react\";\nimport { FC, ReactNode, RefAttributes, createContext, useContext } from \"react\";\n\nconst LevelContext = createContext<number | undefined>(undefined);\nLevelContext.displayName = \"LevelContext\";\n\n/**\n * Properties of the {@link TitledSection} component.\n *\n * @group Headings\n **/\nexport interface TitledSectionProps {\n /**\n * The title component.\n *\n * Strings are automatically wrapped in a {@link SectionHeading}.\n * More complex nodes should use the {@link SectionHeading} internally.\n */\n title?: string | ReactNode | undefined;\n\n /**\n * Properties for the automatically generated section heading.\n *\n * NOTE: This is only applied if `title` is a string.\n */\n sectionHeadingProps?: SectionHeadingProps | undefined;\n\n /**\n * Children are rendered without any modifications.\n */\n children?: ReactNode | undefined;\n}\n\n/**\n * Automatically manages the level of html headings such as `h1` and `h2`.\n *\n * Use this component's `title` property or `<SectionHeading />` components in the children\n * of this component instead of manual heading tags.\n * Nested sections will automatically use the correct level for their current location.\n *\n * Titles are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading) by default.\n *\n * **Example:** Simple string headings (1, 2 and 3 will be rendered as h1, h2 and h3):\n *\n * ```jsx\n * <TitledSection title=\"1\">\n * Top level content\n *\n * <TitledSection title=\"2\" sectionHeadingProps={...}>\n * Nested content\n *\n * <TitledSection title=\"3\">\n * Deeply nested content\n * </TitledSection>\n * </TitledSection>\n * </TitledSection>\n * ```\n *\n * When using using a string for the `title` prop, you can specify the `sectionHeadingProps` to\n * customize the properties of the automatically generated heading component.\n *\n * **Example:** custom section headings as children\n *\n * ```jsx\n * <TitledSection>\n * <SectionHeading>Top level heading (H1)</SectionHeading>\n *\n * .. Some Content ..\n *\n * <TitledSection>\n * <SectionHeading>Other Heading (H2)</SectionHeading>\n *\n * .. More Content ..\n * </TitledSection>\n *\n * </TitledSection>\n * ```\n *\n * > NOTE: You should use exactly one `<SectionHeading />` for each `<TitledSection />`.\n * > The SectionHeading can appear anywhere, for example wrapped in other layout components.\n *\n * **Example:** custom title rendering\n *\n * You can also use completely custom components for the title.\n * In this case, you should ensure that you use the `SectionHeading` component within the `title` in some place.\n * The section heading does not need to be the immediate child, you can wrap it any way you want.\n *\n * ```jsx\n * <TitledSection\n * title={\n * <SectionHeading size=\"4xl\">Heading</SectionHeading>\n * }\n * >\n * Content\n * </TitledSection>\n * ```\n *\n * @group Headings\n * @expandType TitledSectionProps\n */\nexport function TitledSection(props: TitledSectionProps): ReactNode {\n const { title, sectionHeadingProps, children } = props;\n const currentLevel = useContext(LevelContext) ?? 0;\n const heading =\n typeof title === \"string\" ? (\n <SectionHeading {...sectionHeadingProps}>{title}</SectionHeading>\n ) : (\n title\n );\n\n return (\n <LevelContext value={currentLevel + 1}>\n {heading}\n {children}\n </LevelContext>\n );\n}\n\n/**\n * Properties supported by the {@link SectionHeading} component.\n *\n * All chakra properties are forwarded to the [Heading](https://chakra-ui.com/docs/components/heading) component.\n *\n * @group Headings\n */\nexport interface SectionHeadingProps extends HeadingProps, RefAttributes<HTMLHeadingElement> {\n children?: ReactNode | undefined;\n}\n\n/**\n * Renders an appropriate heading tag for the current heading level (`h1` through `h6`).\n * This component should only be used as part of the `title` prop of the {@link TitledSection}.\n *\n * Headings are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading).\n *\n * Heading levels are managed by nesting {@link TitledSection}.\n *\n * @group Headings\n * @expandType SectionHeadingProps\n */\nexport function SectionHeading(props: SectionHeadingProps): ReactNode {\n const { children, ref, ...rest } = props;\n const level = useHeadingLevel();\n const tag = getHeadingTag(level);\n return (\n <Heading as={tag} ref={ref} {...rest}>\n {children}\n </Heading>\n );\n}\n\n/**\n * Properties for the {@link ConfigureTitledSection} component.\n *\n * @group Headings\n */\nexport interface ConfigureTitledSectionProps {\n level: HeadingLevel;\n children?: ReactNode;\n}\n\n/**\n * Overrides the heading level for all children.\n *\n * TitledSection components nested in `children` will start with the configured level.\n * Nested TitledSections will continue to use the next appropriate heading level.\n *\n * Example: Changing the global heading level for your application\n *\n * If your application is embedded into another site, it should often not use the `h1` tag\n * but start with a higher heading level instead. To achieve that, simply wrap your application\n * with `<ConfigureTitledSectionProps>`. No other code changes are necessary:\n *\n * ```jsx\n * <ConfigureTitledSection level={2}>\n * <TheRestOfYourApplication />\n * </ConfigureTitledSection>\n * ```\n *\n * Example: Embedding a widget\n *\n * Given a `<Widget />` (that we cannot easily change) that internally uses `TitledSection`,\n * this is how we can embed it with a custom heading level.\n * This can be appropriate in some circumstances, for example when the react component tree does not match the DOM\n * tree (portals etc.).\n *\n * ```jsx\n * <ConfigureTitledSection level={5}>\n * <Widget />\n * </ConfigureTitledSection>\n * ```\n *\n * The headings used by `Widget` will start with `h5`.\n *\n * @group Headings\n * @expandType ConfigureTitledSectionProps\n */\nexport const ConfigureTitledSection: FC<ConfigureTitledSectionProps> = (props) => {\n const level = props.level - 1; // TitledSection increments by 1.\n return <LevelContext value={level}>{props.children}</LevelContext>;\n};\n\n/**\n * The level of a html heading.\n * @group Headings\n **/\nexport type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Returns the current heading level.\n *\n * This hook should be used in the `title` property of a {@link TitledSection} or in that component's children.\n *\n * @group Headings\n */\nexport function useHeadingLevel(): HeadingLevel {\n const level = useContext(LevelContext);\n if (level == null) {\n throw new Error(\"useHeadingLevel() must be used within a <TitledSection />\");\n }\n return Math.max(1, Math.min(level, 6)) as HeadingLevel;\n}\n\nfunction getHeadingTag(level: HeadingLevel): `h${HeadingLevel}` {\n return `h${level}`;\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,YAAA,GAAe,cAAkC,MAAS,CAAA;AAChE,YAAA,CAAa,WAAA,GAAc,cAAA;AAgGpB,SAAS,cAAc,KAAA,EAAsC;AAChE,EAAA,MAAM,EAAE,KAAA,EAAO,mBAAA,EAAqB,QAAA,EAAS,GAAI,KAAA;AACjD,EAAA,MAAM,YAAA,GAAe,UAAA,CAAW,YAAY,CAAA,IAAK,CAAA;AACjD,EAAA,MAAM,OAAA,GACF,OAAO,KAAA,KAAU,QAAA,uBACZ,cAAA,EAAA,EAAgB,GAAG,mBAAA,EAAsB,QAAA,EAAA,KAAA,EAAM,CAAA,GAEhD,KAAA;AAGR,EAAA,uBACI,IAAA,CAAC,YAAA,EAAA,EAAa,KAAA,EAAO,YAAA,GAAe,CAAA,EAC/B,QAAA,EAAA;AAAA,IAAA,OAAA;AAAA,IACA;AAAA,GAAA,EACL,CAAA;AAER;AAwBO,SAAS,eAAe,KAAA,EAAuC;AAClE,EAAA,MAAM,EAAE,QAAA,EAAU,GAAA,EAAK,GAAG,MAAK,GAAI,KAAA;AACnC,EAAA,MAAM,QAAQ,eAAA,EAAgB;AAC9B,EAAA,MAAM,GAAA,GAAM,cAAc,KAAK,CAAA;AAC/B,EAAA,2BACK,OAAA,EAAA,EAAQ,EAAA,EAAI,KAAK,GAAA,EAAW,GAAG,MAC3B,QAAA,EACL,CAAA;AAER;AAgDO,MAAM,sBAAA,GAA0D,CAAC,KAAA,KAAU;AAC9E,EAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,GAAQ,CAAA;AAC5B,EAAA,uBAAO,GAAA,CAAC,YAAA,EAAA,EAAa,KAAA,EAAO,KAAA,EAAQ,gBAAM,QAAA,EAAS,CAAA;AACvD;
|
|
1
|
+
{"version":3,"file":"TitledSection.js","sources":["TitledSection.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Heading, HeadingProps } from \"@chakra-ui/react\";\nimport { FC, ReactNode, RefAttributes, createContext, useContext } from \"react\";\n\nconst LevelContext = createContext<number | undefined>(undefined);\nLevelContext.displayName = \"LevelContext\";\n\n/**\n * Properties of the {@link TitledSection} component.\n *\n * @group Headings\n **/\nexport interface TitledSectionProps {\n /**\n * The title component.\n *\n * Strings are automatically wrapped in a {@link SectionHeading}.\n * More complex nodes should use the {@link SectionHeading} internally.\n */\n title?: string | ReactNode | undefined;\n\n /**\n * Properties for the automatically generated section heading.\n *\n * NOTE: This is only applied if `title` is a string.\n */\n sectionHeadingProps?: SectionHeadingProps | undefined;\n\n /**\n * Children are rendered without any modifications.\n */\n children?: ReactNode | undefined;\n}\n\n/**\n * Automatically manages the level of html headings such as `h1` and `h2`.\n *\n * Use this component's `title` property or `<SectionHeading />` components in the children\n * of this component instead of manual heading tags.\n * Nested sections will automatically use the correct level for their current location.\n *\n * Titles are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading) by default.\n *\n * **Example:** Simple string headings (1, 2 and 3 will be rendered as h1, h2 and h3):\n *\n * ```jsx\n * <TitledSection title=\"1\">\n * Top level content\n *\n * <TitledSection title=\"2\" sectionHeadingProps={...}>\n * Nested content\n *\n * <TitledSection title=\"3\">\n * Deeply nested content\n * </TitledSection>\n * </TitledSection>\n * </TitledSection>\n * ```\n *\n * When using using a string for the `title` prop, you can specify the `sectionHeadingProps` to\n * customize the properties of the automatically generated heading component.\n *\n * **Example:** custom section headings as children\n *\n * ```jsx\n * <TitledSection>\n * <SectionHeading>Top level heading (H1)</SectionHeading>\n *\n * .. Some Content ..\n *\n * <TitledSection>\n * <SectionHeading>Other Heading (H2)</SectionHeading>\n *\n * .. More Content ..\n * </TitledSection>\n *\n * </TitledSection>\n * ```\n *\n * > NOTE: You should use exactly one `<SectionHeading />` for each `<TitledSection />`.\n * > The SectionHeading can appear anywhere, for example wrapped in other layout components.\n *\n * **Example:** custom title rendering\n *\n * You can also use completely custom components for the title.\n * In this case, you should ensure that you use the `SectionHeading` component within the `title` in some place.\n * The section heading does not need to be the immediate child, you can wrap it any way you want.\n *\n * ```jsx\n * <TitledSection\n * title={\n * <SectionHeading size=\"4xl\">Heading</SectionHeading>\n * }\n * >\n * Content\n * </TitledSection>\n * ```\n *\n * @group Headings\n * @expandType TitledSectionProps\n */\nexport function TitledSection(props: TitledSectionProps): ReactNode {\n const { title, sectionHeadingProps, children } = props;\n const currentLevel = useContext(LevelContext) ?? 0;\n const heading =\n typeof title === \"string\" ? (\n <SectionHeading {...sectionHeadingProps}>{title}</SectionHeading>\n ) : (\n title\n );\n\n return (\n <LevelContext value={currentLevel + 1}>\n {heading}\n {children}\n </LevelContext>\n );\n}\n\n/**\n * Properties supported by the {@link SectionHeading} component.\n *\n * All chakra properties are forwarded to the [Heading](https://chakra-ui.com/docs/components/heading) component.\n *\n * @group Headings\n */\nexport interface SectionHeadingProps extends HeadingProps, RefAttributes<HTMLHeadingElement> {\n children?: ReactNode | undefined;\n}\n\n/**\n * Renders an appropriate heading tag for the current heading level (`h1` through `h6`).\n * This component should only be used as part of the `title` prop of the {@link TitledSection}.\n *\n * Headings are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading).\n *\n * Heading levels are managed by nesting {@link TitledSection}.\n *\n * @group Headings\n * @expandType SectionHeadingProps\n */\nexport function SectionHeading(props: SectionHeadingProps): ReactNode {\n const { children, ref, ...rest } = props;\n const level = useHeadingLevel();\n const tag = getHeadingTag(level);\n return (\n <Heading as={tag} ref={ref} {...rest}>\n {children}\n </Heading>\n );\n}\n\n/**\n * Properties for the {@link ConfigureTitledSection} component.\n *\n * @group Headings\n */\nexport interface ConfigureTitledSectionProps {\n level: HeadingLevel;\n children?: ReactNode;\n}\n\n/**\n * Overrides the heading level for all children.\n *\n * TitledSection components nested in `children` will start with the configured level.\n * Nested TitledSections will continue to use the next appropriate heading level.\n *\n * Example: Changing the global heading level for your application\n *\n * If your application is embedded into another site, it should often not use the `h1` tag\n * but start with a higher heading level instead. To achieve that, simply wrap your application\n * with `<ConfigureTitledSectionProps>`. No other code changes are necessary:\n *\n * ```jsx\n * <ConfigureTitledSection level={2}>\n * <TheRestOfYourApplication />\n * </ConfigureTitledSection>\n * ```\n *\n * Example: Embedding a widget\n *\n * Given a `<Widget />` (that we cannot easily change) that internally uses `TitledSection`,\n * this is how we can embed it with a custom heading level.\n * This can be appropriate in some circumstances, for example when the react component tree does not match the DOM\n * tree (portals etc.).\n *\n * ```jsx\n * <ConfigureTitledSection level={5}>\n * <Widget />\n * </ConfigureTitledSection>\n * ```\n *\n * The headings used by `Widget` will start with `h5`.\n *\n * @group Headings\n * @expandType ConfigureTitledSectionProps\n */\nexport const ConfigureTitledSection: FC<ConfigureTitledSectionProps> = (props) => {\n const level = props.level - 1; // TitledSection increments by 1.\n return <LevelContext value={level}>{props.children}</LevelContext>;\n};\n\n/**\n * The level of a html heading.\n * @group Headings\n **/\nexport type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Returns the current heading level.\n *\n * This hook should be used in the `title` property of a {@link TitledSection} or in that component's children.\n * If you use it outside of a TitledSection, it will throw an error by default.\n * You can set `required: false` to make it return `undefined` instead of throwing an error\n *\n * @group Headings\n */\nexport function useHeadingLevel(): HeadingLevel;\nexport function useHeadingLevel(props: { required: false }): HeadingLevel | undefined;\nexport function useHeadingLevel(props: { required?: true }): HeadingLevel;\nexport function useHeadingLevel(props?: { required?: boolean }): HeadingLevel | undefined {\n const level = useContext(LevelContext);\n if (level == null) {\n if (props?.required === false) {\n return undefined;\n }\n throw new Error(\"useHeadingLevel() must be used within a <TitledSection />\");\n }\n return Math.max(1, Math.min(level, 6)) as HeadingLevel;\n}\n\nfunction getHeadingTag(level: HeadingLevel): `h${HeadingLevel}` {\n return `h${level}`;\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,YAAA,GAAe,cAAkC,MAAS,CAAA;AAChE,YAAA,CAAa,WAAA,GAAc,cAAA;AAgGpB,SAAS,cAAc,KAAA,EAAsC;AAChE,EAAA,MAAM,EAAE,KAAA,EAAO,mBAAA,EAAqB,QAAA,EAAS,GAAI,KAAA;AACjD,EAAA,MAAM,YAAA,GAAe,UAAA,CAAW,YAAY,CAAA,IAAK,CAAA;AACjD,EAAA,MAAM,OAAA,GACF,OAAO,KAAA,KAAU,QAAA,uBACZ,cAAA,EAAA,EAAgB,GAAG,mBAAA,EAAsB,QAAA,EAAA,KAAA,EAAM,CAAA,GAEhD,KAAA;AAGR,EAAA,uBACI,IAAA,CAAC,YAAA,EAAA,EAAa,KAAA,EAAO,YAAA,GAAe,CAAA,EAC/B,QAAA,EAAA;AAAA,IAAA,OAAA;AAAA,IACA;AAAA,GAAA,EACL,CAAA;AAER;AAwBO,SAAS,eAAe,KAAA,EAAuC;AAClE,EAAA,MAAM,EAAE,QAAA,EAAU,GAAA,EAAK,GAAG,MAAK,GAAI,KAAA;AACnC,EAAA,MAAM,QAAQ,eAAA,EAAgB;AAC9B,EAAA,MAAM,GAAA,GAAM,cAAc,KAAK,CAAA;AAC/B,EAAA,2BACK,OAAA,EAAA,EAAQ,EAAA,EAAI,KAAK,GAAA,EAAW,GAAG,MAC3B,QAAA,EACL,CAAA;AAER;AAgDO,MAAM,sBAAA,GAA0D,CAAC,KAAA,KAAU;AAC9E,EAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,GAAQ,CAAA;AAC5B,EAAA,uBAAO,GAAA,CAAC,YAAA,EAAA,EAAa,KAAA,EAAO,KAAA,EAAQ,gBAAM,QAAA,EAAS,CAAA;AACvD;AAoBO,SAAS,gBAAgB,KAAA,EAA0D;AACtF,EAAA,MAAM,KAAA,GAAQ,WAAW,YAAY,CAAA;AACrC,EAAA,IAAI,SAAS,IAAA,EAAM;AACf,IAAA,IAAI,KAAA,EAAO,aAAa,KAAA,EAAO;AAC3B,MAAA,OAAO,MAAA;AAAA,IACX;AACA,IAAA,MAAM,IAAI,MAAM,2DAA2D,CAAA;AAAA,EAC/E;AACA,EAAA,OAAO,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,KAAA,EAAO,CAAC,CAAC,CAAA;AACzC;AAEA,SAAS,cAAc,KAAA,EAAyC;AAC5D,EAAA,OAAO,IAAI,KAAK,CAAA,CAAA;AACpB;;;;"}
|
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.
|
|
4
|
+
"version": "4.6.0-dev-classnames.20260519092818",
|
|
5
5
|
"description": "Contains common react utilities used by the open pioneer trails project",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -15,11 +15,10 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@chakra-ui/react": "^3.34.0",
|
|
18
|
-
"@conterra/reactivity-core": "^0.8.
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"@open-pioneer/
|
|
22
|
-
"@open-pioneer/reactivity": "4.5.1-dev.20260327142931"
|
|
18
|
+
"@conterra/reactivity-core": "^0.8.5",
|
|
19
|
+
"react": "^19.2.6",
|
|
20
|
+
"@open-pioneer/core": "4.6.0-dev-classnames.20260519092818",
|
|
21
|
+
"@open-pioneer/reactivity": "4.6.0-dev-classnames.20260519092818"
|
|
23
22
|
},
|
|
24
23
|
"exports": {
|
|
25
24
|
"./package.json": "./package.json",
|
|
@@ -37,6 +36,6 @@
|
|
|
37
36
|
"references": []
|
|
38
37
|
},
|
|
39
38
|
"properties": [],
|
|
40
|
-
"packageFormatVersion": "1.0.
|
|
39
|
+
"packageFormatVersion": "1.0.1"
|
|
41
40
|
}
|
|
42
41
|
}
|
|
@@ -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;;;;"}
|