oolib 2.35.2 → 2.36.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.
@@ -16,24 +16,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.TabBarStyle2 = exports.TabBarStyle1 = void 0;
18
18
  var react_1 = __importDefault(require("react"));
19
+ var useScrollBar_1 = require("../../utils/customHooks/useScrollBar");
20
+ var Buttons_1 = require("../Buttons");
19
21
  var index_styled_1 = require("./index.styled");
20
22
  var Base = function (_a) {
21
23
  var id = _a.id, options = _a.options, valueProp = _a.value, onChange = _a.onChange, style = _a.style, errorTabs = _a.errorTabs, _b = _a.tabBarStyle, tabBarStyle = _b === void 0 ? '1' : _b, saveValueAsString = _a.saveValueAsString, M = _a.M, S = _a.S, _size = _a.size //use any one of these 3
22
24
  ;
23
25
  var size = _size || (S ? 'S' : 'M'); //defaults to M
24
26
  var value = saveValueAsString ? options.find(function (d) { return d.value === valueProp; }) : valueProp;
27
+ var _c = (0, useScrollBar_1.useScrollBar)(), scrollContainerRef = _c.scrollContainerRef, scrollX = _c.scrollX, scrollIsAtEnd = _c.scrollIsAtEnd, slide = _c.slide, checkScrollPosition = _c.checkScrollPosition;
25
28
  var handleClick = function (v) {
26
29
  onChange && onChange(id, saveValueAsString ? v.value : v);
27
30
  };
28
31
  return (react_1.default.createElement(index_styled_1.TabBarStyled, { size: size, style: style },
29
32
  react_1.default.createElement(index_styled_1.TabBarContainerStyled, { id: id },
30
- react_1.default.createElement(index_styled_1.TabBarRowStyled, { id: id }, options.map(function (op) {
33
+ scrollX !== 0 && (react_1.default.createElement(Buttons_1.ButtonGhost, { S: true, icon: 'CaretLeft', style: { height: '100%' }, onClick: function () { return slide("left"); } })),
34
+ react_1.default.createElement(index_styled_1.TabBarRowStyled, { id: id, ref: scrollContainerRef, onScroll: checkScrollPosition }, options.map(function (op) {
31
35
  var tabHasError = errorTabs && errorTabs.some(function (tab) { return tab.value === op.value; });
32
36
  var tabIsActive = value && op.value === value.value;
33
37
  return (react_1.default.createElement(index_styled_1.TabBarTabWrapper, { tabBarStyle: tabBarStyle, key: op.value, active: tabIsActive, error: tabHasError },
34
38
  react_1.default.createElement(index_styled_1.TabBarTabStyled, { size: size, active: tabIsActive, error: tabHasError, tabBarStyle: tabBarStyle, onClick: function () { return handleClick(op); } },
35
39
  react_1.default.createElement(index_styled_1.STYLED_SANS_2, { semibold: tabBarStyle === "1" }, op.display))));
36
- })))));
40
+ })),
41
+ !scrollIsAtEnd && (react_1.default.createElement(Buttons_1.ButtonGhost, { S: true, icon: 'CaretRight', style: { height: '100%' }, onClick: function () { return slide("right"); } })))));
37
42
  };
38
43
  var TabBarStyle1 = function (props) { return react_1.default.createElement(Base, __assign({}, props, { tabBarStyle: "1" })); };
39
44
  exports.TabBarStyle1 = TabBarStyle1;
@@ -78,19 +78,19 @@ exports.TabBarStyled = styled_components_1.default.div(templateObject_11 || (tem
78
78
  var size = _a.size;
79
79
  return size === 'S' ? '3rem' : '4rem';
80
80
  });
81
- exports.TabBarContainerStyled = styled_components_1.default.div(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n width: fit-content;\n height: 100%;\n"], ["\n width: fit-content;\n height: 100%;\n"])));
82
- exports.TabBarRowStyled = styled_components_1.default.div(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n display: flex;\n height: 100%;\n"], ["\n display: flex;\n height: 100%;\n"])));
83
- exports.TabBarTabWrapper = styled_components_1.default.div(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n ", "\n display: flex;\n align-items: center;\n min-width: 0; //so that ellipsis works on the text within\n"], ["\n ", "\n display: flex;\n align-items: center;\n min-width: 0; //so that ellipsis works on the text within\n"])), function (_a) {
81
+ exports.TabBarContainerStyled = styled_components_1.default.div(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n /* width: fit-content; // */\n /* width: 600px; */\n height: 100%;\n display: flex;\n align-items: center;\n"], ["\n /* width: fit-content; // */\n /* width: 600px; */\n height: 100%;\n display: flex;\n align-items: center;\n"])));
82
+ exports.TabBarRowStyled = styled_components_1.default.div(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n display: flex;\n height: 100%;\n white-space: nowrap;\n max-width: 100%;\n overflow-x: hidden; \n scroll-behavior: smooth;\n &::-webkit-scrollbar {\n background: transparent; /* make scrollbar transparent */\n -webkit-appearance: none;\n width: 0;\n height: 0;\n }\n"], ["\n display: flex;\n height: 100%;\n white-space: nowrap;\n max-width: 100%;\n overflow-x: hidden; \n scroll-behavior: smooth;\n &::-webkit-scrollbar {\n background: transparent; /* make scrollbar transparent */\n -webkit-appearance: none;\n width: 0;\n height: 0;\n }\n"])));
83
+ exports.TabBarTabWrapper = styled_components_1.default.div(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n ", "\n display: flex;\n align-items: center;\n /* min-width: 0; //so that ellipsis works on the text within */\n"], ["\n ", "\n display: flex;\n align-items: center;\n /* min-width: 0; //so that ellipsis works on the text within */\n"])), function (_a) {
84
84
  var tabBarStyle = _a.tabBarStyle;
85
85
  return tabBarStyle === "1"
86
86
  ? tabBarWrapperStyle1
87
87
  : tabBarStyle === "2" && tabBarWrapperStyle2;
88
88
  });
89
- exports.TabBarTabStyled = styled_components_1.default.button(templateObject_15 || (templateObject_15 = __makeTemplateObject(["\n padding: 0 2rem;\n height: 100%;\n cursor: pointer;\n color: ", ";\n background-color: ", ";\n\n border: 0;\n :hover {\n background-color: ", ";\n }\n\n ", "\n"], ["\n padding: 0 2rem;\n height: 100%;\n cursor: pointer;\n color: ", ";\n background-color: ", ";\n\n border: 0;\n :hover {\n background-color: ", ";\n }\n\n ", "\n"])), greyColor100, none, none, function (_a) {
89
+ exports.TabBarTabStyled = styled_components_1.default.button(templateObject_15 || (templateObject_15 = __makeTemplateObject(["\n padding: 0 2rem;\n height: 100%;\n cursor: pointer;\n color: ", ";\n background-color: ", ";\n border: 0;\n :hover {\n background-color: ", ";\n }\n\n ", "\n"], ["\n padding: 0 2rem;\n height: 100%;\n cursor: pointer;\n color: ", ";\n background-color: ", ";\n border: 0;\n :hover {\n background-color: ", ";\n }\n\n ", "\n"])), greyColor100, none, none, function (_a) {
90
90
  var tabBarStyle = _a.tabBarStyle;
91
91
  return tabBarStyle === "1"
92
92
  ? tabBarTabStyle1
93
93
  : tabBarStyle === "2" && tabBarTabStyle2;
94
94
  });
95
- exports.STYLED_SANS_2 = (0, styled_components_1.default)(Typo_1.SANS_2)(templateObject_16 || (templateObject_16 = __makeTemplateObject(["\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n"], ["\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n"])));
95
+ exports.STYLED_SANS_2 = (0, styled_components_1.default)(Typo_1.SANS_2)(templateObject_16 || (templateObject_16 = __makeTemplateObject(["\n /* width: max-content; */\n /* white-space: nowrap; */\n /* text-overflow: ellipsis; */\n /* overflow: hidden; */\n"], ["\n /* width: max-content; */\n /* white-space: nowrap; */\n /* text-overflow: ellipsis; */\n /* overflow: hidden; */\n"])));
96
96
  var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16;
@@ -42,7 +42,7 @@ var SIZES = {
42
42
  };
43
43
  var commonStyle = function (_a) {
44
44
  var size = _a.size;
45
- return "\n padding: ".concat(size === "XS" ? "0 .5rem" : "0 1rem", ";\n position: relative;\n display: inline-flex;\n column-gap: 1rem;\n align-items: \"center\";\n border-radius:0.2rem;\n white-space: nowrap;\n\theight: ").concat(SIZES[size], ";\n max-width: 100%;\n");
45
+ return "\n padding: ".concat(size === "XS" ? "0 .5rem" : "0 1rem", ";\n position: relative;\n display: inline-flex;\n column-gap: 1rem;\n align-items: center;\n border-radius:0.2rem;\n white-space: nowrap;\n\theight: ").concat(SIZES[size], ";\n max-width: 100%;\n");
46
46
  };
47
47
  var blueHover = function (_a) {
48
48
  var invert = _a.invert, colors = _a.colors;
@@ -1,6 +1,7 @@
1
- export function Tooltip({ text, position, style, children }: {
1
+ export function Tooltip({ text, position, style, children, popOutOfOverflowHiddenParent }: {
2
2
  text: any;
3
3
  position?: string;
4
4
  style: any;
5
5
  children: any;
6
+ popOutOfOverflowHiddenParent?: boolean;
6
7
  }): any;
@@ -25,28 +25,51 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Tooltip = void 0;
27
27
  var react_1 = __importStar(require("react"));
28
+ var usePopOutOfOverflowHiddenParent_1 = require("../../utils/usePopOutOfOverflowHiddenParent");
28
29
  var Typo_1 = require("../Typo");
29
30
  var styled_1 = require("./styled");
30
31
  var Tooltip = function (_a) {
31
- var text = _a.text, _b = _a.position, position = _b === void 0 ? 'top' : _b, style = _a.style, children = _a.children;
32
- var _c = (0, react_1.useState)(false), isHovered = _c[0], setIsHovered = _c[1];
33
- var _d = (0, react_1.useState)(false), isFocused = _d[0], setIsFocused = _d[1];
32
+ var text = _a.text, _b = _a.position, position = _b === void 0 ? 'top' : _b, style = _a.style, children = _a.children, _c = _a.popOutOfOverflowHiddenParent, popOutOfOverflowHiddenParent = _c === void 0 ? true : _c;
33
+ var _d = (0, react_1.useState)(false), isHovered = _d[0], setIsHovered = _d[1];
34
+ var _e = (0, react_1.useState)(false), isFocused = _e[0], setIsFocused = _e[1];
35
+ var _f = (0, react_1.useState)(false), isClicked = _f[0], setIsClicked = _f[1];
36
+ var _g = (0, react_1.useState)(false), isTooltipOpen = _g[0], setIsTooltipOpen = _g[1];
34
37
  var targetRef = (0, react_1.useRef)(null);
35
- var handleClick = function (e) {
36
- e.preventDefault();
37
- if (targetRef.current) {
38
- targetRef.current.blur();
38
+ var _h = (0, usePopOutOfOverflowHiddenParent_1.usePopOutOfOverflowHiddenParent)(popOutOfOverflowHiddenParent), trackerRef = _h.trackerRef, applyFixedPos = _h.applyFixedPos, removeFixedPos = _h.removeFixedPos;
39
+ (0, react_1.useEffect)(function () {
40
+ if (isHovered || isFocused) {
41
+ applyFixedPos();
39
42
  }
40
- };
41
- return (react_1.default.createElement(styled_1.StyledWrapper, null,
42
- react_1.default.createElement(styled_1.StyledTooltipTarget, { onMouseEnter: function () { return setIsHovered(true); }, onMouseLeave: function () { return setIsHovered(false); }, onFocus: function () { return setIsFocused(true); }, onBlur: function () { return setIsFocused(false); }, onClick: handleClick, ref: targetRef, isFocused: isFocused, tabIndex: 0 }, children),
43
- isHovered && (react_1.default.createElement(styled_1.StyledTooltip, { position: position, show: isHovered, style: style },
44
- react_1.default.createElement(Typo_1.SANS_2, null, text),
45
- react_1.default.createElement(styled_1.StyledArrowOutline, { position: position },
46
- react_1.default.createElement(styled_1.StyledArrow, { position: position })))),
47
- isFocused && (react_1.default.createElement(styled_1.StyledTooltip, { position: position, show: isFocused, style: style },
43
+ else {
44
+ removeFixedPos();
45
+ }
46
+ }, [isHovered, isFocused]);
47
+ var ShowTooltip = function () {
48
+ return (react_1.default.createElement(styled_1.StyledTooltip, { ref: trackerRef, isOpen: isTooltipOpen, position: position, show: isHovered, style: style },
48
49
  react_1.default.createElement(Typo_1.SANS_2, null, text),
49
50
  react_1.default.createElement(styled_1.StyledArrowOutline, { position: position },
50
- react_1.default.createElement(styled_1.StyledArrow, { position: position }))))));
51
+ react_1.default.createElement(styled_1.StyledArrow, { position: position }))));
52
+ };
53
+ return (react_1.default.createElement(styled_1.StyledWrapper, null,
54
+ react_1.default.createElement(styled_1.StyledTooltipTarget, { onMouseEnter: function () {
55
+ if (!isClicked) {
56
+ setIsHovered(true);
57
+ }
58
+ }, onMouseLeave: function () {
59
+ if (!isClicked) {
60
+ setIsHovered(false);
61
+ }
62
+ }, onClick: function () {
63
+ if (isClicked) {
64
+ setIsTooltipOpen(false);
65
+ }
66
+ else {
67
+ setIsTooltipOpen(true);
68
+ }
69
+ // setIsClicked(!isClicked);
70
+ // setIsHovered(!isHovered);
71
+ }, onFocus: function () { return setIsFocused(true); }, onBlur: function () { setIsFocused(false), setIsClicked(false); }, ref: targetRef, isFocused: isFocused, tabIndex: 0 }, children),
72
+ isHovered && (react_1.default.createElement(ShowTooltip, null)),
73
+ isFocused && (react_1.default.createElement(ShowTooltip, null))));
51
74
  };
52
75
  exports.Tooltip = Tooltip;
@@ -32,7 +32,7 @@ var styled_components_1 = __importStar(require("styled-components"));
32
32
  var themes_1 = require("../../themes");
33
33
  var mixins_1 = require("../../themes/mixins");
34
34
  var util_1 = require("./util");
35
- exports.StyledWrapper = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: relative; // made this wrapper with styled.component to ensure its\n width: fit-content; // engine will make this 'fit-content' compatible with firefox/safari\n text-align: center;\n cursor: pointer;\n"], ["\n position: relative; // made this wrapper with styled.component to ensure its\n width: fit-content; // engine will make this 'fit-content' compatible with firefox/safari\n text-align: center;\n cursor: pointer;\n"])));
35
+ exports.StyledWrapper = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: relative; // made this wrapper with styled.component to ensure its\n width: fit-content; // engine will make this 'fit-content' compatible with firefox/safari\n text-align: left;\n cursor: pointer;\n"], ["\n position: relative; // made this wrapper with styled.component to ensure its\n width: fit-content; // engine will make this 'fit-content' compatible with firefox/safari\n text-align: left;\n cursor: pointer;\n"])));
36
36
  var greyColor15 = themes_1.colors.greyColor15, white = themes_1.colors.white;
37
37
  var clipPaths = {
38
38
  top: "0% 0%, 47% 65.4%, 52% 65.4%, 100% 0",
@@ -0,0 +1,8 @@
1
+ export function useScrollBar(): {
2
+ scrollContainerRef: any;
3
+ scrollX: any;
4
+ scrollIsAtEnd: any;
5
+ slide: (direction: any) => void;
6
+ checkScrollPosition: () => void;
7
+ setScrollIsAtEnd: any;
8
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useScrollBar = void 0;
4
+ var react_1 = require("react");
5
+ /**
6
+ * @summary The hook sets the initial state values of scrollX and scrollIsAtEnd,
7
+ * and uses an effect to check whether the width of the scrollable element is less than or equal to its parent element's width.
8
+ * If so, it sets scrollIsAtEnd to true.
9
+ * @returns scrollContainerRef: reference to the scrollable element. You need to pass this reference to the ref attribute of your scrollable element in your component.
10
+ * scrollX: The current scroll position in pixels, from the left side of the content.
11
+ * scrollIsAtEnd: A boolean value that indicates whether the scroll bar is at the end of the content.
12
+ * slide (shift: string): A function that shifts the scroll position by shifting pixels by directions string provided.
13
+ * checkScrollPosition: A function that updates the scrollX and scrollIsAtEnd values based on the current scroll position.
14
+ */
15
+ var useScrollBar = function () {
16
+ var _a = (0, react_1.useState)(0), scrollX = _a[0], setScrollX = _a[1];
17
+ var _b = (0, react_1.useState)(false), scrollIsAtEnd = _b[0], setScrollIsAtEnd = _b[1];
18
+ var scrollContainerRef = (0, react_1.useRef)(null);
19
+ var slide = function (direction) {
20
+ var _a = scrollContainerRef.current, scrollWidth = _a.scrollWidth, offsetWidth = _a.offsetWidth, scrollLeft = _a.scrollLeft;
21
+ if (direction === "left") {
22
+ var newScrollLeft = Math.max(scrollLeft - window.innerWidth, 0); // // ensures that the content is always visible within the scrollable element and no part of it is hidden.
23
+ if (scrollLeft === newScrollLeft) {
24
+ setScrollIsAtEnd(true);
25
+ }
26
+ scrollContainerRef.current.scrollTo({
27
+ left: newScrollLeft,
28
+ behavior: "smooth"
29
+ });
30
+ }
31
+ else if (direction === "right") {
32
+ var newScrollLeft = Math.min(scrollLeft + window.innerWidth, scrollWidth - offsetWidth); // // ensures that the content is always visible within the scrollable element and no part of it is hidden.
33
+ if (scrollLeft === newScrollLeft) {
34
+ setScrollIsAtEnd(true);
35
+ }
36
+ scrollContainerRef.current.scrollTo({
37
+ left: newScrollLeft,
38
+ behavior: "smooth"
39
+ });
40
+ }
41
+ };
42
+ var checkScrollPosition = function () {
43
+ setScrollX(scrollContainerRef.current.scrollLeft);
44
+ if (Math.floor(scrollContainerRef.current.scrollWidth - scrollContainerRef.current.scrollLeft) <= scrollContainerRef.current.offsetWidth) {
45
+ setScrollIsAtEnd(true);
46
+ }
47
+ else {
48
+ setScrollIsAtEnd(false);
49
+ }
50
+ };
51
+ (0, react_1.useEffect)(function () {
52
+ if (scrollContainerRef.current.offsetWidth >= scrollContainerRef.current.scrollWidth) {
53
+ setScrollIsAtEnd(true);
54
+ }
55
+ }, []);
56
+ return { scrollContainerRef: scrollContainerRef, scrollX: scrollX, scrollIsAtEnd: scrollIsAtEnd, slide: slide, checkScrollPosition: checkScrollPosition, setScrollIsAtEnd: setScrollIsAtEnd };
57
+ };
58
+ exports.useScrollBar = useScrollBar;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oolib",
3
- "version": "2.35.2",
3
+ "version": "2.36.0",
4
4
  "description": " OKE Component Library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",