@slidev-polls/shared 0.0.3 → 0.1.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/package.json +1 -1
- package/src/types.ts +14 -1
- package/src/ui/ConfirmDialog.vue +100 -0
- package/src/ui/index.ts +1 -0
package/package.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -84,11 +84,24 @@ export interface CreatePollRequest {
|
|
|
84
84
|
allowedOrigins?: string[];
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/** Option payload for PATCH /api/admin/polls/{id}; id present means in-place update. */
|
|
88
|
+
export interface UpdateOptionBody {
|
|
89
|
+
id?: string;
|
|
90
|
+
label: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Question payload for PATCH /api/admin/polls/{id}; id present means in-place update. */
|
|
94
|
+
export interface UpdateQuestionRequest {
|
|
95
|
+
id?: string;
|
|
96
|
+
prompt: string;
|
|
97
|
+
options: UpdateOptionBody[];
|
|
98
|
+
}
|
|
99
|
+
|
|
87
100
|
/** Patch-style update payload (PATCH /api/admin/polls/{id}). */
|
|
88
101
|
export interface UpdatePollRequest {
|
|
89
102
|
title?: string;
|
|
90
103
|
slug?: string;
|
|
91
|
-
questions?:
|
|
104
|
+
questions?: UpdateQuestionRequest[];
|
|
92
105
|
allowedOrigins?: string[];
|
|
93
106
|
}
|
|
94
107
|
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, watch } from "vue";
|
|
3
|
+
import Button from "./Button.vue";
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
open: boolean;
|
|
8
|
+
title: string;
|
|
9
|
+
body?: string;
|
|
10
|
+
confirmLabel?: string;
|
|
11
|
+
cancelLabel?: string;
|
|
12
|
+
tone?: "neutral" | "danger";
|
|
13
|
+
}>(),
|
|
14
|
+
{ body: "", confirmLabel: "Confirm", cancelLabel: "Cancel", tone: "neutral" }
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const emit = defineEmits<{
|
|
18
|
+
(e: "confirm"): void;
|
|
19
|
+
(e: "cancel"): void;
|
|
20
|
+
}>();
|
|
21
|
+
|
|
22
|
+
const dialogRef = ref<HTMLDialogElement | null>(null);
|
|
23
|
+
|
|
24
|
+
watch(
|
|
25
|
+
() => props.open,
|
|
26
|
+
(isOpen) => {
|
|
27
|
+
const d = dialogRef.value;
|
|
28
|
+
if (!d) return;
|
|
29
|
+
if (isOpen && !d.open) {
|
|
30
|
+
if (typeof d.showModal === "function") d.showModal();
|
|
31
|
+
else d.setAttribute("open", "");
|
|
32
|
+
}
|
|
33
|
+
if (!isOpen && d.open) d.close();
|
|
34
|
+
},
|
|
35
|
+
{ flush: "post", immediate: true }
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
function onCancel() {
|
|
39
|
+
emit("cancel");
|
|
40
|
+
}
|
|
41
|
+
function onConfirm() {
|
|
42
|
+
emit("confirm");
|
|
43
|
+
}
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<template>
|
|
47
|
+
<dialog
|
|
48
|
+
ref="dialogRef"
|
|
49
|
+
class="cd"
|
|
50
|
+
data-testid="confirm-dialog"
|
|
51
|
+
@cancel.prevent="onCancel"
|
|
52
|
+
@close="onCancel"
|
|
53
|
+
>
|
|
54
|
+
<h2 class="cd__title">{{ title }}</h2>
|
|
55
|
+
<p v-if="body" class="cd__body">{{ body }}</p>
|
|
56
|
+
<div class="cd__actions">
|
|
57
|
+
<Button variant="ghost" data-testid="confirm-dialog-cancel" @click="onCancel">
|
|
58
|
+
{{ cancelLabel }}
|
|
59
|
+
</Button>
|
|
60
|
+
<Button
|
|
61
|
+
:variant="tone === 'danger' ? 'danger' : 'primary'"
|
|
62
|
+
data-testid="confirm-dialog-confirm"
|
|
63
|
+
@click="onConfirm"
|
|
64
|
+
>
|
|
65
|
+
{{ confirmLabel }}
|
|
66
|
+
</Button>
|
|
67
|
+
</div>
|
|
68
|
+
</dialog>
|
|
69
|
+
</template>
|
|
70
|
+
|
|
71
|
+
<style scoped>
|
|
72
|
+
.cd {
|
|
73
|
+
border: none;
|
|
74
|
+
border-radius: var(--sp-radius-lg, 8px);
|
|
75
|
+
padding: 20px 22px;
|
|
76
|
+
max-width: 420px;
|
|
77
|
+
background: var(--sp-bg);
|
|
78
|
+
color: var(--sp-fg);
|
|
79
|
+
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
|
|
80
|
+
}
|
|
81
|
+
.cd::backdrop {
|
|
82
|
+
background: rgba(0, 0, 0, 0.4);
|
|
83
|
+
}
|
|
84
|
+
.cd__title {
|
|
85
|
+
font-size: 16px;
|
|
86
|
+
font-weight: 600;
|
|
87
|
+
margin: 0 0 8px;
|
|
88
|
+
}
|
|
89
|
+
.cd__body {
|
|
90
|
+
font-size: 13px;
|
|
91
|
+
color: var(--sp-fg-subtle);
|
|
92
|
+
margin: 0 0 18px;
|
|
93
|
+
line-height: 1.5;
|
|
94
|
+
}
|
|
95
|
+
.cd__actions {
|
|
96
|
+
display: flex;
|
|
97
|
+
justify-content: flex-end;
|
|
98
|
+
gap: 8px;
|
|
99
|
+
}
|
|
100
|
+
</style>
|
package/src/ui/index.ts
CHANGED
|
@@ -15,3 +15,4 @@ export { default as IconChevronDown } from "./IconChevronDown.vue";
|
|
|
15
15
|
export { default as IconClose } from "./IconClose.vue";
|
|
16
16
|
export { useTheme } from "./useTheme";
|
|
17
17
|
export { validateOrigin, type OriginValidation } from "./origin-validator";
|
|
18
|
+
export { default as ConfirmDialog } from "./ConfirmDialog.vue";
|