Skip to content

Commit cedf113

Browse files
authored
React package (#105)
* init new react package project * setup react package * Fix config for build * update package * Fix build * update package * fix package.json * refactor and cleanup * bumb beta version * fix regex * bump version * Add hashing * Add tests * bump version * Add peer dependecies * Add docs * Add readme link
1 parent 571cab8 commit cedf113

335 files changed

Lines changed: 5164 additions & 11847 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
module.exports = {
2-
"env": {
3-
"browser": true,
4-
"node": true
2+
env: {
3+
browser: true,
4+
node: true
55
},
6-
"extends": ["airbnb-base", "prettier"],
7-
"plugins": ["import", "prettier"],
8-
"rules": {
9-
"no-console": "off",
10-
"no-param-reassign": "off",
11-
"no-shadow": "off",
12-
"no-use-before-define": "off",
13-
"prettier/prettier": [
14-
"error",
6+
extends: ['airbnb-base', 'prettier'],
7+
plugins: ['import', 'prettier'],
8+
rules: {
9+
'no-console': 'off',
10+
'no-param-reassign': 'off',
11+
'no-shadow': 'off',
12+
'no-use-before-define': 'off',
13+
'prettier/prettier': [
14+
'error',
1515
{
16-
"singleQuote": true,
17-
"trailingComma": "all"
16+
singleQuote: true,
17+
trailingComma: 'all'
1818
}
1919
]
2020
}
21-
}
21+
};

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ const myApp = document.getElementById('app');
148148
myApp.appendChild(menuIcon);
149149
```
150150

151+
### With React
152+
153+
You can also use the lucide library as react icons.
154+
155+
See [documentation](https://github.com/lucide-icons/lucide/blob/master/packages/lucide-react/README.md).
156+
151157
### Figma
152158

153159
You can use the components from [this Figma file](https://www.figma.com/file/g0UipfQlRfGrntKPxZknM7/Featherity).

package.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
"description": "Lucide is a community-run fork of Feather Icons, open for anyone to contribute icons.",
44
"version": "0.11.0",
55
"license": "ISC",
6-
"amdName": "lucide",
76
"homepage": "https://lucide.netlify.app",
8-
"url": "https://github.com/owner/project/issues",
97
"repository": "github:lucide-icons/lucide",
8+
"bugs": {
9+
"url": "https://github.com/lucide-icons/lucide/issues"
10+
},
11+
"amdName": "lucide",
1012
"source": "build/lucide.js",
1113
"main": "dist/cjs/lucide.js",
1214
"main:umd": "dist/umd/lucide.js",
@@ -15,11 +17,11 @@
1517
"sideEffects": false,
1618
"scripts": {
1719
"start": "babel-watch --watch src",
18-
"clean": "rimraf lib && rimraf dist && rimraf build",
20+
"clean": "rimraf dist && rimraf build",
1921
"build": "yarn clean && yarn build:move && yarn build:icons && yarn build:es && yarn build:bundles",
2022
"build:move": "cp -av src build",
2123
"build:icons": "npx babel-node ./scripts/buildIcons.js --presets @babel/env",
22-
"build:es": "babel build -d dist/esm --ignore '**/*.test.js','**/__mocks__'",
24+
"build:es": "babel build -d dist/esm",
2325
"build:bundles": "rollup -c rollup.config.js",
2426
"optimize": "npx babel-node ./scripts/optimizeSvgs.js --presets @babel/env",
2527
"test": "jest"
@@ -30,19 +32,22 @@
3032
"@babel/cli": "^7.10.5",
3133
"@babel/core": "^7.11.1",
3234
"@babel/node": "^7.10.5",
35+
"@babel/plugin-transform-runtime": "^7.11.5",
3336
"@babel/preset-env": "^7.11.0",
3437
"@rollup/plugin-babel": "^5.0.0",
3538
"babel-jest": "^26.3.0",
3639
"babel-plugin-add-import-extension": "^1.4.3",
3740
"cheerio": "^1.0.0-rc.2",
41+
"core-js": "3",
3842
"eslint": "^4.19.1",
3943
"eslint-config-airbnb-base": "^12.1.0",
4044
"eslint-config-prettier": "^2.9.0",
4145
"eslint-plugin-import": "^2.5.0",
4246
"eslint-plugin-prettier": "^2.5.0",
4347
"html-minifier": "^3.5.8",
48+
"htmlparser2": "^4.1.0",
4449
"jest": "^26.4.2",
45-
"lodash": "^4.17.19",
50+
"minimist": "^1.2.5",
4651
"prettier": "^1.8.2",
4752
"rollup": "^2.7.3",
4853
"rollup-plugin-commonjs": "^10.1.0",
@@ -52,12 +57,5 @@
5257
"rollup-plugin-terser": "^5.2.0",
5358
"rollup-plugin-visualizer": "^4.1.0",
5459
"svgo": "^1.3.2"
55-
},
56-
"dependencies": {
57-
"@babel/plugin-transform-runtime": "^7.11.5",
58-
"core-js": "3",
59-
"htmlparser2": "^4.1.0",
60-
"lodash-es": "^4.17.15",
61-
"prop-types": "^15.7.2"
6260
}
6361
}

packages/lucide-react/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Lucide React
2+
3+
Use the lucide icon library in you react app.
4+
5+
## Installation
6+
7+
```sh
8+
yarn add lucide-react
9+
10+
# or
11+
12+
npm install lucide-react
13+
```
14+
15+
## How to use
16+
17+
It's build with ESmodules so it's completely threeshakable.
18+
Each icon can be imported as an react component.
19+
20+
### Example
21+
22+
You can pass additional props to adjust the icon.
23+
24+
``` js
25+
import { Camera } from 'lucide-react';
26+
// Returns ReactComponent
27+
28+
// Usage
29+
const App = () => {
30+
return <Camera color="red" size={48}/>
31+
};
32+
33+
export default App;
34+
```
35+
36+
### Props
37+
38+
| name | type | default
39+
| ------------ | -------- | --------
40+
| `size` | *Number* | 24
41+
| `color` | *String* | currentColor
42+
| `strokeWidth`| *Number* | 2
43+
44+
### Custom props
45+
46+
You can also pass custom props that will be added in the svg as attributes.
47+
48+
``` js
49+
// Usage
50+
const App = () => {
51+
return <Camera fill="red"/>
52+
};
53+
```
54+
55+
### One generic icon component
56+
57+
It is possible to create one generic icon component to load icons.
58+
59+
> :warning: Example below importing all EsModules, caution using this example, not recommended when you using bundlers.
60+
61+
#### Icon Component Example
62+
63+
``` js
64+
import * as icons from 'lucide-react';
65+
66+
const Icon = ({name, color, size}) => {
67+
const LucideIcon = icons[name];
68+
69+
return <LucideIcon color={color} size={size} />
70+
};
71+
72+
export default Icon;
73+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// module.exports = require('../../babel.config');
2+
module.exports = {
3+
presets: ['react-app'],
4+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
verbose: true,
3+
roots: ['<rootDir>/src/', '<rootDir>/tests/'],
4+
moduleFileExtensions: ['js'],
5+
transformIgnorePatterns: [`/node_modules`],
6+
moduleNameMapper: {
7+
'^@/(.*)$': '<rootDir>/src/$1',
8+
},
9+
transform: {
10+
'^.+\\.js$': 'babel-jest',
11+
},
12+
};

packages/lucide-react/package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "lucide-react",
3+
"description": "Lucide is a community-run fork of Feather Icons, open for anyone to contribute icons.",
4+
"version": "0.1.2-beta.5",
5+
"license": "ISC",
6+
"amdName": "lucide-react",
7+
"source": "build/lucide-react.js",
8+
"main": "dist/cjs/lucide-react.js",
9+
"main:umd": "dist/umd/lucide-react.js",
10+
"module": "dist/esm/lucide-react.js",
11+
"unpkg": "dist/umd/lucide-react.min.js",
12+
"repository": "github:lucide-icons/lucide",
13+
"author": "Eric Fennis",
14+
"scripts": {
15+
"build": "yarn clean && yarn build:move && yarn build:icons && yarn build:es && yarn build:bundles",
16+
"clean": "rm -rf dist && rm -rf build",
17+
"build:move": "cp -av src build",
18+
"build:icons": "yarn --cwd ../../ build:icons --output=../packages/lucide-react/build --templateSrc=../packages/lucide-react/scripts/exportTemplate --camelizeAttrs --renderUniqueKey",
19+
"build:es": "yarn --cwd ../../ babel packages/lucide-react/build -d packages/lucide-react/dist/esm",
20+
"build:bundles": "yarn --cwd ../../ rollup -c packages/lucide-react/rollup.config.js",
21+
"test": "jest"
22+
},
23+
"dependencies": {
24+
"prop-types": "^15.7.2",
25+
"react": "^17.0.1"
26+
},
27+
"devDependencies": {
28+
"babel-preset-react-app": "^10.0.0",
29+
"jest": "^26.6.3",
30+
"lucide": "file:../..",
31+
"react-test-renderer": "^17.0.1"
32+
},
33+
"peerDependencies": {
34+
"prop-types": "^15.7.2",
35+
"react": "^17.0.1"
36+
}
37+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const plugins = require('lucide/rollup.plugins');
2+
const pkg = require('./package.json');
3+
4+
const outputFileName = pkg.name;
5+
const rootDir = 'packages/lucide-react'; // It runs from the root
6+
const outputDir = `${rootDir}/dist`;
7+
const inputs = [`${rootDir}/build/lucide-react.js`];
8+
const bundles = [
9+
{
10+
format: 'umd',
11+
inputs,
12+
outputDir,
13+
minify: true,
14+
},
15+
{
16+
format: 'umd',
17+
inputs,
18+
outputDir,
19+
},
20+
{
21+
format: 'cjs',
22+
inputs,
23+
outputDir,
24+
},
25+
];
26+
27+
const configs = bundles
28+
.map(({ inputs, outputDir, format, minify }) =>
29+
inputs.map(input => ({
30+
input,
31+
plugins: plugins(pkg, minify),
32+
external: ['react', 'prop-types'],
33+
output: {
34+
name: outputFileName,
35+
file: `${outputDir}/${format}/${outputFileName}${minify ? '.min' : ''}.js`,
36+
format,
37+
sourcemap: true,
38+
globals: {
39+
react: 'react',
40+
'prop-types': 'PropTypes',
41+
},
42+
},
43+
})),
44+
)
45+
.flat();
46+
47+
export default configs;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default ({ componentName, node }) => `
2+
import createReactComponent from '../createReactComponent';
3+
4+
const ${componentName} = createReactComponent('${componentName}', ${node});
5+
6+
export default ${componentName};
7+
`;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { forwardRef, createElement } from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
export default (iconName, [tag, attrs, children]) => {
5+
const Component = forwardRef(
6+
({ color = 'currentColor', size = 24, strokeWidth = 2, ...rest }, ref) =>
7+
createElement(
8+
tag,
9+
{
10+
ref,
11+
...attrs,
12+
width: size,
13+
height: size,
14+
color,
15+
strokeWidth,
16+
...rest,
17+
},
18+
children.map(([childTag, childAttrs]) => createElement(childTag, childAttrs)),
19+
),
20+
);
21+
22+
Component.propTypes = {
23+
color: PropTypes.string,
24+
size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
25+
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
26+
};
27+
28+
Component.displayName = `${iconName}`;
29+
30+
return Component;
31+
};

0 commit comments

Comments
 (0)