Skip to content

Commit a54faeb

Browse files
authored
Merge pull request #91 from laruiss/feat/dsfr-table
Feat/dsfr table
2 parents 11e8436 + 469167d commit a54faeb

File tree

8 files changed

+587
-1
lines changed

8 files changed

+587
-1
lines changed

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const close = () => {
1111
)
1212
}
1313
14+
// eslint-disable-next-line no-unused-vars
1415
const actions = [
1516
{
1617
label: 'Valider',
@@ -28,7 +29,6 @@ const actions = [
2829
onClick: () => { isModalOpen.value = false },
2930
},
3031
]
31-
3232
</script>
3333

3434
<template>

src/assets/variables-dsfr.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494

9595
--block-color-hover: rgba(224, 224, 224, 0.5);
9696
--block-color-active: rgba(194, 194, 194, 0.5);
97+
98+
--bg-success: #00894122;
99+
--bg-error: #e1060022;
100+
--bg-warning: #f902;
101+
--bg-info: #0762c822;
97102
}
98103

99104
:host, :root {
@@ -193,4 +198,9 @@
193198

194199
--color-hover: rgba(71, 71, 255, 0.5);
195200
--color-active: rgba(0, 0, 243, 0.5);
201+
202+
--bg-success: #00eb5e33;
203+
--bg-error: #f333;
204+
--bg-warning: #f903;
205+
--bg-info: #2b8bf733;
196206
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { render } from '@testing-library/vue'
2+
3+
import DsfrTable from './DsfrTable.vue'
4+
import DsfrTag from '../DsfrTag/DsfrTag.vue'
5+
6+
describe('DsfrTable', () => {
7+
it('should render simple table', () => {
8+
// Given
9+
const title = 'Utilisateurs'
10+
const headers = ['Nom', 'Prénom', 'Email', 'Téléphone', 'Portable', 'Statut']
11+
const rows = [
12+
[
13+
'EGAUD',
14+
'Pierre-Louis',
15+
16+
'01 02 03 04 05',
17+
'06 01 02 03 04',
18+
{
19+
component: 'DsfrTag',
20+
label: 'Erreur',
21+
class: 'error',
22+
},
23+
],
24+
[
25+
'DEBROIZE',
26+
'Clément',
27+
28+
'01 02 03 04 05',
29+
'06 01 02 03 04',
30+
{
31+
component: 'DsfrTag',
32+
label: 'Succès',
33+
class: 'success',
34+
},
35+
],
36+
[
37+
'ORMIERES',
38+
'Stan',
39+
40+
'01 02 03 04 05',
41+
'06 01 02 03 04',
42+
{
43+
component: 'DsfrTag',
44+
label: 'Info',
45+
class: 'info',
46+
},
47+
],
48+
]
49+
50+
// When
51+
const { container } = render(DsfrTable, {
52+
global: {
53+
components: {
54+
DsfrTag,
55+
},
56+
},
57+
props: {
58+
title,
59+
headers,
60+
rows,
61+
},
62+
})
63+
64+
const trs = container.querySelectorAll('tr')
65+
const successEl = container.querySelectorAll('.success')
66+
const errorEl = container.querySelectorAll('.error')
67+
const infoEl = container.querySelectorAll('.info')
68+
69+
// Then
70+
expect(trs).toHaveLength(4)
71+
expect(successEl).toHaveLength(1)
72+
expect(errorEl).toHaveLength(1)
73+
expect(infoEl).toHaveLength(1)
74+
})
75+
})
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import DsfrTable from './DsfrTable.vue'
2+
import DsfrTag from '../DsfrTag/DsfrTag.vue'
3+
4+
import { app } from '@storybook/vue3'
5+
6+
app.component('DsfrTag', DsfrTag)
7+
8+
export default {
9+
components: DsfrTable,
10+
title: 'Éléments/Table',
11+
argTypes: {
12+
title: { control: 'text' },
13+
dark: {
14+
control: 'boolean',
15+
description: 'Permet de voir le composant dans les deux **thèmes** : **clair** (`false`, défaut) et **sombre* (`true`).\n\n*N.B. : Ne fait pas partie du composant.*',
16+
},
17+
headers: {
18+
control: 'object',
19+
description: 'Permet de voir la ligne des titres des colonnes du tableau',
20+
},
21+
rows: {
22+
control: 'object',
23+
description: 'Permet de voir les lignes du tableau, on peut afficher un composant ou un texte simple',
24+
},
25+
},
26+
}
27+
28+
const title = 'Utilisateurs'
29+
const headers = ['Nom', 'Prénom', 'Email', 'Téléphone', 'Portable', 'Statut']
30+
const rows = [
31+
[
32+
'EGAUD',
33+
'Pierre-Louis',
34+
35+
'01 02 03 04 05',
36+
'06 01 02 03 04',
37+
{
38+
component: 'DsfrTag',
39+
label: 'Erreur',
40+
class: 'error',
41+
},
42+
],
43+
[
44+
'DEBROIZE',
45+
'Clément',
46+
47+
'01 02 03 04 05',
48+
'06 01 02 03 04',
49+
{
50+
component: 'DsfrTag',
51+
label: 'Succès',
52+
class: 'success',
53+
},
54+
],
55+
[
56+
'ORMIERES',
57+
'Stan',
58+
59+
'01 02 03 04 05',
60+
'06 01 02 03 04',
61+
{
62+
component: 'DsfrTag',
63+
label: 'Info',
64+
class: 'info',
65+
},
66+
],
67+
]
68+
69+
export const TableauSimple = (args) => ({
70+
components: {
71+
DsfrTable,
72+
},
73+
74+
data () {
75+
return {
76+
...args,
77+
}
78+
},
79+
80+
template: `
81+
<div :data-rf-theme="dark ? 'dark' : ''" style="background-color: var(--w); padding: 1rem;">
82+
<DsfrTable
83+
:title="title"
84+
:headers="headers"
85+
:rows="rows"
86+
/>
87+
</div>
88+
`,
89+
90+
})
91+
TableauSimple.args = {
92+
dark: false,
93+
title: title,
94+
headers: headers,
95+
rows: rows,
96+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<template>
2+
<div class="fr-table">
3+
<table class="simple-table">
4+
<caption class="caption">
5+
{{ title }}
6+
</caption>
7+
<thead>
8+
<tr
9+
class="header"
10+
>
11+
<th
12+
v-for="header in headers"
13+
:key="header"
14+
>
15+
{{ header }}
16+
</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr
21+
v-for="(row, i) in rows"
22+
:key="i"
23+
class="body-row"
24+
>
25+
<DsfrTableCell
26+
v-for="(field, j) in row"
27+
:key="`${i}-${j}`"
28+
:field="field"
29+
/>
30+
</tr>
31+
</tbody>
32+
</table>
33+
</div>
34+
</template>
35+
36+
<script>
37+
import { defineComponent } from 'vue'
38+
39+
import DsfrTableCell from './DsfrTableCell.vue'
40+
41+
export default defineComponent({
42+
name: 'DsfrTable',
43+
44+
components: {
45+
DsfrTableCell,
46+
},
47+
48+
props: {
49+
title: {
50+
type: String,
51+
default: undefined,
52+
},
53+
headers: {
54+
type: Array,
55+
default: () => [],
56+
},
57+
rows: {
58+
type: Array,
59+
default: () => [],
60+
},
61+
},
62+
63+
})
64+
</script>
65+
66+
<style src="./table.css" />
67+
68+
<style scoped>
69+
.fr-table td {
70+
color: var(--g800);
71+
}
72+
</style>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<script>
2+
import { defineComponent } from 'vue'
3+
4+
export default defineComponent({
5+
name: 'DsfrTableCell',
6+
7+
props: {
8+
field: {
9+
type: [String, Object],
10+
default: undefined,
11+
},
12+
},
13+
14+
computed: {
15+
isObject () {
16+
return typeof this.field === 'object'
17+
},
18+
isComponent () {
19+
return this.isObject ? this.field.component : false
20+
},
21+
classField () {
22+
return {
23+
label: typeof this.field === 'object',
24+
[this.field.color]: true,
25+
}
26+
},
27+
},
28+
})
29+
</script>
30+
31+
<template>
32+
<td>
33+
<component
34+
:is="isComponent"
35+
v-if="isComponent"
36+
v-bind="field"
37+
/>
38+
<span v-else>
39+
{{ field }}
40+
</span>
41+
</td>
42+
</template>
43+
44+
<style scoped>
45+
.label {
46+
display: inline-block;
47+
width: 7rem;
48+
text-align: center;
49+
border-radius: 2rem;
50+
}
51+
.success {
52+
color: var(--success);
53+
background-color: var(--bg-success);
54+
}
55+
.error {
56+
color: var(--error);
57+
background-color: var(--bg-error);
58+
}
59+
.warning {
60+
color: var(--warning);
61+
background-color: var(--bg-warning);
62+
}
63+
.info {
64+
color: var(--info);
65+
background-color: var(--bg-info);
66+
}
67+
</style>

0 commit comments

Comments
 (0)