@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,220 @@
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 _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
13
+ var _tailwindvariants = require("tailwind-variants");
14
+ var _index = require("../index");
15
+ var _polarisicons = require("@shopify/polaris-icons");
16
+ function _getRequireWildcardCache(nodeInterop) {
17
+ if (typeof WeakMap !== "function") return null;
18
+ var cacheBabelInterop = new WeakMap();
19
+ var cacheNodeInterop = new WeakMap();
20
+ return (_getRequireWildcardCache = function(nodeInterop) {
21
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
22
+ })(nodeInterop);
23
+ }
24
+ function _interop_require_wildcard(obj, nodeInterop) {
25
+ if (!nodeInterop && obj && obj.__esModule) {
26
+ return obj;
27
+ }
28
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
29
+ return {
30
+ default: obj
31
+ };
32
+ }
33
+ var cache = _getRequireWildcardCache(nodeInterop);
34
+ if (cache && cache.has(obj)) {
35
+ return cache.get(obj);
36
+ }
37
+ var newObj = {
38
+ __proto__: null
39
+ };
40
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
41
+ for(var key in obj){
42
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
43
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
44
+ if (desc && (desc.get || desc.set)) {
45
+ Object.defineProperty(newObj, key, desc);
46
+ } else {
47
+ newObj[key] = obj[key];
48
+ }
49
+ }
50
+ }
51
+ newObj.default = obj;
52
+ if (cache) {
53
+ cache.set(obj, newObj);
54
+ }
55
+ return newObj;
56
+ }
57
+ var styles = (0, _tailwindvariants.tv)({
58
+ base: "Litho-Tip relative flex rounded-md p-2",
59
+ variants: {
60
+ status: {
61
+ success: "bg-success-alt text-success-alt-fg",
62
+ critical: "bg-critical-alt text-critical-alt-fg",
63
+ warning: "bg-attention-alt text-attention-alt-fg",
64
+ attention: "bg-attention-alt text-attention-alt-fg",
65
+ highlight: "bg-highlight-alt text-highlight-alt-fg",
66
+ insight: "bg-insight-alt text-insight-alt-fg",
67
+ info: "bg-info-alt text-info-alt-fg",
68
+ plain: "bg-transparent text-subdued px-0!"
69
+ },
70
+ dismissible: {
71
+ true: "pr-8"
72
+ },
73
+ clickable: {
74
+ true: "cursor-pointer"
75
+ },
76
+ border: {
77
+ true: "border border-tint-2"
78
+ }
79
+ },
80
+ defaultVariants: {
81
+ status: "info",
82
+ dismissible: false,
83
+ clickable: false,
84
+ border: false
85
+ },
86
+ compoundVariants: [
87
+ {
88
+ clickable: true,
89
+ status: "info",
90
+ className: "hover:outline hover:outline-info-alt-lower"
91
+ }
92
+ ]
93
+ });
94
+ var innerStyles = (0, _tailwindvariants.tv)({
95
+ base: "flex gap-2 items-start flex-1",
96
+ variants: {
97
+ align: {
98
+ left: "justify-start",
99
+ right: "justify-end",
100
+ center: "justify-center"
101
+ }
102
+ },
103
+ defaultVariants: {
104
+ align: "left"
105
+ }
106
+ });
107
+ var dismissButtonStyles = (0, _tailwindvariants.tv)({
108
+ base: "absolute top-1 right-1 p-1 rounded-md bg-transparent",
109
+ variants: {
110
+ status: {
111
+ success: "hover:bg-success-alt-lower",
112
+ critical: "hover:bg-critical-alt-lower",
113
+ warning: "hover:bg-attention-alt-lower",
114
+ attention: "hover:bg-attention-alt-lower",
115
+ info: "hover:bg-info-alt-lower",
116
+ highlight: "hover:bg-highlight-alt-lower",
117
+ insight: "hover:bg-insight-alt-lower"
118
+ }
119
+ }
120
+ });
121
+ var statusHelpers = {
122
+ info: {},
123
+ critical: {
124
+ icon: _polarisicons.AlertMinor
125
+ },
126
+ success: {},
127
+ warning: {
128
+ icon: _polarisicons.AlertMinor
129
+ },
130
+ attention: {},
131
+ highlight: {},
132
+ neutral: {}
133
+ };
134
+ /**
135
+ * Tip component for displaying informational messages with optional dismiss functionality.
136
+ *
137
+ * @param {Object} props - The component props.
138
+ * @param {"info" | "critical" | "success" | "warning" | "attention" | "highlight" | "neutral"} [props.status="info"] - The status type of the tip.
139
+ * @param {Function} [props.onDismiss] - Function to call when the dismiss button is clicked.
140
+ * @param {Function} [props.onClick] - Function to call when the tip is clicked.
141
+ * @param {React.ReactNode} props.children - The content of the tip.
142
+ * @param {React.ElementType} [props.icon] - Custom icon for the tip.
143
+ * @param {"left" | "right" | "center"} [props.align="left"] - The alignment of the tip.
144
+ * @returns {JSX.Element} The rendered Tip component.
145
+ */ function Tip() {
146
+ var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
147
+ var _statusHelpers_status;
148
+ var _props_status = props.status, status = _props_status === void 0 ? "info" : _props_status, onClick = props.onClick, onDismiss = props.onDismiss, children = props.children, _icon = props.icon, _props_align = props.align, align = _props_align === void 0 ? "left" : _props_align, border = props.border;
149
+ var icon = _icon === null ? null : _icon || ((_statusHelpers_status = statusHelpers[status]) === null || _statusHelpers_status === void 0 ? void 0 : _statusHelpers_status.icon) || _polarisicons.InfoMinor;
150
+ var classes = styles({
151
+ status: status,
152
+ dismissible: !!onDismiss,
153
+ clickable: !!onClick,
154
+ border: border
155
+ });
156
+ var base = "-alt-icon";
157
+ var iconColorMap = {
158
+ critical: "critical".concat(base),
159
+ success: "success".concat(base),
160
+ warning: "warning".concat(base),
161
+ attention: "attention".concat(base),
162
+ info: "info".concat(base),
163
+ highlight: "highlight".concat(base),
164
+ insight: "insight".concat(base),
165
+ neutral: "neutral".concat(base),
166
+ default: "info".concat(base)
167
+ };
168
+ var iconColor = iconColorMap[status] || iconColorMap.default;
169
+ var processedChildren = (0, _react.useMemo)(function() {
170
+ var processChildren = function(children) {
171
+ return _react.default.Children.toArray(children).map(function(child) {
172
+ if (!/*#__PURE__*/ (0, _react.isValidElement)(child)) return child;
173
+ if (child.type.displayName === "Link") {
174
+ return /*#__PURE__*/ (0, _react.cloneElement)(child, {
175
+ color: status
176
+ });
177
+ }
178
+ if (!child.props.children) return child;
179
+ return /*#__PURE__*/ (0, _react.cloneElement)(child, {
180
+ children: processChildren(child.props.children)
181
+ });
182
+ });
183
+ };
184
+ return processChildren(children);
185
+ }, [
186
+ children,
187
+ status
188
+ ]);
189
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
190
+ className: classes,
191
+ onClick: onClick,
192
+ children: [
193
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
194
+ className: innerStyles({
195
+ align: align
196
+ }),
197
+ children: [
198
+ icon && /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.Icon, {
199
+ source: icon,
200
+ color: iconColor
201
+ }),
202
+ /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
203
+ children: processedChildren
204
+ })
205
+ ]
206
+ }),
207
+ onDismiss && /*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
208
+ onClick: onDismiss,
209
+ className: dismissButtonStyles({
210
+ status: status
211
+ }),
212
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.Icon, {
213
+ source: _polarisicons.CancelMinor,
214
+ color: iconColor
215
+ })
216
+ })
217
+ ]
218
+ });
219
+ }
220
+ var _default = Tip;
@@ -0,0 +1,431 @@
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 = /*#__PURE__*/ _interop_require_wildcard(require("react"));
14
+ var _reactdom = require("react-dom");
15
+ var _tailwindvariants = require("tailwind-variants");
16
+ var _index = require("../index");
17
+ var _polarisicons = require("@shopify/polaris-icons");
18
+ function _array_like_to_array(arr, len) {
19
+ if (len == null || len > arr.length) len = arr.length;
20
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
21
+ return arr2;
22
+ }
23
+ function _array_with_holes(arr) {
24
+ if (Array.isArray(arr)) return arr;
25
+ }
26
+ function _define_property(obj, key, value) {
27
+ if (key in obj) {
28
+ Object.defineProperty(obj, key, {
29
+ value: value,
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true
33
+ });
34
+ } else {
35
+ obj[key] = value;
36
+ }
37
+ return obj;
38
+ }
39
+ function _getRequireWildcardCache(nodeInterop) {
40
+ if (typeof WeakMap !== "function") return null;
41
+ var cacheBabelInterop = new WeakMap();
42
+ var cacheNodeInterop = new WeakMap();
43
+ return (_getRequireWildcardCache = function(nodeInterop) {
44
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
45
+ })(nodeInterop);
46
+ }
47
+ function _interop_require_wildcard(obj, nodeInterop) {
48
+ if (!nodeInterop && obj && obj.__esModule) {
49
+ return obj;
50
+ }
51
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
52
+ return {
53
+ default: obj
54
+ };
55
+ }
56
+ var cache = _getRequireWildcardCache(nodeInterop);
57
+ if (cache && cache.has(obj)) {
58
+ return cache.get(obj);
59
+ }
60
+ var newObj = {
61
+ __proto__: null
62
+ };
63
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
64
+ for(var key in obj){
65
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
66
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
67
+ if (desc && (desc.get || desc.set)) {
68
+ Object.defineProperty(newObj, key, desc);
69
+ } else {
70
+ newObj[key] = obj[key];
71
+ }
72
+ }
73
+ }
74
+ newObj.default = obj;
75
+ if (cache) {
76
+ cache.set(obj, newObj);
77
+ }
78
+ return newObj;
79
+ }
80
+ function _iterable_to_array_limit(arr, i) {
81
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
82
+ if (_i == null) return;
83
+ var _arr = [];
84
+ var _n = true;
85
+ var _d = false;
86
+ var _s, _e;
87
+ try {
88
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
89
+ _arr.push(_s.value);
90
+ if (i && _arr.length === i) break;
91
+ }
92
+ } catch (err) {
93
+ _d = true;
94
+ _e = err;
95
+ } finally{
96
+ try {
97
+ if (!_n && _i["return"] != null) _i["return"]();
98
+ } finally{
99
+ if (_d) throw _e;
100
+ }
101
+ }
102
+ return _arr;
103
+ }
104
+ function _non_iterable_rest() {
105
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
106
+ }
107
+ function _object_spread(target) {
108
+ for(var i = 1; i < arguments.length; i++){
109
+ var source = arguments[i] != null ? arguments[i] : {};
110
+ var ownKeys = Object.keys(source);
111
+ if (typeof Object.getOwnPropertySymbols === "function") {
112
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
113
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
114
+ }));
115
+ }
116
+ ownKeys.forEach(function(key) {
117
+ _define_property(target, key, source[key]);
118
+ });
119
+ }
120
+ return target;
121
+ }
122
+ function _sliced_to_array(arr, i) {
123
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
124
+ }
125
+ function _type_of(obj) {
126
+ "@swc/helpers - typeof";
127
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
128
+ }
129
+ function _unsupported_iterable_to_array(o, minLen) {
130
+ if (!o) return;
131
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
132
+ var n = Object.prototype.toString.call(o).slice(8, -1);
133
+ if (n === "Object" && o.constructor) n = o.constructor.name;
134
+ if (n === "Map" || n === "Set") return Array.from(n);
135
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
136
+ }
137
+ var styles = (0, _tailwindvariants.tv)({
138
+ base: "Litho-TooltipContainer relative w-auto h-auto",
139
+ variants: {
140
+ display: {
141
+ inline: "inline",
142
+ "inline-block": "inline-block",
143
+ block: "block"
144
+ },
145
+ hasUnderline: {
146
+ true: "Litho-TooltipContainer--HasUnderline border-b border-dotted",
147
+ false: ""
148
+ }
149
+ }
150
+ });
151
+ var wrapperStyles = (0, _tailwindvariants.tv)({
152
+ base: "Litho-TooltipWrapper absolute w-60 flex",
153
+ variants: {
154
+ preferredPosition: {
155
+ above: "bottom-full pb-2",
156
+ below: "top-full pt-2"
157
+ },
158
+ alignment: {
159
+ center: "left-1/2 -translate-x-1/2 justify-center",
160
+ left: "left-0 justify-start",
161
+ right: "right-0 justify-end"
162
+ },
163
+ dismissOnMouseOut: {
164
+ true: "pointer-events-none",
165
+ false: "pointer-events-auto"
166
+ }
167
+ },
168
+ defaultVariants: {
169
+ preferredPosition: "below",
170
+ alignment: "center",
171
+ dismissOnMouseOut: true
172
+ }
173
+ });
174
+ var tooltipStyles = (0, _tailwindvariants.tv)({
175
+ base: "Litho-Tooltip inline-block w-auto max-w-60 whitespace-normal overflow-hidden bg-surface-alternate text-alternate dark:text-highest py-1.5 px-3 rounded-md",
176
+ variants: {
177
+ alignment: {
178
+ center: "text-center",
179
+ left: "text-left",
180
+ right: "text-right"
181
+ }
182
+ },
183
+ defaultVariants: {
184
+ alignment: "center"
185
+ }
186
+ });
187
+ var arrowStyles = (0, _tailwindvariants.tv)({
188
+ base: "Litho-TooltipArrow absolute w-0 h-0 border-l-transparent border-r-transparent border-l-6 border-r-6",
189
+ variants: {
190
+ preferredPosition: {
191
+ above: "Litho-TooltipArrow--Above mb-0.5 bottom-full border-b-0 border-t-6 border-t-surface-alternate",
192
+ below: "Litho-TooltipArrow--Below mt-0.5 top-full border-t-0 border-b-6 border-b-surface-alternate"
193
+ },
194
+ alignment: {
195
+ center: "left-1/2 -translate-x-1/2",
196
+ left: "left-2.5",
197
+ right: "right-2.5"
198
+ }
199
+ },
200
+ defaultVariants: {
201
+ preferredPosition: "below",
202
+ alignment: "center"
203
+ }
204
+ });
205
+ /**
206
+ * @typedef {Object} TooltipContentItem
207
+ * @property {'paragraph' | 'heading' | 'list'} type - The type of content item
208
+ * @property {string | string[]} content - The content of the item. For 'list' type, this should be an array of strings
209
+ */ /**
210
+ * @typedef {Object} TooltipContentObject
211
+ * @property {string} [heading] - Optional heading text for the tooltip
212
+ * @property {TooltipContentItem[]} content - Array of content items to display in the tooltip
213
+ */ /**
214
+ * Tooltip component for displaying contextual information when hovering over an element.
215
+ * The tooltip can be positioned above or below the activator with customizable alignment.
216
+ * It includes optional underline styling and supports dynamic z-index overrides.
217
+ *
218
+ * @component
219
+ *
220
+ * @param {Object} props - The props for the Tooltip component.
221
+ * @param {React.ReactNode} props.children - The content that triggers the tooltip on hover.
222
+ * @param {React.ReactNode | TooltipContentObject} props.content - The content displayed inside the tooltip. Can be either a React node or a structured content object.
223
+ * @param {boolean} [props.dismissOnMouseOut=true] - Whether the tooltip should be dismissed when the mouse leaves the activator.
224
+ * @param {boolean} [props.dismissOnActivatorClick=true] - Whether the tooltip should be dismissed when clicking the activator.
225
+ * @param {"above" | "below"} [props.preferredPosition="below"] - The preferred position of the tooltip relative to the activator.
226
+ * @param {"center" | "left" | "right"} [props.alignment="center"] - The alignment of the tooltip content.
227
+ * @param {number} [props.hoverDelay=0] - The delay (in milliseconds) before showing the tooltip on hover.
228
+ * @param {boolean} [props.hasUnderline=false] - Whether the activator should have an underline.
229
+ * @param {number | boolean} [props.zIndexOverride] - Override for the z-index of the tooltip.
230
+ * @param {"inline" | "inline-block" | "block"} [props.display="inline-block"] - The display property of the tooltip container.
231
+ *
232
+ * @returns {React.ReactElement} The rendered Tooltip component.
233
+ *
234
+ * @example
235
+ * // Basic usage with string content
236
+ * <Tooltip content="This is a tooltip">
237
+ * <button>Hover me</button>
238
+ * </Tooltip>
239
+ *
240
+ * @example
241
+ * // Using structured content object
242
+ * <Tooltip content={{
243
+ * heading: "Important Information",
244
+ * content: [
245
+ * { type: "paragraph", content: "This is a paragraph." },
246
+ * { type: "list", content: ["Item 1", "Item 2", "Item 3"] }
247
+ * ]
248
+ * }}>
249
+ * <span>Hover for structured content</span>
250
+ * </Tooltip>
251
+ */ function Tooltip() {
252
+ var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
253
+ var _props_display = props.display, display = _props_display === void 0 ? "inline-block" : _props_display, children = props.children, content = props.content, _props_dismissOnMouseOut = props.dismissOnMouseOut, dismissOnMouseOut = _props_dismissOnMouseOut === void 0 ? true : _props_dismissOnMouseOut, _props_dismissOnActivatorClick = props.dismissOnActivatorClick, dismissOnActivatorClick = _props_dismissOnActivatorClick === void 0 ? true : _props_dismissOnActivatorClick, _props_preferredPosition = props.preferredPosition, preferredPosition = _props_preferredPosition === void 0 ? "below" : _props_preferredPosition, _props_alignment = props.alignment, alignment = _props_alignment === void 0 ? "center" : _props_alignment, _props_hoverDelay = props.hoverDelay, hoverDelay = _props_hoverDelay === void 0 ? 0 : _props_hoverDelay, _props_hasUnderline = props.hasUnderline, hasUnderline = _props_hasUnderline === void 0 ? false : _props_hasUnderline, zIndexOverride = props.zIndexOverride;
254
+ var activatorRef = (0, _react.useRef)(null);
255
+ var tooltipRef = (0, _react.useRef)(null);
256
+ var _useState = _sliced_to_array((0, _react.useState)({
257
+ top: 0,
258
+ left: 0
259
+ }), 2), tooltipStyle = _useState[0], setTooltipStyle = _useState[1];
260
+ var _useState1 = _sliced_to_array((0, _react.useState)(false), 2), isVisible = _useState1[0], setIsVisible = _useState1[1];
261
+ var _useState2 = _sliced_to_array((0, _react.useState)(preferredPosition), 2), actualPosition = _useState2[0], setActualPosition = _useState2[1];
262
+ var classes = styles({
263
+ hasUnderline: hasUnderline,
264
+ display: display,
265
+ alignment: alignment
266
+ });
267
+ var wrapperClasses = wrapperStyles({
268
+ preferredPosition: actualPosition,
269
+ alignment: alignment,
270
+ dismissOnMouseOut: dismissOnMouseOut
271
+ });
272
+ var tooltipClasses = tooltipStyles({
273
+ alignment: alignment
274
+ });
275
+ var arrowClasses = arrowStyles({
276
+ preferredPosition: actualPosition,
277
+ alignment: alignment
278
+ });
279
+ var STYLE_OVERRIDES = _object_spread({}, zIndexOverride && {
280
+ zIndex: zIndexOverride
281
+ });
282
+ var hoverTimeoutRef = (0, _react.useRef)(null);
283
+ (0, _react.useEffect)(function() {
284
+ if (isVisible && tooltipRef.current && activatorRef.current) {
285
+ var tooltipRect = tooltipRef.current.getBoundingClientRect();
286
+ var activatorRect = activatorRef.current.getBoundingClientRect();
287
+ var viewportHeight = window.innerHeight;
288
+ var spaceAbove = activatorRect.top;
289
+ var spaceBelow = viewportHeight - activatorRect.bottom;
290
+ if (preferredPosition === "below" && spaceBelow < tooltipRect.height) {
291
+ setActualPosition("above");
292
+ } else if (preferredPosition === "above" && spaceAbove < tooltipRect.height) {
293
+ setActualPosition("below");
294
+ } else {
295
+ setActualPosition(preferredPosition);
296
+ }
297
+ }
298
+ }, [
299
+ isVisible,
300
+ preferredPosition
301
+ ]);
302
+ (0, _react.useEffect)(function() {
303
+ if (isVisible) {
304
+ var activatorRect = activatorRef.current.getBoundingClientRect();
305
+ setTooltipStyle({
306
+ top: activatorRect.top + window.scrollY,
307
+ left: activatorRect.left + window.scrollX,
308
+ width: activatorRect.width,
309
+ height: activatorRect.height
310
+ });
311
+ }
312
+ }, [
313
+ isVisible
314
+ ]);
315
+ var handleMouseEnter = function() {
316
+ if (hoverTimeoutRef.current) {
317
+ clearTimeout(hoverTimeoutRef.current);
318
+ hoverTimeoutRef.current = null;
319
+ }
320
+ if (hoverDelay > 0) {
321
+ hoverTimeoutRef.current = setTimeout(function() {
322
+ setIsVisible(true);
323
+ }, hoverDelay);
324
+ } else {
325
+ setIsVisible(true);
326
+ }
327
+ };
328
+ var handleMouseLeave = function() {
329
+ if (hoverTimeoutRef.current) {
330
+ clearTimeout(hoverTimeoutRef.current);
331
+ hoverTimeoutRef.current = null;
332
+ }
333
+ setTimeout(function() {
334
+ var _tooltipRef_current;
335
+ if (!((_tooltipRef_current = tooltipRef.current) === null || _tooltipRef_current === void 0 ? void 0 : _tooltipRef_current.contains(document.activeElement))) {
336
+ setIsVisible(false);
337
+ }
338
+ }, 10);
339
+ };
340
+ var blockForItem = function(param) {
341
+ var item = param.item, key = param.key;
342
+ if (item.type == "paragraph") {
343
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.Text, {
344
+ variant: "bodySm",
345
+ alignment: "start",
346
+ children: item.content
347
+ }, key);
348
+ } else if (item.type === "heading") {
349
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.Text, {
350
+ variant: "headingSm",
351
+ alignment: "start",
352
+ children: item.content
353
+ }, key);
354
+ } else if (item.type == "list") {
355
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.VerticalStack, {
356
+ inlineAlign: "start",
357
+ align: "start",
358
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.List, {
359
+ type: "bullet",
360
+ children: item.content.map(function(item) {
361
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.List.Item, {
362
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.Text, {
363
+ alignment: "start",
364
+ variant: "bodySm",
365
+ children: item
366
+ })
367
+ }, item);
368
+ })
369
+ })
370
+ }, key);
371
+ }
372
+ };
373
+ var tooltipContent = (typeof content === "undefined" ? "undefined" : _type_of(content)) === "object" && (content.heading || content.content) ? /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
374
+ className: "flex flex-col gap-1.5 py-1",
375
+ children: [
376
+ content.heading && blockForItem({
377
+ item: {
378
+ type: "heading",
379
+ content: content.heading
380
+ },
381
+ key: "heading"
382
+ }),
383
+ content.content.map(function(item, index) {
384
+ return blockForItem({
385
+ item: item,
386
+ key: index
387
+ });
388
+ })
389
+ ]
390
+ }) : content;
391
+ var handleActivatorClick = function() {
392
+ if (isVisible) {
393
+ setIsVisible(false);
394
+ }
395
+ };
396
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
397
+ className: classes,
398
+ ref: activatorRef,
399
+ onMouseEnter: handleMouseEnter,
400
+ onMouseLeave: handleMouseLeave,
401
+ onClick: dismissOnActivatorClick ? handleActivatorClick : undefined,
402
+ children: [
403
+ children ? children : /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.Icon, {
404
+ source: _polarisicons.CircleInformationMajor,
405
+ color: "subdued"
406
+ }),
407
+ isVisible && /*#__PURE__*/ (0, _reactdom.createPortal)(/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
408
+ className: "Litho-TooltipPortal absolute pointer-events-none",
409
+ style: tooltipStyle,
410
+ children: [
411
+ /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
412
+ ref: tooltipRef,
413
+ className: wrapperClasses,
414
+ style: STYLE_OVERRIDES,
415
+ onMouseEnter: dismissOnMouseOut ? undefined : handleMouseEnter,
416
+ onMouseLeave: dismissOnMouseOut ? undefined : handleMouseLeave,
417
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
418
+ className: tooltipClasses,
419
+ children: tooltipContent
420
+ })
421
+ }),
422
+ /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
423
+ className: arrowClasses,
424
+ style: STYLE_OVERRIDES
425
+ })
426
+ ]
427
+ }), document.body)
428
+ ]
429
+ });
430
+ }
431
+ var _default = Tooltip;