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