@onesy/ui-react 1.0.18 → 1.0.20

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.
@@ -152,7 +152,7 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
152
152
  const Append = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Append) || Append_1.default; }, [theme]);
153
153
  const Modal = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Modal) || Modal_1.default; }, [theme]);
154
154
  const Surface = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Surface) || Surface_1.default; }, [theme]);
155
- const { tonal = true, color = 'inverted', open: open_, openDefault, name, label: label_, parent, position = 'bottom', switch: switch_ = true, alignment = 'center', portal = true, fullWidth, maxWidth = 'unset', arrow, anchor: anchor_, anchorElement, noMargin, classNameSwitch, transformOrigin, transformOriginSwitch, transformOriginRtl, transformOriginRtlSwitch, click, touch: touch_ = true, longPress: longPress_ = false, hover: hover_ = true, focus: focus_ = false, inset, nowrap, follow, interactive, onOpen: onOpen_, onClose: onClose_, onExited, TransitionComponent = Grow, TransitionComponentProps, AppendProps, ModalProps, LabelProps,
155
+ const { tonal = true, color = 'inverted', open: open_, openDefault, name, label: label_, parent, position = 'bottom', switch: switch_ = true, alignment = 'center', portal = true, fullWidth, maxWidth = 'unset', arrow, anchor: anchor_, anchorElement, noMargin, classNameSwitch, transformOrigin, transformOriginSwitch, transformOriginRtl, transformOriginRtlSwitch, click, touch: touch_, longPress: longPress_ = false, hover: hover_ = true, focus: focus_ = false, inset, nowrap, follow, interactive, onOpen: onOpen_, onClose: onClose_, onExited, TransitionComponent = Grow, TransitionComponentProps, AppendProps, ModalProps, LabelProps,
156
156
  // other
157
157
  elevation, className, style, children } = props, other = __rest(props, ["tonal", "color", "open", "openDefault", "name", "label", "parent", "position", "switch", "alignment", "portal", "fullWidth", "maxWidth", "arrow", "anchor", "anchorElement", "noMargin", "classNameSwitch", "transformOrigin", "transformOriginSwitch", "transformOriginRtl", "transformOriginRtlSwitch", "click", "touch", "longPress", "hover", "focus", "inset", "nowrap", "follow", "interactive", "onOpen", "onClose", "onExited", "TransitionComponent", "TransitionComponentProps", "AppendProps", "ModalProps", "LabelProps", "elevation", "className", "style", "children"]);
158
158
  const [init, setInit] = react_1.default.useState(false);
@@ -164,15 +164,18 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
164
164
  const [anchor, setAnchor] = react_1.default.useState(anchor_);
165
165
  const [inProp, setInProp] = react_1.default.useState(open_);
166
166
  const refs = {
167
+ root: react_1.default.useRef(null),
167
168
  open: react_1.default.useRef(false),
168
169
  inProp: react_1.default.useRef(inProp),
169
170
  longPress: react_1.default.useRef(false),
170
- longPressTimer: react_1.default.useRef(undefined),
171
+ longPressTimer: react_1.default.useRef(null),
172
+ touchProps: react_1.default.useRef(touch_),
171
173
  props: react_1.default.useRef(undefined)
172
174
  };
173
175
  refs.props.current = props;
174
176
  refs.open.current = open;
175
177
  refs.inProp.current = inProp;
178
+ refs.touchProps.current = touch_;
176
179
  const { classes } = useStyle();
177
180
  const styles = {
178
181
  name: {},
@@ -215,17 +218,19 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
215
218
  children.props.onMouseLeave(event);
216
219
  }, []);
217
220
  const onTouchStart = react_1.default.useCallback((event) => {
218
- if (touch_)
219
- setTouch(true);
221
+ if (!refs.touchProps.current)
222
+ return;
223
+ setTouch(true);
220
224
  if ((0, utils_1.is)('function', children === null || children === void 0 ? void 0 : children.props.onTouchStart))
221
225
  children.props.onTouchStart(event);
222
- }, []);
226
+ }, [touch_]);
223
227
  const onTouchEnd = react_1.default.useCallback((event) => {
224
- if (touch_)
225
- setTouch(false);
228
+ if (!refs.touchProps.current)
229
+ return;
230
+ setTouch(false);
226
231
  if ((0, utils_1.is)('function', children === null || children === void 0 ? void 0 : children.props.onTouchEnd))
227
232
  children.props.onTouchEnd(event);
228
- }, []);
233
+ }, [touch_]);
229
234
  const onFocus = react_1.default.useCallback((event) => {
230
235
  if (focus_)
231
236
  setFocus(true);
@@ -284,7 +289,13 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
284
289
  !refs.open.current ? onOpen() : onPreClose();
285
290
  }, [onOpen, onPreClose]);
286
291
  react_1.default.useEffect(() => {
292
+ var _a;
287
293
  setInit(true);
294
+ const rootDocument = (0, utils_1.isEnvironment)('browser') ? (((_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) || window.document) : undefined;
295
+ rootDocument.addEventListener('touchend', onTouchEnd);
296
+ return () => {
297
+ rootDocument.removeEventListener('touchend', onTouchEnd);
298
+ };
288
299
  }, []);
289
300
  react_1.default.useEffect(() => {
290
301
  setAnchor(anchor_);
@@ -419,10 +430,17 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
419
430
  ]
420
431
  ])
421
432
  }) })) })) })));
422
- } }, { children: children && (react_1.default.cloneElement(children, Object.assign(Object.assign({ onMouseMove }, (click && {
433
+ } }, { children: children && (react_1.default.cloneElement(children, Object.assign(Object.assign({ ref: item => {
434
+ if (children === null || children === void 0 ? void 0 : children.ref) {
435
+ if ((0, utils_1.is)('function', children === null || children === void 0 ? void 0 : children.ref))
436
+ children === null || children === void 0 ? void 0 : children.ref(item);
437
+ else
438
+ children.ref.current = item;
439
+ }
440
+ refs.root.current = item;
441
+ }, onMouseMove }, (click && {
423
442
  onClick: (event) => {
424
443
  var _a, _b;
425
- event.stopPropagation();
426
444
  if ((0, utils_1.is)('function', (_a = children === null || children === void 0 ? void 0 : children.props) === null || _a === void 0 ? void 0 : _a.onClick))
427
445
  (_b = children === null || children === void 0 ? void 0 : children.props) === null || _b === void 0 ? void 0 : _b.onClick(event);
428
446
  onClick(event);
@@ -199,7 +199,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
199
199
  transformOriginRtl,
200
200
  transformOriginRtlSwitch,
201
201
  click,
202
- touch: touch_ = true,
202
+ touch: touch_,
203
203
  longPress: longPress_ = false,
204
204
  hover: hover_ = true,
205
205
  focus: focus_ = false,
@@ -231,15 +231,18 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
231
231
  const [anchor, setAnchor] = React.useState(anchor_);
232
232
  const [inProp, setInProp] = React.useState(open_);
233
233
  const refs = {
234
+ root: React.useRef(null),
234
235
  open: React.useRef(false),
235
236
  inProp: React.useRef(inProp),
236
237
  longPress: React.useRef(false),
237
- longPressTimer: React.useRef(undefined),
238
+ longPressTimer: React.useRef(null),
239
+ touchProps: React.useRef(touch_),
238
240
  props: React.useRef(undefined)
239
241
  };
240
242
  refs.props.current = props;
241
243
  refs.open.current = open;
242
244
  refs.inProp.current = inProp;
245
+ refs.touchProps.current = touch_;
243
246
  const {
244
247
  classes
245
248
  } = useStyle();
@@ -274,13 +277,15 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
274
277
  if (is('function', children?.props.onMouseLeave)) children.props.onMouseLeave(event);
275
278
  }, []);
276
279
  const onTouchStart = React.useCallback(event => {
277
- if (touch_) setTouch(true);
280
+ if (!refs.touchProps.current) return;
281
+ setTouch(true);
278
282
  if (is('function', children?.props.onTouchStart)) children.props.onTouchStart(event);
279
- }, []);
283
+ }, [touch_]);
280
284
  const onTouchEnd = React.useCallback(event => {
281
- if (touch_) setTouch(false);
285
+ if (!refs.touchProps.current) return;
286
+ setTouch(false);
282
287
  if (is('function', children?.props.onTouchEnd)) children.props.onTouchEnd(event);
283
- }, []);
288
+ }, [touch_]);
284
289
  const onFocus = React.useCallback(event => {
285
290
  if (focus_) setFocus(true);
286
291
  if (is('function', children?.props.onFocus)) children.props.onFocus(event);
@@ -324,6 +329,11 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
324
329
  }, [onOpen, onPreClose]);
325
330
  React.useEffect(() => {
326
331
  setInit(true);
332
+ const rootDocument = isEnvironment('browser') ? refs.root.current?.ownerDocument || window.document : undefined;
333
+ rootDocument.addEventListener('touchend', onTouchEnd);
334
+ return () => {
335
+ rootDocument.removeEventListener('touchend', onTouchEnd);
336
+ };
327
337
  }, []);
328
338
  React.useEffect(() => {
329
339
  setAnchor(anchor_);
@@ -432,10 +442,15 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
432
442
  }))));
433
443
  }
434
444
  }), children && (/*#__PURE__*/React.cloneElement(children, _objectSpread(_objectSpread({
445
+ ref: item => {
446
+ if (children?.ref) {
447
+ if (is('function', children?.ref)) children?.ref(item);else children.ref.current = item;
448
+ }
449
+ refs.root.current = item;
450
+ },
435
451
  onMouseMove
436
452
  }, click && {
437
453
  onClick: event => {
438
- event.stopPropagation();
439
454
  if (is('function', children?.props?.onClick)) children?.props?.onClick(event);
440
455
  onClick(event);
441
456
  }
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license UiReact v1.0.18
1
+ /** @license UiReact v1.0.20
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onesy/ui-react",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "UI for React",
5
5
  "repository": "https://github.com/onesy-me/onesy.git",
6
6
  "author": "Lazar <lazareric2@gmail.com>",