Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e38255341d | |||
| 1bbe77d391 | |||
| ccc8410da0 |
@@ -1,101 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="grid grid-cols-1 items-start gap-6 md:grid-cols-2">
|
|
||||||
<div class="rounded-lg border p-4">
|
|
||||||
<h2 class="mb-4 text-xl font-bold">Simple</h2>
|
|
||||||
<MalioCheckbox
|
|
||||||
v-model="simpleValue"
|
|
||||||
label="Accepter les conditions"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="rounded-lg border p-4">
|
|
||||||
<h2 class="mb-4 text-xl font-bold">Coche par default</h2>
|
|
||||||
<MalioCheckbox
|
|
||||||
v-model="checkedValue"
|
|
||||||
label="Recevoir la newsletter"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="rounded-lg border p-4">
|
|
||||||
<h2 class="mb-4 text-xl font-bold">Hint</h2>
|
|
||||||
<MalioCheckbox
|
|
||||||
v-model="hintValue"
|
|
||||||
label="J'accepte le traitement des donnees"
|
|
||||||
hint="Vous pouvez retirer votre consentement a tout moment."
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="rounded-lg border p-4">
|
|
||||||
<h2 class="mb-4 text-xl font-bold">Erreur</h2>
|
|
||||||
<MalioCheckbox
|
|
||||||
:model-value="false"
|
|
||||||
label="Accepter les CGU"
|
|
||||||
error="Ce champ est obligatoire."
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="rounded-lg border p-4">
|
|
||||||
<h2 class="mb-4 text-xl font-bold">Succès</h2>
|
|
||||||
<MalioCheckbox
|
|
||||||
:model-value="true"
|
|
||||||
label="Adresse vérifiée"
|
|
||||||
success="Choix valide."
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="rounded-lg border p-4">
|
|
||||||
<h2 class="mb-4 text-xl font-bold">Disabled et Readonly</h2>
|
|
||||||
<div class="space-y-4">
|
|
||||||
<MalioCheckbox
|
|
||||||
:model-value="true"
|
|
||||||
label="Option désactivée"
|
|
||||||
disabled
|
|
||||||
/>
|
|
||||||
<MalioCheckbox
|
|
||||||
:model-value="true"
|
|
||||||
label="Option readonly"
|
|
||||||
readonly
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="rounded-lg border p-4">
|
|
||||||
<h2 class="mb-4 text-xl font-bold">Plusieurs checkbox</h2>
|
|
||||||
<div class="space-y-4">
|
|
||||||
<MalioCheckbox
|
|
||||||
label="Option 1"
|
|
||||||
/>
|
|
||||||
<MalioCheckbox
|
|
||||||
label="Option 2"
|
|
||||||
/>
|
|
||||||
<MalioCheckbox
|
|
||||||
label="Option 3"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="rounded-lg border p-4">
|
|
||||||
<h2 class="mb-4 text-xl font-bold">Plusieurs checkbox avec v-for</h2>
|
|
||||||
<div class="space-y-4">
|
|
||||||
<MalioCheckbox
|
|
||||||
v-for="option in options"
|
|
||||||
:key="option"
|
|
||||||
:label="option"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import {ref} from 'vue'
|
|
||||||
import MalioCheckbox from '../../../app/components/malio/Checkbox.vue'
|
|
||||||
const simpleValue = ref(false)
|
|
||||||
const checkedValue = ref(true)
|
|
||||||
const hintValue = ref(false)
|
|
||||||
const options = [
|
|
||||||
'Option A',
|
|
||||||
'Option B',
|
|
||||||
'Option C',
|
|
||||||
'Option D',
|
|
||||||
|
|
||||||
]
|
|
||||||
</script>
|
|
||||||
@@ -82,6 +82,16 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="rounded-lg border p-4">
|
||||||
|
<h2 class="mb-4 text-xl font-bold">Peu d'elements (2)</h2>
|
||||||
|
<MalioSelect
|
||||||
|
v-model="shortListValue"
|
||||||
|
:options="shortOptions"
|
||||||
|
label="Civilite"
|
||||||
|
empty-option-label="Aucune selection"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="rounded-lg border p-4 md:col-span-2">
|
<div class="rounded-lg border p-4 md:col-span-2">
|
||||||
<h2 class="mb-4 text-xl font-bold">Liste longue</h2>
|
<h2 class="mb-4 text-xl font-bold">Liste longue</h2>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
@@ -121,6 +131,11 @@ const options = [
|
|||||||
{label: 'Portugal', value: 'pt'},
|
{label: 'Portugal', value: 'pt'},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const shortOptions = [
|
||||||
|
{label: 'Monsieur', value: 'M'},
|
||||||
|
{label: 'Madame', value: 'Mme'},
|
||||||
|
]
|
||||||
|
|
||||||
const longOptions = [
|
const longOptions = [
|
||||||
...options,
|
...options,
|
||||||
{label: 'Pays-Bas', value: 'nl'},
|
{label: 'Pays-Bas', value: 'nl'},
|
||||||
@@ -144,6 +159,7 @@ const errorValue = ref<string | number | null>(null)
|
|||||||
const successValue = ref<string | number | null>('be')
|
const successValue = ref<string | number | null>('be')
|
||||||
const disabledValue = ref<string | number | null>('ca')
|
const disabledValue = ref<string | number | null>('ca')
|
||||||
const emptyValue = ref<string | number | null>(null)
|
const emptyValue = ref<string | number | null>(null)
|
||||||
|
const shortListValue = ref<string | number | null>(null)
|
||||||
const longListValue = ref<string | number | null>(null)
|
const longListValue = ref<string | number | null>(null)
|
||||||
const bottomValue = ref<string | number | null>(null)
|
const bottomValue = ref<string | number | null>(null)
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -163,8 +163,17 @@ Liste déroulante.
|
|||||||
| `options` | `{ value: string \| number, text: string }[]` | `[]` | Options disponibles |
|
| `options` | `{ value: string \| number, text: string }[]` | `[]` | Options disponibles |
|
||||||
| `emptyOptionLabel` | `string` | `''` | Placeholder option vide |
|
| `emptyOptionLabel` | `string` | `''` | Placeholder option vide |
|
||||||
| `label` | `string` | `''` | Label |
|
| `label` | `string` | `''` | Label |
|
||||||
| `disabled` | `boolean` | `false` | Désactivé |
|
| `hint` | `string` | `''` | Message d'aide |
|
||||||
| `error` | `string` | `''` | Message d'erreur |
|
| `error` | `string` | `''` | Message d'erreur |
|
||||||
|
| `success` | `string` | `''` | Message de succès |
|
||||||
|
| `disabled` | `boolean` | `false` | Désactivé |
|
||||||
|
| `groupClass` | `string` | `''` | Classes CSS conteneur (twMerge) |
|
||||||
|
| `minWidth` | `string` | `'w-96'` | Classe largeur minimum |
|
||||||
|
| `maxWidth` | `string` | `''` | Classe largeur maximum |
|
||||||
|
| `rounded` | `string` | `'rounded-md'` | Classe border-radius |
|
||||||
|
| `textField` | `string` | `'text-lg'` | Classe taille texte bouton |
|
||||||
|
| `textValue` | `string` | `'text-lg'` | Classe taille texte valeur |
|
||||||
|
| `textLabel` | `string` | `'text-sm'` | Classe taille texte label |
|
||||||
|
|
||||||
**Events :** `update:modelValue(value: string | number | null)`
|
**Events :** `update:modelValue(value: string | number | null)`
|
||||||
**Slots :** `icon` (icône dropdown custom)
|
**Slots :** `icon` (icône dropdown custom)
|
||||||
@@ -172,6 +181,7 @@ Liste déroulante.
|
|||||||
```vue
|
```vue
|
||||||
<MalioSelect v-model="pays" label="Pays" :options="[{ value: 'FR', text: 'France' }, { value: 'BE', text: 'Belgique' }]" />
|
<MalioSelect v-model="pays" label="Pays" :options="[{ value: 'FR', text: 'France' }, { value: 'BE', text: 'Belgique' }]" />
|
||||||
<MalioSelect v-model="ville" label="Ville" :options="villes" empty-option-label="Choisir..." />
|
<MalioSelect v-model="ville" label="Ville" :options="villes" empty-option-label="Choisir..." />
|
||||||
|
<MalioSelect v-model="civilite" label="Civilité" :options="civilites" group-class="mt-0" />
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -1,142 +0,0 @@
|
|||||||
import {describe, expect, it} from 'vitest'
|
|
||||||
import {mount} from '@vue/test-utils'
|
|
||||||
import type {DefineComponent} from 'vue'
|
|
||||||
import Checkbox from './Checkbox.vue'
|
|
||||||
|
|
||||||
type CheckboxProps = {
|
|
||||||
id?: string
|
|
||||||
label?: string
|
|
||||||
name?: string
|
|
||||||
modelValue?: boolean | null
|
|
||||||
inputClass?: string
|
|
||||||
labelClass?: string
|
|
||||||
groupClass?: string
|
|
||||||
required?: boolean
|
|
||||||
disabled?: boolean
|
|
||||||
readonly?: boolean
|
|
||||||
hint?: string
|
|
||||||
error?: string
|
|
||||||
success?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const CheckboxForTest = Checkbox as DefineComponent<CheckboxProps>
|
|
||||||
|
|
||||||
const mountCheckbox = (props: CheckboxProps = {}) =>
|
|
||||||
mount(CheckboxForTest, {props})
|
|
||||||
|
|
||||||
describe('MalioCheckbox', () => {
|
|
||||||
it('renders a checkbox input', () => {
|
|
||||||
const wrapper = mountCheckbox()
|
|
||||||
|
|
||||||
expect(wrapper.get('input').attributes('type')).toBe('checkbox')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('renders the label text', () => {
|
|
||||||
const wrapper = mountCheckbox({label: 'Accept terms'})
|
|
||||||
|
|
||||||
expect(wrapper.get('label').text()).toContain('Accept terms')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('uses a provided id on input and label', () => {
|
|
||||||
const wrapper = mountCheckbox({
|
|
||||||
id: 'checkbox-id',
|
|
||||||
label: 'Accept terms',
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(wrapper.get('input').attributes('id')).toBe('checkbox-id')
|
|
||||||
expect(wrapper.get('label').attributes('for')).toBe('checkbox-id')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('generates an id when none is provided', () => {
|
|
||||||
const wrapper = mountCheckbox({label: 'Accept terms'})
|
|
||||||
const inputId = wrapper.get('input').attributes('id')
|
|
||||||
|
|
||||||
expect(inputId?.startsWith('malio-checkbox-')).toBe(true)
|
|
||||||
expect(wrapper.get('label').attributes('for')).toBe(inputId)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('applies the name attribute', () => {
|
|
||||||
const wrapper = mountCheckbox({name: 'terms'})
|
|
||||||
|
|
||||||
expect(wrapper.get('input').attributes('name')).toBe('terms')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('reflects the checked state from modelValue', () => {
|
|
||||||
const wrapper = mountCheckbox({modelValue: true})
|
|
||||||
|
|
||||||
expect((wrapper.get('input').element as HTMLInputElement).checked).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('emits update:modelValue when toggled', async () => {
|
|
||||||
const wrapper = mountCheckbox({modelValue: false})
|
|
||||||
const input = wrapper.get('input')
|
|
||||||
|
|
||||||
await input.setValue(true)
|
|
||||||
|
|
||||||
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([true])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('does not emit when readonly', async () => {
|
|
||||||
const wrapper = mountCheckbox({
|
|
||||||
modelValue: true,
|
|
||||||
readonly: true,
|
|
||||||
})
|
|
||||||
const input = wrapper.get('input')
|
|
||||||
|
|
||||||
await input.setValue(false)
|
|
||||||
|
|
||||||
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
|
||||||
expect((input.element as HTMLInputElement).checked).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('sets disabled and required attributes', () => {
|
|
||||||
const wrapper = mountCheckbox({
|
|
||||||
disabled: true,
|
|
||||||
required: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(wrapper.get('input').attributes('disabled')).toBeDefined()
|
|
||||||
expect(wrapper.get('input').attributes('required')).toBeDefined()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('shows a hint message and links it with aria-describedby', () => {
|
|
||||||
const wrapper = mountCheckbox({hint: 'Required field'})
|
|
||||||
const inputId = wrapper.get('input').attributes('id')
|
|
||||||
|
|
||||||
expect(wrapper.get('p').text()).toBe('Required field')
|
|
||||||
expect(wrapper.get('input').attributes('aria-describedby')).toBe(`${inputId}-describedby`)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('shows an error state and message', () => {
|
|
||||||
const wrapper = mountCheckbox({
|
|
||||||
label: 'Accept terms',
|
|
||||||
error: 'You must accept',
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(wrapper.get('input').attributes('aria-invalid')).toBe('true')
|
|
||||||
expect(wrapper.get('label').classes()).toContain('text-m-error')
|
|
||||||
expect(wrapper.get('p').text()).toBe('You must accept')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('shows success only when there is no error', () => {
|
|
||||||
const wrapper = mountCheckbox({
|
|
||||||
success: 'Valid',
|
|
||||||
error: 'Invalid',
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(wrapper.get('p').text()).toBe('Invalid')
|
|
||||||
expect(wrapper.get('p').classes()).toContain('text-m-error')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('shows success styles and message when there is no error', () => {
|
|
||||||
const wrapper = mountCheckbox({
|
|
||||||
label: 'Accept terms',
|
|
||||||
success: 'Valid',
|
|
||||||
modelValue: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(wrapper.get('label').classes()).toContain('text-m-success')
|
|
||||||
expect(wrapper.get('p').text()).toBe('Valid')
|
|
||||||
expect(wrapper.get('p').classes()).toContain('text-m-success')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,227 +0,0 @@
|
|||||||
<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 }}
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<p
|
|
||||||
v-if="hint || hasError || hasSuccess"
|
|
||||||
:id="`${inputId}-describedby`"
|
|
||||||
:class="mergedMessageClass"
|
|
||||||
>
|
|
||||||
{{ error || success || hint }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import {computed, useAttrs, useId} from 'vue'
|
|
||||||
import {twMerge} from 'tailwind-merge'
|
|
||||||
|
|
||||||
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
|
|
||||||
}>(),
|
|
||||||
{
|
|
||||||
id: '',
|
|
||||||
label: '',
|
|
||||||
name: '',
|
|
||||||
modelValue: undefined,
|
|
||||||
inputClass: '',
|
|
||||||
labelClass: '',
|
|
||||||
groupClass: '',
|
|
||||||
required: false,
|
|
||||||
disabled: false,
|
|
||||||
readonly: false,
|
|
||||||
hint: '',
|
|
||||||
error: '',
|
|
||||||
success: '',
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
const attrs = useAttrs()
|
|
||||||
const generatedId = useId()
|
|
||||||
|
|
||||||
const inputId = computed(() => props.id?.toString() || `malio-checkbox-${generatedId}`)
|
|
||||||
const isChecked = computed(() => !!props.modelValue)
|
|
||||||
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 mt-4 w-full',
|
|
||||||
props.groupClass,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
const mergedInputClass = computed(() =>
|
|
||||||
twMerge(
|
|
||||||
'inp-cbx peer',
|
|
||||||
props.inputClass,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
const mergedLabelClass = computed(() =>
|
|
||||||
twMerge(
|
|
||||||
'cbx text-black',
|
|
||||||
disabled.value ? 'cursor-not-allowed text-black/60' : '',
|
|
||||||
hasError.value ? 'text-m-error' : '',
|
|
||||||
hasSuccess.value ? 'text-m-success' : '',
|
|
||||||
props.labelClass,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
const mergedMessageClass = computed(() =>
|
|
||||||
twMerge(
|
|
||||||
'text-xs',
|
|
||||||
hasError.value
|
|
||||||
? 'text-m-error'
|
|
||||||
: 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
|
|
||||||
}
|
|
||||||
|
|
||||||
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(0, 0, 0);
|
|
||||||
transition: all 0.1s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.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-error span:first-child {
|
|
||||||
border-color: rgb(var(--m-error) / 1);
|
|
||||||
}
|
|
||||||
.cbx.text-m-error span:first-child svg {
|
|
||||||
stroke: rgb(var(--m-error) / 1);
|
|
||||||
}
|
|
||||||
.inp-cbx:checked + .cbx.text-m-error span:first-child {
|
|
||||||
border-color: rgb(var(--m-error) / 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>
|
|
||||||
@@ -114,7 +114,7 @@ describe('MalioCheckbox', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
expect(wrapper.get('input').attributes('aria-invalid')).toBe('true')
|
expect(wrapper.get('input').attributes('aria-invalid')).toBe('true')
|
||||||
expect(wrapper.get('label').classes()).toContain('text-m-danger')
|
expect(wrapper.get('label').classes()).toContain('text-m-error')
|
||||||
expect(wrapper.get('p').text()).toBe('You must accept')
|
expect(wrapper.get('p').text()).toBe('You must accept')
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ describe('MalioCheckbox', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
expect(wrapper.get('p').text()).toBe('Invalid')
|
expect(wrapper.get('p').text()).toBe('Invalid')
|
||||||
expect(wrapper.get('p').classes()).toContain('text-m-danger')
|
expect(wrapper.get('p').classes()).toContain('text-m-error')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows success styles and message when there is no error', () => {
|
it('shows success styles and message when there is no error', () => {
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ const mergedLabelClass = computed(() =>
|
|||||||
twMerge(
|
twMerge(
|
||||||
'cbx text-black',
|
'cbx text-black',
|
||||||
disabled.value ? 'cursor-not-allowed text-black/60' : '',
|
disabled.value ? 'cursor-not-allowed text-black/60' : '',
|
||||||
hasError.value ? 'text-m-danger' : '',
|
hasError.value ? 'text-m-error' : '',
|
||||||
hasSuccess.value ? 'text-m-success' : '',
|
hasSuccess.value ? 'text-m-success' : '',
|
||||||
props.labelClass,
|
props.labelClass,
|
||||||
),
|
),
|
||||||
@@ -120,7 +120,7 @@ const mergedMessageClass = computed(() =>
|
|||||||
twMerge(
|
twMerge(
|
||||||
'text-xs',
|
'text-xs',
|
||||||
hasError.value
|
hasError.value
|
||||||
? 'text-m-danger'
|
? 'text-m-error'
|
||||||
: hasSuccess.value
|
: hasSuccess.value
|
||||||
? 'text-m-success'
|
? 'text-m-success'
|
||||||
: 'text-m-muted',
|
: 'text-m-muted',
|
||||||
@@ -200,14 +200,14 @@ const onChange = (event: Event) => {
|
|||||||
stroke-dashoffset: 0;
|
stroke-dashoffset: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.inp-cbx + .cbx.text-m-danger span:first-child {
|
.inp-cbx + .cbx.text-m-error span:first-child {
|
||||||
border-color: rgb(var(--m-danger) / 1);
|
border-color: rgb(var(--m-error) / 1);
|
||||||
}
|
}
|
||||||
.cbx.text-m-danger span:first-child svg {
|
.cbx.text-m-error span:first-child svg {
|
||||||
stroke: rgb(var(--m-danger) / 1);
|
stroke: rgb(var(--m-error) / 1);
|
||||||
}
|
}
|
||||||
.inp-cbx:checked + .cbx.text-m-danger span:first-child {
|
.inp-cbx:checked + .cbx.text-m-error span:first-child {
|
||||||
border-color: rgb(var(--m-danger) / 1);
|
border-color: rgb(var(--m-error) / 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.inp-cbx + .cbx.text-m-success span:first-child {
|
.inp-cbx + .cbx.text-m-success span:first-child {
|
||||||
|
|||||||
@@ -1,67 +1,69 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div>
|
||||||
:class="mergedGroupClass"
|
<div
|
||||||
>
|
:class="mergedGroupClass"
|
||||||
<input
|
|
||||||
:id="inputId"
|
|
||||||
:name="name"
|
|
||||||
:autocomplete="autocomplete"
|
|
||||||
:class="mergedInputClass"
|
|
||||||
:required="required"
|
|
||||||
:maxlength="maxLength"
|
|
||||||
:minlength="minLength"
|
|
||||||
:disabled="disabled"
|
|
||||||
:value="currentValue"
|
|
||||||
:readonly="readonly"
|
|
||||||
:aria-invalid="!!error"
|
|
||||||
:aria-describedby="describedBy"
|
|
||||||
v-bind="attrs"
|
|
||||||
type="text"
|
|
||||||
inputmode="decimal"
|
|
||||||
placeholder="_"
|
|
||||||
@input="onInput"
|
|
||||||
@focus="isFocused = true"
|
|
||||||
@blur="onBlur"
|
|
||||||
>
|
>
|
||||||
|
<input
|
||||||
|
:id="inputId"
|
||||||
|
:name="name"
|
||||||
|
:autocomplete="autocomplete"
|
||||||
|
:class="mergedInputClass"
|
||||||
|
:required="required"
|
||||||
|
:maxlength="maxLength"
|
||||||
|
:minlength="minLength"
|
||||||
|
:disabled="disabled"
|
||||||
|
:value="currentValue"
|
||||||
|
:readonly="readonly"
|
||||||
|
:aria-invalid="!!error"
|
||||||
|
:aria-describedby="describedBy"
|
||||||
|
v-bind="attrs"
|
||||||
|
type="text"
|
||||||
|
inputmode="decimal"
|
||||||
|
placeholder="_"
|
||||||
|
@input="onInput"
|
||||||
|
@focus="isFocused = true"
|
||||||
|
@blur="onBlur"
|
||||||
|
>
|
||||||
|
|
||||||
<label
|
<label
|
||||||
v-if="label"
|
v-if="label"
|
||||||
:for="inputId"
|
:for="inputId"
|
||||||
:class="mergedLabelClass"
|
:class="mergedLabelClass"
|
||||||
>
|
>
|
||||||
{{ label }}
|
{{ label }}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<IconifyIcon
|
<IconifyIcon
|
||||||
v-if="iconName"
|
v-if="iconName"
|
||||||
:icon="iconName"
|
:icon="iconName"
|
||||||
:width="iconSize"
|
:width="iconSize"
|
||||||
:height="iconSize"
|
:height="iconSize"
|
||||||
data-test="icon"
|
data-test="icon"
|
||||||
:class="[
|
:class="[
|
||||||
hasError
|
|
||||||
? 'text-m-danger'
|
|
||||||
: hasSuccess
|
|
||||||
? 'text-m-success' : iconColor,
|
|
||||||
iconPositionClass,
|
|
||||||
]"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<p
|
|
||||||
v-if="hint || hasError || hasSuccess"
|
|
||||||
:id="`${inputId}-describedby`"
|
|
||||||
:class="[
|
|
||||||
hasError
|
hasError
|
||||||
? 'text-m-danger'
|
? 'text-m-danger'
|
||||||
: hasSuccess
|
: hasSuccess
|
||||||
? 'text-m-success'
|
? 'text-m-success' : iconColor,
|
||||||
: 'text-m-muted',
|
iconPositionClass,
|
||||||
'mt-1 text-xs ml-[2px] ',
|
|
||||||
]"
|
]"
|
||||||
>
|
/>
|
||||||
{{ hint || error || success }}
|
|
||||||
</p>
|
</div>
|
||||||
|
<p
|
||||||
|
v-if="hint || hasError || hasSuccess"
|
||||||
|
:id="`${inputId}-describedby`"
|
||||||
|
:class="[
|
||||||
|
hasError
|
||||||
|
? 'text-m-danger'
|
||||||
|
: hasSuccess
|
||||||
|
? 'text-m-success'
|
||||||
|
: 'text-m-muted',
|
||||||
|
'mt-1 text-xs ml-[2px] ',
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
{{ hint || error || success }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -133,7 +135,7 @@ const isFilled = computed(() => currentValue.value.trim().length > 0)
|
|||||||
|
|
||||||
const mergedGroupClass = computed(() =>
|
const mergedGroupClass = computed(() =>
|
||||||
twMerge(
|
twMerge(
|
||||||
'relative mt-4 flex h-12 w-full items-center',
|
'relative flex h-12 w-full items-center',
|
||||||
props.groupClass,
|
props.groupClass,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,68 +1,70 @@
|
|||||||
<template>
|
<template>
|
||||||
<div :class="mergedGroupClass" >
|
<div>
|
||||||
<label
|
<div :class="mergedGroupClass" >
|
||||||
v-if="label"
|
<label
|
||||||
:for="inputId"
|
v-if="label"
|
||||||
:class="mergedLabelClass"
|
:for="inputId"
|
||||||
>
|
:class="mergedLabelClass"
|
||||||
{{ label }}
|
>
|
||||||
</label>
|
{{ label }}
|
||||||
<button
|
</label>
|
||||||
type="button"
|
<button
|
||||||
:disabled="isMinusDisabled"
|
type="button"
|
||||||
@click="decrement"
|
:disabled="isMinusDisabled"
|
||||||
>
|
@click="decrement"
|
||||||
<IconifyIcon
|
>
|
||||||
icon="mdi:minus"
|
<IconifyIcon
|
||||||
:class="mergedButtonMinusClass"
|
icon="mdi:minus"
|
||||||
/>
|
:class="mergedButtonMinusClass"
|
||||||
</button>
|
/>
|
||||||
<input
|
</button>
|
||||||
:id="inputId"
|
<input
|
||||||
:name="name"
|
:id="inputId"
|
||||||
autocomplete="off"
|
:name="name"
|
||||||
:class="mergedInputClass"
|
autocomplete="off"
|
||||||
:style="inputWidthStyle"
|
:class="mergedInputClass"
|
||||||
:value="displayedValue"
|
:style="inputWidthStyle"
|
||||||
:required="required"
|
:value="displayedValue"
|
||||||
:disabled="disabled"
|
:required="required"
|
||||||
:readonly="readonly"
|
:disabled="disabled"
|
||||||
:aria-invalid="!!error"
|
:readonly="readonly"
|
||||||
:aria-describedby="describedBy"
|
:aria-invalid="!!error"
|
||||||
v-bind="attrs"
|
:aria-describedby="describedBy"
|
||||||
type="text"
|
v-bind="attrs"
|
||||||
inputmode="numeric"
|
type="text"
|
||||||
placeholder="_"
|
inputmode="numeric"
|
||||||
@input="onInput"
|
placeholder="_"
|
||||||
@focus="isFocused = true"
|
@input="onInput"
|
||||||
@blur="isFocused = false"
|
@focus="isFocused = true"
|
||||||
>
|
@blur="isFocused = false"
|
||||||
<button
|
>
|
||||||
type="button"
|
<button
|
||||||
:disabled="isPlusDisabled"
|
type="button"
|
||||||
@click="increment"
|
:disabled="isPlusDisabled"
|
||||||
>
|
@click="increment"
|
||||||
<IconifyIcon
|
>
|
||||||
icon="mdi:plus"
|
<IconifyIcon
|
||||||
:class="mergedButtonPlusClass"
|
icon="mdi:plus"
|
||||||
/>
|
:class="mergedButtonPlusClass"
|
||||||
</button>
|
/>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<p
|
||||||
|
v-if="hint || hasError || hasSuccess"
|
||||||
|
:id="`${inputId}-describedby`"
|
||||||
|
:class="[
|
||||||
|
hasError
|
||||||
|
? 'text-m-danger'
|
||||||
|
: hasSuccess
|
||||||
|
? 'text-m-success'
|
||||||
|
: 'text-m-muted',
|
||||||
|
'text-xs ml-[2px] ',
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
{{ hint || error || success }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p
|
|
||||||
v-if="hint || hasError || hasSuccess"
|
|
||||||
:id="`${inputId}-describedby`"
|
|
||||||
:class="[
|
|
||||||
hasError
|
|
||||||
? 'text-m-danger'
|
|
||||||
: hasSuccess
|
|
||||||
? 'text-m-success'
|
|
||||||
: 'text-m-muted',
|
|
||||||
'text-xs ml-[2px] ',
|
|
||||||
]"
|
|
||||||
>
|
|
||||||
{{ hint || error || success }}
|
|
||||||
</p>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -170,7 +172,7 @@ const isPlusDisabled = computed(() =>
|
|||||||
|
|
||||||
const mergedGroupClass = computed(() =>
|
const mergedGroupClass = computed(() =>
|
||||||
twMerge(
|
twMerge(
|
||||||
'relative mt-4 flex h-12 w-full items-center',
|
'relative flex h-12 w-full items-center',
|
||||||
props.groupClass,
|
props.groupClass,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,67 +1,69 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div>
|
||||||
:class="mergedGroupClass"
|
<div
|
||||||
>
|
:class="mergedGroupClass"
|
||||||
<input
|
|
||||||
:id="inputId"
|
|
||||||
:name="name"
|
|
||||||
:autocomplete="autocomplete"
|
|
||||||
:class="mergedInputClass"
|
|
||||||
:required="required"
|
|
||||||
:maxlength="maxLength"
|
|
||||||
:minlength="minLength"
|
|
||||||
:disabled="disabled"
|
|
||||||
:value="currentValue"
|
|
||||||
:readonly="readonly"
|
|
||||||
:aria-invalid="!!error"
|
|
||||||
:aria-describedby="describedBy"
|
|
||||||
v-bind="attrs"
|
|
||||||
placeholder="_"
|
|
||||||
:type="isPasswordVisible ? 'text' : 'password'"
|
|
||||||
@input="onInput"
|
|
||||||
@focus="isFocused = true"
|
|
||||||
@blur="isFocused = false"
|
|
||||||
>
|
>
|
||||||
|
<input
|
||||||
|
:id="inputId"
|
||||||
|
:name="name"
|
||||||
|
:autocomplete="autocomplete"
|
||||||
|
:class="mergedInputClass"
|
||||||
|
:required="required"
|
||||||
|
:maxlength="maxLength"
|
||||||
|
:minlength="minLength"
|
||||||
|
:disabled="disabled"
|
||||||
|
:value="currentValue"
|
||||||
|
:readonly="readonly"
|
||||||
|
:aria-invalid="!!error"
|
||||||
|
:aria-describedby="describedBy"
|
||||||
|
v-bind="attrs"
|
||||||
|
placeholder="_"
|
||||||
|
:type="isPasswordVisible ? 'text' : 'password'"
|
||||||
|
@input="onInput"
|
||||||
|
@focus="isFocused = true"
|
||||||
|
@blur="isFocused = false"
|
||||||
|
>
|
||||||
|
|
||||||
<label
|
<label
|
||||||
v-if="label"
|
v-if="label"
|
||||||
:for="inputId"
|
:for="inputId"
|
||||||
:class="mergedLabelClass"
|
:class="mergedLabelClass"
|
||||||
>
|
>
|
||||||
{{ label }}
|
{{ label }}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<IconifyIcon
|
<IconifyIcon
|
||||||
v-if="displayIcon"
|
v-if="displayIcon"
|
||||||
:icon="isPasswordVisible ? 'mdi:eye-outline' : 'mdi:eye-off-outline'"
|
:icon="isPasswordVisible ? 'mdi:eye-outline' : 'mdi:eye-off-outline'"
|
||||||
:width="24"
|
:width="24"
|
||||||
:height="24"
|
:height="24"
|
||||||
data-test="icon"
|
data-test="icon"
|
||||||
:class="[
|
:class="[
|
||||||
hasError
|
|
||||||
? 'text-m-danger'
|
|
||||||
: hasSuccess
|
|
||||||
? 'text-m-success' : 'text-m-muted',
|
|
||||||
'cursor-pointer absolute right-[10px] top-1/2 -translate-y-1/2',
|
|
||||||
]"
|
|
||||||
@click="toggleVisibility"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<p
|
|
||||||
v-if="hint || hasError || hasSuccess"
|
|
||||||
:id="`${inputId}-describedby`"
|
|
||||||
:class="[
|
|
||||||
hasError
|
hasError
|
||||||
? 'text-m-danger'
|
? 'text-m-danger'
|
||||||
: hasSuccess
|
: hasSuccess
|
||||||
? 'text-m-success'
|
? 'text-m-success' : 'text-m-muted',
|
||||||
: 'text-m-muted',
|
'cursor-pointer absolute right-[10px] top-1/2 -translate-y-1/2',
|
||||||
'mt-1 text-xs ml-[2px] ',
|
|
||||||
]"
|
]"
|
||||||
>
|
@click="toggleVisibility"
|
||||||
{{ hint || error || success }}
|
/>
|
||||||
</p>
|
|
||||||
|
</div>
|
||||||
|
<p
|
||||||
|
v-if="hint || hasError || hasSuccess"
|
||||||
|
:id="`${inputId}-describedby`"
|
||||||
|
:class="[
|
||||||
|
hasError
|
||||||
|
? 'text-m-danger'
|
||||||
|
: hasSuccess
|
||||||
|
? 'text-m-success'
|
||||||
|
: 'text-m-muted',
|
||||||
|
'mt-1 text-xs ml-[2px] ',
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
{{ hint || error || success }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -132,7 +134,7 @@ const hasSuccess = computed(() => !!props.success)
|
|||||||
const isFilled = computed(() => currentValue.value.trim().length > 0)
|
const isFilled = computed(() => currentValue.value.trim().length > 0)
|
||||||
const mergedGroupClass = computed(() =>
|
const mergedGroupClass = computed(() =>
|
||||||
twMerge(
|
twMerge(
|
||||||
'relative mt-4 flex h-12 w-full items-center',
|
'relative flex h-12 w-full items-center',
|
||||||
props.groupClass,
|
props.groupClass,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,67 +1,69 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div>
|
||||||
:class="mergedGroupClass"
|
<div
|
||||||
>
|
:class="mergedGroupClass"
|
||||||
<input
|
|
||||||
:id="inputId"
|
|
||||||
v-maska="mask"
|
|
||||||
:name="name"
|
|
||||||
:autocomplete="autocomplete"
|
|
||||||
:class="mergedInputClass"
|
|
||||||
:required="required"
|
|
||||||
:maxlength="maxLength"
|
|
||||||
:minlength="minLength"
|
|
||||||
:disabled="disabled"
|
|
||||||
:value="currentValue"
|
|
||||||
:readonly="readonly"
|
|
||||||
:aria-invalid="!!error"
|
|
||||||
:aria-describedby="describedBy"
|
|
||||||
v-bind="attrs"
|
|
||||||
placeholder="_"
|
|
||||||
type="text"
|
|
||||||
@input="onInput"
|
|
||||||
@focus="isFocused = true"
|
|
||||||
@blur="isFocused = false"
|
|
||||||
>
|
>
|
||||||
|
<input
|
||||||
|
:id="inputId"
|
||||||
|
v-maska="mask"
|
||||||
|
:name="name"
|
||||||
|
:autocomplete="autocomplete"
|
||||||
|
:class="mergedInputClass"
|
||||||
|
:required="required"
|
||||||
|
:maxlength="maxLength"
|
||||||
|
:minlength="minLength"
|
||||||
|
:disabled="disabled"
|
||||||
|
:value="currentValue"
|
||||||
|
:readonly="readonly"
|
||||||
|
:aria-invalid="!!error"
|
||||||
|
:aria-describedby="describedBy"
|
||||||
|
v-bind="attrs"
|
||||||
|
placeholder="_"
|
||||||
|
type="text"
|
||||||
|
@input="onInput"
|
||||||
|
@focus="isFocused = true"
|
||||||
|
@blur="isFocused = false"
|
||||||
|
>
|
||||||
|
|
||||||
<label
|
<label
|
||||||
v-if="label"
|
v-if="label"
|
||||||
:for="inputId"
|
:for="inputId"
|
||||||
:class="mergedLabelClass"
|
:class="mergedLabelClass"
|
||||||
>
|
>
|
||||||
{{ label }}
|
{{ label }}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<IconifyIcon
|
<IconifyIcon
|
||||||
v-if="iconName"
|
v-if="iconName"
|
||||||
:icon="iconName"
|
:icon="iconName"
|
||||||
:width="iconSize"
|
:width="iconSize"
|
||||||
:height="iconSize"
|
:height="iconSize"
|
||||||
data-test="icon"
|
data-test="icon"
|
||||||
:class="[
|
:class="[
|
||||||
hasError
|
|
||||||
? 'text-m-danger'
|
|
||||||
: hasSuccess
|
|
||||||
? 'text-m-success' : iconColor,
|
|
||||||
iconPositionClass,
|
|
||||||
]"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<p
|
|
||||||
v-if="hint || hasError || hasSuccess"
|
|
||||||
:id="`${inputId}-describedby`"
|
|
||||||
:class="[
|
|
||||||
hasError
|
hasError
|
||||||
? 'text-m-danger'
|
? 'text-m-danger'
|
||||||
: hasSuccess
|
: hasSuccess
|
||||||
? 'text-m-success'
|
? 'text-m-success' : iconColor,
|
||||||
: 'text-m-muted',
|
iconPositionClass,
|
||||||
'mt-1 text-xs ml-[2px] ',
|
|
||||||
]"
|
]"
|
||||||
>
|
/>
|
||||||
{{ hint || error || success }}
|
|
||||||
</p>
|
</div>
|
||||||
|
<p
|
||||||
|
v-if="hint || hasError || hasSuccess"
|
||||||
|
:id="`${inputId}-describedby`"
|
||||||
|
:class="[
|
||||||
|
hasError
|
||||||
|
? 'text-m-danger'
|
||||||
|
: hasSuccess
|
||||||
|
? 'text-m-success'
|
||||||
|
: 'text-m-muted',
|
||||||
|
'mt-1 text-xs ml-[2px] ',
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
{{ hint || error || success }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -138,7 +140,7 @@ const hasSuccess = computed(() => !!props.success)
|
|||||||
const isFilled = computed(() => currentValue.value.trim().length > 0)
|
const isFilled = computed(() => currentValue.value.trim().length > 0)
|
||||||
const mergedGroupClass = computed(() =>
|
const mergedGroupClass = computed(() =>
|
||||||
twMerge(
|
twMerge(
|
||||||
'relative mt-4 flex h-12 w-full items-center',
|
'relative flex h-12 w-full items-center',
|
||||||
props.groupClass,
|
props.groupClass,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,70 +1,72 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div>
|
||||||
:class="mergedGroupClass"
|
<div
|
||||||
>
|
:class="mergedGroupClass"
|
||||||
<input
|
|
||||||
ref="fileInputRef"
|
|
||||||
type="file"
|
|
||||||
:accept="accept"
|
|
||||||
class="hidden"
|
|
||||||
:disabled="disabled"
|
|
||||||
@change="onFileChange"
|
|
||||||
>
|
>
|
||||||
|
<input
|
||||||
|
ref="fileInputRef"
|
||||||
|
type="file"
|
||||||
|
:accept="accept"
|
||||||
|
class="hidden"
|
||||||
|
:disabled="disabled"
|
||||||
|
@change="onFileChange"
|
||||||
|
>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
:id="inputId"
|
:id="inputId"
|
||||||
:class="mergedInputClass"
|
:class="mergedInputClass"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
:value="currentDisplayValue"
|
:value="currentDisplayValue"
|
||||||
:readonly="true"
|
:readonly="true"
|
||||||
:aria-invalid="!!error"
|
:aria-invalid="!!error"
|
||||||
:aria-describedby="describedBy"
|
:aria-describedby="describedBy"
|
||||||
v-bind="attrs"
|
v-bind="attrs"
|
||||||
placeholder="_"
|
placeholder="_"
|
||||||
type="text"
|
type="text"
|
||||||
@click="openFilePicker"
|
@click="openFilePicker"
|
||||||
@focus="isFocused = true"
|
@focus="isFocused = true"
|
||||||
@blur="isFocused = false"
|
@blur="isFocused = false"
|
||||||
>
|
>
|
||||||
|
|
||||||
<label
|
<label
|
||||||
v-if="label"
|
v-if="label"
|
||||||
:for="inputId"
|
:for="inputId"
|
||||||
:class="mergedLabelClass"
|
:class="mergedLabelClass"
|
||||||
>
|
>
|
||||||
{{ label }}
|
{{ label }}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<IconifyIcon
|
<IconifyIcon
|
||||||
v-if="displayIcon"
|
v-if="displayIcon"
|
||||||
icon="mdi:cloud-arrow-up-outline"
|
icon="mdi:cloud-arrow-up-outline"
|
||||||
:width="24"
|
:width="24"
|
||||||
:height="24"
|
:height="24"
|
||||||
data-test="icon"
|
data-test="icon"
|
||||||
:class="[
|
:class="[
|
||||||
hasError
|
|
||||||
? 'text-m-danger'
|
|
||||||
: hasSuccess
|
|
||||||
? 'text-m-success' : 'text-m-muted',
|
|
||||||
'pointer-events-none absolute right-[10px] top-1/2 -translate-y-1/2',
|
|
||||||
]"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<p
|
|
||||||
v-if="hint || hasError || hasSuccess"
|
|
||||||
:id="`${inputId}-describedby`"
|
|
||||||
:class="[
|
|
||||||
hasError
|
hasError
|
||||||
? 'text-m-danger'
|
? 'text-m-danger'
|
||||||
: hasSuccess
|
: hasSuccess
|
||||||
? 'text-m-success'
|
? 'text-m-success' : 'text-m-muted',
|
||||||
: 'text-m-muted',
|
'pointer-events-none absolute right-[10px] top-1/2 -translate-y-1/2',
|
||||||
'mt-1 text-xs ml-[2px] ',
|
|
||||||
]"
|
]"
|
||||||
>
|
/>
|
||||||
{{ hint || error || success }}
|
|
||||||
</p>
|
</div>
|
||||||
|
<p
|
||||||
|
v-if="hint || hasError || hasSuccess"
|
||||||
|
:id="`${inputId}-describedby`"
|
||||||
|
:class="[
|
||||||
|
hasError
|
||||||
|
? 'text-m-danger'
|
||||||
|
: hasSuccess
|
||||||
|
? 'text-m-success'
|
||||||
|
: 'text-m-muted',
|
||||||
|
'mt-1 text-xs ml-[2px] ',
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
{{ hint || error || success }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -121,7 +123,7 @@ const hasSuccess = computed(() => !!props.success)
|
|||||||
const isFilled = computed(() => currentDisplayValue.value.trim().length > 0)
|
const isFilled = computed(() => currentDisplayValue.value.trim().length > 0)
|
||||||
const mergedGroupClass = computed(() =>
|
const mergedGroupClass = computed(() =>
|
||||||
twMerge(
|
twMerge(
|
||||||
'relative mt-4 flex h-12 w-full items-center',
|
'relative flex h-12 w-full items-center',
|
||||||
props.groupClass,
|
props.groupClass,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div>
|
||||||
ref="root"
|
<div
|
||||||
:class="mergedGroupClass"
|
ref="root"
|
||||||
>
|
:class="mergedGroupClass"
|
||||||
|
>
|
||||||
<button
|
<button
|
||||||
:id="buttonId"
|
:id="buttonId"
|
||||||
type="button"
|
type="button"
|
||||||
@@ -133,21 +134,22 @@
|
|||||||
{{ opt.label || '\u00A0' }}
|
{{ opt.label || '\u00A0' }}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
|
<p
|
||||||
|
v-if="hint || hasError || hasSuccess"
|
||||||
|
:id="`${buttonId}-describedby`"
|
||||||
|
:class="[
|
||||||
|
hasError
|
||||||
|
? 'text-m-danger'
|
||||||
|
: hasSuccess
|
||||||
|
? 'text-m-success'
|
||||||
|
: 'text-m-muted',
|
||||||
|
'mt-1 ml-[2px] text-xs',
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
{{ error || success || hint }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p
|
|
||||||
v-if="hint || hasError || hasSuccess"
|
|
||||||
:id="`${buttonId}-describedby`"
|
|
||||||
:class="[
|
|
||||||
hasError
|
|
||||||
? 'text-m-danger'
|
|
||||||
: hasSuccess
|
|
||||||
? 'text-m-success'
|
|
||||||
: 'text-m-muted',
|
|
||||||
'mt-1 ml-[2px] text-xs',
|
|
||||||
]"
|
|
||||||
>
|
|
||||||
{{ error || success || hint }}
|
|
||||||
</p>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -211,7 +213,7 @@ const normalizedOptions = computed<Option[]>(() => [
|
|||||||
...props.options,
|
...props.options,
|
||||||
])
|
])
|
||||||
const mergedGroupClass = computed(() =>
|
const mergedGroupClass = computed(() =>
|
||||||
twMerge('relative mt-4 w-full', props.minWidth, props.maxWidth, props.groupClass),
|
twMerge('relative w-full', props.minWidth, props.maxWidth, props.groupClass),
|
||||||
)
|
)
|
||||||
const hasError = computed(() => !!props.error)
|
const hasError = computed(() => !!props.error)
|
||||||
const hasSuccess = computed(() => !!props.success && !hasError.value)
|
const hasSuccess = computed(() => !!props.success && !hasError.value)
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div>
|
||||||
ref="root"
|
<div
|
||||||
class="relative mt-4 w-full"
|
ref="root"
|
||||||
:class="[minWidth, maxWidth]"
|
class="relative w-full"
|
||||||
>
|
:class="[minWidth, maxWidth]"
|
||||||
|
>
|
||||||
<button
|
<button
|
||||||
:id="buttonId"
|
:id="buttonId"
|
||||||
type="button"
|
type="button"
|
||||||
@@ -184,21 +185,22 @@
|
|||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
|
<p
|
||||||
|
v-if="hint || hasError || hasSuccess"
|
||||||
|
:id="`${buttonId}-describedby`"
|
||||||
|
:class="[
|
||||||
|
hasError
|
||||||
|
? 'text-m-danger'
|
||||||
|
: hasSuccess
|
||||||
|
? 'text-m-success'
|
||||||
|
: 'text-m-muted',
|
||||||
|
'mt-1 ml-[2px] text-xs',
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
{{ error || success || hint }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p
|
|
||||||
v-if="hint || hasError || hasSuccess"
|
|
||||||
:id="`${buttonId}-describedby`"
|
|
||||||
:class="[
|
|
||||||
hasError
|
|
||||||
? 'text-m-danger'
|
|
||||||
: hasSuccess
|
|
||||||
? 'text-m-success'
|
|
||||||
: 'text-m-muted',
|
|
||||||
'mt-1 ml-[2px] text-xs',
|
|
||||||
]"
|
|
||||||
>
|
|
||||||
{{ error || success || hint }}
|
|
||||||
</p>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
<template>
|
|
||||||
<Story title="Input/Checkbox">
|
|
||||||
<MalioCheckbox
|
|
||||||
v-model="simpleValue"
|
|
||||||
label="Accepter les conditions"
|
|
||||||
/>
|
|
||||||
</Story>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<docs lang="md">
|
|
||||||
# MalioCheckbox
|
|
||||||
|
|
||||||
Composant checkbox custom avec `v-model`, message d'aide, et états visuels
|
|
||||||
`error` / `success`.
|
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
|
||||||
|
|
||||||
## Props
|
|
||||||
|
|
||||||
### id
|
|
||||||
|
|
||||||
- Type: `string`
|
|
||||||
- Description: Identifiant HTML du checkbox.
|
|
||||||
- Comportement: si absent, un id unique est généré automatiquement.
|
|
||||||
|
|
||||||
### label
|
|
||||||
|
|
||||||
- Type: `string`
|
|
||||||
- Description: Texte affiche a cote de la case.
|
|
||||||
|
|
||||||
### name
|
|
||||||
|
|
||||||
- Type: `string`
|
|
||||||
- Description: Attribut `name` du champ.
|
|
||||||
|
|
||||||
### modelValue
|
|
||||||
|
|
||||||
- Type: `boolean | null | undefined`
|
|
||||||
- Description: État coche du composant.
|
|
||||||
|
|
||||||
### inputClass
|
|
||||||
|
|
||||||
- Type: `string`
|
|
||||||
- Description: Classes supplémentaires appliquées a l'input natif.
|
|
||||||
|
|
||||||
### labelClass
|
|
||||||
|
|
||||||
- Type: `string`
|
|
||||||
- Description: Classes supplémentaires appliquées au label.
|
|
||||||
|
|
||||||
### groupClass
|
|
||||||
|
|
||||||
- Type: `string`
|
|
||||||
- Description: Classes supplémentaires appliquées au conteneur.
|
|
||||||
|
|
||||||
### required
|
|
||||||
|
|
||||||
- Type: `boolean`
|
|
||||||
- Description: Ajoute l'attribut HTML `required`.
|
|
||||||
|
|
||||||
### disabled
|
|
||||||
|
|
||||||
- Type: `boolean`
|
|
||||||
- Description: Désactive le composant.
|
|
||||||
|
|
||||||
### readonly
|
|
||||||
|
|
||||||
- Type: `boolean`
|
|
||||||
- Description: Empêche la mise a jour du `v-model` tout en gardant
|
|
||||||
l'affichage courant.
|
|
||||||
|
|
||||||
### hint
|
|
||||||
|
|
||||||
- Type: `string`
|
|
||||||
- Description: Message d'aide affiche sous le checkbox.
|
|
||||||
|
|
||||||
### error
|
|
||||||
|
|
||||||
- Type: `string`
|
|
||||||
- Description: Message d'erreur.
|
|
||||||
- Effet: prioritaire sur `success`, applique `aria-invalid` et la couleur
|
|
||||||
d'erreur au texte et a la case.
|
|
||||||
|
|
||||||
### success
|
|
||||||
|
|
||||||
- Type: `string`
|
|
||||||
- Description: Message de succès.
|
|
||||||
- Effet: applique la couleur de succès au texte et a la case si `error`
|
|
||||||
est absent.
|
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
|
||||||
|
|
||||||
## Accessibilité
|
|
||||||
|
|
||||||
- `aria-invalid` est active si `error` existe.
|
|
||||||
- `aria-describedby` pointe vers le message affiche.
|
|
||||||
- L'input natif reste present pour conserver le comportement formulaire.
|
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
|
||||||
|
|
||||||
## Event
|
|
||||||
|
|
||||||
### update:modelValue
|
|
||||||
|
|
||||||
- Émis a chaque changement de l'état coche.
|
|
||||||
- Retourne un booléen `true` ou `false`.
|
|
||||||
</docs>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import {ref} from 'vue'
|
|
||||||
import MalioCheckbox from '../components/malio/Checkbox.vue'
|
|
||||||
|
|
||||||
const simpleValue = ref(false)
|
|
||||||
</script>
|
|
||||||
@@ -6,7 +6,8 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"app/**",
|
"app/**",
|
||||||
"nuxt.config.ts",
|
"nuxt.config.ts",
|
||||||
"README.md"
|
"README.md",
|
||||||
|
"COMPONENTS.md"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nuxi dev .playground",
|
"dev": "nuxi dev .playground",
|
||||||
|
|||||||
Reference in New Issue
Block a user