@quaffui/quaff 1.0.0-beta1 → 1.0.0-beta12
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/README.md +2 -0
- package/dist/classes/QScrollObserver.svelte.d.ts +4 -4
- package/dist/classes/QScrollObserver.svelte.js +26 -13
- package/dist/components/avatar/QAvatar.svelte +4 -0
- package/dist/components/avatar/QAvatar.svelte.d.ts +4 -14
- package/dist/components/breadcrumbs/QBreadcrumbs.scss +9 -5
- package/dist/components/breadcrumbs/QBreadcrumbs.svelte +46 -16
- package/dist/components/breadcrumbs/QBreadcrumbs.svelte.d.ts +24 -12
- package/dist/components/breadcrumbs/QBreadcrumbsEl.scss +22 -3
- package/dist/components/breadcrumbs/QBreadcrumbsEl.svelte +50 -38
- package/dist/components/breadcrumbs/QBreadcrumbsEl.svelte.d.ts +4 -14
- package/dist/components/breadcrumbs/props.d.ts +4 -4
- package/dist/components/button/QBtn.scss +3 -1
- package/dist/components/button/QBtn.svelte +38 -22
- package/dist/components/button/QBtn.svelte.d.ts +4 -14
- package/dist/components/button/props.d.ts +9 -2
- package/dist/components/card/QCard.svelte +9 -5
- package/dist/components/card/QCard.svelte.d.ts +4 -14
- package/dist/components/card/QCardActions.svelte +4 -0
- package/dist/components/card/QCardActions.svelte.d.ts +4 -14
- package/dist/components/card/QCardSection.svelte +2 -0
- package/dist/components/card/QCardSection.svelte.d.ts +4 -14
- package/dist/components/checkbox/QCheckbox.svelte +6 -4
- package/dist/components/checkbox/QCheckbox.svelte.d.ts +4 -14
- package/dist/components/checkbox/props.d.ts +1 -1
- package/dist/components/chip/QChip.scss +3 -1
- package/dist/components/chip/QChip.svelte +24 -14
- package/dist/components/chip/QChip.svelte.d.ts +4 -14
- package/dist/components/codeBlock/QCodeBlock.svelte +8 -0
- package/dist/components/codeBlock/QCodeBlock.svelte.d.ts +4 -14
- package/dist/components/dialog/QDialog.scss +17 -0
- package/dist/components/dialog/QDialog.svelte +34 -9
- package/dist/components/dialog/QDialog.svelte.d.ts +8 -21
- package/dist/components/drawer/QDrawer.scss +2 -2
- package/dist/components/drawer/QDrawer.svelte +124 -69
- package/dist/components/drawer/QDrawer.svelte.d.ts +8 -21
- package/dist/components/drawer/props.d.ts +3 -3
- package/dist/components/expansion-item/QExpansionItem.scss +59 -0
- package/dist/components/expansion-item/QExpansionItem.svelte +319 -0
- package/dist/components/expansion-item/QExpansionItem.svelte.d.ts +8 -0
- package/dist/components/expansion-item/docs.d.ts +2 -0
- package/dist/components/expansion-item/docs.js +17 -0
- package/dist/components/expansion-item/props.d.ts +129 -0
- package/dist/components/expansion-item/props.js +1 -0
- package/dist/components/footer/QFooter.scss +1 -1
- package/dist/components/footer/QFooter.svelte +32 -28
- package/dist/components/footer/QFooter.svelte.d.ts +4 -14
- package/dist/components/header/QHeader.scss +1 -1
- package/dist/components/header/QHeader.svelte +41 -33
- package/dist/components/header/QHeader.svelte.d.ts +4 -14
- package/dist/components/icon/QIcon.svelte +6 -4
- package/dist/components/icon/QIcon.svelte.d.ts +4 -14
- package/dist/components/index.d.ts +3 -1
- package/dist/components/index.js +3 -1
- package/dist/components/input/QInput.svelte +139 -17
- package/dist/components/input/QInput.svelte.d.ts +4 -14
- package/dist/components/input/docs.js +2 -2
- package/dist/components/input/mask.d.ts +10 -0
- package/dist/components/input/mask.js +204 -0
- package/dist/components/input/props.d.ts +37 -4
- package/dist/components/layout/QLayout.svelte +248 -93
- package/dist/components/layout/QLayout.svelte.d.ts +67 -15
- package/dist/components/layout/props.d.ts +1 -1
- package/dist/components/list/QItem.scss +7 -4
- package/dist/components/list/QItem.svelte +44 -24
- package/dist/components/list/QItem.svelte.d.ts +17 -13
- package/dist/components/list/QItemSection.scss +24 -3
- package/dist/components/list/QItemSection.svelte +19 -21
- package/dist/components/list/QItemSection.svelte.d.ts +4 -14
- package/dist/components/list/QList.scss +17 -4
- package/dist/components/list/QList.svelte +30 -8
- package/dist/components/list/QList.svelte.d.ts +17 -13
- package/dist/components/list/props.d.ts +3 -3
- package/dist/components/menu/QMenu.scss +37 -0
- package/dist/components/menu/QMenu.svelte +314 -0
- package/dist/components/menu/QMenu.svelte.d.ts +8 -0
- package/dist/components/menu/docs.d.ts +2 -0
- package/dist/components/menu/docs.js +27 -0
- package/dist/components/menu/props.d.ts +48 -0
- package/dist/components/menu/props.js +1 -0
- package/dist/components/progress/QCircularProgress.svelte +17 -14
- package/dist/components/progress/QCircularProgress.svelte.d.ts +4 -14
- package/dist/components/progress/QLinearProgress.svelte +15 -15
- package/dist/components/progress/QLinearProgress.svelte.d.ts +4 -14
- package/dist/components/radio/QRadio.svelte +6 -4
- package/dist/components/radio/QRadio.svelte.d.ts +4 -14
- package/dist/components/radio/props.d.ts +1 -1
- package/dist/components/railbar/QRailbar.scss +1 -1
- package/dist/components/railbar/QRailbar.svelte +36 -35
- package/dist/components/railbar/QRailbar.svelte.d.ts +4 -14
- package/dist/components/select/QSelect.svelte +316 -102
- package/dist/components/select/QSelect.svelte.d.ts +4 -14
- package/dist/components/select/filter.d.ts +13 -0
- package/dist/components/select/filter.js +73 -0
- package/dist/components/select/index.scss +28 -27
- package/dist/components/select/option.d.ts +9 -0
- package/dist/components/select/option.js +59 -0
- package/dist/components/select/props.d.ts +40 -7
- package/dist/components/separator/QSeparator.scss +2 -0
- package/dist/components/separator/QSeparator.svelte +9 -8
- package/dist/components/separator/QSeparator.svelte.d.ts +4 -14
- package/dist/components/switch/QSwitch.scss +12 -6
- package/dist/components/switch/QSwitch.svelte +7 -1
- package/dist/components/switch/QSwitch.svelte.d.ts +4 -14
- package/dist/components/table/QTable.svelte +31 -19
- package/dist/components/table/QTable.svelte.d.ts +4 -14
- package/dist/components/table/index.scss +1 -1
- package/dist/components/tabs/QTab.scss +2 -0
- package/dist/components/tabs/QTab.svelte +19 -22
- package/dist/components/tabs/QTab.svelte.d.ts +4 -14
- package/dist/components/tabs/QTabs.svelte +59 -32
- package/dist/components/tabs/QTabs.svelte.d.ts +18 -18
- package/dist/components/toolbar/QToolbar.svelte +2 -0
- package/dist/components/toolbar/QToolbar.svelte.d.ts +4 -14
- package/dist/components/toolbar/QToolbarTitle.svelte +2 -0
- package/dist/components/toolbar/QToolbarTitle.svelte.d.ts +4 -14
- package/dist/components/tooltip/QTooltip.svelte +48 -38
- package/dist/components/tooltip/QTooltip.svelte.d.ts +29 -17
- package/dist/components/tooltip/QTooltipBase.svelte +18 -8
- package/dist/components/tooltip/QTooltipBase.svelte.d.ts +4 -14
- package/dist/composables/index.d.ts +2 -0
- package/dist/composables/index.js +2 -0
- package/dist/composables/useColor.d.ts +1 -0
- package/dist/composables/useColor.js +19 -0
- package/dist/composables/useRevealScrollObserver.svelte.d.ts +9 -0
- package/dist/composables/useRevealScrollObserver.svelte.js +25 -0
- package/dist/composables/useRouterLink.d.ts +3 -2
- package/dist/composables/useRouterLink.js +2 -2
- package/dist/css/_components.scss +2 -0
- package/dist/css/classes/_grid.scss +12 -1
- package/dist/css/index.css +1 -1
- package/dist/css/mixins/_design.scss +1 -1
- package/dist/css/mixins/_field.scss +3 -2
- package/dist/css/mixins/_table.scss +1 -1
- package/dist/css/mixins/_toolbar.scss +1 -1
- package/dist/css/shared/q-field.scss +7 -6
- package/dist/css/theme/_page.scss +8 -6
- package/dist/css/theme/_reset.scss +2 -1
- package/dist/helpers/clickOutside.js +5 -4
- package/dist/helpers/ripple.js +5 -6
- package/dist/helpers/version.d.ts +1 -1
- package/dist/helpers/version.js +1 -1
- package/dist/{components/private/ContextReseter.svelte → internal/ContextResetter.svelte} +2 -3
- package/dist/internal/ContextResetter.svelte.d.ts +8 -0
- package/dist/{components/private → internal}/QIconSnippet.svelte +2 -2
- package/dist/internal/QIconSnippet.svelte.d.ts +10 -0
- package/dist/utils/context.d.ts +49 -32
- package/dist/utils/context.js +82 -33
- package/dist/utils/dom.d.ts +6 -0
- package/dist/utils/dom.js +33 -0
- package/dist/utils/events.d.ts +0 -24
- package/dist/utils/events.js +0 -24
- package/package.json +44 -38
- package/dist/classes/QContext.svelte.d.ts +0 -42
- package/dist/classes/QContext.svelte.js +0 -63
- package/dist/components/avatar/docs.props.d.ts +0 -3
- package/dist/components/avatar/docs.props.js +0 -87
- package/dist/components/breadcrumbs/docs.props.d.ts +0 -5
- package/dist/components/breadcrumbs/docs.props.js +0 -144
- package/dist/components/button/docs.props.d.ts +0 -3
- package/dist/components/button/docs.props.js +0 -227
- package/dist/components/card/docs.props.d.ts +0 -7
- package/dist/components/card/docs.props.js +0 -89
- package/dist/components/checkbox/docs.props.d.ts +0 -3
- package/dist/components/checkbox/docs.props.js +0 -41
- package/dist/components/chip/docs.props.d.ts +0 -3
- package/dist/components/chip/docs.props.js +0 -137
- package/dist/components/codeBlock/docs.props.d.ts +0 -3
- package/dist/components/codeBlock/docs.props.js +0 -83
- package/dist/components/dialog/docs.props.d.ts +0 -3
- package/dist/components/dialog/docs.props.js +0 -65
- package/dist/components/drawer/docs.props.d.ts +0 -3
- package/dist/components/drawer/docs.props.js +0 -149
- package/dist/components/footer/docs.props.d.ts +0 -3
- package/dist/components/footer/docs.props.js +0 -65
- package/dist/components/header/docs.props.d.ts +0 -7
- package/dist/components/header/docs.props.js +0 -131
- package/dist/components/icon/docs.props.d.ts +0 -3
- package/dist/components/icon/docs.props.js +0 -107
- package/dist/components/input/docs.props.d.ts +0 -3
- package/dist/components/input/docs.props.js +0 -162
- package/dist/components/layout/docs.props.d.ts +0 -3
- package/dist/components/layout/docs.props.js +0 -81
- package/dist/components/list/docs.props.d.ts +0 -11
- package/dist/components/list/docs.props.js +0 -434
- package/dist/components/private/ContextReseter.svelte.d.ts +0 -14
- package/dist/components/private/QApi.svelte +0 -296
- package/dist/components/private/QApi.svelte.d.ts +0 -14
- package/dist/components/private/QDocs.svelte +0 -155
- package/dist/components/private/QDocs.svelte.d.ts +0 -14
- package/dist/components/private/QDocsSection.svelte +0 -62
- package/dist/components/private/QDocsSection.svelte.d.ts +0 -14
- package/dist/components/private/QIconSnippet.svelte.d.ts +0 -14
- package/dist/components/private/index.d.ts +0 -6
- package/dist/components/private/index.js +0 -6
- package/dist/components/progress/docs.props.d.ts +0 -5
- package/dist/components/progress/docs.props.js +0 -314
- package/dist/components/radio/docs.props.d.ts +0 -3
- package/dist/components/radio/docs.props.js +0 -53
- package/dist/components/railbar/docs.props.d.ts +0 -3
- package/dist/components/railbar/docs.props.js +0 -47
- package/dist/components/select/docs.props.d.ts +0 -3
- package/dist/components/select/docs.props.js +0 -198
- package/dist/components/separator/docs.props.d.ts +0 -5
- package/dist/components/separator/docs.props.js +0 -196
- package/dist/components/switch/docs.props.d.ts +0 -3
- package/dist/components/switch/docs.props.js +0 -119
- package/dist/components/table/docs.props.d.ts +0 -3
- package/dist/components/table/docs.props.js +0 -94
- package/dist/components/tabs/docs.props.d.ts +0 -5
- package/dist/components/tabs/docs.props.js +0 -86
- package/dist/components/toolbar/docs.props.d.ts +0 -5
- package/dist/components/toolbar/docs.props.js +0 -68
- package/dist/components/tooltip/docs.props.d.ts +0 -3
- package/dist/components/tooltip/docs.props.js +0 -77
- package/dist/utils/types.json +0 -31
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, tick, untrack } from "svelte";
|
|
3
|
+
import { on } from "svelte/events";
|
|
4
|
+
import { innerHeight, innerWidth } from "svelte/reactivity/window";
|
|
5
|
+
import { browser } from "$app/environment";
|
|
6
|
+
import {
|
|
7
|
+
doesOverlayUsePopover,
|
|
8
|
+
getOverlayPortalTarget,
|
|
9
|
+
usePortal,
|
|
10
|
+
} from "../../utils";
|
|
11
|
+
import type { QMenuAnchor, QMenuProps } from "./props";
|
|
12
|
+
|
|
13
|
+
// #region: --- Props
|
|
14
|
+
let {
|
|
15
|
+
value = $bindable(false),
|
|
16
|
+
target,
|
|
17
|
+
anchor = "bottom left",
|
|
18
|
+
self = "top left",
|
|
19
|
+
fit = false,
|
|
20
|
+
persistent = false,
|
|
21
|
+
autoClose = true,
|
|
22
|
+
children,
|
|
23
|
+
class: userClass,
|
|
24
|
+
...props
|
|
25
|
+
}: QMenuProps = $props();
|
|
26
|
+
// #endregion: --- Props
|
|
27
|
+
|
|
28
|
+
// #region: --- Reactive variables
|
|
29
|
+
let helperEl = $state<HTMLDivElement>();
|
|
30
|
+
let menuEl = $state<HTMLDivElement>();
|
|
31
|
+
let anchorEl = $state<HTMLElement | null>(null);
|
|
32
|
+
let menuTop = $state(0);
|
|
33
|
+
let menuLeft = $state(0);
|
|
34
|
+
let menuWidth = $state<string | undefined>();
|
|
35
|
+
let menuMaxWidth = $state<string | undefined>();
|
|
36
|
+
let menuPosition = $state<"fixed" | "absolute">("fixed");
|
|
37
|
+
let wasMenuOpen = false;
|
|
38
|
+
// #endregion: --- Reactive variables
|
|
39
|
+
|
|
40
|
+
// #region: --- Derived values
|
|
41
|
+
const [anchorX, anchorY] = $derived(parseAnchor(anchor));
|
|
42
|
+
const [selfX, selfY] = $derived(parseAnchor(self));
|
|
43
|
+
const portalTarget = $derived(
|
|
44
|
+
browser ? getOverlayPortalTarget(anchorEl) : undefined,
|
|
45
|
+
);
|
|
46
|
+
// #endregion: --- Derived values
|
|
47
|
+
|
|
48
|
+
// #region: --- Effects
|
|
49
|
+
$effect(() => {
|
|
50
|
+
if (!browser || !helperEl) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (target) {
|
|
55
|
+
anchorEl = target;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
anchorEl = findParentQuaffElement(helperEl);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
$effect(() => {
|
|
63
|
+
if (!browser) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (value && !wasMenuOpen) {
|
|
68
|
+
wasMenuOpen = true;
|
|
69
|
+
untrack(openMenu);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!value && wasMenuOpen) {
|
|
74
|
+
wasMenuOpen = false;
|
|
75
|
+
untrack(closeMenu);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
$effect(() => {
|
|
80
|
+
if (!browser || !value || !anchorEl || !menuEl) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const viewportWidth = innerWidth.current;
|
|
85
|
+
const viewportHeight = innerHeight.current;
|
|
86
|
+
const syncCurrentPosition = () =>
|
|
87
|
+
syncPosition(viewportWidth, viewportHeight);
|
|
88
|
+
|
|
89
|
+
syncCurrentPosition();
|
|
90
|
+
const removeWindowScrollListener = on(
|
|
91
|
+
window,
|
|
92
|
+
"scroll",
|
|
93
|
+
syncCurrentPosition,
|
|
94
|
+
{ capture: true },
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return () => {
|
|
98
|
+
removeWindowScrollListener();
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
$effect(() => {
|
|
103
|
+
if (!browser || !value) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const removeDocumentPointerdownListener = on(
|
|
108
|
+
document,
|
|
109
|
+
"pointerdown",
|
|
110
|
+
handleDocumentPointerdown,
|
|
111
|
+
{
|
|
112
|
+
capture: true,
|
|
113
|
+
},
|
|
114
|
+
);
|
|
115
|
+
const removeDocumentKeydownListener = on(
|
|
116
|
+
document,
|
|
117
|
+
"keydown",
|
|
118
|
+
handleDocumentKeydown,
|
|
119
|
+
{
|
|
120
|
+
capture: true,
|
|
121
|
+
},
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return () => {
|
|
125
|
+
removeDocumentPointerdownListener();
|
|
126
|
+
removeDocumentKeydownListener();
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
// #endregion: --- Effects
|
|
130
|
+
|
|
131
|
+
// #region: --- Lifecycle
|
|
132
|
+
onMount(() => hidePopover);
|
|
133
|
+
// #endregion: --- Lifecycle
|
|
134
|
+
|
|
135
|
+
// #region: --- Methods
|
|
136
|
+
export function show() {
|
|
137
|
+
value = true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function hide() {
|
|
141
|
+
value = false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function toggle() {
|
|
145
|
+
value = !value;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// #endregion: --- Methods
|
|
149
|
+
|
|
150
|
+
// #region: --- Functions
|
|
151
|
+
function findParentQuaffElement(el: HTMLElement) {
|
|
152
|
+
let parent = el.parentElement;
|
|
153
|
+
|
|
154
|
+
while (parent) {
|
|
155
|
+
if (parent.hasAttribute("data-quaff")) {
|
|
156
|
+
return parent;
|
|
157
|
+
}
|
|
158
|
+
parent = parent.parentElement;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return el.parentElement;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function parseAnchor(anchorValue: QMenuAnchor): [number, number] {
|
|
165
|
+
const [vertical, horizontal] = anchorValue.split(" ") as [string, string];
|
|
166
|
+
const verticalMap: Record<string, number> = {
|
|
167
|
+
top: 0,
|
|
168
|
+
center: 0.5,
|
|
169
|
+
bottom: 1,
|
|
170
|
+
};
|
|
171
|
+
const horizontalMap: Record<string, number> = {
|
|
172
|
+
left: 0,
|
|
173
|
+
middle: 0.5,
|
|
174
|
+
right: 1,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
return [horizontalMap[horizontal] ?? 0, verticalMap[vertical] ?? 0];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function openMenu() {
|
|
181
|
+
await tick();
|
|
182
|
+
|
|
183
|
+
if (menuEl && doesOverlayUsePopover(anchorEl) && "showPopover" in menuEl) {
|
|
184
|
+
menuEl.showPopover();
|
|
185
|
+
await tick();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
syncPosition();
|
|
189
|
+
requestAnimationFrame(() => syncPosition());
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function closeMenu() {
|
|
193
|
+
hidePopover();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function hidePopover() {
|
|
197
|
+
if (!menuEl || !("hidePopover" in menuEl)) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
menuEl.hidePopover();
|
|
203
|
+
} catch {
|
|
204
|
+
/* already closed */
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function syncPosition(
|
|
209
|
+
viewportWidth = innerWidth.current,
|
|
210
|
+
viewportHeight = innerHeight.current,
|
|
211
|
+
) {
|
|
212
|
+
if (
|
|
213
|
+
!browser ||
|
|
214
|
+
!anchorEl ||
|
|
215
|
+
!menuEl ||
|
|
216
|
+
viewportWidth === undefined ||
|
|
217
|
+
viewportHeight === undefined
|
|
218
|
+
) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const rect = anchorEl.getBoundingClientRect();
|
|
223
|
+
const dialog = anchorEl.closest("dialog");
|
|
224
|
+
const shouldUsePopover = doesOverlayUsePopover(anchorEl);
|
|
225
|
+
const dialogRect =
|
|
226
|
+
dialog?.open && !shouldUsePopover ? dialog.getBoundingClientRect() : null;
|
|
227
|
+
const margin = 8;
|
|
228
|
+
const maxViewportWidth = viewportWidth - margin * 2;
|
|
229
|
+
const baseTop = rect.top + rect.height * anchorY;
|
|
230
|
+
const baseLeft = rect.left + rect.width * anchorX;
|
|
231
|
+
const measured = menuEl.getBoundingClientRect();
|
|
232
|
+
const measuredWidth = fit
|
|
233
|
+
? Math.min(rect.width, maxViewportWidth)
|
|
234
|
+
: measured.width;
|
|
235
|
+
|
|
236
|
+
const top = baseTop - measured.height * selfY;
|
|
237
|
+
const left = baseLeft - measuredWidth * selfX;
|
|
238
|
+
|
|
239
|
+
menuWidth = fit ? `${rect.width}px` : undefined;
|
|
240
|
+
menuMaxWidth = fit ? `${maxViewportWidth}px` : undefined;
|
|
241
|
+
|
|
242
|
+
if (dialogRect) {
|
|
243
|
+
menuPosition = "absolute";
|
|
244
|
+
menuTop = top - dialogRect.top;
|
|
245
|
+
menuLeft = left - dialogRect.left;
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
menuPosition = "fixed";
|
|
250
|
+
menuTop = Math.max(
|
|
251
|
+
margin,
|
|
252
|
+
Math.min(top, viewportHeight - measured.height - margin),
|
|
253
|
+
);
|
|
254
|
+
menuLeft = Math.max(
|
|
255
|
+
margin,
|
|
256
|
+
Math.min(left, viewportWidth - measuredWidth - margin),
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function handleDocumentPointerdown(event: PointerEvent) {
|
|
261
|
+
if (!value || persistent) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const targetNode = event.target as Node;
|
|
266
|
+
if (anchorEl?.contains(targetNode) || menuEl?.contains(targetNode)) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
hide();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function handleDocumentKeydown(event: KeyboardEvent) {
|
|
274
|
+
if (!value || event.key !== "Escape") {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
event.preventDefault();
|
|
279
|
+
event.stopPropagation();
|
|
280
|
+
hide();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function handleMenuClick() {
|
|
284
|
+
if (autoClose) {
|
|
285
|
+
hide();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// #endregion: --- Functions
|
|
289
|
+
</script>
|
|
290
|
+
|
|
291
|
+
<div bind:this={helperEl} class="q-menu__helper" aria-hidden="true"></div>
|
|
292
|
+
|
|
293
|
+
{#if value}
|
|
294
|
+
<div
|
|
295
|
+
bind:this={menuEl}
|
|
296
|
+
use:usePortal={portalTarget}
|
|
297
|
+
popover={doesOverlayUsePopover(anchorEl) ? "manual" : undefined}
|
|
298
|
+
data-quaff
|
|
299
|
+
data-quaff-overlay
|
|
300
|
+
data-quaff-menu
|
|
301
|
+
role="menu"
|
|
302
|
+
tabindex="-1"
|
|
303
|
+
{...props}
|
|
304
|
+
class={["q-menu", userClass]}
|
|
305
|
+
style:position={menuPosition}
|
|
306
|
+
style:top="{menuTop}px"
|
|
307
|
+
style:left="{menuLeft}px"
|
|
308
|
+
style:width={menuWidth}
|
|
309
|
+
style:max-width={menuMaxWidth}
|
|
310
|
+
onclick={handleMenuClick}
|
|
311
|
+
>
|
|
312
|
+
{@render children?.()}
|
|
313
|
+
</div>
|
|
314
|
+
{/if}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { QMenuDocsProps, QMenuDocsSnippets } from "./docs.props";
|
|
2
|
+
export const QMenuDocs = {
|
|
3
|
+
name: "QMenu",
|
|
4
|
+
description: "QMenu displays anchored popup content. It handles positioning, outside-click dismissal, Escape dismissal, and native dialog layering.",
|
|
5
|
+
docs: {
|
|
6
|
+
props: QMenuDocsProps,
|
|
7
|
+
snippets: QMenuDocsSnippets,
|
|
8
|
+
methods: [
|
|
9
|
+
{
|
|
10
|
+
name: "show",
|
|
11
|
+
type: "() => void",
|
|
12
|
+
description: "Opens the menu.",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "hide",
|
|
16
|
+
type: "() => void",
|
|
17
|
+
description: "Closes the menu.",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "toggle",
|
|
21
|
+
type: "() => void",
|
|
22
|
+
description: "Toggles the menu open state.",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
events: [],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
export type QMenuAnchor = "top left" | "top middle" | "top right" | "center left" | "center middle" | "center right" | "bottom left" | "bottom middle" | "bottom right";
|
|
4
|
+
export interface QMenuProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
/**
|
|
6
|
+
* Bound open state.
|
|
7
|
+
*
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
value?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Element to anchor the menu to. When omitted, QMenu anchors to the nearest parent Quaff component.
|
|
13
|
+
*
|
|
14
|
+
* @default undefined
|
|
15
|
+
*/
|
|
16
|
+
target?: HTMLElement;
|
|
17
|
+
/**
|
|
18
|
+
* Anchor point on the target element.
|
|
19
|
+
*
|
|
20
|
+
* @default "bottom left"
|
|
21
|
+
*/
|
|
22
|
+
anchor?: QMenuAnchor;
|
|
23
|
+
/**
|
|
24
|
+
* Anchor point on the menu element.
|
|
25
|
+
*
|
|
26
|
+
* @default "top left"
|
|
27
|
+
*/
|
|
28
|
+
self?: QMenuAnchor;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the menu width to the target width.
|
|
31
|
+
*
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
fit?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Prevents outside click dismissal.
|
|
37
|
+
*
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
persistent?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Closes the menu when its content is clicked.
|
|
43
|
+
*
|
|
44
|
+
* @default true
|
|
45
|
+
*/
|
|
46
|
+
autoClose?: boolean;
|
|
47
|
+
children?: Snippet;
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { useSize } from "../../composables";
|
|
2
|
+
import { useColor, useSize } from "../../composables";
|
|
3
3
|
import { between } from "../../utils";
|
|
4
4
|
import type { QCircularProgressProps } from "./props";
|
|
5
5
|
|
|
@@ -10,11 +10,7 @@
|
|
|
10
10
|
rounded?: boolean;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
diameter = 2 * radius,
|
|
15
|
-
circumference = diameter * Math.PI,
|
|
16
|
-
strokeDashArray = Math.round(circumference * 1000) / 1000;
|
|
17
|
-
|
|
13
|
+
// #region: --- Props
|
|
18
14
|
let {
|
|
19
15
|
value = $bindable(0),
|
|
20
16
|
indeterminate = false,
|
|
@@ -33,17 +29,23 @@
|
|
|
33
29
|
children = fallback,
|
|
34
30
|
...props
|
|
35
31
|
}: QCircularProgressProps = $props();
|
|
32
|
+
// #endregion: --- Props
|
|
33
|
+
|
|
34
|
+
// #region: --- Non-reactive variables
|
|
35
|
+
const radius = 50;
|
|
36
|
+
|
|
37
|
+
const diameter = 2 * radius;
|
|
38
|
+
|
|
39
|
+
const circumference = diameter * Math.PI;
|
|
36
40
|
|
|
41
|
+
const strokeDashArray = Math.round(circumference * 1000) / 1000;
|
|
42
|
+
// #endregion: --- Non-reactive variables
|
|
43
|
+
|
|
44
|
+
// #region: --- Derived values
|
|
37
45
|
const qSize = $derived(useSize(size, "q-circular-progress"));
|
|
38
46
|
|
|
39
|
-
const parsedColor = $derived(
|
|
40
|
-
|
|
41
|
-
);
|
|
42
|
-
const parsedTrackColor = $derived(
|
|
43
|
-
trackColor.includes("#")
|
|
44
|
-
? trackColor
|
|
45
|
-
: `var(--${trackColor}, ${trackColor})`,
|
|
46
|
-
);
|
|
47
|
+
const parsedColor = $derived(useColor(color));
|
|
48
|
+
const parsedTrackColor = $derived(useColor(trackColor));
|
|
47
49
|
|
|
48
50
|
const svgStyle = $derived(`rotate3d(0, 0, 1, ${angle - 90}deg)`);
|
|
49
51
|
const circleStyle = $derived(
|
|
@@ -70,6 +72,7 @@
|
|
|
70
72
|
|
|
71
73
|
return circumference * dashRatio + dashGap;
|
|
72
74
|
});
|
|
75
|
+
// #endregion: --- Derived values
|
|
73
76
|
</script>
|
|
74
77
|
|
|
75
78
|
<div
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[evt: string]: CustomEvent<any>;
|
|
6
|
-
};
|
|
7
|
-
slots: {};
|
|
8
|
-
};
|
|
9
|
-
type QCircularProgressProps_ = typeof __propDef.props;
|
|
10
|
-
export { QCircularProgressProps_ as QCircularProgressProps };
|
|
11
|
-
export type QCircularProgressEvents = typeof __propDef.events;
|
|
12
|
-
export type QCircularProgressSlots = typeof __propDef.slots;
|
|
13
|
-
export default class QCircularProgress extends SvelteComponentTyped<QCircularProgressProps_, QCircularProgressEvents, QCircularProgressSlots> {
|
|
14
|
-
}
|
|
1
|
+
import type { QCircularProgressProps } from "./props";
|
|
2
|
+
declare const QCircularProgress: import("svelte").Component<QCircularProgressProps, {}, "value">;
|
|
3
|
+
type QCircularProgress = ReturnType<typeof QCircularProgress>;
|
|
4
|
+
export default QCircularProgress;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { useSize } from "../../composables";
|
|
2
|
+
import { useColor, useSize } from "../../composables";
|
|
3
3
|
import type { QLinearProgressProps } from "./props";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
return reverse
|
|
7
|
-
? `translateX(100%) scale3d(-${val}, 1, 1)`
|
|
8
|
-
: `scale3d(${val}, 1, 1)`;
|
|
9
|
-
}
|
|
10
|
-
|
|
5
|
+
// #region: --- Props
|
|
11
6
|
let {
|
|
12
7
|
value = $bindable(0),
|
|
13
8
|
buffer,
|
|
@@ -21,20 +16,16 @@
|
|
|
21
16
|
indeterminate = false,
|
|
22
17
|
...props
|
|
23
18
|
}: QLinearProgressProps = $props();
|
|
19
|
+
// #endregion: --- Props
|
|
24
20
|
|
|
21
|
+
// #region: --- Derived values
|
|
25
22
|
const normalized = $derived(value > 1 ? value / 100 : value);
|
|
26
23
|
const normalizedBuffer = $derived(
|
|
27
24
|
buffer && buffer > 1 ? buffer / 100 : buffer,
|
|
28
25
|
);
|
|
29
26
|
|
|
30
|
-
const parsedColor = $derived(
|
|
31
|
-
|
|
32
|
-
);
|
|
33
|
-
const parsedTrackColor = $derived(
|
|
34
|
-
trackColor.includes("#")
|
|
35
|
-
? trackColor
|
|
36
|
-
: `var(--${trackColor}, ${trackColor})`,
|
|
37
|
-
);
|
|
27
|
+
const parsedColor = $derived(useColor(color));
|
|
28
|
+
const parsedTrackColor = $derived(useColor(trackColor));
|
|
38
29
|
|
|
39
30
|
const qSize = $derived(useSize(size, "q-linear-progress"));
|
|
40
31
|
|
|
@@ -49,6 +40,15 @@
|
|
|
49
40
|
const indicatorTransform = $derived(
|
|
50
41
|
width(+indeterminate || normalized, reverse),
|
|
51
42
|
);
|
|
43
|
+
// #endregion: --- Derived values
|
|
44
|
+
|
|
45
|
+
// #region: --- Functions
|
|
46
|
+
function width(val: number, reverse: boolean) {
|
|
47
|
+
return reverse
|
|
48
|
+
? `translateX(100%) scale3d(-${val}, 1, 1)`
|
|
49
|
+
: `scale3d(${val}, 1, 1)`;
|
|
50
|
+
}
|
|
51
|
+
// #endregion: --- Functions
|
|
52
52
|
</script>
|
|
53
53
|
|
|
54
54
|
<div
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[evt: string]: CustomEvent<any>;
|
|
6
|
-
};
|
|
7
|
-
slots: {};
|
|
8
|
-
};
|
|
9
|
-
type QLinearProgressProps_ = typeof __propDef.props;
|
|
10
|
-
export { QLinearProgressProps_ as QLinearProgressProps };
|
|
11
|
-
export type QLinearProgressEvents = typeof __propDef.events;
|
|
12
|
-
export type QLinearProgressSlots = typeof __propDef.slots;
|
|
13
|
-
export default class QLinearProgress extends SvelteComponentTyped<QLinearProgressProps_, QLinearProgressEvents, QLinearProgressSlots> {
|
|
14
|
-
}
|
|
1
|
+
import type { QLinearProgressProps } from "./props";
|
|
2
|
+
declare const QLinearProgress: import("svelte").Component<QLinearProgressProps, {}, "value">;
|
|
3
|
+
type QLinearProgress = ReturnType<typeof QLinearProgress>;
|
|
4
|
+
export default QLinearProgress;
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { QRadioProps } from "./props";
|
|
3
3
|
|
|
4
|
+
// #region: --- Props
|
|
4
5
|
let {
|
|
5
6
|
value = "",
|
|
6
7
|
label = "",
|
|
7
8
|
selected = $bindable(),
|
|
8
|
-
|
|
9
|
+
disabled = false,
|
|
9
10
|
...props
|
|
10
11
|
}: QRadioProps = $props();
|
|
12
|
+
// #endregion: --- Props
|
|
11
13
|
</script>
|
|
12
14
|
|
|
13
15
|
<label
|
|
14
16
|
{...props}
|
|
15
|
-
class={["q-radio", props.class,
|
|
16
|
-
aria-disabled={
|
|
17
|
+
class={["q-radio", props.class, disabled && "q-radio--disabled"]}
|
|
18
|
+
aria-disabled={disabled || undefined}
|
|
17
19
|
data-quaff
|
|
18
20
|
>
|
|
19
|
-
<input type="radio" bind:group={selected} {value} disabled
|
|
21
|
+
<input type="radio" bind:group={selected} {value} {disabled} />
|
|
20
22
|
<span>{label}</span>
|
|
21
23
|
</label>
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[evt: string]: CustomEvent<any>;
|
|
6
|
-
};
|
|
7
|
-
slots: {};
|
|
8
|
-
};
|
|
9
|
-
type QRadioProps_ = typeof __propDef.props;
|
|
10
|
-
export { QRadioProps_ as QRadioProps };
|
|
11
|
-
export type QRadioEvents = typeof __propDef.events;
|
|
12
|
-
export type QRadioSlots = typeof __propDef.slots;
|
|
13
|
-
export default class QRadio extends SvelteComponentTyped<QRadioProps_, QRadioEvents, QRadioSlots> {
|
|
14
|
-
}
|
|
1
|
+
import type { QRadioProps } from "./props";
|
|
2
|
+
declare const QRadio: import("svelte").Component<QRadioProps, {}, "selected">;
|
|
3
|
+
type QRadio = ReturnType<typeof QRadio>;
|
|
4
|
+
export default QRadio;
|