@zohodesk/components 1.0.0-alpha-244 → 1.0.0-alpha-247

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.
Files changed (31) hide show
  1. package/README.md +10 -0
  2. package/assets/Appearance/pureDark/mode/pureDarkMode.module.css +2 -2
  3. package/es/CheckBox/CheckBox.module.css +12 -8
  4. package/es/LightNightMode/Colors.json +496 -397
  5. package/es/LightNightMode/docs/AlternativeColors.docs.js +21 -1
  6. package/es/ListItem/ListItem.module.css +12 -8
  7. package/es/MultiSelect/AdvancedGroupMultiSelect.js +1 -1
  8. package/es/Radio/Radio.module.css +8 -6
  9. package/es/RippleEffect/RippleEffect.module.css +37 -15
  10. package/es/Switch/Switch.module.css +3 -2
  11. package/es/index.js +0 -4
  12. package/lib/CheckBox/CheckBox.module.css +12 -8
  13. package/lib/LightNightMode/Colors.json +496 -397
  14. package/lib/LightNightMode/docs/AlternativeColors.docs.js +23 -1
  15. package/lib/ListItem/ListItem.module.css +12 -8
  16. package/lib/MultiSelect/AdvancedGroupMultiSelect.js +1 -1
  17. package/lib/Radio/Radio.module.css +8 -6
  18. package/lib/RippleEffect/RippleEffect.module.css +37 -15
  19. package/lib/Switch/Switch.module.css +3 -2
  20. package/lib/index.js +0 -36
  21. package/package.json +5 -5
  22. package/es/a11y/FocusScope/FocusScope.js +0 -370
  23. package/es/a11y/FocusScope/docs/FocusScope__default.docs.js +0 -139
  24. package/es/beta/FocusRing/FocusRing.js +0 -281
  25. package/es/beta/FocusRing/FocusRing.module.css +0 -152
  26. package/es/beta/FocusRing/docs/FocusRing__default.docs.js +0 -48
  27. package/lib/a11y/FocusScope/FocusScope.js +0 -443
  28. package/lib/a11y/FocusScope/docs/FocusScope__default.docs.js +0 -191
  29. package/lib/beta/FocusRing/FocusRing.js +0 -338
  30. package/lib/beta/FocusRing/FocusRing.module.css +0 -152
  31. package/lib/beta/FocusRing/docs/FocusRing__default.docs.js +0 -101
@@ -1,139 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import FocusScope, { useFocusManager } from '../FocusScope';
4
- import style from '../../../beta/FocusRing/FocusRing.module.css';
5
- export default class FocusScope__default extends React.Component {
6
- constructor(props) {
7
- super(props);
8
- this.state = {
9
- isOpen: false,
10
- isSub: false
11
- };
12
- this.handleSubmit = this.handleSubmit.bind(this);
13
- }
14
-
15
- handleSubmit(e, issub) {
16
- this.setState({
17
- isSub: issub,
18
- isOpen: e
19
- });
20
- }
21
-
22
- render() {
23
- const {
24
- isOpen,
25
- isSub
26
- } = this.state;
27
- console.log(this.state);
28
- return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("button", {
29
- className: style.primary,
30
- type: "button",
31
- onClick: this.handleSubmit.bind(this, true, false)
32
- }, "Focusscope"), isOpen ? /*#__PURE__*/React.createElement("div", {
33
- className: style.freezeLayer
34
- }, /*#__PURE__*/React.createElement(FocusScope, {
35
- contain: true,
36
- autoFocus: true,
37
- restoreFocus: true
38
- }, /*#__PURE__*/React.createElement(FormContainer, {
39
- onSubmit: this.handleSubmit.bind(this, true, true),
40
- onCancel: this.handleSubmit.bind(this, false, false)
41
- }), isSub ? /*#__PURE__*/React.createElement(FocusScope, {
42
- contain: true,
43
- restoreFocus: true,
44
- autoFocus: true
45
- }, /*#__PURE__*/React.createElement("span", {
46
- className: `${style.container} ${isSub && style.box1} ${isSub && style.manage}`
47
- }, /*#__PURE__*/React.createElement(ToolbarButton, null, "Cut"), /*#__PURE__*/React.createElement(ToolbarButton, null, "Copy"), /*#__PURE__*/React.createElement(ToolbarButton, null, "Paste"), /*#__PURE__*/React.createElement(ToolbarButton, {
48
- onClick: this.handleSubmit.bind(this, true, false)
49
- }, "Close"))) : null)) : null);
50
- }
51
-
52
- }
53
-
54
- function ToolbarButton(props) {
55
- const focusManager = useFocusManager();
56
-
57
- const onKeyDown = e => {
58
- switch (e.key) {
59
- case 'ArrowRight':
60
- focusManager.focusNext({
61
- wrap: true
62
- });
63
- break;
64
-
65
- case 'ArrowLeft':
66
- focusManager.focusPrevious({
67
- wrap: true
68
- });
69
- break;
70
-
71
- default:
72
- }
73
- };
74
-
75
- const {
76
- onClick,
77
- children
78
- } = props;
79
- return /*#__PURE__*/React.createElement("button", {
80
- className: style.primary,
81
- type: "button",
82
- onClick: onClick,
83
- onKeyDown: onKeyDown
84
- }, children);
85
- }
86
-
87
- ToolbarButton.propTypes = {
88
- children: PropTypes.string.isRequired,
89
- onClick: PropTypes.func
90
- };
91
-
92
- function FormContainer(props) {
93
- const {
94
- onSubmit,
95
- onCancel
96
- } = props;
97
- const options = ['apple', 'MSoffice'];
98
- return /*#__PURE__*/React.createElement("div", {
99
- className: `${style.container} ${style.box1}`
100
- }, /*#__PURE__*/React.createElement("button", {
101
- className: style.secondary,
102
- type: "button",
103
- onClick: onCancel
104
- }, "close"), /*#__PURE__*/React.createElement("form", {
105
- className: style.formContainer
106
- }, /*#__PURE__*/React.createElement("h3", null, "name"), /*#__PURE__*/React.createElement("input", {
107
- type: "text",
108
- value: "Input A",
109
- className: `${style.input} ${style.inpFocus}`,
110
- name: "name"
111
- }), /*#__PURE__*/React.createElement("h3", null, "contact"), /*#__PURE__*/React.createElement("input", {
112
- type: "text",
113
- value: "Input A",
114
- className: `${style.input} ${style.inpFocus}`,
115
- name: "contact"
116
- }), /*#__PURE__*/React.createElement("h3", null, "select"), /*#__PURE__*/React.createElement("select", {
117
- options: options,
118
- name: "select",
119
- className: `${style.input} ${style.inpFocus}`
120
- }, options.map((item, i) => /*#__PURE__*/React.createElement("option", {
121
- key: `item-${i}`
122
- }, item)))), /*#__PURE__*/React.createElement("button", {
123
- className: style.primary,
124
- type: "submit",
125
- onClick: onSubmit
126
- }, "Submit"), /*#__PURE__*/React.createElement("button", {
127
- className: style.secondary,
128
- type: "button",
129
- onClick: onCancel
130
- }, "Cancel"));
131
- }
132
-
133
- FormContainer.propTypes = {
134
- onCancel: PropTypes.func,
135
- onSubmit: PropTypes.func
136
- };
137
- FocusScope__default.docs = {
138
- componentGroup: 'Atom'
139
- };
@@ -1,281 +0,0 @@
1
- import React, { useState, useRef, useEffect } from 'react';
2
- const eventFrom = 'keyboard' | 'pointer' | 'virtual';
3
- const eventType = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent; //const eventHandler = (evType=eventFrom, e=eventType) => {return eventFrom}
4
-
5
- let currentEventType = null;
6
- let changeHandlers = new Set();
7
- let hasSetupGlobalListeners = false;
8
- let hasEventBeforeFocus = false; // let onFocusWithin= props.onFocusWithin?props.onFocusWithin:(e)=>{return void};
9
- // let onBlurWithin = props.onBlurWithin?props.onBlurWithin:(e) =>void
10
- // eventHandler that is called when the the focus within state changes.
11
- // onFocusWithinChange(isFocusWithin)=> void
12
- // Only Tab or Esc keys will make focus visible on text input elements
13
-
14
- const FOCUS_VISIBLE_INPUT_KEYS = {
15
- Tab: true,
16
- Escape: false
17
- };
18
-
19
- function triggerChangeHandlers() {
20
- let evType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : eventFrom;
21
- let e = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : eventType;
22
-
23
- for (let handler of changeHandlers) {
24
- handler(evType, e);
25
- }
26
- } //Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus styles visible.
27
-
28
-
29
- function isValidKey(e) {
30
- return !(e.metaKey || e.altKey || e.ctrlKey);
31
- }
32
-
33
- function handleKeyboardEvent(e) {
34
- hasEventBeforeFocus = true;
35
-
36
- if (isValidKey(e)) {
37
- currentEventType = 'keyboard';
38
- triggerChangeHandlers('keyboard', e);
39
- }
40
- }
41
-
42
- function handlePointerEvent(e) {
43
- currentEventType = 'pointer';
44
-
45
- if (e.type === 'mousedown' || e.type === 'pointerdown') {
46
- hasEventBeforeFocus = true;
47
- triggerChangeHandlers('pointer', e);
48
- }
49
- }
50
-
51
- function handleFocusEvent(e) {
52
- // Firefox fires two extra focus events when the user first clicks into an iframe:
53
- // first on the window, then on the document. We ignore these events so they don't
54
- // cause keyboard focus rings to appear.
55
- if (e.target === window || e.target === document) {
56
- return;
57
- } // If a focus event occurs without a preceding keyboard or pointer event, switch to keyboard evType.
58
- // This occurs, for example, when navigating a form with the next/previous buttons on iOS.
59
-
60
-
61
- if (!hasEventBeforeFocus) {
62
- currentEventType = 'keyboard';
63
- triggerChangeHandlers('keyboard', e);
64
- }
65
-
66
- hasEventBeforeFocus = false;
67
- }
68
-
69
- function handleWindowBlur() {
70
- // When the window is blurred, reset state. This is necessary when tabbing out of the window,
71
- // for example, since a subsequent focus event won't be fired.
72
- hasEventBeforeFocus = false;
73
- }
74
-
75
- function setupGlobalFocusEvents() {
76
- if (typeof window === 'undefined' || hasSetupGlobalListeners) {
77
- return;
78
- } // Programmatic focus() calls shouldn't affect the current input evType.
79
- // However, we need to detect other cases when a focus event occurs without
80
- // a preceding user event (e.g. screen reader focus). Overriding the focus
81
- // method on HTMLElement.prototype is a bit hacky, but works.
82
-
83
-
84
- let focus = HTMLElement.prototype.focus;
85
-
86
- HTMLElement.prototype.focus = function () {
87
- hasEventBeforeFocus = true;
88
- focus.apply(this, arguments);
89
- };
90
-
91
- document.addEventListener('keydown', handleKeyboardEvent, true);
92
- document.addEventListener('keyup', handleKeyboardEvent, true); // Register focus events on the window so they are sure to happen
93
- // before React's event listeners (registered on the document).
94
-
95
- window.addEventListener('focus', handleFocusEvent, true);
96
- window.addEventListener('blur', handleWindowBlur, false);
97
-
98
- if (typeof PointerEvent !== 'undefined') {
99
- document.addEventListener('pointerdown', handlePointerEvent, true);
100
- document.addEventListener('pointermove', handlePointerEvent, true);
101
- document.addEventListener('pointerup', handlePointerEvent, true);
102
- } else {
103
- document.addEventListener('mousedown', handlePointerEvent, true);
104
- document.addEventListener('mousemove', handlePointerEvent, true);
105
- document.addEventListener('mouseup', handlePointerEvent, true);
106
- }
107
-
108
- hasSetupGlobalListeners = true;
109
- }
110
-
111
- function isFocusVisible() {
112
- return currentEventType !== 'pointer';
113
- }
114
-
115
- function useFocusVisible(props) {
116
- setupGlobalFocusEvents();
117
- let [isFocusVisibleState, setFocusVisible] = useState(isFocusVisible());
118
- useEffect(() => {
119
- let handler = (evType, e) => {
120
- // If this is a text input component, don't update the focus visible style when
121
- // typing except for when the Tab and Escape keys are pressed.
122
- if (evType === 'keyboard' && e instanceof KeyboardEvent && !FOCUS_VISIBLE_INPUT_KEYS[e.key]) {
123
- return;
124
- }
125
-
126
- setFocusVisible(isFocusVisible());
127
- };
128
-
129
- changeHandlers.add(handler);
130
- return () => {
131
- changeHandlers.delete(handler);
132
- };
133
- });
134
- return {
135
- isFocusVisible: isFocusVisibleState
136
- };
137
- } //If true, keyboard focus is visible.
138
-
139
-
140
- function useFocusWithin(props) {
141
- let state = useRef({
142
- isFocusWithin: false
143
- }).current;
144
-
145
- if (props.isDisabled) {
146
- return {
147
- focusWithinProps: {}
148
- };
149
- }
150
-
151
- let onFocus = e => {
152
- if (!state.isFocusWithin) {
153
- if (props.onFocusWithin) {
154
- props.onFocusWithin(e);
155
- }
156
-
157
- if (props.onFocusWithinChange) {
158
- props.onFocusWithinChange(true);
159
- }
160
-
161
- state.isFocusWithin = true;
162
- }
163
- };
164
-
165
- let onBlur = e => {
166
- // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
167
- // when moving focus inside the element. Only trigger if the currentTarget doesn't
168
- // include the relatedTarget (where focus is moving).
169
- if (state.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
170
- if (props.onBlurWithin) {
171
- props.onBlurWithin(e);
172
- }
173
-
174
- if (props.onFocusWithinChange) {
175
- props.onFocusWithinChange(false);
176
- }
177
-
178
- state.isFocusWithin = false;
179
- }
180
- };
181
-
182
- return {
183
- focusWithinProps: {
184
- onFocus: onFocus,
185
- onBlur: onBlur
186
- }
187
- };
188
- }
189
-
190
- function useFocus(props) {
191
- if (props.isDisabled) {
192
- return {
193
- focusProps: {}
194
- };
195
- }
196
-
197
- let onFocus, onBlur;
198
-
199
- if (props.onFocus || props.onFocusChange) {
200
- onFocus = e => {
201
- if (e.target === e.currentTarget) {
202
- if (props.onFocus) {
203
- props.onFocus(e);
204
- }
205
-
206
- if (props.onFocusChange) {
207
- props.onFocusChange(true);
208
- }
209
- }
210
- };
211
- }
212
-
213
- if (props.onBlur || props.onFocusChange) {
214
- onBlur = e => {
215
- if (e.target === e.currentTarget) {
216
- if (props.onBlur) {
217
- props.onBlur(e);
218
- }
219
-
220
- if (props.onFocusChange) {
221
- props.onFocusChange(false);
222
- }
223
- }
224
- };
225
- }
226
-
227
- return {
228
- focusProps: {
229
- onFocus,
230
- onBlur
231
- }
232
- };
233
- }
234
-
235
- function useFocusRing(props) {
236
- let {
237
- within
238
- } = props;
239
- let [isFocused, setFocused] = useState(false);
240
- let [isFocusWithin, setFocusWithin] = useState(false);
241
- let {
242
- isFocusVisible
243
- } = useFocusVisible(props);
244
- let {
245
- focusProps
246
- } = useFocus({
247
- isDisabled: within,
248
- onFocusChange: setFocused
249
- });
250
- let {
251
- focusWithinProps
252
- } = useFocusWithin({
253
- isDisabled: !within,
254
- onFocusWithinChange: setFocusWithin
255
- });
256
- return {
257
- isFocused: within ? isFocusWithin : isFocused,
258
- isFocusVisible: (within ? isFocusWithin : isFocused) && isFocusVisible,
259
- focusProps: within ? focusWithinProps : focusProps
260
- };
261
- }
262
-
263
- export default function FocusRing(props) {
264
- let {
265
- children,
266
- focusClass,
267
- focusRingClass
268
- } = props;
269
- let {
270
- isFocused,
271
- isFocusVisible,
272
- focusProps
273
- } = useFocusRing(props);
274
- let child = React.Children.only(children);
275
- return /*#__PURE__*/React.cloneElement(child, { ...focusProps,
276
- customClass: isFocusVisible ? focusRingClass : isFocused ? focusClass : ''
277
- });
278
- }
279
- FocusRing.docs = {
280
- componentGroup: 'Atom'
281
- };
@@ -1,152 +0,0 @@
1
- .input{
2
- width:100%;
3
- outline: 0;
4
- border: 1px;
5
- border-bottom: 1px solid #ddd
6
- }
7
- .badFocus {
8
- display: inline-block;
9
- margin-top: 10px;
10
- border-radius: 2px;
11
- box-shadow: 0 0 0 4px rgba(20,20,20,0.15);
12
- margin-bottom: 30px;
13
- padding: 2px;
14
- margin: 10px;
15
- }
16
- [dir=ltr] .badFocus {
17
- margin-right: 5px;
18
- }
19
- [dir=rtl] .badFocus {
20
- margin-left: 5px;
21
- }
22
- :focus{
23
- outline: 0;
24
- }
25
- .goodFocus {
26
- display: inline-block;
27
- border-radius: 2px;
28
- padding: 2px;
29
- box-shadow: 0 0 0 4px rgba(91,147,255,0.25);
30
- }
31
- .inpFocus{
32
- width: auto;
33
- padding: 5px;
34
- border-radius: 2px;
35
- margin: 10px;
36
- }
37
- .mouseFocus, .inpFocus:focus{
38
- box-shadow: 0 0 0 4px rgba(20,20,20,0.15);
39
- }
40
- .tabFocus, .tabFocus:focus{
41
- box-shadow: 0 0 0 4px rgba(24, 91, 226, 0.25);
42
- }
43
- .freezeLayer{
44
- position: fixed;
45
- top:0;
46
- bottom: 0;
47
- display: flex;
48
- justify-content: center;
49
- align-items: center;
50
- background-color: rgba(20,20,20,.5);
51
- }
52
- [dir=ltr] .freezeLayer{
53
- left:0;
54
- right: 0;
55
- }
56
- [dir=rtl] .freezeLayer{
57
- right:0;
58
- left: 0;
59
- }
60
- [dir=ltr] .element{
61
- margin:1rem 0 1rem .5rem;
62
- }
63
- [dir=rtl] .element{
64
- margin:1rem .5rem 1rem 0;
65
- }
66
- .container{
67
- min-width: 400px;
68
- transition: .3s ease-in-out;
69
- position: absolute;
70
- background-color: #fff;
71
- border-radius: 10px;
72
- padding: 20px;
73
- }
74
- .formContainer{
75
- display: flex;
76
- flex-direction: column;
77
- }
78
- label{
79
- font-weight: 400;
80
- font-size: 20px;
81
- }
82
- .sOpt:focus{
83
- background-color: red;
84
- }
85
- .button {
86
- -webkit-appearance: none;
87
- appearance: none;
88
- color: white;
89
- font-size: 14px;
90
- background: green;
91
- border: none;
92
- padding: 4px 8px;
93
- }
94
-
95
- .focus-ring {
96
- outline: 2px solid dodgerblue;
97
- outline-offset: 2px;
98
- }
99
- .box{
100
- display: flex;
101
- flex-direction: column;
102
- }
103
- .box1{
104
- transform: scale(1);
105
- }
106
- [dir=ltr] .manage{
107
- right: 0;
108
- }
109
- [dir=rtl] .manage{
110
- left: 0;
111
- }
112
- .primary{
113
- color: #fff;
114
- text-decoration: none;
115
- font-size: 13px;
116
- background: #00aefe;
117
- box-shadow: 0 2px 6px 0 rgba(209, 209, 209, 0.18);
118
- padding: 7px 12px;
119
- cursor: pointer;
120
- margin-top: 1px;
121
- border-radius: 3px;
122
- border: 1px solid #00aefe;
123
- margin:10px
124
- }
125
- .secondary{
126
- color: #8c8c8c;
127
- text-decoration: none;
128
- font-size: 13px;
129
- background: #fff;
130
- box-shadow: 0 2px 6px 0 rgba(209, 209, 209, 0.18);
131
- padding: 7px 12px;
132
- cursor: pointer;
133
- margin-top: 1px;
134
- border-radius: 3px;
135
- border: 1px solid #8c8c8c
136
- }
137
-
138
- [dir=ltr] .primary:focus{
139
- box-shadow: 2px 2px 6px 0 rgba(19, 173, 211, 0.493);
140
- }
141
-
142
- [dir=rtl] .primary:focus{
143
- box-shadow: -2px 2px 6px 0 rgba(19, 173, 211, 0.493);
144
- }
145
-
146
- [dir=ltr] .secondary:focus{
147
- box-shadow: 2px 2px 6px 0 rgba(39, 40, 41, 0.493)
148
- }
149
-
150
- [dir=rtl] .secondary:focus{
151
- box-shadow: -2px 2px 6px 0 rgba(39, 40, 41, 0.493)
152
- }
@@ -1,48 +0,0 @@
1
- import React from 'react';
2
- import Button from '../../../Button/Button';
3
- import TextBox from '../../../TextBox/TextBox';
4
- import FocusRing from '../FocusRing';
5
- import style from '../FocusRing.module.css';
6
- import { Box } from '../../../Layout';
7
- export default class FocusRing__default extends React.Component {
8
- render() {
9
- let styles = {
10
- margin: '30px',
11
- width: '50%',
12
- display: 'block'
13
- };
14
- return /*#__PURE__*/React.createElement(FocusRing, {
15
- focusClass: style.mouseFocus,
16
- focusRingClass: style.tabFocus,
17
- within: true
18
- }, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement("span", {
19
- style: styles
20
- }, /*#__PURE__*/React.createElement(FocusRing, {
21
- focusClass: style.mouseFocus,
22
- focusRingClass: style.tabFocus
23
- }, /*#__PURE__*/React.createElement(TextBox, {
24
- type: "text",
25
- defaultValue: "Input a",
26
- id: "1"
27
- }))), /*#__PURE__*/React.createElement("span", {
28
- style: styles
29
- }, /*#__PURE__*/React.createElement(FocusRing, {
30
- focusClass: style.mouseFocus,
31
- focusRingClass: style.tabFocus
32
- }, /*#__PURE__*/React.createElement(TextBox, {
33
- type: "text",
34
- defaultValue: "Input b",
35
- id: "2"
36
- }))), /*#__PURE__*/React.createElement("span", {
37
- style: styles
38
- }, /*#__PURE__*/React.createElement(TextBox, {
39
- type: "text",
40
- defaultValue: "Input c",
41
- id: "3"
42
- }))));
43
- }
44
-
45
- }
46
- FocusRing__default.docs = {
47
- componentGroup: 'Atom'
48
- };