@micromag/element-scroll 0.3.541 → 0.3.569

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 (2) hide show
  1. package/package.json +4 -5
  2. package/lib/index.js +0 -176
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/element-scroll",
3
- "version": "0.3.541",
3
+ "version": "0.3.569",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -30,11 +30,10 @@
30
30
  }
31
31
  ],
32
32
  "license": "ISC",
33
- "main": "lib/index.js",
33
+ "type": "module",
34
34
  "module": "es/index.js",
35
35
  "exports": {
36
36
  ".": {
37
- "require": "./lib/index.js",
38
37
  "import": "./es/index.js"
39
38
  },
40
39
  "./assets/css/styles": "./assets/css/styles.css",
@@ -60,7 +59,7 @@
60
59
  },
61
60
  "dependencies": {
62
61
  "@babel/runtime": "^7.13.10",
63
- "@micromag/core": "^0.3.541",
62
+ "@micromag/core": "^0.3.569",
64
63
  "@use-gesture/react": "^10.3.0",
65
64
  "classnames": "^2.2.6",
66
65
  "lodash": "^4.17.21",
@@ -72,5 +71,5 @@
72
71
  "access": "public",
73
72
  "registry": "https://registry.npmjs.org/"
74
73
  },
75
- "gitHead": "6c04a7e327b5fbc096785c11320b3fbd3c5751c8"
74
+ "gitHead": "ceb71f23a32ab8df4a1563a1e5cd5598e539de4d"
76
75
  }
package/lib/index.js DELETED
@@ -1,176 +0,0 @@
1
- 'use strict';
2
-
3
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
5
- var react = require('@use-gesture/react');
6
- var classNames = require('classnames');
7
- var PropTypes = require('prop-types');
8
- var React = require('react');
9
- var hooks = require('@micromag/core/hooks');
10
-
11
- var styles = {"container":"micromag-element-scroll-container","withScroll":"micromag-element-scroll-withScroll","scrollable":"micromag-element-scroll-scrollable","top":"micromag-element-scroll-top","scrollee":"micromag-element-scroll-scrollee","middle":"micromag-element-scroll-middle","bottom":"micromag-element-scroll-bottom","withArrow":"micromag-element-scroll-withArrow","arrowContainer":"micromag-element-scroll-arrowContainer","withShadow":"micromag-element-scroll-withShadow","arrow":"micromag-element-scroll-arrow","upAndDown":"micromag-element-scroll-upAndDown"};
12
-
13
- var propTypes = {
14
- width: PropTypes.number,
15
- height: PropTypes.number,
16
- disabled: PropTypes.bool,
17
- verticalAlign: PropTypes.oneOf(['top', 'middle', 'bottom']),
18
- className: PropTypes.string,
19
- children: PropTypes.node,
20
- scrollPosition: PropTypes.oneOf([PropTypes.number, PropTypes.string]),
21
- onScrolledBottom: PropTypes.func,
22
- onScrolledNotBottom: PropTypes.func,
23
- onScrollHeightChange: PropTypes.func,
24
- scrollContainerRef: PropTypes.any,
25
- // eslint-disable-line
26
- withShadow: PropTypes.bool,
27
- withArrow: PropTypes.bool
28
- };
29
- var defaultProps = {
30
- width: null,
31
- height: null,
32
- disabled: false,
33
- verticalAlign: null,
34
- className: null,
35
- children: null,
36
- scrollPosition: null,
37
- onScrolledBottom: null,
38
- onScrolledNotBottom: null,
39
- onScrollHeightChange: null,
40
- scrollContainerRef: null,
41
- withShadow: false,
42
- withArrow: true
43
- };
44
- function Scroll(_ref) {
45
- var width = _ref.width,
46
- height = _ref.height,
47
- disabled = _ref.disabled,
48
- verticalAlign = _ref.verticalAlign,
49
- className = _ref.className,
50
- children = _ref.children,
51
- scrollPosition = _ref.scrollPosition,
52
- onScrolledBottom = _ref.onScrolledBottom,
53
- onScrolledNotBottom = _ref.onScrolledNotBottom,
54
- onScrollHeightChange = _ref.onScrollHeightChange,
55
- scrollContainerRef = _ref.scrollContainerRef,
56
- withShadow = _ref.withShadow,
57
- showArrow = _ref.withArrow;
58
- var finalStyle = {
59
- width: width,
60
- height: height
61
- };
62
- var _useState = React.useState(false),
63
- _useState2 = _slicedToArray(_useState, 2),
64
- withArrow = _useState2[0],
65
- setWithArrow = _useState2[1];
66
- var _useDimensionObserver = hooks.useDimensionObserver(),
67
- scrollableRef = _useDimensionObserver.ref,
68
- scrollableHeight = _useDimensionObserver.height;
69
- if (scrollContainerRef !== null) {
70
- scrollContainerRef.current = scrollableRef.current; // eslint-disable-line
71
- }
72
- var _useDimensionObserver2 = hooks.useDimensionObserver(),
73
- scrolleeRef = _useDimensionObserver2.ref,
74
- scrolleeHeight = _useDimensionObserver2.height;
75
- var scrolledBottomOnce = React.useRef(false);
76
- var scrolledNotBottomOnce = React.useRef(false);
77
- var reachedBottom = React.useRef(false);
78
- var bind = react.useScroll(function (_ref2) {
79
- var _ref2$xy = _slicedToArray(_ref2.xy, 2),
80
- scrollY = _ref2$xy[1];
81
- var newWithArrow = scrollY <= 1;
82
- var maxScrollAmount = scrolleeHeight - scrollableHeight;
83
- var nowReachedBottom = scrollY + 1 >= maxScrollAmount;
84
- if (nowReachedBottom) {
85
- if (!reachedBottom.current) {
86
- if (onScrolledBottom !== null) {
87
- onScrolledBottom({
88
- initial: !scrolledBottomOnce.current
89
- });
90
- }
91
- scrolledBottomOnce.current = true;
92
- }
93
- } else if (reachedBottom.current) {
94
- if (onScrolledNotBottom !== null) {
95
- onScrolledNotBottom({
96
- initial: !scrolledNotBottomOnce.current
97
- });
98
- }
99
- scrolledNotBottomOnce.current = true;
100
- }
101
- if (newWithArrow !== withArrow && showArrow) {
102
- setWithArrow(newWithArrow);
103
- }
104
- reachedBottom.current = nowReachedBottom;
105
- }, {
106
- enabled: !disabled
107
- });
108
-
109
- // need to call scrolled callbacks on initial render also
110
-
111
- React.useEffect(function () {
112
- if (scrolleeHeight > 0 && scrollableHeight > 0 && !disabled) {
113
- setWithArrow(Math.round(scrolleeHeight) > Math.round(scrollableHeight));
114
- var maxScrollAmount = scrolleeHeight - scrollableHeight;
115
- var nowReachedBottom = scrollableRef.current.scrollTop + 1 >= maxScrollAmount;
116
- if (nowReachedBottom) {
117
- if (onScrolledBottom !== null) {
118
- onScrolledBottom({
119
- initial: false
120
- });
121
- }
122
- } else if (onScrolledNotBottom !== null) {
123
- onScrolledNotBottom({
124
- initial: false
125
- });
126
- }
127
- }
128
- }, [scrollableHeight, scrolleeHeight, setWithArrow, disabled]);
129
- React.useEffect(function () {
130
- if (onScrollHeightChange !== null) {
131
- var canScroll = (scrolleeHeight || 0) > (scrollableHeight || 0);
132
- onScrollHeightChange({
133
- scrollableHeight: scrollableHeight,
134
- scrolleeHeight: scrolleeHeight,
135
- canScroll: canScroll
136
- });
137
- }
138
- }, [scrollableHeight, scrolleeHeight, onScrollHeightChange]);
139
- React.useEffect(function () {
140
- if (scrollableRef.current !== null && scrollPosition !== null) {
141
- scrollableRef.current.scrollTop = scrollPosition;
142
- }
143
- }, [scrolleeRef, scrollPosition]);
144
- return /*#__PURE__*/React.createElement("div", {
145
- className: classNames([styles.container, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, styles.withScroll, !disabled), className, className !== null), styles[verticalAlign], verticalAlign !== null), styles.withArrow, showArrow && withArrow), styles.withShadow, withShadow)]),
146
- style: finalStyle
147
- }, /*#__PURE__*/React.createElement("div", Object.assign({
148
- className: styles.scrollable,
149
- ref: scrollableRef
150
- }, bind()), /*#__PURE__*/React.createElement("div", {
151
- className: styles.scrollee,
152
- ref: scrolleeRef
153
- }, children)), !disabled && showArrow ? /*#__PURE__*/React.createElement("div", {
154
- className: styles.arrowContainer
155
- }, /*#__PURE__*/React.createElement("svg", {
156
- xmlns: "http://www.w3.org/2000/svg",
157
- width: "10",
158
- height: "16",
159
- viewBox: "0 0 10 16",
160
- className: styles.arrow,
161
- fill: "currentColor"
162
- }, /*#__PURE__*/React.createElement("polygon", {
163
- // stroke="#000"
164
- // strokeWidth="0.5"
165
- points: ".38 11.38 5 16 9.62 11.38 8.56 10.32 5.75 13.13 5.75 1.61 4.25 1.61 4.25 13.13 1.44 10.32 .38 11.38"
166
- }))) : null);
167
- }
168
- Scroll.defaultProps = defaultProps;
169
- Scroll.propTypes = propTypes;
170
- var Scroll$1 = /*#__PURE__*/React.forwardRef(function (props, ref) {
171
- return /*#__PURE__*/React.createElement(Scroll, Object.assign({
172
- scrollContainerRef: ref
173
- }, props));
174
- });
175
-
176
- module.exports = Scroll$1;