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