@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.
- package/.gitignore +1 -0
- package/CHANGELOG.md +12 -0
- package/Icon.cy.tsx +22 -0
- package/Icon.stories.mdx +83 -0
- package/Icon.tsx +53 -0
- package/ReadMe.md +50 -0
- package/compileProperties.ts +35 -0
- package/dist/Icon.d.ts +489 -0
- package/dist/Icon.d.ts.map +1 -0
- package/dist/TreeShakableIcons.d.ts +123 -0
- package/dist/TreeShakableIcons.d.ts.map +1 -0
- package/dist/compileProperties.d.ts +11 -0
- package/dist/compileProperties.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +1427 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +1571 -0
- package/dist/index.umd.js.map +1 -0
- package/generate-icons.js +61 -0
- package/index.ts +2 -0
- package/package.json +30 -0
- package/rollup.config.js +3 -0
- package/tsconfig.build.json +7 -0
- package/tsconfig.json +4 -0
|
@@ -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
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
|
+
}
|
package/rollup.config.js
ADDED
package/tsconfig.json
ADDED