@koine/react 1.0.5 → 1.0.8

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 (159) hide show
  1. package/Alert/Alert.js +18 -0
  2. package/Alert/index.js +1 -0
  3. package/Animations/Reveal.js +17 -0
  4. package/Animations/Underline.js +15 -0
  5. package/Animations/index.js +3 -0
  6. package/Animations/useReveal.js +70 -0
  7. package/Autocomplete/AutocompleteDownshift.js +158 -0
  8. package/Autocomplete/AutocompleteDownshiftMultiselect.js +353 -0
  9. package/Autocomplete/AutocompleteMui.js +172 -0
  10. package/Autocomplete/AutocompleteReach.js +112 -0
  11. package/Autocomplete/components.js +89 -0
  12. package/Autocomplete/helpers.js +28 -0
  13. package/Autocomplete/index.js +3 -0
  14. package/Bg/BgColor.js +33 -0
  15. package/Bg/BgPhoto.js +59 -0
  16. package/Bg/BgSvg.js +15 -0
  17. package/Bg/index.js +3 -0
  18. package/Breadcrumbs/Breadcrumbs.js +70 -0
  19. package/Breadcrumbs/index.js +1 -0
  20. package/Buttons/Button.js +79 -0
  21. package/Buttons/ButtonComposite.d.ts +1 -1
  22. package/Buttons/ButtonComposite.js +53 -0
  23. package/Buttons/ButtonFab.js +8 -0
  24. package/Buttons/ButtonLink.js +16 -0
  25. package/Buttons/IconButton.js +19 -0
  26. package/Buttons/index.js +5 -0
  27. package/Calendar/CalendarDaygridCell.js +52 -0
  28. package/Calendar/CalendarDaygridNav.js +23 -0
  29. package/Calendar/CalendarDaygridTable.js +49 -0
  30. package/Calendar/CalendarLegend.js +12 -0
  31. package/Calendar/calendar-api-google.js +97 -0
  32. package/Calendar/index.js +6 -0
  33. package/Calendar/types.js +1 -0
  34. package/Calendar/useCalendar.js +166 -0
  35. package/Calendar/utils.js +197 -0
  36. package/Carousel/Carousel.js +378 -0
  37. package/Carousel/CarouselCss.js +39 -0
  38. package/Carousel/index.js +1 -0
  39. package/Collapsable/Collapsable.js +132 -0
  40. package/Collapsable/index.js +1 -0
  41. package/Debug/Debug.js +21 -0
  42. package/Debug/index.js +1 -0
  43. package/Dialog/Dialog.js +93 -0
  44. package/Dialog/index.js +1 -0
  45. package/Editor/Editor--tiptap.js +21 -0
  46. package/Editor/components.d.ts +1 -2
  47. package/Editor/components.js +28 -0
  48. package/Editor/index.js +1 -0
  49. package/Favicon/FaviconTags.js +14 -0
  50. package/Favicon/index.js +1 -0
  51. package/Forms/Checkbox/Checkbox.js +24 -0
  52. package/Forms/Checkbox/index.js +1 -0
  53. package/Forms/Feedback/Feedback.js +10 -0
  54. package/Forms/Feedback/index.js +1 -0
  55. package/Forms/Field/Field.js +61 -0
  56. package/Forms/Field/FieldControl.js +45 -0
  57. package/Forms/Field/FieldHint.js +6 -0
  58. package/Forms/Field/index.js +2 -0
  59. package/Forms/Form/Form.js +64 -0
  60. package/Forms/Form/index.js +1 -0
  61. package/Forms/Input/Input.js +25 -0
  62. package/Forms/Input/index.js +1 -0
  63. package/Forms/InputGroup/InputGroup.js +42 -0
  64. package/Forms/InputGroup/index.js +1 -0
  65. package/Forms/Label/Label.js +24 -0
  66. package/Forms/Label/index.js +1 -0
  67. package/Forms/Password/Password.js +32 -0
  68. package/Forms/Password/index.js +1 -0
  69. package/Forms/Radio/Radio.js +31 -0
  70. package/Forms/Radio/index.js +1 -0
  71. package/Forms/Switch/Switch.js +50 -0
  72. package/Forms/Switch/index.js +1 -0
  73. package/Forms/Textarea/Textarea.js +15 -0
  74. package/Forms/Textarea/TextareaRich.js +44 -0
  75. package/Forms/Textarea/index.js +2 -0
  76. package/Forms/Toggle/Toggle.js +79 -0
  77. package/Forms/Toggle/index.js +1 -0
  78. package/Forms/Toggle/useToggle.js +143 -0
  79. package/Forms/antispam.js +56 -0
  80. package/Forms/helpers.js +44 -0
  81. package/Forms/index.js +17 -0
  82. package/Forms/styles.js +60 -0
  83. package/Gauge/Gauge.js +102 -0
  84. package/Grid/Grid.js +79 -0
  85. package/Grid/index.js +1 -0
  86. package/Hamburger/Hamburger.js +55 -0
  87. package/Hamburger/index.js +1 -0
  88. package/Header/index.js +1 -0
  89. package/Header/useHeader.js +30 -0
  90. package/Hidden/Hidden.js +14 -0
  91. package/Hidden/index.js +1 -0
  92. package/Img/Img.js +34 -0
  93. package/Img/index.js +1 -0
  94. package/Link/Link.js +2 -0
  95. package/Link/LinkBlank.d.ts +1 -1
  96. package/Link/LinkBlank.js +28 -0
  97. package/Link/index.js +2 -0
  98. package/Menu/Menu.js +11 -0
  99. package/Menu/index.js +1 -0
  100. package/MenuItem/MenuItem.js +20 -0
  101. package/MenuItem/index.js +1 -0
  102. package/Meta/Meta.js +4 -0
  103. package/Meta/index.js +1 -0
  104. package/NoJs/NoJs.js +6 -0
  105. package/NoJs/index.js +1 -0
  106. package/Pagination/PaginationNav.js +87 -0
  107. package/Pagination/PaginationResults.js +10 -0
  108. package/Pagination/index.js +2 -0
  109. package/Pill/Pill.js +37 -0
  110. package/Pill/index.js +1 -0
  111. package/Progress/ProgressCircular.js +38 -0
  112. package/Progress/ProgressLinear.js +34 -0
  113. package/Progress/ProgressOverlay.js +40 -0
  114. package/Progress/index.js +3 -0
  115. package/Rating/Rating.js +93 -0
  116. package/Rating/index.js +45 -0
  117. package/Select/SelectDownshift.js +38 -0
  118. package/Select/components.js +20 -0
  119. package/Select/index.js +3 -0
  120. package/Sidebar/Sidebar.js +48 -0
  121. package/Sidebar/index.js +1 -0
  122. package/Spacing/Spacing.js +47 -0
  123. package/Spacing/index.js +1 -0
  124. package/Sticky/Sticky.js +220 -0
  125. package/Sticky/StickyCss.js +6 -0
  126. package/Sticky/index.js +1 -0
  127. package/Tabs/Tabs.js +67 -0
  128. package/Tabs/index.js +1 -0
  129. package/Typography/CopyPasteVisible.js +6 -0
  130. package/Typography/Native.js +47 -0
  131. package/Typography/ReadMore.js +71 -0
  132. package/Typography/TextLoop.js +45 -0
  133. package/Typography/TypeStairs.js +46 -0
  134. package/Typography/index.js +5 -0
  135. package/helpers/index.js +19 -0
  136. package/hooks/index.js +5 -0
  137. package/hooks/useDateLocale.js +30 -0
  138. package/hooks/useFocus.js +11 -0
  139. package/hooks/usePrevious.js +8 -0
  140. package/hooks/useTraceUpdate.js +20 -0
  141. package/hooks/useWindowSize.js +13 -0
  142. package/index.js +36 -0
  143. package/index.umd.js +232 -239
  144. package/package.json +15 -9
  145. package/styles/Body.js +17 -0
  146. package/styles/Global.js +50 -0
  147. package/styles/classed.js +11 -0
  148. package/styles/index.js +7 -0
  149. package/styles/media.js +150 -0
  150. package/styles/spacing.d.ts +6 -6
  151. package/styles/spacing.js +46 -0
  152. package/styles/styled.d.ts +2 -2
  153. package/styles/styled.js +27 -0
  154. package/styles/theme--vanilla.js +53 -0
  155. package/styles/theme.d.ts +0 -7
  156. package/styles/theme.js +38 -0
  157. package/types.js +1 -0
  158. package/typings.d.ts +21 -0
  159. package/index.esm.js +0 -9456
@@ -0,0 +1,40 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect } from "react";
3
+ import styled from "styled-components";
4
+ import { m } from "framer-motion";
5
+ import { ProgressCircular } from "./ProgressCircular";
6
+ import { ProgressLinear } from "./ProgressLinear";
7
+ import { useHeader } from "../Header";
8
+ const ProgressOverlayWrap = styled(m.div) `
9
+ z-index: 10000;
10
+ position: fixed;
11
+ top: 0;
12
+ left: 0;
13
+ right: 0;
14
+ bottom: 0;
15
+ pointer-events: none;
16
+ cursor: wait;
17
+ `;
18
+ const ProgressOverlayCenterer = styled.div `
19
+ position: absolute;
20
+ top: 0;
21
+ left: 0;
22
+ right: 0;
23
+ bottom: 0;
24
+ display: flex;
25
+ align-items: center;
26
+ justify-content: center;
27
+ background: var(--progress-overlay-bg);
28
+ `;
29
+ export const ProgressOverlay = ({ running }) => {
30
+ const [, , headerHeight] = useHeader();
31
+ // const [progress, setProgress] = useState(0);
32
+ useEffect(() => {
33
+ document.body.style.cursor = running ? "wait" : "";
34
+ }, [running]);
35
+ return (_jsxs(ProgressOverlayWrap, Object.assign({ animate: {
36
+ opacity: running ? 1 : 0,
37
+ }, initial: { opacity: 0 }, transition: { type: "easeInOut" } }, { children: [_jsx(ProgressLinear, { bg: "var(--accent400)", fg: "var(--accent300)", done: !running }), _jsx(ProgressOverlayCenterer, Object.assign({ style: {
38
+ top: headerHeight + "px",
39
+ } }, { children: _jsx(ProgressCircular, { size: "50px", color: "var(--accent300)" }) }))] })));
40
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./ProgressCircular";
2
+ export * from "./ProgressLinear";
3
+ export * from "./ProgressOverlay";
@@ -0,0 +1,93 @@
1
+ import { __rest } from "tslib";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useCallback, useEffect, useState } from "react";
4
+ import styled from "styled-components";
5
+ import { uid } from "@koine/utils";
6
+ export const RatingStarRoot = styled.svg `
7
+ display: inline-block;
8
+ vertical-align: middle;
9
+ margin-right: 1px;
10
+ `;
11
+ export const RatingStar = (_a) => {
12
+ var { value, colorBg = "#FFD84C", colorStroke = "#947813", size } = _a, props = __rest(_a, ["value", "colorBg", "colorStroke", "size"]);
13
+ const id = uid("Star");
14
+ return (_jsxs(RatingStarRoot, Object.assign({ viewBox: "0 0 16 16", "data-value": value, width: size + "px", height: size + "px" }, props, { children: [_jsx("defs", { children: _jsxs("linearGradient", Object.assign({ id: id, x1: "0", y1: "0", x2: "1", y2: "0" }, { children: [_jsx("stop", { offset: "0", stopColor: colorBg }), _jsx("stop", { offset: value, stopColor: colorBg }), _jsx("stop", { offset: value, stopColor: "rgba(255, 255, 255, 0)" })] })) }), _jsx("path", { stroke: colorStroke, strokeWidth: "0.5", fill: `url(#${id})`, d: "M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.283.95l-3.523 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z" })] })));
15
+ };
16
+ export const RatingDetails = styled.span `
17
+ padding-left: 0.5em;
18
+ font-size: 12px;
19
+ color: var(--grey100);
20
+
21
+ &:before {
22
+ content: "(";
23
+ }
24
+ &:after {
25
+ content: ")";
26
+ }
27
+ `;
28
+ export const RatingCount = styled.span ``;
29
+ export const RatingValue = styled.span `
30
+ display: none;
31
+ `;
32
+ export const RatingRoot = styled.div `
33
+ display: flex;
34
+ align-items: center;
35
+
36
+ &:hover ${RatingValue} {
37
+ display: inline-block;
38
+ }
39
+ `;
40
+ export const Rating = ({ value = 0, count, min = 0, max = 5, showDetails = true, colorBg, colorStroke, starSize = 16, }) => {
41
+ const id = uid("Rating");
42
+ const [currentValue /* , _setCurrentValue */] = useState(value);
43
+ const [stars, setStars] = useState([]);
44
+ const getStars = useCallback((activeCount) => {
45
+ const stars = [];
46
+ for (let currentStar = min + 1; currentStar < max + 1; currentStar++) {
47
+ let starValue;
48
+ const roundedActiveCount = Math.floor(activeCount);
49
+ // we have a rating of 3.4, when we get to the 4th star:
50
+ if (roundedActiveCount === currentStar - 1) {
51
+ starValue = 1 - (currentStar - activeCount);
52
+ }
53
+ else if (roundedActiveCount >= currentStar) {
54
+ starValue = 1;
55
+ }
56
+ else {
57
+ starValue = 0;
58
+ }
59
+ stars.push({ value: starValue });
60
+ }
61
+ return stars;
62
+ }, [min, max]);
63
+ useEffect(() => {
64
+ setStars(getStars(currentValue));
65
+ }, [currentValue, getStars]);
66
+ // function updateStars(index) {
67
+ // var currentActive = stars.filter((x) => x.active);
68
+ // if (index !== currentActive.length) {
69
+ // setStars(getStars(index));
70
+ // }
71
+ // }
72
+ // function handleMouseOver(event) {
73
+ // let index = Number(event.currentTarget.getAttribute("data-idx")) + 1;
74
+ // updateStars(index);
75
+ // }
76
+ // function handleMouseLeave() {
77
+ // setStars(getStars());
78
+ // }
79
+ // const handleClick = useCallback((event) => {
80
+ // let index = Number(event.currentTarget.getAttribute("data-idx"));
81
+ // let value = index = index + 1;
82
+ // if (value !== currentValue) {
83
+ // setStars(getStars(value));
84
+ // setCurrentValue(value);
85
+ // onChange(value);
86
+ // }
87
+ // }, [onChange];
88
+ return (_jsxs(RatingRoot, { children: [stars.map((star, idx) => (_jsx(RatingStar, { idx: idx, dataIdx: idx, size: starSize,
89
+ // onMouseOver={handleMouseOver}
90
+ // onMouseLeave={handleMouseLeave}
91
+ // onClick={handleClick}
92
+ value: star.value, colorBg: colorBg, colorStroke: colorStroke }, id + idx))), " ", showDetails && count && (_jsxs(RatingDetails, { children: [_jsx(RatingCount, { children: count }), _jsx(RatingValue, { children: ` - ${value}` })] }))] }));
93
+ };
@@ -0,0 +1,45 @@
1
+ export * from "./Rating";
2
+ const RATING_WORDS = {
3
+ 0: "Worst",
4
+ 1: "Bad",
5
+ 2: "Mediocre",
6
+ 3: "Good",
7
+ 4: "Great",
8
+ 4.5: "Excellent",
9
+ 5: "Best",
10
+ };
11
+ export const getRatingWord = (value, precision = 0.5) => {
12
+ let buffer = 0;
13
+ let word;
14
+ while (buffer < value) {
15
+ // @ts-expect-error can't remember
16
+ word = RATING_WORDS[buffer];
17
+ buffer += precision;
18
+ }
19
+ return word;
20
+ };
21
+ export const getRatingValue = (value) => {
22
+ const converted = convertRange(value, [0, 5], [0, 10]);
23
+ if (converted % 1 === 0) {
24
+ return converted;
25
+ }
26
+ return converted.toFixed(1);
27
+ };
28
+ /**
29
+ * @see https://stackoverflow.com/a/14224813
30
+ */
31
+ export function convertRange(value, r1, r2) {
32
+ return ((value - r1[0]) * (r2[1] - r2[0])) / (r1[1] - r1[0]) + r2[0];
33
+ }
34
+ export const deriveRating = (title, date, minValue = 3.8, maxValue = 5, minQuantity = 9) => {
35
+ const entityTime = date.getTime();
36
+ const nowTime = new Date().getTime();
37
+ const length = title.length;
38
+ const value = Number(convertRange(length, [0, 90], [minValue, maxValue]).toFixed(2));
39
+ const timeDifference = convertRange(nowTime - entityTime, [0, 10000000000000], [minQuantity, 999999]);
40
+ const count = Math.round(timeDifference / length);
41
+ return {
42
+ value,
43
+ count,
44
+ };
45
+ };
@@ -0,0 +1,38 @@
1
+ export const Select = null;
2
+ // import { useSelect } from "downshift";
3
+ // export type SelectProps = {
4
+ // options?: Option[];
5
+ // };
6
+ // export const Select = ({ options = [] }: SelectProps) => {
7
+ // const {
8
+ // isOpen,
9
+ // selectedItem,
10
+ // getToggleButtonProps,
11
+ // getLabelProps,
12
+ // getMenuProps,
13
+ // highlightedIndex,
14
+ // getItemProps,
15
+ // } = useSelect({ items: options });
16
+ // return (
17
+ // <div>
18
+ // <label {...getLabelProps()}>Choose an element:</label>
19
+ // <button type="button" {...getToggleButtonProps()}>
20
+ // {selectedItem || "Elements"}
21
+ // </button>
22
+ // <ul {...getMenuProps()}>
23
+ // {isOpen &&
24
+ // options.map((item, index) => (
25
+ // <li
26
+ // style={
27
+ // highlightedIndex === index ? { backgroundColor: "#bde4ff" } : {}
28
+ // }
29
+ // key={`${item.value}${index}`}
30
+ // {...getItemProps({ item, index })}
31
+ // >
32
+ // {item.label}
33
+ // </li>
34
+ // ))}
35
+ // </ul>
36
+ // </div>
37
+ // );
38
+ // };
@@ -0,0 +1,20 @@
1
+ import { __rest } from "tslib";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { forwardRef } from "react";
4
+ import styled from "styled-components";
5
+ import { m } from "framer-motion";
6
+ import { BsBoxArrowInDown as IconCollapse } from "react-icons/bs";
7
+ export const SelectArrowStyled = styled(m.span) `
8
+ display: inline-flex;
9
+ align-items: center;
10
+ justify-content: center;
11
+ width: 2em;
12
+
13
+ &:not([disabled]) {
14
+ cursor: pointer;
15
+ }
16
+ `;
17
+ export const SelectArrow = forwardRef(function SelectArrow(_a, ref) {
18
+ var { isOpen } = _a, props = __rest(_a, ["isOpen"]);
19
+ return (_jsx(SelectArrowStyled, Object.assign({ animate: { rotate: isOpen ? 180 : 0 }, ref: ref }, props, { children: _jsx(IconCollapse, {}) })));
20
+ });
@@ -0,0 +1,3 @@
1
+ export { Select } from "./SelectDownshift";
2
+ // export type { SelectProps } from "./SelectReach";
3
+ // export { Select } from "./SelectReach";
@@ -0,0 +1,48 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useState } from "react";
3
+ import styled from "styled-components";
4
+ import { GrFolderOpen as IconOpen } from "react-icons/gr";
5
+ import { CgCloseR as IconClose } from "react-icons/cg";
6
+ import { max, min } from "../styles/media";
7
+ import { IconButtonFab } from "../Buttons";
8
+ import { useHeader } from "../Header";
9
+ const SidebarWrapper = styled.div `
10
+ ${(p) => `${max.md} {
11
+ z-index: 20;
12
+ display: flex;
13
+ flex-direction: column;
14
+ position: fixed;
15
+ right: 0;
16
+ left: var(--gutter-half);
17
+ top: ${p.$top || 0}px;
18
+ bottom: 0;
19
+ padding: var(--gutter-half);
20
+ transform: ${p.$open ? `translateX(0)` : `translateX(100%)`};
21
+ transition: transform .18s ease-in-out, box-shadow .18s ease-in-out;
22
+ background: white;
23
+ box-shadow: ${p.$open ? `0 0 0 100vh rgba(0, 0, 0, .3)` : `0 0 100vh rgba(0, 0, 0, 0)`};
24
+ will-change: transform, box-shadow;
25
+ pointer-events: ${p.$open ? "all" : "none"}
26
+ }`}
27
+ `;
28
+ const SidebarToggle = styled.span `
29
+ z-index: 21;
30
+ position: fixed;
31
+ right: var(--gutter-half);
32
+ bottom: var(--gutter-half);
33
+ ${min.md} {
34
+ display: none;
35
+ }
36
+
37
+ path {
38
+ stroke: currentColor;
39
+ }
40
+ `;
41
+ export const Sidebar = ({ children }) => {
42
+ const [open, setOpen] = useState(false);
43
+ const [, , headerHeight] = useHeader();
44
+ const handleClickToggle = useCallback(() => {
45
+ setOpen((prevOpen) => !prevOpen);
46
+ }, []);
47
+ return (_jsxs(_Fragment, { children: [_jsx(SidebarToggle, Object.assign({ onClick: handleClickToggle }, { children: _jsx(IconButtonFab, Object.assign({ "$variant": "contained" }, { children: open ? _jsx(IconClose, {}) : _jsx(IconOpen, {}) })) })), _jsx(SidebarWrapper, Object.assign({ "$open": open, "$top": headerHeight }, { children: children }))] }));
48
+ };
@@ -0,0 +1 @@
1
+ export * from "./Sidebar";
@@ -0,0 +1,47 @@
1
+ import { __rest } from "tslib";
2
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
+ import styled from "styled-components";
4
+ import { isUndefined } from "@koine/utils";
5
+ import { spacingTop, spacingBottom, } from "../styles/spacing";
6
+ const Root = styled.div `
7
+ ${(p) => p.$top && spacingTop.call(p.theme, ...p.$top)}
8
+ ${(p) => p.$bottom && spacingBottom.call(p.theme, ...p.$bottom)}
9
+ `;
10
+ const extractDirectionArgs = (raw) => {
11
+ const [size, factor, property, devices] = raw.split(":");
12
+ const factorArg = isUndefined(factor) ? undefined : parseFloat(factor);
13
+ const devicesArg = devices === null || devices === void 0 ? void 0 : devices.split(",");
14
+ return [size, factorArg, property, devicesArg];
15
+ };
16
+ /**
17
+ * Usage:
18
+ *
19
+ * ```jsx
20
+ * <Spacing top="sm" />
21
+ * <Spacing top="sm:1.5" />
22
+ * <Spacing top="sm:1.5" bottom="lg" />
23
+ * <Spacing vertical="sm:1.5:margin:mobile" />
24
+ * <Spacing top="sm:1.5:padding:mobile" />
25
+ * <Spacing top="sm:2:padding:tablet,desktop" />
26
+ * ```
27
+ */
28
+ export const Spacing = (_a) => {
29
+ var { top, bottom, vertical } = _a, props = __rest(_a, ["top", "bottom", "vertical"]);
30
+ let $top;
31
+ let $bottom;
32
+ if (top) {
33
+ $top = extractDirectionArgs(top);
34
+ }
35
+ if (bottom) {
36
+ $bottom = extractDirectionArgs(bottom);
37
+ }
38
+ if (vertical) {
39
+ $top = extractDirectionArgs(vertical);
40
+ $bottom = $top;
41
+ }
42
+ if (!$top && !$bottom && !vertical) {
43
+ // eslint-disable-next-line react/jsx-no-useless-fragment
44
+ return _jsx(_Fragment, { children: props.children });
45
+ }
46
+ return _jsx(Root, Object.assign({ "$top": $top, "$bottom": $bottom }, props));
47
+ };
@@ -0,0 +1 @@
1
+ export * from "./Spacing";
@@ -0,0 +1,220 @@
1
+ export const Sticky = null;
2
+ // import {
3
+ // FC,
4
+ // Ref,
5
+ // CSSProperties,
6
+ // useState,
7
+ // useCallback,
8
+ // useEffect,
9
+ // useRef,
10
+ // } from "react";
11
+ // /**
12
+ // * Get current coordinates `left` and `top` of specific element.
13
+ // */
14
+ // const offsetRelative = (element: HTMLElement) => {
15
+ // var result = { l: 0, t: 0 };
16
+ // do {
17
+ // let offsetTop = element.offsetTop;
18
+ // let offsetLeft = element.offsetLeft;
19
+ // if (!isNaN(offsetTop)) result.t += offsetTop;
20
+ // if (!isNaN(offsetLeft)) result.l += offsetLeft;
21
+ // // @ts-expect-error just rething everyhting in this file
22
+ // element =
23
+ // "BODY" === element.tagName ? element.parentElement : element.offsetParent;
24
+ // } while (element);
25
+ // return result;
26
+ // };
27
+ // export type StickyElementProps = {
28
+ // ref: Ref<HTMLDivElement>;
29
+ // sticky?: boolean;
30
+ // style: CSSProperties;
31
+ // };
32
+ // /**
33
+ // * - `0`: "STATIC": Static position as nothing happened
34
+ // * - `1`: "VIEWPORT-TOP": Sticked to the top screen edge
35
+ // * - `2`: "VIEWPORT-BOTTOM": Sticked to the bottom screen edge
36
+ // * - `4`: "VIEWPORT-UNBOTTOM": ? Scrolling in the middle of the element, neither sticked nor static
37
+ // * - `3`: "CONTAINER-BOTTOM": ?
38
+ // */
39
+ // export type StickyStatus = 0 | 1 | 2 | 3;
40
+ // type DimensionsBasic = [
41
+ // /** containerTop */
42
+ // number,
43
+ // /** containerHeight */
44
+ // number,
45
+ // /** containerBottom */
46
+ // number,
47
+ // /** elementHeight */
48
+ // number,
49
+ // /** elementWidth */
50
+ // number,
51
+ // /** viewportHeight */
52
+ // number,
53
+ // /** maxTranslateY */
54
+ // number
55
+ // ];
56
+ // type DimensionsOnScroll = [
57
+ // /** elementLeft */
58
+ // number,
59
+ // /** viewportTop */
60
+ // number,
61
+ // /** viewportBottom */
62
+ // number,
63
+ // /** viewportLeft */
64
+ // number,
65
+ // /** topSpacing */
66
+ // number,
67
+ // /** bottomSpacing */
68
+ // number
69
+ // /** translateY */
70
+ // // number,
71
+ // /** lastTopSpacing */
72
+ // // number,
73
+ // /** lastBottomSpacing */
74
+ // // number,
75
+ // /** lastViewportTop */
76
+ // // number,
77
+ // ];
78
+ // type Dimensions = DimensionsBasic & DimensionsOnScroll;
79
+ // const getDimensionsBasic = (container: HTMLElement, inner: HTMLElement) => {
80
+ // const containerTop = offsetRelative(container).t;
81
+ // const containerHeight = container.clientHeight;
82
+ // const containerBottom = containerTop + containerHeight;
83
+ // const elementHeight = inner.offsetHeight;
84
+ // const elementWidth = inner.offsetWidth;
85
+ // const viewportHeight = window.innerHeight;
86
+ // const maxTranslateY = containerHeight - elementHeight;
87
+ // return [
88
+ // containerTop,
89
+ // containerHeight,
90
+ // containerBottom,
91
+ // elementHeight,
92
+ // elementWidth,
93
+ // viewportHeight,
94
+ // maxTranslateY,
95
+ // ] as DimensionsBasic;
96
+ // };
97
+ // const getDimensionsOnScroll = (
98
+ // wrapper: HTMLElement,
99
+ // container: HTMLElement,
100
+ // inner: HTMLElement
101
+ // ) => {
102
+ // const elementLeft = offsetRelative(wrapper).l;
103
+ // const viewportTop =
104
+ // document.documentElement.scrollTop || document.body.scrollTop;
105
+ // const viewportBottom = viewportTop + window.innerHeight;
106
+ // const viewportLeft =
107
+ // document.documentElement.scrollLeft || document.body.scrollLeft;
108
+ // const topSpacing = 0; // TODO: make it a prop?
109
+ // const bottomSpacing = 0; // TODO: make it a prop?
110
+ // // const lastTopSpacing = topSpacing;
111
+ // // const lastBottomSpacing = bottomSpacing;
112
+ // return [
113
+ // elementLeft,
114
+ // viewportTop,
115
+ // viewportBottom,
116
+ // viewportLeft,
117
+ // topSpacing,
118
+ // bottomSpacing,
119
+ // ] as DimensionsOnScroll;
120
+ // };
121
+ // // const getTranslateYonScroll = (dimensions: DimensionsOnScroll, status: StickyStatus) => {
122
+ // // if (status === 1) {
123
+ // // // Adjust translate Y in the case decrease top spacing value.
124
+ // // if (dimensions[5] < dims.lastTopSpacing) {
125
+ // // dims.translateY += dims.lastTopSpacing - dims.topSpacing;
126
+ // // this._reStyle = true;
127
+ // // }
128
+ // // } else if (status === 2) {
129
+ // // // Adjust translate Y in the case decrease bottom spacing value.
130
+ // // if (dims.bottomSpacing < dims.lastBottomSpacing) {
131
+ // // dims.translateY += dims.lastBottomSpacing - dims.bottomSpacing;
132
+ // // this._reStyle = true;
133
+ // // }
134
+ // // }
135
+ // // }
136
+ // export type StickyProps = {
137
+ // /** @default "div" */
138
+ // Wrapper?: FC<StickyElementProps>;
139
+ // /** @default "div" */
140
+ // Inner?: FC<StickyElementProps>;
141
+ // top: number;
142
+ // };
143
+ // export const Sticky: FC<StickyProps> = ({
144
+ // Wrapper = "div",
145
+ // Inner = "div",
146
+ // children,
147
+ // top,
148
+ // ...props
149
+ // }) => {
150
+ // const [sticky, setSticky] = useState(false);
151
+ // const [shouldRestyle, setShouldRestyle] = useState<boolean>();
152
+ // const stickyStatus = useRef<StickyStatus>(0);
153
+ // const [dimensionsBasic, setDimensionsBasic] = useState<DimensionsBasic>();
154
+ // const [dimensionsOnScroll, setDimensionsOnScroll] =
155
+ // useState<DimensionsOnScroll>();
156
+ // const [translateY, setTranslateY] = useState<number>(0);
157
+ // const [styleWrapper, setStyleWrapper] = useState({});
158
+ // const [styleInner, setStyleInner] = useState({});
159
+ // const [innerWidth, setInnerWidth] = useState<string>();
160
+ // const wrapperRef = useRef<HTMLDivElement>(null);
161
+ // const innerRef = useRef<HTMLDivElement>(null);
162
+ // const handleScroll = useCallback(() => {
163
+ // const wrapper = wrapperRef?.current;
164
+ // const container = wrapper?.parentElement || null;
165
+ // const inner = innerRef?.current;
166
+ // if (wrapper && inner && container) {
167
+ // const dimensions = getDimensionsOnScroll(wrapper, container, inner);
168
+ // setDimensionsOnScroll(dimensions);
169
+ // }
170
+ // }, []);
171
+ // const handleResize = useCallback(() => {
172
+ // const container = wrapperRef?.current?.parentElement || null;
173
+ // const inner = innerRef?.current;
174
+ // if (inner && container) {
175
+ // setDimensionsBasic(getDimensionsBasic(container, inner));
176
+ // // if (innerRef?.current) {
177
+ // // setInnerWidth(window.getComputedStyle(innerRef.current).width);
178
+ // // }
179
+ // // setSticky(wrapperRef.current.getBoundingClientRect().top <= top);
180
+ // }
181
+ // }, []);
182
+ // useEffect(() => {
183
+ // const container = wrapperRef?.current?.parentElement || null;
184
+ // const inner = innerRef?.current;
185
+ // if (inner && container) {
186
+ // setDimensionsBasic(getDimensionsBasic(container, inner));
187
+ // }
188
+ // window.addEventListener("scroll", handleScroll, { passive: true });
189
+ // window.addEventListener("resize", handleResize, { passive: true });
190
+ // return () => {
191
+ // window.removeEventListener("scroll", () => handleScroll);
192
+ // window.removeEventListener("resize", () => handleResize);
193
+ // };
194
+ // }, [wrapperRef, innerRef, handleScroll, handleResize]);
195
+ // // useEffect(() => {
196
+ // // if (sticky) {
197
+ // // setStyleInner({
198
+ // // position: "fixed",
199
+ // // zIndex: 1,
200
+ // // top,
201
+ // // width: innerWidth,
202
+ // // });
203
+ // // } else {
204
+ // // setStyleInner({});
205
+ // // }
206
+ // // }, [sticky, top, innerWidth]);
207
+ // return (
208
+ // <Wrapper
209
+ // ref={wrapperRef}
210
+ // sticky={Wrapper === "div" ? undefined : sticky}
211
+ // style={{
212
+ // position: "relative",
213
+ // }}
214
+ // >
215
+ // <Inner ref={innerRef} style={styleInner}>
216
+ // {children}
217
+ // </Inner>
218
+ // </Wrapper>
219
+ // );
220
+ // };
@@ -0,0 +1,6 @@
1
+ import { __rest } from "tslib";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export const StickyCss = (_a) => {
4
+ var { top } = _a, props = __rest(_a, ["top"]);
5
+ return _jsx("div", Object.assign({ style: { position: "sticky", top: 100 } }, props));
6
+ };
@@ -0,0 +1 @@
1
+ export * from "./StickyCss";
package/Tabs/Tabs.js ADDED
@@ -0,0 +1,67 @@
1
+ import { __rest } from "tslib";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * @file
5
+ *
6
+ * Here we manage only "vertical" oriented tabs for now
7
+ */
8
+ import { AnimateSharedLayout } from "framer-motion";
9
+ import styled from "styled-components";
10
+ import { Tabs as _Tabs, TabList as _TabList, Tab as _Tab, TabPanels as _TabPanels, TabPanel as _TabPanel, useTabsContext, } from "@reach/tabs";
11
+ import { min } from "../styles/media";
12
+ import { UnderlineSkewed } from "../Animations/Underline";
13
+ import { btnStyleReset } from "../Buttons";
14
+ export const TabsStyled = styled(_Tabs) `
15
+ ${min.sm} {
16
+ display: flex;
17
+ ${(p) => p.$vertical && "flex-direction: column;"}
18
+ }
19
+ `;
20
+ export const Tabs = (props) => {
21
+ return (_jsx(AnimateSharedLayout, { children: _jsx(TabsStyled, Object.assign({}, props)) }));
22
+ };
23
+ export const TabList = styled(_TabList) `
24
+ display: flex;
25
+ flex-direction: column;
26
+ ${min.sm} {
27
+ border-right: 1px solid var(--grey800);
28
+ }
29
+ `;
30
+ export const TabWrap = styled(_Tab) `
31
+ ${btnStyleReset}
32
+ position: relative;
33
+ justify-content: flex-end;
34
+ padding: 0.7em;
35
+ margin-bottom: 1em;
36
+ font-weight: bold;
37
+ color: ${(p) => (p.$active ? "var(--accent200)" : "var(--grey300)")};
38
+ ${min.sm} {
39
+ padding-right: var(--gutter-half);
40
+ }
41
+
42
+ &:hover {
43
+ color: ${(p) => (p.$active ? "var(--accent200)" : "var(--accent300)")};
44
+ }
45
+ `;
46
+ export const TabText = styled.span `
47
+ position: relative;
48
+ z-index: 1;
49
+ `;
50
+ export const TabUnderline = styled(UnderlineSkewed) ``;
51
+ export const Tab = (_a) => {
52
+ var { children } = _a, props = __rest(_a, ["children"]);
53
+ const { selectedIndex, focusedIndex } = useTabsContext();
54
+ const styledProps = {
55
+ $active: props.idx === selectedIndex,
56
+ $focused: props.idx === focusedIndex,
57
+ };
58
+ return (_jsxs(TabWrap, Object.assign({}, props, styledProps, { children: [styledProps.$active && (_jsx(TabUnderline, Object.assign({}, styledProps, { layoutId: "Tab-underline" }))), _jsx(TabText, Object.assign({}, styledProps, { children: children }))] })));
59
+ };
60
+ export const TabPanels = styled(_TabPanels) `
61
+ flex: 1;
62
+ `;
63
+ export const TabPanel = styled(_TabPanel) `
64
+ ${min.sm} {
65
+ padding-left: var(--gutter-half);
66
+ }
67
+ `;
package/Tabs/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./Tabs";
@@ -0,0 +1,6 @@
1
+ import styled from "styled-components";
2
+ export const CopyPasteVisible = styled.span `
3
+ color: transparent;
4
+ opacity: 0;
5
+ font-size: 0;
6
+ `;