add optional secondary action button
This commit is contained in:
@@ -33,15 +33,22 @@ window.app.component('lnbits-dialog', {
|
|||||||
action: {
|
action: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: null
|
default: null
|
||||||
|
},
|
||||||
|
secondaryAction: {
|
||||||
|
type: Object,
|
||||||
|
default: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
emits: ['update:show', 'hide', 'cancel', 'action'],
|
emits: ['update:show', 'hide', 'cancel', 'action', 'secondary-action'],
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
hasAction() {
|
hasAction() {
|
||||||
return !!(this.action && this.action.label)
|
return !!(this.action && this.action.label)
|
||||||
},
|
},
|
||||||
|
hasSecondaryAction() {
|
||||||
|
return !!(this.secondaryAction && this.secondaryAction.label)
|
||||||
|
},
|
||||||
|
|
||||||
actionProps() {
|
actionProps() {
|
||||||
const action = this.action || {}
|
const action = this.action || {}
|
||||||
@@ -50,7 +57,19 @@ window.app.component('lnbits-dialog', {
|
|||||||
label: action.label || 'Action',
|
label: action.label || 'Action',
|
||||||
color: action.color || 'primary',
|
color: action.color || 'primary',
|
||||||
loading: !!action.loading,
|
loading: !!action.loading,
|
||||||
disable: !!action.disable
|
disable: !!action.disable,
|
||||||
|
closePopup: !!action.closePopup
|
||||||
|
}
|
||||||
|
},
|
||||||
|
secondaryActionProps() {
|
||||||
|
const action = this.secondaryAction || {}
|
||||||
|
return {
|
||||||
|
icon: action.icon || null,
|
||||||
|
label: action.label || 'Secondary',
|
||||||
|
color: action.color || 'secondary',
|
||||||
|
loading: !!action.loading,
|
||||||
|
disable: !!action.disable,
|
||||||
|
closePopup: !!action.closePopup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -83,6 +102,22 @@ window.app.component('lnbits-dialog', {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('lnbits-dialog action handler failed', error)
|
console.error('lnbits-dialog action handler failed', error)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
async handleSecondaryAction() {
|
||||||
|
try {
|
||||||
|
if (
|
||||||
|
this.secondaryAction &&
|
||||||
|
typeof this.secondaryAction.handler === 'function'
|
||||||
|
) {
|
||||||
|
await this.secondaryAction.handler()
|
||||||
|
}
|
||||||
|
this.$emit('secondary-action')
|
||||||
|
if (this.secondaryAction && this.secondaryAction.closeOnClick) {
|
||||||
|
this.handleModelUpdate(false)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('lnbits-dialog secondary action handler failed', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
|
||||||
<q-card-actions
|
<q-card-actions
|
||||||
v-if="showCancel || hasAction"
|
v-if="showCancel || hasAction || hasSecondaryAction"
|
||||||
class="q-mt-lg"
|
class="q-mt-lg"
|
||||||
align="right"
|
align="right"
|
||||||
>
|
>
|
||||||
@@ -32,6 +32,18 @@
|
|||||||
|
|
||||||
<q-space></q-space>
|
<q-space></q-space>
|
||||||
|
|
||||||
|
<q-btn
|
||||||
|
v-if="hasSecondaryAction"
|
||||||
|
:icon="secondaryActionProps.icon"
|
||||||
|
:color="secondaryActionProps.color"
|
||||||
|
:label="secondaryActionProps.label"
|
||||||
|
:loading="secondaryActionProps.loading"
|
||||||
|
:disable="secondaryActionProps.disable"
|
||||||
|
@click="handleSecondaryAction"
|
||||||
|
v-close-popup="secondaryActionProps.closePopup"
|
||||||
|
class="q-mr-sm"
|
||||||
|
></q-btn>
|
||||||
|
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="hasAction"
|
v-if="hasAction"
|
||||||
:icon="actionProps.icon"
|
:icon="actionProps.icon"
|
||||||
@@ -40,6 +52,7 @@
|
|||||||
:loading="actionProps.loading"
|
:loading="actionProps.loading"
|
||||||
:disable="actionProps.disable"
|
:disable="actionProps.disable"
|
||||||
@click="handleAction"
|
@click="handleAction"
|
||||||
|
v-close-popup="actionProps.closePopup"
|
||||||
></q-btn>
|
></q-btn>
|
||||||
</q-card-actions>
|
</q-card-actions>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|||||||
Reference in New Issue
Block a user