Files
malio-layer-ui/app/components/malio/checkbox/Checkbox.vue
T
tristan 887ebdebd7 feat(ui) : required cohérent + astérisque label + sanitisation email (MUI-41) (#60)
## Résumé (MUI-41)

Harmonise l'état « obligatoire » des composants de formulaire et normalise le champ email.

### `required` + astérisque
- Nouveau composant partagé `MalioRequiredMark` : astérisque rouge (`text-m-danger`, **16px**), `aria-hidden`.
- Prop `required` désormais cohérente sur toute la famille formulaire ; quand vraie, l'astérisque s'affiche **dans le label**.
- Prop ajoutée à `Select`, `SelectCheckbox`, `InputUpload`, `InputRichText` (les autres l'avaient déjà).
- Accessibilité : `required` natif là où l'élément le supporte, sinon `aria-required` (Select/SelectCheckbox sur le `<button>`, RichText sur le wrapper éditeur, Upload sur le champ visible).
- `MalioSiteSelector` **exclu** volontairement (segmented control, pas de label de champ).

### Sanitisation email (`MalioInputEmail`)
- Suppression de **tous les espaces** à la saisie (pas de masque).
- Nouvelle prop opt-in `lowercase` (défaut `false`) : normalise en minuscules à la frappe (cohérent RG-1.21 Starseed).
- Garde défensive curseur : l'API de sélection est interdite sur `type="email"` → repositionnement best-effort sans jamais lever.
- La validation de format reste à la couche `error`.

### Docs & playground
- `COMPONENTS.md` (doc `required` cohérente + note famille + `lowercase`) et `CHANGELOG.md` mis à jour.
- Exemples playground `required` et email `lowercase` ajoutés.

## Test plan
- [x] Suite complète : 42 fichiers / 771 tests verts
- [x] Lint : 0 erreur
- [x] Tests `aria-required` sur Select/SelectCheckbox/RichText
- [ ] Vérif visuelle playground : astérisque 16px dans le label, email qui retire les espaces / minuscule

Spec & plan : `docs/superpowers/specs/` et `docs/superpowers/plans/`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed-on: #60
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
2026-06-04 06:42:19 +00:00

243 lines
5.1 KiB
Vue

<template>
<div :class="mergedGroupClass">
<input
:id="inputId"
:name="name"
:checked="isChecked"
:required="required"
:disabled="disabled"
:aria-invalid="!!error"
:aria-describedby="describedBy"
:class="mergedInputClass"
v-bind="attrs"
type="checkbox"
@change="onChange"
>
<label
v-if="label"
:for="inputId"
:class="mergedLabelClass"
>
<span>
<svg width="12" height="10" viewBox="0 0 12 10" aria-hidden="true">
<polyline points="1.5 6 4.5 9 10.5 1"/>
</svg>
</span>
<span>
{{ label }}<MalioRequiredMark v-if="required" />
</span>
</label>
<p
v-if="reserveMessageSpace || hint || error || success"
:id="`${inputId}-describedby`"
:class="mergedMessageClass"
>
{{ error || success || hint }}
</p>
</div>
</template>
<script setup lang="ts">
import {computed, ref, useAttrs, useId} from 'vue'
import {twMerge} from 'tailwind-merge'
import MalioRequiredMark from '../shared/RequiredMark.vue'
defineOptions({name: 'MalioCheckbox', inheritAttrs: false})
const props = withDefaults(
defineProps<{
id?: string
label?: string
name?: string
modelValue?: boolean | null | undefined
inputClass?: string
labelClass?: string
groupClass?: string
required?: boolean
disabled?: boolean
readonly?: boolean
hint?: string
error?: string
success?: string
reserveMessageSpace?: boolean
}>(),
{
id: '',
label: '',
name: '',
modelValue: undefined,
inputClass: '',
labelClass: '',
groupClass: '',
required: false,
disabled: false,
readonly: false,
hint: '',
error: '',
success: '',
reserveMessageSpace: true,
},
)
const attrs = useAttrs()
const generatedId = useId()
const localChecked = ref(false)
const inputId = computed(() => props.id?.toString() || `malio-checkbox-${generatedId}`)
const isControlled = computed(() => props.modelValue !== undefined)
const isChecked = computed(() => (isControlled.value ? !!props.modelValue : localChecked.value))
const hasError = computed(() => !!props.error)
const hasSuccess = computed(() => !!props.success && !hasError.value)
const disabled = computed(() => props.disabled)
const describedBy = computed(() => {
if (!props.hint && !hasError.value && !hasSuccess.value) return undefined
return `${inputId.value}-describedby`
})
const mergedGroupClass = computed(() =>
twMerge(
'checkbox-wrapper-4 w-full',
props.groupClass,
),
)
const mergedInputClass = computed(() =>
twMerge(
'inp-cbx peer ',
props.inputClass,
),
)
const mergedLabelClass = computed(() =>
twMerge(
'cbx text-lg',
isChecked.value ? 'text-black' : 'text-m-muted',
disabled.value ? 'cursor-not-allowed text-black/60' : '',
hasError.value ? 'text-m-danger' : '',
hasSuccess.value ? 'text-m-success' : '',
props.labelClass,
),
)
const mergedMessageClass = computed(() =>
twMerge(
'text-xs',
props.reserveMessageSpace ? 'min-h-[1rem]' : '',
hasError.value
? 'text-m-danger'
: hasSuccess.value
? 'text-m-success'
: 'text-m-muted',
),
)
const emit = defineEmits<{
(event: 'update:modelValue', value: boolean): void
}>()
const onChange = (event: Event) => {
const target = event.target as HTMLInputElement
if (props.readonly) {
target.checked = isChecked.value
return
}
if (!isControlled.value) {
localChecked.value = target.checked
}
emit('update:modelValue', target.checked)
}
</script>
<style scoped>
.cbx {
display: inline-flex;
align-items: center;
cursor: pointer;
}
.cbx span {
display: inline-flex;
align-items: center;
}
.cbx span:first-child {
position: relative;
width: 18px;
height: 18px;
flex: 0 0 18px;
transform: scale(1);
border: 2px solid rgb(var(--m-muted) / 1);
transition: all 0.1s ease;
}
.inp-cbx:checked + .cbx span:first-child {
border-color: rgb(0, 0, 0);
}
.cbx span:first-child svg {
position: absolute;
top: 2px;
left: 1px;
fill: none;
stroke: #000000;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
stroke-dashoffset: 16px;
transition: all 0.125s ease;
}
.cbx span:last-child {
padding-left: 12px;
line-height: 18px;
}
.inp-cbx {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
border: 0;
}
.inp-cbx:checked + .cbx span:first-child svg {
stroke-dashoffset: 0;
}
.inp-cbx + .cbx.text-m-danger span:first-child {
border-color: rgb(var(--m-danger) / 1);
}
.cbx.text-m-danger span:first-child svg {
stroke: rgb(var(--m-danger) / 1);
}
.inp-cbx:checked + .cbx.text-m-danger span:first-child {
border-color: rgb(var(--m-danger) / 1);
}
.inp-cbx + .cbx.text-m-success span:first-child {
border-color: rgb(var(--m-success) / 1);
}
.cbx.text-m-success span:first-child svg {
stroke: rgb(var(--m-success) / 1);
}
.inp-cbx:checked + .cbx.text-m-success span:first-child {
border-color: rgb(var(--m-success) / 1);
}
.inp-cbx:disabled + .cbx {
cursor: not-allowed;
opacity: 0.6;
}
</style>