@baseline-ui/icons 0.1.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/dist/index.mjs ADDED
@@ -0,0 +1,77 @@
1
+ // src/Icon.tsx
2
+ import * as Dompurify from "dompurify";
3
+ import React from "react";
4
+ import { useId } from "react-aria";
5
+ import { classNames, invariant } from "@baseline-ui/utils";
6
+
7
+ // src/Icon.css.ts
8
+ var iconWrapper = "Icon_iconWrapper__1rl8ope0";
9
+
10
+ // src/Icon.tsx
11
+ import { jsx } from "react/jsx-runtime";
12
+ var setSizeAttributes = (svgElement, size) => {
13
+ svgElement.setAttribute(
14
+ "height",
15
+ typeof size === "number" ? `${size}px` : size
16
+ );
17
+ svgElement.setAttribute(
18
+ "width",
19
+ typeof size === "number" ? `${size}px` : size
20
+ );
21
+ };
22
+ var updateSvgTitle = (svgElement, title, id) => {
23
+ const titleElement = svgElement.querySelector("title");
24
+ if (titleElement) {
25
+ titleElement.textContent = title;
26
+ titleElement.setAttribute("id", id);
27
+ } else {
28
+ const newTitleElement = document.createElement("title");
29
+ newTitleElement.textContent = title;
30
+ newTitleElement.setAttribute("id", id);
31
+ svgElement.prepend(newTitleElement);
32
+ }
33
+ };
34
+ var setClassName = (svgElement, className) => {
35
+ if (className) {
36
+ svgElement.classList.add(className);
37
+ }
38
+ };
39
+ var getSanitizedSvgElement = (_svg) => {
40
+ const span = document.createElement("span");
41
+ span.innerHTML = Dompurify.default.sanitize(_svg);
42
+ const svgElement = span.querySelector("svg");
43
+ invariant(svgElement, "Icon: svg prop must be a valid svg string");
44
+ return svgElement;
45
+ };
46
+ var Icon = React.forwardRef(
47
+ ({ size, title, className, style, ...rest }, ref) => {
48
+ const id = useId();
49
+ const _svg = "svg" in rest ? rest.svg : void 0;
50
+ const svgString = React.useMemo(() => {
51
+ if (_svg) {
52
+ const svgElement = getSanitizedSvgElement(_svg);
53
+ if (size) {
54
+ setSizeAttributes(svgElement, size);
55
+ }
56
+ if (title) {
57
+ updateSvgTitle(svgElement, title, id);
58
+ }
59
+ setClassName(svgElement, className);
60
+ return svgElement.outerHTML;
61
+ }
62
+ }, [_svg, size, title, className, id]);
63
+ return /* @__PURE__ */ jsx(
64
+ "span",
65
+ {
66
+ className: classNames(iconWrapper, className),
67
+ ref,
68
+ style,
69
+ dangerouslySetInnerHTML: svgString ? { __html: svgString } : void 0
70
+ }
71
+ );
72
+ }
73
+ );
74
+ Icon.displayName = "Icon";
75
+ export {
76
+ Icon
77
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@baseline-ui/icons",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "style": "dist/index.css",
9
+ "source": "./src/index.ts",
10
+ "files": [
11
+ "dist",
12
+ "8",
13
+ "12",
14
+ "16",
15
+ "20",
16
+ "24"
17
+ ],
18
+ "license": "ISC",
19
+ "dependencies": {
20
+ "@baseline-ui/utils": "*",
21
+ "dompurify": "^3.0.6",
22
+ "react-aria": "^3.30.0"
23
+ },
24
+ "devDependencies": {
25
+ "@svgr/cli": "^8.1.0",
26
+ "@types/dompurify": "^3.0.5",
27
+ "just-kebab-case": "^4.2.0"
28
+ },
29
+ "peerDependencies": {
30
+ "react": "^17.0.2 || ^18.0.0",
31
+ "react-dom": "^17.0.2 || ^18.0.0"
32
+ },
33
+ "scripts": {
34
+ "build": "tsup",
35
+ "build:icons": "./scripts/buildIcons.sh && eslint src --fix"
36
+ }
37
+ }