@open-pioneer/react-utils 0.2.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,13 +1,19 @@
1
1
  # @open-pioneer/react-utils
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 762e7b9: Add 'aria-pressed' attribute to "pressable" tool buttons (when `isActive` is `true` or `false`).
8
+
3
9
  ## 0.2.0
4
10
 
5
11
  ### Minor Changes
6
12
 
7
- - 70349a8: Update to new core packages major versions
13
+ - 70349a8: Update to new core packages major versions
8
14
 
9
15
  ## 0.1.0
10
16
 
11
17
  ### Minor Changes
12
18
 
13
- - 182da1c: Initial release.
19
+ - 182da1c: Initial release.
package/ToolButton.d.ts CHANGED
@@ -23,7 +23,11 @@ export interface ToolButtonProps extends CommonComponentProps, RefAttributes<HTM
23
23
  isLoading?: boolean;
24
24
  /**
25
25
  * If `true`, indicates that the button is currently active with a different style.
26
- * Defaults to `false`.
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).
27
31
  */
28
32
  isActive?: boolean;
29
33
  /**
package/ToolButton.js CHANGED
@@ -23,6 +23,7 @@ const ToolButton = forwardRef(function ToolButton2(props, ref) {
23
23
  "tool-button--loading": isLoading,
24
24
  "tool-button--disabled": isDisabled
25
25
  });
26
+ const ariaPressed = typeof isActive === "boolean" ? isActive ? "true" : "false" : void 0;
26
27
  const [tooltipOpen, setTooltipOpen] = useState(false);
27
28
  const onClick = (e) => {
28
29
  setTooltipOpen(false);
@@ -50,6 +51,7 @@ const ToolButton = forwardRef(function ToolButton2(props, ref) {
50
51
  isDisabled,
51
52
  isLoading,
52
53
  isActive,
54
+ "aria-pressed": ariaPressed,
53
55
  ...containerProps,
54
56
  ...buttonProps,
55
57
  onClick
package/ToolButton.js.map CHANGED
@@ -1 +1 @@
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 `false`.\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\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 {...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":";;;;;;AAyEO,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,IACA,QAAA;AAAA,I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;AAAA,SAAA;AAAA,OACJ;AAAA,KAAA;AAAA,GACJ,CAAA;AAER,CAAC,EAAA;AAOD,MAAM,uBAA0B,GAAA,UAAA,CAAW,SAASC,wBAAAA,CAChD,OACA,GACF,EAAA;AACE,EAAA,MAAM,EAAE,iBAAmB,EAAA,MAAA,EAAQ,oBAAoB,YAAc,EAAA,GAAG,MAAS,GAAA,KAAA,CAAA;AACjF,EAAA,uBAAQ,GAAA,CAAA,MAAA,EAAA,EAAO,GAAW,EAAA,GAAG,IAAM,EAAA,CAAA,CAAA;AACvC,CAAC,CAAA;;;;"}
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,IACA,QAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA;AAAA,GACA,GAAA,KAAA,CAAA;AAEJ,EAAM,MAAA;AAAA,IACF,cAAgB,EAAA,EAAE,SAAW,EAAA,aAAA,EAAe,GAAG,cAAe,EAAA;AAAA,GAClE,GAAI,uBAAwB,CAAA,aAAA,EAAe,KAAK,CAAA,CAAA;AAEhD,EAAM,MAAA,SAAA,GAAY,WAAW,aAAe,EAAA;AAAA,IACxC,qBAAuB,EAAA,QAAA;AAAA,IACvB,sBAAwB,EAAA,SAAA;AAAA,IACxB,uBAAyB,EAAA,UAAA;AAAA,GAC5B,CAAA,CAAA;AACD,EAAA,MAAM,cAAc,OAAO,QAAA,KAAa,SAAa,GAAA,QAAA,GAAW,SAAS,OAAW,GAAA,KAAA,CAAA,CAAA;AAEpF,EAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AACpD,EAAM,MAAA,OAAA,GAAU,CAAC,CAAqC,KAAA;AAGlD,IAAA,cAAA,CAAe,KAAK,CAAA,CAAA;AACpB,IAAA,WAAA,GAAc,CAAC,CAAA,CAAA;AAAA,GACnB,CAAA;AAEA,EACI,uBAAA,GAAA;AAAA,IAAC,OAAA;AAAA,IAAA;AAAA,MACG,KAAA;AAAA,MACA,SAAU,EAAA,MAAA;AAAA,MACV,SAAW,EAAA,GAAA;AAAA,MACV,GAAG,YAAA;AAAA,MAEJ,MAAQ,EAAA,WAAA;AAAA,MACR,MAAA,EAAQ,MAAM,cAAA,CAAe,IAAI,CAAA;AAAA,MACjC,OAAA,EAAS,MAAM,cAAA,CAAe,KAAK,CAAA;AAAA,MAEnC,QAAA,kBAAA,GAAA;AAAA,QAAC,uBAAA;AAAA,QAAA;AAAA,UACG,SAAA;AAAA,UACA,GAAA;AAAA,UACA,YAAY,EAAA,KAAA;AAAA,UACZ,QAAU,EAAA,IAAA;AAAA,UACV,WAAa,EAAA,CAAA;AAAA,UACb,OAAS,EAAA,CAAA;AAAA,UACT,UAAA;AAAA,UACA,SAAA;AAAA,UACA,QAAA;AAAA,UACA,cAAc,EAAA,WAAA;AAAA,UACb,GAAG,cAAA;AAAA,UACH,GAAG,WAAA;AAAA,UAEJ,OAAA;AAAA,SAAA;AAAA,OACJ;AAAA,KAAA;AAAA,GACJ,CAAA;AAER,CAAC,EAAA;AAOD,MAAM,uBAA0B,GAAA,UAAA,CAAW,SAASC,wBAAAA,CAChD,OACA,GACF,EAAA;AACE,EAAA,MAAM,EAAE,iBAAmB,EAAA,MAAA,EAAQ,oBAAoB,YAAc,EAAA,GAAG,MAAS,GAAA,KAAA,CAAA;AACjF,EAAA,uBAAQ,GAAA,CAAA,MAAA,EAAA,EAAO,GAAW,EAAA,GAAG,IAAM,EAAA,CAAA,CAAA;AACvC,CAAC,CAAA;;;;"}
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.0",
4
+ "version": "0.2.1",
5
5
  "description": "Contains common react utilities used by the open pioneer trails project",
6
6
  "license": "Apache-2.0",
7
7
  "peerDependencies": {