@fiscozen/card 0.1.3 → 0.1.5
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 +3 -3
- package/src/FzCard.vue +48 -25
- package/src/__test__/FzCard.test.ts +31 -0
- package/src/types.ts +65 -1
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiscozen/card",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Design System Card component",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [],
|
|
8
8
|
"author": "Cristian Barraco",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@fiscozen/
|
|
11
|
-
"@fiscozen/
|
|
10
|
+
"@fiscozen/button": "^0.1.9",
|
|
11
|
+
"@fiscozen/icons": "^0.1.19"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"tailwindcss": "^3.4.1",
|
package/src/FzCard.vue
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<section :class="[sectionStaticClass, backgroundColor]">
|
|
3
|
-
<header
|
|
3
|
+
<header
|
|
4
|
+
v-if="existHeader"
|
|
5
|
+
:class="[headerContainerComputedClass, borderColor]"
|
|
6
|
+
@click="toggleOpen"
|
|
7
|
+
>
|
|
4
8
|
<div :class="headerStaticClass">
|
|
5
9
|
<div class="flex flex-row gap-12 items-center">
|
|
6
10
|
<h2
|
|
@@ -20,38 +24,50 @@
|
|
|
20
24
|
</div>
|
|
21
25
|
<slot name="header-content"></slot>
|
|
22
26
|
</header>
|
|
23
|
-
<article
|
|
27
|
+
<article
|
|
28
|
+
v-if="isAlive"
|
|
29
|
+
:class="['p-20', contentClass]"
|
|
30
|
+
v-show="showContent"
|
|
31
|
+
>
|
|
24
32
|
<slot></slot>
|
|
25
33
|
</article>
|
|
26
|
-
<footer
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
<footer
|
|
35
|
+
v-if="(slots.footer || atLeastOneButton) && isAlive"
|
|
36
|
+
:class="[footerStaticClass, borderColor]"
|
|
37
|
+
v-show="showContent"
|
|
38
|
+
>
|
|
39
|
+
<slot name="footer">
|
|
40
|
+
<FzIconButton
|
|
41
|
+
v-if="tertiaryAction"
|
|
42
|
+
@click="emit('fztertiary:click')"
|
|
43
|
+
:iconName="tertiaryAction.icon"
|
|
44
|
+
variant="invisible"
|
|
45
|
+
/>
|
|
46
|
+
<FzButton
|
|
47
|
+
v-if="secondaryAction"
|
|
48
|
+
@click="emit('fzsecondary:click')"
|
|
49
|
+
:label="secondaryAction.label"
|
|
50
|
+
variant="secondary"
|
|
51
|
+
/>
|
|
52
|
+
<FzButton
|
|
53
|
+
v-if="primaryAction"
|
|
54
|
+
@click="emit('fzprimary:click')"
|
|
55
|
+
:label="primaryAction.label"
|
|
56
|
+
variant="primary"
|
|
57
|
+
/>
|
|
58
|
+
</slot>
|
|
45
59
|
</footer>
|
|
46
60
|
</section>
|
|
47
61
|
</template>
|
|
48
62
|
|
|
49
63
|
<script setup lang="ts">
|
|
50
64
|
import { computed, onMounted, ref } from "vue";
|
|
51
|
-
import { FzCardProps } from "./types";
|
|
65
|
+
import { FzCardEvents, FzCardProps, FzCardSlots } from "./types";
|
|
52
66
|
import { FzButton, FzIconButton } from "@fiscozen/button";
|
|
53
67
|
|
|
54
68
|
const props = defineProps<FzCardProps>();
|
|
69
|
+
const emit = defineEmits<FzCardEvents>();
|
|
70
|
+
const slots = defineSlots<FzCardSlots>();
|
|
55
71
|
const isOpen = ref(props.defaultExpanded ?? false);
|
|
56
72
|
|
|
57
73
|
const sectionStaticClass =
|
|
@@ -63,6 +79,9 @@ const footerStaticClass =
|
|
|
63
79
|
|
|
64
80
|
const showContent = computed(() => isOpen.value || !props.collapsible);
|
|
65
81
|
const isAlive = computed(() => props.alwaysAlive || showContent.value);
|
|
82
|
+
const existHeader = computed(
|
|
83
|
+
() => props.title || slots["header"] || slots["header-content"],
|
|
84
|
+
);
|
|
66
85
|
const headerContainerComputedClass = computed(() => [
|
|
67
86
|
showContent.value ? "border-b-1" : "border-b-0",
|
|
68
87
|
props.collapsible ? "cursor-pointer" : "",
|
|
@@ -102,8 +121,7 @@ const atLeastOneButton = computed(
|
|
|
102
121
|
);
|
|
103
122
|
|
|
104
123
|
function toggleOpen() {
|
|
105
|
-
if (props.collapsible)
|
|
106
|
-
isOpen.value = !isOpen.value;
|
|
124
|
+
if (props.collapsible) isOpen.value = !isOpen.value;
|
|
107
125
|
}
|
|
108
126
|
|
|
109
127
|
onMounted(() => {
|
|
@@ -117,5 +135,10 @@ onMounted(() => {
|
|
|
117
135
|
);
|
|
118
136
|
});
|
|
119
137
|
|
|
120
|
-
defineExpose({
|
|
138
|
+
defineExpose({
|
|
139
|
+
/**
|
|
140
|
+
* Method to toggle the card open/closed state
|
|
141
|
+
*/
|
|
142
|
+
toggleOpen,
|
|
143
|
+
});
|
|
121
144
|
</script>
|
|
@@ -159,4 +159,35 @@ describe("FzCard", () => {
|
|
|
159
159
|
await wrapper.find("header").find("button").trigger("click");
|
|
160
160
|
expect(wrapper.find("article").exists()).toBeTruthy();
|
|
161
161
|
});
|
|
162
|
+
|
|
163
|
+
it("should hide the header when no title is defined", async () => {
|
|
164
|
+
const wrapper = mount(FzCard, {
|
|
165
|
+
props: {},
|
|
166
|
+
});
|
|
167
|
+
await wrapper.vm.$nextTick();
|
|
168
|
+
|
|
169
|
+
expect(wrapper.find("header").exists()).toBeFalsy();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("should show the header when no title is defined but header slot is", async () => {
|
|
173
|
+
const wrapper = mount(FzCard, {
|
|
174
|
+
slots: {
|
|
175
|
+
header: "<div>Header</div>",
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
await wrapper.vm.$nextTick();
|
|
179
|
+
|
|
180
|
+
expect(wrapper.find("header").exists()).toBeTruthy();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("should show the header when no title is defined but header-content slot is", async () => {
|
|
184
|
+
const wrapper = mount(FzCard, {
|
|
185
|
+
slots: {
|
|
186
|
+
"header-content": "<div>Header</div>",
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
await wrapper.vm.$nextTick();
|
|
190
|
+
|
|
191
|
+
expect(wrapper.find("header").exists()).toBeTruthy();
|
|
192
|
+
});
|
|
162
193
|
});
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
export type FzCardProps = {
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The title of the card
|
|
4
|
+
*/
|
|
5
|
+
title?: string;
|
|
6
|
+
/**
|
|
7
|
+
* The background color of the card
|
|
8
|
+
*/
|
|
3
9
|
color?: FzCardColor;
|
|
10
|
+
/**
|
|
11
|
+
* The primary action button
|
|
12
|
+
*/
|
|
4
13
|
primaryAction?: FzCardButton;
|
|
14
|
+
/**
|
|
15
|
+
* The secondary action button
|
|
16
|
+
*/
|
|
5
17
|
secondaryAction?: FzCardButton;
|
|
18
|
+
/**
|
|
19
|
+
* The tertiary action button
|
|
20
|
+
*/
|
|
6
21
|
tertiaryAction?: FzCardIconButton;
|
|
22
|
+
/**
|
|
23
|
+
* Custom css class to apply to the content
|
|
24
|
+
*/
|
|
7
25
|
contentClass?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the card is collapsible
|
|
28
|
+
*/
|
|
8
29
|
collapsible?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the card is expanded by default (only if collapsible)
|
|
32
|
+
*/
|
|
9
33
|
defaultExpanded?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the card content is always alive (never destroyed) when collapsed
|
|
36
|
+
*/
|
|
10
37
|
alwaysAlive?: boolean;
|
|
11
38
|
};
|
|
12
39
|
|
|
@@ -19,3 +46,40 @@ type FzCardIconButton = {
|
|
|
19
46
|
};
|
|
20
47
|
|
|
21
48
|
export type FzCardColor = "purple" | "orange" | "blue";
|
|
49
|
+
|
|
50
|
+
export interface FzCardEvents {
|
|
51
|
+
/**
|
|
52
|
+
* Event emitted when the primary action is clicked
|
|
53
|
+
* @type {() => void}
|
|
54
|
+
*/
|
|
55
|
+
(event: "fzprimary:click"): void;
|
|
56
|
+
/**
|
|
57
|
+
* Event emitted when the secondary action is clicked
|
|
58
|
+
* @type {() => void}
|
|
59
|
+
*/
|
|
60
|
+
(event: "fzsecondary:click"): void;
|
|
61
|
+
/**
|
|
62
|
+
* Event emitted when the tertiary action is clicked
|
|
63
|
+
* @type {() => void}
|
|
64
|
+
*/
|
|
65
|
+
(event: "fztertiary:click"): void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface FzCardSlots {
|
|
69
|
+
/**
|
|
70
|
+
* Slot for the content of the card
|
|
71
|
+
*/
|
|
72
|
+
default(props: {}): any;
|
|
73
|
+
/**
|
|
74
|
+
* Slot for the header, it will be displayed on the left of the title
|
|
75
|
+
*/
|
|
76
|
+
header(props: {}): any;
|
|
77
|
+
/**
|
|
78
|
+
* Slot for the header content, it will be displayed below the title
|
|
79
|
+
*/
|
|
80
|
+
"header-content"(props: {}): any;
|
|
81
|
+
/**
|
|
82
|
+
* Slot for the footer of the card
|
|
83
|
+
*/
|
|
84
|
+
footer(props: {}): any;
|
|
85
|
+
}
|