@onepercentio/one-ui 0.16.4 → 0.17.0
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/dist/components/StaticScroller/StaticScroller.d.ts +5 -0
- package/dist/components/StaticScroller/StaticScroller.js +84 -0
- package/dist/components/StaticScroller/StaticScroller.js.map +1 -0
- package/dist/components/StaticScroller/StaticScroller.module.scss +12 -0
- package/dist/components/StaticScroller/index.d.ts +1 -0
- package/dist/components/StaticScroller/index.js +9 -0
- package/dist/components/StaticScroller/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DetailedHTMLProps, HTMLAttributes, PropsWithChildren } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Mantains a static content at the start of the container and when scrolled animates it's concealment
|
|
4
|
+
**/
|
|
5
|
+
export default function StaticScroller({ children, ...props }: PropsWithChildren<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>>): JSX.Element;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
const react_1 = __importStar(require("react"));
|
|
41
|
+
const StaticScroller_module_scss_1 = __importDefault(require("./StaticScroller.module.scss"));
|
|
42
|
+
const lodash_1 = require("lodash");
|
|
43
|
+
/**
|
|
44
|
+
* Mantains a static content at the start of the container and when scrolled animates it's concealment
|
|
45
|
+
**/
|
|
46
|
+
function StaticScroller(_a) {
|
|
47
|
+
var { children } = _a, props = __rest(_a, ["children"]);
|
|
48
|
+
const rootRef = (0, react_1.useRef)(null);
|
|
49
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
50
|
+
const el = rootRef.current;
|
|
51
|
+
let latestScroll;
|
|
52
|
+
const child = el.children[0];
|
|
53
|
+
const checkIfNeedsToHide = (0, lodash_1.debounce)(() => {
|
|
54
|
+
const direction = el.scrollLeft > latestScroll ? "in" : "out";
|
|
55
|
+
if (el.scrollLeft < child.clientWidth) {
|
|
56
|
+
el.scrollTo({
|
|
57
|
+
left: direction === "in" ? child.clientWidth : 0,
|
|
58
|
+
behavior: "smooth",
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
latestScroll = undefined;
|
|
62
|
+
}, 500);
|
|
63
|
+
const throtleSetLast = (0, lodash_1.throttle)((last) => {
|
|
64
|
+
latestScroll = last;
|
|
65
|
+
}, 1000 / 5, {
|
|
66
|
+
leading: true,
|
|
67
|
+
trailing: false,
|
|
68
|
+
});
|
|
69
|
+
const onScroll = () => {
|
|
70
|
+
const min = Math.min(el.scrollLeft, child.clientWidth);
|
|
71
|
+
const opacity = String(1 - min / child.clientWidth);
|
|
72
|
+
child.style.opacity = opacity;
|
|
73
|
+
checkIfNeedsToHide();
|
|
74
|
+
throtleSetLast(el.scrollLeft);
|
|
75
|
+
};
|
|
76
|
+
el.addEventListener("scroll", onScroll);
|
|
77
|
+
return () => {
|
|
78
|
+
el.removeEventListener("scroll", onScroll);
|
|
79
|
+
};
|
|
80
|
+
}, []);
|
|
81
|
+
return (react_1.default.createElement("div", Object.assign({ className: StaticScroller_module_scss_1.default.root }, props, { ref: rootRef }), children));
|
|
82
|
+
}
|
|
83
|
+
exports.default = StaticScroller;
|
|
84
|
+
//# sourceMappingURL=StaticScroller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StaticScroller.js","sourceRoot":"","sources":["../../../src/components/StaticScroller/StaticScroller.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAMe;AACf,8FAAkD;AAClD,mCAA4C;AAE5C;;IAEI;AACJ,SAAwB,cAAc,CAAC,EAKtC;QALsC,EACrC,QAAQ,OAIT,EAHI,KAAK,cAF6B,YAGtC,CADS;IAIR,MAAM,OAAO,GAAG,IA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AAC,UAAU,CAAC,CAAC;QAChC,CAAC,CAAC;QACF,EAAE,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAExC,OAAO,GAAG,EAAE;YACV,EAAE,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,qDAAK,SAAS,EAAE,oCAAM,CAAC,IAAI,IAAM,KAAK,IAAE,GAAG,EAAE,OAAO,KACjD,QAAQ,CACL,CACP,CAAC;AACJ,CAAC;AApDD,iCAoDC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './StaticScroller';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var StaticScroller_1 = require("./StaticScroller");
|
|
8
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StaticScroller_1).default; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/StaticScroller/index.tsx"],"names":[],"mappings":";;;;;;AAAA,mDAA2C;AAAlC,0HAAA,OAAO,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onepercentio/one-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "A set of reusable components created through the development of Onepercent projects",
|
|
5
5
|
"repository": "git@github.com:onepercentio/one-ui.git",
|
|
6
6
|
"author": "Murilo Oliveira de Araujo <murilo.araujo@onepercent.io>",
|