@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.
- package/@types/clickOutside.d.ts +11 -7
- package/Button.svelte +11 -183
- package/Button.svelte.d.ts +2 -6
- package/Callout.svelte +188 -0
- package/Callout.svelte.d.ts +54 -0
- package/Checkbox.svelte +15 -177
- package/Checkbox.svelte.d.ts +2 -2
- package/ColorPicker.svelte +204 -223
- package/ColorPicker.svelte.d.ts +1 -2
- package/Dialog.svelte +91 -187
- package/Dialog.svelte.d.ts +3 -1
- package/Dropdown.svelte +52 -219
- package/Dropdown.svelte.d.ts +4 -8
- package/HexColorSliders.svelte +77 -145
- package/HexColorSliders.svelte.d.ts +28 -1
- package/HslColorSliders.svelte +99 -179
- package/HslColorSliders.svelte.d.ts +28 -1
- package/Input.svelte +27 -136
- package/Input.svelte.d.ts +2 -3
- package/Label.constants.d.ts +1 -0
- package/Label.constants.js +1 -0
- package/Label.svelte +96 -169
- package/Label.svelte.d.ts +6 -1
- package/Label.types.d.ts +3 -1
- package/Link.svelte +9 -106
- package/Link.svelte.d.ts +0 -1
- package/List.svelte +142 -230
- package/List.svelte.d.ts +2 -3
- package/List.types.d.ts +6 -1
- package/ListItem.svelte +25 -94
- package/ListItem.svelte.d.ts +2 -0
- package/Menu.svelte +48 -64
- package/Menu.svelte.d.ts +4 -1
- package/MenuBar.svelte +84 -86
- package/MenuBar.svelte.d.ts +4 -1
- package/MenuButton.svelte +67 -74
- package/MenuButton.svelte.d.ts +7 -3
- package/MenuItem.svelte +256 -288
- package/MenuItem.svelte.d.ts +2 -2
- package/MenuItemDisplay.svelte +12 -116
- package/MenuItemDisplay.svelte.d.ts +21 -7
- package/MenuSeparator.svelte +6 -45
- package/MenuSeparator.svelte.d.ts +8 -78
- package/Popover.constants.d.ts +2 -0
- package/{floating-ui.constants.js → Popover.constants.js} +10 -9
- package/Popover.svelte +72 -82
- package/Popover.svelte.d.ts +10 -5
- package/Popover.types.d.ts +4 -0
- package/Progress.svelte +28 -126
- package/Progress.svelte.d.ts +4 -3
- package/Radio.svelte +49 -192
- package/Radio.svelte.d.ts +2 -2
- package/RgbColorSliders.svelte +48 -137
- package/RgbColorSliders.svelte.d.ts +5 -5
- package/Select.svelte +124 -251
- package/Select.svelte.d.ts +6 -2
- package/Slider.svelte +90 -259
- package/Slider.svelte.d.ts +1 -2
- package/Switch.svelte +24 -259
- package/Switch.svelte.d.ts +3 -1
- package/Tab.svelte +27 -175
- package/Tab.svelte.d.ts +6 -4
- package/TabList.svelte +146 -171
- package/TabList.svelte.d.ts +3 -2
- package/TabList.types.d.ts +6 -1
- package/TextArea.svelte +32 -129
- package/TextArea.svelte.d.ts +1 -1
- package/Tooltip.svelte +88 -222
- package/Tooltip.svelte.d.ts +21 -13
- package/Tree.constants.d.ts +0 -1
- package/Tree.constants.js +0 -1
- package/Tree.svelte +35 -119
- package/Tree.svelte.d.ts +4 -4
- package/Tree.types.d.ts +1 -3
- package/TreeChevron.svelte +18 -98
- package/TreeChevron.svelte.d.ts +1 -0
- package/TreeItem.constants.d.ts +1 -0
- package/TreeItem.constants.js +1 -0
- package/TreeItem.svelte +251 -211
- package/TreeItem.svelte.d.ts +7 -3
- package/TreeItem.types.d.ts +1 -1
- package/TreeItemDisplay.svelte +20 -104
- package/TreeItemDisplay.svelte.d.ts +2 -2
- package/actions/applyLightDarkMode.d.ts +10 -0
- package/actions/applyLightDarkMode.js +36 -0
- package/actions/forwardEvents.js +3 -3
- package/css/Button.base.css +74 -0
- package/css/Button.colorful.css +17 -0
- package/css/Button.css +7 -0
- package/css/Button.secondary.colorful.css +15 -0
- package/css/Button.secondary.css +11 -0
- package/css/Button.shapes.css +14 -0
- package/css/Button.tool.colorful.css +13 -0
- package/css/Button.tool.css +18 -0
- package/css/Callout.base.css +43 -0
- package/css/Callout.colorful.css +5 -0
- package/css/Callout.css +2 -0
- package/css/Checkbox.base.css +145 -0
- package/css/Checkbox.colorful.css +17 -0
- package/css/Checkbox.css +2 -0
- package/css/ColorPicker.base.css +23 -0
- package/css/ColorPicker.css +1 -0
- package/css/Dialog.base.css +116 -0
- package/css/Dialog.css +1 -0
- package/css/Dropdown.base.css +147 -0
- package/css/Dropdown.colorful.css +23 -0
- package/css/Dropdown.css +2 -0
- package/css/HexColorSliders.base.css +106 -0
- package/css/HexColorSliders.css +1 -0
- package/css/HslColorSliders.base.css +124 -0
- package/css/HslColorSliders.css +1 -0
- package/css/Input.base.css +100 -0
- package/css/Input.colorful.css +22 -0
- package/css/Input.composed.css +8 -0
- package/css/Input.css +3 -0
- package/css/Label.base.css +119 -0
- package/css/Label.boxed.colorful.css +21 -0
- package/css/Label.boxed.css +31 -0
- package/css/Label.colorful.css +3 -0
- package/css/Label.css +4 -0
- package/css/Link.base.css +52 -0
- package/css/Link.colorful.css +15 -0
- package/css/Link.css +6 -0
- package/css/Link.ghost.colorful.css +7 -0
- package/css/Link.ghost.css +11 -0
- package/css/Link.undecorated.colorful.css +6 -0
- package/css/Link.undecorated.css +6 -0
- package/css/List.base.css +98 -0
- package/css/List.css +1 -0
- package/css/ListItem.base.css +59 -0
- package/css/ListItem.css +1 -0
- package/css/Menu.base.css +21 -0
- package/css/Menu.css +1 -0
- package/css/MenuBar.base.css +9 -0
- package/css/MenuBar.css +1 -0
- package/css/MenuButton.base.css +13 -0
- package/css/MenuButton.css +1 -0
- package/css/MenuItem.base.css +48 -0
- package/css/MenuItem.css +1 -0
- package/css/MenuItemDisplay.base.css +104 -0
- package/css/MenuItemDisplay.css +1 -0
- package/css/MenuSeparator.base.css +5 -0
- package/css/MenuSeparator.css +1 -0
- package/css/Popover copy.css +21 -0
- package/css/Popover.css +21 -0
- package/css/Progress.base.css +99 -0
- package/css/Progress.css +1 -0
- package/css/Radio.base.css +135 -0
- package/css/Radio.colorful.css +18 -0
- package/css/Radio.css +2 -0
- package/css/RgbColorSliders.base.css +94 -0
- package/css/RgbColorSliders.css +1 -0
- package/css/Select.base.css +127 -0
- package/css/Select.colorful.css +24 -0
- package/css/Select.composed.css +12 -0
- package/css/Select.css +3 -0
- package/css/Slider.base.css +182 -0
- package/css/Slider.colorful.css +11 -0
- package/css/Slider.composed.css +8 -0
- package/css/Slider.css +3 -0
- package/css/Switch.base.css +193 -0
- package/css/Switch.colorful.css +39 -0
- package/css/Switch.css +2 -0
- package/css/Tab.base.css +135 -0
- package/css/Tab.colorful.css +13 -0
- package/css/Tab.css +2 -0
- package/css/TabList.base.css +34 -0
- package/css/TabList.css +1 -0
- package/css/TextArea.base.css +85 -0
- package/css/TextArea.colorful.css +17 -0
- package/css/TextArea.composed.css +8 -0
- package/css/TextArea.css +3 -0
- package/css/Tooltip.base.css +6 -0
- package/css/Tooltip.css +1 -0
- package/css/Tree.base.css +74 -0
- package/css/Tree.composed.css +8 -0
- package/css/Tree.css +2 -0
- package/css/TreeChevron.base.css +86 -0
- package/css/TreeChevron.css +1 -0
- package/css/TreeItem.base.css +3 -0
- package/css/TreeItem.css +1 -0
- package/css/TreeItemDisplay.base.css +74 -0
- package/css/TreeItemDisplay.colorful.css +9 -0
- package/css/TreeItemDisplay.css +1 -0
- package/css/dark-mode.css +134 -0
- package/css/light-mode.css +134 -0
- package/css/sterling.css +37 -0
- package/index.d.ts +13 -18
- package/index.js +11 -15
- package/mediaQueries/prefersColorSchemeDark.d.ts +2 -0
- package/mediaQueries/prefersColorSchemeDark.js +10 -0
- package/{stores → mediaQueries}/prefersReducedMotion.d.ts +1 -0
- package/{stores → mediaQueries}/usingKeyboard.d.ts +1 -0
- package/package.json +136 -19
- package/Link.constants.d.ts +0 -1
- package/Link.constants.js +0 -1
- package/Link.types.d.ts +0 -4
- package/Tooltip.constants.d.ts +0 -1
- package/Tooltip.constants.js +0 -1
- package/Tooltip.types.d.ts +0 -4
- package/Tooltip.types.js +0 -1
- package/floating-ui.constants.d.ts +0 -1
- package/floating-ui.types.d.ts +0 -4
- package/floating-ui.types.js +0 -1
- package/theme/applyDarkTheme.d.ts +0 -7
- package/theme/applyDarkTheme.js +0 -11
- package/theme/applyLightTheme.d.ts +0 -7
- package/theme/applyLightTheme.js +0 -11
- package/theme/applyTheme.d.ts +0 -7
- package/theme/applyTheme.js +0 -20
- package/theme/colors.d.ts +0 -54
- package/theme/colors.js +0 -82
- package/theme/darkTheme.d.ts +0 -2
- package/theme/darkTheme.js +0 -142
- package/theme/lightTheme.d.ts +0 -2
- package/theme/lightTheme.js +0 -119
- package/theme/toggleDarkTheme.d.ts +0 -18
- package/theme/toggleDarkTheme.js +0 -53
- package/theme/types.d.ts +0 -21
- package/theme/types.js +0 -1
- /package/{Link.types.js → Popover.types.js} +0 -0
- /package/{stores → mediaQueries}/prefersReducedMotion.js +0 -0
- /package/{stores → mediaQueries}/usingKeyboard.js +0 -0
package/@types/clickOutside.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
type ClickOutsideEventDetail = {
|
|
3
|
-
mouseEvent: MouseEvent;
|
|
4
|
-
};
|
|
1
|
+
import type { EventHandler } from 'svelte/elements';
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
export type ClickOutsideEventDetail = {
|
|
4
|
+
mouseEvent: MouseEvent;
|
|
5
|
+
};
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
2
|
-
export let
|
|
3
|
-
|
|
4
|
-
export let
|
|
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
|
-
|
|
9
|
+
buttonRef?.click();
|
|
8
10
|
};
|
|
9
11
|
export const blur = () => {
|
|
10
|
-
|
|
12
|
+
buttonRef?.blur();
|
|
11
13
|
};
|
|
12
14
|
export const focus = (options) => {
|
|
13
|
-
|
|
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=
|
|
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} {
|
|
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>
|
package/Button.svelte.d.ts
CHANGED
|
@@ -3,9 +3,7 @@ declare const __propDef: {
|
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
disabled?: boolean | undefined;
|
|
6
|
-
variant?:
|
|
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
|
-
|
|
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 {};
|