@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 ADDED
@@ -0,0 +1 @@
1
+ TreeShakableIcons.ts
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # @cypress-design/react-icon
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#10](https://github.com/cypress-io/cypress-design/pull/10) [`e20eea8`](https://github.com/cypress-io/cypress-design/commit/e20eea84375b7f4bd3a15a80fce3bdbfcb327981) Thanks [@elevatebart](https://github.com/elevatebart)! - Creation of vue and react icon components
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`e20eea8`](https://github.com/cypress-io/cypress-design/commit/e20eea84375b7f4bd3a15a80fce3bdbfcb327981)]:
12
+ - @cypress-design/icon-registry@0.1.0
package/Icon.cy.tsx ADDED
@@ -0,0 +1,22 @@
1
+ import * as React from 'react';
2
+ import Icon, { IconObjectBookCode } from './index'
3
+ import { mount } from 'cypress/react';
4
+
5
+ describe('Icon', () => {
6
+ it('renders correctly', () => {
7
+ mount(<ul className="m-4">
8
+ <li className="flex items-center mb-3 px-2">
9
+ fillColor="red-100" - <IconObjectBookCode fillColor="red-100" className="ml-2" strokeColor="red-500" secondaryFillColor="indigo-100" secondaryStrokeColor="indigo-600"/>
10
+ </li>
11
+ <li className="flex items-center mb-3 px-2 bg-magenta-100">
12
+ fillColor="transparent" - <Icon name="arrow-outline-down" strokeColor="magenta-500" fillColor="transparent" className="ml-2" />
13
+ </li>
14
+ <li className="flex items-center px-2">
15
+ strokeColor="current" - <button className="flex gap-2 items-center m-2 bg-jade-400 hover:bg-jade-500 text-white py-1 px-2 rounded">
16
+ <Icon name="action-add-large" strokeColor="current" />
17
+ Add a new icon
18
+ </button>
19
+ </li>
20
+ </ul>)
21
+ })
22
+ })
@@ -0,0 +1,83 @@
1
+ import { ArgsTable, Canvas, Meta, Story, Description } from '@storybook/addon-docs'
2
+ import { iconsMetadata } from '@cypress-design/icon-registry';
3
+ import { version } from "./package.json";
4
+ import changelog from "./CHANGELOG.md";
5
+
6
+ import { Icon } from './Icon'
7
+
8
+ <h1>Icon<span className="text-lg font-normal"> - v{version}</span></h1>
9
+
10
+ <Meta
11
+ title="Icon"
12
+ component={Icon}
13
+ argTypes={{
14
+ name: {
15
+ control: { type: 'select' },
16
+ },
17
+ size: {
18
+ control: { type: 'select' },
19
+ },
20
+ strokeColor: {
21
+ control: { type: 'select' },
22
+ },
23
+ fillColor: {
24
+ control: { type: 'select' },
25
+ },
26
+ secondaryStrokeColor: {
27
+ control: { type: 'select' },
28
+ },
29
+ secondaryFillColor: {
30
+ control: { type: 'select' },
31
+ },
32
+ }}
33
+ parameters={{
34
+ design: {
35
+ type: "figma",
36
+ url: 'https://www.figma.com/file/1WJ3GVQyMV5e7xVxPg3yID/Design-System?node-id=864%3A11',
37
+ }
38
+ }}
39
+ />
40
+
41
+ <Canvas>
42
+ <Story name="Icon">
43
+ {(args) => {
44
+ const name = args.name ?? 'general-placeholder'
45
+ if(args.size && !iconsMetadata[name]?.availableSizes.includes(args.size)) {
46
+ return <p className="text-red-500 bg-red-50">Not available at this size</p>
47
+ }
48
+ return <Icon {...{...args, name }} className="m-2"/>
49
+ }}
50
+ </Story>
51
+ </Canvas>
52
+
53
+ <ArgsTable/>
54
+
55
+ ## Usage
56
+
57
+ The simple way using the Icon component
58
+
59
+ ```tsx
60
+ import { Icon } from '@cypress-design/react-icon'
61
+
62
+ export const MyButtonWithIcon = () => {
63
+ return (<button>
64
+ <Icon name="book" size="16" strokeColor="blue-600" fillColor="red-200" className="bg-red-100" />Read
65
+ </button>)
66
+ }
67
+ ```
68
+
69
+ The tree-shakable way (more optimized)
70
+
71
+ ```tsx
72
+ import { IconBook } from '@cypress-design/react-icon'
73
+
74
+ export const MyButtonWithIcon = () => {
75
+ return (<button>
76
+ <IconBook size="16" strokeColor="blue-600" fillColor="red-200" />
77
+ </button>)
78
+ }
79
+ ```
80
+
81
+ <Description>
82
+ {changelog.replace(/^# .+/, '## Changelog')}
83
+ </Description>
package/Icon.tsx ADDED
@@ -0,0 +1,53 @@
1
+ import * as React from 'react';
2
+ import type { FunctionComponent, SVGProps } from 'react';
3
+ import { compileIcon } from '@cypress-design/icon-registry';
4
+ import type { IconProps } from '@cypress-design/icon-registry';
5
+
6
+ type SVGPropsWithoutColorsOrSize = Omit<React.SVGProps<SVGSVGElement>, 'fill' | 'stroke' | 'fillColor' | 'strokeColor' | 'size' >
7
+
8
+ export const Icon: FunctionComponent<
9
+ IconProps & SVGPropsWithoutColorsOrSize
10
+ > = (props) => {
11
+ return React.createElement(
12
+ 'svg',
13
+ compileReactIconProperties(compileIcon(props))
14
+ );
15
+ };
16
+
17
+ export const compileReactIconProperties = ({
18
+ body,
19
+ compiledClasses,
20
+ size,
21
+ strokeColor,
22
+ fillColor,
23
+ secondaryStrokeColor,
24
+ secondaryFillColor,
25
+ ...attributes
26
+ }: {
27
+ body: string;
28
+ compiledClasses: string[];
29
+ size: string;
30
+ strokeColor?;
31
+ fillColor?;
32
+ secondaryStrokeColor?;
33
+ secondaryFillColor?;
34
+ } & SVGPropsWithoutColorsOrSize) => {
35
+ const componentProps = {
36
+ width: size,
37
+ height: size,
38
+ fill: 'none',
39
+ dangerouslySetInnerHTML: {
40
+ __html: body,
41
+ },
42
+ ...attributes, // add all standard attributes back to the svg tag
43
+ };
44
+ if (attributes.className) {
45
+ compiledClasses.push(attributes.className);
46
+ }
47
+ if (compiledClasses.length) {
48
+ componentProps.className = compiledClasses.join(' ');
49
+ }
50
+ return componentProps;
51
+ };
52
+
53
+ export default Icon;
package/ReadMe.md ADDED
@@ -0,0 +1,50 @@
1
+ # Icon
2
+
3
+ ## Usage
4
+
5
+ The simple way using the Icon component
6
+
7
+ ```tsx
8
+ import { Icon } from '@cypress-design/react-icon';
9
+
10
+ export const MyButtonWithIcon = () => {
11
+ return (
12
+ <button>
13
+ <Icon
14
+ name="book"
15
+ size="16"
16
+ strokeColor="blue-600"
17
+ fillColor="red-200"
18
+ className="bg-red-100"
19
+ />
20
+ Read
21
+ </button>
22
+ );
23
+ };
24
+ ```
25
+
26
+ The tree-shakable way (more optimized)
27
+
28
+ ```tsx
29
+ import { IconBook } from '@cypress-design/react-icon';
30
+
31
+ export const MyButtonWithIcon = () => {
32
+ return (
33
+ <button>
34
+ <IconBook size="16" strokeColor="blue-600" fillColor="red-200" />
35
+ </button>
36
+ );
37
+ };
38
+ ```
39
+
40
+ ## install
41
+
42
+ ```bash
43
+ npm install @cypress-design/react-icon
44
+ ```
45
+
46
+ or with yarn
47
+
48
+ ```bash
49
+ yarn add @cypress-design/react-icon
50
+ ```
@@ -0,0 +1,35 @@
1
+ export const compileReactIconProperties = ({
2
+ body,
3
+ compiledClasses,
4
+ size,
5
+ strokeColor,
6
+ fillColor,
7
+ secondaryStrokeColor,
8
+ secondaryFillColor,
9
+ ...attributes
10
+ }: {
11
+ body: string;
12
+ compiledClasses: string[];
13
+ size: string;
14
+ strokeColor?;
15
+ fillColor?;
16
+ secondaryStrokeColor?;
17
+ secondaryFillColor?;
18
+ } & React.SVGProps<SVGSVGElement>) => {
19
+ const componentProps: any = {
20
+ width: size,
21
+ height: size,
22
+ fill: 'none',
23
+ dangerouslySetInnerHTML: {
24
+ __html: body,
25
+ },
26
+ ...attributes, // add all standard attributes back to the svg tag
27
+ };
28
+ if (attributes.className) {
29
+ compiledClasses.push(attributes.className);
30
+ }
31
+ if (compiledClasses.length) {
32
+ componentProps.className = compiledClasses.join(' ');
33
+ }
34
+ return componentProps;
35
+ };