@heymantle/litho 0.0.1
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/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/cjs/components/ActionList.js +267 -0
- package/dist/cjs/components/AnnouncementBar.js +73 -0
- package/dist/cjs/components/AppProvider.js +245 -0
- package/dist/cjs/components/Autocomplete.js +351 -0
- package/dist/cjs/components/Badge.js +234 -0
- package/dist/cjs/components/Banner.js +264 -0
- package/dist/cjs/components/Box.js +247 -0
- package/dist/cjs/components/Button.js +1018 -0
- package/dist/cjs/components/ButtonGroup.js +196 -0
- package/dist/cjs/components/Card.js +593 -0
- package/dist/cjs/components/Checkbox.js +175 -0
- package/dist/cjs/components/ChoiceList.js +160 -0
- package/dist/cjs/components/Collapsible.js +42 -0
- package/dist/cjs/components/ColorField.js +159 -0
- package/dist/cjs/components/ContextualSaveBar.js +53 -0
- package/dist/cjs/components/DatePicker.js +547 -0
- package/dist/cjs/components/Divider.js +50 -0
- package/dist/cjs/components/DropZone.js +547 -0
- package/dist/cjs/components/EmptyState.js +111 -0
- package/dist/cjs/components/Filters.js +874 -0
- package/dist/cjs/components/FooterHelp.js +48 -0
- package/dist/cjs/components/Form.js +44 -0
- package/dist/cjs/components/Frame.js +386 -0
- package/dist/cjs/components/FrameSaveBar.js +239 -0
- package/dist/cjs/components/Grid.js +151 -0
- package/dist/cjs/components/HorizontalStack.js +180 -0
- package/dist/cjs/components/Icon.js +346 -0
- package/dist/cjs/components/Image.js +191 -0
- package/dist/cjs/components/InlineError.js +57 -0
- package/dist/cjs/components/Label.js +78 -0
- package/dist/cjs/components/Layout.js +228 -0
- package/dist/cjs/components/LayoutSection.js +133 -0
- package/dist/cjs/components/Link.js +128 -0
- package/dist/cjs/components/List.js +69 -0
- package/dist/cjs/components/Listbox.js +211 -0
- package/dist/cjs/components/Loading.js +103 -0
- package/dist/cjs/components/Modal.js +449 -0
- package/dist/cjs/components/Navigation.js +331 -0
- package/dist/cjs/components/Page.js +529 -0
- package/dist/cjs/components/Pagination.js +109 -0
- package/dist/cjs/components/Pane.js +128 -0
- package/dist/cjs/components/Popover.js +365 -0
- package/dist/cjs/components/PopoverManager.js +34 -0
- package/dist/cjs/components/ProgressBar.js +124 -0
- package/dist/cjs/components/RadioButton.js +172 -0
- package/dist/cjs/components/RadioButtonCard.js +193 -0
- package/dist/cjs/components/RangeSlider.js +235 -0
- package/dist/cjs/components/ResourceList.js +105 -0
- package/dist/cjs/components/Select.js +300 -0
- package/dist/cjs/components/SkeletonText.js +130 -0
- package/dist/cjs/components/Spinner.js +72 -0
- package/dist/cjs/components/Table.js +1184 -0
- package/dist/cjs/components/Tabs.js +421 -0
- package/dist/cjs/components/Tag.js +165 -0
- package/dist/cjs/components/Text.js +274 -0
- package/dist/cjs/components/TextField.js +584 -0
- package/dist/cjs/components/Thumbnail.js +73 -0
- package/dist/cjs/components/TimePicker.js +23 -0
- package/dist/cjs/components/Tip.js +220 -0
- package/dist/cjs/components/Tooltip.js +431 -0
- package/dist/cjs/components/TopBar.js +210 -0
- package/dist/cjs/components/VerticalStack.js +161 -0
- package/dist/cjs/index.js +308 -0
- package/dist/cjs/styles/Table.js +591 -0
- package/dist/cjs/utilities/dates.js +339 -0
- package/dist/cjs/utilities/useIndexResourceState.js +175 -0
- package/dist/cjs/utilities/useMounted.js +67 -0
- package/dist/cjs/utilities/useTableScrollState.js +142 -0
- package/dist/esm/components/ActionList.js +216 -0
- package/dist/esm/components/AnnouncementBar.js +63 -0
- package/dist/esm/components/AppProvider.js +185 -0
- package/dist/esm/components/Autocomplete.js +300 -0
- package/dist/esm/components/Badge.js +225 -0
- package/dist/esm/components/Banner.js +254 -0
- package/dist/esm/components/Box.js +238 -0
- package/dist/esm/components/Button.js +967 -0
- package/dist/esm/components/ButtonGroup.js +137 -0
- package/dist/esm/components/Card.js +537 -0
- package/dist/esm/components/Checkbox.js +165 -0
- package/dist/esm/components/ChoiceList.js +145 -0
- package/dist/esm/components/Collapsible.js +32 -0
- package/dist/esm/components/ColorField.js +149 -0
- package/dist/esm/components/ContextualSaveBar.js +43 -0
- package/dist/esm/components/DatePicker.js +532 -0
- package/dist/esm/components/Divider.js +41 -0
- package/dist/esm/components/DropZone.js +537 -0
- package/dist/esm/components/EmptyState.js +101 -0
- package/dist/esm/components/Filters.js +823 -0
- package/dist/esm/components/FooterHelp.js +38 -0
- package/dist/esm/components/Form.js +35 -0
- package/dist/esm/components/Frame.js +376 -0
- package/dist/esm/components/FrameSaveBar.js +229 -0
- package/dist/esm/components/Grid.js +142 -0
- package/dist/esm/components/HorizontalStack.js +171 -0
- package/dist/esm/components/Icon.js +296 -0
- package/dist/esm/components/Image.js +141 -0
- package/dist/esm/components/InlineError.js +43 -0
- package/dist/esm/components/Label.js +63 -0
- package/dist/esm/components/Layout.js +164 -0
- package/dist/esm/components/LayoutSection.js +82 -0
- package/dist/esm/components/Link.js +119 -0
- package/dist/esm/components/List.js +61 -0
- package/dist/esm/components/Listbox.js +201 -0
- package/dist/esm/components/Loading.js +93 -0
- package/dist/esm/components/Modal.js +390 -0
- package/dist/esm/components/Navigation.js +321 -0
- package/dist/esm/components/Page.js +473 -0
- package/dist/esm/components/Pagination.js +99 -0
- package/dist/esm/components/Pane.js +118 -0
- package/dist/esm/components/Popover.js +350 -0
- package/dist/esm/components/PopoverManager.js +24 -0
- package/dist/esm/components/ProgressBar.js +114 -0
- package/dist/esm/components/RadioButton.js +157 -0
- package/dist/esm/components/RadioButtonCard.js +178 -0
- package/dist/esm/components/RangeSlider.js +225 -0
- package/dist/esm/components/ResourceList.js +95 -0
- package/dist/esm/components/Select.js +285 -0
- package/dist/esm/components/SkeletonText.js +120 -0
- package/dist/esm/components/Spinner.js +63 -0
- package/dist/esm/components/Table.js +1129 -0
- package/dist/esm/components/Tabs.js +366 -0
- package/dist/esm/components/Tag.js +151 -0
- package/dist/esm/components/Text.js +265 -0
- package/dist/esm/components/TextField.js +533 -0
- package/dist/esm/components/Thumbnail.js +63 -0
- package/dist/esm/components/TimePicker.js +13 -0
- package/dist/esm/components/Tip.js +169 -0
- package/dist/esm/components/Tooltip.js +380 -0
- package/dist/esm/components/TopBar.js +200 -0
- package/dist/esm/components/VerticalStack.js +152 -0
- package/dist/esm/index.js +61 -0
- package/dist/esm/styles/Table.js +581 -0
- package/dist/esm/utilities/dates.js +289 -0
- package/dist/esm/utilities/useIndexResourceState.js +158 -0
- package/dist/esm/utilities/useMounted.js +57 -0
- package/dist/esm/utilities/useTableScrollState.js +132 -0
- package/index.css +1137 -0
- package/package.json +53 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { CancelMajor } from "@shopify/polaris-icons";
|
|
4
|
+
import { tv } from "tailwind-variants";
|
|
5
|
+
import { FrameContext } from "./AppProvider.js";
|
|
6
|
+
import { createContext, useContext, useEffect, Children } from "react";
|
|
7
|
+
import { Button } from "../index.js";
|
|
8
|
+
var styles = tv({
|
|
9
|
+
base: "Litho-Pane hidden md:block fixed inset-0 w-full md:left-auto md:max-w-100 block bg-surface-highest shadow-card-strong pointer-events-auto"
|
|
10
|
+
});
|
|
11
|
+
var innerStyles = tv({
|
|
12
|
+
base: "flex flex-col overflow-y-auto h-full"
|
|
13
|
+
});
|
|
14
|
+
var PaneContext = /*#__PURE__*/ createContext({});
|
|
15
|
+
function Pane() {
|
|
16
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
17
|
+
var open = props.open, onClose = props.onClose, children = props.children;
|
|
18
|
+
var setPaneIsOpen = useContext(FrameContext).setPaneIsOpen;
|
|
19
|
+
var classes = styles();
|
|
20
|
+
useEffect(function() {
|
|
21
|
+
setPaneIsOpen(open);
|
|
22
|
+
if (!open || !onClose) return;
|
|
23
|
+
var handleKeyDown = function(event) {
|
|
24
|
+
if (event.key === "Escape") {
|
|
25
|
+
onClose();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
29
|
+
return function() {
|
|
30
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
31
|
+
};
|
|
32
|
+
}, [
|
|
33
|
+
open,
|
|
34
|
+
onClose
|
|
35
|
+
]);
|
|
36
|
+
if (!open) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return /*#__PURE__*/ _jsx(PaneContext.Provider, {
|
|
40
|
+
value: {
|
|
41
|
+
onClose: onClose
|
|
42
|
+
},
|
|
43
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
44
|
+
className: classes,
|
|
45
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
46
|
+
className: innerStyles(),
|
|
47
|
+
children: children
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function Header() {
|
|
53
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
54
|
+
var children = props.children, _props_actions = props.actions, actions = _props_actions === void 0 ? [] : _props_actions, _props_showCloseButton = props.showCloseButton, showCloseButton = _props_showCloseButton === void 0 ? true : _props_showCloseButton, _props_bottomBorder = props.bottomBorder, bottomBorder = _props_bottomBorder === void 0 ? true : _props_bottomBorder;
|
|
55
|
+
var onClose = useContext(PaneContext).onClose;
|
|
56
|
+
var showActionsOrClose = actions.length > 0 || showCloseButton;
|
|
57
|
+
var childCount = Children.count(children);
|
|
58
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
59
|
+
className: "grid grid-cols-12 min-h-14 pl-4 pr-3 border-edge-subdued ".concat(bottomBorder ? "border-b" : ""),
|
|
60
|
+
children: [
|
|
61
|
+
/*#__PURE__*/ _jsx("div", {
|
|
62
|
+
className: "grid grid-cols-5 col-span-10",
|
|
63
|
+
children: Children.map(children, function(child, index) {
|
|
64
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
65
|
+
className: "flex col-span-2 items-center ".concat(childCount === 1 ? "col-span-5" : "", " ").concat(index > 0 ? "justify-center" : ""),
|
|
66
|
+
children: child
|
|
67
|
+
});
|
|
68
|
+
})
|
|
69
|
+
}),
|
|
70
|
+
showActionsOrClose && /*#__PURE__*/ _jsxs("div", {
|
|
71
|
+
className: "flex col-span-2 items-center justify-end",
|
|
72
|
+
children: [
|
|
73
|
+
actions.map(function(action, index) {
|
|
74
|
+
return /*#__PURE__*/ _jsx(Button, {
|
|
75
|
+
plain: !action.destructive,
|
|
76
|
+
onClick: action.onAction || action.onClick,
|
|
77
|
+
disabled: action.disabled,
|
|
78
|
+
icon: action.icon,
|
|
79
|
+
loading: action.loading,
|
|
80
|
+
external: action.external,
|
|
81
|
+
url: action.url,
|
|
82
|
+
destructive: action.destructive,
|
|
83
|
+
tooltip: action.tooltip,
|
|
84
|
+
tooltipPosition: "below"
|
|
85
|
+
}, index);
|
|
86
|
+
}),
|
|
87
|
+
showCloseButton && /*#__PURE__*/ _jsx(Button, {
|
|
88
|
+
plain: true,
|
|
89
|
+
icon: CancelMajor,
|
|
90
|
+
onClick: onClose,
|
|
91
|
+
tooltip: "Close",
|
|
92
|
+
tooltipPosition: "below"
|
|
93
|
+
})
|
|
94
|
+
]
|
|
95
|
+
})
|
|
96
|
+
]
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
Pane.Header = Header;
|
|
100
|
+
function Content() {
|
|
101
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
102
|
+
var children = props.children;
|
|
103
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
104
|
+
className: "flex-1 overflow-auto",
|
|
105
|
+
children: children
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
Pane.Content = Content;
|
|
109
|
+
function Footer() {
|
|
110
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
111
|
+
var children = props.children, _props_topBorder = props.topBorder, topBorder = _props_topBorder === void 0 ? true : _props_topBorder;
|
|
112
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
113
|
+
className: "min-h-14 ".concat(topBorder ? "border-t border-edge-subdued" : ""),
|
|
114
|
+
children: children
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
Pane.Footer = Footer;
|
|
118
|
+
export default Pane;
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
function _array_like_to_array(arr, len) {
|
|
3
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
+
return arr2;
|
|
6
|
+
}
|
|
7
|
+
function _array_with_holes(arr) {
|
|
8
|
+
if (Array.isArray(arr)) return arr;
|
|
9
|
+
}
|
|
10
|
+
function _define_property(obj, key, value) {
|
|
11
|
+
if (key in obj) {
|
|
12
|
+
Object.defineProperty(obj, key, {
|
|
13
|
+
value: value,
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
obj[key] = value;
|
|
20
|
+
}
|
|
21
|
+
return obj;
|
|
22
|
+
}
|
|
23
|
+
function _iterable_to_array_limit(arr, i) {
|
|
24
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
25
|
+
if (_i == null) return;
|
|
26
|
+
var _arr = [];
|
|
27
|
+
var _n = true;
|
|
28
|
+
var _d = false;
|
|
29
|
+
var _s, _e;
|
|
30
|
+
try {
|
|
31
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
32
|
+
_arr.push(_s.value);
|
|
33
|
+
if (i && _arr.length === i) break;
|
|
34
|
+
}
|
|
35
|
+
} catch (err) {
|
|
36
|
+
_d = true;
|
|
37
|
+
_e = err;
|
|
38
|
+
} finally{
|
|
39
|
+
try {
|
|
40
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
41
|
+
} finally{
|
|
42
|
+
if (_d) throw _e;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return _arr;
|
|
46
|
+
}
|
|
47
|
+
function _non_iterable_rest() {
|
|
48
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
49
|
+
}
|
|
50
|
+
function _object_spread(target) {
|
|
51
|
+
for(var i = 1; i < arguments.length; i++){
|
|
52
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
53
|
+
var ownKeys = Object.keys(source);
|
|
54
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
55
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
56
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
ownKeys.forEach(function(key) {
|
|
60
|
+
_define_property(target, key, source[key]);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return target;
|
|
64
|
+
}
|
|
65
|
+
function ownKeys(object, enumerableOnly) {
|
|
66
|
+
var keys = Object.keys(object);
|
|
67
|
+
if (Object.getOwnPropertySymbols) {
|
|
68
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
69
|
+
if (enumerableOnly) {
|
|
70
|
+
symbols = symbols.filter(function(sym) {
|
|
71
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
keys.push.apply(keys, symbols);
|
|
75
|
+
}
|
|
76
|
+
return keys;
|
|
77
|
+
}
|
|
78
|
+
function _object_spread_props(target, source) {
|
|
79
|
+
source = source != null ? source : {};
|
|
80
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
81
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
82
|
+
} else {
|
|
83
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
84
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return target;
|
|
88
|
+
}
|
|
89
|
+
function _sliced_to_array(arr, i) {
|
|
90
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
91
|
+
}
|
|
92
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
93
|
+
if (!o) return;
|
|
94
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
95
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
96
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
97
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
98
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
99
|
+
}
|
|
100
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
101
|
+
import { useEffect, useId, useMemo, useRef, useState, useLayoutEffect } from "react";
|
|
102
|
+
import { createPortal } from "react-dom";
|
|
103
|
+
import { tv } from "tailwind-variants";
|
|
104
|
+
import PopoverManager from "./PopoverManager.js";
|
|
105
|
+
var TOP_SPACING = 4;
|
|
106
|
+
var EDGE_SPACING = 16;
|
|
107
|
+
var styles = tv({
|
|
108
|
+
base: "Litho-Popover bg-surface-highest rounded-sm max-h-100 overflow-y-auto overflow-x-hidden shadow-popover dark:shadow-popover-dark outline outline-tint-3 min-w-32 overscroll-contain dark:outline-hidden dark:border-t dark:border-tint-alt-2",
|
|
109
|
+
variants: {
|
|
110
|
+
maxWidth: {
|
|
111
|
+
default: "max-w-80",
|
|
112
|
+
datePicker: "max-w-75 @sm:max-w-full",
|
|
113
|
+
none: ""
|
|
114
|
+
},
|
|
115
|
+
sectioned: {
|
|
116
|
+
true: "Litho-Popover--Sectioned p-4",
|
|
117
|
+
false: ""
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
/**
|
|
122
|
+
* Popover component for displaying an overlay near an activator.
|
|
123
|
+
*
|
|
124
|
+
* @param {Object} props - The component props.
|
|
125
|
+
* @param {string|React.ComponentType} [props.activatorWrapper="div"] - The wrapper element for the activator.
|
|
126
|
+
* @param {React.ReactNode} props.activator - The activator element that triggers the popover.
|
|
127
|
+
* @param {string} [props.activatorDisplayType="inline-block"] - The display type for the activator.
|
|
128
|
+
* @param {React.ReactNode} props.children - The content of the popover.
|
|
129
|
+
* @param {Function} [props.onClose] - Callback function triggered when the popover is closed.
|
|
130
|
+
* @param {boolean} [props.active=false] - Whether the popover is currently active.
|
|
131
|
+
* @param {boolean} [props.fixed=false] - Whether the popover is fixed or absolute positioned.
|
|
132
|
+
* @param {number} [props.zIndexOverride] - Custom z-index for the popover.
|
|
133
|
+
* @param {boolean} [props.sectioned=false] - Whether the popover content is sectioned with padding.
|
|
134
|
+
* @param {string} [props.preferredAlignment="center"] - Preferred alignment for the popover (left, center, right).
|
|
135
|
+
* @param {string} [props.preferredPosition="below"] - Preferred position for the popover (above, below, cover).
|
|
136
|
+
* @param {boolean|string} [props.autofocusTarget=false] - Automatically focus on the first focusable element in the popover.
|
|
137
|
+
* @param {string} [props.className] - Additional class name for the popover.
|
|
138
|
+
* @param {string} [props.containerClassName] - Additional class name for the popover container.
|
|
139
|
+
* @returns {JSX.Element} The rendered popover component.
|
|
140
|
+
*/ function Popover() {
|
|
141
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
142
|
+
var tmp = props.activatorWrapper, ActivatorWrapper = tmp === void 0 ? "div" : tmp, _props_activatorDisplayType = props.activatorDisplayType, activatorDisplayType = _props_activatorDisplayType === void 0 ? "inline-block" : _props_activatorDisplayType, activator = props.activator, children = props.children, onClose = props.onClose, active = props.active, fixed = props.fixed, zIndexOverride = props.zIndexOverride, _props_sectioned = props.sectioned, sectioned = _props_sectioned === void 0 ? false : _props_sectioned, _props_preferredAlignment = props.preferredAlignment, preferredAlignment = _props_preferredAlignment === void 0 ? "center" : _props_preferredAlignment, _props_preferredPosition = props.preferredPosition, preferredPosition = _props_preferredPosition === void 0 ? "below" : _props_preferredPosition, _props_autofocusTarget = props.autofocusTarget, autofocusTarget = _props_autofocusTarget === void 0 ? false : _props_autofocusTarget, _props_matchActivatorWidth = props.matchActivatorWidth, matchActivatorWidth = _props_matchActivatorWidth === void 0 ? false : _props_matchActivatorWidth, _props_maxWidth = props.maxWidth, maxWidth = _props_maxWidth === void 0 ? "default" : _props_maxWidth, className = props.className, containerClassName = props.containerClassName;
|
|
143
|
+
var idValue = useId();
|
|
144
|
+
var idRef = useRef(idValue);
|
|
145
|
+
var initialWidthRef = useRef(null);
|
|
146
|
+
var popoverRef = useRef(null);
|
|
147
|
+
var activatorRef = useRef(null);
|
|
148
|
+
var _useState = _sliced_to_array(useState(_object_spread({
|
|
149
|
+
visibility: "hidden",
|
|
150
|
+
opacity: 0,
|
|
151
|
+
position: "absolute",
|
|
152
|
+
top: 0,
|
|
153
|
+
left: 0
|
|
154
|
+
}, zIndexOverride ? {
|
|
155
|
+
zIndex: zIndexOverride
|
|
156
|
+
} : {})), 2), popoverStyle = _useState[0], setPopoverStyle = _useState[1];
|
|
157
|
+
useEffect(function() {
|
|
158
|
+
if (active) {
|
|
159
|
+
PopoverManager.open(idRef.current);
|
|
160
|
+
} else {
|
|
161
|
+
PopoverManager.close(idRef.current);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (!popoverRef.current) return;
|
|
165
|
+
var observer = new ResizeObserver(function() {
|
|
166
|
+
if (!active) return;
|
|
167
|
+
requestAnimationFrame(function() {
|
|
168
|
+
if (!popoverRef.current || !activatorRef.current) return;
|
|
169
|
+
var popoverRect = popoverRef.current.getBoundingClientRect();
|
|
170
|
+
var activatorRect = activatorRef.current.getBoundingClientRect();
|
|
171
|
+
var windowWidth = window.innerWidth;
|
|
172
|
+
var windowHeight = window.innerHeight;
|
|
173
|
+
var top, left;
|
|
174
|
+
if (preferredPosition === "below") {
|
|
175
|
+
top = fixed ? activatorRect.bottom + TOP_SPACING : activatorRect.bottom + window.scrollY + TOP_SPACING;
|
|
176
|
+
} else if (preferredPosition === "above") {
|
|
177
|
+
top = fixed ? activatorRect.top - popoverRect.height - TOP_SPACING : activatorRect.top + window.scrollY - popoverRect.height - TOP_SPACING;
|
|
178
|
+
} else if (preferredPosition === "cover") {
|
|
179
|
+
top = fixed ? activatorRect.top : activatorRect.top + window.scrollY;
|
|
180
|
+
}
|
|
181
|
+
if (preferredAlignment === "left") {
|
|
182
|
+
left = fixed ? activatorRect.left : activatorRect.left + window.scrollX;
|
|
183
|
+
} else if (preferredAlignment === "right") {
|
|
184
|
+
left = fixed ? activatorRect.right - popoverRect.width : activatorRect.right + window.scrollX - popoverRect.width;
|
|
185
|
+
} else if (preferredAlignment === "center") {
|
|
186
|
+
left = fixed ? activatorRect.left + activatorRect.width / 2 - popoverRect.width / 2 : activatorRect.left + window.scrollX + activatorRect.width / 2 - popoverRect.width / 2;
|
|
187
|
+
}
|
|
188
|
+
if (top + popoverRect.height + EDGE_SPACING > windowHeight) {
|
|
189
|
+
top = fixed ? activatorRect.top - popoverRect.height - TOP_SPACING : activatorRect.top + window.scrollY - popoverRect.height - TOP_SPACING;
|
|
190
|
+
}
|
|
191
|
+
if (top < 0) {
|
|
192
|
+
top = fixed ? activatorRect.bottom + TOP_SPACING : activatorRect.bottom + window.scrollY + TOP_SPACING;
|
|
193
|
+
}
|
|
194
|
+
if (left + popoverRect.width > windowWidth) {
|
|
195
|
+
left = windowWidth - popoverRect.width - EDGE_SPACING;
|
|
196
|
+
}
|
|
197
|
+
if (left < 0) {
|
|
198
|
+
left = EDGE_SPACING;
|
|
199
|
+
}
|
|
200
|
+
if (initialWidthRef.current === null) {
|
|
201
|
+
var popoverRect1 = popoverRef.current.getBoundingClientRect();
|
|
202
|
+
initialWidthRef.current = popoverRect1.width;
|
|
203
|
+
}
|
|
204
|
+
setPopoverStyle(function(prev) {
|
|
205
|
+
return _object_spread_props(_object_spread(_object_spread_props(_object_spread(_object_spread_props(_object_spread({}, prev), {
|
|
206
|
+
position: fixed ? "fixed" : "absolute"
|
|
207
|
+
}), zIndexOverride ? {
|
|
208
|
+
zIndex: zIndexOverride
|
|
209
|
+
} : {}), {
|
|
210
|
+
top: top,
|
|
211
|
+
left: left,
|
|
212
|
+
visibility: "visible",
|
|
213
|
+
opacity: 1
|
|
214
|
+
}), !matchActivatorWidth && {
|
|
215
|
+
minWidth: initialWidthRef.current
|
|
216
|
+
}, matchActivatorWidth && {
|
|
217
|
+
width: activatorRect.width
|
|
218
|
+
}), {
|
|
219
|
+
maxWidth: matchActivatorWidth ? activatorRect.width : window.innerWidth - 32
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
observer.observe(popoverRef.current);
|
|
225
|
+
return function() {
|
|
226
|
+
observer.disconnect();
|
|
227
|
+
};
|
|
228
|
+
}, [
|
|
229
|
+
active
|
|
230
|
+
]);
|
|
231
|
+
useLayoutEffect(function() {
|
|
232
|
+
if (!active || !popoverRef.current) return;
|
|
233
|
+
var focusable = popoverRef.current.querySelector("input, button, a, select, textarea");
|
|
234
|
+
if (focusable) {
|
|
235
|
+
// focusable.focus();
|
|
236
|
+
setTimeout(function() {
|
|
237
|
+
focusable.focus();
|
|
238
|
+
}, 0);
|
|
239
|
+
}
|
|
240
|
+
}, [
|
|
241
|
+
active
|
|
242
|
+
]);
|
|
243
|
+
useEffect(function() {
|
|
244
|
+
var handleOutsideClick = function handleOutsideClick(event) {
|
|
245
|
+
if (!onClose) return;
|
|
246
|
+
var closestPopover = event.target.closest(".Litho-Popover");
|
|
247
|
+
var isClickInsidePopover = popoverRef.current && popoverRef.current.contains(event.target);
|
|
248
|
+
var isClickInsideActivator = activatorRef.current && activatorRef.current.contains(event.target);
|
|
249
|
+
if (!closestPopover && !isClickInsideActivator) {
|
|
250
|
+
PopoverManager.closeAll();
|
|
251
|
+
onClose();
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (!isClickInsidePopover && !isClickInsideActivator && idRef.current === PopoverManager.getActivePopoverId()) {
|
|
255
|
+
event.stopPropagation();
|
|
256
|
+
onClose();
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
var handleEscapeKey = function handleEscapeKey(event) {
|
|
260
|
+
if (event.key === "Escape" && onClose && idRef.current === PopoverManager.getActivePopoverId()) {
|
|
261
|
+
PopoverManager.close(PopoverManager.getActivePopoverId());
|
|
262
|
+
onClose();
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
var handleScroll = function handleScroll() {
|
|
266
|
+
if (!onClose) return;
|
|
267
|
+
var scrollDiffTop = Math.abs(window.scrollY - initialScrollTop);
|
|
268
|
+
var scrollDiffLeft = Math.abs(window.scrollX - initialScrollLeft);
|
|
269
|
+
if (scrollDiffTop > SCROLL_THRESHOLD || scrollDiffLeft > SCROLL_THRESHOLD) {
|
|
270
|
+
onClose();
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
var handleResize = function handleResize() {
|
|
274
|
+
if (onClose) {
|
|
275
|
+
onClose();
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
if (!active) return;
|
|
279
|
+
var timer;
|
|
280
|
+
var initialScrollTop = window.scrollY;
|
|
281
|
+
var initialScrollLeft = window.scrollX;
|
|
282
|
+
var SCROLL_THRESHOLD = 100;
|
|
283
|
+
timer = setTimeout(function() {
|
|
284
|
+
document.addEventListener("click", handleOutsideClick);
|
|
285
|
+
document.addEventListener("keydown", handleEscapeKey);
|
|
286
|
+
window.addEventListener("resize", handleResize);
|
|
287
|
+
window.addEventListener("scroll", handleScroll);
|
|
288
|
+
}, 0);
|
|
289
|
+
return function() {
|
|
290
|
+
clearTimeout(timer);
|
|
291
|
+
document.removeEventListener("click", handleOutsideClick);
|
|
292
|
+
document.removeEventListener("keydown", handleEscapeKey);
|
|
293
|
+
window.removeEventListener("resize", handleResize);
|
|
294
|
+
window.removeEventListener("scroll", handleScroll);
|
|
295
|
+
};
|
|
296
|
+
}, [
|
|
297
|
+
active,
|
|
298
|
+
PopoverManager
|
|
299
|
+
]);
|
|
300
|
+
var classes = styles({
|
|
301
|
+
sectioned: sectioned,
|
|
302
|
+
maxWidth: maxWidth
|
|
303
|
+
});
|
|
304
|
+
var memoizedActivator = useMemo(function() {
|
|
305
|
+
return activator;
|
|
306
|
+
}, [
|
|
307
|
+
activator
|
|
308
|
+
]);
|
|
309
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
310
|
+
className: "Litho-PopoverContainer".concat(containerClassName ? " ".concat(containerClassName) : ""),
|
|
311
|
+
children: [
|
|
312
|
+
/*#__PURE__*/ _jsx(ActivatorWrapper, {
|
|
313
|
+
ref: activatorRef,
|
|
314
|
+
className: "Litho-PopoverActivator ".concat(activatorDisplayType),
|
|
315
|
+
children: memoizedActivator
|
|
316
|
+
}),
|
|
317
|
+
active && typeof children !== "undefined" && /*#__PURE__*/ createPortal(/*#__PURE__*/ _jsx("div", {
|
|
318
|
+
className: "@container",
|
|
319
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
320
|
+
ref: popoverRef,
|
|
321
|
+
style: popoverStyle,
|
|
322
|
+
className: "".concat(classes).concat(className ? " ".concat(className) : ""),
|
|
323
|
+
children: children
|
|
324
|
+
})
|
|
325
|
+
}), document.body)
|
|
326
|
+
]
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
Popover.displayName = "Popover";
|
|
330
|
+
var sectionStyles = tv({
|
|
331
|
+
base: "Litho-Popover__Section border-b border-edge-default last:border-b-0"
|
|
332
|
+
});
|
|
333
|
+
/**
|
|
334
|
+
* Section component for use within the Popover.
|
|
335
|
+
*
|
|
336
|
+
* @param {Object} props - The component props.
|
|
337
|
+
* @param {React.ReactNode} [props.children] - The content of the section.
|
|
338
|
+
* @returns {JSX.Element} The rendered section.
|
|
339
|
+
*/ function Section() {
|
|
340
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
341
|
+
var children = props.children, className = props.className;
|
|
342
|
+
var sectionClasses = sectionStyles();
|
|
343
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
344
|
+
className: "".concat(sectionClasses).concat(className ? " ".concat(className) : ""),
|
|
345
|
+
children: children
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
Popover.Section = Section;
|
|
349
|
+
Popover.Section.displayName = "Popover.Section";
|
|
350
|
+
export default Popover;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
var PopoverManager = new EventEmitter();
|
|
3
|
+
PopoverManager.activePopovers = [];
|
|
4
|
+
PopoverManager.open = function(id) {
|
|
5
|
+
if (!this.activePopovers.includes(id)) {
|
|
6
|
+
this.activePopovers.push(id);
|
|
7
|
+
this.emit('change');
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
PopoverManager.close = function(id) {
|
|
11
|
+
var index = this.activePopovers.indexOf(id);
|
|
12
|
+
if (index !== -1) {
|
|
13
|
+
this.activePopovers.splice(index, 1);
|
|
14
|
+
this.emit('change');
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
PopoverManager.closeAll = function() {
|
|
18
|
+
this.activePopovers = [];
|
|
19
|
+
this.emit('change');
|
|
20
|
+
};
|
|
21
|
+
PopoverManager.getActivePopoverId = function() {
|
|
22
|
+
return this.activePopovers[this.activePopovers.length - 1] || null;
|
|
23
|
+
};
|
|
24
|
+
export default PopoverManager;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { tv } from "tailwind-variants";
|
|
3
|
+
var styles = tv({
|
|
4
|
+
base: "Litho-ProgressBar relative bg-tint-2 dark:bg-tint-alt-2 rounded-full overflow-hidden min-w-12",
|
|
5
|
+
variants: {
|
|
6
|
+
size: {
|
|
7
|
+
small: "h-1",
|
|
8
|
+
medium: "h-3",
|
|
9
|
+
large: "h-4"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
defaultVariants: {
|
|
13
|
+
size: "medium",
|
|
14
|
+
color: "highlight",
|
|
15
|
+
animated: true
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var barStyles = tv({
|
|
19
|
+
base: "Litho-ProgressBar__Inner h-full w-0 rounded-full",
|
|
20
|
+
variants: {
|
|
21
|
+
color: {
|
|
22
|
+
attention: "bg-attention",
|
|
23
|
+
highlight: "bg-highlight",
|
|
24
|
+
success: "bg-success",
|
|
25
|
+
warning: "bg-warning",
|
|
26
|
+
critical: "bg-critical",
|
|
27
|
+
previousPositive: "bg-success/60",
|
|
28
|
+
previousNegative: "bg-critical/10",
|
|
29
|
+
positive: "bg-success/40",
|
|
30
|
+
negative: "bg-critical/60"
|
|
31
|
+
},
|
|
32
|
+
animated: {
|
|
33
|
+
true: "transition-width duration-500 ease-in-out",
|
|
34
|
+
false: ""
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
defaultVariants: {
|
|
38
|
+
color: "attention",
|
|
39
|
+
animated: true
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* A progress bar component with configurable size, color, and animation.
|
|
44
|
+
* Can be used in single or comparison mode to show progress changes.
|
|
45
|
+
*
|
|
46
|
+
* @param {Object} props - Properties to configure the progress bar.
|
|
47
|
+
* @param {number} [props.progress=0] - The progress percentage (0-100).
|
|
48
|
+
* @param {number} [props.previousProgress] - The previous period's progress percentage (0-100).
|
|
49
|
+
* @param {boolean} [props.comparisonMode=false] - Whether to show comparison between current and previous period.
|
|
50
|
+
* @param {("small"|"medium"|"large")} [props.size="medium"] - The size of the progress bar.
|
|
51
|
+
* @param {("attention"|"highlight"|"success"|"warning"|"critical"|"neutral"|"positive"|"negative")} [props.color="attention"] - The color of the progress indicator.
|
|
52
|
+
* @param {boolean} [props.animated=true] - Whether the progress bar should animate width changes.
|
|
53
|
+
*
|
|
54
|
+
* @returns {JSX.Element} The rendered progress bar component.
|
|
55
|
+
*/ function ProgressBar() {
|
|
56
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
57
|
+
var _props_progress = props.progress, progress = _props_progress === void 0 ? 0 : _props_progress, previousProgress = props.previousProgress, _props_comparisonMode = props.comparisonMode, comparisonMode = _props_comparisonMode === void 0 ? false : _props_comparisonMode, _props_size = props.size, size = _props_size === void 0 ? "medium" : _props_size, _props_color = props.color, color = _props_color === void 0 ? "attention" : _props_color, _props_animated = props.animated, animated = _props_animated === void 0 ? true : _props_animated, className = props.className;
|
|
58
|
+
var classes = styles({
|
|
59
|
+
size: size
|
|
60
|
+
});
|
|
61
|
+
var parsedProgress = Math.min(100, Math.max(0, parseInt(progress, 10)));
|
|
62
|
+
var parsedPreviousProgress = previousProgress !== undefined ? Math.min(100, Math.max(0, parseInt(previousProgress, 10))) : null;
|
|
63
|
+
if (comparisonMode && parsedPreviousProgress !== null) {
|
|
64
|
+
var difference = parsedProgress - parsedPreviousProgress;
|
|
65
|
+
var isPositive = difference > 0;
|
|
66
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
67
|
+
className: "".concat(classes).concat(className ? " ".concat(className) : ""),
|
|
68
|
+
role: "progressbar",
|
|
69
|
+
"aria-valuenow": parsedProgress,
|
|
70
|
+
"aria-valuemin": 0,
|
|
71
|
+
"aria-valuemax": 100,
|
|
72
|
+
children: [
|
|
73
|
+
/*#__PURE__*/ _jsx("div", {
|
|
74
|
+
className: "absolute ".concat(barStyles({
|
|
75
|
+
color: isPositive ? "previousPositive" : "previousNegative",
|
|
76
|
+
animated: animated
|
|
77
|
+
})),
|
|
78
|
+
style: {
|
|
79
|
+
width: "".concat(parsedPreviousProgress, "%"),
|
|
80
|
+
zIndex: isPositive ? 0 : 1
|
|
81
|
+
}
|
|
82
|
+
}),
|
|
83
|
+
difference !== 0 && /*#__PURE__*/ _jsx("div", {
|
|
84
|
+
className: "absolute ".concat(barStyles({
|
|
85
|
+
color: isPositive ? "positive" : "negative",
|
|
86
|
+
animated: animated
|
|
87
|
+
})),
|
|
88
|
+
style: {
|
|
89
|
+
width: "".concat(parsedProgress, "%"),
|
|
90
|
+
zIndex: isPositive ? 1 : 0
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
// Single bar mode
|
|
97
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
98
|
+
className: "".concat(classes).concat(className ? " ".concat(className) : ""),
|
|
99
|
+
role: "progressbar",
|
|
100
|
+
"aria-valuenow": parsedProgress,
|
|
101
|
+
"aria-valuemin": 0,
|
|
102
|
+
"aria-valuemax": 100,
|
|
103
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
104
|
+
className: barStyles({
|
|
105
|
+
color: color,
|
|
106
|
+
animated: animated
|
|
107
|
+
}),
|
|
108
|
+
style: {
|
|
109
|
+
width: "".concat(parsedProgress, "%")
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
export default ProgressBar;
|