@rdicons/react-octicon 0.0.0-stage → 0.2.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 +25 -0
- package/LICENSES/octicon.txt +31 -0
- package/README.md +19 -2
- package/index.d.ts +1916 -0
- package/index.js +959 -0
- package/package.json +51 -4
- package/runtime.d.ts +25 -0
- package/runtime.js +40 -0
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rdicons/react-octicon",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Octicons: 957 icons as React components. Just this library, tree-shakable. Part of rdicons.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"icons",
|
|
7
|
+
"react",
|
|
8
|
+
"svg",
|
|
9
|
+
"octicon",
|
|
10
|
+
"octicons",
|
|
11
|
+
"rdicons"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "rdicons contributors",
|
|
15
|
+
"homepage": "https://rdicons.vimalbhatt.com/library/octicon",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/DevHydeOut/rdicons-lib.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/DevHydeOut/rdicons-lib/issues"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"main": "./index.js",
|
|
26
|
+
"module": "./index.js",
|
|
27
|
+
"types": "./index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./index.d.ts",
|
|
31
|
+
"default": "./index.js"
|
|
32
|
+
},
|
|
33
|
+
"./package.json": "./package.json"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"index.js",
|
|
37
|
+
"index.d.ts",
|
|
38
|
+
"runtime.js",
|
|
39
|
+
"runtime.d.ts",
|
|
40
|
+
"LICENSES",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"react": "^19.3.1"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
}
|
|
53
|
+
}
|
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, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
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
|
+
}
|