@cypress-design/react-icon 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.
@@ -0,0 +1,61 @@
1
+ const path = require('path');
2
+ const dedent = require('dedent');
3
+ const { promises: fs } = require('fs');
4
+ const camelcase = require('camelcase');
5
+ const { iconsMetadata, iconSet } = require('@cypress-design/icon-registry');
6
+
7
+ const iconsComponents = Object.keys(iconsMetadata).map((name) => {
8
+ const pascalCaseName = camelcase(name, { pascalCase: true });
9
+ const iconMetadata = iconsMetadata[name];
10
+ const availableIds = iconMetadata.availableSizes.map(
11
+ (size) => `${camelcase(name)}X${size}`
12
+ );
13
+
14
+ const iconBodies = iconSet.reduce((acc, icon) => {
15
+ const sizeIndex = availableIds.indexOf(icon.name);
16
+ if (sizeIndex > -1) {
17
+ acc[iconMetadata.availableSizes[sizeIndex]] = icon.data;
18
+ }
19
+ return acc;
20
+ }, {});
21
+ return dedent`
22
+ export const Icon${pascalCaseName}: React.FC<
23
+ Omit<iconsRegistry.Icon${pascalCaseName}Props, 'name'> & React.SVGProps<SVGSVGElement>
24
+ > = (props) => {
25
+ const { sizeWithDefault: size, compiledClasses } = iconsRegistry.getComponentAttributes({ ...(props as any), availableSizes: ${JSON.stringify(
26
+ iconMetadata.availableSizes
27
+ )} })
28
+ const iconBodies: Record<string, string> = ${JSON.stringify(
29
+ iconBodies,
30
+ null,
31
+ 2
32
+ )}
33
+ const body = iconBodies[size]
34
+ if(!body){
35
+ throw Error(\`Icon "${name}" is not available in size ${'$'}{size}\`)
36
+ }
37
+ return React.createElement('svg', compileReactIconProperties({
38
+ ...props,
39
+ size,
40
+ body,
41
+ compiledClasses
42
+ }))
43
+ }
44
+ `;
45
+ });
46
+
47
+ writeFile(`
48
+ import * as iconsRegistry from '@cypress-design/icon-registry'
49
+ import { compileReactIconProperties } from './compileProperties'
50
+ import * as React from 'react';
51
+
52
+ ${iconsComponents.join('\n\n\n')}
53
+ `);
54
+
55
+ async function writeFile(fileContents) {
56
+ await fs.writeFile(
57
+ path.resolve(__dirname, './TreeShakableIcons.ts'),
58
+ fileContents,
59
+ 'utf-8'
60
+ );
61
+ }
package/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { default } from './Icon';
2
+ export * from './TreeShakableIcons';
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@cypress-design/react-icon",
3
+ "version": "0.1.0",
4
+ "files": [
5
+ "*"
6
+ ],
7
+ "typings": "./dist/index.d.ts",
8
+ "main": "./dist/index.umd.js",
9
+ "module": "./dist/index.es.js",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.es.js",
13
+ "require": "./dist/index.umd.js"
14
+ }
15
+ },
16
+ "scripts": {
17
+ "build": "yarn build:codegen && yarn build:module && yarn build:types",
18
+ "build:codegen": "node ./generate-icons.js",
19
+ "build:module": "rollup -c ./rollup.config.js",
20
+ "build:types": "tsc --project ./tsconfig.build.json"
21
+ },
22
+ "dependencies": {
23
+ "@cypress-design/icon-registry": "^0.1.0"
24
+ },
25
+ "devDependencies": {
26
+ "camelcase": "^6.3.0",
27
+ "dedent": "^0.7.0"
28
+ },
29
+ "license": "MIT"
30
+ }
@@ -0,0 +1,3 @@
1
+ import rootRollupConfig from '../../root.rollup.config';
2
+
3
+ export default rootRollupConfig({ input: './index.ts' });
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../../tsconfig.react.build.json",
3
+ "include": ["./Icon.tsx", "./index.ts"],
4
+ "compilerOptions": {
5
+ "outDir": "dist",
6
+ }
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.react.json",
3
+ "include": ["*.tsx", "*.ts"]
4
+ }