mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
refactor: ButtonItem typing
This commit is contained in:
parent
32da3d9ee4
commit
906d9ca95c
2 changed files with 27 additions and 18 deletions
|
@ -1,24 +1,18 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
|
|
||||||
const props = withDefaults(
|
import type { ButtonItemProps } from '@/types/form'
|
||||||
defineProps<{
|
|
||||||
label?: string
|
|
||||||
id?: string
|
|
||||||
type?: 'success' | 'info' | 'warning' | 'danger'
|
|
||||||
icon?: string
|
|
||||||
enabled?: string | boolean
|
|
||||||
}>(),
|
|
||||||
{
|
|
||||||
label: undefined,
|
|
||||||
id: undefined,
|
|
||||||
type: 'success',
|
|
||||||
icon: undefined,
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
const emit = defineEmits(['action'])
|
const props = withDefaults(defineProps<ButtonItemProps>(), {
|
||||||
|
id: undefined,
|
||||||
|
enabled: true,
|
||||||
|
icon: undefined,
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
action: [value: ButtonItemProps['id']]
|
||||||
|
}>()
|
||||||
|
|
||||||
const icon = computed(() => {
|
const icon = computed(() => {
|
||||||
const icons = {
|
const icons = {
|
||||||
|
@ -36,9 +30,9 @@ const icon = computed(() => {
|
||||||
<BButton
|
<BButton
|
||||||
:id="id"
|
:id="id"
|
||||||
:variant="type"
|
:variant="type"
|
||||||
@click="emit('action', $event)"
|
|
||||||
:disabled="!enabled"
|
:disabled="!enabled"
|
||||||
class="d-block mb-3"
|
class="d-block mb-3"
|
||||||
|
@click="emit('action', id)"
|
||||||
>
|
>
|
||||||
<YIcon :iname="icon" class="me-2" />
|
<YIcon :iname="icon" class="me-2" />
|
||||||
<span v-html="label" />
|
<span v-html="label" />
|
||||||
|
|
|
@ -1,6 +1,21 @@
|
||||||
import type { BaseValidation } from '@vuelidate/core'
|
import type { BaseValidation } from '@vuelidate/core'
|
||||||
type StateValidation = false | null
|
type StateValidation = false | null
|
||||||
|
|
||||||
|
// DISPLAY
|
||||||
|
|
||||||
|
type BaseDisplayItemProps = {
|
||||||
|
label: string
|
||||||
|
id?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ButtonItemProps = BaseDisplayItemProps & {
|
||||||
|
// FIXME compute enabled JSExpression
|
||||||
|
enabled?: boolean
|
||||||
|
icon?: string
|
||||||
|
type?: StateVariant
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// WRITABLE
|
// WRITABLE
|
||||||
|
|
||||||
type BaseWritableItemProps = {
|
type BaseWritableItemProps = {
|
||||||
|
|
Loading…
Reference in a new issue