@geoffcox/sterling-svelte 0.0.31 → 1.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 (215) 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 +107 -146
  5. package/Callout.svelte.d.ts +1 -1
  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 +90 -187
  11. package/Dialog.svelte.d.ts +2 -1
  12. package/Dropdown.svelte +52 -220
  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 -65
  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 +66 -73
  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 +1 -1
  45. package/Popover.constants.js +1 -1
  46. package/Popover.svelte +66 -80
  47. package/Popover.svelte.d.ts +5 -1
  48. package/Progress.svelte +28 -126
  49. package/Progress.svelte.d.ts +4 -3
  50. package/Radio.svelte +49 -192
  51. package/Radio.svelte.d.ts +2 -2
  52. package/RgbColorSliders.svelte +48 -137
  53. package/RgbColorSliders.svelte.d.ts +5 -5
  54. package/Select.svelte +122 -250
  55. package/Select.svelte.d.ts +6 -2
  56. package/Slider.svelte +90 -259
  57. package/Slider.svelte.d.ts +1 -2
  58. package/Switch.svelte +24 -259
  59. package/Switch.svelte.d.ts +3 -1
  60. package/Tab.svelte +27 -175
  61. package/Tab.svelte.d.ts +6 -4
  62. package/TabList.svelte +146 -171
  63. package/TabList.svelte.d.ts +3 -2
  64. package/TabList.types.d.ts +6 -1
  65. package/TextArea.svelte +32 -129
  66. package/TextArea.svelte.d.ts +1 -1
  67. package/Tooltip.svelte +46 -47
  68. package/Tooltip.svelte.d.ts +8 -3
  69. package/Tree.constants.d.ts +0 -1
  70. package/Tree.constants.js +0 -1
  71. package/Tree.svelte +35 -119
  72. package/Tree.svelte.d.ts +4 -4
  73. package/Tree.types.d.ts +1 -3
  74. package/TreeChevron.svelte +18 -98
  75. package/TreeChevron.svelte.d.ts +1 -0
  76. package/TreeItem.constants.d.ts +1 -0
  77. package/TreeItem.constants.js +1 -0
  78. package/TreeItem.svelte +251 -211
  79. package/TreeItem.svelte.d.ts +7 -3
  80. package/TreeItem.types.d.ts +1 -1
  81. package/TreeItemDisplay.svelte +20 -104
  82. package/TreeItemDisplay.svelte.d.ts +2 -2
  83. package/actions/applyLightDarkMode.d.ts +10 -0
  84. package/actions/applyLightDarkMode.js +36 -0
  85. package/actions/forwardEvents.js +3 -3
  86. package/css/Button.base.css +74 -0
  87. package/css/Button.colorful.css +17 -0
  88. package/css/Button.css +7 -0
  89. package/css/Button.secondary.colorful.css +15 -0
  90. package/css/Button.secondary.css +11 -0
  91. package/css/Button.shapes.css +14 -0
  92. package/css/Button.tool.colorful.css +13 -0
  93. package/css/Button.tool.css +18 -0
  94. package/css/Callout.base.css +43 -0
  95. package/css/Callout.colorful.css +5 -0
  96. package/css/Callout.css +2 -0
  97. package/css/Checkbox.base.css +145 -0
  98. package/css/Checkbox.colorful.css +17 -0
  99. package/css/Checkbox.css +2 -0
  100. package/css/ColorPicker.base.css +23 -0
  101. package/css/ColorPicker.css +1 -0
  102. package/css/Dialog.base.css +116 -0
  103. package/css/Dialog.css +1 -0
  104. package/css/Dropdown.base.css +147 -0
  105. package/css/Dropdown.colorful.css +23 -0
  106. package/css/Dropdown.css +2 -0
  107. package/css/HexColorSliders.base.css +106 -0
  108. package/css/HexColorSliders.css +1 -0
  109. package/css/HslColorSliders.base.css +124 -0
  110. package/css/HslColorSliders.css +1 -0
  111. package/css/Input.base.css +100 -0
  112. package/css/Input.colorful.css +22 -0
  113. package/css/Input.composed.css +8 -0
  114. package/css/Input.css +3 -0
  115. package/css/Label.base.css +119 -0
  116. package/css/Label.boxed.colorful.css +21 -0
  117. package/css/Label.boxed.css +31 -0
  118. package/css/Label.colorful.css +3 -0
  119. package/css/Label.css +4 -0
  120. package/css/Link.base.css +52 -0
  121. package/css/Link.colorful.css +15 -0
  122. package/css/Link.css +6 -0
  123. package/css/Link.ghost.colorful.css +7 -0
  124. package/css/Link.ghost.css +11 -0
  125. package/css/Link.undecorated.colorful.css +6 -0
  126. package/css/Link.undecorated.css +6 -0
  127. package/css/List.base.css +98 -0
  128. package/css/List.css +1 -0
  129. package/css/ListItem.base.css +59 -0
  130. package/css/ListItem.css +1 -0
  131. package/css/Menu.base.css +21 -0
  132. package/css/Menu.css +1 -0
  133. package/css/MenuBar.base.css +9 -0
  134. package/css/MenuBar.css +1 -0
  135. package/css/MenuButton.base.css +13 -0
  136. package/css/MenuButton.css +1 -0
  137. package/css/MenuItem.base.css +48 -0
  138. package/css/MenuItem.css +1 -0
  139. package/css/MenuItemDisplay.base.css +104 -0
  140. package/css/MenuItemDisplay.css +1 -0
  141. package/css/MenuSeparator.base.css +5 -0
  142. package/css/MenuSeparator.css +1 -0
  143. package/css/Popover copy.css +21 -0
  144. package/css/Popover.css +21 -0
  145. package/css/Progress.base.css +99 -0
  146. package/css/Progress.css +1 -0
  147. package/css/Radio.base.css +135 -0
  148. package/css/Radio.colorful.css +18 -0
  149. package/css/Radio.css +2 -0
  150. package/css/RgbColorSliders.base.css +94 -0
  151. package/css/RgbColorSliders.css +1 -0
  152. package/css/Select.base.css +127 -0
  153. package/css/Select.colorful.css +24 -0
  154. package/css/Select.composed.css +12 -0
  155. package/css/Select.css +3 -0
  156. package/css/Slider.base.css +182 -0
  157. package/css/Slider.colorful.css +11 -0
  158. package/css/Slider.composed.css +8 -0
  159. package/css/Slider.css +3 -0
  160. package/css/Switch.base.css +193 -0
  161. package/css/Switch.colorful.css +39 -0
  162. package/css/Switch.css +2 -0
  163. package/css/Tab.base.css +135 -0
  164. package/css/Tab.colorful.css +13 -0
  165. package/css/Tab.css +2 -0
  166. package/css/TabList.base.css +34 -0
  167. package/css/TabList.css +1 -0
  168. package/css/TextArea.base.css +85 -0
  169. package/css/TextArea.colorful.css +17 -0
  170. package/css/TextArea.composed.css +8 -0
  171. package/css/TextArea.css +3 -0
  172. package/css/Tooltip.base.css +6 -0
  173. package/css/Tooltip.css +1 -0
  174. package/css/Tree.base.css +74 -0
  175. package/css/Tree.composed.css +8 -0
  176. package/css/Tree.css +2 -0
  177. package/css/TreeChevron.base.css +86 -0
  178. package/css/TreeChevron.css +1 -0
  179. package/css/TreeItem.base.css +3 -0
  180. package/css/TreeItem.css +1 -0
  181. package/css/TreeItemDisplay.base.css +74 -0
  182. package/css/TreeItemDisplay.colorful.css +9 -0
  183. package/css/TreeItemDisplay.css +1 -0
  184. package/css/dark-mode.css +134 -0
  185. package/css/light-mode.css +134 -0
  186. package/css/sterling.css +37 -0
  187. package/index.d.ts +9 -13
  188. package/index.js +8 -12
  189. package/mediaQueries/prefersColorSchemeDark.d.ts +2 -0
  190. package/mediaQueries/prefersColorSchemeDark.js +10 -0
  191. package/{stores → mediaQueries}/prefersReducedMotion.d.ts +1 -0
  192. package/{stores → mediaQueries}/usingKeyboard.d.ts +1 -0
  193. package/package.json +121 -13
  194. package/Link.constants.d.ts +0 -1
  195. package/Link.constants.js +0 -1
  196. package/Link.types.d.ts +0 -4
  197. package/Link.types.js +0 -1
  198. package/theme/applyDarkTheme.d.ts +0 -7
  199. package/theme/applyDarkTheme.js +0 -11
  200. package/theme/applyLightTheme.d.ts +0 -7
  201. package/theme/applyLightTheme.js +0 -11
  202. package/theme/applyTheme.d.ts +0 -7
  203. package/theme/applyTheme.js +0 -20
  204. package/theme/colors.d.ts +0 -54
  205. package/theme/colors.js +0 -82
  206. package/theme/darkTheme.d.ts +0 -2
  207. package/theme/darkTheme.js +0 -142
  208. package/theme/lightTheme.d.ts +0 -2
  209. package/theme/lightTheme.js +0 -119
  210. package/theme/toggleDarkTheme.d.ts +0 -18
  211. package/theme/toggleDarkTheme.js +0 -53
  212. package/theme/types.d.ts +0 -21
  213. package/theme/types.js +0 -1
  214. /package/{stores → mediaQueries}/prefersReducedMotion.js +0 -0
  215. /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 CHANGED
@@ -1,127 +1,139 @@
1
- <script>import { onMount } from "svelte";
2
- import {
3
- arrow,
4
- autoUpdate,
5
- computePosition,
6
- flip,
7
- offset
8
- } from "@floating-ui/dom";
9
- import { portal } from "./actions/portal";
10
- import { POPOVER_PORTAL_ID } from "./Popover.constants";
11
- import { fade } from "svelte/transition";
12
- import { prefersReducedMotion } from "./stores/prefersReducedMotion";
13
- export let colorful = false;
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. */
14
9
  export let conditionalRender = true;
10
+ /** The offset along the side of the reference element. */
15
11
  export let crossAxisOffset = 0;
12
+ /** The offset towards or away from the side of the reference element. */
16
13
  export let mainAxisOffset = 0;
14
+ /** When true, the callout is open and visible. */
17
15
  export let open = false;
18
- export let placement = "bottom-start";
19
- export let portalHost = void 0;
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. */
20
21
  export let reference;
22
+ /** Additional class names to apply. */
23
+ export let variant = '';
24
+ // ----- State ----- //
21
25
  let popupRef;
22
26
  let arrowRef;
23
27
  let popupPosition = { x: 0, y: 0 };
24
- $:
25
- floatingUIPlacement = placement;
28
+ $: floatingUIPlacement = placement;
29
+ // ----- Portal Host ----- //
26
30
  const ensurePortalHost = () => {
27
- if (document) {
28
- if (portalHost) {
29
- return portalHost;
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;
30
43
  }
31
- let host = document.querySelector(`#${POPOVER_PORTAL_ID}`);
32
- if (!host) {
33
- host = document.createElement("div");
34
- host.id = POPOVER_PORTAL_ID;
35
- host.style.overflow = "visible";
36
- document.body.append(host);
37
- }
38
- portalHost = host;
39
- }
40
44
  };
45
+ // ----- Body Height Change ----- //
41
46
  let bodyHeight = 0;
47
+ // create an Observer instance
42
48
  const resizeObserver = new ResizeObserver((entries) => {
43
- bodyHeight = entries[0].target.clientHeight;
49
+ bodyHeight = entries[0].target.clientHeight;
44
50
  });
45
- $:
46
- middleware = [
51
+ // ----- Position ----- //
52
+ $: middleware = [
47
53
  offset({ mainAxis: mainAxisOffset, crossAxis: crossAxisOffset }),
48
54
  flip(),
49
55
  arrow({ element: arrowRef, padding: 8 })
50
- ];
56
+ ];
51
57
  const computeCalloutPosition = async () => {
52
- if (reference && popupRef) {
53
- popupPosition = await computePosition(reference, popupRef, {
54
- placement: floatingUIPlacement,
55
- middleware
56
- });
57
- } else {
58
- popupPosition = { x: 0, y: 0 };
59
- }
60
- };
61
- let cleanupAutoUpdate = () => {
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
+ }
62
67
  };
68
+ // whenever a positioned element is portaled it needs resubscription to auto-update
69
+ let cleanupAutoUpdate = () => { };
63
70
  const autoUpdateCalloutPosition = () => {
64
- cleanupAutoUpdate();
65
- if (reference && popupRef) {
66
- cleanupAutoUpdate = autoUpdate(reference, popupRef, computeCalloutPosition);
67
- }
71
+ cleanupAutoUpdate();
72
+ if (reference && popupRef) {
73
+ cleanupAutoUpdate = autoUpdate(reference, popupRef, computeCalloutPosition);
74
+ }
68
75
  };
69
- $:
70
- popupRef, reference, autoUpdateCalloutPosition();
71
- $:
72
- open, bodyHeight, middleware, placement, computeCalloutPosition();
76
+ $: popupRef, reference, autoUpdateCalloutPosition();
77
+ $: open, bodyHeight, middleware, placement, computeCalloutPosition();
78
+ // ----- Arrow ----- //
73
79
  const getArrowPlacementStyle = (position) => {
74
- if (position?.placement && arrowRef) {
75
- switch (position.placement) {
76
- case "top":
77
- case "top-start":
78
- case "top-end":
79
- return `bottom: -${arrowRef.offsetWidth}px;filter: drop-shadow(-1px -2px 1px rgba(0,0,0,0.2));transform:translate(0, -50%) rotate(135deg);`;
80
- case "right":
81
- case "right-start":
82
- case "right-end":
83
- return `left: -${arrowRef.offsetWidth}px;transform:translate(50%, 0) rotate(225deg);`;
84
- case "bottom":
85
- case "bottom-start":
86
- case "bottom-end":
87
- return `top: -${arrowRef.offsetWidth}px;transform:translate(0, 50%) rotate(-45deg);`;
88
- case "left":
89
- case "left-start":
90
- case "left-end":
91
- return `right: -${arrowRef.offsetWidth}px;filter: drop-shadow(2px 2px 1px rgba(0,0,0,0.2));transform:translate(-50%, 0) rotate(45deg);`;
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
+ }
92
103
  }
93
- }
94
- return "";
104
+ return '';
95
105
  };
96
106
  const getArrowOffsetStyle = (position) => {
97
- const arrow2 = position?.middlewareData?.arrow;
98
- if (arrow2) {
99
- if (arrow2.x !== null && arrow2.x !== void 0) {
100
- return `left: ${arrow2.x}px;`;
101
- } else if (arrow2.y !== null && arrow2.y !== void 0) {
102
- return `top: ${arrow2.y}px;`;
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
+ }
103
115
  }
104
- }
105
- return "";
116
+ return '';
106
117
  };
107
- $:
108
- arrowStyle = getArrowPlacementStyle(popupPosition) + getArrowOffsetStyle(popupPosition);
118
+ $: arrowStyle = getArrowPlacementStyle(popupPosition) + getArrowOffsetStyle(popupPosition);
119
+ // ----- Animation ----- //
109
120
  const fadeNoOp = (node, params) => {
110
- return { delay: 0, duration: 0 };
121
+ return { delay: 0, duration: 0 };
111
122
  };
112
- $:
113
- fadeMotion = !$prefersReducedMotion ? fade : fadeNoOp;
123
+ $: fadeMotion = !$prefersReducedMotion ? fade : fadeNoOp;
124
+ // ----- EventHandlers ----- //
114
125
  onMount(() => {
115
- ensurePortalHost();
116
- resizeObserver.observe(document.body);
117
- return () => {
118
- resizeObserver.unobserve(document.body);
119
- };
126
+ ensurePortalHost();
127
+ // start observing a DOM node
128
+ resizeObserver.observe(document.body);
129
+ return () => {
130
+ resizeObserver.unobserve(document.body);
131
+ };
120
132
  });
121
133
  const onKeydown = (event) => {
122
- if (event.key === "Escape") {
123
- open = false;
124
- }
134
+ if (event.key === 'Escape') {
135
+ open = false;
136
+ }
125
137
  };
126
138
  ensurePortalHost();
127
139
  </script>
@@ -132,11 +144,12 @@ ensurePortalHost();
132
144
  class="sterling-callout-portal"
133
145
  transition:fadeMotion|global={{ duration: 250 }}
134
146
  >
147
+ <!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
135
148
  <div
136
149
  bind:this={popupRef}
137
- class="sterling-callout"
150
+ class={`sterling-callout ${variant}`}
138
151
  class:open
139
- class:colorful
152
+ role="tooltip"
140
153
  on:blur
141
154
  on:click
142
155
  on:copy
@@ -173,55 +186,3 @@ ensurePortalHost();
173
186
  </div>
174
187
  </div>
175
188
  {/if}
176
-
177
- <style>
178
- .sterling-callout-portal {
179
- position: relative;
180
- overflow: visible;
181
- }
182
-
183
- .sterling-callout {
184
- background-color: var(--stsv-common__background-color);
185
- border-color: var(--stsv-common__border-color);
186
- border-radius: var(--stsv-common__border-radius);
187
- border-style: var(--stsv-common__border-style);
188
- border-width: var(--stsv-common__border-width);
189
- box-shadow: rgba(0, 0, 0, 0.4) 2px 2px 4px -1px;
190
- box-sizing: border-box;
191
- color: var(--stsv-common__color);
192
- display: none;
193
- grid-template-columns: 1fr;
194
- grid-template-rows: 1fr;
195
- height: fit-content;
196
- left: 0;
197
- overflow: visible;
198
- position: absolute;
199
- top: 0;
200
- width: max-content;
201
- z-index: 0;
202
- }
203
-
204
- .sterling-callout.open {
205
- display: grid;
206
- }
207
-
208
- .sterling-callout.colorful {
209
- background-color: var(--stsv-button--colorful__background-color);
210
- border-color: var(--stsv-button--colorful__border-color);
211
- color: var(--stsv-button--colorful__color);
212
- }
213
-
214
- .arrow {
215
- position: absolute;
216
- box-sizing: border-box;
217
- width: 14px;
218
- height: 14px;
219
- background-color: inherit;
220
- border-color: inherit;
221
- border-style: inherit;
222
- border-width: inherit;
223
- /* This clip path clips 1/2 the square to create a triangle */
224
- /* The -100% and 200% allow for the drop-shadow to not be clipped */
225
- clip-path: polygon(-100% -100%, 200% -100%, 200% 200%, -100% -100%);
226
- }
227
- </style>
@@ -2,7 +2,6 @@ import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
4
  [x: string]: any;
5
- colorful?: boolean | undefined;
6
5
  conditionalRender?: boolean | undefined;
7
6
  crossAxisOffset?: number | undefined;
8
7
  mainAxisOffset?: number | undefined;
@@ -10,6 +9,7 @@ declare const __propDef: {
10
9
  placement?: string | undefined;
11
10
  portalHost?: HTMLElement | undefined;
12
11
  reference: HTMLElement | undefined;
12
+ variant?: string | undefined;
13
13
  };
14
14
  events: {
15
15
  blur: FocusEvent;