mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-17 04:47:40 +01:00
Add lucide-react-native package (#687)
* Add `lucide-react-native` package Closes #394 * minor fixes build config * Add `lucide-react-native` package Closes #394 * make it work Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
This commit is contained in:
47
packages/lucide-react-native/scripts/buildTypes.js
Normal file
47
packages/lucide-react-native/scripts/buildTypes.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import path from 'path';
|
||||
import {
|
||||
appendFile,
|
||||
readSvgDirectory,
|
||||
resetFile,
|
||||
toPascalCase,
|
||||
writeFile,
|
||||
} from '../../../scripts/helpers';
|
||||
|
||||
const srcDirectory = path.join(__dirname, '../dist');
|
||||
|
||||
// Declare type definitions
|
||||
const typeDefinitions = `\
|
||||
/// <reference types="react" />
|
||||
import { SVGAttributes } from 'react'
|
||||
|
||||
declare module 'lucide-react-native'
|
||||
|
||||
// Create interface extending SVGProps
|
||||
export interface LucideProps extends Partial<React.SVGProps<SVGSVGElement>> {
|
||||
size?: string | number
|
||||
}
|
||||
|
||||
export declare const createReactComponent: (iconName: string, iconNode: any[]) => (props: LucideProps) => JSX.Element;
|
||||
|
||||
export type Icon = React.FC<LucideProps>;
|
||||
|
||||
// Generated icons
|
||||
`;
|
||||
|
||||
const ICONS_DIR = path.resolve(__dirname, '../../../icons');
|
||||
const TYPES_FILE = 'lucide-react-native.d.ts';
|
||||
|
||||
resetFile(TYPES_FILE, srcDirectory);
|
||||
writeFile(typeDefinitions, TYPES_FILE, srcDirectory);
|
||||
|
||||
const svgFiles = readSvgDirectory(ICONS_DIR);
|
||||
|
||||
svgFiles.forEach(svgFile => {
|
||||
const iconName = path.basename(svgFile, '.svg');
|
||||
const componentName = toPascalCase(iconName);
|
||||
|
||||
const exportTypeString = `export declare const ${componentName}: (props: LucideProps) => JSX.Element;\n`;
|
||||
appendFile(exportTypeString, TYPES_FILE, srcDirectory);
|
||||
});
|
||||
|
||||
console.log(`Generated ${TYPES_FILE} file with`, svgFiles.length, 'icons');
|
||||
7
packages/lucide-react-native/scripts/exportTemplate.js
Normal file
7
packages/lucide-react-native/scripts/exportTemplate.js
Normal file
@@ -0,0 +1,7 @@
|
||||
export default ({ componentName, children }) => `
|
||||
import createReactComponent from '../createReactComponent';
|
||||
|
||||
const ${componentName} = createReactComponent('${componentName}', ${JSON.stringify(children)});
|
||||
|
||||
export default ${componentName};
|
||||
`;
|
||||
Reference in New Issue
Block a user