@onesy/ui-react 1.0.90 → 1.0.91
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/Interaction/Interaction.js +41 -31
- package/esm/Interaction/Interaction.js +36 -31
- package/esm/index.js +1 -1
- package/package.json +1 -1
@@ -98,9 +98,8 @@ const useStyle = (0, style_react_1.style)(theme => ({
|
|
98
98
|
const Interaction = react_1.default.forwardRef((props_, ref) => {
|
99
99
|
const theme = (0, style_react_1.useOnesyTheme)();
|
100
100
|
const props = react_1.default.useMemo(() => { var _a, _b, _c, _d, _e, _f, _g, _h; return (Object.assign(Object.assign(Object.assign({}, (_d = (_c = (_b = (_a = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.all) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.default), (_h = (_g = (_f = (_e = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _e === void 0 ? void 0 : _e.elements) === null || _f === void 0 ? void 0 : _f.onesyInteraction) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]);
|
101
|
-
const { wave = true, background = true, border:
|
101
|
+
const { wave = true, background = true, border: hasBorder, pulse, origin: originProps, preselected, selected, dragged, wave_version, subscription, clear, disabled, className } = props;
|
102
102
|
const { classes } = useStyle();
|
103
|
-
const [init, setInit] = react_1.default.useState(false);
|
104
103
|
const [interactions, setInteractions] = react_1.default.useState([]);
|
105
104
|
const [border, setBorder] = react_1.default.useState(false);
|
106
105
|
const [waves, setWaves] = react_1.default.useState([]);
|
@@ -111,7 +110,12 @@ const Interaction = react_1.default.forwardRef((props_, ref) => {
|
|
111
110
|
pulse: react_1.default.useRef(undefined),
|
112
111
|
touch: react_1.default.useRef(undefined),
|
113
112
|
interactions: react_1.default.useRef(undefined),
|
114
|
-
|
113
|
+
border: react_1.default.useRef(border),
|
114
|
+
props: react_1.default.useRef(undefined),
|
115
|
+
init: react_1.default.useRef(false),
|
116
|
+
waves: react_1.default.useRef(waves),
|
117
|
+
origin: react_1.default.useRef(originProps),
|
118
|
+
hasBorder: react_1.default.useRef(hasBorder)
|
115
119
|
};
|
116
120
|
const touch = (0, __1.useMediaQuery)('(pointer: coarse)', { element: refs.root.current });
|
117
121
|
refs.props.current = props;
|
@@ -119,16 +123,20 @@ const Interaction = react_1.default.forwardRef((props_, ref) => {
|
|
119
123
|
refs.pulse.current = pulse;
|
120
124
|
refs.touch.current = touch;
|
121
125
|
refs.interactions.current = interactions;
|
126
|
+
refs.border.current = border;
|
127
|
+
refs.waves.current = waves;
|
128
|
+
refs.origin.current = originProps;
|
129
|
+
refs.hasBorder.current = hasBorder;
|
122
130
|
react_1.default.useEffect(() => {
|
123
131
|
var _a;
|
124
132
|
const parent = refs.root.current.parentNode;
|
125
|
-
const onMouseIn = (
|
133
|
+
const onMouseIn = () => {
|
126
134
|
if (refs.touch.current)
|
127
135
|
return;
|
128
136
|
add('mouse-in');
|
129
137
|
removeWaves();
|
130
138
|
};
|
131
|
-
const onMouseOut = (
|
139
|
+
const onMouseOut = () => {
|
132
140
|
if (refs.touch.current)
|
133
141
|
return;
|
134
142
|
refs.mouse.current.up = new Date().getTime();
|
@@ -143,18 +151,19 @@ const Interaction = react_1.default.forwardRef((props_, ref) => {
|
|
143
151
|
add('mouse-down');
|
144
152
|
addWave(event);
|
145
153
|
};
|
146
|
-
const updateBorder = (0, utils_1.debounce)(() =>
|
154
|
+
const updateBorder = (0, utils_1.debounce)(() => {
|
155
|
+
if (refs.border.current)
|
156
|
+
setBorder(false);
|
157
|
+
}, theme.transitions.duration.sm);
|
147
158
|
const onMouseUp = () => {
|
159
|
+
if (!(has('mouse-down') || refs.waves.current.length))
|
160
|
+
return;
|
148
161
|
refs.mouse.current.up = new Date().getTime();
|
149
162
|
refs.mouse.current.press = refs.mouse.current.down ? Math.round(refs.mouse.current.up - refs.mouse.current.down) : 0;
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
updateBorder();
|
155
|
-
}
|
156
|
-
return items;
|
157
|
-
});
|
163
|
+
if (refs.hasBorder.current && has('mouse-down')) {
|
164
|
+
setBorder(true);
|
165
|
+
updateBorder();
|
166
|
+
}
|
158
167
|
remove('mouse-down');
|
159
168
|
removeWaves();
|
160
169
|
};
|
@@ -171,7 +180,7 @@ const Interaction = react_1.default.forwardRef((props_, ref) => {
|
|
171
180
|
parent.addEventListener('mouseleave', onMouseOut);
|
172
181
|
// parent.addEventListener('touchend', onMouseOut, { passive: true });
|
173
182
|
}
|
174
|
-
|
183
|
+
refs.init.current = true;
|
175
184
|
return () => {
|
176
185
|
if (parent) {
|
177
186
|
parent.removeEventListener('mousedown', onMouseDown);
|
@@ -188,8 +197,9 @@ const Interaction = react_1.default.forwardRef((props_, ref) => {
|
|
188
197
|
};
|
189
198
|
}, []);
|
190
199
|
react_1.default.useEffect(() => {
|
191
|
-
if (init) {
|
192
|
-
|
200
|
+
if (refs.init.current) {
|
201
|
+
if (refs.interactions.current.length)
|
202
|
+
setInteractions([]);
|
193
203
|
removeWaves();
|
194
204
|
}
|
195
205
|
}, [clear]);
|
@@ -221,12 +231,12 @@ const Interaction = react_1.default.forwardRef((props_, ref) => {
|
|
221
231
|
};
|
222
232
|
}, [subscription]);
|
223
233
|
react_1.default.useEffect(() => {
|
224
|
-
if (disabled)
|
234
|
+
if (disabled && refs.interactions.current.length)
|
225
235
|
setInteractions([]);
|
226
236
|
}, [disabled]);
|
227
237
|
const addWave = react_1.default.useCallback((event, overrides = {}) => {
|
228
238
|
var _a, _b;
|
229
|
-
const origin = overrides.origin !== undefined ? overrides.origin :
|
239
|
+
const origin = overrides.origin !== undefined ? overrides.origin : refs.origin.current;
|
230
240
|
if (refs.wave.current && !refs.props.current.disabled) {
|
231
241
|
let top = 0;
|
232
242
|
let left = 0;
|
@@ -268,7 +278,7 @@ const Interaction = react_1.default.forwardRef((props_, ref) => {
|
|
268
278
|
if (refs.pulse.current && !refs.props.current.disabled) {
|
269
279
|
// Remove previous wave
|
270
280
|
// if there is one
|
271
|
-
if (waves.length)
|
281
|
+
if (refs.waves.current.length)
|
272
282
|
removeWaves();
|
273
283
|
const root = refs.root.current.parentNode.getBoundingClientRect();
|
274
284
|
const w = root.width;
|
@@ -290,19 +300,19 @@ const Interaction = react_1.default.forwardRef((props_, ref) => {
|
|
290
300
|
]);
|
291
301
|
}
|
292
302
|
}, []);
|
293
|
-
const removeWaves = react_1.default.useCallback(() =>
|
303
|
+
const removeWaves = react_1.default.useCallback(() => {
|
304
|
+
if (refs.waves.current.length)
|
305
|
+
setWaves([]);
|
306
|
+
}, []);
|
294
307
|
const add = react_1.default.useCallback((value) => {
|
295
|
-
if (!refs.props.current.disabled)
|
296
|
-
setInteractions(items =>
|
297
|
-
const newItems = [...items];
|
298
|
-
if (newItems.indexOf(value) === -1)
|
299
|
-
newItems.push(value);
|
300
|
-
return newItems;
|
301
|
-
});
|
302
|
-
}
|
308
|
+
if (!refs.props.current.disabled && !has(value))
|
309
|
+
setInteractions(items => [...items, value]);
|
303
310
|
}, []);
|
304
311
|
const has = react_1.default.useCallback((value) => refs.interactions.current.includes(value), []);
|
305
|
-
const remove = react_1.default.useCallback((value) =>
|
312
|
+
const remove = react_1.default.useCallback((value) => {
|
313
|
+
if (has(value))
|
314
|
+
setInteractions(items => [...items].filter(item => item !== value));
|
315
|
+
}, []);
|
306
316
|
return ((0, jsx_runtime_1.jsxs)("span", Object.assign({ ref: item => {
|
307
317
|
if (ref) {
|
308
318
|
if ((0, utils_1.is)('function', ref))
|
@@ -335,7 +345,7 @@ const Interaction = react_1.default.forwardRef((props_, ref) => {
|
|
335
345
|
style: {
|
336
346
|
transitionDuration: refs.mouse.current.press < 500 ? 340 : 500
|
337
347
|
}
|
338
|
-
} }, { children: waves })),
|
348
|
+
} }, { children: waves })), hasBorder && ((0, jsx_runtime_1.jsx)(__1.Transition, Object.assign({ in: border }, { children: (status) => ((0, jsx_runtime_1.jsx)("span", { className: (0, style_react_1.classNames)([
|
339
349
|
(0, __1.staticClassName)('Interaction', theme) && [
|
340
350
|
'onesy-Interaction-border'
|
341
351
|
],
|
@@ -138,9 +138,9 @@ const Interaction = /*#__PURE__*/React.forwardRef((props_, ref) => {
|
|
138
138
|
const {
|
139
139
|
wave = true,
|
140
140
|
background = true,
|
141
|
-
border:
|
141
|
+
border: hasBorder,
|
142
142
|
pulse,
|
143
|
-
origin:
|
143
|
+
origin: originProps,
|
144
144
|
preselected,
|
145
145
|
selected,
|
146
146
|
dragged,
|
@@ -153,7 +153,6 @@ const Interaction = /*#__PURE__*/React.forwardRef((props_, ref) => {
|
|
153
153
|
const {
|
154
154
|
classes
|
155
155
|
} = useStyle();
|
156
|
-
const [init, setInit] = React.useState(false);
|
157
156
|
const [interactions, setInteractions] = React.useState([]);
|
158
157
|
const [border, setBorder] = React.useState(false);
|
159
158
|
const [waves, setWaves] = React.useState([]);
|
@@ -168,7 +167,12 @@ const Interaction = /*#__PURE__*/React.forwardRef((props_, ref) => {
|
|
168
167
|
pulse: React.useRef(undefined),
|
169
168
|
touch: React.useRef(undefined),
|
170
169
|
interactions: React.useRef(undefined),
|
171
|
-
|
170
|
+
border: React.useRef(border),
|
171
|
+
props: React.useRef(undefined),
|
172
|
+
init: React.useRef(false),
|
173
|
+
waves: React.useRef(waves),
|
174
|
+
origin: React.useRef(originProps),
|
175
|
+
hasBorder: React.useRef(hasBorder)
|
172
176
|
};
|
173
177
|
const touch = useMediaQuery('(pointer: coarse)', {
|
174
178
|
element: refs.root.current
|
@@ -178,14 +182,18 @@ const Interaction = /*#__PURE__*/React.forwardRef((props_, ref) => {
|
|
178
182
|
refs.pulse.current = pulse;
|
179
183
|
refs.touch.current = touch;
|
180
184
|
refs.interactions.current = interactions;
|
185
|
+
refs.border.current = border;
|
186
|
+
refs.waves.current = waves;
|
187
|
+
refs.origin.current = originProps;
|
188
|
+
refs.hasBorder.current = hasBorder;
|
181
189
|
React.useEffect(() => {
|
182
190
|
const parent = refs.root.current.parentNode;
|
183
|
-
const onMouseIn =
|
191
|
+
const onMouseIn = () => {
|
184
192
|
if (refs.touch.current) return;
|
185
193
|
add('mouse-in');
|
186
194
|
removeWaves();
|
187
195
|
};
|
188
|
-
const onMouseOut =
|
196
|
+
const onMouseOut = () => {
|
189
197
|
if (refs.touch.current) return;
|
190
198
|
refs.mouse.current.up = new Date().getTime();
|
191
199
|
refs.mouse.current.press = refs.mouse.current.down ? Math.round(refs.mouse.current.up - refs.mouse.current.down) : 0;
|
@@ -199,18 +207,17 @@ const Interaction = /*#__PURE__*/React.forwardRef((props_, ref) => {
|
|
199
207
|
add('mouse-down');
|
200
208
|
addWave(event);
|
201
209
|
};
|
202
|
-
const updateBorder = debounce(() =>
|
210
|
+
const updateBorder = debounce(() => {
|
211
|
+
if (refs.border.current) setBorder(false);
|
212
|
+
}, theme.transitions.duration.sm);
|
203
213
|
const onMouseUp = () => {
|
214
|
+
if (!(has('mouse-down') || refs.waves.current.length)) return;
|
204
215
|
refs.mouse.current.up = new Date().getTime();
|
205
216
|
refs.mouse.current.press = refs.mouse.current.down ? Math.round(refs.mouse.current.up - refs.mouse.current.down) : 0;
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
updateBorder();
|
211
|
-
}
|
212
|
-
return items;
|
213
|
-
});
|
217
|
+
if (refs.hasBorder.current && has('mouse-down')) {
|
218
|
+
setBorder(true);
|
219
|
+
updateBorder();
|
220
|
+
}
|
214
221
|
remove('mouse-down');
|
215
222
|
removeWaves();
|
216
223
|
};
|
@@ -233,7 +240,7 @@ const Interaction = /*#__PURE__*/React.forwardRef((props_, ref) => {
|
|
233
240
|
parent.addEventListener('mouseleave', onMouseOut);
|
234
241
|
// parent.addEventListener('touchend', onMouseOut, { passive: true });
|
235
242
|
}
|
236
|
-
|
243
|
+
refs.init.current = true;
|
237
244
|
return () => {
|
238
245
|
if (parent) {
|
239
246
|
parent.removeEventListener('mousedown', onMouseDown);
|
@@ -250,8 +257,8 @@ const Interaction = /*#__PURE__*/React.forwardRef((props_, ref) => {
|
|
250
257
|
};
|
251
258
|
}, []);
|
252
259
|
React.useEffect(() => {
|
253
|
-
if (init) {
|
254
|
-
setInteractions([]);
|
260
|
+
if (refs.init.current) {
|
261
|
+
if (refs.interactions.current.length) setInteractions([]);
|
255
262
|
removeWaves();
|
256
263
|
}
|
257
264
|
}, [clear]);
|
@@ -276,11 +283,11 @@ const Interaction = /*#__PURE__*/React.forwardRef((props_, ref) => {
|
|
276
283
|
};
|
277
284
|
}, [subscription]);
|
278
285
|
React.useEffect(() => {
|
279
|
-
if (disabled) setInteractions([]);
|
286
|
+
if (disabled && refs.interactions.current.length) setInteractions([]);
|
280
287
|
}, [disabled]);
|
281
288
|
const addWave = React.useCallback(function (event) {
|
282
289
|
let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
283
|
-
const origin = overrides.origin !== undefined ? overrides.origin :
|
290
|
+
const origin = overrides.origin !== undefined ? overrides.origin : refs.origin.current;
|
284
291
|
if (refs.wave.current && !refs.props.current.disabled) {
|
285
292
|
let top = 0;
|
286
293
|
let left = 0;
|
@@ -327,7 +334,7 @@ const Interaction = /*#__PURE__*/React.forwardRef((props_, ref) => {
|
|
327
334
|
if (refs.pulse.current && !refs.props.current.disabled) {
|
328
335
|
// Remove previous wave
|
329
336
|
// if there is one
|
330
|
-
if (waves.length) removeWaves();
|
337
|
+
if (refs.waves.current.length) removeWaves();
|
331
338
|
const root = refs.root.current.parentNode.getBoundingClientRect();
|
332
339
|
const w = root.width;
|
333
340
|
const h = root.height;
|
@@ -352,18 +359,16 @@ const Interaction = /*#__PURE__*/React.forwardRef((props_, ref) => {
|
|
352
359
|
}))]);
|
353
360
|
}
|
354
361
|
}, []);
|
355
|
-
const removeWaves = React.useCallback(() =>
|
362
|
+
const removeWaves = React.useCallback(() => {
|
363
|
+
if (refs.waves.current.length) setWaves([]);
|
364
|
+
}, []);
|
356
365
|
const add = React.useCallback(value => {
|
357
|
-
if (!refs.props.current.disabled)
|
358
|
-
setInteractions(items => {
|
359
|
-
const newItems = [...items];
|
360
|
-
if (newItems.indexOf(value) === -1) newItems.push(value);
|
361
|
-
return newItems;
|
362
|
-
});
|
363
|
-
}
|
366
|
+
if (!refs.props.current.disabled && !has(value)) setInteractions(items => [...items, value]);
|
364
367
|
}, []);
|
365
368
|
const has = React.useCallback(value => refs.interactions.current.includes(value), []);
|
366
|
-
const remove = React.useCallback(value =>
|
369
|
+
const remove = React.useCallback(value => {
|
370
|
+
if (has(value)) setInteractions(items => [...items].filter(item => item !== value));
|
371
|
+
}, []);
|
367
372
|
return /*#__PURE__*/React.createElement("span", {
|
368
373
|
ref: item => {
|
369
374
|
if (ref) {
|
@@ -385,7 +390,7 @@ const Interaction = /*#__PURE__*/React.forwardRef((props_, ref) => {
|
|
385
390
|
transitionDuration: refs.mouse.current.press < 500 ? 340 : 500
|
386
391
|
}
|
387
392
|
}
|
388
|
-
}, waves),
|
393
|
+
}, waves), hasBorder && /*#__PURE__*/React.createElement(Transition, {
|
389
394
|
in: border
|
390
395
|
}, status => /*#__PURE__*/React.createElement("span", {
|
391
396
|
className: classNames([staticClassName('Interaction', theme) && ['onesy-Interaction-border'], classes.border]),
|
package/esm/index.js
CHANGED