@geoffcox/sterling-svelte 0.0.30 → 1.0.0

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 (223) hide show
  1. package/@types/clickOutside.d.ts +11 -7
  2. package/Button.svelte +11 -183
  3. package/Button.svelte.d.ts +2 -6
  4. package/Callout.svelte +188 -0
  5. package/Callout.svelte.d.ts +54 -0
  6. package/Checkbox.svelte +15 -177
  7. package/Checkbox.svelte.d.ts +2 -2
  8. package/ColorPicker.svelte +204 -223
  9. package/ColorPicker.svelte.d.ts +1 -2
  10. package/Dialog.svelte +91 -187
  11. package/Dialog.svelte.d.ts +3 -1
  12. package/Dropdown.svelte +52 -219
  13. package/Dropdown.svelte.d.ts +4 -8
  14. package/HexColorSliders.svelte +77 -145
  15. package/HexColorSliders.svelte.d.ts +28 -1
  16. package/HslColorSliders.svelte +99 -179
  17. package/HslColorSliders.svelte.d.ts +28 -1
  18. package/Input.svelte +27 -136
  19. package/Input.svelte.d.ts +2 -3
  20. package/Label.constants.d.ts +1 -0
  21. package/Label.constants.js +1 -0
  22. package/Label.svelte +96 -169
  23. package/Label.svelte.d.ts +6 -1
  24. package/Label.types.d.ts +3 -1
  25. package/Link.svelte +9 -106
  26. package/Link.svelte.d.ts +0 -1
  27. package/List.svelte +142 -230
  28. package/List.svelte.d.ts +2 -3
  29. package/List.types.d.ts +6 -1
  30. package/ListItem.svelte +25 -94
  31. package/ListItem.svelte.d.ts +2 -0
  32. package/Menu.svelte +48 -64
  33. package/Menu.svelte.d.ts +4 -1
  34. package/MenuBar.svelte +84 -86
  35. package/MenuBar.svelte.d.ts +4 -1
  36. package/MenuButton.svelte +67 -74
  37. package/MenuButton.svelte.d.ts +7 -3
  38. package/MenuItem.svelte +256 -288
  39. package/MenuItem.svelte.d.ts +2 -2
  40. package/MenuItemDisplay.svelte +12 -116
  41. package/MenuItemDisplay.svelte.d.ts +21 -7
  42. package/MenuSeparator.svelte +6 -45
  43. package/MenuSeparator.svelte.d.ts +8 -78
  44. package/Popover.constants.d.ts +2 -0
  45. package/{floating-ui.constants.js → Popover.constants.js} +10 -9
  46. package/Popover.svelte +72 -82
  47. package/Popover.svelte.d.ts +10 -5
  48. package/Popover.types.d.ts +4 -0
  49. package/Progress.svelte +28 -126
  50. package/Progress.svelte.d.ts +4 -3
  51. package/Radio.svelte +49 -192
  52. package/Radio.svelte.d.ts +2 -2
  53. package/RgbColorSliders.svelte +48 -137
  54. package/RgbColorSliders.svelte.d.ts +5 -5
  55. package/Select.svelte +124 -251
  56. package/Select.svelte.d.ts +6 -2
  57. package/Slider.svelte +90 -259
  58. package/Slider.svelte.d.ts +1 -2
  59. package/Switch.svelte +24 -259
  60. package/Switch.svelte.d.ts +3 -1
  61. package/Tab.svelte +27 -175
  62. package/Tab.svelte.d.ts +6 -4
  63. package/TabList.svelte +146 -171
  64. package/TabList.svelte.d.ts +3 -2
  65. package/TabList.types.d.ts +6 -1
  66. package/TextArea.svelte +32 -129
  67. package/TextArea.svelte.d.ts +1 -1
  68. package/Tooltip.svelte +88 -222
  69. package/Tooltip.svelte.d.ts +21 -13
  70. package/Tree.constants.d.ts +0 -1
  71. package/Tree.constants.js +0 -1
  72. package/Tree.svelte +35 -119
  73. package/Tree.svelte.d.ts +4 -4
  74. package/Tree.types.d.ts +1 -3
  75. package/TreeChevron.svelte +18 -98
  76. package/TreeChevron.svelte.d.ts +1 -0
  77. package/TreeItem.constants.d.ts +1 -0
  78. package/TreeItem.constants.js +1 -0
  79. package/TreeItem.svelte +251 -211
  80. package/TreeItem.svelte.d.ts +7 -3
  81. package/TreeItem.types.d.ts +1 -1
  82. package/TreeItemDisplay.svelte +20 -104
  83. package/TreeItemDisplay.svelte.d.ts +2 -2
  84. package/actions/applyLightDarkMode.d.ts +10 -0
  85. package/actions/applyLightDarkMode.js +36 -0
  86. package/actions/forwardEvents.js +3 -3
  87. package/css/Button.base.css +74 -0
  88. package/css/Button.colorful.css +17 -0
  89. package/css/Button.css +7 -0
  90. package/css/Button.secondary.colorful.css +15 -0
  91. package/css/Button.secondary.css +11 -0
  92. package/css/Button.shapes.css +14 -0
  93. package/css/Button.tool.colorful.css +13 -0
  94. package/css/Button.tool.css +18 -0
  95. package/css/Callout.base.css +43 -0
  96. package/css/Callout.colorful.css +5 -0
  97. package/css/Callout.css +2 -0
  98. package/css/Checkbox.base.css +145 -0
  99. package/css/Checkbox.colorful.css +17 -0
  100. package/css/Checkbox.css +2 -0
  101. package/css/ColorPicker.base.css +23 -0
  102. package/css/ColorPicker.css +1 -0
  103. package/css/Dialog.base.css +116 -0
  104. package/css/Dialog.css +1 -0
  105. package/css/Dropdown.base.css +147 -0
  106. package/css/Dropdown.colorful.css +23 -0
  107. package/css/Dropdown.css +2 -0
  108. package/css/HexColorSliders.base.css +106 -0
  109. package/css/HexColorSliders.css +1 -0
  110. package/css/HslColorSliders.base.css +124 -0
  111. package/css/HslColorSliders.css +1 -0
  112. package/css/Input.base.css +100 -0
  113. package/css/Input.colorful.css +22 -0
  114. package/css/Input.composed.css +8 -0
  115. package/css/Input.css +3 -0
  116. package/css/Label.base.css +119 -0
  117. package/css/Label.boxed.colorful.css +21 -0
  118. package/css/Label.boxed.css +31 -0
  119. package/css/Label.colorful.css +3 -0
  120. package/css/Label.css +4 -0
  121. package/css/Link.base.css +52 -0
  122. package/css/Link.colorful.css +15 -0
  123. package/css/Link.css +6 -0
  124. package/css/Link.ghost.colorful.css +7 -0
  125. package/css/Link.ghost.css +11 -0
  126. package/css/Link.undecorated.colorful.css +6 -0
  127. package/css/Link.undecorated.css +6 -0
  128. package/css/List.base.css +98 -0
  129. package/css/List.css +1 -0
  130. package/css/ListItem.base.css +59 -0
  131. package/css/ListItem.css +1 -0
  132. package/css/Menu.base.css +21 -0
  133. package/css/Menu.css +1 -0
  134. package/css/MenuBar.base.css +9 -0
  135. package/css/MenuBar.css +1 -0
  136. package/css/MenuButton.base.css +13 -0
  137. package/css/MenuButton.css +1 -0
  138. package/css/MenuItem.base.css +48 -0
  139. package/css/MenuItem.css +1 -0
  140. package/css/MenuItemDisplay.base.css +104 -0
  141. package/css/MenuItemDisplay.css +1 -0
  142. package/css/MenuSeparator.base.css +5 -0
  143. package/css/MenuSeparator.css +1 -0
  144. package/css/Popover copy.css +21 -0
  145. package/css/Popover.css +21 -0
  146. package/css/Progress.base.css +99 -0
  147. package/css/Progress.css +1 -0
  148. package/css/Radio.base.css +135 -0
  149. package/css/Radio.colorful.css +18 -0
  150. package/css/Radio.css +2 -0
  151. package/css/RgbColorSliders.base.css +94 -0
  152. package/css/RgbColorSliders.css +1 -0
  153. package/css/Select.base.css +127 -0
  154. package/css/Select.colorful.css +24 -0
  155. package/css/Select.composed.css +12 -0
  156. package/css/Select.css +3 -0
  157. package/css/Slider.base.css +182 -0
  158. package/css/Slider.colorful.css +11 -0
  159. package/css/Slider.composed.css +8 -0
  160. package/css/Slider.css +3 -0
  161. package/css/Switch.base.css +193 -0
  162. package/css/Switch.colorful.css +39 -0
  163. package/css/Switch.css +2 -0
  164. package/css/Tab.base.css +135 -0
  165. package/css/Tab.colorful.css +13 -0
  166. package/css/Tab.css +2 -0
  167. package/css/TabList.base.css +34 -0
  168. package/css/TabList.css +1 -0
  169. package/css/TextArea.base.css +85 -0
  170. package/css/TextArea.colorful.css +17 -0
  171. package/css/TextArea.composed.css +8 -0
  172. package/css/TextArea.css +3 -0
  173. package/css/Tooltip.base.css +6 -0
  174. package/css/Tooltip.css +1 -0
  175. package/css/Tree.base.css +74 -0
  176. package/css/Tree.composed.css +8 -0
  177. package/css/Tree.css +2 -0
  178. package/css/TreeChevron.base.css +86 -0
  179. package/css/TreeChevron.css +1 -0
  180. package/css/TreeItem.base.css +3 -0
  181. package/css/TreeItem.css +1 -0
  182. package/css/TreeItemDisplay.base.css +74 -0
  183. package/css/TreeItemDisplay.colorful.css +9 -0
  184. package/css/TreeItemDisplay.css +1 -0
  185. package/css/dark-mode.css +134 -0
  186. package/css/light-mode.css +134 -0
  187. package/css/sterling.css +37 -0
  188. package/index.d.ts +13 -18
  189. package/index.js +11 -15
  190. package/mediaQueries/prefersColorSchemeDark.d.ts +2 -0
  191. package/mediaQueries/prefersColorSchemeDark.js +10 -0
  192. package/{stores → mediaQueries}/prefersReducedMotion.d.ts +1 -0
  193. package/{stores → mediaQueries}/usingKeyboard.d.ts +1 -0
  194. package/package.json +136 -19
  195. package/Link.constants.d.ts +0 -1
  196. package/Link.constants.js +0 -1
  197. package/Link.types.d.ts +0 -4
  198. package/Tooltip.constants.d.ts +0 -1
  199. package/Tooltip.constants.js +0 -1
  200. package/Tooltip.types.d.ts +0 -4
  201. package/Tooltip.types.js +0 -1
  202. package/floating-ui.constants.d.ts +0 -1
  203. package/floating-ui.types.d.ts +0 -4
  204. package/floating-ui.types.js +0 -1
  205. package/theme/applyDarkTheme.d.ts +0 -7
  206. package/theme/applyDarkTheme.js +0 -11
  207. package/theme/applyLightTheme.d.ts +0 -7
  208. package/theme/applyLightTheme.js +0 -11
  209. package/theme/applyTheme.d.ts +0 -7
  210. package/theme/applyTheme.js +0 -20
  211. package/theme/colors.d.ts +0 -54
  212. package/theme/colors.js +0 -82
  213. package/theme/darkTheme.d.ts +0 -2
  214. package/theme/darkTheme.js +0 -142
  215. package/theme/lightTheme.d.ts +0 -2
  216. package/theme/lightTheme.js +0 -119
  217. package/theme/toggleDarkTheme.d.ts +0 -18
  218. package/theme/toggleDarkTheme.js +0 -53
  219. package/theme/types.d.ts +0 -21
  220. package/theme/types.js +0 -1
  221. /package/{Link.types.js → Popover.types.js} +0 -0
  222. /package/{stores → mediaQueries}/prefersReducedMotion.js +0 -0
  223. /package/{stores → mediaQueries}/usingKeyboard.js +0 -0
@@ -1,11 +1,15 @@
1
- declare namespace svelte.JSX {
2
- type ClickOutsideEventDetail = {
3
- mouseEvent: MouseEvent;
4
- };
1
+ import type { EventHandler } from 'svelte/elements';
5
2
 
6
- type ClickOutsideEvent = CustomEvent<ClickOutsideEventDetail>;
3
+ export type ClickOutsideEventDetail = {
4
+ mouseEvent: MouseEvent;
5
+ };
7
6
 
8
- interface DOMAttributes<T> {
9
- onclick_outside?: (e: ClickOutsideEvent) => void;
7
+ export type ClickOutsideEvent = CustomEvent<ClickOutsideEventDetail>;
8
+
9
+ declare module 'svelte/elements' {
10
+ export interface DOMAttributes<T extends EventTarget> {
11
+ 'on:click_outside'?: EventHandler<ClickOutsideEvent, T>;
10
12
  }
11
13
  }
14
+
15
+ export {}; // ensure this is not an ambient module, else types will be overridden instead of augmented
package/Button.svelte CHANGED
@@ -1,16 +1,18 @@
1
- <script>export let disabled = false;
2
- export let variant = "regular";
3
- export let shape = "rounded";
4
- export let colorful = false;
1
+ <script>// ----- Props ----- //
2
+ export let disabled = false;
3
+ /** Additional class names to apply. */
4
+ export let variant = '';
5
+ // ----- State ----- //
5
6
  let buttonRef;
7
+ // ----- Methods ----- //
6
8
  export const click = () => {
7
- buttonRef?.click();
9
+ buttonRef?.click();
8
10
  };
9
11
  export const blur = () => {
10
- buttonRef?.blur();
12
+ buttonRef?.blur();
11
13
  };
12
14
  export const focus = (options) => {
13
- buttonRef?.focus(options);
15
+ buttonRef?.focus(options);
14
16
  };
15
17
  </script>
16
18
 
@@ -20,12 +22,7 @@ export const focus = (options) => {
20
22
  -->
21
23
  <button
22
24
  bind:this={buttonRef}
23
- class="sterling-button"
24
- class:colorful
25
- class:square={shape === 'square'}
26
- class:circular={shape === 'circular'}
27
- class:outline={variant === 'outline'}
28
- class:ghost={variant === 'ghost'}
25
+ class={`sterling-button ${variant}`}
29
26
  {disabled}
30
27
  type="button"
31
28
  on:blur
@@ -62,174 +59,5 @@ export const focus = (options) => {
62
59
  on:wheel|passive
63
60
  {...$$restProps}
64
61
  >
65
- <slot {disabled} {colorful} {shape} {variant} />
62
+ <slot {disabled} {variant} />
66
63
  </button>
67
-
68
- <style>
69
- button {
70
- align-content: center;
71
- align-items: center;
72
- background-color: var(--stsv-button__background-color);
73
- border-color: var(--stsv-button__border-color);
74
- border-radius: var(--stsv-button__border-radius);
75
- border-style: var(--stsv-button__border-style);
76
- border-width: var(--stsv-button__border-width);
77
- box-sizing: border-box;
78
- color: var(--stsv-button__color);
79
- cursor: pointer;
80
- display: inline-flex;
81
- flex-direction: row;
82
- font: inherit;
83
- justify-content: center;
84
- justify-items: center;
85
- column-gap: 0.25em;
86
- overflow: hidden;
87
- padding: 0.5em 1em;
88
- text-decoration: none;
89
- text-overflow: ellipsis;
90
- transition: background-color 250ms, color 250ms, border-color 250ms;
91
- white-space: nowrap;
92
- user-select: none;
93
- }
94
-
95
- button.vertical {
96
- flex-direction: column;
97
- row-gap: 0.15em;
98
- }
99
-
100
- button.circular {
101
- border-radius: 10000px;
102
- padding: 0.5em;
103
- }
104
-
105
- button.square {
106
- border-radius: 0;
107
- }
108
-
109
- button:hover {
110
- background-color: var(--stsv-button__background-color--hover);
111
- border-color: var(--stsv-button__border-color--hover);
112
- color: var(--stsv-button__color--hover);
113
- }
114
-
115
- button:active {
116
- background-color: var(--stsv-button__background-color--active);
117
- border-color: var(--stsv-button__border-color--active);
118
- color: var(--stsv-button__color--active);
119
- }
120
-
121
- button:focus-visible {
122
- border-color: var(--stsv-button__border-color--focus);
123
- outline-color: var(--stsv-common__outline-color);
124
- outline-offset: var(--stsv-common__outline-offset);
125
- outline-style: var(--stsv-common__outline-style);
126
- outline-width: var(--stsv-common__outline-width);
127
- }
128
-
129
- button.colorful {
130
- background-color: var(--stsv-button--colorful__background-color);
131
- border-color: var(--stsv-button--colorful__border-color);
132
- color: var(--stsv-button--colorful__color);
133
- }
134
- button.colorful:hover {
135
- background-color: var(--stsv-button--colorful__background-color--hover);
136
- border-color: var(--stsv-button--colorful__border-color--hover);
137
- color: var(--stsv-button--colorful__color--hover);
138
- }
139
-
140
- button.colorful:active {
141
- background-color: var(--stsv-button--colorful__background-color--active);
142
- border-color: var(--stsv-button--colorful__border-color--active);
143
- color: var(--stsv-button--colorful__color--active);
144
- }
145
-
146
- button.outline {
147
- background-color: transparent;
148
- }
149
-
150
- button.outline:hover {
151
- background-color: var(--stsv-button__background-color--hover);
152
- }
153
-
154
- button.outline:active {
155
- background-color: var(--stsv-button__background-color--active);
156
- }
157
-
158
- button.outline.colorful {
159
- border-color: var(--stsv-button--colorful__border-color);
160
- color: var(--stsv-button--colorful__border-color);
161
- }
162
- button.outline.colorful:hover {
163
- background-color: var(--stsv-button--colorful__background-color--hover);
164
- border-color: var(--stsv-button--colorful__border-color--hover);
165
- color: var(--stsv-button--colorful__color--hover);
166
- }
167
-
168
- button.outline.colorful:active {
169
- background-color: var(--stsv-button--colorful__background-color--active);
170
- border-color: var(--stsv-button--colorful__border-color--active);
171
- color: var(--stsv-button--colorful__color--active);
172
- }
173
-
174
- button.ghost {
175
- background-color: transparent;
176
- border-color: transparent;
177
- }
178
-
179
- button.ghost:hover {
180
- background-color: var(--stsv-button__background-color--hover);
181
- border-color: transparent;
182
- }
183
-
184
- button.ghost:active {
185
- background-color: var(--stsv-button__background-color--active);
186
- border-color: transparent;
187
- }
188
-
189
- button.ghost:focus-visible {
190
- border-color: var(--stsv-button__border-color--focus);
191
- }
192
-
193
- button.ghost.colorful {
194
- color: var(--stsv-button--colorful__border-color);
195
- }
196
-
197
- button.ghost.colorful:hover {
198
- background-color: var(--stsv-button--colorful__background-color--hover);
199
- color: var(--stsv-button--colorful__color--hover);
200
- }
201
-
202
- button.ghost.colorful:active {
203
- background-color: var(--stsv-button--colorful__background-color--active);
204
- color: var(--stsv-button--colorful__color--active);
205
- }
206
-
207
- button:disabled {
208
- cursor: not-allowed;
209
- position: relative;
210
- }
211
-
212
- button:disabled::after {
213
- content: '';
214
- position: absolute;
215
- left: 0;
216
- right: 0;
217
- top: 0;
218
- bottom: 0;
219
- background: repeating-linear-gradient(
220
- var(--stsv-common--disabled__stripe-angle),
221
- var(--stsv-common--disabled__stripe-color),
222
- var(--stsv-common--disabled__stripe-color) var(--stsv-common--disabled__stripe-width),
223
- var(--stsv-common--disabled__stripe-color--alt) var(--stsv-common--disabled__stripe-width),
224
- var(--stsv-common--disabled__stripe-color--alt)
225
- calc(2 * var(--stsv-common--disabled__stripe-width))
226
- );
227
- pointer-events: none;
228
- }
229
-
230
- @media (prefers-reduced-motion) {
231
- button {
232
- transition: none;
233
- }
234
- }
235
- </style>
@@ -3,9 +3,7 @@ declare const __propDef: {
3
3
  props: {
4
4
  [x: string]: any;
5
5
  disabled?: boolean | undefined;
6
- variant?: "regular" | "outline" | "ghost" | undefined;
7
- shape?: "circular" | "rounded" | "square" | undefined;
8
- colorful?: boolean | undefined;
6
+ variant?: string | undefined;
9
7
  click?: (() => void) | undefined;
10
8
  blur?: (() => void) | undefined;
11
9
  focus?: ((options?: FocusOptions) => void) | undefined;
@@ -49,9 +47,7 @@ declare const __propDef: {
49
47
  slots: {
50
48
  default: {
51
49
  disabled: boolean;
52
- colorful: boolean;
53
- shape: "circular" | "rounded" | "square";
54
- variant: "regular" | "outline" | "ghost";
50
+ variant: string;
55
51
  };
56
52
  };
57
53
  };
package/Callout.svelte ADDED
@@ -0,0 +1,188 @@
1
+ <script>import { onMount } from 'svelte';
2
+ import { arrow, autoUpdate, computePosition, flip, offset } from '@floating-ui/dom';
3
+ import { portal } from './actions/portal';
4
+ import { STERLING_PORTAL_HOST_ID } from './Popover.constants';
5
+ import { fade } from 'svelte/transition';
6
+ import { prefersReducedMotion } from './mediaQueries/prefersReducedMotion';
7
+ // ----- Props ----- //
8
+ /** Conditionally renders content based on open. */
9
+ export let conditionalRender = true;
10
+ /** The offset along the side of the reference element. */
11
+ export let crossAxisOffset = 0;
12
+ /** The offset towards or away from the side of the reference element. */
13
+ export let mainAxisOffset = 0;
14
+ /** When true, the callout is open and visible. */
15
+ export let open = false;
16
+ /** How the callout should be positioned relative to the reference element. */
17
+ export let placement = 'bottom-start';
18
+ /** The host container for the callout. */
19
+ export let portalHost = undefined;
20
+ /** The reference to the element anchoring the position of the callout. */
21
+ export let reference;
22
+ /** Additional class names to apply. */
23
+ export let variant = '';
24
+ // ----- State ----- //
25
+ let popupRef;
26
+ let arrowRef;
27
+ let popupPosition = { x: 0, y: 0 };
28
+ $: floatingUIPlacement = placement;
29
+ // ----- Portal Host ----- //
30
+ const ensurePortalHost = () => {
31
+ if (document) {
32
+ if (portalHost) {
33
+ return portalHost;
34
+ }
35
+ let host = document.querySelector(`#${STERLING_PORTAL_HOST_ID}`);
36
+ if (!host) {
37
+ host = document.createElement('div');
38
+ host.id = STERLING_PORTAL_HOST_ID;
39
+ host.style.overflow = 'visible';
40
+ document.body.append(host);
41
+ }
42
+ portalHost = host;
43
+ }
44
+ };
45
+ // ----- Body Height Change ----- //
46
+ let bodyHeight = 0;
47
+ // create an Observer instance
48
+ const resizeObserver = new ResizeObserver((entries) => {
49
+ bodyHeight = entries[0].target.clientHeight;
50
+ });
51
+ // ----- Position ----- //
52
+ $: middleware = [
53
+ offset({ mainAxis: mainAxisOffset, crossAxis: crossAxisOffset }),
54
+ flip(),
55
+ arrow({ element: arrowRef, padding: 8 })
56
+ ];
57
+ const computeCalloutPosition = async () => {
58
+ if (reference && popupRef) {
59
+ popupPosition = await computePosition(reference, popupRef, {
60
+ placement: floatingUIPlacement,
61
+ middleware
62
+ });
63
+ }
64
+ else {
65
+ popupPosition = { x: 0, y: 0 };
66
+ }
67
+ };
68
+ // whenever a positioned element is portaled it needs resubscription to auto-update
69
+ let cleanupAutoUpdate = () => { };
70
+ const autoUpdateCalloutPosition = () => {
71
+ cleanupAutoUpdate();
72
+ if (reference && popupRef) {
73
+ cleanupAutoUpdate = autoUpdate(reference, popupRef, computeCalloutPosition);
74
+ }
75
+ };
76
+ $: popupRef, reference, autoUpdateCalloutPosition();
77
+ $: open, bodyHeight, middleware, placement, computeCalloutPosition();
78
+ // ----- Arrow ----- //
79
+ const getArrowPlacementStyle = (position) => {
80
+ if (position?.placement && arrowRef) {
81
+ switch (position.placement) {
82
+ case 'top':
83
+ case 'top-start':
84
+ case 'top-end':
85
+ return (`bottom: -${arrowRef.offsetWidth}px;` +
86
+ `filter: drop-shadow(-1px -2px 1px rgba(0,0,0,0.2));` +
87
+ `transform:translate(0, -50%) rotate(135deg);`);
88
+ case 'right':
89
+ case 'right-start':
90
+ case 'right-end':
91
+ return (`left: -${arrowRef.offsetWidth}px;` + `transform:translate(50%, 0) rotate(225deg);`);
92
+ case 'bottom':
93
+ case 'bottom-start':
94
+ case 'bottom-end':
95
+ return `top: -${arrowRef.offsetWidth}px;` + `transform:translate(0, 50%) rotate(-45deg);`;
96
+ case 'left':
97
+ case 'left-start':
98
+ case 'left-end':
99
+ return (`right: -${arrowRef.offsetWidth}px;` +
100
+ `filter: drop-shadow(2px 2px 1px rgba(0,0,0,0.2));` +
101
+ `transform:translate(-50%, 0) rotate(45deg);`);
102
+ }
103
+ }
104
+ return '';
105
+ };
106
+ const getArrowOffsetStyle = (position) => {
107
+ const arrow = position?.middlewareData?.arrow;
108
+ if (arrow) {
109
+ if (arrow.x !== null && arrow.x !== undefined) {
110
+ return `left: ${arrow.x}px;`;
111
+ }
112
+ else if (arrow.y !== null && arrow.y !== undefined) {
113
+ return `top: ${arrow.y}px;`;
114
+ }
115
+ }
116
+ return '';
117
+ };
118
+ $: arrowStyle = getArrowPlacementStyle(popupPosition) + getArrowOffsetStyle(popupPosition);
119
+ // ----- Animation ----- //
120
+ const fadeNoOp = (node, params) => {
121
+ return { delay: 0, duration: 0 };
122
+ };
123
+ $: fadeMotion = !$prefersReducedMotion ? fade : fadeNoOp;
124
+ // ----- EventHandlers ----- //
125
+ onMount(() => {
126
+ ensurePortalHost();
127
+ // start observing a DOM node
128
+ resizeObserver.observe(document.body);
129
+ return () => {
130
+ resizeObserver.unobserve(document.body);
131
+ };
132
+ });
133
+ const onKeydown = (event) => {
134
+ if (event.key === 'Escape') {
135
+ open = false;
136
+ }
137
+ };
138
+ ensurePortalHost();
139
+ </script>
140
+
141
+ {#if open || !conditionalRender}
142
+ <div
143
+ use:portal={{ target: portalHost ?? document.body }}
144
+ class="sterling-callout-portal"
145
+ transition:fadeMotion|global={{ duration: 250 }}
146
+ >
147
+ <!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
148
+ <div
149
+ bind:this={popupRef}
150
+ class={`sterling-callout ${variant}`}
151
+ class:open
152
+ role="tooltip"
153
+ on:blur
154
+ on:click
155
+ on:copy
156
+ on:cut
157
+ on:dblclick
158
+ on:dragend
159
+ on:dragenter
160
+ on:dragleave
161
+ on:dragover
162
+ on:dragstart
163
+ on:drop
164
+ on:focus
165
+ on:focusin
166
+ on:focusout
167
+ on:keydown
168
+ on:keypress
169
+ on:keyup
170
+ on:mousedown
171
+ on:mouseenter
172
+ on:mouseleave
173
+ on:mousemove
174
+ on:mouseover
175
+ on:mouseout
176
+ on:mouseup
177
+ on:scroll
178
+ on:wheel|passive
179
+ on:paste
180
+ on:keydown={onKeydown}
181
+ {...$$restProps}
182
+ style="left:{popupPosition.x}px; top:{popupPosition.y}px"
183
+ >
184
+ <slot />
185
+ <div class="arrow" bind:this={arrowRef} style={arrowStyle} />
186
+ </div>
187
+ </div>
188
+ {/if}
@@ -0,0 +1,54 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ [x: string]: any;
5
+ conditionalRender?: boolean | undefined;
6
+ crossAxisOffset?: number | undefined;
7
+ mainAxisOffset?: number | undefined;
8
+ open?: boolean | undefined;
9
+ placement?: string | undefined;
10
+ portalHost?: HTMLElement | undefined;
11
+ reference: HTMLElement | undefined;
12
+ variant?: string | undefined;
13
+ };
14
+ events: {
15
+ blur: FocusEvent;
16
+ click: MouseEvent;
17
+ copy: ClipboardEvent;
18
+ cut: ClipboardEvent;
19
+ dblclick: MouseEvent;
20
+ dragend: DragEvent;
21
+ dragenter: DragEvent;
22
+ dragleave: DragEvent;
23
+ dragover: DragEvent;
24
+ dragstart: DragEvent;
25
+ drop: DragEvent;
26
+ focus: FocusEvent;
27
+ focusin: FocusEvent;
28
+ focusout: FocusEvent;
29
+ keydown: KeyboardEvent;
30
+ keypress: KeyboardEvent;
31
+ keyup: KeyboardEvent;
32
+ mousedown: MouseEvent;
33
+ mouseenter: MouseEvent;
34
+ mouseleave: MouseEvent;
35
+ mousemove: MouseEvent;
36
+ mouseover: MouseEvent;
37
+ mouseout: MouseEvent;
38
+ mouseup: MouseEvent;
39
+ scroll: Event;
40
+ wheel: WheelEvent;
41
+ paste: ClipboardEvent;
42
+ } & {
43
+ [evt: string]: CustomEvent<any>;
44
+ };
45
+ slots: {
46
+ default: {};
47
+ };
48
+ };
49
+ export type CalloutProps = typeof __propDef.props;
50
+ export type CalloutEvents = typeof __propDef.events;
51
+ export type CalloutSlots = typeof __propDef.slots;
52
+ export default class Callout extends SvelteComponentTyped<CalloutProps, CalloutEvents, CalloutSlots> {
53
+ }
54
+ export {};