@cypress-design/react-icon 0.2.0 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,65 @@
1
1
  # @cypress-design/react-icon
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#51](https://github.com/cypress-io/cypress-design/pull/51) [`ccd8f9a`](https://github.com/cypress-io/cypress-design/commit/ccd8f9a8feb624c0a52deaa9754c76969f43fc1e) Thanks [@elevatebart](https://github.com/elevatebart)! - in the build asset, add a comment containing all used windicss classes in the component
8
+
9
+ ### Patch Changes
10
+
11
+ - [#56](https://github.com/cypress-io/cypress-design/pull/56) [`0866c65`](https://github.com/cypress-io/cypress-design/commit/0866c654f24c36951c98468d789462748606b428) Thanks [@elevatebart](https://github.com/elevatebart)! - fix: avoid using `delete` to avoid memory leaks
12
+
13
+ * [#52](https://github.com/cypress-io/cypress-design/pull/52) [`43b53eb`](https://github.com/cypress-io/cypress-design/commit/43b53eb6bd10111629239a87374cfcc894eda0e3) Thanks [@mapsandapps](https://github.com/mapsandapps)! - New icons for statuses
14
+
15
+ * Updated dependencies [[`31aaa18`](https://github.com/cypress-io/cypress-design/commit/31aaa182c8cd415f2884289144f504183e5ab418), [`0866c65`](https://github.com/cypress-io/cypress-design/commit/0866c654f24c36951c98468d789462748606b428), [`43b53eb`](https://github.com/cypress-io/cypress-design/commit/43b53eb6bd10111629239a87374cfcc894eda0e3)]:
16
+ - @cypress-design/icon-registry@0.5.0
17
+
18
+ ## 0.3.0
19
+
20
+ ### Minor Changes
21
+
22
+ - [#41](https://github.com/cypress-io/cypress-design/pull/41) [`4259026`](https://github.com/cypress-io/cypress-design/commit/4259026314464260e89bcd88690c8a60ad2f0459) Thanks [@elevatebart](https://github.com/elevatebart)! - ## New syntaxes to add dynamic icon colors
23
+
24
+ ### With a prefix focus/hover
25
+
26
+ ```html
27
+ <IconBook
28
+ size="16"
29
+ strokeColor="blue-600"
30
+ hoverStrokeColor="jade-600"
31
+ focusStrokeColor="jade-900"
32
+ />
33
+ ```
34
+
35
+ ### With the same prefix acting on a group
36
+
37
+ ```html
38
+ <button class="group">
39
+ <IconBook
40
+ size="16"
41
+ strokeColor="blue-600"
42
+ hoverStrokeColor="jade-600"
43
+ focusStrokeColor="jade-900"
44
+ interactiveColorsOnGroup
45
+ />Read
46
+ </button>
47
+ ```
48
+
49
+ ### Patch Changes
50
+
51
+ - [#39](https://github.com/cypress-io/cypress-design/pull/39) [`1b383f3`](https://github.com/cypress-io/cypress-design/commit/1b383f3d149948bf2cc062d3baa17d5ce032f07e) Thanks [@elevatebart](https://github.com/elevatebart)! - fix file path of sourcemaps
52
+
53
+ - Updated dependencies [[`4259026`](https://github.com/cypress-io/cypress-design/commit/4259026314464260e89bcd88690c8a60ad2f0459)]:
54
+ - @cypress-design/icon-registry@0.4.0
55
+
56
+ ## 0.2.1
57
+
58
+ ### Patch Changes
59
+
60
+ - Updated dependencies [[`5f9cf10`](https://github.com/cypress-io/cypress-design/commit/5f9cf10ff4709fcd7d322c2dc5dbc676473b433e), [`69b3327`](https://github.com/cypress-io/cypress-design/commit/69b332757ba3b73d0ae881c5959daa7a2e644fe0)]:
61
+ - @cypress-design/icon-registry@0.3.0
62
+
3
63
  ## 0.2.0
4
64
 
5
65
  ### Minor Changes
package/Icon.stories.mdx CHANGED
@@ -50,7 +50,7 @@ import { Icon } from './Icon'
50
50
  </Story>
51
51
  </Canvas>
52
52
 
53
- <ArgsTable/>
53
+ <ArgsTable exclude={/^(hover|focus|hocus)/g} />
54
54
 
55
55
  ## Usage
56
56
 
@@ -73,7 +73,37 @@ import { IconBook } from '@cypress-design/react-icon'
73
73
 
74
74
  export const MyButtonWithIcon = () => {
75
75
  return (<button>
76
- <IconBook size="16" strokeColor="blue-600" fillColor="red-200" />
76
+ <IconBook size="16" strokeColor="indigo-600" fillColor="red-200" />
77
+ </button>)
78
+ }
79
+ ```
80
+
81
+ Should you need to change the color of the icon on `hover` or `focus` prefix the props with these words.
82
+
83
+ Here, the `strokeColor` will change on hover from indigo to jade
84
+
85
+ ```tsx
86
+ import { IconBook } from '@cypress-design/react-icon'
87
+
88
+ export const MyButtonWithIcon = () => {
89
+ return (<button>
90
+ <IconBook size="16" strokeColor="indigo-600" hoverStrokeColor="jade-600" />
91
+ </button>)
92
+ }
93
+ ```
94
+
95
+ If you need the `hover` or `focus` effect to be triggered on the parent group, use `interactiveColorsOnGroup`.
96
+ This prop will change all the pseudo prefixes to be group focused instead of triggered by the icon itself.
97
+
98
+ To achieve the same goal, in WindiCSS, we would use `group-hover:` instead of `hover:`.
99
+
100
+ ```tsx
101
+ import { IconBook } from '@cypress-design/react-icon'
102
+
103
+ export const MyButtonWithIcon = () => {
104
+ return (<button className="group hover:text-jade-800">
105
+ <IconBook size="16" strokeColor="indigo-600" hoverStrokeColor="jade-600" interactiveColorsOnGroup />
106
+ Book
77
107
  </button>)
78
108
  }
79
109
  ```
package/Icon.tsx CHANGED
@@ -1,9 +1,13 @@
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';
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
+ import { compileReactIconProperties } from './compileProperties'
5
6
 
6
- type SVGPropsWithoutColorsOrSize = Omit<React.SVGProps<SVGSVGElement>, 'fill' | 'stroke' | 'fillColor' | 'strokeColor' | 'size' >
7
+ type SVGPropsWithoutColorsOrSize = Omit<
8
+ SVGProps<SVGSVGElement>,
9
+ 'fill' | 'stroke' | 'fillColor' | 'strokeColor' | 'size'
10
+ >
7
11
 
8
12
  export const Icon: FunctionComponent<
9
13
  IconProps & SVGPropsWithoutColorsOrSize
@@ -11,43 +15,7 @@ export const Icon: FunctionComponent<
11
15
  return React.createElement(
12
16
  'svg',
13
17
  compileReactIconProperties(compileIcon(props))
14
- );
15
- };
18
+ )
19
+ }
16
20
 
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;
21
+ export default Icon
@@ -0,0 +1,38 @@
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(
8
+ <ul className="m-4">
9
+ <li className="flex items-center mb-3 px-2">
10
+ fillColor="red-100" -{' '}
11
+ <IconObjectBookCode
12
+ fillColor="red-100"
13
+ className="ml-2"
14
+ strokeColor="red-500"
15
+ secondaryFillColor="indigo-100"
16
+ secondaryStrokeColor="indigo-600"
17
+ />
18
+ </li>
19
+ <li className="flex items-center mb-3 px-2 bg-magenta-100">
20
+ fillColor="transparent" -{' '}
21
+ <Icon
22
+ name="arrow-outline-down"
23
+ strokeColor="magenta-500"
24
+ fillColor="transparent"
25
+ className="ml-2"
26
+ />
27
+ </li>
28
+ <li className="flex items-center px-2">
29
+ strokeColor="current" -{' '}
30
+ <button className="flex gap-2 items-center m-2 bg-jade-600 hover:bg-jade-800 text-white py-1 px-2 rounded">
31
+ <Icon name="action-add-large" strokeColor="current" />
32
+ Add a new icon
33
+ </button>
34
+ </li>
35
+ </ul>
36
+ )
37
+ })
38
+ })
package/ReadMe.md CHANGED
@@ -5,7 +5,7 @@
5
5
  The simple way using the Icon component
6
6
 
7
7
  ```tsx
8
- import { Icon } from '@cypress-design/react-icon';
8
+ import { Icon } from '@cypress-design/react-icon'
9
9
 
10
10
  export const MyButtonWithIcon = () => {
11
11
  return (
@@ -19,22 +19,65 @@ export const MyButtonWithIcon = () => {
19
19
  />
20
20
  Read
21
21
  </button>
22
- );
23
- };
22
+ )
23
+ }
24
24
  ```
25
25
 
26
26
  The tree-shakable way (more optimized)
27
27
 
28
28
  ```tsx
29
- import { IconBook } from '@cypress-design/react-icon';
29
+ import { IconBook } from '@cypress-design/react-icon'
30
30
 
31
31
  export const MyButtonWithIcon = () => {
32
32
  return (
33
33
  <button>
34
- <IconBook size="16" strokeColor="blue-600" fillColor="red-200" />
34
+ <IconBook size="16" strokeColor="indigo-600" fillColor="red-200" />
35
35
  </button>
36
- );
37
- };
36
+ )
37
+ }
38
+ ```
39
+
40
+ Should you need to change the color of the icon on `hover` or `focus` prefix the props with these words.
41
+
42
+ Here, the `strokeColor` will change on hover from indigo to jade
43
+
44
+ ```tsx
45
+ import { IconBook } from '@cypress-design/react-icon'
46
+
47
+ export const MyButtonWithIcon = () => {
48
+ return (
49
+ <button>
50
+ <IconBook
51
+ size="16"
52
+ strokeColor="indigo-600"
53
+ hoverStrokeColor="jade-600"
54
+ />
55
+ </button>
56
+ )
57
+ }
58
+ ```
59
+
60
+ If you need the `hover` or `focus` effect to be triggered on the parent group, use `interactiveColorsOnGroup`.
61
+ This prop will change all the pseudo prefixes to be group focused instead of triggered by the icon itself.
62
+
63
+ To achieve the same goal, in WindiCSS, we would use `group-hover:` instead of `hover:`.
64
+
65
+ ```tsx
66
+ import { IconBook } from '@cypress-design/react-icon'
67
+
68
+ export const MyButtonWithIcon = () => {
69
+ return (
70
+ <button className="group hover:text-jade-800">
71
+ <IconBook
72
+ size="16"
73
+ strokeColor="indigo-600"
74
+ hoverStrokeColor="jade-600"
75
+ interactiveColorsOnGroup
76
+ />
77
+ Book
78
+ </button>
79
+ )
80
+ }
38
81
  ```
39
82
 
40
83
  ## install
@@ -1,21 +1,27 @@
1
+ import type { ColorIconProps } from '@cypress-design/icon-registry'
2
+ import { ICON_COLOR_PROP_NAMES } from '@cypress-design/icon-registry'
3
+
1
4
  export const compileReactIconProperties = ({
2
5
  body,
3
6
  compiledClasses,
4
7
  size,
5
- strokeColor,
6
- fillColor,
7
- secondaryStrokeColor,
8
- secondaryFillColor,
9
8
  ...attributes
10
9
  }: {
11
- body: string;
12
- compiledClasses: string[];
13
- size: string;
14
- strokeColor?;
15
- fillColor?;
16
- secondaryStrokeColor?;
17
- secondaryFillColor?;
18
- } & React.SVGProps<SVGSVGElement>) => {
10
+ body: string
11
+ compiledClasses: string[]
12
+ size: string
13
+ } & ColorIconProps &
14
+ React.SVGProps<SVGSVGElement>) => {
15
+ const filteredAttributes = Object.keys(attributes).reduce(
16
+ (newAttributes, attrName) => {
17
+ if (!ICON_COLOR_PROP_NAMES.includes(attrName)) {
18
+ newAttributes[attrName] =
19
+ attributes[attrName as keyof typeof attributes]
20
+ }
21
+ return newAttributes
22
+ },
23
+ {} as Record<string, any>
24
+ )
19
25
  const componentProps: any = {
20
26
  width: size,
21
27
  height: size,
@@ -23,13 +29,13 @@ export const compileReactIconProperties = ({
23
29
  dangerouslySetInnerHTML: {
24
30
  __html: body,
25
31
  },
26
- ...attributes, // add all standard attributes back to the svg tag
27
- };
32
+ ...filteredAttributes, // add all standard attributes back to the svg tag
33
+ }
28
34
  if (attributes.className) {
29
- compiledClasses.push(attributes.className);
35
+ compiledClasses.push(attributes.className)
30
36
  }
31
37
  if (compiledClasses.length) {
32
- componentProps.className = compiledClasses.join(' ');
38
+ componentProps.className = compiledClasses.join(' ')
33
39
  }
34
- return componentProps;
35
- };
40
+ return componentProps
41
+ }