@code-coaching/vuetiful 0.12.1 → 0.13.1
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/types/components/atoms/VRadio/VRadioDescription.test.d.ts +1 -0
- package/dist/types/components/atoms/VRadio/VRadioDescription.vue.d.ts +14 -0
- package/dist/types/components/atoms/VRadio/VRadioGroup.test.d.ts +1 -0
- package/dist/types/components/atoms/VRadio/VRadioGroup.vue.d.ts +70 -0
- package/dist/types/components/atoms/VRadio/VRadioItem.test.d.ts +1 -0
- package/dist/types/components/atoms/{VRadioItem.vue.d.ts → VRadio/VRadioItem.vue.d.ts} +2 -2
- package/dist/types/components/atoms/VRadio/VRadioLabel.test.d.ts +1 -0
- package/dist/types/components/atoms/VRadio/VRadioLabel.vue.d.ts +14 -0
- package/dist/types/components/atoms/index.d.ts +5 -3
- package/dist/types/components/index.d.ts +2 -3
- package/dist/types/components/molecules/VDrawer.vue.d.ts +1 -1
- package/dist/types/utils/code-block/VCodeBlock.vue.d.ts +1 -1
- package/package.json +2 -1
- package/src/components/atoms/VRadio/VRadioDescription.test.ts +55 -0
- package/src/components/atoms/VRadio/VRadioDescription.vue +14 -0
- package/src/components/atoms/VRadio/VRadioGroup.test.ts +81 -0
- package/src/components/atoms/VRadio/VRadioGroup.vue +71 -0
- package/src/components/atoms/VRadio/VRadioItem.test.ts +183 -0
- package/src/components/atoms/VRadio/VRadioItem.vue +26 -0
- package/src/components/atoms/VRadio/VRadioLabel.test.ts +55 -0
- package/src/components/atoms/VRadio/VRadioLabel.vue +14 -0
- package/src/components/atoms/index.ts +6 -3
- package/src/components/index.ts +2 -4
- package/dist/style.css +0 -10
- package/dist/styles/all.css +0 -6753
- package/dist/types/components/atoms/VRadioGroup.vue.d.ts +0 -32
- package/dist/vuetiful.es.mjs +0 -47478
- package/dist/vuetiful.umd.js +0 -18
- package/src/components/atoms/VRadioGroup.vue +0 -42
- package/src/components/atoms/VRadioItem.vue +0 -154
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{
|
|
2
|
+
as: {
|
|
3
|
+
type: StringConstructor;
|
|
4
|
+
default: string;
|
|
5
|
+
};
|
|
6
|
+
}, () => void, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
7
|
+
as: {
|
|
8
|
+
type: StringConstructor;
|
|
9
|
+
default: string;
|
|
10
|
+
};
|
|
11
|
+
}>>, {
|
|
12
|
+
as: string;
|
|
13
|
+
}>;
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{
|
|
2
|
+
as: {
|
|
3
|
+
type: StringConstructor;
|
|
4
|
+
default: string;
|
|
5
|
+
};
|
|
6
|
+
disabled: {
|
|
7
|
+
type: BooleanConstructor;
|
|
8
|
+
default: boolean;
|
|
9
|
+
};
|
|
10
|
+
by: {
|
|
11
|
+
type: (StringConstructor | FunctionConstructor)[];
|
|
12
|
+
};
|
|
13
|
+
modelValue: any;
|
|
14
|
+
active: {
|
|
15
|
+
type: StringConstructor;
|
|
16
|
+
default: string;
|
|
17
|
+
};
|
|
18
|
+
hover: {
|
|
19
|
+
type: StringConstructor;
|
|
20
|
+
default: string;
|
|
21
|
+
};
|
|
22
|
+
background: {
|
|
23
|
+
type: StringConstructor;
|
|
24
|
+
default: string;
|
|
25
|
+
};
|
|
26
|
+
text: {
|
|
27
|
+
type: StringConstructor;
|
|
28
|
+
default: string;
|
|
29
|
+
};
|
|
30
|
+
}, () => void, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, "update:modelValue"[], "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
31
|
+
as: {
|
|
32
|
+
type: StringConstructor;
|
|
33
|
+
default: string;
|
|
34
|
+
};
|
|
35
|
+
disabled: {
|
|
36
|
+
type: BooleanConstructor;
|
|
37
|
+
default: boolean;
|
|
38
|
+
};
|
|
39
|
+
by: {
|
|
40
|
+
type: (StringConstructor | FunctionConstructor)[];
|
|
41
|
+
};
|
|
42
|
+
modelValue: any;
|
|
43
|
+
active: {
|
|
44
|
+
type: StringConstructor;
|
|
45
|
+
default: string;
|
|
46
|
+
};
|
|
47
|
+
hover: {
|
|
48
|
+
type: StringConstructor;
|
|
49
|
+
default: string;
|
|
50
|
+
};
|
|
51
|
+
background: {
|
|
52
|
+
type: StringConstructor;
|
|
53
|
+
default: string;
|
|
54
|
+
};
|
|
55
|
+
text: {
|
|
56
|
+
type: StringConstructor;
|
|
57
|
+
default: string;
|
|
58
|
+
};
|
|
59
|
+
}>> & {
|
|
60
|
+
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
as: string;
|
|
63
|
+
disabled: boolean;
|
|
64
|
+
modelValue: any;
|
|
65
|
+
active: string;
|
|
66
|
+
hover: string;
|
|
67
|
+
background: string;
|
|
68
|
+
text: string;
|
|
69
|
+
}>;
|
|
70
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
declare const _default: import("vue").DefineComponent<{
|
|
2
2
|
value: {
|
|
3
|
-
type: (StringConstructor | NumberConstructor)[];
|
|
3
|
+
type: (BooleanConstructor | StringConstructor | ObjectConstructor | NumberConstructor)[];
|
|
4
4
|
required: true;
|
|
5
5
|
};
|
|
6
6
|
}, () => void, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
7
7
|
value: {
|
|
8
|
-
type: (StringConstructor | NumberConstructor)[];
|
|
8
|
+
type: (BooleanConstructor | StringConstructor | ObjectConstructor | NumberConstructor)[];
|
|
9
9
|
required: true;
|
|
10
10
|
};
|
|
11
11
|
}>>, {}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{
|
|
2
|
+
as: {
|
|
3
|
+
type: StringConstructor;
|
|
4
|
+
default: string;
|
|
5
|
+
};
|
|
6
|
+
}, () => void, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
7
|
+
as: {
|
|
8
|
+
type: StringConstructor;
|
|
9
|
+
default: string;
|
|
10
|
+
};
|
|
11
|
+
}>>, {
|
|
12
|
+
as: string;
|
|
13
|
+
}>;
|
|
14
|
+
export default _default;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import VBadge from "./VBadge.vue";
|
|
2
2
|
import VButton from "./VButton.vue";
|
|
3
3
|
import VChip from "./VChip.vue";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
4
|
+
import VRadioDescription from "./VRadio/VRadioDescription.vue";
|
|
5
|
+
import VRadioGroup from "./VRadio/VRadioGroup.vue";
|
|
6
|
+
import VRadioItem from "./VRadio/VRadioItem.vue";
|
|
7
|
+
import VRadioLabel from "./VRadio/VRadioLabel.vue";
|
|
8
|
+
export { VButton, VBadge, VChip, VRadioGroup, VRadioItem, VRadioLabel, VRadioDescription };
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { VButton, VRail, VRailTile, VShell, VDrawer, VBadge, VChip, VRadioGroup, VRadioItem };
|
|
1
|
+
export * from './atoms';
|
|
2
|
+
export * from './molecules';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-coaching/vuetiful",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "onchange 'src/**/*.vue' 'src/**/*.ts' 'src/**/*.css' -- npm run build",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"vue": "^3.2.25"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@headlessui/vue": "^1.7.13",
|
|
21
22
|
"highlight.js": "^11.7.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { mount } from "@vue/test-utils";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import VRadioGroup from "./VRadioGroup.vue";
|
|
4
|
+
import VRadioDescription from "./VRadioDescription.vue";
|
|
5
|
+
|
|
6
|
+
test("VRadioDescription using slot", () => {
|
|
7
|
+
const wrapper = mount({
|
|
8
|
+
template: `
|
|
9
|
+
<v-radio-group>
|
|
10
|
+
<v-radio-description>John Duck</v-radio-description>
|
|
11
|
+
</v-radio-group>
|
|
12
|
+
`,
|
|
13
|
+
components: {
|
|
14
|
+
"v-radio-description": VRadioDescription,
|
|
15
|
+
"v-radio-group": VRadioGroup,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(wrapper.text()).toContain("John Duck");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("VRadioDescription props", () => {
|
|
23
|
+
test("default 'as' prop", () => {
|
|
24
|
+
const wrapper = mount({
|
|
25
|
+
template: `
|
|
26
|
+
<v-radio-group>
|
|
27
|
+
<v-radio-label data-test="label">John Duck</v-radio-label>
|
|
28
|
+
</v-radio-group>
|
|
29
|
+
`,
|
|
30
|
+
components: {
|
|
31
|
+
"v-radio-label": VRadioDescription,
|
|
32
|
+
"v-radio-group": VRadioGroup,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const label = wrapper.find("[data-test='label']");
|
|
37
|
+
expect(label.element).toBeInstanceOf(HTMLParagraphElement);
|
|
38
|
+
});
|
|
39
|
+
test("custom 'as' prop", () => {
|
|
40
|
+
const wrapper = mount({
|
|
41
|
+
template: `
|
|
42
|
+
<v-radio-group>
|
|
43
|
+
<v-radio-label as="div" data-test="label">John Duck</v-radio-label>
|
|
44
|
+
</v-radio-group>
|
|
45
|
+
`,
|
|
46
|
+
components: {
|
|
47
|
+
"v-radio-label": VRadioDescription,
|
|
48
|
+
"v-radio-group": VRadioGroup,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const label = wrapper.find("[data-test='label']");
|
|
53
|
+
expect(label.element).toBeInstanceOf(HTMLDivElement);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { RadioGroupDescription } from '@headlessui/vue';
|
|
3
|
+
|
|
4
|
+
defineProps({
|
|
5
|
+
as: {
|
|
6
|
+
type: String,
|
|
7
|
+
default: 'p',
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<RadioGroupDescription :as="as"><slot /></RadioGroupDescription>
|
|
14
|
+
</template>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { mount } from "@vue/test-utils";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import VRadioGroup from "./VRadioGroup.vue";
|
|
4
|
+
|
|
5
|
+
test("VRadioGroup using slot", () => {
|
|
6
|
+
const wrapper = mount(VRadioGroup, {
|
|
7
|
+
slots: {
|
|
8
|
+
default: "John Duck",
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
expect(wrapper.text()).toContain("John Duck");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("VRadioGroup default props", () => {
|
|
16
|
+
const wrapper = mount(VRadioGroup);
|
|
17
|
+
const radioGroupEl = wrapper.find("div");
|
|
18
|
+
expect(radioGroupEl.classes()).toEqual([
|
|
19
|
+
"radio-group",
|
|
20
|
+
"inline-flex",
|
|
21
|
+
"gap-1",
|
|
22
|
+
"p-1",
|
|
23
|
+
"bg-surface-200-700-token",
|
|
24
|
+
"text-surface-900",
|
|
25
|
+
"dark:text-surface-50",
|
|
26
|
+
"border-token",
|
|
27
|
+
"border-surface-400-500-token",
|
|
28
|
+
"rounded-container-token",
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const radioGroup = wrapper.find("[data-test='radio-group']");
|
|
32
|
+
expect(radioGroup.element.tagName).toBe("DIV");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("VRadioGroup custom class props", () => {
|
|
36
|
+
const wrapper = mount(VRadioGroup, {
|
|
37
|
+
props: {
|
|
38
|
+
background: "custom-background-class",
|
|
39
|
+
text: "custom-text-class",
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const radioGroupEl = wrapper.find("div");
|
|
43
|
+
expect(radioGroupEl.classes()).toEqual([
|
|
44
|
+
"radio-group",
|
|
45
|
+
"inline-flex",
|
|
46
|
+
"gap-1",
|
|
47
|
+
"p-1",
|
|
48
|
+
"custom-background-class",
|
|
49
|
+
"custom-text-class",
|
|
50
|
+
"border-token",
|
|
51
|
+
"border-surface-400-500-token",
|
|
52
|
+
"rounded-container-token",
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("VRadioGroup custom 'as' prop", () => {
|
|
57
|
+
const wrapper = mount(VRadioGroup, {
|
|
58
|
+
props: {
|
|
59
|
+
as: "span",
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const radioGroup = wrapper.find("[data-test='radio-group']");
|
|
64
|
+
expect(radioGroup.element.tagName).toBe("SPAN");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("VRadioGroup v-model", () => {
|
|
68
|
+
describe("given value changes", () => {
|
|
69
|
+
test("should emit update:modelValue", async () => {
|
|
70
|
+
const wrapper = mount(VRadioGroup, {
|
|
71
|
+
props: {
|
|
72
|
+
modelValue: "John Duck",
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
wrapper.setProps({ modelValue: "Jane Duck" });
|
|
77
|
+
await wrapper.vm.$nextTick();
|
|
78
|
+
expect(wrapper.emitted()['update:modelValue'][0]).toEqual(["Jane Duck"]);
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
})
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { RadioGroup } from "@headlessui/vue";
|
|
3
|
+
import { provide, ref, watch } from "vue";
|
|
4
|
+
|
|
5
|
+
const emit = defineEmits(["update:modelValue"]);
|
|
6
|
+
const props = defineProps({
|
|
7
|
+
as: {
|
|
8
|
+
type: String,
|
|
9
|
+
default: "div",
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
disabled: {
|
|
13
|
+
type: Boolean,
|
|
14
|
+
default: false,
|
|
15
|
+
},
|
|
16
|
+
by: {
|
|
17
|
+
type: [String, Function],
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
modelValue: RadioGroup.props["modelValue"],
|
|
21
|
+
|
|
22
|
+
active: {
|
|
23
|
+
type: String,
|
|
24
|
+
default: "variant-filled",
|
|
25
|
+
},
|
|
26
|
+
hover: {
|
|
27
|
+
type: String,
|
|
28
|
+
default: "hover:variant-ghost",
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
background: {
|
|
32
|
+
type: String,
|
|
33
|
+
default: "bg-surface-200-700-token",
|
|
34
|
+
},
|
|
35
|
+
text: {
|
|
36
|
+
type: String,
|
|
37
|
+
default: "text-surface-900 dark:text-surface-50",
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const parentModelValue = ref(props.modelValue);
|
|
42
|
+
watch(
|
|
43
|
+
() => props.modelValue,
|
|
44
|
+
(newValue) => {
|
|
45
|
+
parentModelValue.value = newValue;
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
watch(
|
|
49
|
+
() => parentModelValue.value,
|
|
50
|
+
(newValue) => {
|
|
51
|
+
emit("update:modelValue", newValue);
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
provide("active", props.active);
|
|
56
|
+
provide("hover", props.hover);
|
|
57
|
+
</script>
|
|
58
|
+
l
|
|
59
|
+
<template>
|
|
60
|
+
<!-- There is some odd behavior with test coverge, v-model must be the last property in this component -->
|
|
61
|
+
<radio-group
|
|
62
|
+
data-test="radio-group"
|
|
63
|
+
:as="as"
|
|
64
|
+
:disabled="disabled"
|
|
65
|
+
:by="by"
|
|
66
|
+
:class="`radio-group inline-flex gap-1 p-1 ${background} ${text} border-token border-surface-400-500-token rounded-container-token`"
|
|
67
|
+
v-model="parentModelValue"
|
|
68
|
+
>
|
|
69
|
+
<slot></slot>
|
|
70
|
+
</radio-group>
|
|
71
|
+
</template>
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { mount } from "@vue/test-utils";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import { ref } from "vue";
|
|
4
|
+
import VRadioGroup from "./VRadioGroup.vue";
|
|
5
|
+
import VRadioItem from "./VRadioItem.vue";
|
|
6
|
+
|
|
7
|
+
test("VRadioItem using slot", () => {
|
|
8
|
+
const wrapper = mount({
|
|
9
|
+
template: `
|
|
10
|
+
<v-radio-group>
|
|
11
|
+
<v-radio-item data-test="item" value="'John Duck'">John Duck</v-radio-item>
|
|
12
|
+
</v-radio-group>
|
|
13
|
+
`,
|
|
14
|
+
components: {
|
|
15
|
+
"v-radio-item": VRadioItem,
|
|
16
|
+
"v-radio-group": VRadioGroup,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const itemEl = wrapper.find("[data-test='item']").element;
|
|
21
|
+
expect(itemEl.textContent).toBe("John Duck");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("VRadioItem slot states", () => {
|
|
25
|
+
describe("given no injected provide", () => {
|
|
26
|
+
test("should have the default active class", () => {
|
|
27
|
+
const wrapper = mount({
|
|
28
|
+
setup() {
|
|
29
|
+
const value = ref("John Duck");
|
|
30
|
+
return { value };
|
|
31
|
+
},
|
|
32
|
+
template: `
|
|
33
|
+
<v-radio-group v-model="value">
|
|
34
|
+
<v-radio-item data-test="item" :value="'John Duck'">John Duck</v-radio-item>
|
|
35
|
+
</v-radio-group>
|
|
36
|
+
`,
|
|
37
|
+
components: {
|
|
38
|
+
"v-radio-item": VRadioItem,
|
|
39
|
+
"v-radio-group": VRadioGroup,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const itemEl = wrapper.find("[data-test='item']").find("span");
|
|
44
|
+
expect(itemEl.element.classList.contains("variant-filled")).toBe(true);
|
|
45
|
+
expect(itemEl.element.classList.contains("hover:variant-ghost")).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("should have the default hover class", () => {
|
|
49
|
+
const wrapper = mount({
|
|
50
|
+
setup() {
|
|
51
|
+
const value = ref("not John Duck");
|
|
52
|
+
return { value };
|
|
53
|
+
},
|
|
54
|
+
template: `
|
|
55
|
+
<v-radio-group v-model="value">
|
|
56
|
+
<v-radio-item data-test="item" :value="'John Duck'">John Duck</v-radio-item>
|
|
57
|
+
</v-radio-group>
|
|
58
|
+
`,
|
|
59
|
+
components: {
|
|
60
|
+
"v-radio-item": VRadioItem,
|
|
61
|
+
"v-radio-group": VRadioGroup,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const itemEl = wrapper.find("[data-test='item']").find("span");
|
|
66
|
+
expect(itemEl.element.classList.contains("variant-filled")).toBe(false);
|
|
67
|
+
expect(itemEl.element.classList.contains("hover:variant-ghost")).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
})
|
|
70
|
+
describe("given v-slot checked is true", () => {
|
|
71
|
+
test("should have the active class", () => {
|
|
72
|
+
const wrapper = mount({
|
|
73
|
+
setup() {
|
|
74
|
+
const value = ref("John Duck");
|
|
75
|
+
return { value };
|
|
76
|
+
},
|
|
77
|
+
template: `
|
|
78
|
+
<v-radio-group hover="custom-hover-class" active="custom-active-class" v-model="value">
|
|
79
|
+
<v-radio-item data-test="item" :value="'John Duck'">John Duck</v-radio-item>
|
|
80
|
+
</v-radio-group>
|
|
81
|
+
`,
|
|
82
|
+
components: {
|
|
83
|
+
"v-radio-item": VRadioItem,
|
|
84
|
+
"v-radio-group": VRadioGroup,
|
|
85
|
+
},
|
|
86
|
+
provide: {
|
|
87
|
+
active: "custom-active-class",
|
|
88
|
+
hover: "custom-hover-class",
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const itemEl = wrapper.find("[data-test='item']").find("span");
|
|
93
|
+
expect(itemEl.element.classList.contains("custom-active-class")).toBe(true);
|
|
94
|
+
expect(itemEl.element.classList.contains("custom-hover-class")).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("given v-slot checked is false", () => {
|
|
99
|
+
test("should have the hover class", () => {
|
|
100
|
+
const wrapper = mount({
|
|
101
|
+
setup() {
|
|
102
|
+
const value = ref("not John Duck");
|
|
103
|
+
return { value };
|
|
104
|
+
},
|
|
105
|
+
template: `
|
|
106
|
+
<v-radio-group hover="custom-hover-class" active="custom-active-class" v-model="value">
|
|
107
|
+
<v-radio-item data-test="item" :value="'John Duck'">John Duck</v-radio-item>
|
|
108
|
+
</v-radio-group>
|
|
109
|
+
`,
|
|
110
|
+
components: {
|
|
111
|
+
"v-radio-item": VRadioItem,
|
|
112
|
+
"v-radio-group": VRadioGroup,
|
|
113
|
+
},
|
|
114
|
+
provide: {
|
|
115
|
+
active: "custom-active-class",
|
|
116
|
+
hover: "custom-hover-class",
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const itemEl = wrapper.find("[data-test='item']").find("span");
|
|
121
|
+
expect(itemEl.element.classList.contains("custom-active-class")).toBe(false);
|
|
122
|
+
expect(itemEl.element.classList.contains("custom-hover-class")).toBe(true);
|
|
123
|
+
});
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
describe("given v-slot disabled is false", () => {
|
|
127
|
+
test("should not have the disabled classes", () => {
|
|
128
|
+
const wrapper = mount({
|
|
129
|
+
setup() {
|
|
130
|
+
const value = ref("John Duck");
|
|
131
|
+
return { value };
|
|
132
|
+
},
|
|
133
|
+
template: `
|
|
134
|
+
<v-radio-group hover="custom-hover-class" active="custom-active-class" v-model="value">
|
|
135
|
+
<v-radio-item data-test="item" :value="'not John Duck'">John Duck</v-radio-item>
|
|
136
|
+
</v-radio-group>
|
|
137
|
+
`,
|
|
138
|
+
components: {
|
|
139
|
+
"v-radio-item": VRadioItem,
|
|
140
|
+
"v-radio-group": VRadioGroup,
|
|
141
|
+
},
|
|
142
|
+
provide: {
|
|
143
|
+
active: "custom-active-class",
|
|
144
|
+
hover: "custom-hover-class",
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const itemEl = wrapper.find("[data-test='item']").find("span");
|
|
149
|
+
expect(itemEl.element.classList.contains("cursor-pointer")).toBe(true);
|
|
150
|
+
expect(itemEl.element.classList.contains("cursor-not-allowed")).toBe(false);
|
|
151
|
+
expect(itemEl.element.classList.contains("opacity-50")).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("given v-slot disabled is true", () => {
|
|
156
|
+
test("should have the disabled classes", () => {
|
|
157
|
+
const wrapper = mount({
|
|
158
|
+
setup() {
|
|
159
|
+
const value = ref("John Duck");
|
|
160
|
+
return { value };
|
|
161
|
+
},
|
|
162
|
+
template: `
|
|
163
|
+
<v-radio-group hover="custom-hover-class" active="custom-active-class" v-model="value">
|
|
164
|
+
<v-radio-item disabled data-test="item" :value="'not John Duck'">John Duck</v-radio-item>
|
|
165
|
+
</v-radio-group>
|
|
166
|
+
`,
|
|
167
|
+
components: {
|
|
168
|
+
"v-radio-item": VRadioItem,
|
|
169
|
+
"v-radio-group": VRadioGroup,
|
|
170
|
+
},
|
|
171
|
+
provide: {
|
|
172
|
+
active: "custom-active-class",
|
|
173
|
+
hover: "custom-hover-class",
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const itemEl = wrapper.find("[data-test='item']").find("span");
|
|
178
|
+
expect(itemEl.element.classList.contains("cursor-pointer")).toBe(false);
|
|
179
|
+
expect(itemEl.element.classList.contains("cursor-not-allowed")).toBe(true);
|
|
180
|
+
expect(itemEl.element.classList.contains("opacity-50")).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { RadioGroupOption } from "@headlessui/vue";
|
|
3
|
+
import { inject } from "vue";
|
|
4
|
+
|
|
5
|
+
defineProps({
|
|
6
|
+
value: {
|
|
7
|
+
type: [String, Number, Boolean, Object],
|
|
8
|
+
required: true,
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const active = (inject("active") as string);
|
|
13
|
+
const hover = (inject("hover") as string);
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<RadioGroupOption v-slot="{ checked, disabled }" :value="value">
|
|
18
|
+
<span
|
|
19
|
+
:class="`radio-item px-4 py-1 text-center text-base rounded-token ${
|
|
20
|
+
checked ? active : hover
|
|
21
|
+
} ${disabled ? 'cursor-not-allowed opacity-50' : 'cursor-pointer'}`"
|
|
22
|
+
>
|
|
23
|
+
<slot />
|
|
24
|
+
</span>
|
|
25
|
+
</RadioGroupOption>
|
|
26
|
+
</template>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { mount } from "@vue/test-utils";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import VRadioGroup from "./VRadioGroup.vue";
|
|
4
|
+
import VRadioLabel from "./VRadioLabel.vue";
|
|
5
|
+
|
|
6
|
+
test("VRadioLabel using slot", () => {
|
|
7
|
+
const wrapper = mount({
|
|
8
|
+
template: `
|
|
9
|
+
<v-radio-group>
|
|
10
|
+
<v-radio-label>John Duck</v-radio-label>
|
|
11
|
+
</v-radio-group>
|
|
12
|
+
`,
|
|
13
|
+
components: {
|
|
14
|
+
"v-radio-label": VRadioLabel,
|
|
15
|
+
"v-radio-group": VRadioGroup,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(wrapper.text()).toContain("John Duck");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("VRadioLabel props", () => {
|
|
23
|
+
test("default 'as' prop", () => {
|
|
24
|
+
const wrapper = mount({
|
|
25
|
+
template: `
|
|
26
|
+
<v-radio-group>
|
|
27
|
+
<v-radio-label data-test="label">John Duck</v-radio-label>
|
|
28
|
+
</v-radio-group>
|
|
29
|
+
`,
|
|
30
|
+
components: {
|
|
31
|
+
"v-radio-label": VRadioLabel,
|
|
32
|
+
"v-radio-group": VRadioGroup,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const label = wrapper.find("[data-test='label']");
|
|
37
|
+
expect(label.element).toBeInstanceOf(HTMLParagraphElement);
|
|
38
|
+
});
|
|
39
|
+
test("custom 'as' prop", () => {
|
|
40
|
+
const wrapper = mount({
|
|
41
|
+
template: `
|
|
42
|
+
<v-radio-group>
|
|
43
|
+
<v-radio-label as="div" data-test="label">John Duck</v-radio-label>
|
|
44
|
+
</v-radio-group>
|
|
45
|
+
`,
|
|
46
|
+
components: {
|
|
47
|
+
"v-radio-label": VRadioLabel,
|
|
48
|
+
"v-radio-group": VRadioGroup,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const label = wrapper.find("[data-test='label']");
|
|
53
|
+
expect(label.element).toBeInstanceOf(HTMLDivElement);
|
|
54
|
+
});
|
|
55
|
+
});
|