@canonical/react-ds-global 0.27.0 → 0.28.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.
@@ -9,9 +9,17 @@ const componentCssClassName = "ds button";
9
9
  * @implements ds:global.component.button
10
10
  */
11
11
  const Button = ({ id, className, children, style, importance, anticipation, variant, icon, iconPosition = "start", ...props }) => {
12
- // Derive aria-label from children if not explicitly provided
13
- const ariaLabel = props["aria-label"] ||
14
- (typeof children === "string" ? children : undefined);
12
+ // Booleans and nullish children render nothing; everything else (including
13
+ // the number 0) produces visible text that names the button.
14
+ const hasVisibleChildren = children != null && typeof children !== "boolean" && children !== "";
15
+ if (typeof process !== "undefined" &&
16
+ process.env.NODE_ENV !== "production" &&
17
+ icon &&
18
+ !hasVisibleChildren &&
19
+ !props["aria-label"] &&
20
+ !props["aria-labelledby"]) {
21
+ console.warn("Button: icon-only buttons need an explicit `aria-label` or `aria-labelledby` to be accessible.");
22
+ }
15
23
  const iconElement = icon && _jsx("span", { className: "icon", children: icon });
16
24
  return (_jsx("button", { id: id, className: [
17
25
  componentCssClassName,
@@ -21,7 +29,7 @@ const Button = ({ id, className, children, style, importance, anticipation, vari
21
29
  className,
22
30
  ]
23
31
  .filter(Boolean)
24
- .join(" "), style: style, "aria-label": ariaLabel, ...props, children: iconPosition === "start" ? (_jsxs(_Fragment, { children: [iconElement, children] })) : (_jsxs(_Fragment, { children: [children, iconElement] })) }));
32
+ .join(" "), style: style, ...props, children: iconPosition === "start" ? (_jsxs(_Fragment, { children: [iconElement, children] })) : (_jsxs(_Fragment, { children: [children, iconElement] })) }));
25
33
  };
26
34
  export default Button;
27
35
  //# sourceMappingURL=Button.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Button.js","sourceRoot":"","sources":["../../../../src/lib/Button/Button.tsx"],"names":[],"mappings":";AAEA,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,WAAW,CAAC;AAE1C;;;;;;GAMG;AAC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AM,kBAAkB,GACtB,QAAQ,IAAI,IAAI,IAAI,OAAO,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,EAAE,CAAC;IAEvE,IACE,OAAO,OAAO,KAAK,WAAW;QAC9B,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;QACrC,IAAI;QACJ,CAAC,kBAAkB;QACnB,CAAC,KAAK,CAAC,YAAY,CAAC;QACpB,CAAC,KAAK,CAAC,iBAAiB,CAAC,EACzB,CAAC;QACD,OAAO,CAAC,IAAI,CACV,gGAAgG,CACjG,CAAC;IACJ,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,IAAI,eAAM,SAAS,EAAC,MAAM,YAAE,IAAI,GAAQ,CAAC;IAEjE,OAAO,CACL,iBACE,EAAE,EAAE,EAAE,EACN,SAAS,EAAE;YACT,qBAAqB;YACrB,UAAU;YACV,YAAY;YACZ,OAAO;YACP,SAAS;SACV;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,EACZ,KAAK,EAAE,KAAK,KACR,KAAK,YAER,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,CAC1B,8BACG,WAAW,EACX,QAAQ,IACR,CACJ,CAAC,CAAC,CAAC,CACF,8BACG,QAAQ,EACR,WAAW,IACX,CACJ,GACM,CACV,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -1,12 +1,22 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import "./styles.css";
3
3
  const componentCssClassName = "ds icon";
4
+ /** An empty or whitespace-only label provides no accessible name. */
5
+ const hasAccessibleName = (value) => typeof value === "string" && value.trim() !== "";
4
6
  /**
5
7
  * Icon component that renders SVG icons from @canonical/ds-assets
6
8
  * @implements ds:global.component.icon
7
9
  */
8
- const Icon = ({ xmlns = "http://www.w3.org/2000/svg", viewBox = "0 0 16 16", icon, className, rootPath = "/icons", role = "img", ...props }) => {
9
- return (_jsx("svg", { xmlns: xmlns, viewBox: viewBox, className: [componentCssClassName, className].filter(Boolean).join(" "), role: role, "aria-label": icon, ...props, children: _jsx("use", { href: `${rootPath}/${icon}.svg#${icon}` }) }));
10
+ const Icon = ({ xmlns = "http://www.w3.org/2000/svg", viewBox = "0 0 16 16", icon, className, rootPath = "/icons", role, ...props }) => {
11
+ // Icons are decorative by default and hidden from assistive technology.
12
+ // Providing an accessible name (aria-label/aria-labelledby) or an explicit
13
+ // role exposes the icon as a named image instead. An empty label counts as
14
+ // decorative, mirroring the `alt=""` convention on images.
15
+ const isLabelled = hasAccessibleName(props["aria-label"]) ||
16
+ hasAccessibleName(props["aria-labelledby"]);
17
+ return (
18
+ // biome-ignore lint/a11y/noSvgWithoutTitle: decorative icons render aria-hidden="true"; labelled icons render role="img" with an aria-label/aria-labelledby (computed at runtime)
19
+ _jsx("svg", { xmlns: xmlns, viewBox: viewBox, className: [componentCssClassName, className].filter(Boolean).join(" "), role: role ?? (isLabelled ? "img" : undefined), "aria-hidden": isLabelled || role ? undefined : true, ...props, children: _jsx("use", { href: `${rootPath}/${icon}.svg#${icon}` }) }));
10
20
  };
11
21
  export default Icon;
12
22
  //# sourceMappingURL=Icon.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Icon.js","sourceRoot":"","sources":["../../../../src/lib/Icon/Icon.tsx"],"names":[],"mappings":";AAEA,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,SAAS,CAAC;AAExC;;;GAGG;AACH,MAAM,IAAI,GAAG,CAAC,EACZ,KAAK,GAAG,4BAA4B,EACpC,OAAO,GAAG,WAAW,EACrB,IAAI,EACJ,SAAS,EACT,QAAQ,GAAG,QAAQ,EACnB,IAAI,GAAG,KAAK,EACZ,GAAG,KAAK,EACE,EAAgB,EAAE;IAC5B,OAAO,CACL,cACE,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO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C,CAAC,CAAC,IAAI,KAC9C,KAAK,YAET,cAAK,IAAI,EAAE,GAAG,QAAQ,IAAI,IAAI,QAAQ,IAAI,EAAE,GAAI,GAC5C,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../../../src/lib/Button/Button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,cAAc,CAAC;AAItB;;;;;;GAMG;AACH,QAAA,MAAM,MAAM,GAAI,qGAWb,KAAK,KAAG,KAAK,CAAC,YAqChB,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../../../src/lib/Button/Button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,cAAc,CAAC;AAItB;;;;;;GAMG;AACH,QAAA,MAAM,MAAM,GAAI,qGAWb,KAAK,KAAG,KAAK,CAAC,YAiDhB,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -7,9 +7,9 @@ export interface BaseProps {
7
7
  className?: string;
8
8
  /**
9
9
  * Button contents (label text).
10
- * This will also be used for the `aria-label` if not explicitly provided.
11
- * If this contains anything other than a string literal (such as a <p> element),
12
- * you should specify an `aria-label` prop to ensure accessibility.
10
+ * The button's accessible name derives from its rendered text content,
11
+ * so no `aria-label` is set automatically. Pass an explicit `aria-label`
12
+ * (or `aria-labelledby`) for icon-only buttons without visible text.
13
13
  */
14
14
  children?: ReactNode;
15
15
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Icon.d.ts","sourceRoot":"","sources":["../../../../src/lib/Icon/Icon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,cAAc,CAAC;AAItB;;;GAGG;AACH,QAAA,MAAM,IAAI,GAAI,+DAQX,SAAS,KAAG,YAad,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"Icon.d.ts","sourceRoot":"","sources":["../../../../src/lib/Icon/Icon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,cAAc,CAAC;AAQtB;;;GAGG;AACH,QAAA,MAAM,IAAI,GAAI,+DAQX,SAAS,KAAG,YAsBd,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -6,6 +6,12 @@ import type { SVGAttributes } from "react";
6
6
  See https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API for a full list of HTML elements interfaces.
7
7
  */
8
8
  export interface IconProps extends SVGAttributes<HTMLOrSVGElement> {
9
+ /**
10
+ * Name of the icon to display.
11
+ * Icons are decorative by default (`aria-hidden="true"`). Pass an
12
+ * `aria-label` (or `aria-labelledby`) when the icon conveys meaning on
13
+ * its own; it is then exposed as a named `img` element.
14
+ */
9
15
  icon: IconName;
10
16
  /** Root path to the icons (default: /icons). Must be exposed to the user. */
11
17
  rootPath?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/Icon/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C;;;;EAIE;AACF,MAAM,WAAW,SAAU,SAAQ,aAAa,CAAC,gBAAgB,CAAC;IAEhE,IAAI,EAAE,QAAQ,CAAC;IACf,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/Icon/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C;;;;EAIE;AACF,MAAM,WAAW,SAAU,SAAQ,aAAa,CAAC,gBAAgB,CAAC;IAChE;;;;;OAKG;IACH,IAAI,EAAE,QAAQ,CAAC;IACf,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@canonical/react-ds-global",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "type": "module",
5
+ "main": "dist/esm/index.js",
5
6
  "module": "dist/esm/index.js",
6
7
  "types": "dist/types/index.d.ts",
7
8
  "files": [
@@ -20,6 +21,9 @@
20
21
  "url": "https://github.com/canonical/pragma/issues"
21
22
  },
22
23
  "homepage": "https://github.com/canonical/pragma#readme",
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
23
27
  "scripts": {
24
28
  "build": "bun run build:package",
25
29
  "build:all": "bun run build:package && bun run build:storybook",
@@ -39,21 +43,21 @@
39
43
  "test:vitest:watch": "vitest"
40
44
  },
41
45
  "dependencies": {
42
- "@canonical/ds-assets": "^0.27.0",
43
- "@canonical/storybook-config": "^0.27.0",
44
- "@canonical/styles": "^0.27.0",
45
- "@canonical/utils": "^0.27.0",
46
+ "@canonical/ds-assets": "^0.28.0",
47
+ "@canonical/storybook-config": "^0.28.0",
48
+ "@canonical/styles": "^0.28.0",
49
+ "@canonical/utils": "^0.28.0",
46
50
  "react": "^19.2.4",
47
51
  "react-dom": "^19.2.4"
48
52
  },
49
53
  "devDependencies": {
50
54
  "@biomejs/biome": "2.4.9",
51
- "@canonical/biome-config": "^0.27.0",
55
+ "@canonical/biome-config": "^0.28.0",
52
56
  "@canonical/design-tokens": "^0.6.0",
53
- "@canonical/ds-types": "^0.27.0",
54
- "@canonical/storybook-helpers": "^0.27.0",
55
- "@canonical/typescript-config-react": "^0.27.0",
56
- "@canonical/webarchitect": "^0.27.0",
57
+ "@canonical/ds-types": "^0.28.0",
58
+ "@canonical/storybook-helpers": "^0.28.0",
59
+ "@canonical/typescript-config-react": "^0.28.0",
60
+ "@canonical/webarchitect": "^0.28.0",
57
61
  "@chromatic-com/storybook": "^5.0.1",
58
62
  "@storybook/addon-docs": "^10.3.1",
59
63
  "@storybook/react-vite": "^10.3.1",
@@ -71,5 +75,5 @@
71
75
  "vite": "^8.0.1",
72
76
  "vitest": "^4.0.18"
73
77
  },
74
- "gitHead": "5df5709bf7cb6f2016be2f6eba8391637e2e2a0c"
78
+ "gitHead": "8297d72122bcba903f7e8833cb23ccbaa164ed56"
75
79
  }