From 7ab221976462e48bf188730bf4e87ce7d0ce3aae Mon Sep 17 00:00:00 2001 From: tristan Date: Wed, 20 May 2026 08:13:37 +0200 Subject: [PATCH] =?UTF-8?q?docs=20:=20plan=20d'impl=C3=A9mentation=20du=20?= =?UTF-8?q?datepicker=20MalioDate=20(#MUI-33)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 (1M context) --- .../plans/2026-05-20-datepicker.md | 1440 +++++++++++++++++ 1 file changed, 1440 insertions(+) create mode 100644 docs/superpowers/plans/2026-05-20-datepicker.md diff --git a/docs/superpowers/plans/2026-05-20-datepicker.md b/docs/superpowers/plans/2026-05-20-datepicker.md new file mode 100644 index 0000000..aa925c2 --- /dev/null +++ b/docs/superpowers/plans/2026-05-20-datepicker.md @@ -0,0 +1,1440 @@ +# MalioDate (Datepicker) Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Composant `` : champ readonly + popover calendrier (vue jours + vue mois), valeur ISO `YYYY-MM-DD`, bornes `min`/`max`, effacement. + +**Architecture:** Composant public `Date.vue` orchestrant 3 sous-composants internes (`CalendarHeader`, `MonthGrid`, `MonthPicker`) et 3 modules colocalisés (`dateFormat`, `useMonthMatrix`, `useCalendarPopover`). On construit du bas vers le haut : modules purs d'abord (TDD strict), puis sous-composants, puis composant public. + +**Tech Stack:** Nuxt 4 layer, Vue 3 ` +``` + +- [ ] **Step 2 : Vérifier le lint** + +Run: `npm run lint` +Expected: aucune nouvelle erreur (les warnings préexistants sont tolérés) + +- [ ] **Step 3 : Commit** + +```bash +git add app/components/malio/date/internal/MonthGrid.vue +git commit -m "feat : grille mensuelle du datepicker (#MUI-33)" +``` + +--- + +## Task 5 : Sous-composant `CalendarHeader.vue` + +**Files:** +- Create: `app/components/malio/date/internal/CalendarHeader.vue` + +Props : `viewMode: 'days' | 'months'`, `currentMonth: number`, `currentYear: number`. Emits : `prev`, `next`, `toggle-view`. + +- [ ] **Step 1 : Implémenter le composant** — *utilisateur* (référence ci-dessous) + +```vue + + + +``` + +- [ ] **Step 2 : Vérifier le lint** + +Run: `npm run lint` +Expected: aucune nouvelle erreur + +- [ ] **Step 3 : Commit** + +```bash +git add app/components/malio/date/internal/CalendarHeader.vue +git commit -m "feat : header de navigation du datepicker (#MUI-33)" +``` + +--- + +## Task 6 : Sous-composant `MonthPicker.vue` + +**Files:** +- Create: `app/components/malio/date/internal/MonthPicker.vue` + +Props : `selectedMonth?: number`. Emit : `select` (payload `number` 0-11). + +- [ ] **Step 1 : Implémenter le composant** — *utilisateur* (référence ci-dessous) + +```vue + + + +``` + +- [ ] **Step 2 : Vérifier le lint** + +Run: `npm run lint` +Expected: aucune nouvelle erreur + +- [ ] **Step 3 : Commit** + +```bash +git add app/components/malio/date/internal/MonthPicker.vue +git commit -m "feat : sélecteur de mois du datepicker (#MUI-33)" +``` + +--- + +## Task 7 : Composant public `Date.vue` + tests d'intégration + +**Files:** +- Create: `app/components/malio/date/Date.vue` +- Test: `app/components/malio/date/Date.test.ts` + +- [ ] **Step 1 : Implémenter le composant** — *utilisateur* (référence ci-dessous) + +```vue + + + + + +``` + +- [ ] **Step 2 : Écrire les tests d'intégration (échouent au départ si lancés avant l'impl)** — *assistant* + +```ts +import {describe, expect, it, beforeEach, afterEach, vi} from 'vitest' +import {mount} from '@vue/test-utils' +import type {DefineComponent} from 'vue' +import Date_ from './Date.vue' + +type DateProps = { + id?: string + name?: string + label?: string + modelValue?: string | null + placeholder?: string + required?: boolean + disabled?: boolean + readonly?: boolean + hint?: string + error?: string + success?: string + min?: string + max?: string + clearable?: boolean + inputClass?: string + labelClass?: string + groupClass?: string +} + +const DateForTest = Date_ as DefineComponent +const mountDate = (props: DateProps = {}) => mount(DateForTest, {props, attachTo: document.body}) + +describe('MalioDate', () => { + beforeEach(() => { + vi.useFakeTimers() + vi.setSystemTime(new Date(2026, 4, 19)) // 19 mai 2026 + }) + afterEach(() => vi.useRealTimers()) + + describe('rendu', () => { + it('renders the label and the calendar icon', () => { + const wrapper = mountDate({label: 'Date de naissance'}) + expect(wrapper.get('label').text()).toBe('Date de naissance') + expect(wrapper.find('[data-test="calendar-icon"]').exists()).toBe(true) + }) + + it('displays the formatted value in the field', () => { + const wrapper = mountDate({modelValue: '2026-05-19'}) + const input = wrapper.get('[data-test="date-input"]').element as HTMLInputElement + expect(input.value).toBe('19/05/2026') + }) + + it('does not show the popover initially', () => { + const wrapper = mountDate() + expect(wrapper.find('[data-test="popover"]').exists()).toBe(false) + }) + }) + + describe('popover', () => { + it('opens on field click', async () => { + const wrapper = mountDate() + await wrapper.get('[data-test="date-input"]').trigger('click') + expect(wrapper.find('[data-test="popover"]').exists()).toBe(true) + }) + + it('opens on the current month when there is no value', async () => { + const wrapper = mountDate() + await wrapper.get('[data-test="date-input"]').trigger('click') + expect(wrapper.get('[data-test="header-toggle"]').text()).toContain('Mai 2026') + }) + + it('opens on the value month when a value is set', async () => { + const wrapper = mountDate({modelValue: '2025-12-25'}) + await wrapper.get('[data-test="date-input"]').trigger('click') + expect(wrapper.get('[data-test="header-toggle"]').text()).toContain('Décembre 2025') + }) + + it('closes on outside mousedown', async () => { + const wrapper = mountDate() + await wrapper.get('[data-test="date-input"]').trigger('click') + document.body.dispatchEvent(new MouseEvent('mousedown', {bubbles: true})) + await wrapper.vm.$nextTick() + expect(wrapper.find('[data-test="popover"]').exists()).toBe(false) + }) + }) + + describe('navigation jours', () => { + it('goes to the next month on the right chevron', async () => { + const wrapper = mountDate() + await wrapper.get('[data-test="date-input"]').trigger('click') + await wrapper.get('[data-test="header-next"]').trigger('click') + expect(wrapper.get('[data-test="header-toggle"]').text()).toContain('Juin 2026') + }) + + it('rolls December to January and bumps the year', async () => { + const wrapper = mountDate({modelValue: '2026-12-15'}) + await wrapper.get('[data-test="date-input"]').trigger('click') + await wrapper.get('[data-test="header-next"]').trigger('click') + expect(wrapper.get('[data-test="header-toggle"]').text()).toContain('Janvier 2027') + }) + }) + + describe('sélection', () => { + it('emits the ISO date and closes on day click', async () => { + const wrapper = mountDate() + await wrapper.get('[data-test="date-input"]').trigger('click') + await wrapper.get('[data-test="day"][data-iso="2026-05-19"]').trigger('click') + expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual(['2026-05-19']) + expect(wrapper.find('[data-test="popover"]').exists()).toBe(false) + }) + }) + + describe('bornes min/max', () => { + it('disables days outside the range', async () => { + const wrapper = mountDate({min: '2026-05-10', max: '2026-05-20'}) + await wrapper.get('[data-test="date-input"]').trigger('click') + const outside = wrapper.get('[data-test="day"][data-iso="2026-05-05"]') + expect((outside.element as HTMLButtonElement).disabled).toBe(true) + await outside.trigger('click') + expect(wrapper.emitted('update:modelValue')).toBeUndefined() + }) + }) + + describe('vue mois', () => { + it('switches to month view on header toggle', async () => { + const wrapper = mountDate() + await wrapper.get('[data-test="date-input"]').trigger('click') + await wrapper.get('[data-test="header-toggle"]').trigger('click') + expect(wrapper.find('[data-test="month-picker"]').exists()).toBe(true) + }) + + it('navigates the year with chevrons in month view', async () => { + const wrapper = mountDate() + await wrapper.get('[data-test="date-input"]').trigger('click') + await wrapper.get('[data-test="header-toggle"]').trigger('click') + await wrapper.get('[data-test="header-next"]').trigger('click') + expect(wrapper.get('[data-test="header-toggle"]').text()).toContain('2027') + }) + + it('returns to day view on month click', async () => { + const wrapper = mountDate() + await wrapper.get('[data-test="date-input"]').trigger('click') + await wrapper.get('[data-test="header-toggle"]').trigger('click') + await wrapper.get('[data-test="month"][data-month="0"]').trigger('click') + expect(wrapper.find('[data-test="month-picker"]').exists()).toBe(false) + expect(wrapper.get('[data-test="header-toggle"]').text()).toContain('Janvier 2026') + expect(wrapper.emitted('update:modelValue')).toBeUndefined() + }) + }) + + describe('effacement', () => { + it('shows the clear button when there is a value', () => { + const wrapper = mountDate({modelValue: '2026-05-19'}) + expect(wrapper.find('[data-test="clear"]').exists()).toBe(true) + }) + + it('hides the clear button when empty', () => { + const wrapper = mountDate() + expect(wrapper.find('[data-test="clear"]').exists()).toBe(false) + }) + + it('emits null and does not open the popover on clear', async () => { + const wrapper = mountDate({modelValue: '2026-05-19'}) + await wrapper.get('[data-test="clear"]').trigger('click') + expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual([null]) + expect(wrapper.find('[data-test="popover"]').exists()).toBe(false) + }) + }) + + describe('états', () => { + it('does not open when disabled', async () => { + const wrapper = mountDate({disabled: true}) + await wrapper.get('[data-test="date-input"]').trigger('click') + expect(wrapper.find('[data-test="popover"]').exists()).toBe(false) + }) + + it('does not open when readonly', async () => { + const wrapper = mountDate({readonly: true, modelValue: '2026-05-19'}) + await wrapper.get('[data-test="date-input"]').trigger('click') + expect(wrapper.find('[data-test="popover"]').exists()).toBe(false) + }) + }) + + describe('accessibilité', () => { + it('sets aria-invalid and describedby on error', () => { + const wrapper = mountDate({error: 'Date requise'}) + const input = wrapper.get('[data-test="date-input"]') + expect(input.attributes('aria-invalid')).toBe('true') + expect(input.attributes('aria-describedby')).toBeTruthy() + expect(wrapper.text()).toContain('Date requise') + }) + }) + + describe('synchronisation externe', () => { + it('updates the displayed value when modelValue changes', async () => { + const wrapper = mountDate({modelValue: '2026-05-19'}) + await wrapper.setProps({modelValue: '2026-12-25'}) + const input = wrapper.get('[data-test="date-input"]').element as HTMLInputElement + expect(input.value).toBe('25/12/2026') + }) + }) +}) +``` + +- [ ] **Step 3 : Lancer les tests, vérifier le succès** + +Run: `npm run test -- Date` +Expected: PASS (toutes les assertions). Si un test échoue, ajuster l'implémentation (les tests sont le contrat). + +- [ ] **Step 4 : Vérifier le lint et la suite complète** + +Run: `npm run lint && npm run test` +Expected: 0 erreur de lint nouvelle ; toute la suite verte. + +- [ ] **Step 5 : Commit** + +```bash +git add app/components/malio/date/Date.vue app/components/malio/date/Date.test.ts +git commit -m "feat : composant MalioDate (datepicker) (#MUI-33)" +``` + +--- + +## Task 8 : Story Histoire + page Playground + +**Files:** +- Create: `app/story/date/Date.story.vue` +- Create: `.playground/pages/composant/date/date.vue` + +- [ ] **Step 1 : Créer la story** — *utilisateur* (référence ci-dessous) + +```vue + + + +``` + +- [ ] **Step 2 : Créer la page playground** — *utilisateur* (référence ci-dessous) + +```vue + + + +``` + +- [ ] **Step 3 : Vérification visuelle manuelle** + +Run: `npm run dev` (playground) puis ouvrir la page "Date" du menu. +Vérifier : ouverture/fermeture, navigation mois, bascule vue mois, sélection, effacement, bornes grisées, état error/disabled/readonly. +Run aussi : `npm run story:dev` pour la story Histoire. + +- [ ] **Step 4 : Lint final** + +Run: `npm run lint` +Expected: aucune nouvelle erreur. + +- [ ] **Step 5 : Commit** + +```bash +git add app/story/date/Date.story.vue .playground/pages/composant/date/date.vue +git commit -m "feat : story et page playground du datepicker (#MUI-33)" +``` + +--- + +## Self-Review (effectuée à l'écriture du plan) + +**Couverture spec :** modelValue ISO ✓ (T1), props/emits ✓ (T7), CalendarHeader ✓ (T5), MonthGrid + colonne semaine + min/max + today/sélection ✓ (T4), MonthPicker ✓ (T6), composables ✓ (T1-3), comportements ouverture/sélection/navigation/vue mois/fermeture/clear/états/synchro ✓ (T7 tests), a11y `aria-*` ✓ (T7), tests ✓ (T1-3, T7), story ✓ (T8), playground ✓ (T8). Reportés v2 (clavier, vue années, disabledDates, saisie éditable) : non planifiés, conforme. + +**Placeholders :** aucun TODO/TBD ; tout le code de référence est complet. + +**Cohérence des types :** `DayCell`/`WeekRow` définis en T2 et réutilisés en T4. `useCalendarPopover` renvoie `{isOpen, viewMode, open, close, toggleView}` (T3) — consommés tels quels en T7. `data-test` cohérents entre composants (T4-6) et tests (T7). Emit `select` (ISO string en T4, number en T6) consommés correctement par T7 (`onSelectDay`/`onSelectMonth`). + +**Écart assumé vs spec :** la spec mentionnait "lien ajouté dans index.vue" pour le playground ; en réalité le menu est auto-globé → aucune édition manuelle requise (noté en tête de plan).