@knime/kds-components 0.1.0 → 0.2.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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { shallowRef, watch, defineComponent, toRef, createBlock, createElementBlock, unref, openBlock, resolveDynamicComponent, normalizeClass, computed, withCtx, createCommentVNode, toDisplayString, mergeProps, h, useSlots, getCurrentInstance, useId, createElementVNode, ref } from 'vue';
1
+ import { shallowRef, watch, defineComponent, toRef, createBlock, createElementBlock, unref, openBlock, resolveDynamicComponent, normalizeClass, computed, withCtx, createCommentVNode, toDisplayString, mergeProps, h, useSlots, getCurrentInstance, useId, createElementVNode, useCssVars, useTemplateRef, nextTick, withModifiers, Fragment, createVNode, renderSlot, ref, createSlots, renderList } from 'vue';
2
2
  import { useLocalStorage, useDark, usePreferredDark } from '@vueuse/core';
3
3
 
4
4
  import './index.css';const __variableDynamicImportRuntimeHelper = (glob$1, path$13, segs) => {
@@ -35,7 +35,7 @@ const useIcon = ({
35
35
  return iconComponent;
36
36
  };
37
37
 
38
- const _sfc_main$5 = /* @__PURE__ */ defineComponent({
38
+ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
39
39
  __name: "KdsIcon",
40
40
  props: {
41
41
  name: {},
@@ -68,13 +68,13 @@ const _export_sfc = (sfc, props) => {
68
68
  return target;
69
69
  };
70
70
 
71
- const Icon = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-d965b88c"]]);
71
+ const KdsIcon = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["__scopeId", "data-v-d965b88c"]]);
72
72
 
73
- const _hoisted_1$2 = {
73
+ const _hoisted_1$4 = {
74
74
  key: 1,
75
75
  class: "label"
76
76
  };
77
- const _sfc_main$4 = /* @__PURE__ */ defineComponent({
77
+ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
78
78
  __name: "BaseButton",
79
79
  props: {
80
80
  variant: { default: "filled" },
@@ -116,13 +116,13 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
116
116
  onClick: _cache[0] || (_cache[0] = ($event) => onClick($event))
117
117
  }, {
118
118
  default: withCtx(() => [
119
- props.leadingIcon ? (openBlock(), createBlock(Icon, {
119
+ props.leadingIcon ? (openBlock(), createBlock(KdsIcon, {
120
120
  key: 0,
121
121
  name: props.leadingIcon,
122
122
  size: iconSize.value
123
123
  }, null, 8, ["name", "size"])) : createCommentVNode("", true),
124
- props.label ? (openBlock(), createElementBlock("span", _hoisted_1$2, toDisplayString(props.label), 1)) : createCommentVNode("", true),
125
- props.trailingIcon && props.label ? (openBlock(), createBlock(Icon, {
124
+ props.label ? (openBlock(), createElementBlock("span", _hoisted_1$4, toDisplayString(props.label), 1)) : createCommentVNode("", true),
125
+ props.trailingIcon && props.label ? (openBlock(), createBlock(KdsIcon, {
126
126
  key: 2,
127
127
  name: props.trailingIcon,
128
128
  size: iconSize.value
@@ -134,9 +134,9 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
134
134
  }
135
135
  });
136
136
 
137
- const BaseButton = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-6eda26d0"]]);
137
+ const BaseButton = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["__scopeId", "data-v-f82890d7"]]);
138
138
 
139
- const _sfc_main$3 = /* @__PURE__ */ defineComponent({
139
+ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
140
140
  __name: "KdsButton",
141
141
  props: {
142
142
  variant: {},
@@ -187,7 +187,7 @@ const resolveNuxtLinkComponent = () => {
187
187
  return fallbackComponent;
188
188
  };
189
189
 
190
- const _sfc_main$2 = /* @__PURE__ */ defineComponent({
190
+ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
191
191
  __name: "KdsLinkButton",
192
192
  props: {
193
193
  variant: {},
@@ -221,15 +221,15 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
221
221
  }
222
222
  });
223
223
 
224
- const _hoisted_1$1 = ["disabled", "aria-checked", "aria-describedby", "aria-invalid", "title"];
225
- const _hoisted_2 = { class: "control" };
226
- const _hoisted_3 = {
224
+ const _hoisted_1$3 = ["disabled", "aria-checked", "aria-describedby", "aria-invalid", "title"];
225
+ const _hoisted_2$2 = { class: "control" };
226
+ const _hoisted_3$2 = {
227
227
  key: 0,
228
228
  class: "content"
229
229
  };
230
- const _hoisted_4 = { class: "label" };
230
+ const _hoisted_4$1 = { class: "label" };
231
231
  const _hoisted_5 = ["id"];
232
- const _sfc_main$1 = /* @__PURE__ */ defineComponent({
232
+ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
233
233
  __name: "KdsCheckbox",
234
234
  props: {
235
235
  modelValue: { type: [Boolean, String], default: false },
@@ -286,28 +286,28 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
286
286
  role: "checkbox",
287
287
  onClick: handleClick
288
288
  }, [
289
- createElementVNode("div", _hoisted_2, [
290
- icon.value ? (openBlock(), createBlock(Icon, {
289
+ createElementVNode("div", _hoisted_2$2, [
290
+ icon.value ? (openBlock(), createBlock(KdsIcon, {
291
291
  key: 0,
292
292
  name: icon.value,
293
293
  class: "icon",
294
294
  size: "xsmall"
295
295
  }, null, 8, ["name"])) : createCommentVNode("", true)
296
296
  ]),
297
- props.label || props.helperText ? (openBlock(), createElementBlock("div", _hoisted_3, [
298
- createElementVNode("div", _hoisted_4, toDisplayString(props.label), 1),
297
+ props.label || props.helperText ? (openBlock(), createElementBlock("div", _hoisted_3$2, [
298
+ createElementVNode("div", _hoisted_4$1, toDisplayString(props.label), 1),
299
299
  props.helperText ? (openBlock(), createElementBlock("div", {
300
300
  key: 0,
301
301
  id: `${unref(id)}-helper`,
302
302
  class: "helper-text"
303
303
  }, toDisplayString(props.helperText), 9, _hoisted_5)) : createCommentVNode("", true)
304
304
  ])) : createCommentVNode("", true)
305
- ], 10, _hoisted_1$1);
305
+ ], 10, _hoisted_1$3);
306
306
  };
307
307
  }
308
308
  });
309
309
 
310
- const KdsCheckbox = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-9fc2815a"]]);
310
+ const KdsCheckbox = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-9fc2815a"]]);
311
311
 
312
312
  const ID_TO_ICON_MAP = {
313
313
  // Flow Variables
@@ -453,8 +453,8 @@ const typeIconNames = [
453
453
  "xml-datatype"
454
454
  ];
455
455
 
456
- const _hoisted_1 = ["title"];
457
- const _sfc_main = /* @__PURE__ */ defineComponent({
456
+ const _hoisted_1$2 = ["title"];
457
+ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
458
458
  __name: "KdsDataType",
459
459
  props: {
460
460
  iconName: { default: "unknown-datatype" },
@@ -494,12 +494,270 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
494
494
  "aria-hidden": "true",
495
495
  focusable: "false"
496
496
  }, null, 8, ["class"]))
497
- ], 10, _hoisted_1);
497
+ ], 10, _hoisted_1$2);
498
+ };
499
+ }
500
+ });
501
+
502
+ const KdsDataType = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-f7d93fdf"]]);
503
+
504
+ const _hoisted_1$1 = ["closedby"];
505
+ const _hoisted_2$1 = { class: "modal-header" };
506
+ const _hoisted_3$1 = { class: "modal-header-title" };
507
+ const _hoisted_4 = { class: "modal-footer" };
508
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
509
+ __name: "KdsModal",
510
+ props: {
511
+ icon: { default: void 0 },
512
+ title: { default: "" },
513
+ variant: { default: "default" },
514
+ width: { default: "medium" },
515
+ height: { default: "auto" },
516
+ active: { type: Boolean, default: false },
517
+ closedby: { default: "closerequest" }
518
+ },
519
+ emits: ["close"],
520
+ setup(__props, { emit: __emit }) {
521
+ useCssVars((_ctx) => ({
522
+ "d0cb9b20": cssModalWidth.value,
523
+ "v41dd21bd": cssModalHeight.value
524
+ }));
525
+ const props = __props;
526
+ const emit = __emit;
527
+ const dialog = useTemplateRef("dialogElement");
528
+ const onClose = (e) => {
529
+ emit("close", e);
530
+ };
531
+ watch(
532
+ () => props.active,
533
+ async (active) => {
534
+ if (active) {
535
+ await nextTick();
536
+ dialog.value?.showModal();
537
+ } else {
538
+ dialog.value?.close();
539
+ }
540
+ },
541
+ { immediate: true }
542
+ );
543
+ const widthMapping = {
544
+ small: 25,
545
+ medium: 32,
546
+ large: 45,
547
+ xlarge: 61
548
+ };
549
+ const cssModalWidth = computed(() => {
550
+ if (props.width === "full") {
551
+ return "var(--modal-full-size)";
552
+ }
553
+ return `var(--kds-dimension-component-width-${widthMapping[props.width]}x)`;
554
+ });
555
+ const cssModalHeight = computed(() => {
556
+ if (props.height === "full") {
557
+ return "var(--modal-full-size)";
558
+ }
559
+ return "fit-content";
560
+ });
561
+ return (_ctx, _cache) => {
562
+ return openBlock(), createElementBlock("dialog", {
563
+ ref: "dialogElement",
564
+ class: "base-modal",
565
+ closedby: __props.closedby,
566
+ onClose,
567
+ onCancel: withModifiers(onClose, ["prevent"])
568
+ }, [
569
+ __props.active ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
570
+ createElementVNode("header", _hoisted_2$1, [
571
+ props.icon ? (openBlock(), createBlock(KdsIcon, {
572
+ key: 0,
573
+ name: props.icon,
574
+ size: "medium"
575
+ }, null, 8, ["name"])) : createCommentVNode("", true),
576
+ createElementVNode("div", _hoisted_3$1, toDisplayString(__props.title), 1),
577
+ createVNode(_sfc_main$5, {
578
+ "leading-icon": "x-close",
579
+ variant: "transparent",
580
+ size: "medium",
581
+ title: "Close",
582
+ onClick: onClose
583
+ })
584
+ ]),
585
+ createElementVNode("div", {
586
+ class: normalizeClass(["modal-body", `modal-body-variant-${__props.variant}`])
587
+ }, [
588
+ renderSlot(_ctx.$slots, "default", {}, void 0, true)
589
+ ], 2),
590
+ createElementVNode("footer", _hoisted_4, [
591
+ renderSlot(_ctx.$slots, "footer", {}, void 0, true)
592
+ ])
593
+ ], 64)) : createCommentVNode("", true)
594
+ ], 40, _hoisted_1$1);
595
+ };
596
+ }
597
+ });
598
+
599
+ const KdsModal = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-6203f1f2"]]);
600
+
601
+ const createUnwrappedPromise = () => {
602
+ let resolve = () => {
603
+ };
604
+ let reject = () => {
605
+ };
606
+ const promise = new Promise((res, rej) => {
607
+ resolve = res;
608
+ reject = rej;
609
+ });
610
+ return { resolve, reject, promise };
611
+ };
612
+
613
+ const defaultCancelButton = {
614
+ type: "cancel",
615
+ label: "Cancel"
616
+ };
617
+ const defaultConfirmButton = {
618
+ type: "confirm",
619
+ label: "Confirm"
620
+ };
621
+ const isActive = ref(false);
622
+ const activeModalConfig = ref(null);
623
+ const unwrappedPromise = ref(
624
+ createUnwrappedPromise()
625
+ );
626
+ const isComponentBasedConfig = (config) => {
627
+ return "component" in config;
628
+ };
629
+ const useKdsConfirmDialog = () => {
630
+ function show(config) {
631
+ activeModalConfig.value = {
632
+ buttons: [defaultCancelButton, defaultConfirmButton],
633
+ ...config
634
+ };
635
+ isActive.value = true;
636
+ return unwrappedPromise.value.promise;
637
+ }
638
+ const close = () => {
639
+ isActive.value = false;
640
+ activeModalConfig.value = null;
641
+ unwrappedPromise.value = createUnwrappedPromise();
642
+ };
643
+ const confirm = (doNotAskAgain = false) => {
644
+ unwrappedPromise.value.resolve({
645
+ confirmed: true,
646
+ doNotAskAgain
647
+ });
648
+ close();
649
+ };
650
+ const cancel = () => {
651
+ unwrappedPromise.value.resolve({ confirmed: false });
652
+ close();
653
+ };
654
+ return {
655
+ show,
656
+ confirm,
657
+ cancel,
658
+ config: computed(() => activeModalConfig.value),
659
+ isActive: computed(() => isActive.value),
660
+ dialogResult: computed(() => unwrappedPromise.value.promise),
661
+ isComponentBasedConfig
662
+ };
663
+ };
664
+
665
+ const _hoisted_1 = {
666
+ key: 1,
667
+ class: "confirmation"
668
+ };
669
+ const _hoisted_2 = { class: "message" };
670
+ const _hoisted_3 = {
671
+ key: 0,
672
+ class: "ask-again"
673
+ };
674
+ const _sfc_main = /* @__PURE__ */ defineComponent({
675
+ __name: "KdsConfirmDialog",
676
+ setup(__props) {
677
+ const askAgain = ref(false);
678
+ const { config, isActive, confirm, cancel, isComponentBasedConfig } = useKdsConfirmDialog();
679
+ const reset = () => {
680
+ askAgain.value = false;
681
+ };
682
+ const onConfirm = () => {
683
+ confirm(askAgain.value);
684
+ reset();
685
+ };
686
+ const onCancel = () => {
687
+ cancel();
688
+ reset();
689
+ };
690
+ const handleConfirmButtonClick = (button) => {
691
+ if (button.customHandler) {
692
+ button.customHandler({ confirm: onConfirm });
693
+ return;
694
+ }
695
+ onConfirm();
696
+ };
697
+ const handleCancelButtonClick = (button) => {
698
+ if (button.customHandler) {
699
+ button.customHandler({ cancel: onCancel });
700
+ return;
701
+ }
702
+ onCancel();
703
+ };
704
+ const handleButtonClick = (button) => {
705
+ if (button.type === "cancel") {
706
+ handleCancelButtonClick(button);
707
+ } else {
708
+ handleConfirmButtonClick(button);
709
+ }
710
+ };
711
+ const defaultVariant = (type) => type === "cancel" ? "transparent" : "filled";
712
+ return (_ctx, _cache) => {
713
+ return openBlock(), createBlock(KdsModal, {
714
+ class: "confirm-dialog",
715
+ active: unref(isActive),
716
+ title: unref(config)?.title,
717
+ closedby: unref(config)?.closedby,
718
+ icon: unref(config)?.icon,
719
+ onClose: onCancel
720
+ }, createSlots({
721
+ default: withCtx(() => [
722
+ unref(config) && unref(isComponentBasedConfig)(unref(config)) ? (openBlock(), createBlock(resolveDynamicComponent(unref(config).component), { key: 0 })) : (openBlock(), createElementBlock("div", _hoisted_1, [
723
+ createElementVNode("div", _hoisted_2, toDisplayString(unref(config)?.message), 1),
724
+ unref(config)?.doNotAskAgain ? (openBlock(), createElementBlock("div", _hoisted_3, [
725
+ createVNode(KdsCheckbox, {
726
+ modelValue: askAgain.value,
727
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => askAgain.value = $event),
728
+ label: unref(config).doNotAskAgain.label,
729
+ title: unref(config).doNotAskAgain.title,
730
+ "helper-text": unref(config).doNotAskAgain.helperText
731
+ }, null, 8, ["modelValue", "label", "title", "helper-text"])
732
+ ])) : createCommentVNode("", true)
733
+ ]))
734
+ ]),
735
+ _: 2
736
+ }, [
737
+ unref(config) ? {
738
+ name: "footer",
739
+ fn: withCtx(() => [
740
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(config).buttons, (button, index) => {
741
+ return openBlock(), createBlock(_sfc_main$5, {
742
+ key: index,
743
+ destructive: button.destructive,
744
+ autofocus: button.autofocus,
745
+ label: button.label,
746
+ variant: button.variant ?? defaultVariant(button.type),
747
+ class: normalizeClass({ "flush-left": button.flushLeft }),
748
+ "data-test-id": `${button.type}-button`,
749
+ onClick: ($event) => handleButtonClick(button)
750
+ }, null, 8, ["destructive", "autofocus", "label", "variant", "class", "data-test-id", "onClick"]);
751
+ }), 128))
752
+ ]),
753
+ key: "0"
754
+ } : void 0
755
+ ]), 1032, ["active", "title", "closedby", "icon"]);
498
756
  };
499
757
  }
500
758
  });
501
759
 
502
- const KdsDataType = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-f7d93fdf"]]);
760
+ const KdsConfirmDialog = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-14083a4d"]]);
503
761
 
504
762
  const KDS_DARK_MODE_STORAGE_KEY = "KNIME_DARK_MODE";
505
763
  const defaultMode = "light";
@@ -580,5 +838,5 @@ const useKdsLegacyMode = (initialValue = false) => {
580
838
  };
581
839
  };
582
840
 
583
- export { _sfc_main$3 as KdsButton, KdsCheckbox, KdsDataType, Icon as KdsIcon, _sfc_main$2 as KdsLinkButton, useKdsDarkMode, useKdsLegacyMode };
841
+ export { _sfc_main$5 as KdsButton, KdsCheckbox, KdsConfirmDialog, KdsDataType, KdsIcon, _sfc_main$4 as KdsLinkButton, KdsModal, useKdsConfirmDialog, useKdsDarkMode, useKdsLegacyMode };
584
842
  //# sourceMappingURL=index.js.map