@homecode/ui 5.3.10 → 5.3.11

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.
@@ -1,4 +1,4 @@
1
- import { createElement, Component } from 'react';
1
+ import { createElement, Component, createRef } from 'react';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import cn from 'classnames';
4
4
  import { useStore } from 'justorm/react';
@@ -19,8 +19,69 @@ function getDeltaPos(p1, p2) {
19
19
  };
20
20
  }
21
21
  const TOUCH_MOVE_TRESHOLD = 50;
22
+ const WHEEL_MOVE_THRESHOLD = 20;
23
+ const WHEEL_RESET_MS = 150;
24
+ const wheelGesture = {
25
+ itemId: null,
26
+ deltaX: 0,
27
+ deltaY: 0,
28
+ resetTimer: null,
29
+ };
30
+ function resetWheelGesture() {
31
+ wheelGesture.itemId = null;
32
+ wheelGesture.deltaX = 0;
33
+ wheelGesture.deltaY = 0;
34
+ if (wheelGesture.resetTimer) {
35
+ clearTimeout(wheelGesture.resetTimer);
36
+ wheelGesture.resetTimer = null;
37
+ }
38
+ }
39
+ function scheduleWheelGestureReset() {
40
+ if (wheelGesture.resetTimer) {
41
+ clearTimeout(wheelGesture.resetTimer);
42
+ }
43
+ wheelGesture.resetTimer = setTimeout(resetWheelGesture, WHEEL_RESET_MS);
44
+ }
45
+ function isHorizontalWheel(e, id) {
46
+ const absX = Math.abs(e.deltaX);
47
+ const absY = Math.abs(e.deltaY);
48
+ if (absX > absY)
49
+ return true;
50
+ return (wheelGesture.itemId === id && wheelGesture.deltaX >= wheelGesture.deltaY);
51
+ }
52
+ function handleNotificationWheel(id, e, unpause, close) {
53
+ scheduleWheelGestureReset();
54
+ if (wheelGesture.itemId !== null && wheelGesture.itemId !== id) {
55
+ return;
56
+ }
57
+ if (wheelGesture.itemId === null) {
58
+ wheelGesture.itemId = id;
59
+ }
60
+ wheelGesture.deltaX += Math.abs(e.deltaX);
61
+ wheelGesture.deltaY += Math.abs(e.deltaY);
62
+ if (wheelGesture.deltaX > wheelGesture.deltaY &&
63
+ wheelGesture.deltaX > WHEEL_MOVE_THRESHOLD) {
64
+ const closingId = wheelGesture.itemId;
65
+ unpause();
66
+ wheelGesture.deltaX = 0;
67
+ wheelGesture.deltaY = 0;
68
+ close(closingId);
69
+ }
70
+ }
22
71
  class Item extends Component {
23
72
  startPos = null;
73
+ itemRef = createRef();
74
+ componentDidMount() {
75
+ this.itemRef.current?.addEventListener('wheel', this.onWheelNative, {
76
+ passive: false,
77
+ capture: true,
78
+ });
79
+ }
80
+ componentWillUnmount() {
81
+ this.itemRef.current?.removeEventListener('wheel', this.onWheelNative, {
82
+ capture: true,
83
+ });
84
+ }
24
85
  onTouchStart = e => {
25
86
  this.startPos = getTouchPos(e);
26
87
  };
@@ -43,6 +104,14 @@ class Item extends Component {
43
104
  this.startPos = null;
44
105
  };
45
106
  onTouchCancel = () => (this.startPos = null);
107
+ onWheelNative = (e) => {
108
+ const { id, unpause, close } = this.props;
109
+ if (isHorizontalWheel(e, id)) {
110
+ e.preventDefault();
111
+ e.stopPropagation();
112
+ }
113
+ handleNotificationWheel(id, e, unpause, close);
114
+ };
46
115
  closeMe = () => {
47
116
  const { id, close } = this.props;
48
117
  close(id);
@@ -50,7 +119,7 @@ class Item extends Component {
50
119
  render() {
51
120
  const { type = 'default', title, content, visible, pause, unpause, } = this.props;
52
121
  const classes = cn(S.item, S[`type-${type}`], visible && S.visible);
53
- return (jsx("div", { className: classes, onMouseOver: pause, onFocus: pause, onTouchStart: this.onTouchStart, onTouchMove: this.onTouchMove, onMouseOut: unpause, onBlur: unpause, onTouchEnd: this.onTouchEnd, onTouchCancel: this.onTouchCancel, children: jsxs("div", { className: S.itemInner, children: [(title || content) && (jsxs("div", { className: S.text, children: [title && jsx("div", { className: S.title, children: title }), content != null && (jsx("div", { className: S.content, children: typeof content === 'function' ? content() : content }))] })), jsx(Button, { className: S.close, variant: "clear", square: true, onClick: this.closeMe, children: jsx(Icon, { type: "close", size: "s" }) })] }) }));
122
+ return (jsx("div", { ref: this.itemRef, className: classes, onMouseOver: pause, onFocus: pause, onTouchStart: this.onTouchStart, onTouchMove: this.onTouchMove, onMouseOut: unpause, onBlur: unpause, onTouchEnd: this.onTouchEnd, onTouchCancel: this.onTouchCancel, children: jsxs("div", { className: S.itemInner, children: [(title || content) && (jsxs("div", { className: S.text, children: [title && jsx("div", { className: S.title, children: title }), content != null && (jsx("div", { className: S.content, children: typeof content === 'function' ? content() : content }))] })), jsx(Button, { className: S.close, variant: "clear", square: true, onClick: this.closeMe, children: jsx(Icon, { type: "close", size: "s" }) })] }) }));
54
123
  }
55
124
  }
56
125
  const NotificationsStore = STORE;
@@ -1,6 +1,6 @@
1
1
  import styleInject from '../../../node_modules/style-inject/dist/style-inject.es.js';
2
2
 
3
- var css_248z = ".Notifications_root__S3ujN{max-height:calc(var(--vh)*100);overflow:hidden;position:fixed;right:0;top:0;transform:translateZ(0);transition:right .3s ease-out;width:320px;z-index:20}.Notifications_inner__6v9e3{padding:var(--p-5);padding-right:var(--p-3)}.Notifications_empty__zCpOA{pointer-events:none}.Notifications_itemInner__nEYAl,.Notifications_item__I3Up4{border-radius:var(--p-4)}.Notifications_item__I3Up4{-webkit-backface-visibility:hidden;backface-visibility:hidden;left:100%;max-height:0;max-width:100%;opacity:0;position:relative;transition:all .3s ease-out;width:300px}.Notifications_item__I3Up4:first-child{margin-top:calc(var(--p-2)*-1)}.Notifications_item__I3Up4+.Notifications_item__I3Up4{padding-top:var(--p-2)}.Notifications_item__I3Up4:hover{transform:translateX(-2px)}.Notifications_visible__ln4-n{left:0;max-height:500px;opacity:1}.Notifications_itemInner__nEYAl{align-items:center;-webkit-backdrop-filter:blur(30px);backdrop-filter:blur(30px);background-color:var(--decent-color-alpha-500);box-shadow:inset 0 0 1px var(--accent-color-alpha-300),0 0 20px var(--decent-color);box-sizing:border-box;display:flex;padding:var(--p-3);padding-right:var(--p-6);position:relative;transition:.3s ease-out;transition-property:transform}.Notifications_type-warning__Nxg6C .Notifications_itemInner__nEYAl{background-color:var(--warning-color-alpha-300)}.Notifications_type-danger__zeIMt .Notifications_itemInner__nEYAl{background-color:var(--danger-color-alpha-300)}.Notifications_itemInner__nEYAl button{margin-bottom:calc(var(--p-2)*-1);margin-top:calc(var(--p-2)*-1)}.Notifications_icon__nKs-X{background:no-repeat 50%;height:24px;margin-right:10px;min-width:24px;width:24px}.Notifications_type-loading__N4EE5 .Notifications_icon__nKs-X{transform:translateY(-20px)}.Notifications_text__7QZL6{display:flex;flex-direction:column;flex-grow:1;z-index:1}.Notifications_title__Gu9bs{font-size:16px;font-weight:700}.Notifications_content__Zrvw2{font-size:12px;margin-top:calc(var(--p-3)/2)}.Notifications_content__Zrvw2:first-child{margin-top:0}.Notifications_close__-IUH3{background-color:transparent;border-radius:50%;cursor:pointer;height:40px!important;max-height:40px!important;max-width:40px!important;opacity:0;position:absolute;right:-5px;top:2px;transform:scale(.8);transition:.1s ease-out;transition-property:opacity,transform;width:40px!important}.Notifications_close__-IUH3:before{background-color:var(--decent-color-alpha-400);border-radius:inherit;bottom:var(--p-2);content:\"\";left:var(--p-2);pointer-events:none;position:absolute;right:var(--p-2);top:var(--p-2);transition:background-color .1s ease-out}.Notifications_close__-IUH3 svg{transform:scale(.6)}.Notifications_item__I3Up4:hover .Notifications_close__-IUH3{opacity:.8}.Notifications_close__-IUH3:hover{background-color:transparent;background-color:initial;opacity:1}.Notifications_close__-IUH3:hover:before{background-color:var(--decent-color-alpha-800)}@media (max-width:700px){.Notifications_item__I3Up4,.Notifications_root__S3ujN{width:100%}.Notifications_title__Gu9bs{font-size:20px}.Notifications_content__Zrvw2{font-size:16px}.Notifications_close__-IUH3{transform:scale(1.2)}}";
3
+ var css_248z = ".Notifications_root__S3ujN{max-height:calc(var(--vh)*100);overflow:hidden;position:fixed;right:0;top:0;transform:translateZ(0);transition:right .3s ease-out;width:320px;z-index:20}.Notifications_inner__6v9e3{padding:var(--p-5);padding-right:var(--p-3)}.Notifications_empty__zCpOA{pointer-events:none}.Notifications_itemInner__nEYAl,.Notifications_item__I3Up4{border-radius:var(--p-4)}.Notifications_item__I3Up4{-webkit-backface-visibility:hidden;backface-visibility:hidden;left:100%;max-height:0;max-width:100%;opacity:0;overscroll-behavior-x:none;position:relative;touch-action:pan-y;transition:all .3s ease-out;width:300px}.Notifications_item__I3Up4:first-child{margin-top:calc(var(--p-2)*-1)}.Notifications_item__I3Up4+.Notifications_item__I3Up4{padding-top:var(--p-2)}.Notifications_item__I3Up4:hover{transform:translateX(-2px)}.Notifications_visible__ln4-n{left:0;max-height:500px;opacity:1}.Notifications_itemInner__nEYAl{align-items:center;-webkit-backdrop-filter:blur(30px);backdrop-filter:blur(30px);background-color:var(--decent-color-alpha-500);box-shadow:inset 0 0 1px var(--accent-color-alpha-300),0 0 20px var(--decent-color);box-sizing:border-box;display:flex;padding:var(--p-3);padding-right:var(--p-6);position:relative;transition:.3s ease-out;transition-property:transform}.Notifications_type-warning__Nxg6C .Notifications_itemInner__nEYAl{background-color:var(--warning-color-alpha-300)}.Notifications_type-danger__zeIMt .Notifications_itemInner__nEYAl{background-color:var(--danger-color-alpha-300)}.Notifications_itemInner__nEYAl button{margin-bottom:calc(var(--p-2)*-1);margin-top:calc(var(--p-2)*-1)}.Notifications_icon__nKs-X{background:no-repeat 50%;height:24px;margin-right:10px;min-width:24px;width:24px}.Notifications_type-loading__N4EE5 .Notifications_icon__nKs-X{transform:translateY(-20px)}.Notifications_text__7QZL6{display:flex;flex-direction:column;flex-grow:1;z-index:1}.Notifications_title__Gu9bs{font-size:16px;font-weight:700}.Notifications_content__Zrvw2{font-size:12px;margin-top:calc(var(--p-3)/2)}.Notifications_content__Zrvw2:first-child{margin-top:0}.Notifications_close__-IUH3{background-color:transparent;border-radius:50%;cursor:pointer;height:40px!important;max-height:40px!important;max-width:40px!important;opacity:0;position:absolute;right:-5px;top:2px;transform:scale(.8);transition:.1s ease-out;transition-property:opacity,transform;width:40px!important}.Notifications_close__-IUH3:before{background-color:var(--decent-color-alpha-400);border-radius:inherit;bottom:var(--p-2);content:\"\";left:var(--p-2);pointer-events:none;position:absolute;right:var(--p-2);top:var(--p-2);transition:background-color .1s ease-out}.Notifications_close__-IUH3 svg{transform:scale(.6)}.Notifications_item__I3Up4:hover .Notifications_close__-IUH3{opacity:.8}.Notifications_close__-IUH3:hover{background-color:transparent;background-color:initial;opacity:1}.Notifications_close__-IUH3:hover:before{background-color:var(--decent-color-alpha-800)}@media (max-width:700px){.Notifications_item__I3Up4,.Notifications_root__S3ujN{width:100%}.Notifications_title__Gu9bs{font-size:20px}.Notifications_content__Zrvw2{font-size:16px}.Notifications_close__-IUH3{transform:scale(1.2)}}";
4
4
  var S = {"root":"Notifications_root__S3ujN","inner":"Notifications_inner__6v9e3","empty":"Notifications_empty__zCpOA","item":"Notifications_item__I3Up4","itemInner":"Notifications_itemInner__nEYAl","visible":"Notifications_visible__ln4-n","type-warning":"Notifications_type-warning__Nxg6C","type-danger":"Notifications_type-danger__zeIMt","icon":"Notifications_icon__nKs-X","type-loading":"Notifications_type-loading__N4EE5","text":"Notifications_text__7QZL6","title":"Notifications_title__Gu9bs","content":"Notifications_content__Zrvw2","close":"Notifications_close__-IUH3"};
5
5
  styleInject(css_248z);
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homecode/ui",
3
- "version": "5.3.10",
3
+ "version": "5.3.11",
4
4
  "description": "React UI components library",
5
5
  "scripts": {
6
6
  "tests": "jest",