@dative-gpi/foundation-shared-components 0.0.38 → 0.0.40
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/components/FSButton.vue +1 -14
- package/components/FSChip.vue +10 -17
- package/components/FSClickable.vue +11 -12
- package/components/FSColor.vue +2 -2
- package/components/FSDivider.vue +30 -10
- package/components/FSErrorToast.vue +67 -0
- package/components/FSFadeOut.vue +23 -5
- package/components/FSForm.vue +7 -3
- package/components/FSOptionGroup.vue +311 -0
- package/components/FSOptionItem.vue +132 -0
- package/components/FSSlideGroup.vue +25 -1
- package/components/FSTabs.vue +3 -4
- package/components/FSTag.vue +7 -8
- package/components/FSToggleSet.vue +2 -0
- package/components/FSWrapGroup.vue +1 -17
- package/components/fields/FSIconField.vue +1 -1
- package/composables/useColors.ts +66 -37
- package/composables/useRules.ts +3 -0
- package/models/colors.ts +4 -0
- package/models/errors.ts +36 -0
- package/models/index.ts +1 -0
- package/package.json +4 -4
- package/styles/components/fs_color.scss +1 -1
- package/styles/components/fs_container.scss +5 -5
- package/styles/components/fs_error_toast.scss +5 -0
- package/styles/components/fs_option_group.scss +7 -0
- package/styles/components/index.scss +2 -0
- package/utils/error.ts +5 -0
- package/utils/index.ts +1 -0
package/components/FSButton.vue
CHANGED
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
|
|
97
97
|
<script lang="ts">
|
|
98
98
|
import { computed, defineComponent, PropType } from "vue";
|
|
99
|
-
import { RouteLocation
|
|
99
|
+
import { RouteLocation } from "vue-router";
|
|
100
100
|
|
|
101
101
|
import { useColors, useSlots } from "@dative-gpi/foundation-shared-components/composables";
|
|
102
102
|
import { ColorBase, ColorEnum } from "@dative-gpi/foundation-shared-components/models";
|
|
@@ -170,7 +170,6 @@ export default defineComponent({
|
|
|
170
170
|
setup(props, { emit }) {
|
|
171
171
|
const { getColors } = useColors();
|
|
172
172
|
const { slots } = useSlots();
|
|
173
|
-
const router = useRouter();
|
|
174
173
|
|
|
175
174
|
const colors = computed(() => getColors(props.color));
|
|
176
175
|
const lights = getColors(ColorEnum.Light);
|
|
@@ -232,18 +231,6 @@ export default defineComponent({
|
|
|
232
231
|
return "fit-content";
|
|
233
232
|
});
|
|
234
233
|
|
|
235
|
-
const href = computed((): string | null => {
|
|
236
|
-
if (!props.to || !props.editable || props.load) {
|
|
237
|
-
return null;
|
|
238
|
-
}
|
|
239
|
-
if (typeof props.to === "string") {
|
|
240
|
-
return props.to;
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
return router.resolve(props.to).href;
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
|
|
247
234
|
const onClick = (event: MouseEvent) => {
|
|
248
235
|
if (!props.to && props.editable && !props.load) {
|
|
249
236
|
emit("click", event);
|
package/components/FSChip.vue
CHANGED
|
@@ -85,41 +85,34 @@ export default defineComponent({
|
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
87
|
setup(props) {
|
|
88
|
-
const { getColors
|
|
88
|
+
const { getColors } = useColors();
|
|
89
89
|
|
|
90
90
|
const colors = computed(() => getColors(props.color));
|
|
91
91
|
const backgrounds = getColors(ColorEnum.Background);
|
|
92
92
|
|
|
93
|
-
const textColors = computed(() => {
|
|
94
|
-
switch (props.variant) {
|
|
95
|
-
case "standard": return colors.value;
|
|
96
|
-
case "full": return getContrasts(props.color);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
93
|
const style = computed((): { [code: string]: string } & Partial<CSSStyleDeclaration> => {
|
|
101
94
|
switch (props.variant) {
|
|
102
95
|
case "standard": return {
|
|
103
96
|
"--fs-chip-background-color" : backgrounds.base,
|
|
104
97
|
"--fs-chip-border-color" : colors.value.base,
|
|
105
|
-
"--fs-chip-color" :
|
|
98
|
+
"--fs-chip-color" : colors.value.base,
|
|
106
99
|
"--fs-chip-hover-background-color" : backgrounds.base,
|
|
107
100
|
"--fs-chip-hover-border-color" : colors.value.base,
|
|
108
|
-
"--fs-chip-hover-color" :
|
|
101
|
+
"--fs-chip-hover-color" : colors.value.base,
|
|
109
102
|
"--fs-chip-active-background-color": backgrounds.base,
|
|
110
103
|
"--fs-chip-active-border-color" : colors.value.dark,
|
|
111
|
-
"--fs-chip-active-color" :
|
|
104
|
+
"--fs-chip-active-color" : colors.value.dark
|
|
112
105
|
};
|
|
113
106
|
case "full": return {
|
|
114
107
|
"--fs-chip-background-color" : colors.value.base,
|
|
115
|
-
"--fs-chip-border-color" : colors.value.
|
|
116
|
-
"--fs-chip-color" :
|
|
108
|
+
"--fs-chip-border-color" : colors.value.baseContrast,
|
|
109
|
+
"--fs-chip-color" : colors.value.baseContrast,
|
|
117
110
|
"--fs-chip-hover-background-color" : colors.value.base,
|
|
118
|
-
"--fs-chip-hover-border-color" : colors.value.
|
|
119
|
-
"--fs-chip-hover-color" :
|
|
111
|
+
"--fs-chip-hover-border-color" : colors.value.baseContrast,
|
|
112
|
+
"--fs-chip-hover-color" : colors.value.baseContrast,
|
|
120
113
|
"--fs-chip-active-background-color": colors.value.dark,
|
|
121
|
-
"--fs-chip-active-border-color" : colors.value.
|
|
122
|
-
"--fs-chip-active-color" :
|
|
114
|
+
"--fs-chip-active-border-color" : colors.value.darkContrast,
|
|
115
|
+
"--fs-chip-active-color" : colors.value.darkContrast
|
|
123
116
|
};
|
|
124
117
|
}
|
|
125
118
|
});
|
|
@@ -116,10 +116,9 @@ export default defineComponent({
|
|
|
116
116
|
},
|
|
117
117
|
emits: ["click"],
|
|
118
118
|
setup(props, { emit }) {
|
|
119
|
-
const { getColors
|
|
119
|
+
const { getColors } = useColors();
|
|
120
120
|
const router = useRouter();
|
|
121
121
|
|
|
122
|
-
const textColors = computed(() => getContrasts(props.color));
|
|
123
122
|
const colors = computed(() => getColors(props.color));
|
|
124
123
|
const lights = getColors(ColorEnum.Light);
|
|
125
124
|
const darks = getColors(ColorEnum.Dark);
|
|
@@ -129,7 +128,7 @@ export default defineComponent({
|
|
|
129
128
|
return {
|
|
130
129
|
"--fs-clickable-border-size" : props.border ? "1px" : "0",
|
|
131
130
|
"--fs-clickable-border-radius" : sizeToVar(props.borderRadius),
|
|
132
|
-
"--fs-clickable-background-color": lights.
|
|
131
|
+
"--fs-clickable-background-color": lights.light,
|
|
133
132
|
"--fs-clickable-border-color" : lights.dark,
|
|
134
133
|
"--fs-clickable-color" : lights.dark
|
|
135
134
|
};
|
|
@@ -139,27 +138,27 @@ export default defineComponent({
|
|
|
139
138
|
"--fs-clickable-border-size" : props.border ? "1px" : "0",
|
|
140
139
|
"--fs-clickable-border-radius" : sizeToVar(props.borderRadius),
|
|
141
140
|
"--fs-clickable-background-color" : colors.value.light,
|
|
142
|
-
"--fs-clickable-border-color" : colors.value.
|
|
143
|
-
"--fs-clickable-color" :
|
|
141
|
+
"--fs-clickable-border-color" : colors.value.lightContrast,
|
|
142
|
+
"--fs-clickable-color" : colors.value.lightContrast,
|
|
144
143
|
"--fs-clickable-hover-background-color" : colors.value.base,
|
|
145
|
-
"--fs-clickable-hover-border-color" : colors.value.
|
|
146
|
-
"--fs-clickable-hover-color" :
|
|
144
|
+
"--fs-clickable-hover-border-color" : colors.value.baseContrast,
|
|
145
|
+
"--fs-clickable-hover-color" : colors.value.baseContrast,
|
|
147
146
|
"--fs-clickable-active-background-color": colors.value.dark,
|
|
148
|
-
"--fs-clickable-active-border-color" : colors.value.
|
|
149
|
-
"--fs-clickable-active-color" :
|
|
147
|
+
"--fs-clickable-active-border-color" : colors.value.darkContrast,
|
|
148
|
+
"--fs-clickable-active-color" : colors.value.darkContrast
|
|
150
149
|
};
|
|
151
150
|
case "full": return {
|
|
152
151
|
"--fs-clickable-border-size" : props.border ? "1px" : "0",
|
|
153
152
|
"--fs-clickable-border-radius" : sizeToVar(props.borderRadius),
|
|
154
153
|
"--fs-clickable-background-color" : colors.value.base,
|
|
155
154
|
"--fs-clickable-border-color" : colors.value.base,
|
|
156
|
-
"--fs-clickable-color" :
|
|
155
|
+
"--fs-clickable-color" : colors.value.baseContrast,
|
|
157
156
|
"--fs-clickable-hover-background-color" : colors.value.base,
|
|
158
157
|
"--fs-clickable-hover-border-color" : colors.value.base,
|
|
159
|
-
"--fs-clickable-hover-color" :
|
|
158
|
+
"--fs-clickable-hover-color" : colors.value.baseContrast,
|
|
160
159
|
"--fs-clickable-active-background-color": colors.value.dark,
|
|
161
160
|
"--fs-clickable-active-border-color" : colors.value.dark,
|
|
162
|
-
"--fs-clickable-active-color" :
|
|
161
|
+
"--fs-clickable-active-color" : colors.value.darkContrast
|
|
163
162
|
};
|
|
164
163
|
}
|
|
165
164
|
});
|
package/components/FSColor.vue
CHANGED
|
@@ -41,8 +41,8 @@ export default defineComponent({
|
|
|
41
41
|
|
|
42
42
|
const style: Ref<{ [code: string]: string } & Partial<CSSStyleDeclaration>> = ref({
|
|
43
43
|
"--fs-color-background-color": colors.value.light,
|
|
44
|
-
"--fs-color-border-color" : colors.value.
|
|
45
|
-
"--fs-color-color" : colors.value.
|
|
44
|
+
"--fs-color-border-color" : colors.value.lightContrast,
|
|
45
|
+
"--fs-color-color" : colors.value.lightContrast,
|
|
46
46
|
"--fs-color-light" : colors.value.light,
|
|
47
47
|
"--fs-color-base" : colors.value.base,
|
|
48
48
|
"--fs-color-dark" : colors.value.dark
|
package/components/FSDivider.vue
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
import { computed, defineComponent, PropType } from "vue";
|
|
33
33
|
|
|
34
34
|
import { useColors, useSlots } from "@dative-gpi/foundation-shared-components/composables";
|
|
35
|
-
import { ColorEnum } from "@dative-gpi/foundation-shared-components/models";
|
|
35
|
+
import { ColorBase, ColorEnum } from "@dative-gpi/foundation-shared-components/models";
|
|
36
36
|
import { sizeToVar } from "@dative-gpi/foundation-shared-components/utils";
|
|
37
37
|
|
|
38
38
|
import FSText from "./FSText.vue";
|
|
@@ -43,32 +43,52 @@ export default defineComponent({
|
|
|
43
43
|
FSText
|
|
44
44
|
},
|
|
45
45
|
props: {
|
|
46
|
-
width: {
|
|
47
|
-
type: [String, Number],
|
|
48
|
-
required: false,
|
|
49
|
-
default: "100%"
|
|
50
|
-
},
|
|
51
46
|
label: {
|
|
52
47
|
type: String,
|
|
53
48
|
required: false,
|
|
54
49
|
default: null
|
|
55
50
|
},
|
|
51
|
+
width: {
|
|
52
|
+
type: [String, Number],
|
|
53
|
+
required: false,
|
|
54
|
+
default: "100%"
|
|
55
|
+
},
|
|
56
56
|
font: {
|
|
57
57
|
type: String as PropType<"text-h1" | "text-h2" | "text-h3" | "text-h4" | "text-body" | "text-button" | "text-overline" | "text-underline">,
|
|
58
58
|
required: false,
|
|
59
59
|
default: "text-body"
|
|
60
|
+
},
|
|
61
|
+
color: {
|
|
62
|
+
type: String as PropType<ColorBase>,
|
|
63
|
+
required: false,
|
|
64
|
+
default: ColorEnum.Light
|
|
65
|
+
},
|
|
66
|
+
variant: {
|
|
67
|
+
type: String as PropType<"base" | "light" | "dark">,
|
|
68
|
+
required: false,
|
|
69
|
+
default: "dark"
|
|
60
70
|
}
|
|
61
71
|
},
|
|
62
72
|
setup(props) {
|
|
63
73
|
const { getColors } = useColors();
|
|
64
74
|
const { slots } = useSlots();
|
|
65
75
|
|
|
66
|
-
const
|
|
76
|
+
const colors = computed(() => getColors(props.color));
|
|
67
77
|
|
|
68
78
|
const style = computed((): { [code: string]: string } & Partial<CSSStyleDeclaration> => {
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
79
|
+
switch (props.variant) {
|
|
80
|
+
case "base": return {
|
|
81
|
+
"--fs-divider-width": sizeToVar(props.width),
|
|
82
|
+
"--fs-divider-color": colors.value.base
|
|
83
|
+
};
|
|
84
|
+
case "light": return {
|
|
85
|
+
"--fs-divider-width": sizeToVar(props.width),
|
|
86
|
+
"--fs-divider-color": colors.value.light
|
|
87
|
+
};
|
|
88
|
+
case "dark": return {
|
|
89
|
+
"--fs-divider-width": sizeToVar(props.width),
|
|
90
|
+
"--fs-divider-color": colors.value.dark
|
|
91
|
+
};
|
|
72
92
|
}
|
|
73
93
|
});
|
|
74
94
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<FSRow
|
|
3
|
+
padding="18px 0 18px 32px"
|
|
4
|
+
class="fs-error-toast"
|
|
5
|
+
align="center-left"
|
|
6
|
+
:style="style"
|
|
7
|
+
>
|
|
8
|
+
<FSIcon>
|
|
9
|
+
mdi-alert-outline
|
|
10
|
+
</FSIcon>
|
|
11
|
+
<FSSpan>
|
|
12
|
+
{{ $tr(error.code, error.default) }}
|
|
13
|
+
</FSSpan>
|
|
14
|
+
</FSRow>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
import { computed, defineComponent } from "vue";
|
|
19
|
+
|
|
20
|
+
import { getError, sizeToVar } from "@dative-gpi/foundation-shared-components/utils";
|
|
21
|
+
import { useColors } from "@dative-gpi/foundation-shared-components/composables";
|
|
22
|
+
import { ColorEnum } from "@dative-gpi/foundation-shared-components/models";
|
|
23
|
+
|
|
24
|
+
import FSIcon from "./FSIcon.vue";
|
|
25
|
+
import FSSpan from "./FSSpan.vue";
|
|
26
|
+
import FSRow from "./FSRow.vue";
|
|
27
|
+
|
|
28
|
+
export default defineComponent({
|
|
29
|
+
name: "FSErrorToast",
|
|
30
|
+
components: {
|
|
31
|
+
FSIcon,
|
|
32
|
+
FSSpan,
|
|
33
|
+
FSRow
|
|
34
|
+
},
|
|
35
|
+
props: {
|
|
36
|
+
errorCode: {
|
|
37
|
+
type: String,
|
|
38
|
+
required: true
|
|
39
|
+
},
|
|
40
|
+
borderRadius: {
|
|
41
|
+
type: [String, Number],
|
|
42
|
+
required: false,
|
|
43
|
+
default: "4px"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
setup(props) {
|
|
47
|
+
const { getColors } = useColors();
|
|
48
|
+
|
|
49
|
+
const errors = getColors(ColorEnum.Error);
|
|
50
|
+
|
|
51
|
+
const style = computed((): { [code: string]: string } & Partial<CSSStyleDeclaration> => {
|
|
52
|
+
return {
|
|
53
|
+
"--fs-error-toast-border-radius" : sizeToVar(props.borderRadius),
|
|
54
|
+
"--fs-error-toast-background-color": errors.base,
|
|
55
|
+
"--fs-error-toast-color" : errors.light
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const error = computed((): { code: string, default: string, status: number } => getError(props.errorCode));
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
error,
|
|
63
|
+
style
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
</script>
|
package/components/FSFadeOut.vue
CHANGED
|
@@ -66,10 +66,18 @@ export default defineComponent({
|
|
|
66
66
|
case "number": return sizeToVar(props.padding);
|
|
67
67
|
default:
|
|
68
68
|
const paddings = props.padding.split(" ");
|
|
69
|
+
let tempPadding = "0px";
|
|
69
70
|
switch (paddings.length) {
|
|
70
|
-
case 0 :
|
|
71
|
-
|
|
71
|
+
case 0 :
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
tempPadding = "-" + sizeToVar(paddings[0]);
|
|
75
|
+
break;
|
|
72
76
|
}
|
|
77
|
+
if (tempPadding === "0px") {
|
|
78
|
+
return "-1px";
|
|
79
|
+
}
|
|
80
|
+
return tempPadding;
|
|
73
81
|
}
|
|
74
82
|
});
|
|
75
83
|
|
|
@@ -78,12 +86,22 @@ export default defineComponent({
|
|
|
78
86
|
case "number": return sizeToVar(props.padding);
|
|
79
87
|
default:
|
|
80
88
|
const paddings = props.padding.split(" ");
|
|
89
|
+
let tempPadding = "0px";
|
|
81
90
|
switch (paddings.length) {
|
|
82
|
-
case 0 :
|
|
91
|
+
case 0 :
|
|
92
|
+
break;
|
|
83
93
|
case 1 :
|
|
84
|
-
case 2 :
|
|
85
|
-
|
|
94
|
+
case 2 :
|
|
95
|
+
tempPadding = "-" + sizeToVar(paddings[0]);
|
|
96
|
+
break;
|
|
97
|
+
default:
|
|
98
|
+
tempPadding = "-" + sizeToVar(paddings[2]);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
if (tempPadding === "0px") {
|
|
102
|
+
return "-1px";
|
|
86
103
|
}
|
|
104
|
+
return tempPadding;
|
|
87
105
|
}
|
|
88
106
|
});
|
|
89
107
|
|
package/components/FSForm.vue
CHANGED
|
@@ -27,8 +27,8 @@ export default defineComponent({
|
|
|
27
27
|
default: "standard"
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
|
-
emits: ["update:modelValue"],
|
|
31
|
-
setup(props) {
|
|
30
|
+
emits: ["update:modelValue", "submit"],
|
|
31
|
+
setup(props, { emit }) {
|
|
32
32
|
const formRef = ref<HTMLFormElement | null>(null);
|
|
33
33
|
const submitted = ref(false);
|
|
34
34
|
|
|
@@ -40,10 +40,14 @@ export default defineComponent({
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
const onSubmit = (event: SubmitEvent) => {
|
|
43
|
+
const onSubmit = async (event: SubmitEvent) => {
|
|
44
44
|
event.stopImmediatePropagation();
|
|
45
45
|
event.preventDefault();
|
|
46
46
|
submitted.value = true;
|
|
47
|
+
await formRef.value.validate();
|
|
48
|
+
emit("update:modelValue", !!formRef.value.isValid);
|
|
49
|
+
emit("submit", !!formRef.value.isValid);
|
|
50
|
+
|
|
47
51
|
};
|
|
48
52
|
|
|
49
53
|
provide("validateOn", validateOn);
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<FSWrapGroup
|
|
3
|
+
v-if="['wrap'].includes($props.variant)"
|
|
4
|
+
class="fs-option-group"
|
|
5
|
+
:padding="$props.padding"
|
|
6
|
+
:gap="$props.gap"
|
|
7
|
+
:style="style"
|
|
8
|
+
>
|
|
9
|
+
<template v-if="$props.values.length">
|
|
10
|
+
<template v-if="!firstChild">
|
|
11
|
+
<FSOptionItem
|
|
12
|
+
v-for="(item, index) in $props.values"
|
|
13
|
+
:prependIcon="item.prependIcon"
|
|
14
|
+
:appendIcon="item.appendIcon"
|
|
15
|
+
:editable="$props.editable"
|
|
16
|
+
:variant="getVariant(item)"
|
|
17
|
+
:color="getColor(item)"
|
|
18
|
+
:class="getClass(item)"
|
|
19
|
+
:label="item.label"
|
|
20
|
+
:icon="item.icon"
|
|
21
|
+
:key="index"
|
|
22
|
+
@click="toggle(item)"
|
|
23
|
+
/>
|
|
24
|
+
</template>
|
|
25
|
+
<template v-else>
|
|
26
|
+
<component
|
|
27
|
+
v-for="(item, index) in $props.values"
|
|
28
|
+
:key="index"
|
|
29
|
+
:is="firstChild"
|
|
30
|
+
:prependIcon="getFromFirstChild('prependIcon', item)"
|
|
31
|
+
:appendIcon="getFromFirstChild('appendIcon', item)"
|
|
32
|
+
:variant="getFromFirstChild('variant', item)"
|
|
33
|
+
:color="getFromFirstChild('color', item)"
|
|
34
|
+
:class="getFromFirstChild('class', item)"
|
|
35
|
+
:label="getFromFirstChild('label', item)"
|
|
36
|
+
:icon="getFromFirstChild('icon', item)"
|
|
37
|
+
:editable="$props.editable"
|
|
38
|
+
@click="toggle(item)"
|
|
39
|
+
/>
|
|
40
|
+
</template>
|
|
41
|
+
</template>
|
|
42
|
+
<slot v-else />
|
|
43
|
+
</FSWrapGroup>
|
|
44
|
+
<FSSlideGroup
|
|
45
|
+
v-else
|
|
46
|
+
class="fs-option-group"
|
|
47
|
+
:padding="$props.padding"
|
|
48
|
+
:gap="$props.gap"
|
|
49
|
+
:style="style"
|
|
50
|
+
>
|
|
51
|
+
<template v-if="$props.values.length">
|
|
52
|
+
<template v-if="!firstChild">
|
|
53
|
+
<FSOptionItem
|
|
54
|
+
v-for="(item, index) in $props.values"
|
|
55
|
+
:prependIcon="item.prependIcon"
|
|
56
|
+
:appendIcon="item.appendIcon"
|
|
57
|
+
:editable="$props.editable"
|
|
58
|
+
:variant="getVariant(item)"
|
|
59
|
+
:color="getColor(item)"
|
|
60
|
+
:class="getClass(item)"
|
|
61
|
+
:label="item.label"
|
|
62
|
+
:icon="item.icon"
|
|
63
|
+
:key="index"
|
|
64
|
+
@click="toggle(item)"
|
|
65
|
+
/>
|
|
66
|
+
</template>
|
|
67
|
+
<template v-else>
|
|
68
|
+
<component
|
|
69
|
+
v-for="(item, index) in $props.values"
|
|
70
|
+
:key="index"
|
|
71
|
+
:is="firstChild"
|
|
72
|
+
:prependIcon="getFromFirstChild('prependIcon', item)"
|
|
73
|
+
:appendIcon="getFromFirstChild('appendIcon', item)"
|
|
74
|
+
:variant="getFromFirstChild('variant', item)"
|
|
75
|
+
:color="getFromFirstChild('color', item)"
|
|
76
|
+
:class="getFromFirstChild('class', item)"
|
|
77
|
+
:label="getFromFirstChild('label', item)"
|
|
78
|
+
:icon="getFromFirstChild('icon', item)"
|
|
79
|
+
:editable="$props.editable"
|
|
80
|
+
@click="toggle(item)"
|
|
81
|
+
/>
|
|
82
|
+
</template>
|
|
83
|
+
</template>
|
|
84
|
+
<slot v-else />
|
|
85
|
+
</FSSlideGroup>
|
|
86
|
+
</template>
|
|
87
|
+
|
|
88
|
+
<script lang="ts">
|
|
89
|
+
import { computed, defineComponent, PropType } from "vue";
|
|
90
|
+
|
|
91
|
+
import { useColors, useSlots } from "@dative-gpi/foundation-shared-components/composables";
|
|
92
|
+
import { ColorBase, ColorEnum } from "@dative-gpi/foundation-shared-components/models";
|
|
93
|
+
import { sizeToVar } from "@dative-gpi/foundation-shared-components/utils";
|
|
94
|
+
import { FSToggle } from "@dative-gpi/foundation-shared-components/models";
|
|
95
|
+
|
|
96
|
+
import FSOptionItem from "./FSOptionItem.vue";
|
|
97
|
+
import FSSlideGroup from "./FSSlideGroup.vue";
|
|
98
|
+
import FSWrapGroup from "./FSWrapGroup.vue";
|
|
99
|
+
|
|
100
|
+
export default defineComponent({
|
|
101
|
+
name: "FSOptionGroup",
|
|
102
|
+
components: {
|
|
103
|
+
FSOptionItem,
|
|
104
|
+
FSSlideGroup,
|
|
105
|
+
FSWrapGroup
|
|
106
|
+
},
|
|
107
|
+
props: {
|
|
108
|
+
values: {
|
|
109
|
+
type: Array as PropType<FSToggle[]>,
|
|
110
|
+
required: false,
|
|
111
|
+
default: () => []
|
|
112
|
+
},
|
|
113
|
+
border: {
|
|
114
|
+
type: Boolean,
|
|
115
|
+
required: false,
|
|
116
|
+
default: true
|
|
117
|
+
},
|
|
118
|
+
borderRadius: {
|
|
119
|
+
type: [String, Number],
|
|
120
|
+
required: false,
|
|
121
|
+
default: "4px"
|
|
122
|
+
},
|
|
123
|
+
variant: {
|
|
124
|
+
type: String as PropType<"wrap" | "slide">,
|
|
125
|
+
required: false,
|
|
126
|
+
default: "wrap"
|
|
127
|
+
},
|
|
128
|
+
optionVariant: {
|
|
129
|
+
type: String as PropType<"standard" | "full">,
|
|
130
|
+
required: false,
|
|
131
|
+
default: "full"
|
|
132
|
+
},
|
|
133
|
+
activeVariant: {
|
|
134
|
+
type: String as PropType<"standard" | "full">,
|
|
135
|
+
required: false,
|
|
136
|
+
default: "full"
|
|
137
|
+
},
|
|
138
|
+
optionClass: {
|
|
139
|
+
type: [Array, String] as PropType<string[] | string>,
|
|
140
|
+
required: false,
|
|
141
|
+
default: null
|
|
142
|
+
},
|
|
143
|
+
activeClass: {
|
|
144
|
+
type: [Array, String] as PropType<string[] | string>,
|
|
145
|
+
required: false,
|
|
146
|
+
default: null
|
|
147
|
+
},
|
|
148
|
+
modelValue: {
|
|
149
|
+
type: [Array, String, Number] as PropType<(string | number)[] | string | number>,
|
|
150
|
+
required: false,
|
|
151
|
+
default: false
|
|
152
|
+
},
|
|
153
|
+
optionColor: {
|
|
154
|
+
type: String as PropType<ColorBase>,
|
|
155
|
+
required: false,
|
|
156
|
+
default: ColorEnum.Background
|
|
157
|
+
},
|
|
158
|
+
activeColor: {
|
|
159
|
+
type: String as PropType<ColorBase>,
|
|
160
|
+
required: false,
|
|
161
|
+
default: ColorEnum.Primary
|
|
162
|
+
},
|
|
163
|
+
padding: {
|
|
164
|
+
type: [String, Number],
|
|
165
|
+
required: false,
|
|
166
|
+
default: "3px"
|
|
167
|
+
},
|
|
168
|
+
gap: {
|
|
169
|
+
type: [String, Number],
|
|
170
|
+
required: false,
|
|
171
|
+
default: "0"
|
|
172
|
+
},
|
|
173
|
+
multiple: {
|
|
174
|
+
type: Boolean,
|
|
175
|
+
required: false,
|
|
176
|
+
default: false
|
|
177
|
+
},
|
|
178
|
+
required: {
|
|
179
|
+
type: Boolean,
|
|
180
|
+
required: false,
|
|
181
|
+
default: true
|
|
182
|
+
},
|
|
183
|
+
editable: {
|
|
184
|
+
type: Boolean,
|
|
185
|
+
required: false,
|
|
186
|
+
default: true
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
emits: ["update:modelValue"],
|
|
190
|
+
setup(props, { emit }) {
|
|
191
|
+
const { getFirstChild } = useSlots();
|
|
192
|
+
const { getColors } = useColors();
|
|
193
|
+
|
|
194
|
+
const lights = getColors(ColorEnum.Light);
|
|
195
|
+
|
|
196
|
+
const firstChild = getFirstChild("item");
|
|
197
|
+
|
|
198
|
+
const style = computed((): { [code: string]: string } & Partial<CSSStyleDeclaration> => {
|
|
199
|
+
return {
|
|
200
|
+
"--fs-option-group-border-size" : props.border ? "1px" : "0",
|
|
201
|
+
"--fs-option-group-border-radius": sizeToVar(props.borderRadius),
|
|
202
|
+
"--fs-option-group-border-color" : lights.base
|
|
203
|
+
};
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
const getFromFirstChild = (prop: string, value: FSToggle): any => {
|
|
207
|
+
switch (prop) {
|
|
208
|
+
case "prependIcon":
|
|
209
|
+
return firstChild.props.prependIcon ?? value.prependIcon;
|
|
210
|
+
case "label":
|
|
211
|
+
return firstChild.props.label ?? value.label;
|
|
212
|
+
case "appendIcon":
|
|
213
|
+
return firstChild.props.appendIcon ?? value.appendIcon;
|
|
214
|
+
case "icon":
|
|
215
|
+
return firstChild.props.icon ?? value.icon;
|
|
216
|
+
case "variant":
|
|
217
|
+
return firstChild.props.variant ?? getVariant(value);
|
|
218
|
+
case "color":
|
|
219
|
+
return firstChild.props.color ?? getColor(value);
|
|
220
|
+
default:
|
|
221
|
+
return firstChild.props[prop];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const getVariant = (value: FSToggle): "standard" | "full" => {
|
|
226
|
+
if (Array.isArray(props.modelValue) && props.modelValue.some(v => v === value.id)) {
|
|
227
|
+
return props.activeVariant;
|
|
228
|
+
}
|
|
229
|
+
if (!Array.isArray(props.modelValue) && props.modelValue === value.id) {
|
|
230
|
+
return props.activeVariant;
|
|
231
|
+
}
|
|
232
|
+
return props.optionVariant;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const getColor = (value: FSToggle): ColorBase => {
|
|
236
|
+
if (Array.isArray(props.modelValue) && props.modelValue.some(v => v === value.id)) {
|
|
237
|
+
return props.activeColor;
|
|
238
|
+
}
|
|
239
|
+
if (!Array.isArray(props.modelValue) && props.modelValue === value.id) {
|
|
240
|
+
return props.activeColor;
|
|
241
|
+
}
|
|
242
|
+
return props.optionColor;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const getClass = (value: FSToggle): string[] | string => {
|
|
246
|
+
if (Array.isArray(props.modelValue) && props.modelValue.some(v => v === value.id)) {
|
|
247
|
+
return props.activeClass;
|
|
248
|
+
}
|
|
249
|
+
if (!Array.isArray(props.modelValue) && props.modelValue === value.id) {
|
|
250
|
+
return props.activeClass;
|
|
251
|
+
}
|
|
252
|
+
return props.optionClass;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const toggle = (value: FSToggle): void => {
|
|
256
|
+
if (Array.isArray(props.modelValue)) {
|
|
257
|
+
if (props.multiple) {
|
|
258
|
+
if (props.modelValue.length && props.modelValue.every(v => v === value.id)) {
|
|
259
|
+
if (!props.required) {
|
|
260
|
+
emit("update:modelValue", []);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
else if (props.modelValue.some(v => v === value.id)) {
|
|
265
|
+
emit("update:modelValue", props.modelValue.filter(v => v !== value.id));
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
emit("update:modelValue", [...props.modelValue, value.id]);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
if (props.modelValue.some(v => v === value.id)) {
|
|
275
|
+
if (!props.required) {
|
|
276
|
+
emit("update:modelValue", []);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
emit("update:modelValue", [value.id]);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
if (props.modelValue === value.id) {
|
|
288
|
+
if (!props.required) {
|
|
289
|
+
emit("update:modelValue", null);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
emit("update:modelValue", value.id);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
return {
|
|
301
|
+
firstChild,
|
|
302
|
+
style,
|
|
303
|
+
getFromFirstChild,
|
|
304
|
+
getVariant,
|
|
305
|
+
getColor,
|
|
306
|
+
getClass,
|
|
307
|
+
toggle
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
})
|
|
311
|
+
</script>
|