@zohodesk/icons 1.3.1 → 1.3.2

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/README.md CHANGED
@@ -2,11 +2,14 @@
2
2
 
3
3
  In this GiftBox we Provide FontIcons
4
4
 
5
+ # 1.3.2
6
+
7
+ - Introduced SvgIcon, IconContext, and IconProvider to enable centralized control of SvgIcon behavior through IconProvider.
5
8
 
6
9
  # 1.3.1
7
10
 
8
11
  - ReactTicketsFontIcon --> ZD-TK-sideChat icon included.
9
- - ReactAutomationIcon --> ZD-TK-sideChat icon included.
12
+ - ReactAutomationIcon --> ZD-AU-skip, ZD-AU-scheduleDelay, ZD-AU-reschedule, ZD-AU-nodeRemove and ZD-AU-failure icons included.
10
13
 
11
14
  # 1.3.0
12
15
 
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ const IconContext = /*#__PURE__*/React.createContext({
3
+ type: 'fontIcon',
4
+ svgIconPrefix: '#',
5
+ svgIconClass: ''
6
+ });
7
+ export default IconContext;
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import IconContext from "./IconContext";
3
+ import { IconProviderProps } from "./props/propTypes";
4
+ import { IconProviderDefaultProps } from "./props/defaultProps";
5
+ export default function IconProvider(props) {
6
+ let {
7
+ type,
8
+ svgIconPrefix,
9
+ svgIconClass,
10
+ children
11
+ } = props;
12
+ const value = React.useMemo(() => ({
13
+ type,
14
+ svgIconPrefix,
15
+ svgIconClass
16
+ }), [type, svgIconPrefix, svgIconClass]);
17
+ return /*#__PURE__*/React.createElement(IconContext.Provider, {
18
+ value: value
19
+ }, children);
20
+ }
21
+ IconProvider.propTypes = IconProviderProps;
22
+ IconProvider.defaultProps = IconProviderDefaultProps;
@@ -0,0 +1,115 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import Icon from "../../Icon";
4
+ import IconProvider from "../IconProvider";
5
+ describe('IconProvider / IconContext - ', () => {
6
+ test('default context - renders font icon (no provider)', () => {
7
+ const {
8
+ asFragment
9
+ } = render( /*#__PURE__*/React.createElement(Icon, {
10
+ name: "ZD-close2"
11
+ }));
12
+ expect(asFragment()).toMatchSnapshot();
13
+ });
14
+ test('type "fontIcon" - renders font icon', () => {
15
+ const {
16
+ asFragment
17
+ } = render( /*#__PURE__*/React.createElement(IconProvider, {
18
+ type: "fontIcon"
19
+ }, /*#__PURE__*/React.createElement(Icon, {
20
+ name: "ZD-close2"
21
+ })));
22
+ expect(asFragment()).toMatchSnapshot();
23
+ });
24
+ test('type "svgIcon" - renders svg symbol', () => {
25
+ const {
26
+ asFragment
27
+ } = render( /*#__PURE__*/React.createElement(IconProvider, {
28
+ type: "svgIcon"
29
+ }, /*#__PURE__*/React.createElement(Icon, {
30
+ name: "ZD-close2"
31
+ })));
32
+ expect(asFragment()).toMatchSnapshot();
33
+ });
34
+ test('type "svgIcon" with custom "svgIconPrefix"', () => {
35
+ const {
36
+ asFragment
37
+ } = render( /*#__PURE__*/React.createElement(IconProvider, {
38
+ type: "svgIcon",
39
+ svgIconPrefix: "/sprites.svg#"
40
+ }, /*#__PURE__*/React.createElement(Icon, {
41
+ name: "ZD-close2"
42
+ })));
43
+ expect(asFragment()).toMatchSnapshot();
44
+ });
45
+ test('type "svgIcon" with "svgIconClass"', () => {
46
+ const {
47
+ asFragment
48
+ } = render( /*#__PURE__*/React.createElement(IconProvider, {
49
+ type: "svgIcon",
50
+ svgIconClass: "app-svg-icon"
51
+ }, /*#__PURE__*/React.createElement(Icon, {
52
+ name: "ZD-close2"
53
+ })));
54
+ expect(asFragment()).toMatchSnapshot();
55
+ });
56
+ test('type "svgIcon" - passes "size" prop to svg', () => {
57
+ const {
58
+ asFragment
59
+ } = render( /*#__PURE__*/React.createElement(IconProvider, {
60
+ type: "svgIcon"
61
+ }, /*#__PURE__*/React.createElement(Icon, {
62
+ name: "ZD-close2",
63
+ size: "20"
64
+ })));
65
+ expect(asFragment()).toMatchSnapshot();
66
+ });
67
+ test('type "svgIcon" - passes "title" prop to svg', () => {
68
+ const {
69
+ asFragment
70
+ } = render( /*#__PURE__*/React.createElement(IconProvider, {
71
+ type: "svgIcon"
72
+ }, /*#__PURE__*/React.createElement(Icon, {
73
+ name: "ZD-close2",
74
+ title: "Close"
75
+ })));
76
+ expect(asFragment()).toMatchSnapshot();
77
+ });
78
+ test('type "svgIcon" - passes "iconClass" prop to svg', () => {
79
+ const {
80
+ asFragment
81
+ } = render( /*#__PURE__*/React.createElement(IconProvider, {
82
+ type: "svgIcon"
83
+ }, /*#__PURE__*/React.createElement(Icon, {
84
+ name: "ZD-close2",
85
+ iconClass: "custom-class"
86
+ })));
87
+ expect(asFragment()).toMatchSnapshot();
88
+ });
89
+ test('type "svgIcon" - passes "a11y" ariaHidden false', () => {
90
+ const {
91
+ asFragment
92
+ } = render( /*#__PURE__*/React.createElement(IconProvider, {
93
+ type: "svgIcon"
94
+ }, /*#__PURE__*/React.createElement(Icon, {
95
+ name: "ZD-close2",
96
+ a11y: {
97
+ ariaHidden: false
98
+ }
99
+ })));
100
+ expect(asFragment()).toMatchSnapshot();
101
+ });
102
+ test('multiple icons share the same provider context', () => {
103
+ const {
104
+ asFragment
105
+ } = render( /*#__PURE__*/React.createElement(IconProvider, {
106
+ type: "svgIcon",
107
+ svgIconPrefix: "#"
108
+ }, /*#__PURE__*/React.createElement(Icon, {
109
+ name: "ZD-close2"
110
+ }), /*#__PURE__*/React.createElement(Icon, {
111
+ name: "ZD-addAccount"
112
+ })));
113
+ expect(asFragment()).toMatchSnapshot();
114
+ });
115
+ });
@@ -0,0 +1,166 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`IconProvider / IconContext - default context - renders font icon (no provider) 1`] = `
4
+ <DocumentFragment>
5
+ <i
6
+ aria-hidden="true"
7
+ class="zd_font_icons basic icon-close2 "
8
+ data-id="fontIcon"
9
+ data-selector-id="fontIcon"
10
+ data-test-id="fontIcon"
11
+ />
12
+ </DocumentFragment>
13
+ `;
14
+
15
+ exports[`IconProvider / IconContext - multiple icons share the same provider context 1`] = `
16
+ <DocumentFragment>
17
+ <svg
18
+ aria-hidden="true"
19
+ class="svgIcon "
20
+ data-id="fontIcon"
21
+ data-selector-id="fontIcon"
22
+ data-test-id="fontIcon"
23
+ >
24
+ <use
25
+ href="#ZD-close2"
26
+ />
27
+ </svg>
28
+ <svg
29
+ aria-hidden="true"
30
+ class="svgIcon "
31
+ data-id="fontIcon"
32
+ data-selector-id="fontIcon"
33
+ data-test-id="fontIcon"
34
+ >
35
+ <use
36
+ href="#ZD-addAccount"
37
+ />
38
+ </svg>
39
+ </DocumentFragment>
40
+ `;
41
+
42
+ exports[`IconProvider / IconContext - type "fontIcon" - renders font icon 1`] = `
43
+ <DocumentFragment>
44
+ <i
45
+ aria-hidden="true"
46
+ class="zd_font_icons basic icon-close2 "
47
+ data-id="fontIcon"
48
+ data-selector-id="fontIcon"
49
+ data-test-id="fontIcon"
50
+ />
51
+ </DocumentFragment>
52
+ `;
53
+
54
+ exports[`IconProvider / IconContext - type "svgIcon" - passes "a11y" ariaHidden false 1`] = `
55
+ <DocumentFragment>
56
+ <svg
57
+ aria-hidden="false"
58
+ class="svgIcon "
59
+ data-id="fontIcon"
60
+ data-selector-id="fontIcon"
61
+ data-test-id="fontIcon"
62
+ >
63
+ <use
64
+ href="#ZD-close2"
65
+ />
66
+ </svg>
67
+ </DocumentFragment>
68
+ `;
69
+
70
+ exports[`IconProvider / IconContext - type "svgIcon" - passes "iconClass" prop to svg 1`] = `
71
+ <DocumentFragment>
72
+ <svg
73
+ aria-hidden="true"
74
+ class="svgIcon custom-class "
75
+ data-id="fontIcon"
76
+ data-selector-id="fontIcon"
77
+ data-test-id="fontIcon"
78
+ >
79
+ <use
80
+ href="#ZD-close2"
81
+ />
82
+ </svg>
83
+ </DocumentFragment>
84
+ `;
85
+
86
+ exports[`IconProvider / IconContext - type "svgIcon" - passes "size" prop to svg 1`] = `
87
+ <DocumentFragment>
88
+ <svg
89
+ aria-hidden="true"
90
+ class="svgIcon "
91
+ data-id="fontIcon"
92
+ data-selector-id="fontIcon"
93
+ data-test-id="fontIcon"
94
+ style="--zd-iconfont-size: var(--zd_font_size20);"
95
+ >
96
+ <use
97
+ href="#ZD-close2"
98
+ />
99
+ </svg>
100
+ </DocumentFragment>
101
+ `;
102
+
103
+ exports[`IconProvider / IconContext - type "svgIcon" - passes "title" prop to svg 1`] = `
104
+ <DocumentFragment>
105
+ <svg
106
+ aria-hidden="true"
107
+ class="svgIcon "
108
+ data-id="fontIcon"
109
+ data-selector-id="fontIcon"
110
+ data-test-id="fontIcon"
111
+ data-title="Close"
112
+ >
113
+ <use
114
+ href="#ZD-close2"
115
+ />
116
+ </svg>
117
+ </DocumentFragment>
118
+ `;
119
+
120
+ exports[`IconProvider / IconContext - type "svgIcon" - renders svg symbol 1`] = `
121
+ <DocumentFragment>
122
+ <svg
123
+ aria-hidden="true"
124
+ class="svgIcon "
125
+ data-id="fontIcon"
126
+ data-selector-id="fontIcon"
127
+ data-test-id="fontIcon"
128
+ >
129
+ <use
130
+ href="#ZD-close2"
131
+ />
132
+ </svg>
133
+ </DocumentFragment>
134
+ `;
135
+
136
+ exports[`IconProvider / IconContext - type "svgIcon" with "svgIconClass" 1`] = `
137
+ <DocumentFragment>
138
+ <svg
139
+ aria-hidden="true"
140
+ class="svgIcon app-svg-icon "
141
+ data-id="fontIcon"
142
+ data-selector-id="fontIcon"
143
+ data-test-id="fontIcon"
144
+ >
145
+ <use
146
+ href="#ZD-close2"
147
+ />
148
+ </svg>
149
+ </DocumentFragment>
150
+ `;
151
+
152
+ exports[`IconProvider / IconContext - type "svgIcon" with custom "svgIconPrefix" 1`] = `
153
+ <DocumentFragment>
154
+ <svg
155
+ aria-hidden="true"
156
+ class="svgIcon "
157
+ data-id="fontIcon"
158
+ data-selector-id="fontIcon"
159
+ data-test-id="fontIcon"
160
+ >
161
+ <use
162
+ href="/sprites.svg#ZD-close2"
163
+ />
164
+ </svg>
165
+ </DocumentFragment>
166
+ `;
@@ -0,0 +1,5 @@
1
+ export const IconProviderDefaultProps = {
2
+ type: 'fontIcon',
3
+ svgIconPrefix: '#',
4
+ svgIconClass: ''
5
+ };
@@ -0,0 +1,7 @@
1
+ import PropTypes from 'prop-types';
2
+ export const IconProviderProps = {
3
+ type: PropTypes.oneOf(['fontIcon', 'svgIcon']),
4
+ svgIconPrefix: PropTypes.string,
5
+ svgIconClass: PropTypes.string,
6
+ children: PropTypes.node.isRequired
7
+ };
@@ -65,11 +65,4 @@ export default class FontIcon extends React.Component {
65
65
 
66
66
  }
67
67
  FontIcon.propTypes = IconProps;
68
- FontIcon.defaultProps = IconDefaultProps;
69
-
70
- if (__DOCS__) {
71
- FontIcon.docs = {
72
- componentGroup: 'Icon',
73
- folderName: 'Style Guide'
74
- };
75
- }
68
+ FontIcon.defaultProps = IconDefaultProps;
@@ -18,6 +18,12 @@
18
18
  word-break: initial;
19
19
  }
20
20
 
21
+ .svgIcon{
22
+ height:1em;
23
+ width:1em;
24
+ font-size: var(--zd-iconfont-size, inherit);
25
+ }
26
+
21
27
  .fbold {
22
28
  font-weight: bold;
23
29
  }
@@ -0,0 +1,45 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React from 'react';
4
+ import { SvgIconDefaultProps } from "./props/defaultProps";
5
+ import { SvgIconProps } from "./props/propTypes";
6
+ import { DUMMY_OBJECT } from '@zohodesk/dotkit/es/utils/constants';
7
+ import style from "./Icon.module.css";
8
+ export default function SvgIcon(_ref) {
9
+ let {
10
+ name,
11
+ onClick,
12
+ title,
13
+ dataId,
14
+ dataSelectorId,
15
+ size,
16
+ iconClass,
17
+ titlePosition,
18
+ tagAttributes,
19
+ a11y,
20
+ svgPrefix
21
+ } = _ref;
22
+ let {
23
+ ariaHidden = true
24
+ } = a11y;
25
+ let href = `${svgPrefix}${name}`;
26
+ let fontStyle = size ? {
27
+ '--zd-iconfont-size': 'var(--zd_font_size' + size + ')'
28
+ } : DUMMY_OBJECT;
29
+ let className = `${style.svgIcon} ${iconClass ? iconClass : ''} ${onClick ? style.cursor : ''}`;
30
+ return /*#__PURE__*/React.createElement("svg", _extends({
31
+ className: className,
32
+ onClick: onClick,
33
+ "data-title": title,
34
+ "data-id": dataId,
35
+ "data-test-id": dataId,
36
+ "data-selector-id": dataSelectorId,
37
+ "data-title-position": titlePosition,
38
+ style: fontStyle,
39
+ "aria-hidden": ariaHidden
40
+ }, tagAttributes), /*#__PURE__*/React.createElement("use", {
41
+ href: href
42
+ }));
43
+ }
44
+ SvgIcon.propTypes = SvgIconProps;
45
+ SvgIcon.defaultProps = SvgIconDefaultProps;
@@ -0,0 +1,94 @@
1
+ import React from 'react';
2
+ import SvgIcon from "../SvgIcon";
3
+ import { render } from '@testing-library/react';
4
+ describe('SvgIcon - ', () => {
5
+ test('rendering the "default" props', () => {
6
+ const {
7
+ asFragment
8
+ } = render( /*#__PURE__*/React.createElement(SvgIcon, null));
9
+ expect(asFragment()).toMatchSnapshot();
10
+ });
11
+ test('rendering with "name" and "svgPrefix"', () => {
12
+ const {
13
+ asFragment
14
+ } = render( /*#__PURE__*/React.createElement(SvgIcon, {
15
+ name: "ZD-close2",
16
+ svgPrefix: "#"
17
+ }));
18
+ expect(asFragment()).toMatchSnapshot();
19
+ });
20
+ test('rendering with external sprite "svgPrefix"', () => {
21
+ const {
22
+ asFragment
23
+ } = render( /*#__PURE__*/React.createElement(SvgIcon, {
24
+ name: "ZD-close2",
25
+ svgPrefix: "/sprites.svg#"
26
+ }));
27
+ expect(asFragment()).toMatchSnapshot();
28
+ });
29
+ test('rendering with "title"', () => {
30
+ const {
31
+ asFragment
32
+ } = render( /*#__PURE__*/React.createElement(SvgIcon, {
33
+ name: "ZD-close2",
34
+ svgPrefix: "#",
35
+ title: "Close"
36
+ }));
37
+ expect(asFragment()).toMatchSnapshot();
38
+ });
39
+ test('rendering with "size"', () => {
40
+ const {
41
+ asFragment
42
+ } = render( /*#__PURE__*/React.createElement(SvgIcon, {
43
+ name: "ZD-close2",
44
+ svgPrefix: "#",
45
+ size: "15"
46
+ }));
47
+ expect(asFragment()).toMatchSnapshot();
48
+ });
49
+ test('rendering with "iconClass"', () => {
50
+ const {
51
+ asFragment
52
+ } = render( /*#__PURE__*/React.createElement(SvgIcon, {
53
+ name: "ZD-close2",
54
+ svgPrefix: "#",
55
+ iconClass: "myIconClass"
56
+ }));
57
+ expect(asFragment()).toMatchSnapshot();
58
+ });
59
+ test('rendering with "ariaHidden" false', () => {
60
+ const {
61
+ asFragment
62
+ } = render( /*#__PURE__*/React.createElement(SvgIcon, {
63
+ name: "ZD-close2",
64
+ svgPrefix: "#",
65
+ a11y: {
66
+ ariaHidden: false
67
+ }
68
+ }));
69
+ expect(asFragment()).toMatchSnapshot();
70
+ });
71
+ const titlePositions = ['top', 'bottom', 'left', 'right'];
72
+ test.each(titlePositions)('rendering with "titlePosition" - %s', titlePosition => {
73
+ const {
74
+ asFragment
75
+ } = render( /*#__PURE__*/React.createElement(SvgIcon, {
76
+ name: "ZD-close2",
77
+ svgPrefix: "#",
78
+ titlePosition: titlePosition
79
+ }));
80
+ expect(asFragment()).toMatchSnapshot();
81
+ });
82
+ test('rendering with "tagAttributes"', () => {
83
+ const {
84
+ asFragment
85
+ } = render( /*#__PURE__*/React.createElement(SvgIcon, {
86
+ name: "ZD-close2",
87
+ svgPrefix: "#",
88
+ tagAttributes: {
89
+ 'data-custom-attr': 'true'
90
+ }
91
+ }));
92
+ expect(asFragment()).toMatchSnapshot();
93
+ });
94
+ });