@cnamts/synapse 0.0.15-alpha → 0.0.16-alpha
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/components/CookiesSelection/CookiesSelection.d.ts +26 -26
- package/dist/components/Customs/SyTextField/SyTextField.d.ts +1391 -1
- package/dist/components/DatePicker/DatePicker.d.ts +2810 -16
- package/dist/components/DatePicker/DateTextInput.d.ts +1401 -4
- package/dist/components/LangBtn/LangBtn.d.ts +4 -4
- package/dist/components/NirField/NirField.d.ts +2794 -4
- package/dist/components/PeriodField/PeriodField.d.ts +5636 -48
- package/dist/components/SyAlert/SyAlert.d.ts +72 -1
- package/dist/components/UploadWorkflow/UploadWorkflow.d.ts +26 -26
- package/dist/components/index.d.ts +1 -0
- package/dist/composables/date/useDateFormat.d.ts +2 -2
- package/dist/composables/date/useDateFormatDayjs.d.ts +23 -0
- package/dist/composables/date/useDateInitializationDayjs.d.ts +18 -0
- package/dist/design-system-v3.js +3953 -3728
- package/dist/design-system-v3.umd.cjs +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/Customs/SyTextField/Accessibilite.stories.ts +7 -0
- package/src/components/Customs/SyTextField/SyTextField.stories.ts +13 -0
- package/src/components/Customs/SyTextField/SyTextField.vue +82 -17
- package/src/components/DatePicker/ComplexDatePicker/ComplexDatePicker.vue +795 -0
- package/src/components/DatePicker/DatePicker.stories.ts +432 -1
- package/src/components/DatePicker/DatePicker.vue +66 -24
- package/src/components/DatePicker/DatePickerValidation.stories.ts +9 -1
- package/src/components/DatePicker/DateTextInput.vue +85 -133
- package/src/components/DatePicker/docExamples/DatePickerBidirectionalValidation.vue +282 -0
- package/src/components/DatePicker/tests/DatePicker.spec.ts +33 -32
- package/src/components/DatePicker/tests/DateTextInput.spec.ts +81 -33
- package/src/components/SyAlert/Accessibilite.stories.ts +4 -0
- package/src/components/SyAlert/SyAlert.mdx +3 -7
- package/src/components/SyAlert/SyAlert.stories.ts +19 -12
- package/src/components/SyAlert/SyAlert.vue +88 -51
- package/src/components/SyAlert/tests/SyAlert.spec.ts +20 -2
- package/src/components/SyAlert/tests/__snapshots__/SyAlert.spec.ts.snap +83 -75
- package/src/components/index.ts +1 -0
- package/src/composables/date/useDateFormat.ts +17 -1
- package/src/composables/date/useDateFormatDayjs.ts +84 -0
- package/src/composables/date/useDateInitializationDayjs.ts +133 -0
- package/src/stories/Accessibilite/Avancement/Avancement.mdx +12 -0
- package/src/stories/Accessibilite/Avancement/Avancement.stories.ts +134 -0
- /package/src/components/DatePicker/{DatePickerValidationExamples.vue → docExamples/DatePickerValidationExamples.vue} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed } from 'vue'
|
|
2
|
+
import { computed, ref, onMounted, useAttrs } from 'vue'
|
|
3
3
|
import { locales } from './locales'
|
|
4
4
|
import {
|
|
5
5
|
mdiAlertOutline,
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
mdiInformationOutline,
|
|
9
9
|
mdiClose,
|
|
10
10
|
} from '@mdi/js'
|
|
11
|
+
import type { VIcon } from 'vuetify/components'
|
|
11
12
|
|
|
12
13
|
const show = defineModel<boolean>({
|
|
13
14
|
default: true,
|
|
@@ -23,6 +24,8 @@
|
|
|
23
24
|
variant: 'tonal',
|
|
24
25
|
})
|
|
25
26
|
|
|
27
|
+
const attrs = useAttrs()
|
|
28
|
+
|
|
26
29
|
const prependIcon = computed(() => {
|
|
27
30
|
return {
|
|
28
31
|
info: mdiInformationOutline,
|
|
@@ -43,58 +46,71 @@
|
|
|
43
46
|
prependIcon,
|
|
44
47
|
dismissAlert,
|
|
45
48
|
})
|
|
49
|
+
|
|
50
|
+
const alertIcon = ref<typeof VIcon | null>(null)
|
|
51
|
+
onMounted(() => {
|
|
52
|
+
alertIcon.value?.$el?.querySelector('svg')?.setAttribute('role', 'presentation')
|
|
53
|
+
})
|
|
46
54
|
</script>
|
|
47
55
|
|
|
48
56
|
<template>
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
:closable="props.closable"
|
|
53
|
-
:variant="props.variant"
|
|
54
|
-
:class="`alert alert--${props.type}`"
|
|
55
|
-
:color="props.type"
|
|
56
|
-
:border="props.variant === 'tonal' ? 'start' : false"
|
|
57
|
+
<div
|
|
58
|
+
class="sy-alert"
|
|
59
|
+
role="alert"
|
|
57
60
|
>
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
</template>
|
|
68
|
-
|
|
69
|
-
<template #default>
|
|
70
|
-
<slot />
|
|
71
|
-
</template>
|
|
72
|
-
|
|
73
|
-
<template
|
|
74
|
-
v-if="props.closable"
|
|
75
|
-
#close
|
|
61
|
+
<VAlert
|
|
62
|
+
v-model="show"
|
|
63
|
+
v-bind="attrs"
|
|
64
|
+
:type="props.type"
|
|
65
|
+
:closable="props.closable"
|
|
66
|
+
:variant="props.variant"
|
|
67
|
+
:class="`alert alert--${props.type}`"
|
|
68
|
+
:color="props.type"
|
|
69
|
+
:border="props.variant === 'tonal' ? 'start' : false"
|
|
76
70
|
>
|
|
77
|
-
<
|
|
78
|
-
:color="props.variant === 'outlined' ? undefined : 'primary'"
|
|
79
|
-
:ripple="false"
|
|
80
|
-
variant="text"
|
|
81
|
-
width="auto"
|
|
82
|
-
height="100%"
|
|
83
|
-
class="alert-close-btn"
|
|
84
|
-
@click="dismissAlert"
|
|
85
|
-
>
|
|
71
|
+
<template #prepend>
|
|
86
72
|
<VIcon
|
|
87
|
-
|
|
73
|
+
ref="alertIcon"
|
|
74
|
+
class="alert-icon"
|
|
75
|
+
size="1.5rem"
|
|
76
|
+
role="presentation"
|
|
88
77
|
>
|
|
89
|
-
|
|
78
|
+
<slot name="icon">
|
|
79
|
+
{{ prependIcon }}
|
|
80
|
+
</slot>
|
|
90
81
|
</VIcon>
|
|
82
|
+
</template>
|
|
83
|
+
|
|
84
|
+
<template #default>
|
|
85
|
+
<slot />
|
|
86
|
+
</template>
|
|
91
87
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
88
|
+
<template
|
|
89
|
+
v-if="props.closable"
|
|
90
|
+
#close
|
|
91
|
+
>
|
|
92
|
+
<VBtn
|
|
93
|
+
:color="props.variant === 'outlined' ? undefined : 'primary'"
|
|
94
|
+
:ripple="false"
|
|
95
|
+
variant="text"
|
|
96
|
+
width="auto"
|
|
97
|
+
height="100%"
|
|
98
|
+
class="alert-close-btn"
|
|
99
|
+
@click="dismissAlert"
|
|
100
|
+
>
|
|
101
|
+
<VIcon
|
|
102
|
+
size="small"
|
|
103
|
+
>
|
|
104
|
+
{{ mdiClose }}
|
|
105
|
+
</VIcon>
|
|
106
|
+
|
|
107
|
+
<span>
|
|
108
|
+
{{ locales.close }}
|
|
109
|
+
</span>
|
|
110
|
+
</VBtn>
|
|
111
|
+
</template>
|
|
112
|
+
</VAlert>
|
|
113
|
+
</div>
|
|
98
114
|
</template>
|
|
99
115
|
|
|
100
116
|
<style lang="scss" scoped>
|
|
@@ -128,17 +144,24 @@
|
|
|
128
144
|
.alert-close-btn {
|
|
129
145
|
cursor: pointer;
|
|
130
146
|
line-height: 0;
|
|
131
|
-
|
|
132
|
-
.v-btn__overlay {
|
|
133
|
-
display: none;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
.v-btn {
|
|
138
147
|
text-transform: none;
|
|
139
148
|
font-weight: bold;
|
|
140
149
|
font-size: 0.75rem;
|
|
141
150
|
letter-spacing: normal;
|
|
151
|
+
|
|
152
|
+
&:focus-visible {
|
|
153
|
+
outline: solid 2px black !important;
|
|
154
|
+
outline-color: var(--v-primary-base) !important;
|
|
155
|
+
outline-offset: 2px !important;
|
|
156
|
+
|
|
157
|
+
&::after {
|
|
158
|
+
visibility: hidden;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.v-btn__overlay {
|
|
163
|
+
display: none;
|
|
164
|
+
}
|
|
142
165
|
}
|
|
143
166
|
|
|
144
167
|
@media screen and (width <= 440px) {
|
|
@@ -254,4 +277,18 @@
|
|
|
254
277
|
)
|
|
255
278
|
);
|
|
256
279
|
}
|
|
280
|
+
|
|
281
|
+
.v-alert.v-theme--dark {
|
|
282
|
+
&.v-alert--variant-outlined {
|
|
283
|
+
background-color: tokens.$white-base !important;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.alert-close-btn {
|
|
287
|
+
color: black !important;
|
|
288
|
+
|
|
289
|
+
&:focus-visible {
|
|
290
|
+
outline-color: black !important;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
257
294
|
</style>
|
|
@@ -46,7 +46,16 @@ describe('Alert', () => {
|
|
|
46
46
|
modelValue: false,
|
|
47
47
|
})
|
|
48
48
|
|
|
49
|
-
expect(wrapper.html()).
|
|
49
|
+
expect(wrapper.html()).toMatchInlineSnapshot(`
|
|
50
|
+
<div
|
|
51
|
+
class="sy-alert"
|
|
52
|
+
message="message"
|
|
53
|
+
role="alert"
|
|
54
|
+
title="title"
|
|
55
|
+
>
|
|
56
|
+
<!---->
|
|
57
|
+
</div>
|
|
58
|
+
`)
|
|
50
59
|
|
|
51
60
|
await wrapper.setProps({
|
|
52
61
|
modelValue: true,
|
|
@@ -79,7 +88,16 @@ describe('Alert', () => {
|
|
|
79
88
|
|
|
80
89
|
await closeBtn.element.click()
|
|
81
90
|
|
|
82
|
-
expect(wrapper.html()).
|
|
91
|
+
expect(wrapper.html()).toMatchInlineSnapshot(`
|
|
92
|
+
<div
|
|
93
|
+
class="sy-alert"
|
|
94
|
+
message="message"
|
|
95
|
+
role="alert"
|
|
96
|
+
title="title"
|
|
97
|
+
>
|
|
98
|
+
<!---->
|
|
99
|
+
</div>
|
|
100
|
+
`)
|
|
83
101
|
expect(wrapper.emitted('update:modelValue')![0]![0]).toBe(false)
|
|
84
102
|
})
|
|
85
103
|
|
|
@@ -2,86 +2,94 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`Alert > render correctly 1`] = `
|
|
4
4
|
<div
|
|
5
|
-
class="
|
|
6
|
-
alert
|
|
7
|
-
alert--success
|
|
8
|
-
text-success
|
|
9
|
-
v-alert
|
|
10
|
-
v-alert--border
|
|
11
|
-
v-alert--border-start
|
|
12
|
-
v-alert--density-default
|
|
13
|
-
v-alert--variant-tonal
|
|
14
|
-
v-theme--light
|
|
15
|
-
"
|
|
5
|
+
class="sy-alert"
|
|
16
6
|
message="message"
|
|
17
7
|
role="alert"
|
|
8
|
+
title="title"
|
|
18
9
|
>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
10
|
+
<div
|
|
11
|
+
class="
|
|
12
|
+
alert
|
|
13
|
+
alert--success
|
|
14
|
+
text-success
|
|
15
|
+
v-alert
|
|
16
|
+
v-alert--border
|
|
17
|
+
v-alert--border-start
|
|
18
|
+
v-alert--density-default
|
|
19
|
+
v-alert--variant-tonal
|
|
20
|
+
v-theme--light
|
|
21
|
+
"
|
|
22
|
+
message="message"
|
|
23
|
+
role="alert"
|
|
24
|
+
>
|
|
25
|
+
<!---->
|
|
26
|
+
<span class="v-alert__underlay"></span>
|
|
27
|
+
<div class="v-alert__border"></div>
|
|
28
|
+
<div class="v-alert__prepend">
|
|
29
|
+
<i
|
|
30
|
+
aria-hidden="true"
|
|
31
|
+
class="
|
|
32
|
+
11.59L6
|
|
33
|
+
12
|
|
34
|
+
12
|
|
35
|
+
12
|
|
36
|
+
12
|
|
37
|
+
12
|
|
38
|
+
12
|
|
39
|
+
12S6.5
|
|
40
|
+
12S7.59
|
|
41
|
+
13L10
|
|
42
|
+
14.17L7.41
|
|
43
|
+
16.41
|
|
44
|
+
16.41
|
|
45
|
+
17.5
|
|
46
|
+
17.5
|
|
47
|
+
17L18
|
|
48
|
+
2
|
|
49
|
+
2
|
|
50
|
+
2
|
|
51
|
+
2
|
|
52
|
+
20
|
|
53
|
+
20
|
|
54
|
+
20
|
|
55
|
+
20
|
|
56
|
+
20C7.59
|
|
57
|
+
20M16.59
|
|
58
|
+
22
|
|
59
|
+
22
|
|
60
|
+
22
|
|
61
|
+
22
|
|
62
|
+
2C6.5
|
|
63
|
+
2M12
|
|
64
|
+
4
|
|
65
|
+
4
|
|
66
|
+
4
|
|
67
|
+
4
|
|
68
|
+
6.5
|
|
69
|
+
7.58L10
|
|
70
|
+
7.58Z
|
|
71
|
+
7.59
|
|
72
|
+
9L16.59
|
|
73
|
+
M12
|
|
74
|
+
alert-icon
|
|
75
|
+
mdi
|
|
76
|
+
notranslate
|
|
77
|
+
v-icon
|
|
78
|
+
v-theme--light
|
|
79
|
+
"
|
|
80
|
+
role="presentation"
|
|
81
|
+
style="font-size: 1.5rem; height: 1.5rem; width: 1.5rem;"
|
|
82
|
+
></i>
|
|
80
83
|
</div>
|
|
84
|
+
<div class="v-alert__content">
|
|
85
|
+
<div class="v-alert-title">
|
|
86
|
+
title
|
|
87
|
+
</div>
|
|
88
|
+
<!---->
|
|
89
|
+
slot content
|
|
90
|
+
</div>
|
|
91
|
+
<!---->
|
|
81
92
|
<!---->
|
|
82
|
-
slot content
|
|
83
93
|
</div>
|
|
84
|
-
<!---->
|
|
85
|
-
<!---->
|
|
86
94
|
</div>
|
|
87
95
|
`;
|
package/src/components/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { useFieldValidation } from '../composables/rules/useFieldValidation'
|
|
|
3
3
|
export type { RuleOptions } from '../composables/rules/useFieldValidation'
|
|
4
4
|
export { useNotificationService } from '../services/NotificationService'
|
|
5
5
|
export { useValidation } from '../composables/validation/useValidation'
|
|
6
|
+
export { useDateFormat } from '../composables/date/useDateFormatDayjs'
|
|
6
7
|
export { default as BackBtn } from './BackBtn/BackBtn.vue'
|
|
7
8
|
export { default as BackToTopBtn } from './BackToTopBtn/BackToTopBtn.vue'
|
|
8
9
|
export { default as ChipList } from './ChipList/ChipList.vue'
|
|
@@ -8,9 +8,25 @@
|
|
|
8
8
|
* @param format - Le format de la date (ex: 'DD/MM/YYYY')
|
|
9
9
|
* @returns Un objet Date ou null si la chaîne n'est pas valide
|
|
10
10
|
*/
|
|
11
|
-
export const parseDate = (dateString: string, format: string): Date | null => {
|
|
11
|
+
export const parseDate = (dateString: string | Date | null, format: string): Date | null => {
|
|
12
|
+
// Si dateString est null ou undefined, retourner null
|
|
12
13
|
if (!dateString) return null
|
|
13
14
|
|
|
15
|
+
// Si dateString est déjà un objet Date, le retourner directement
|
|
16
|
+
if (dateString instanceof Date) {
|
|
17
|
+
return dateString
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Si dateString n'est pas une chaîne de caractères, convertir en chaîne ou retourner null
|
|
21
|
+
if (typeof dateString !== 'string') {
|
|
22
|
+
try {
|
|
23
|
+
dateString = String(dateString)
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
14
30
|
// Créer un mapping des positions des éléments de date selon le format
|
|
15
31
|
const separator = format.includes('/') ? '/' : format.includes('-') ? '-' : '.'
|
|
16
32
|
const parts = format.split(separator)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composable pour le formatage et le parsing des dates avec dayjs
|
|
3
|
+
*/
|
|
4
|
+
import dayjs from 'dayjs'
|
|
5
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat'
|
|
6
|
+
import localizedFormat from 'dayjs/plugin/localizedFormat'
|
|
7
|
+
import utc from 'dayjs/plugin/utc'
|
|
8
|
+
import timezone from 'dayjs/plugin/timezone'
|
|
9
|
+
import 'dayjs/locale/fr'
|
|
10
|
+
|
|
11
|
+
// Initialiser les plugins dayjs
|
|
12
|
+
dayjs.extend(customParseFormat)
|
|
13
|
+
dayjs.extend(localizedFormat)
|
|
14
|
+
dayjs.extend(utc)
|
|
15
|
+
dayjs.extend(timezone)
|
|
16
|
+
dayjs.locale('fr')
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parse une chaîne de caractères en objet Date selon un format spécifié
|
|
20
|
+
* @param dateString - La chaîne de caractères à parser
|
|
21
|
+
* @param format - Le format de la date (ex: 'DD/MM/YYYY')
|
|
22
|
+
* @returns Un objet Date ou null si la chaîne n'est pas valide
|
|
23
|
+
*/
|
|
24
|
+
export const parseDate = (dateString: string | Date | null, format: string): Date | null => {
|
|
25
|
+
// Si dateString est null ou undefined, retourner null
|
|
26
|
+
if (!dateString) return null
|
|
27
|
+
|
|
28
|
+
// Si dateString est déjà un objet Date, le retourner directement
|
|
29
|
+
if (dateString instanceof Date) {
|
|
30
|
+
return dateString
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Si dateString n'est pas une chaîne de caractères, convertir en chaîne ou retourner null
|
|
34
|
+
if (typeof dateString !== 'string') {
|
|
35
|
+
try {
|
|
36
|
+
dateString = String(dateString)
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Utiliser dayjs pour parser la date
|
|
44
|
+
const parsedDate = dayjs(dateString, format, true)
|
|
45
|
+
|
|
46
|
+
if (!parsedDate.isValid()) return null
|
|
47
|
+
|
|
48
|
+
// Extraire les composants de la date pour créer une date UTC
|
|
49
|
+
// Cela évite les problèmes de décalage de fuseau horaire
|
|
50
|
+
return dayjs.utc()
|
|
51
|
+
.year(parsedDate.year())
|
|
52
|
+
.month(parsedDate.month())
|
|
53
|
+
.date(parsedDate.date())
|
|
54
|
+
.hour(0)
|
|
55
|
+
.minute(0)
|
|
56
|
+
.second(0)
|
|
57
|
+
.millisecond(0)
|
|
58
|
+
.toDate()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Formate une date selon un format spécifié
|
|
63
|
+
* @param date - La date à formater
|
|
64
|
+
* @param format - Le format de sortie (ex: 'DD/MM/YYYY')
|
|
65
|
+
* @returns La date formatée en chaîne de caractères
|
|
66
|
+
*/
|
|
67
|
+
export const formatDate = (date: Date | null, format: string): string => {
|
|
68
|
+
if (!date) return ''
|
|
69
|
+
|
|
70
|
+
return dayjs(date).format(format)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Hook composable pour le formatage et le parsing des dates
|
|
75
|
+
* @returns Fonctions de formatage et parsing de dates
|
|
76
|
+
*/
|
|
77
|
+
export function useDateFormat() {
|
|
78
|
+
return {
|
|
79
|
+
parseDate,
|
|
80
|
+
formatDate,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export default useDateFormat
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composable pour l'initialisation des dates dans le DatePicker avec dayjs
|
|
3
|
+
*/
|
|
4
|
+
import dayjs from 'dayjs'
|
|
5
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat'
|
|
6
|
+
import utc from 'dayjs/plugin/utc'
|
|
7
|
+
import timezone from 'dayjs/plugin/timezone'
|
|
8
|
+
import 'dayjs/locale/fr'
|
|
9
|
+
|
|
10
|
+
// Initialiser les plugins dayjs
|
|
11
|
+
dayjs.extend(customParseFormat)
|
|
12
|
+
dayjs.extend(utc)
|
|
13
|
+
dayjs.extend(timezone)
|
|
14
|
+
dayjs.locale('fr')
|
|
15
|
+
|
|
16
|
+
// Types
|
|
17
|
+
export type DateValue = string | [string, string] | null
|
|
18
|
+
export type DateInput = string | string[] | null | object
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Parse une date en utilisant dayjs et retourne une Date UTC
|
|
22
|
+
* @param dateStr - La chaîne de date à analyser
|
|
23
|
+
* @param format - Le format de la date
|
|
24
|
+
* @returns Une Date ou null si la date est invalide
|
|
25
|
+
*/
|
|
26
|
+
const parseToUTCDate = (dateStr: string, format: string): Date | null => {
|
|
27
|
+
if (!dayjs(dateStr, format).isValid()) return null
|
|
28
|
+
|
|
29
|
+
// Extraire les composants de la date à partir de la chaîne
|
|
30
|
+
const dateParts = dayjs(dateStr, format)
|
|
31
|
+
|
|
32
|
+
// Créer une date UTC avec les composants exacts pour éviter les décalages de fuseau horaire
|
|
33
|
+
// Utiliser set pour définir explicitement l'année, le mois et le jour
|
|
34
|
+
return dayjs.utc()
|
|
35
|
+
.year(dateParts.year())
|
|
36
|
+
.month(dateParts.month())
|
|
37
|
+
.date(dateParts.date())
|
|
38
|
+
.hour(0)
|
|
39
|
+
.minute(0)
|
|
40
|
+
.second(0)
|
|
41
|
+
.millisecond(0)
|
|
42
|
+
.toDate()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Initialise les dates sélectionnées à partir d'une valeur d'entrée
|
|
47
|
+
* @param modelValue - La valeur d'entrée (peut être une chaîne, un tableau, null ou un objet)
|
|
48
|
+
* @param displayFormat - Le format d'affichage des dates
|
|
49
|
+
* @param returnFormat - Le format de retour des dates (optionnel)
|
|
50
|
+
* @returns Une date, un tableau de dates ou null
|
|
51
|
+
*/
|
|
52
|
+
export const initializeSelectedDates = (
|
|
53
|
+
modelValue: DateInput | null,
|
|
54
|
+
displayFormat: string,
|
|
55
|
+
returnFormat: string = '',
|
|
56
|
+
): Date | Date[] | null => {
|
|
57
|
+
if (!modelValue) return null
|
|
58
|
+
|
|
59
|
+
// Déterminer le format à utiliser pour l'analyse
|
|
60
|
+
const parseFormat = returnFormat || displayFormat
|
|
61
|
+
|
|
62
|
+
if (Array.isArray(modelValue)) {
|
|
63
|
+
if (modelValue.length >= 2) {
|
|
64
|
+
// Essayer d'abord avec le format de retour, puis avec le format d'affichage
|
|
65
|
+
let dates = [
|
|
66
|
+
parseToUTCDate(modelValue[0], parseFormat),
|
|
67
|
+
parseToUTCDate(modelValue[1], parseFormat),
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
// Si l'une des dates est invalide avec le format de retour, essayer avec le format d'affichage
|
|
71
|
+
if (dates.some(date => date === null) && returnFormat) {
|
|
72
|
+
dates = [
|
|
73
|
+
parseToUTCDate(modelValue[0], displayFormat),
|
|
74
|
+
parseToUTCDate(modelValue[1], displayFormat),
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Vérifie si l'une des dates est toujours invalide
|
|
79
|
+
if (dates.some(date => date === null)) {
|
|
80
|
+
return []
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Vérifie si la première date est après la seconde
|
|
84
|
+
if (dates[0] && dates[1] && dayjs(dates[0]).isAfter(dayjs(dates[1]))) {
|
|
85
|
+
return []
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Filtrer les dates nulles et convertir en tableau de Date
|
|
89
|
+
return dates.filter((date): date is Date => date !== null)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (modelValue.length === 1) {
|
|
93
|
+
// Essayer d'abord avec le format de retour, puis avec le format d'affichage
|
|
94
|
+
let date = parseToUTCDate(modelValue[0], parseFormat)
|
|
95
|
+
|
|
96
|
+
// Si la date est invalide avec le format de retour, essayer avec le format d'affichage
|
|
97
|
+
if (date === null && returnFormat) {
|
|
98
|
+
date = parseToUTCDate(modelValue[0], displayFormat)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return date === null ? [] : [date]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return []
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Si modelValue est un objet, on le convertit en chaîne
|
|
108
|
+
if (typeof modelValue === 'object') {
|
|
109
|
+
return null
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Essayer d'abord avec le format de retour, puis avec le format d'affichage
|
|
113
|
+
let date = parseToUTCDate(modelValue, parseFormat)
|
|
114
|
+
|
|
115
|
+
// Si la date est invalide avec le format de retour, essayer avec le format d'affichage
|
|
116
|
+
if (date === null && returnFormat) {
|
|
117
|
+
date = parseToUTCDate(modelValue, displayFormat)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return date
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Hook composable pour l'initialisation des dates
|
|
125
|
+
* @returns Fonction d'initialisation des dates
|
|
126
|
+
*/
|
|
127
|
+
export function useDateInitialization() {
|
|
128
|
+
return {
|
|
129
|
+
initializeSelectedDates,
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export default useDateInitialization
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Story, Meta } from '@storybook/addon-docs/blocks';
|
|
2
|
+
import * as AvancementStories from './Avancement.stories.ts';
|
|
3
|
+
|
|
4
|
+
<Meta of={AvancementStories} />
|
|
5
|
+
|
|
6
|
+
# Outils de pré-audit
|
|
7
|
+
|
|
8
|
+
<Story of={AvancementStories.PreAudit} />
|
|
9
|
+
|
|
10
|
+
# Contrôle manuel
|
|
11
|
+
|
|
12
|
+
<Story of={AvancementStories.Manuel} />
|