@jannchie/icons-react 0.0.0-stage → 0.7.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/LICENSE +21 -0
- package/NOTICE +32 -0
- package/README.md +96 -3
- package/dist/attrs.cjs +23 -0
- package/dist/attrs.js +22 -0
- package/dist/index.cjs +80 -0
- package/dist/index.d.cts +43 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +73 -0
- package/dist/static.cjs +17 -0
- package/dist/static.d.cts +15 -0
- package/dist/static.d.ts +15 -0
- package/dist/static.js +12 -0
- package/package.json +64 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jianqi Pan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Jannchie Icons
|
|
2
|
+
Copyright (c) 2026 Jianqi Pan
|
|
3
|
+
|
|
4
|
+
What the MIT license covers
|
|
5
|
+
|
|
6
|
+
The MIT license in LICENSE covers this project's code, including the drawing
|
|
7
|
+
code of every icon, and the original icons designed for this project.
|
|
8
|
+
|
|
9
|
+
Third-party characters and marks
|
|
10
|
+
|
|
11
|
+
Some icons refer to or depict characters, logos and marks that belong to third
|
|
12
|
+
parties. They are included as fan art or for nominative reference only, for
|
|
13
|
+
example to label a link, a file type or a rating. All rights in these
|
|
14
|
+
characters, trademarks and logos remain with their respective owners. The MIT
|
|
15
|
+
license does not grant any right to them, and including them here does not
|
|
16
|
+
imply any affiliation with or endorsement by their owners. Check the owners'
|
|
17
|
+
guidelines before using these icons. They include:
|
|
18
|
+
|
|
19
|
+
- Chiikawa characters: chiikawa, hachiware, usagi
|
|
20
|
+
- Content rating marks: MPA, ESRB, PEGI, BBFC, ACB, Eirin, CERO, KMRB, USK,
|
|
21
|
+
CADPA (the rating-* icons, except the original rating-sensitivity-* set)
|
|
22
|
+
- Creative Commons symbols (cc and the cc-* icons)
|
|
23
|
+
- Company and project logos: GitHub (github), Model Context Protocol (mcp)
|
|
24
|
+
and programming language logos
|
|
25
|
+
(python, javascript, typescript, java, c, csharp, cpp, golang, rust, php,
|
|
26
|
+
kotlin, swift, ruby, lua, haskell, html)
|
|
27
|
+
- Game controller buttons: PlayStation (playstation-*) and Xbox (xbox-*)
|
|
28
|
+
- License names (the license-* icons)
|
|
29
|
+
|
|
30
|
+
These icons are still exported from the main entry of @jannchie/icons so that
|
|
31
|
+
existing imports keep working. They are planned to move to a separate entry in
|
|
32
|
+
version 1.0.
|
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @jannchie/icons-react
|
|
2
|
+
|
|
3
|
+
React component for [Jannchie Icons](https://icons.jannchie.com): one `<JIcon>` renders any icon from [`@jannchie/icons`](https://www.npmjs.com/package/@jannchie/icons), redrawn for the corner radius and stroke weight you choose, snapped to the device pixel grid, with optional duo-tone colors. Set the radius and weight once for the whole app.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm add @jannchie/icons @jannchie/icons-react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```jsx
|
|
10
|
+
import { IconFolderPlus, IconHeart } from '@jannchie/icons'
|
|
11
|
+
import { JIcon } from '@jannchie/icons-react'
|
|
12
|
+
|
|
13
|
+
export function Toolbar({ onCreate }) {
|
|
14
|
+
return (
|
|
15
|
+
<>
|
|
16
|
+
<JIcon icon={IconHeart} size={20} />
|
|
17
|
+
<JIcon icon={IconFolderPlus} radius="sharp" weight="bold" duo title="New folder" className="icon" onClick={onCreate} />
|
|
18
|
+
</>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Icons are imported one by one, so bundlers keep only those you use. One icon, the drawing engine and the component add about 9 KB gzipped to an app (measured with Vite 8); the [static entry](#static-entry) adds about 0.5 KB.
|
|
24
|
+
|
|
25
|
+
## Props
|
|
26
|
+
|
|
27
|
+
| Prop | Values | Default |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| `icon` | an icon object such as `IconHeart` (required) | — |
|
|
30
|
+
| `size` | width and height: a number (px) or a CSS length such as `'1em'` | `24` |
|
|
31
|
+
| `radius` | `'sharp'`, `0`, `1`, `2`, `3` | `2` |
|
|
32
|
+
| `weight` | `'light'`, `'regular'`, `'bold'` | `'regular'` |
|
|
33
|
+
| `duo` | color badges and strike-throughs by meaning | `false` |
|
|
34
|
+
| `theme` | `'light'` or `'dark'` recommended colors for `duo` | `'light'` |
|
|
35
|
+
| `colors` | overrides: `{ primary, danger, success, warning, info, accent }`, any CSS color including `var(--x)` | — |
|
|
36
|
+
| `title` | accessible name, see [Accessibility](#accessibility) | — |
|
|
37
|
+
| `hinting` | shift the icon so stroke edges land on device pixels | `false` |
|
|
38
|
+
|
|
39
|
+
The icon is drawn with `currentColor`, so it follows the text color. All other props (`className`, `style`, event handlers, `aria-*`, `data-*`) go to the root `<svg>`, and `ref` gives you the `SVGSVGElement`. Animated icons (such as `IconLoadingAtom`) play through SVG `<animate>` elements, without JavaScript.
|
|
40
|
+
|
|
41
|
+
### Pixel hinting
|
|
42
|
+
|
|
43
|
+
Off by default: icons render with their exact geometry, like other icon sets. Turn it on (`hinting`, or in the defaults) to redraw the icon for `size × devicePixelRatio` device pixels and shift it by less than half a pixel so the outer edges of horizontal and vertical strokes land on pixel boundaries. This sharpens small icons on 1× screens (16 and 20 px) at the cost of sub-pixel offsets between icons. It needs `size` in pixels (a number, `'20'` or `'20px'`) and follows changes of the device pixel ratio.
|
|
44
|
+
|
|
45
|
+
## App-wide defaults
|
|
46
|
+
|
|
47
|
+
Wrap the app (or any part of it) in `IconProvider` to give every `JIcon` below it the same radius, weight or size; props on a single icon still win. Nested providers merge with outer ones (`colors` merges role by role).
|
|
48
|
+
|
|
49
|
+
```jsx
|
|
50
|
+
import { IconProvider } from '@jannchie/icons-react'
|
|
51
|
+
|
|
52
|
+
root.render(
|
|
53
|
+
<IconProvider radius="sharp" weight="bold" size={18}>
|
|
54
|
+
<App />
|
|
55
|
+
</IconProvider>,
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`IconProvider` takes `size`, `radius`, `weight`, `duo`, `theme`, `colors` and `hinting`. Pass a stable `colors` object (a constant or `useMemo`) so that the context value does not change on every render. `IconContext` is exported for reading the merged defaults.
|
|
60
|
+
|
|
61
|
+
## Server-side rendering
|
|
62
|
+
|
|
63
|
+
The component is safe to render on the server (Next.js, Remix, Vite SSR): nothing touches `window` at import or render time. The server renders as if the device pixel ratio were 1; during hydration React uses the same value, then re-renders icons with the real ratio, so hydration does not report mismatches.
|
|
64
|
+
|
|
65
|
+
The main entry uses hooks and starts with `'use client'`, so in the Next.js App Router it works from Server Components as a client component. To render icons inside Server Components without client JavaScript, use the [static entry](#static-entry), which has no hooks.
|
|
66
|
+
|
|
67
|
+
## Accessibility
|
|
68
|
+
|
|
69
|
+
Icons are decorative by default: the `<svg>` gets `aria-hidden="true"`, and screen readers read the surrounding text instead. When an icon carries meaning on its own (an icon-only button, a status mark), pass `title`: the `<svg>` gets `role="img"` and a `<title>` child that names it.
|
|
70
|
+
|
|
71
|
+
```jsx
|
|
72
|
+
<button type="button" onClick={remove}>
|
|
73
|
+
<JIcon icon={IconTrash} title="Delete" />
|
|
74
|
+
</button>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
You can also label the button itself (`aria-label="Delete"`) and keep the icon decorative. Props you pass, such as `aria-label` or `aria-hidden`, override the defaults.
|
|
78
|
+
|
|
79
|
+
## Static entry
|
|
80
|
+
|
|
81
|
+
`@jannchie/icons-react/static` renders the precomputed icons of [`@jannchie/icons/static`](https://www.npmjs.com/package/@jannchie/icons#static-entry): the default style only (radius 2, regular weight, single color), no hinting, and no drawing engine in the bundle. It takes `icon`, `size` (default 24) and `title`, does not read `IconProvider`, and uses no hooks, so it also renders in React Server Components.
|
|
82
|
+
|
|
83
|
+
```jsx
|
|
84
|
+
import { IconHeart } from '@jannchie/icons/static'
|
|
85
|
+
import { JIcon } from '@jannchie/icons-react/static'
|
|
86
|
+
|
|
87
|
+
<JIcon icon={IconHeart} size="1em" />
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Requirements
|
|
91
|
+
|
|
92
|
+
React 18 or later, and `@jannchie/icons` of the same version as this package (both are peer dependencies). ES modules and CommonJS builds with TypeScript types are included.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT. See the [`@jannchie/icons` README](https://www.npmjs.com/package/@jannchie/icons#license) for third-party marks among the icons.
|
package/dist/attrs.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
let _jannchie_icons_runtime = require("@jannchie/icons/runtime");
|
|
2
|
+
let react = require("react");
|
|
3
|
+
//#region packages/react/src/attrs.js
|
|
4
|
+
function reactAttrs(o) {
|
|
5
|
+
const out = {};
|
|
6
|
+
for (const k in o) if (o[k] != null) out[k.startsWith("aria-") || k.startsWith("data-") ? k : k.replace(/-([a-z])/g, (_, c) => c.toUpperCase())] = o[k];
|
|
7
|
+
return out;
|
|
8
|
+
}
|
|
9
|
+
function renderSvg(size, { svg, paths, title }, props, children) {
|
|
10
|
+
const body = paths.map(({ animate, ...p }, i) => (0, react.createElement)("path", {
|
|
11
|
+
key: i,
|
|
12
|
+
...reactAttrs(p)
|
|
13
|
+
}, animate ? (0, react.createElement)("animate", animate) : null));
|
|
14
|
+
if (title) body.unshift((0, react.createElement)("title", { key: "title" }, title));
|
|
15
|
+
return (0, react.createElement)("svg", {
|
|
16
|
+
...(0, _jannchie_icons_runtime.rootAttrs)(size),
|
|
17
|
+
...reactAttrs(svg),
|
|
18
|
+
...props
|
|
19
|
+
}, body, children);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.reactAttrs = reactAttrs;
|
|
23
|
+
exports.renderSvg = renderSvg;
|
package/dist/attrs.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { rootAttrs } from "@jannchie/icons/runtime";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
//#region packages/react/src/attrs.js
|
|
4
|
+
function reactAttrs(o) {
|
|
5
|
+
const out = {};
|
|
6
|
+
for (const k in o) if (o[k] != null) out[k.startsWith("aria-") || k.startsWith("data-") ? k : k.replace(/-([a-z])/g, (_, c) => c.toUpperCase())] = o[k];
|
|
7
|
+
return out;
|
|
8
|
+
}
|
|
9
|
+
function renderSvg(size, { svg, paths, title }, props, children) {
|
|
10
|
+
const body = paths.map(({ animate, ...p }, i) => createElement("path", {
|
|
11
|
+
key: i,
|
|
12
|
+
...reactAttrs(p)
|
|
13
|
+
}, animate ? createElement("animate", animate) : null));
|
|
14
|
+
if (title) body.unshift(createElement("title", { key: "title" }, title));
|
|
15
|
+
return createElement("svg", {
|
|
16
|
+
...rootAttrs(size),
|
|
17
|
+
...reactAttrs(svg),
|
|
18
|
+
...props
|
|
19
|
+
}, body, children);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { reactAttrs, renderSvg };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
const require_attrs = require("./attrs.cjs");
|
|
7
|
+
let _jannchie_icons = require("@jannchie/icons");
|
|
8
|
+
let _jannchie_icons_runtime = require("@jannchie/icons/runtime");
|
|
9
|
+
let react = require("react");
|
|
10
|
+
//#region packages/react/src/index.js
|
|
11
|
+
var IconContext = (0, react.createContext)(null);
|
|
12
|
+
var getServerDpr = () => 1;
|
|
13
|
+
function IconProvider({ children, size, radius, weight, duo, theme, colors, hinting }) {
|
|
14
|
+
const parent = (0, react.useContext)(IconContext);
|
|
15
|
+
const value = (0, react.useMemo)(() => {
|
|
16
|
+
const own = Object.fromEntries(Object.entries({
|
|
17
|
+
size,
|
|
18
|
+
radius,
|
|
19
|
+
weight,
|
|
20
|
+
duo,
|
|
21
|
+
theme,
|
|
22
|
+
colors,
|
|
23
|
+
hinting
|
|
24
|
+
}).filter(([, v]) => v !== void 0));
|
|
25
|
+
return (0, _jannchie_icons_runtime.mergeDefaults)(parent ?? {}, own);
|
|
26
|
+
}, [
|
|
27
|
+
parent,
|
|
28
|
+
size,
|
|
29
|
+
radius,
|
|
30
|
+
weight,
|
|
31
|
+
duo,
|
|
32
|
+
theme,
|
|
33
|
+
colors,
|
|
34
|
+
hinting
|
|
35
|
+
]);
|
|
36
|
+
return (0, react.createElement)(IconContext.Provider, { value }, children);
|
|
37
|
+
}
|
|
38
|
+
var JIcon = (0, react.forwardRef)(function JIcon({ icon, size, radius, weight, duo, theme, colors, title, hinting, children, ...rest }, ref) {
|
|
39
|
+
const d = (0, react.useContext)(IconContext) ?? {};
|
|
40
|
+
const dpr = (0, react.useSyncExternalStore)(_jannchie_icons_runtime.subscribeDpr, _jannchie_icons_runtime.getDpr, getServerDpr);
|
|
41
|
+
const s = size ?? d.size ?? 24;
|
|
42
|
+
const css = (0, _jannchie_icons_runtime.pixelSize)(s);
|
|
43
|
+
const px = (hinting ?? d.hinting ?? false) && css ? Math.round(css * dpr) : 0;
|
|
44
|
+
const r = radius ?? d.radius;
|
|
45
|
+
const w = weight ?? d.weight;
|
|
46
|
+
const du = duo ?? d.duo;
|
|
47
|
+
const th = theme ?? d.theme;
|
|
48
|
+
const c = d.colors || colors ? {
|
|
49
|
+
...d.colors,
|
|
50
|
+
...colors
|
|
51
|
+
} : void 0;
|
|
52
|
+
const ckey = c && JSON.stringify(c);
|
|
53
|
+
const shape = (0, react.useMemo)(() => (0, _jannchie_icons.toPaths)(icon, {
|
|
54
|
+
radius: r,
|
|
55
|
+
weight: w,
|
|
56
|
+
duo: du,
|
|
57
|
+
theme: th,
|
|
58
|
+
colors: c,
|
|
59
|
+
title,
|
|
60
|
+
px
|
|
61
|
+
}), [
|
|
62
|
+
icon,
|
|
63
|
+
r,
|
|
64
|
+
w,
|
|
65
|
+
du,
|
|
66
|
+
th,
|
|
67
|
+
ckey,
|
|
68
|
+
title,
|
|
69
|
+
px
|
|
70
|
+
]);
|
|
71
|
+
return require_attrs.renderSvg(s, shape, {
|
|
72
|
+
...rest,
|
|
73
|
+
ref
|
|
74
|
+
}, children);
|
|
75
|
+
});
|
|
76
|
+
//#endregion
|
|
77
|
+
exports.IconContext = IconContext;
|
|
78
|
+
exports.IconProvider = IconProvider;
|
|
79
|
+
exports.JIcon = JIcon;
|
|
80
|
+
exports.default = JIcon;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Icon, Radius, Role, Theme, Weight } from '@jannchie/icons'
|
|
2
|
+
import type { Context, ForwardRefExoticComponent, ReactElement, ReactNode, RefAttributes, SVGProps } from 'react'
|
|
3
|
+
|
|
4
|
+
export type IconColors = Partial<Record<'primary' | Role, string>>
|
|
5
|
+
|
|
6
|
+
/** Defaults for every JIcon in a subtree; props on a JIcon override them */
|
|
7
|
+
export interface IconDefaults {
|
|
8
|
+
/** Width and height: a number (px) or a CSS length such as '1em'. Defaults to 24 */
|
|
9
|
+
size?: number | string
|
|
10
|
+
/** Corner radius: 'sharp', 0, 1, 2 or 3. Defaults to 2 */
|
|
11
|
+
radius?: Radius
|
|
12
|
+
/** Stroke weight: 'light', 'regular' or 'bold'. Defaults to 'regular' */
|
|
13
|
+
weight?: Weight
|
|
14
|
+
/** Color badges and strike-throughs by their meaning */
|
|
15
|
+
duo?: boolean
|
|
16
|
+
/** Light or dark recommended colors for duo */
|
|
17
|
+
theme?: Theme
|
|
18
|
+
/** Overrides for single roles or the main color (any CSS color, including var(--x)); merged role by role */
|
|
19
|
+
colors?: IconColors
|
|
20
|
+
/** Snap strokes to the device pixel grid when size is in px. Defaults to true */
|
|
21
|
+
hinting?: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type OwnKeys = keyof IconDefaults | 'icon' | 'title' | 'ref'
|
|
25
|
+
|
|
26
|
+
export interface JIconProps extends IconDefaults, Omit<SVGProps<SVGSVGElement>, OwnKeys> {
|
|
27
|
+
/** An icon object such as IconHeart from @jannchie/icons */
|
|
28
|
+
icon: Icon<string>
|
|
29
|
+
/** Accessible name: adds role="img" and a <title>; without it the icon gets aria-hidden="true" */
|
|
30
|
+
title?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Renders an icon from @jannchie/icons as an inline <svg>; other props (className, style, onClick, aria-*) go to the <svg> */
|
|
34
|
+
export declare const JIcon: ForwardRefExoticComponent<JIconProps & RefAttributes<SVGSVGElement>>
|
|
35
|
+
export default JIcon
|
|
36
|
+
|
|
37
|
+
export interface IconProviderProps extends IconDefaults {
|
|
38
|
+
children?: ReactNode
|
|
39
|
+
}
|
|
40
|
+
/** Sets defaults for every JIcon below it; nested providers merge with outer ones */
|
|
41
|
+
export declare function IconProvider(props: IconProviderProps): ReactElement
|
|
42
|
+
/** The merged defaults (null outside any IconProvider) */
|
|
43
|
+
export declare const IconContext: Context<IconDefaults | null>
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Icon, Radius, Role, Theme, Weight } from '@jannchie/icons'
|
|
2
|
+
import type { Context, ForwardRefExoticComponent, ReactElement, ReactNode, RefAttributes, SVGProps } from 'react'
|
|
3
|
+
|
|
4
|
+
export type IconColors = Partial<Record<'primary' | Role, string>>
|
|
5
|
+
|
|
6
|
+
/** Defaults for every JIcon in a subtree; props on a JIcon override them */
|
|
7
|
+
export interface IconDefaults {
|
|
8
|
+
/** Width and height: a number (px) or a CSS length such as '1em'. Defaults to 24 */
|
|
9
|
+
size?: number | string
|
|
10
|
+
/** Corner radius: 'sharp', 0, 1, 2 or 3. Defaults to 2 */
|
|
11
|
+
radius?: Radius
|
|
12
|
+
/** Stroke weight: 'light', 'regular' or 'bold'. Defaults to 'regular' */
|
|
13
|
+
weight?: Weight
|
|
14
|
+
/** Color badges and strike-throughs by their meaning */
|
|
15
|
+
duo?: boolean
|
|
16
|
+
/** Light or dark recommended colors for duo */
|
|
17
|
+
theme?: Theme
|
|
18
|
+
/** Overrides for single roles or the main color (any CSS color, including var(--x)); merged role by role */
|
|
19
|
+
colors?: IconColors
|
|
20
|
+
/** Snap strokes to the device pixel grid when size is in px. Defaults to true */
|
|
21
|
+
hinting?: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type OwnKeys = keyof IconDefaults | 'icon' | 'title' | 'ref'
|
|
25
|
+
|
|
26
|
+
export interface JIconProps extends IconDefaults, Omit<SVGProps<SVGSVGElement>, OwnKeys> {
|
|
27
|
+
/** An icon object such as IconHeart from @jannchie/icons */
|
|
28
|
+
icon: Icon<string>
|
|
29
|
+
/** Accessible name: adds role="img" and a <title>; without it the icon gets aria-hidden="true" */
|
|
30
|
+
title?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Renders an icon from @jannchie/icons as an inline <svg>; other props (className, style, onClick, aria-*) go to the <svg> */
|
|
34
|
+
export declare const JIcon: ForwardRefExoticComponent<JIconProps & RefAttributes<SVGSVGElement>>
|
|
35
|
+
export default JIcon
|
|
36
|
+
|
|
37
|
+
export interface IconProviderProps extends IconDefaults {
|
|
38
|
+
children?: ReactNode
|
|
39
|
+
}
|
|
40
|
+
/** Sets defaults for every JIcon below it; nested providers merge with outer ones */
|
|
41
|
+
export declare function IconProvider(props: IconProviderProps): ReactElement
|
|
42
|
+
/** The merged defaults (null outside any IconProvider) */
|
|
43
|
+
export declare const IconContext: Context<IconDefaults | null>
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { renderSvg } from "./attrs.js";
|
|
3
|
+
import { toPaths } from "@jannchie/icons";
|
|
4
|
+
import { getDpr, mergeDefaults, pixelSize, subscribeDpr } from "@jannchie/icons/runtime";
|
|
5
|
+
import { createContext, createElement, forwardRef, useContext, useMemo, useSyncExternalStore } from "react";
|
|
6
|
+
//#region packages/react/src/index.js
|
|
7
|
+
var IconContext = createContext(null);
|
|
8
|
+
var getServerDpr = () => 1;
|
|
9
|
+
function IconProvider({ children, size, radius, weight, duo, theme, colors, hinting }) {
|
|
10
|
+
const parent = useContext(IconContext);
|
|
11
|
+
const value = useMemo(() => {
|
|
12
|
+
const own = Object.fromEntries(Object.entries({
|
|
13
|
+
size,
|
|
14
|
+
radius,
|
|
15
|
+
weight,
|
|
16
|
+
duo,
|
|
17
|
+
theme,
|
|
18
|
+
colors,
|
|
19
|
+
hinting
|
|
20
|
+
}).filter(([, v]) => v !== void 0));
|
|
21
|
+
return mergeDefaults(parent ?? {}, own);
|
|
22
|
+
}, [
|
|
23
|
+
parent,
|
|
24
|
+
size,
|
|
25
|
+
radius,
|
|
26
|
+
weight,
|
|
27
|
+
duo,
|
|
28
|
+
theme,
|
|
29
|
+
colors,
|
|
30
|
+
hinting
|
|
31
|
+
]);
|
|
32
|
+
return createElement(IconContext.Provider, { value }, children);
|
|
33
|
+
}
|
|
34
|
+
var JIcon = forwardRef(function JIcon({ icon, size, radius, weight, duo, theme, colors, title, hinting, children, ...rest }, ref) {
|
|
35
|
+
const d = useContext(IconContext) ?? {};
|
|
36
|
+
const dpr = useSyncExternalStore(subscribeDpr, getDpr, getServerDpr);
|
|
37
|
+
const s = size ?? d.size ?? 24;
|
|
38
|
+
const css = pixelSize(s);
|
|
39
|
+
const px = (hinting ?? d.hinting ?? false) && css ? Math.round(css * dpr) : 0;
|
|
40
|
+
const r = radius ?? d.radius;
|
|
41
|
+
const w = weight ?? d.weight;
|
|
42
|
+
const du = duo ?? d.duo;
|
|
43
|
+
const th = theme ?? d.theme;
|
|
44
|
+
const c = d.colors || colors ? {
|
|
45
|
+
...d.colors,
|
|
46
|
+
...colors
|
|
47
|
+
} : void 0;
|
|
48
|
+
const ckey = c && JSON.stringify(c);
|
|
49
|
+
const shape = useMemo(() => toPaths(icon, {
|
|
50
|
+
radius: r,
|
|
51
|
+
weight: w,
|
|
52
|
+
duo: du,
|
|
53
|
+
theme: th,
|
|
54
|
+
colors: c,
|
|
55
|
+
title,
|
|
56
|
+
px
|
|
57
|
+
}), [
|
|
58
|
+
icon,
|
|
59
|
+
r,
|
|
60
|
+
w,
|
|
61
|
+
du,
|
|
62
|
+
th,
|
|
63
|
+
ckey,
|
|
64
|
+
title,
|
|
65
|
+
px
|
|
66
|
+
]);
|
|
67
|
+
return renderSvg(s, shape, {
|
|
68
|
+
...rest,
|
|
69
|
+
ref
|
|
70
|
+
}, children);
|
|
71
|
+
});
|
|
72
|
+
//#endregion
|
|
73
|
+
export { IconContext, IconProvider, JIcon, JIcon as default };
|
package/dist/static.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
const require_attrs = require("./attrs.cjs");
|
|
6
|
+
let react = require("react");
|
|
7
|
+
let _jannchie_icons_static = require("@jannchie/icons/static");
|
|
8
|
+
//#region packages/react/src/static.js
|
|
9
|
+
var JIcon = (0, react.forwardRef)(function JIcon({ icon, size = 24, title, children, ...rest }, ref) {
|
|
10
|
+
return require_attrs.renderSvg(size, (0, _jannchie_icons_static.toPaths)(icon, { title }), {
|
|
11
|
+
...rest,
|
|
12
|
+
ref
|
|
13
|
+
}, children);
|
|
14
|
+
});
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.JIcon = JIcon;
|
|
17
|
+
exports.default = JIcon;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StaticIcon } from '@jannchie/icons/static'
|
|
2
|
+
import type { ForwardRefExoticComponent, RefAttributes, SVGProps } from 'react'
|
|
3
|
+
|
|
4
|
+
export interface StaticJIconProps extends Omit<SVGProps<SVGSVGElement>, 'size' | 'title' | 'ref'> {
|
|
5
|
+
/** A precomputed icon such as IconHeart from @jannchie/icons/static */
|
|
6
|
+
icon: StaticIcon<string>
|
|
7
|
+
/** Width and height: a number (px) or a CSS length such as '1em'. Defaults to 24 */
|
|
8
|
+
size?: number | string
|
|
9
|
+
/** Accessible name: adds role="img" and a <title>; without it the icon gets aria-hidden="true" */
|
|
10
|
+
title?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Renders a precomputed icon (default style) as an inline <svg>; no hooks, so it also works in React Server Components */
|
|
14
|
+
export declare const JIcon: ForwardRefExoticComponent<StaticJIconProps & RefAttributes<SVGSVGElement>>
|
|
15
|
+
export default JIcon
|
package/dist/static.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StaticIcon } from '@jannchie/icons/static'
|
|
2
|
+
import type { ForwardRefExoticComponent, RefAttributes, SVGProps } from 'react'
|
|
3
|
+
|
|
4
|
+
export interface StaticJIconProps extends Omit<SVGProps<SVGSVGElement>, 'size' | 'title' | 'ref'> {
|
|
5
|
+
/** A precomputed icon such as IconHeart from @jannchie/icons/static */
|
|
6
|
+
icon: StaticIcon<string>
|
|
7
|
+
/** Width and height: a number (px) or a CSS length such as '1em'. Defaults to 24 */
|
|
8
|
+
size?: number | string
|
|
9
|
+
/** Accessible name: adds role="img" and a <title>; without it the icon gets aria-hidden="true" */
|
|
10
|
+
title?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Renders a precomputed icon (default style) as an inline <svg>; no hooks, so it also works in React Server Components */
|
|
14
|
+
export declare const JIcon: ForwardRefExoticComponent<StaticJIconProps & RefAttributes<SVGSVGElement>>
|
|
15
|
+
export default JIcon
|
package/dist/static.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { renderSvg } from "./attrs.js";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { toPaths } from "@jannchie/icons/static";
|
|
4
|
+
//#region packages/react/src/static.js
|
|
5
|
+
var JIcon = forwardRef(function JIcon({ icon, size = 24, title, children, ...rest }, ref) {
|
|
6
|
+
return renderSvg(size, toPaths(icon, { title }), {
|
|
7
|
+
...rest,
|
|
8
|
+
ref
|
|
9
|
+
}, children);
|
|
10
|
+
});
|
|
11
|
+
//#endregion
|
|
12
|
+
export { JIcon, JIcon as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@jannchie/icons-react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@jannchie/icons-react",
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "React component for Jannchie Icons: one <JIcon> for every icon, with context defaults for radius and weight, pixel hinting and duo-tone colors",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Jianqi Pan",
|
|
7
|
+
"homepage": "https://icons.jannchie.com",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/Jannchie/jannchie-icons/issues"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/Jannchie/jannchie-icons.git",
|
|
14
|
+
"directory": "packages/react"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"icons",
|
|
18
|
+
"svg",
|
|
19
|
+
"line-icons",
|
|
20
|
+
"react", "component"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"main": "./dist/index.cjs",
|
|
25
|
+
"module": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./dist/index.d.cts",
|
|
35
|
+
"default": "./dist/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"./static": {
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/static.d.ts",
|
|
41
|
+
"default": "./dist/static.js"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/static.d.cts",
|
|
45
|
+
"default": "./dist/static.cjs"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@jannchie/icons": "^0.7.0",
|
|
52
|
+
"react": ">=18.0.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@jannchie/icons": "workspace:^"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=18"
|
|
59
|
+
},
|
|
60
|
+
"files": [
|
|
61
|
+
"dist",
|
|
62
|
+
"NOTICE"
|
|
63
|
+
]
|
|
64
|
+
}
|