@fastkit/vui 0.14.1 → 0.16.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/src/service.tsx CHANGED
@@ -5,9 +5,12 @@ import { ScopeName, ColorVariant } from '@fastkit/color-scheme';
5
5
  import type { IconName, RawIconProp } from './components/VIcon';
6
6
  import {
7
7
  type VueStackService,
8
- type VDialogProps,
9
8
  type VStackControl,
10
- resolveVStackDynamicInput,
9
+ type VStackBuiltinActionType,
10
+ type VStackAction,
11
+ type StackableLauncher,
12
+ VStackBuiltinActions,
13
+ BUILTIN_ACTION_HANDLERS,
11
14
  } from '@fastkit/vue-stack';
12
15
  import { type VNodeChildOrSlot } from '@fastkit/vue-utils';
13
16
  import { type VueColorSchemePluginSettings } from '@fastkit/vue-color-scheme';
@@ -20,9 +23,16 @@ import { VTextField, TextFieldInput } from './components/VTextField';
20
23
  import { VueForm, FormControlHinttipDelay } from '@fastkit/vue-form-control';
21
24
  import { getDocumentScroller, UseScroller } from '@fastkit/vue-scroller';
22
25
  import { ControlSize } from './schemes';
26
+ import { VButton } from './components/VButton';
27
+ import { VDialog } from './components/VDialog';
28
+ import { VSnackbar } from './components/VSnackbar';
29
+ import { VMenu } from './components/VMenu';
30
+ import { VSheetModal } from './components/VSheetModal';
23
31
 
24
32
  export type UseLinkResult = ReturnType<typeof useLink>;
25
33
 
34
+ type VDialogProps = InstanceType<typeof VDialog>['$props'];
35
+
26
36
  export interface VuiFormPromptSettings<
27
37
  T extends { [key: string]: any } = { [key: string]: any },
28
38
  > extends Partial<VDialogProps> {
@@ -192,6 +202,13 @@ export class VuiService {
192
202
  readonly location: LocationService;
193
203
  readonly stack: VueStackService;
194
204
  readonly useLink: typeof useLink;
205
+ readonly stackActions: VStackBuiltinActions;
206
+ readonly dialog: StackableLauncher<typeof VDialog>;
207
+ readonly alert: StackableLauncher<typeof VDialog>;
208
+ readonly confirm: StackableLauncher<typeof VDialog, boolean>;
209
+ readonly snackbar: StackableLauncher<typeof VSnackbar>;
210
+ readonly menu: StackableLauncher<typeof VMenu>;
211
+ readonly sheet: StackableLauncher<typeof VSheetModal>;
195
212
 
196
213
  get scroller(): UseScroller {
197
214
  return getDocumentScroller();
@@ -215,8 +232,53 @@ export class VuiService {
215
232
  this.location = new LocationService({
216
233
  router: this.router,
217
234
  });
218
- this.stack = stackService;
219
235
  this.useLink = options.useLink || useLink;
236
+
237
+ this.stack = stackService;
238
+ const { uiSettings } = options;
239
+ this.stackActions = {
240
+ ok: ({ bindings }) => (
241
+ <VButton {...uiSettings.dialogOk} {...bindings}>
242
+ OK
243
+ </VButton>
244
+ ),
245
+ cancel: ({ bindings }) => (
246
+ <VButton {...uiSettings.dialogCancel} {...bindings}>
247
+ CANCEL
248
+ </VButton>
249
+ ),
250
+ close: ({ bindings }) => (
251
+ <VButton {...uiSettings.dialogClose} {...bindings}>
252
+ CLOSE
253
+ </VButton>
254
+ ),
255
+ };
256
+
257
+ this.dialog = stackService.createLauncher(VDialog);
258
+ this.alert = stackService.createLauncher(VDialog, (props) => {
259
+ const actions = [...(props?.actions || [])];
260
+ if (!actions.length) {
261
+ actions.push(this.stackAction('ok'));
262
+ }
263
+ return {
264
+ ...props,
265
+ actions,
266
+ };
267
+ });
268
+
269
+ this.confirm = stackService.createLauncher(VDialog, (props) => {
270
+ const actions = [...(props?.actions || [])];
271
+ if (!actions.length) {
272
+ actions.push(this.stackAction('cancel'), this.stackAction('ok'));
273
+ }
274
+ return {
275
+ ...props,
276
+ actions,
277
+ };
278
+ });
279
+ this.snackbar = stackService.createLauncher(VSnackbar);
280
+ this.menu = stackService.createLauncher(VMenu);
281
+ this.sheet = stackService.createLauncher(VSheetModal);
220
282
  }
221
283
 
222
284
  configure(options?: Partial<VuiServiceOptions>) {
@@ -253,26 +315,6 @@ export class VuiService {
253
315
  return requiredChip && requiredChip();
254
316
  }
255
317
 
256
- dialog(...args: Parameters<VueStackService['dialog']>) {
257
- return this.stack.dialog(...args);
258
- }
259
-
260
- alert(...args: Parameters<VueStackService['alert']>) {
261
- return this.stack.alert(...args);
262
- }
263
-
264
- confirm(...args: Parameters<VueStackService['confirm']>) {
265
- return this.stack.confirm(...args);
266
- }
267
-
268
- snackbar(...args: Parameters<VueStackService['snackbar']>) {
269
- return this.stack.snackbar(...args);
270
- }
271
-
272
- menu(...args: Parameters<VueStackService['menu']>) {
273
- return this.stack.menu(...args);
274
- }
275
-
276
318
  formPrompt<T extends { [key: string]: any } = { [key: string]: any }>(
277
319
  settings: VuiFormPromptSettings<T>,
278
320
  slot: (
@@ -292,8 +334,8 @@ export class VuiService {
292
334
  const _state = reactive(state);
293
335
 
294
336
  options.actions = options.actions || [
295
- this.stack.action('cancel', undefined, { size }),
296
- this.stack.action('ok', undefined, {
337
+ this.stackAction('cancel', undefined, { size }),
338
+ this.stackAction('ok', undefined, {
297
339
  size,
298
340
  onClick: () => {
299
341
  if (form) {
@@ -304,34 +346,29 @@ export class VuiService {
304
346
  }),
305
347
  ];
306
348
 
307
- const resolved = resolveVStackDynamicInput({
308
- ...options,
309
- content: (stack) => {
310
- return (
311
- <VForm
312
- disableAutoScroll
313
- size={size}
314
- // onVnodeMounted={(vnode) => {
315
- // form = (vnode.component as any).ctx.form as VueForm;
316
- // }}
317
- onVnodeBeforeUnmount={() => {
318
- form = undefined;
319
- }}
320
- onSubmit={(ev) => {
321
- stack.resolve(_state);
322
- }}
323
- v-slots={{
324
- default: (_form) => {
325
- form = _form;
326
- return slot(_state, { form, stack });
327
- },
328
- }}
329
- />
330
- );
331
- },
349
+ return this.dialog(options, (stack) => {
350
+ return (
351
+ <VForm
352
+ disableAutoScroll
353
+ size={size}
354
+ // onVnodeMounted={(vnode) => {
355
+ // form = (vnode.component as any).ctx.form as VueForm;
356
+ // }}
357
+ onVnodeBeforeUnmount={() => {
358
+ form = undefined;
359
+ }}
360
+ onSubmit={(ev) => {
361
+ stack.resolve(_state);
362
+ }}
363
+ v-slots={{
364
+ default: (_form) => {
365
+ form = _form;
366
+ return slot(_state, { form, stack });
367
+ },
368
+ }}
369
+ />
370
+ );
332
371
  });
333
-
334
- return this.dialog(resolved);
335
372
  }
336
373
 
337
374
  prompt(rawOptions: RawVuiPromptOptions = {}) {
@@ -370,4 +407,27 @@ export class VuiService {
370
407
  return result ? result.input : result;
371
408
  });
372
409
  }
410
+
411
+ stackAction(
412
+ key: VStackBuiltinActionType,
413
+ override?: Partial<VStackAction>,
414
+ attrs?: Record<string, unknown>,
415
+ ) {
416
+ const factory = this.stackActions[key];
417
+ const _onClick = BUILTIN_ACTION_HANDLERS[key];
418
+ const action: VStackAction = {
419
+ key,
420
+ content: ({ control, key }) => {
421
+ const onClick = (ev: MouseEvent) => _onClick(control, ev);
422
+ return factory({
423
+ service: this.stack,
424
+ control,
425
+ key,
426
+ bindings: { onClick, ...attrs },
427
+ });
428
+ },
429
+ ...override,
430
+ };
431
+ return action;
432
+ }
373
433
  }
@@ -328,6 +328,35 @@
328
328
  // tiles
329
329
  // =============================================
330
330
  --list-tile-padding: calc(var(--root-em) * 0.625);
331
+
332
+ // =============================================
333
+ // snackbar
334
+ // =============================================
335
+ --snackbar-shadow: 0 3px 5px -1px rgba(0, 0, 0, 0.2),
336
+ 0 6px 10px 0 rgba(0, 0, 0, 0.14), 0 1px 18px 0 rgba(0, 0, 0, 0.12);
337
+
338
+ // =============================================
339
+ // dialogs
340
+ // =============================================
341
+ --dialog-shadow: 0 11px 15px -7px rgba(0, 0, 0, 0.2),
342
+ 0 24px 38px 3px rgba(0, 0, 0, 0.14), 0 9px 46px 8px rgba(0, 0, 0, 0.12);
343
+
344
+ // =============================================
345
+ // menus
346
+ // =============================================
347
+ --menu-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
348
+ 0 8px 10px 1px rgba(0, 0, 0, 0.14), 0 3px 14px 2px rgba(0, 0, 0, 0.12);
349
+
350
+ // =============================================
351
+ // tooltips
352
+ // =============================================
353
+ --tooltip-background: rgba(35, 47, 52, 0.9);
354
+ --tooltip-color: #fff;
355
+ --tooltip-radius: 4px;
356
+ --tooltip-padding: 5px 16px;
357
+ --tooltip-font-size: calc(var(--root-em) * 0.875);
358
+ --tooltip-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2),
359
+ 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
331
360
  }
332
361
 
333
362
  :root,
@@ -1 +0,0 @@
1
- export { VDialog, VMenu, VSnackbar, VTooltip } from '@fastkit/vue-stack';