@open-pioneer/react-utils 0.2.3 → 1.0.0

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,5 +1,24 @@
1
1
  # @open-pioneer/react-utils
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - a208b32: **Breaking:** Removed the `ToolButton` component; it has moved to `@open-pioneer/map-ui-components`.
8
+
9
+ If you were previously using the `ToolButton` in your app, you need to update your import statements when updating to this version:
10
+
11
+ ```diff
12
+ - import { ToolButton } from "@open-pioneer/react-utils";
13
+ + import { ToolButton } from "@open-pioneer/map-ui-components";
14
+ ```
15
+
16
+ You need to update your `package.json` as well to refer to the `map-ui-components` package.
17
+
18
+ ### Minor Changes
19
+
20
+ - a208b32: Move this package to the core-packages repository.
21
+
3
22
  ## 0.2.3
4
23
 
5
24
  ### Patch Changes
package/README.md CHANGED
@@ -41,16 +41,6 @@ Example:
41
41
  In the preceding example the topmost heading(s) in `TheRestOfYourApplication` start at level 2, and nested headings use increasing levels as usual.
42
42
  For more details, see the API documentation.
43
43
 
44
- ## Tool buttons
45
-
46
- To create a simple icon button with a tooltip and an `aria-label`, use the `ToolButton` component as in the following sample:
47
-
48
- ```jsx
49
- <ToolButton label={someLabel} icon={<SomeIcon />} onClick={someEventHandler} />
50
- ```
51
-
52
- This is used, for example, to add an icon button to the map.
53
-
54
44
  ## Hooks
55
45
 
56
46
  ### useCommonComponentProps()
@@ -112,6 +102,9 @@ function someReactComponent(props) {
112
102
  }
113
103
  ```
114
104
 
105
+ > Warning: the function returned by `useEvent` must **not** be called during rendering.
106
+ > It can only be used in an effect or in a event handler callback.
107
+
115
108
  For more details, see the API docs of `useEvent` or <https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md>.
116
109
 
117
110
  ## License
@@ -34,13 +34,13 @@ export interface TitledSectionProps {
34
34
  *
35
35
  * Titles are rendered as [Chakra Headings](https://chakra-ui.com/docs/components/heading) by default.
36
36
  *
37
- * Example: Simple string headings (1, 2 and 3 will be rendered as h1, h2 and h3):
37
+ * **Example:** Simple string headings (1, 2 and 3 will be rendered as h1, h2 and h3):
38
38
  *
39
39
  * ```jsx
40
40
  * <TitledSection title="1">
41
41
  * Top level content
42
42
  *
43
- * <TitledSection title="2">
43
+ * <TitledSection title="2" sectionHeadingProps={...}>
44
44
  * Nested content
45
45
  *
46
46
  * <TitledSection title="3">
@@ -50,7 +50,14 @@ export interface TitledSectionProps {
50
50
  * </TitledSection>
51
51
  * ```
52
52
  *
53
- * Example: custom title rendering
53
+ * When using using a string for the `title` prop, you can specify the `sectionHeadingProps` to
54
+ * customize the properties of the automatically generated heading component.
55
+ *
56
+ * **Example:** custom title rendering
57
+ *
58
+ * You can also use completely custom components for the title.
59
+ * In this case, you should ensure that you use the `SectionHeading` component within the `title` in some place.
60
+ * The section heading does not need to be the immediate child, you can wrap it any way you want.
54
61
  *
55
62
  * ```jsx
56
63
  * <TitledSection
@@ -1 +1 @@
1
- {"version":3,"file":"TitledSection.js","sources":["TitledSection.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Heading, HeadingProps } from \"@open-pioneer/chakra-integration\";\nimport { FC, ForwardedRef, ReactNode, createContext, forwardRef, useContext } from \"react\";\n\nconst DEFAULT_LEVEL = 1;\n\nconst LevelContext = createContext(DEFAULT_LEVEL);\nLevelContext.displayName = \"LevelContext\";\n\n/** Properties of the {@link TitledSection} component. */\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 * Allows to substitute the heading level that is used up from this section.\n * This should only be used to configure the initial level\n * or if it is actually intended to adjust the DOM structure.\n */\n substituteHeadingLevel?: HeadingLevel | 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 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\">\n * Nested content\n *\n * <TitledSection title=\"3\">\n * Deeply nested content\n * </TitledSection>\n * </TitledSection>\n * </TitledSection>\n * ```\n *\n * Example: custom title rendering\n *\n * ```jsx\n * <TitledSection\n * title={\n * <SectionHeading size=\"4xl\">Heading</SectionHeading>\n * }\n * >\n * Content\n * </TitledSection>\n * ```\n */\nexport function TitledSection(props: TitledSectionProps): JSX.Element {\n const { title, sectionHeadingProps, children } = props;\n const currentLevel = useContext(LevelContext);\n const heading =\n typeof title === \"string\" ? (\n <SectionHeading {...sectionHeadingProps}>{title}</SectionHeading>\n ) : (\n title\n );\n\n return (\n <>\n {heading}\n <LevelContext.Provider value={currentLevel + 1}>{children}</LevelContext.Provider>\n </>\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 */\nexport interface SectionHeadingProps extends HeadingProps {\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 */\nexport const SectionHeading = forwardRef(function SectionHeading(\n props: SectionHeadingProps,\n forwardedRef: ForwardedRef<HTMLHeadingElement>\n): JSX.Element {\n const { children, ...rest } = props;\n const level = useHeadingLevel();\n const tag = getHeadingTag(level);\n return (\n <Heading as={tag} ref={forwardedRef} {...rest}>\n {children}\n </Heading>\n );\n});\n\n/**\n * Properties for the {@link ConfigureTitledSection} component.\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 */\nexport const ConfigureTitledSection: FC<ConfigureTitledSectionProps> = (props) => {\n return <LevelContext.Provider value={props.level}>{props.children}</LevelContext.Provider>;\n};\n\n/** The level of a html heading. */\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}.\n */\nexport function useHeadingLevel(): HeadingLevel {\n const level = useContext(LevelContext);\n return Math.min(level, 6) as HeadingLevel;\n}\n\nfunction getHeadingTag(level: HeadingLevel): `h${HeadingLevel}` {\n return `h${level}`;\n}\n"],"names":["SectionHeading"],"mappings":";;;;AAKA,MAAM,aAAgB,GAAA,CAAA,CAAA;AAEtB,MAAM,YAAA,GAAe,cAAc,aAAa,CAAA,CAAA;A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A,CAAK,GAAI,CAAA,KAAA,EAAO,CAAC,CAAA,CAAA;AAC5B,CAAA;AAEA,SAAS,cAAc,KAAyC,EAAA;AAC5D,EAAA,OAAO,IAAI,KAAK,CAAA,CAAA,CAAA;AACpB;;;;"}
1
+ {"version":3,"file":"TitledSection.js","sources":["TitledSection.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Heading, HeadingProps } from \"@open-pioneer/chakra-integration\";\nimport { FC, ForwardedRef, ReactNode, createContext, forwardRef, useContext } from \"react\";\n\nconst DEFAULT_LEVEL = 1;\n\nconst LevelContext = createContext(DEFAULT_LEVEL);\nLevelContext.displayName = \"LevelContext\";\n\n/** Properties of the {@link TitledSection} component. */\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 * Allows to substitute the heading level that is used up from this section.\n * This should only be used to configure the initial level\n * or if it is actually intended to adjust the DOM structure.\n */\n substituteHeadingLevel?: HeadingLevel | 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 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 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 */\nexport function TitledSection(props: TitledSectionProps): JSX.Element {\n const { title, sectionHeadingProps, children } = props;\n const currentLevel = useContext(LevelContext);\n const heading =\n typeof title === \"string\" ? (\n <SectionHeading {...sectionHeadingProps}>{title}</SectionHeading>\n ) : (\n title\n );\n\n return (\n <>\n {heading}\n <LevelContext.Provider value={currentLevel + 1}>{children}</LevelContext.Provider>\n </>\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 */\nexport interface SectionHeadingProps extends HeadingProps {\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 */\nexport const SectionHeading = forwardRef(function SectionHeading(\n props: SectionHeadingProps,\n forwardedRef: ForwardedRef<HTMLHeadingElement>\n): JSX.Element {\n const { children, ...rest } = props;\n const level = useHeadingLevel();\n const tag = getHeadingTag(level);\n return (\n <Heading as={tag} ref={forwardedRef} {...rest}>\n {children}\n </Heading>\n );\n});\n\n/**\n * Properties for the {@link ConfigureTitledSection} component.\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 */\nexport const ConfigureTitledSection: FC<ConfigureTitledSectionProps> = (props) => {\n return <LevelContext.Provider value={props.level}>{props.children}</LevelContext.Provider>;\n};\n\n/** The level of a html heading. */\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}.\n */\nexport function useHeadingLevel(): HeadingLevel {\n const level = useContext(LevelContext);\n return Math.min(level, 6) as HeadingLevel;\n}\n\nfunction getHeadingTag(level: HeadingLevel): `h${HeadingLevel}` {\n return `h${level}`;\n}\n"],"names":["SectionHeading"],"mappings":";;;;AAKA,MAAM,aAAgB,GAAA,CAAA,CAAA;AAEtB,MAAM,YAAA,GAAe,cAAc,aAAa,CAAA,CAAA;AAChD,YAAA,CAAa,WAAc,GAAA,cAAA,CAAA;AA2EpB,SAAS,cAAc,KAAwC,EAAA;AAClE,EAAA,MAAM,EAAE,KAAA,EAAO,mBAAqB,EAAA,QAAA,EAAa,GAAA,KAAA,CAAA;AACjD,EAAM,MAAA,YAAA,GAAe,WAAW,YAAY,CAAA,CAAA;AAC5C,EAAM,MAAA,OAAA,GACF,OAAO,KAAU,KAAA,QAAA,uBACZ,cAAgB,EAAA,EAAA,GAAG,mBAAsB,EAAA,QAAA,EAAA,KAAA,EAAM,CAEhD,GAAA,KAAA,CAAA;AAGR,EAAA,uBAES,IAAA,CAAA,QAAA,EAAA,EAAA,QAAA,EAAA;AAAA,IAAA,OAAA;AAAA,wBACA,YAAa,CAAA,QAAA,EAAb,EAAsB,KAAO,EAAA,YAAA,GAAe,GAAI,QAAS,EAAA,CAAA;AAAA,GAC9D,EAAA,CAAA,CAAA;AAER,CAAA;AAmBO,MAAM,cAAiB,GAAA,UAAA,CAAW,SAASA,eAAAA,CAC9C,OACA,YACW,EAAA;AACX,EAAA,MAAM,EAAE,QAAA,EAAU,GAAG,IAAA,EAAS,GAAA,KAAA,CAAA;AAC9B,EAAA,MAAM,QAAQ,eAAgB,EAAA,CAAA;AAC9B,EAAM,MAAA,GAAA,GAAM,cAAc,KAAK,CAAA,CAAA;AAC/B,EACI,uBAAA,GAAA,CAAC,WAAQ,EAAI,EAAA,GAAA,EAAK,KAAK,YAAe,EAAA,GAAG,MACpC,QACL,EAAA,CAAA,CAAA;AAER,CAAC,EAAA;AA4CY,MAAA,sBAAA,GAA0D,CAAC,KAAU,KAAA;AAC9E,EAAO,uBAAA,GAAA,CAAC,aAAa,QAAb,EAAA,EAAsB,OAAO,KAAM,CAAA,KAAA,EAAQ,gBAAM,QAAS,EAAA,CAAA,CAAA;AACtE,EAAA;AAUO,SAAS,eAAgC,GAAA;AAC5C,EAAM,MAAA,KAAA,GAAQ,WAAW,YAAY,CAAA,CAAA;AACrC,EAAO,OAAA,IAAA,CAAK,GAAI,CAAA,KAAA,EAAO,CAAC,CAAA,CAAA;AAC5B,CAAA;AAEA,SAAS,cAAc,KAAyC,EAAA;AAC5D,EAAA,OAAO,IAAI,KAAK,CAAA,CAAA,CAAA;AACpB;;;;"}
package/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export { useEvent } from "./useEvent";
2
2
  export { type TitledSectionProps, TitledSection, type SectionHeadingProps, SectionHeading, type ConfigureTitledSectionProps, ConfigureTitledSection, type HeadingLevel, useHeadingLevel } from "./TitledSection";
3
- export { type ToolButtonProps, ToolButton } from "./ToolButton";
4
3
  export { type CommonComponentProps, useCommonComponentProps } from "./useCommonComponentProps";
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export { useEvent } from './useEvent.js';
2
2
  export { ConfigureTitledSection, SectionHeading, TitledSection, useHeadingLevel } from './TitledSection.js';
3
- export { ToolButton } from './ToolButton.js';
4
3
  export { useCommonComponentProps } from './useCommonComponentProps.js';
5
4
  //# 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": "0.2.3",
4
+ "version": "1.0.0",
5
5
  "description": "Contains common react utilities used by the open pioneer trails project",
6
6
  "keywords": [
7
7
  "open-pioneer-trails"
@@ -10,14 +10,14 @@
10
10
  "license": "Apache-2.0",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/open-pioneer/trails-openlayers-base-packages",
13
+ "url": "https://github.com/open-pioneer/trails-core-packages",
14
14
  "directory": "src/packages/react-utils"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "react": "^18.3.1",
18
+ "classnames": "^2.3.2",
18
19
  "@open-pioneer/core": "^1.2.3",
19
- "@open-pioneer/chakra-integration": "^1.1.3",
20
- "classnames": "^2.3.2"
20
+ "@open-pioneer/chakra-integration": "^1.1.3"
21
21
  },
22
22
  "exports": {
23
23
  "./package.json": "./package.json",
package/useEvent.d.ts CHANGED
@@ -5,7 +5,8 @@
5
5
  * The returned event handler can be used, for example, as an event handler in `useEffect()`.
6
6
  * Because the function identity is stable, `useEffect()` will not re-trigger if the implementation changes.
7
7
  *
8
- * NOTE: the event handler must not be called during rendering!
8
+ * > Warning: the function returned by `useEvent` must **not** be called during rendering.
9
+ * > It can only be used in an effect or in a event handler callback.
9
10
  *
10
11
  * See also: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
11
12
  */
package/useEvent.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"useEvent.js","sources":["useEvent.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useCallback, useLayoutEffect, useRef } from \"react\";\n\n/**\n * Creates an event handler with stable function identity.\n * The returned function will always invoke the most recent implementation of `handler`.\n *\n * The returned event handler can be used, for example, as an event handler in `useEffect()`.\n * Because the function identity is stable, `useEffect()` will not re-trigger if the implementation changes.\n *\n * NOTE: the event handler must not be called during rendering!\n *\n * See also: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md\n */\nexport function useEvent<Args extends unknown[], Ret>(\n handler: (...args: Args) => Ret\n): typeof handler {\n const handlerRef = useRef<typeof handler | null>(null);\n\n useLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n const stableHandler = useCallback((...args: Args): Ret => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const currentHandler = handlerRef.current!;\n return currentHandler(...args);\n }, []);\n return stableHandler;\n}\n"],"names":[],"mappings":";;AAeO,SAAS,SACZ,OACc,EAAA;AACd,EAAM,MAAA,UAAA,GAAa,OAA8B,IAAI,CAAA,CAAA;AAErD,EAAA,eAAA,CAAgB,MAAM;AAClB,IAAA,UAAA,CAAW,OAAU,GAAA,OAAA,CAAA;AAAA,GACxB,CAAA,CAAA;AAED,EAAM,MAAA,aAAA,GAAgB,WAAY,CAAA,CAAA,GAAI,IAAoB,KAAA;AAEtD,IAAA,MAAM,iBAAiB,UAAW,CAAA,OAAA,CAAA;AAClC,IAAO,OAAA,cAAA,CAAe,GAAG,IAAI,CAAA,CAAA;AAAA,GACjC,EAAG,EAAE,CAAA,CAAA;AACL,EAAO,OAAA,aAAA,CAAA;AACX;;;;"}
1
+ {"version":3,"file":"useEvent.js","sources":["useEvent.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useCallback, useLayoutEffect, useRef } from \"react\";\n\n/**\n * Creates an event handler with stable function identity.\n * The returned function will always invoke the most recent implementation of `handler`.\n *\n * The returned event handler can be used, for example, as an event handler in `useEffect()`.\n * Because the function identity is stable, `useEffect()` will not re-trigger if the implementation changes.\n *\n * > Warning: the function returned by `useEvent` must **not** be called during rendering.\n * > It can only be used in an effect or in a event handler callback.\n *\n * See also: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md\n */\nexport function useEvent<Args extends unknown[], Ret>(\n handler: (...args: Args) => Ret\n): typeof handler {\n const handlerRef = useRef<typeof handler | null>(null);\n\n useLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n const stableHandler = useCallback((...args: Args): Ret => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const currentHandler = handlerRef.current!;\n return currentHandler(...args);\n }, []);\n return stableHandler;\n}\n"],"names":[],"mappings":";;AAgBO,SAAS,SACZ,OACc,EAAA;AACd,EAAM,MAAA,UAAA,GAAa,OAA8B,IAAI,CAAA,CAAA;AAErD,EAAA,eAAA,CAAgB,MAAM;AAClB,IAAA,UAAA,CAAW,OAAU,GAAA,OAAA,CAAA;AAAA,GACxB,CAAA,CAAA;AAED,EAAM,MAAA,aAAA,GAAgB,WAAY,CAAA,CAAA,GAAI,IAAoB,KAAA;AAEtD,IAAA,MAAM,iBAAiB,UAAW,CAAA,OAAA,CAAA;AAClC,IAAO,OAAA,cAAA,CAAe,GAAG,IAAI,CAAA,CAAA;AAAA,GACjC,EAAG,EAAE,CAAA,CAAA;AACL,EAAO,OAAA,aAAA,CAAA;AACX;;;;"}
package/ToolButton.d.ts DELETED
@@ -1,58 +0,0 @@
1
- import { ButtonProps, TooltipProps } from "@open-pioneer/chakra-integration";
2
- import { FC, MouseEventHandler, ReactElement, RefAttributes } from "react";
3
- import { CommonComponentProps } from "./useCommonComponentProps";
4
- /**
5
- * Properties supported by {@link ToolButton}.
6
- */
7
- export interface ToolButtonProps extends CommonComponentProps, RefAttributes<HTMLButtonElement> {
8
- /**
9
- * The label for the ToolButton.
10
- * This value services as the tooltip text and the aria-label.
11
- *
12
- * This property is required for a11y reasons because a ToolButton usually only displays an icon.
13
- */
14
- label: string;
15
- /**
16
- * The icon displayed by the button.
17
- */
18
- icon: ReactElement;
19
- /**
20
- * If `true`, the button will show a spinner.
21
- * Defaults to `false`.
22
- */
23
- isLoading?: boolean;
24
- /**
25
- * If `true`, indicates that the button is currently active with a different style.
26
- * Defaults to `undefined`.
27
- *
28
- * A value of `true` or `false` indicates that the button supports being active (i.e. pressed).
29
- * In that case the `aria-pressed` attribute will be configured automatically
30
- * (see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-pressed).
31
- */
32
- isActive?: boolean;
33
- /**
34
- * If `true`, the button will be disabled.
35
- * Defaults to `false`.
36
- */
37
- isDisabled?: boolean;
38
- /**
39
- * The callback that will be called when the user clicks the button.
40
- */
41
- onClick?: MouseEventHandler<HTMLButtonElement> | undefined;
42
- /**
43
- * Additional properties for the `Tooltip` element.
44
- *
45
- * Note that the ToolButton also defines some of these props.
46
- */
47
- tooltipProps?: Partial<TooltipProps>;
48
- /**
49
- * Additional properties for the `Button` element.
50
- *
51
- * Note that the ToolButton also defines some of these props.
52
- */
53
- buttonProps?: Partial<ButtonProps>;
54
- }
55
- /**
56
- * An button with a tooltip, used for tool buttons on a map.
57
- */
58
- export declare const ToolButton: FC<ToolButtonProps>;
package/ToolButton.js DELETED
@@ -1,69 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { Tooltip, Button } from '@open-pioneer/chakra-integration';
3
- import { forwardRef, useState } from 'react';
4
- import { useCommonComponentProps } from './useCommonComponentProps.js';
5
- import classNames from 'classnames';
6
-
7
- const ToolButton = forwardRef(function ToolButton2(props, ref) {
8
- const {
9
- label,
10
- icon,
11
- onClick: onClickProp,
12
- isLoading,
13
- isDisabled,
14
- isActive,
15
- tooltipProps,
16
- buttonProps
17
- } = props;
18
- const {
19
- containerProps: { className: baseClassName, ...containerProps }
20
- } = useCommonComponentProps("tool-button", props);
21
- const className = classNames(baseClassName, {
22
- "tool-button--active": isActive,
23
- "tool-button--loading": isLoading,
24
- "tool-button--disabled": isDisabled
25
- });
26
- const ariaPressed = typeof isActive === "boolean" ? isActive ? "true" : "false" : void 0;
27
- const [tooltipOpen, setTooltipOpen] = useState(false);
28
- const onClick = (e) => {
29
- setTooltipOpen(false);
30
- onClickProp?.(e);
31
- };
32
- return /* @__PURE__ */ jsx(
33
- Tooltip,
34
- {
35
- label,
36
- placement: "auto",
37
- openDelay: 500,
38
- ...tooltipProps,
39
- isOpen: tooltipOpen,
40
- onOpen: () => setTooltipOpen(true),
41
- onClose: () => setTooltipOpen(false),
42
- children: /* @__PURE__ */ jsx(
43
- ButtonIgnoringAriaProps,
44
- {
45
- className,
46
- ref,
47
- "aria-label": label,
48
- leftIcon: icon,
49
- iconSpacing: 0,
50
- padding: 0,
51
- isDisabled,
52
- isLoading,
53
- isActive,
54
- "aria-pressed": ariaPressed,
55
- ...containerProps,
56
- ...buttonProps,
57
- onClick
58
- }
59
- )
60
- }
61
- );
62
- });
63
- const ButtonIgnoringAriaProps = forwardRef(function ButtonIgnoringAriaProps2(props, ref) {
64
- const { "aria-labelledby": _label, "aria-describedby": _describedBy, ...rest } = props;
65
- return /* @__PURE__ */ jsx(Button, { ref, ...rest });
66
- });
67
-
68
- export { ToolButton };
69
- //# sourceMappingURL=ToolButton.js.map
package/ToolButton.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"ToolButton.js","sources":["ToolButton.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Button, ButtonProps, Tooltip, TooltipProps } from \"@open-pioneer/chakra-integration\";\nimport {\n FC,\n MouseEvent,\n MouseEventHandler,\n ReactElement,\n RefAttributes,\n forwardRef,\n useState\n} from \"react\";\nimport { CommonComponentProps, useCommonComponentProps } from \"./useCommonComponentProps\";\nimport classNames from \"classnames\";\n\n/**\n * Properties supported by {@link ToolButton}.\n */\nexport interface ToolButtonProps extends CommonComponentProps, RefAttributes<HTMLButtonElement> {\n /**\n * The label for the ToolButton.\n * This value services as the tooltip text and the aria-label.\n *\n * This property is required for a11y reasons because a ToolButton usually only displays an icon.\n */\n label: string;\n\n /**\n * The icon displayed by the button.\n */\n icon: ReactElement;\n\n /**\n * If `true`, the button will show a spinner.\n * Defaults to `false`.\n */\n isLoading?: boolean;\n\n /**\n * If `true`, indicates that the button is currently active with a different style.\n * Defaults to `undefined`.\n *\n * A value of `true` or `false` indicates that the button supports being active (i.e. pressed).\n * In that case the `aria-pressed` attribute will be configured automatically\n * (see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-pressed).\n */\n isActive?: boolean;\n\n /**\n * If `true`, the button will be disabled.\n * Defaults to `false`.\n */\n isDisabled?: boolean;\n\n /**\n * The callback that will be called when the user clicks the button.\n */\n onClick?: MouseEventHandler<HTMLButtonElement> | undefined;\n\n /**\n * Additional properties for the `Tooltip` element.\n *\n * Note that the ToolButton also defines some of these props.\n */\n tooltipProps?: Partial<TooltipProps>;\n\n /**\n * Additional properties for the `Button` element.\n *\n * Note that the ToolButton also defines some of these props.\n */\n buttonProps?: Partial<ButtonProps>;\n}\n\n/**\n * An button with a tooltip, used for tool buttons on a map.\n */\nexport const ToolButton: FC<ToolButtonProps> = forwardRef(function ToolButton(\n props: ToolButtonProps,\n ref\n) {\n const {\n label,\n icon,\n onClick: onClickProp,\n isLoading,\n isDisabled,\n isActive,\n tooltipProps,\n buttonProps\n } = props;\n\n const {\n containerProps: { className: baseClassName, ...containerProps }\n } = useCommonComponentProps(\"tool-button\", props);\n\n const className = classNames(baseClassName, {\n \"tool-button--active\": isActive,\n \"tool-button--loading\": isLoading,\n \"tool-button--disabled\": isDisabled\n });\n const ariaPressed = typeof isActive === \"boolean\" ? (isActive ? \"true\" : \"false\") : undefined;\n\n const [tooltipOpen, setTooltipOpen] = useState(false);\n const onClick = (e: MouseEvent<HTMLButtonElement>) => {\n // Immediately hide the tooltip. When the label switches in reaction to the click,\n // the tooltip would flicker briefly with the new label.\n setTooltipOpen(false);\n onClickProp?.(e);\n };\n\n return (\n <Tooltip\n label={label}\n placement=\"auto\"\n openDelay={500}\n {...tooltipProps}\n /* don't allow overwrite because component would break */\n isOpen={tooltipOpen}\n onOpen={() => setTooltipOpen(true)}\n onClose={() => setTooltipOpen(false)}\n >\n <ButtonIgnoringAriaProps\n className={className}\n ref={ref}\n aria-label={label}\n leftIcon={icon}\n iconSpacing={0}\n padding={0}\n isDisabled={isDisabled}\n isLoading={isLoading}\n isActive={isActive}\n aria-pressed={ariaPressed}\n {...containerProps}\n {...buttonProps}\n /* don't allow overwrite because component would break */\n onClick={onClick}\n />\n </Tooltip>\n );\n});\n\n/**\n * The tooltip will automatically set 'aria-describedby' when it is being shown.\n * This is redundant because the aria-label already has the same content as the tooltip.\n * This component wraps chakra's button to ignore the *-by attributes.\n */\nconst ButtonIgnoringAriaProps = forwardRef(function ButtonIgnoringAriaProps(\n props: ButtonProps,\n ref: React.ForwardedRef<HTMLButtonElement>\n) {\n const { \"aria-labelledby\": _label, \"aria-describedby\": _describedBy, ...rest } = props;\n return <Button ref={ref} {...rest} />;\n});\n"],"names":["ToolButton","ButtonIgnoringAriaProps"],"mappings":";;;;;;AA6EO,MAAM,UAAkC,GAAA,UAAA,CAAW,SAASA,WAAAA,CAC/D,OACA,GACF,EAAA;AACE,EAAM,MAAA;AAAA,IACF,KAAA;AAAA,IACA,IAAA;AAAA,IACA,OAAS,EAAA,WAAA;AAAA,IACT,SAAA;AAAA,IACA,UAAA;AAAA,I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