@rdicons/react-rd 0.0.0-stage → 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/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@rdicons/react-rd",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "rd: 543 icons as React components. Just this library, tree-shakable. Part of rdicons.",
5
+ "keywords": [
6
+ "icons",
7
+ "react",
8
+ "svg",
9
+ "rd",
10
+ "rdicons"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "rdicons contributors",
14
+ "homepage": "https://rdicons.vimalbhatt.com/library/rd",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/DevHydeOut/rdicons-lib.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/DevHydeOut/rdicons-lib/issues"
21
+ },
22
+ "type": "module",
23
+ "sideEffects": false,
24
+ "main": "./index.js",
25
+ "module": "./index.js",
26
+ "types": "./index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./index.d.ts",
30
+ "default": "./index.js"
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
34
+ "files": [
35
+ "index.js",
36
+ "index.d.ts",
37
+ "runtime.js",
38
+ "runtime.d.ts",
39
+ "LICENSES",
40
+ "README.md",
41
+ "LICENSE"
42
+ ],
43
+ "engines": {
44
+ "node": ">=18"
45
+ },
46
+ "peerDependencies": {
47
+ "react": ">=17"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ }
52
+ }
package/runtime.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { ForwardRefExoticComponent, RefAttributes, SVGProps } from 'react'
2
+
3
+ export interface RdIconProps extends Omit<SVGProps<SVGSVGElement>, 'ref' | 'children' | 'dangerouslySetInnerHTML'> {
4
+ /** Width and height in px (or any CSS length). Default 24 */
5
+ size?: number | string
6
+ /** Any CSS color. Default: inherits the surrounding text color (currentColor) */
7
+ color?: string
8
+ /** Replaces the icon's own stroke width (outline icons only) */
9
+ strokeWidth?: number | string
10
+ /** Accessible name. Without it the icon is hidden from screen readers (decorative) */
11
+ title?: string
12
+ /**
13
+ * Plays the icon's animation (icons without one ignore this). Off by default.
14
+ * `true` or `"hover"`: when the icon is hovered. `"parent"`: when its parent (for example a button) is hovered.
15
+ * `"play"`: while set (change it away and back to replay). `"loop"`: continuously.
16
+ * Nothing moves when the user's device asks for reduced motion.
17
+ */
18
+ animate?: boolean | 'hover' | 'parent' | 'play' | 'loop'
19
+ /** Animation speed: 2 is twice as fast, 0.5 twice as slow. Default 1 */
20
+ speed?: number
21
+ }
22
+
23
+ export type RdIcon = ForwardRefExoticComponent<RdIconProps & RefAttributes<SVGSVGElement>>
24
+
25
+ export declare function createIcon(id: string, body: string, width?: number, height?: number, anim?: { b: string; c: string }): RdIcon
package/runtime.js ADDED
@@ -0,0 +1,40 @@
1
+ import { createElement, forwardRef } from 'react'
2
+
3
+ const STROKE_WIDTH = /stroke-width="[^"]*"/g
4
+ const escapeHtml = (s) => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
5
+
6
+ /**
7
+ * Turns an icon (SVG inner markup + viewBox size) into a React component.
8
+ * Every generated icon in this package is created with this function.
9
+ */
10
+ export function createIcon(id, body, width = 24, height = 24, anim) {
11
+ const name = id.slice(id.indexOf(':') + 1)
12
+ const Icon = forwardRef(function RdIcon({ size = 24, color, strokeWidth, title, style, animate, speed, className, ...rest }, ref) {
13
+ // Animation is opt-in. Only icons that have motion (anim = { b: animated drawing, c: css }) react to `animate`; the rest ignore it.
14
+ const mode = anim && animate ? (animate === true ? 'hover' : animate) : null
15
+ const drawing = mode ? anim.b : body
16
+ const html = strokeWidth == null ? drawing : drawing.replace(STROKE_WIDTH, 'stroke-width="' + strokeWidth + '"')
17
+ // Fit the longest side into the `size` box, like the rdicons website does.
18
+ const n = typeof size === 'number' ? size : Number.parseFloat(size)
19
+ const long = Math.max(width, height)
20
+ const w = typeof size === 'number' && width !== height ? (n * width) / long : size
21
+ const h = typeof size === 'number' && width !== height ? (n * height) / long : size
22
+ return createElement('svg', {
23
+ ref,
24
+ xmlns: 'http://www.w3.org/2000/svg',
25
+ viewBox: '0 0 ' + width + ' ' + height,
26
+ width: w,
27
+ height: h,
28
+ role: title ? 'img' : undefined,
29
+ 'aria-hidden': title ? undefined : true,
30
+ focusable: 'false',
31
+ className: mode ? 'rd-a-' + name + (className ? ' ' + className : '') : className,
32
+ 'data-rd-animate': mode || undefined,
33
+ style: color || (mode && speed) ? { ...(color ? { color } : null), ...(mode && speed ? { '--rd-speed': 1 / speed } : null), ...style } : style,
34
+ ...rest,
35
+ dangerouslySetInnerHTML: { __html: (title ? '<title>' + escapeHtml(title) + '</title>' : '') + (mode ? '<style>' + anim.c + '</style>' : '') + html },
36
+ })
37
+ })
38
+ Icon.displayName = id
39
+ return Icon
40
+ }