@code-coaching/vuetiful 0.20.0 → 0.21.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-coaching/vuetiful",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "onchange 'src/**/*.vue' 'src/**/*.ts' 'src/**/*.css' -- npm run build",
@@ -0,0 +1,47 @@
1
+ import { mount } from "@vue/test-utils";
2
+ import { describe, expect, test } from "vitest";
3
+ import { VCard } from "..";
4
+
5
+ describe("VCard", () => {
6
+ test("defaults", async () => {
7
+ const wrapper = mount(VCard);
8
+ expect(wrapper.props()).toEqual({
9
+ background: "bg-surface-200-700-token",
10
+ clickable: false,
11
+ hideSeparator: false,
12
+ horizontal: false,
13
+ text: "text-surface-900-50-token",
14
+ });
15
+ });
16
+
17
+ describe("given the card is clicked", () => {
18
+ describe("given the card is not clickable", () => {
19
+ test("should not emit click", async () => {
20
+ const wrapper = mount(VCard, { props: { clickable: false } });
21
+ expect(wrapper.attributes()['tabindex']).toBeUndefined();
22
+ await wrapper.trigger("click");
23
+ expect(wrapper.emitted()["click"]).toBeUndefined();
24
+
25
+ await wrapper.trigger("keydown", { key: "Enter" });
26
+ expect(wrapper.emitted()["click"]).toBeUndefined();
27
+
28
+ await wrapper.trigger("keydown", { key: " " });
29
+ expect(wrapper.emitted()["click"]).toBeUndefined();
30
+ });
31
+ });
32
+ describe("given the card is clickable", () => {
33
+ test("should emit click", async () => {
34
+ const wrapper = mount(VCard, { props: { clickable: true } });
35
+ expect(wrapper.attributes()['tabindex']).toEqual("0");
36
+ await wrapper.trigger("click");
37
+ expect(wrapper.emitted()["click"].length).toEqual(1);
38
+
39
+ await wrapper.trigger("keydown", { key: "Enter" });
40
+ expect(wrapper.emitted()["click"].length).toEqual(2);
41
+
42
+ await wrapper.trigger("keydown", { key: " " });
43
+ expect(wrapper.emitted()["click"].length).toEqual(3);
44
+ });
45
+ });
46
+ });
47
+ });
@@ -0,0 +1,71 @@
1
+ <script setup lang="ts">
2
+ import { provide } from "vue";
3
+
4
+ const emit = defineEmits(["click"]);
5
+
6
+ const props = defineProps({
7
+ hideSeparator: {
8
+ type: Boolean,
9
+ default: false,
10
+ },
11
+ background: {
12
+ type: String,
13
+ default: "bg-surface-200-700-token",
14
+ },
15
+ text: {
16
+ type: String,
17
+ default: "text-surface-900-50-token",
18
+ },
19
+ horizontal: {
20
+ type: Boolean,
21
+ default: false,
22
+ },
23
+ clickable: {
24
+ type: Boolean,
25
+ default: false,
26
+ },
27
+ });
28
+
29
+ provide("hideSeparator", props.hideSeparator);
30
+
31
+ const onClick = () => {
32
+ if (!props.clickable) return;
33
+ emit("click");
34
+ };
35
+ const onKeydown = (event: KeyboardEvent) => {
36
+ if (!props.clickable) return;
37
+ if (event.key === "Enter") {
38
+ event.preventDefault();
39
+ emit("click");
40
+ }
41
+ if (event.key === " ") {
42
+ event.preventDefault();
43
+ emit("click");
44
+ }
45
+ };
46
+ </script>
47
+
48
+ <template>
49
+ <div
50
+ @click="onClick"
51
+ @keydown="onKeydown"
52
+ :tabindex="clickable ? 0 : undefined"
53
+ :class="`vuetiful-card flex border-token rounded-container-token ring-outline-token ${
54
+ horizontal ? 'flex-row' : 'flex-col'
55
+ } ${background} ${text} ${clickable ? 'card-hover hover:cursor-pointer' : ''}`"
56
+ >
57
+ <slot />
58
+ </div>
59
+ </template>
60
+
61
+ <style>
62
+ .vuetiful-card-header {
63
+ border-top-left-radius: inherit;
64
+ border-top-right-radius: inherit;
65
+ }
66
+
67
+ .vuetiful-card-header > * {
68
+ border-top-left-radius: inherit;
69
+ border-top-right-radius: inherit;
70
+ }
71
+ </style>
@@ -0,0 +1,21 @@
1
+ import { mount } from "@vue/test-utils";
2
+ import { describe, expect, test } from "vitest";
3
+ import { VCard, VCardBody } from "..";
4
+
5
+ describe("VCardBody", () => {
6
+ test("defaults", async () => {
7
+ const wrapper = mount({
8
+ template: /*html*/ `
9
+ <v-card>
10
+ <v-card-body>John Duck</v-card-body>
11
+ </v-card>
12
+ `,
13
+ components: {
14
+ "v-card": VCard,
15
+ "v-card-body": VCardBody,
16
+ },
17
+ });
18
+
19
+ expect(wrapper.text()).toEqual("John Duck");
20
+ });
21
+ });
@@ -0,0 +1,5 @@
1
+ <template>
2
+ <div data-test="vuetiful-card-body-content" class="vuetiful-card-body p-4">
3
+ <slot />
4
+ </div>
5
+ </template>
@@ -0,0 +1,45 @@
1
+ import { mount } from "@vue/test-utils";
2
+ import { describe, expect, test } from "vitest";
3
+ import { VCard, VCardFooter } from "..";
4
+
5
+ describe("VCardFooter", () => {
6
+ test("defaults", async () => {
7
+ const wrapper = mount({
8
+ template: /*html*/ `
9
+ <v-card>
10
+ <v-card-footer>John Duck</v-card-footer>
11
+ </v-card>
12
+ `,
13
+ components: {
14
+ "v-card": VCard,
15
+ "v-card-footer": VCardFooter,
16
+ },
17
+ });
18
+
19
+ const separator = wrapper.find("[data-test='vuetiful-card-footer-separator']");
20
+ const content = wrapper.find("[data-test='vuetiful-card-footer-content']");
21
+ expect(separator.element.tagName).toEqual("HR");
22
+ expect(content.text()).toEqual("John Duck");
23
+ });
24
+
25
+ describe("given hideSeparator is true", () => {
26
+ test("should not show separator", async () => {
27
+ const wrapper = mount({
28
+ template: /*html*/ `
29
+ <v-card hide-separator>
30
+ <v-card-footer>John Duck</v-card-footer>
31
+ </v-card>
32
+ `,
33
+ components: {
34
+ "v-card": VCard,
35
+ "v-card-footer": VCardFooter,
36
+ },
37
+ });
38
+
39
+ const separator = wrapper.find("[data-test='vuetiful-card-footer-separator']");
40
+ const content = wrapper.find("[data-test='vuetiful-card-footer-content']");
41
+ expect(separator.exists()).toEqual(false);
42
+ expect(content.text()).toEqual("John Duck");
43
+ })
44
+ })
45
+ });
@@ -0,0 +1,11 @@
1
+ <script setup lang="ts">
2
+ import { inject } from "vue";
3
+ const hideSeparator = inject("hideSeparator", false);
4
+ </script>
5
+
6
+ <template>
7
+ <hr v-if="!hideSeparator" data-test="vuetiful-card-footer-separator" class="opacity-90" />
8
+ <div data-test="vuetiful-card-footer-content" class="vuetiful-card-footer p-4">
9
+ <slot />
10
+ </div>
11
+ </template>
@@ -0,0 +1,68 @@
1
+ import { mount } from "@vue/test-utils";
2
+ import { describe, expect, test } from "vitest";
3
+ import { VCard, VCardHeader } from "..";
4
+
5
+ describe("VCardHeader", () => {
6
+ test("defaults", async () => {
7
+ const wrapper = mount({
8
+ template: /*html*/ `
9
+ <v-card>
10
+ <v-card-header>John Duck</v-card-header>
11
+ </v-card>
12
+ `,
13
+ components: {
14
+ "v-card": VCard,
15
+ "v-card-header": VCardHeader,
16
+ },
17
+ });
18
+
19
+ const separator = wrapper.find("[data-test='vuetiful-card-header-separator']");
20
+ const content = wrapper.find("[data-test='vuetiful-card-header-content']");
21
+ expect(separator.element.tagName).toEqual("HR");
22
+ expect(content.text()).toEqual("John Duck");
23
+ expect(content.classes()).toContain("p-4");
24
+ });
25
+
26
+ describe("given hideSeparator is true", () => {
27
+ test("should not show separator", async () => {
28
+ const wrapper = mount({
29
+ template: /*html*/ `
30
+ <v-card hide-separator>
31
+ <v-card-header>John Duck</v-card-header>
32
+ </v-card>
33
+ `,
34
+ components: {
35
+ "v-card": VCard,
36
+ "v-card-header": VCardHeader,
37
+ },
38
+ });
39
+
40
+ const separator = wrapper.find("[data-test='vuetiful-card-header-separator']");
41
+ const content = wrapper.find("[data-test='vuetiful-card-header-content']");
42
+ expect(separator.exists()).toEqual(false);
43
+ expect(content.text()).toEqual("John Duck");
44
+ });
45
+ });
46
+
47
+ describe("given an image is present", () => {
48
+ test("should not have padding", async () => {
49
+ const wrapper = mount({
50
+ template: /*html*/ `
51
+ <v-card>
52
+ <v-card-header>
53
+ <img src="fakeUrl" />
54
+ </v-card-header>
55
+ </v-card>
56
+ `,
57
+ components: {
58
+ "v-card": VCard,
59
+ "v-card-header": VCardHeader,
60
+ },
61
+ });
62
+ await wrapper.vm.$nextTick();
63
+
64
+ const content = wrapper.find("[data-test='vuetiful-card-header-content']");
65
+ expect(content.classes()).not.toContain("p-4");
66
+ });
67
+ });
68
+ });
@@ -0,0 +1,33 @@
1
+ <script setup lang="ts">
2
+ import { Ref, computed, inject, ref } from 'vue';
3
+
4
+ const headerRef = ref() as Ref<HTMLDivElement>;
5
+
6
+ const hasImageAsChild = computed(() => {
7
+ const children = headerRef.value?.children;
8
+ if (!children) return false;
9
+ const childrenArray = Array.from(children);
10
+ return childrenArray.some((child) => child.tagName === 'IMG');
11
+ });
12
+
13
+ const hideSeparator = inject('hideSeparator', false);
14
+ </script>
15
+
16
+ <template>
17
+ <div ref="headerRef" data-test='vuetiful-card-header-content' :class="`vuetiful-card-header ${hasImageAsChild ? '' : 'p-4'}`">
18
+ <slot />
19
+ </div>
20
+ <hr v-if="!hideSeparator" data-test='vuetiful-card-header-separator' class="opacity-90" />
21
+ </template>
22
+
23
+ <style>
24
+ .vuetiful-card-header {
25
+ border-top-left-radius: inherit;
26
+ border-top-right-radius: inherit;
27
+ }
28
+
29
+ .vuetiful-card-header > * {
30
+ border-top-left-radius: inherit;
31
+ border-top-right-radius: inherit;
32
+ }
33
+ </style>
@@ -19,10 +19,19 @@ import VAccordionItem from "./VAccordion/VAccordionItem.vue";
19
19
 
20
20
  import VAlert from "./VAlert.vue";
21
21
 
22
+ import VCard from "./VCard/VCard.vue";
23
+ import VCardBody from "./VCard/VCardBody.vue";
24
+ import VCardFooter from "./VCard/VCardFooter.vue";
25
+ import VCardHeader from "./VCard/VCardHeader.vue";
26
+
22
27
  export {
23
28
  VAccordion,
24
29
  VAccordionItem,
25
30
  VAlert,
31
+ VCard,
32
+ VCardBody,
33
+ VCardFooter,
34
+ VCardHeader,
26
35
  VDrawer,
27
36
  VListbox,
28
37
  VListboxButton,