mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-29 19:30:37 +01:00
feat(Toggle): add loading prop (#1546)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
committed by
GitHub
parent
224ec3c1fb
commit
e1e05af0ba
@@ -52,6 +52,19 @@ excludedProps:
|
|||||||
---
|
---
|
||||||
::
|
::
|
||||||
|
|
||||||
|
### Loading :u-badge{label="New" class="align-middle ml-2 !rounded-full" variant="subtle"}
|
||||||
|
|
||||||
|
Use the `loading` prop to show a loading icon and disable the Toggle.
|
||||||
|
|
||||||
|
Use the `loading-icon` prop to set a different icon or change it globally in `ui.toggle.default.loadingIcon`. Defaults to `i-heroicons-arrow-path-20-solid`.
|
||||||
|
|
||||||
|
::component-card
|
||||||
|
---
|
||||||
|
props:
|
||||||
|
loading: true
|
||||||
|
---
|
||||||
|
::
|
||||||
|
|
||||||
### Disabled
|
### Disabled
|
||||||
|
|
||||||
Use the `disabled` prop to disable the Toggle.
|
Use the `disabled` prop to disable the Toggle.
|
||||||
|
|||||||
@@ -3,15 +3,26 @@
|
|||||||
:id="inputId"
|
:id="inputId"
|
||||||
v-model="active"
|
v-model="active"
|
||||||
:name="name"
|
:name="name"
|
||||||
:disabled="disabled"
|
:disabled="disabled || loading"
|
||||||
:class="switchClass"
|
:class="switchClass"
|
||||||
v-bind="attrs"
|
v-bind="attrs"
|
||||||
>
|
>
|
||||||
<span :class="containerClass">
|
<span :class="containerClass">
|
||||||
<span v-if="onIcon" :class="[active ? ui.icon.active : ui.icon.inactive, ui.icon.base]" aria-hidden="true">
|
<span v-if="loading" :class="[ui.icon.active, ui.icon.base]" aria-hidden="true">
|
||||||
|
<UIcon :name="loadingIcon" :class="loadingIconClass" />
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="!loading && onIcon"
|
||||||
|
:class="[active ? ui.icon.active : ui.icon.inactive, ui.icon.base]"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
<UIcon :name="onIcon" :class="onIconClass" />
|
<UIcon :name="onIcon" :class="onIconClass" />
|
||||||
</span>
|
</span>
|
||||||
<span v-if="offIcon" :class="[active ? ui.icon.inactive : ui.icon.active, ui.icon.base]" aria-hidden="true">
|
<span
|
||||||
|
v-if="!loading && offIcon"
|
||||||
|
:class="[active ? ui.icon.inactive : ui.icon.active, ui.icon.base]"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
<UIcon :name="offIcon" :class="offIconClass" />
|
<UIcon :name="offIcon" :class="offIconClass" />
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
@@ -58,6 +69,10 @@ export default defineComponent({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
|
loading: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
onIcon: {
|
onIcon: {
|
||||||
type: String,
|
type: String,
|
||||||
default: () => config.default.onIcon
|
default: () => config.default.onIcon
|
||||||
@@ -66,6 +81,10 @@ export default defineComponent({
|
|||||||
type: String,
|
type: String,
|
||||||
default: () => config.default.offIcon
|
default: () => config.default.offIcon
|
||||||
},
|
},
|
||||||
|
loadingIcon: {
|
||||||
|
type: String,
|
||||||
|
default: () => config.default.loadingIcon
|
||||||
|
},
|
||||||
color: {
|
color: {
|
||||||
type: String as PropType<ToggleColor>,
|
type: String as PropType<ToggleColor>,
|
||||||
default: () => config.default.color,
|
default: () => config.default.color,
|
||||||
@@ -137,6 +156,13 @@ export default defineComponent({
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const loadingIconClass = computed(() => {
|
||||||
|
return twJoin(
|
||||||
|
ui.value.icon.size[props.size],
|
||||||
|
color.value && ui.value.icon.loading.replaceAll('{color}', color.value)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
provideUseId(() => useId())
|
provideUseId(() => useId())
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -150,7 +176,8 @@ export default defineComponent({
|
|||||||
switchClass,
|
switchClass,
|
||||||
containerClass,
|
containerClass,
|
||||||
onIconClass,
|
onIconClass,
|
||||||
offIconClass
|
offIconClass,
|
||||||
|
loadingIconClass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -49,12 +49,14 @@ export default {
|
|||||||
'2xl': 'h-6 w-6'
|
'2xl': 'h-6 w-6'
|
||||||
},
|
},
|
||||||
on: 'text-{color}-500 dark:text-{color}-400',
|
on: 'text-{color}-500 dark:text-{color}-400',
|
||||||
off: 'text-gray-400 dark:text-gray-500'
|
off: 'text-gray-400 dark:text-gray-500',
|
||||||
|
loading: 'animate-spin text-{color}-500 dark:text-{color}-400'
|
||||||
},
|
},
|
||||||
default: {
|
default: {
|
||||||
onIcon: null,
|
onIcon: null,
|
||||||
offIcon: null,
|
offIcon: null,
|
||||||
|
loadingIcon: 'i-heroicons-arrow-path-20-solid',
|
||||||
color: 'primary',
|
color: 'primary',
|
||||||
size: 'md'
|
size: 'md'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user