- Inscription, suivi de l'inscription (lien de confirmation), seconde étape de connexion (code à 6 chiffres ou code de secours), mot de passe oublié et réinitialisation, page « Mon compte » (mot de passe, 2FA avec QR code et codes de secours), d'après les maquettes Penpot. - Les jetons reçus par e-mail sont retirés de l'URL dès l'arrivée. - Favicon de la SSMG (ssmg.be) ; retour en haut de page à chaque navigation. - 93 tests Vitest ; README et CLAUDE.md mis à jour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
2.7 KiB
Vue
110 lines
2.7 KiB
Vue
<script setup lang="ts">
|
||
import { nextTick, ref } from 'vue'
|
||
|
||
/** Saisie d'un code à 6 chiffres en 6 cases (maquettes 13 et 14). Accepte le collage. */
|
||
const props = withDefaults(defineProps<{ length?: number; label: string; autofocus?: boolean }>(), {
|
||
length: 6,
|
||
autofocus: false,
|
||
})
|
||
const emit = defineEmits<{ complete: [code: string] }>()
|
||
const model = defineModel<string>({ default: '' })
|
||
|
||
const inputs = ref<HTMLInputElement[]>([])
|
||
const digits = ref<string[]>(Array.from({ length: props.length }, (_, i) => model.value[i] ?? ''))
|
||
|
||
function sync() {
|
||
// On teste la chaîne locale : `model.value` n'est mis à jour qu'au rendu du parent.
|
||
const code = digits.value.join('')
|
||
model.value = code
|
||
if (code.length === props.length) emit('complete', code)
|
||
}
|
||
|
||
function focus(index: number) {
|
||
void nextTick(() => inputs.value[Math.max(0, Math.min(index, props.length - 1))]?.focus())
|
||
}
|
||
|
||
function onInput(index: number, event: Event) {
|
||
const value = (event.target as HTMLInputElement).value.replace(/\D/g, '')
|
||
if (value.length > 1) {
|
||
fill(index, value)
|
||
return
|
||
}
|
||
digits.value[index] = value
|
||
sync()
|
||
if (value) focus(index + 1)
|
||
}
|
||
|
||
function fill(start: number, value: string) {
|
||
for (const [offset, char] of [...value].entries()) {
|
||
if (start + offset < props.length) digits.value[start + offset] = char
|
||
}
|
||
sync()
|
||
focus(start + value.length)
|
||
}
|
||
|
||
function onPaste(index: number, event: ClipboardEvent) {
|
||
const text = event.clipboardData?.getData('text').replace(/\D/g, '') ?? ''
|
||
if (!text) return
|
||
event.preventDefault()
|
||
fill(index, text)
|
||
}
|
||
|
||
function onKeydown(index: number, event: KeyboardEvent) {
|
||
if (event.key === 'Backspace' && !digits.value[index]) focus(index - 1)
|
||
if (event.key === 'ArrowLeft') focus(index - 1)
|
||
if (event.key === 'ArrowRight') focus(index + 1)
|
||
}
|
||
|
||
function clear() {
|
||
digits.value = digits.value.map(() => '')
|
||
sync()
|
||
focus(0)
|
||
}
|
||
|
||
defineExpose({ clear })
|
||
</script>
|
||
|
||
<template>
|
||
<div class="code-input" role="group" :aria-label="label">
|
||
<input
|
||
v-for="(_, index) in digits"
|
||
:key="index"
|
||
ref="inputs"
|
||
v-model="digits[index]"
|
||
type="text"
|
||
inputmode="numeric"
|
||
maxlength="6"
|
||
:autocomplete="index === 0 ? 'one-time-code' : 'off'"
|
||
:autofocus="autofocus && index === 0"
|
||
:aria-label="`${label} – chiffre ${index + 1}`"
|
||
class="form-control digit"
|
||
@input="onInput(index, $event)"
|
||
@paste="onPaste(index, $event)"
|
||
@keydown="onKeydown(index, $event)"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.code-input {
|
||
display: flex;
|
||
gap: 10px;
|
||
}
|
||
|
||
.digit {
|
||
width: 52px;
|
||
height: 60px;
|
||
padding: 0;
|
||
text-align: center;
|
||
font-size: 1.5rem;
|
||
font-weight: 500;
|
||
}
|
||
|
||
@media (max-width: 400px) {
|
||
.digit {
|
||
width: 42px;
|
||
height: 52px;
|
||
}
|
||
}
|
||
</style>
|