@geoffcox/sterling-svelte 0.0.7 → 0.0.9

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.
@@ -0,0 +1,241 @@
1
+ <script>import { createEventDispatcher, onMount, tick } from "svelte";
2
+ import Button from "../buttons/Button.svelte";
3
+ import CloseX from "./CloseX.svelte";
4
+ const dialogFadeDuration = 250;
5
+ export let open = false;
6
+ export let returnValue = "";
7
+ export let backdropCloses = false;
8
+ let dialogRef;
9
+ let contentRef;
10
+ let formRef;
11
+ let closing = false;
12
+ const dispatch = createEventDispatcher();
13
+ const onDocumentClick = (event) => {
14
+ const targetNode = event?.target;
15
+ if (targetNode && !contentRef.contains(targetNode) && backdropCloses) {
16
+ open = false;
17
+ }
18
+ };
19
+ const showDialog = () => {
20
+ if (dialogRef?.open === false) {
21
+ document.addEventListener("click", onDocumentClick, true);
22
+ dialogRef.showModal();
23
+ }
24
+ open = true;
25
+ };
26
+ const closeDialog = (returnValue2 = "") => {
27
+ if (dialogRef?.open === true) {
28
+ document.removeEventListener("click", onDocumentClick);
29
+ closing = true;
30
+ tick();
31
+ setTimeout(() => {
32
+ dialogRef.close(returnValue2);
33
+ open = false;
34
+ closing = false;
35
+ }, dialogFadeDuration);
36
+ } else {
37
+ open = false;
38
+ }
39
+ };
40
+ const updateDialog = (open2) => {
41
+ if (open2) {
42
+ showDialog();
43
+ } else {
44
+ closeDialog();
45
+ }
46
+ };
47
+ const onCancel = (event) => {
48
+ event.preventDefault();
49
+ event.stopPropagation();
50
+ closeDialog();
51
+ return false;
52
+ };
53
+ const onSubmit = (event) => {
54
+ console.log(event);
55
+ const anyEvent = event;
56
+ if (anyEvent?.submitter.type === "submit") {
57
+ if (dialogRef.open) {
58
+ closeDialog(anyEvent?.submitter.value ?? "");
59
+ setTimeout(() => {
60
+ formRef.requestSubmit(anyEvent?.submitter);
61
+ }, dialogFadeDuration);
62
+ event.preventDefault();
63
+ return false;
64
+ }
65
+ } else {
66
+ console.log("cancelling");
67
+ event.preventDefault();
68
+ return false;
69
+ }
70
+ };
71
+ const onClose = (event) => {
72
+ returnValue = dialogRef.returnValue;
73
+ };
74
+ $: {
75
+ updateDialog(open);
76
+ }
77
+ onMount(() => {
78
+ updateDialog(open);
79
+ dialogRef.addEventListener("cancel", onCancel);
80
+ dialogRef.addEventListener("close", onClose);
81
+ return () => {
82
+ dialogRef?.removeEventListener("cancel", onCancel);
83
+ dialogRef?.removeEventListener("close", onClose);
84
+ };
85
+ });
86
+ </script>
87
+
88
+ <!-- @component
89
+ A styled &lt;dialog&gt; element
90
+
91
+ - Slots for typical dialog content.
92
+ - Props and events to make using &lt;dialog&gt; easier
93
+ -->
94
+ <dialog
95
+ class="dialog"
96
+ class:open
97
+ class:closing
98
+ bind:this={dialogRef}
99
+ on:close
100
+ on:cancel
101
+ {...$$restProps}
102
+ >
103
+ <form method="dialog" bind:this={formRef} on:submit={onSubmit}>
104
+ <div class="content" bind:this={contentRef}>
105
+ <slot name="content">
106
+ <div class="header">
107
+ <slot name="header">
108
+ <div class="title">
109
+ <slot name="title" />
110
+ </div>
111
+ <div class="close">
112
+ <Button variant="ghost" shape="circular" on:click={() => closeDialog()}>
113
+ <div class="close-x">
114
+ <CloseX />
115
+ </div>
116
+ </Button>
117
+ </div>
118
+ </slot>
119
+ </div>
120
+ <div class="body">
121
+ <slot name="body" />
122
+ </div>
123
+ <div class="separator" />
124
+ <div class="footer">
125
+ <slot name="footer" />
126
+ </div>
127
+ </slot>
128
+ </div>
129
+ </form>
130
+ </dialog>
131
+
132
+ <style>
133
+ .dialog {
134
+ padding: 0;
135
+ border: none;
136
+ background: none;
137
+ }
138
+
139
+ .dialog::backdrop {
140
+ backdrop-filter: blur(2px);
141
+ background: rgba(0, 0, 0, 0.3);
142
+ transition: opacity 250ms;
143
+ opacity: 0;
144
+ }
145
+
146
+ .dialog.open::backdrop {
147
+ opacity: 1;
148
+ }
149
+
150
+ .dialog.closing::backdrop {
151
+ opacity: 0;
152
+ }
153
+
154
+ .header {
155
+ background-color: var(--Display__background-color);
156
+ }
157
+
158
+ .content {
159
+ background-color: var(--Common__background-color);
160
+ border-color: var(--Common__border-color);
161
+ border-radius: var(--Common__border-radius);
162
+ border-style: var(--Common__border-style);
163
+ border-width: var(--Common__border-width);
164
+ box-sizing: border-box;
165
+ color: var(--Common__color);
166
+ display: grid;
167
+ grid-template-columns: 1fr;
168
+ grid-template-rows: auto 1fr auto auto;
169
+ justify-content: stretch;
170
+ justify-items: stretch;
171
+ align-items: stretch;
172
+ transition: opacity 250ms;
173
+ opacity: 0;
174
+ }
175
+
176
+ .dialog.open .content {
177
+ opacity: 1;
178
+ }
179
+
180
+ .dialog.closing .content {
181
+ opacity: 0;
182
+ }
183
+
184
+ .header {
185
+ display: grid;
186
+ grid-template-columns: 1fr auto;
187
+ grid-template-rows: 1fr;
188
+ justify-items: stretch;
189
+ align-items: center;
190
+ padding: 0.25em 0.5em;
191
+ }
192
+
193
+ .title {
194
+ font-size: 1.4em;
195
+ }
196
+
197
+ .close {
198
+ justify-self: flex-end;
199
+ }
200
+
201
+ .close :global(button) {
202
+ width: 1.75em;
203
+ height: 1.75em;
204
+ padding: 0;
205
+ }
206
+
207
+ .close-x {
208
+ width: 1.5em;
209
+ height: 1.5em;
210
+ display: grid;
211
+ grid-template-columns: 1fr;
212
+ grid-template-rows: 1fr;
213
+ place-content: center;
214
+ align-content: center;
215
+ }
216
+
217
+ .body {
218
+ padding: 1em;
219
+ }
220
+
221
+ .separator {
222
+ background-color: var(--Display__background-color);
223
+ height: var(--Common__border-width);
224
+ margin: 0 0.25em;
225
+ }
226
+
227
+ .footer {
228
+ display: flex;
229
+ justify-content: flex-end;
230
+ justify-items: flex-end;
231
+ padding: 0.5em 1em;
232
+ gap: 5px;
233
+ }
234
+
235
+ @media (prefers-reduced-motion) {
236
+ .dialog::backdrop,
237
+ .content {
238
+ transition: none;
239
+ }
240
+ }
241
+ </style>
@@ -0,0 +1,34 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ [x: string]: any;
5
+ open?: boolean | undefined;
6
+ returnValue?: string | undefined;
7
+ backdropCloses?: boolean | undefined;
8
+ };
9
+ events: {
10
+ close: Event;
11
+ cancel: Event;
12
+ } & {
13
+ [evt: string]: CustomEvent<any>;
14
+ };
15
+ slots: {
16
+ content: {};
17
+ header: {};
18
+ title: {};
19
+ body: {};
20
+ footer: {};
21
+ };
22
+ };
23
+ export type DialogProps = typeof __propDef.props;
24
+ export type DialogEvents = typeof __propDef.events;
25
+ export type DialogSlots = typeof __propDef.slots;
26
+ /**
27
+ * A styled &lt;dialog&gt; element
28
+ *
29
+ * - Slots for typical dialog content.
30
+ * - Props and events to make using &lt;dialog&gt; easier
31
+ */
32
+ export default class Dialog extends SvelteComponentTyped<DialogProps, DialogEvents, DialogSlots> {
33
+ }
34
+ export {};
package/theme/colors.js CHANGED
@@ -1,6 +1,8 @@
1
1
  export const neutrals = {
2
2
  neutral0: 'hsl(0, 0%, 0%)',
3
+ neutral10: 'hsl(0, 0%, 12%)',
3
4
  neutral15: 'hsl(0, 0%, 15%)',
5
+ neutral20: 'hsl(0, 0%, 20%)',
4
6
  neutral30: 'hsl(0, 0%, 30%)',
5
7
  neutral45: 'hsl(0, 0%, 45%)',
6
8
  neutral60: 'hsl(0, 0%, 60%)',
@@ -25,11 +25,11 @@ export const darkTheme = {
25
25
  '--Common__border-color--disabled': neutrals.neutral92,
26
26
  '--Common__color--disabled': neutrals.neutral92,
27
27
  // ----- Layer ---- //
28
- '--Layer__background-color--1': neutrals.neutral30,
28
+ '--Layer__background-color--1': neutrals.neutral20,
29
29
  '--Layer__color--1': neutrals.neutral100,
30
- '--Layer__background-color--2': neutrals.neutral45,
30
+ '--Layer__background-color--2': neutrals.neutral10,
31
31
  '--Layer__color--2': neutrals.neutral100,
32
- '--Layer__background-color--3': neutrals.neutral60,
32
+ '--Layer__background-color--3': neutrals.neutral45,
33
33
  '--Layer__color--3': neutrals.neutral100,
34
34
  // ----- Button ----- //
35
35
  '--Button__background-color': neutrals.neutral45,
@@ -22,8 +22,8 @@ export const lightTheme = {
22
22
  '--Common__outline-width': '2px',
23
23
  // disabled
24
24
  '--Common__background-color--disabled': neutrals.neutral96,
25
- '--Common__border-color--disabled': neutrals.neutral60,
26
- '--Common__color--disabled': neutrals.neutral60,
25
+ '--Common__border-color--disabled': neutrals.neutral75,
26
+ '--Common__color--disabled': neutrals.neutral75,
27
27
  // ----- Layer ---- //
28
28
  '--Layer__background-color--1': neutrals.neutral98,
29
29
  '--Layer__color--1': neutrals.neutral15,