@behivetech/icons.base 0.0.0-stage → 0.4.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/README.md CHANGED
@@ -1,3 +1,25 @@
1
- # Temporary Holding Version
1
+ # Icon base
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The shared builder and stylesheet for every `@behivetech/icons.*` package: `createIcon`, the factory each icon package builds its component with, and the stylesheet that sizes them. It holds no glyphs; each one is its own package, `@behivetech/icons.<name>`, so an app loads only the icons it renders.
4
+
5
+ Docs: https://platform.behivetech.com/behivetech/icons/base
6
+
7
+ ## Usage
8
+
9
+ ```jsx
10
+ import { CheckIcon } from '@behivetech/icons.check';
11
+ import '@behivetech/icons.base/styles.css';
12
+
13
+ <CheckIcon />
14
+ <CheckIcon size="lg" titleAccess="Done" />
15
+ ```
16
+
17
+ Import the stylesheet once in the app. Icons use `stroke="currentColor"`, so they take the colour of the text around them, and size through `size` (`sm`, `md`, `lg`, `xl`).
18
+
19
+ ## Accessibility
20
+
21
+ An icon is decorative by default: `aria-hidden="true"` and `focusable="false"`. Name it with `titleAccess` (rendered as the svg's `<title>`) or `aria-label`/`aria-labelledby` and it becomes an image (`role="img"`). `ref` goes to the root svg, and any svg attribute passed overrides the defaults (`strokeWidth`, `viewBox`).
22
+
23
+ ## Making an icon
24
+
25
+ Run `pnpm gen icon <scope> <name> <svg> <visibility>` with the glyph's markup (or the path of an `.svg` file): it writes the package with its example and spec, and refreshes `@behivetech/icons.all`, the name-keyed `Icon` for the places where the name is data. The markup may hold geometry only (paths, shapes, groups, gradients and clip paths); script, style, `{ }` expressions, namespaced names and links that leave the svg are refused.
@@ -0,0 +1,90 @@
1
+ import { type ReactNode, type Ref, type SVGAttributes } from "react";
2
+ import { getClassName } from "@behivetech/get-class-name";
3
+ import styles from "./icon.module.scss";
4
+
5
+ export type IconSize = "sm" | "md" | "lg" | "xl";
6
+
7
+ export interface IconBaseProps extends SVGAttributes<SVGSVGElement> {
8
+ /** Controls width/height; defaults to md */
9
+ size?: IconSize;
10
+ /** Additional class names to merge with the component root element */
11
+ className?: string;
12
+ /**
13
+ * Accessible name of the icon, rendered as the svg's `<title>`. When set
14
+ * the icon is exposed as an image with this name; without it (and without
15
+ * `aria-label` or `aria-labelledby`) the icon is decorative and hidden from
16
+ * assistive technology. Pass an already translated string.
17
+ */
18
+ titleAccess?: string;
19
+ /** Ref to the root svg element */
20
+ ref?: Ref<SVGSVGElement>;
21
+ }
22
+
23
+ export type IconComponent = (props: IconBaseProps) => ReactNode;
24
+
25
+ /**
26
+ * Builds an icon component from its glyph geometry, the way MUI's
27
+ * `createSvgIcon` does. Each icon package (`@scope/icons.<name>`) calls this
28
+ * once, and lists this package as a dependency (`workspace:^`), so an app has one
29
+ * factory and one stylesheet however many icons it uses. Mark each call `PURE`
30
+ * (a `#__PURE__` comment) so a bundler can drop an icon nothing uses.
31
+ *
32
+ * @param displayName The component's name in devtools, e.g. `CheckIcon`
33
+ * @param children The svg's geometry: one element or a fragment of them, on a 24 by 24 grid
34
+ * @returns A component taking `IconBaseProps`
35
+ */
36
+ export function createIcon(
37
+ displayName: string,
38
+ children: ReactNode,
39
+ ): IconComponent {
40
+ // React 19 passes `ref` to a function component as an ordinary prop, so
41
+ // there is no `forwardRef` wrapper here; the ref lands on the root svg. Nor is
42
+ // there a `memo`: the glyph is one element built once, and re-rendering an
43
+ // svg of a few nodes costs less than comparing its props.
44
+ const Component = ({
45
+ size = "md",
46
+ className,
47
+ titleAccess,
48
+ ref,
49
+ ...rest
50
+ }: IconBaseProps) => {
51
+ // `rootClass` is "BHT__Icon", not "BHT__CreateIcon": this file is the
52
+ // factory, not a component, and every glyph it builds renders as an Icon.
53
+ // A conventions audit keying off the file name will flag this — it is
54
+ // correct as is.
55
+ const [rootClass] = getClassName({
56
+ className,
57
+ rootClass: "BHT__Icon",
58
+ modifiers: { [size]: true },
59
+ styles,
60
+ });
61
+ const isLabelled = Boolean(
62
+ titleAccess || rest["aria-label"] || rest["aria-labelledby"],
63
+ );
64
+
65
+ // `rest` comes after the defaults so a caller can override any of them
66
+ // (`strokeWidth`, `viewBox`, `aria-hidden`), as with MUI's SvgIcon.
67
+ return (
68
+ <svg
69
+ ref={ref}
70
+ viewBox="0 0 24 24"
71
+ fill="none"
72
+ stroke="currentColor"
73
+ strokeWidth={2}
74
+ strokeLinecap="round"
75
+ strokeLinejoin="round"
76
+ focusable="false"
77
+ aria-hidden={isLabelled ? undefined : true}
78
+ role={isLabelled ? "img" : undefined}
79
+ {...rest}
80
+ className={rootClass}
81
+ >
82
+ {children}
83
+ {titleAccess ? <title>{titleAccess}</title> : null}
84
+ </svg>
85
+ );
86
+ };
87
+
88
+ Component.displayName = displayName;
89
+ return Component;
90
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createIcon: () => createIcon
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // create-icon.tsx
28
+ var import_get_class_name = require("@behivetech/get-class-name");
29
+
30
+ // icon.module.scss
31
+ var icon_module_default = {
32
+ "BHT__Icon": "BHT__Icon",
33
+ "BHT__Icon--sm": "BHT__Icon--sm",
34
+ "BHT__Icon--md": "BHT__Icon--md",
35
+ "BHT__Icon--lg": "BHT__Icon--lg",
36
+ "BHT__Icon--xl": "BHT__Icon--xl"
37
+ };
38
+
39
+ // create-icon.tsx
40
+ var import_jsx_runtime = require("react/jsx-runtime");
41
+ function createIcon(displayName, children) {
42
+ const Component = ({
43
+ size = "md",
44
+ className,
45
+ titleAccess,
46
+ ref,
47
+ ...rest
48
+ }) => {
49
+ const [rootClass] = (0, import_get_class_name.getClassName)({
50
+ className,
51
+ rootClass: "BHT__Icon",
52
+ modifiers: { [size]: true },
53
+ styles: icon_module_default
54
+ });
55
+ const isLabelled = Boolean(
56
+ titleAccess || rest["aria-label"] || rest["aria-labelledby"]
57
+ );
58
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
59
+ "svg",
60
+ {
61
+ ref,
62
+ viewBox: "0 0 24 24",
63
+ fill: "none",
64
+ stroke: "currentColor",
65
+ strokeWidth: 2,
66
+ strokeLinecap: "round",
67
+ strokeLinejoin: "round",
68
+ focusable: "false",
69
+ "aria-hidden": isLabelled ? void 0 : true,
70
+ role: isLabelled ? "img" : void 0,
71
+ ...rest,
72
+ className: rootClass,
73
+ children: [
74
+ children,
75
+ titleAccess ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("title", { children: titleAccess }) : null
76
+ ]
77
+ }
78
+ );
79
+ };
80
+ Component.displayName = displayName;
81
+ return Component;
82
+ }
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ createIcon
86
+ });
package/dist/index.css ADDED
@@ -0,0 +1,21 @@
1
+ /* esbuild-sass-plugin:css-chunkicon.module.scss */
2
+ .BHT__Icon {
3
+ display: inline-block;
4
+ flex-shrink: 0;
5
+ }
6
+ .BHT__Icon--sm {
7
+ width: 1rem;
8
+ height: 1rem;
9
+ }
10
+ .BHT__Icon--md {
11
+ width: 1.25rem;
12
+ height: 1.25rem;
13
+ }
14
+ .BHT__Icon--lg {
15
+ width: 1.5rem;
16
+ height: 1.5rem;
17
+ }
18
+ .BHT__Icon--xl {
19
+ width: 2.5rem;
20
+ height: 2.5rem;
21
+ }
@@ -0,0 +1,33 @@
1
+ import { SVGAttributes, Ref, ReactNode } from 'react';
2
+
3
+ type IconSize = "sm" | "md" | "lg" | "xl";
4
+ interface IconBaseProps extends SVGAttributes<SVGSVGElement> {
5
+ /** Controls width/height; defaults to md */
6
+ size?: IconSize;
7
+ /** Additional class names to merge with the component root element */
8
+ className?: string;
9
+ /**
10
+ * Accessible name of the icon, rendered as the svg's `<title>`. When set
11
+ * the icon is exposed as an image with this name; without it (and without
12
+ * `aria-label` or `aria-labelledby`) the icon is decorative and hidden from
13
+ * assistive technology. Pass an already translated string.
14
+ */
15
+ titleAccess?: string;
16
+ /** Ref to the root svg element */
17
+ ref?: Ref<SVGSVGElement>;
18
+ }
19
+ type IconComponent = (props: IconBaseProps) => ReactNode;
20
+ /**
21
+ * Builds an icon component from its glyph geometry, the way MUI's
22
+ * `createSvgIcon` does. Each icon package (`@scope/icons.<name>`) calls this
23
+ * once, and lists this package as a dependency (`workspace:^`), so an app has one
24
+ * factory and one stylesheet however many icons it uses. Mark each call `PURE`
25
+ * (a `#__PURE__` comment) so a bundler can drop an icon nothing uses.
26
+ *
27
+ * @param displayName The component's name in devtools, e.g. `CheckIcon`
28
+ * @param children The svg's geometry: one element or a fragment of them, on a 24 by 24 grid
29
+ * @returns A component taking `IconBaseProps`
30
+ */
31
+ declare function createIcon(displayName: string, children: ReactNode): IconComponent;
32
+
33
+ export { type IconBaseProps, type IconComponent, type IconSize, createIcon };
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ // create-icon.tsx
2
+ import { getClassName } from "@behivetech/get-class-name";
3
+
4
+ // icon.module.scss
5
+ var icon_module_default = {
6
+ "BHT__Icon": "BHT__Icon",
7
+ "BHT__Icon--sm": "BHT__Icon--sm",
8
+ "BHT__Icon--md": "BHT__Icon--md",
9
+ "BHT__Icon--lg": "BHT__Icon--lg",
10
+ "BHT__Icon--xl": "BHT__Icon--xl"
11
+ };
12
+
13
+ // create-icon.tsx
14
+ import { jsx, jsxs } from "react/jsx-runtime";
15
+ function createIcon(displayName, children) {
16
+ const Component = ({
17
+ size = "md",
18
+ className,
19
+ titleAccess,
20
+ ref,
21
+ ...rest
22
+ }) => {
23
+ const [rootClass] = getClassName({
24
+ className,
25
+ rootClass: "BHT__Icon",
26
+ modifiers: { [size]: true },
27
+ styles: icon_module_default
28
+ });
29
+ const isLabelled = Boolean(
30
+ titleAccess || rest["aria-label"] || rest["aria-labelledby"]
31
+ );
32
+ return /* @__PURE__ */ jsxs(
33
+ "svg",
34
+ {
35
+ ref,
36
+ viewBox: "0 0 24 24",
37
+ fill: "none",
38
+ stroke: "currentColor",
39
+ strokeWidth: 2,
40
+ strokeLinecap: "round",
41
+ strokeLinejoin: "round",
42
+ focusable: "false",
43
+ "aria-hidden": isLabelled ? void 0 : true,
44
+ role: isLabelled ? "img" : void 0,
45
+ ...rest,
46
+ className: rootClass,
47
+ children: [
48
+ children,
49
+ titleAccess ? /* @__PURE__ */ jsx("title", { children: titleAccess }) : null
50
+ ]
51
+ }
52
+ );
53
+ };
54
+ Component.displayName = displayName;
55
+ return Component;
56
+ }
57
+ export {
58
+ createIcon
59
+ };
package/docs.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "$schema": "https://github.com/behivetech/bht-component-registry/docs.schema.json",
3
+ "version": 2,
4
+ "generatedAt": "2026-11-11T04:38:21.566Z",
5
+ "docs": [],
6
+ "functions": [
7
+ {
8
+ "name": "createIcon",
9
+ "kind": "function",
10
+ "description": "Builds an icon component from its glyph geometry, the way MUI's\n`createSvgIcon` does. Each icon package (`@scope/icons.<name>`) calls this\nonce, and lists this package as a dependency (`workspace:^`), so an app has one\nfactory and one stylesheet however many icons it uses. Mark each call `PURE`\n(a `#__PURE__` comment) so a bundler can drop an icon nothing uses.",
11
+ "signatures": [
12
+ {
13
+ "text": "createIcon(displayName: string, children: ReactNode): IconComponent",
14
+ "params": [
15
+ {
16
+ "name": "displayName",
17
+ "type": "string",
18
+ "optional": false,
19
+ "defaultValue": null,
20
+ "description": "The component's name in devtools, e.g. `CheckIcon`"
21
+ },
22
+ {
23
+ "name": "children",
24
+ "type": "ReactNode",
25
+ "optional": false,
26
+ "defaultValue": null,
27
+ "description": "The svg's geometry: one element or a fragment of them, on a 24 by 24 grid"
28
+ }
29
+ ],
30
+ "returns": {
31
+ "type": "IconComponent",
32
+ "description": "A component taking `IconBaseProps`"
33
+ }
34
+ }
35
+ ],
36
+ "examples": []
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,19 @@
1
+ import { createIcon } from "./create-icon.js";
2
+
3
+ const SquareIcon = createIcon(
4
+ "SquareIcon",
5
+ <rect x="4" y="4" width="16" height="16" rx="2" />,
6
+ );
7
+
8
+ /** An icon built with `createIcon`, at each size. Real icons come from the `@behivetech/icons.*` packages. */
9
+ export const IconSizes = () => (
10
+ <>
11
+ <SquareIcon size="sm" />
12
+ <SquareIcon />
13
+ <SquareIcon size="lg" />
14
+ <SquareIcon size="xl" />
15
+ </>
16
+ );
17
+
18
+ /** Named with `titleAccess`, so it is announced as an image. */
19
+ export const NamedIcon = () => <SquareIcon titleAccess="Square" />;
@@ -0,0 +1,24 @@
1
+ .BHT__Icon {
2
+ display: inline-block;
3
+ flex-shrink: 0;
4
+
5
+ &--sm {
6
+ width: 1rem;
7
+ height: 1rem;
8
+ }
9
+
10
+ &--md {
11
+ width: 1.25rem;
12
+ height: 1.25rem;
13
+ }
14
+
15
+ &--lg {
16
+ width: 1.5rem;
17
+ height: 1.5rem;
18
+ }
19
+
20
+ &--xl {
21
+ width: 2.5rem;
22
+ height: 2.5rem;
23
+ }
24
+ }
package/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { createIcon } from "./create-icon.js";
2
+ export type { IconBaseProps, IconComponent, IconSize } from "./create-icon.js";
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "@behivetech/icons.base",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.4.0",
4
+ "license": "MIT",
5
+ "description": "The shared builder and stylesheet for every `@behivetech/icons.*` package: `createIcon`, the factory each icon package builds its component with, and the stylesheet that sizes them. It holds no glyphs; each one is its own package, `@behivetech/icons.<name>`, so an app loads only the icons it renders.",
6
+ "type": "module",
7
+ "private": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./styles.css": "./dist/index.css"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "index.ts",
20
+ "create-icon.tsx",
21
+ "icon.module.scss",
22
+ "*.example.tsx",
23
+ "docs.json"
24
+ ],
25
+ "registry": {
26
+ "status": "stable",
27
+ "tags": []
28
+ },
29
+ "sideEffects": [
30
+ "**/*.css",
31
+ "**/*.scss"
32
+ ],
33
+ "dependencies": {
34
+ "@behivetech/get-class-name": "0.1.0"
35
+ },
36
+ "peerDependencies": {
37
+ "react": "^19.2.7",
38
+ "react-dom": "^19.2.7"
39
+ },
40
+ "devDependencies": {
41
+ "@bht-component-registry/env": "0.1.0",
42
+ "@types/react": "19.2.17",
43
+ "@types/react-dom": "19.2.3",
44
+ "eslint": "^9.39.5",
45
+ "tsup": "^8.5.1",
46
+ "typescript": "^6.0.3",
47
+ "vitest": "^4.1.10"
48
+ },
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "https://github.com/behivetech/bht-galaxy.git",
52
+ "directory": "registry/behivetech/icons/base"
53
+ },
54
+ "homepage": "https://platform.behivetech.com/behivetech/icons/base",
55
+ "publishConfig": {
56
+ "registry": "https://npm.pkg.github.com",
57
+ "access": "public"
58
+ },
59
+ "scripts": {
60
+ "build": "tsup && bht-registry-docgen",
61
+ "dev": "tsup --watch",
62
+ "lint": "eslint . --max-warnings 0",
63
+ "check-types": "tsc --noEmit",
64
+ "test": "vitest run"
65
+ }
6
66
  }