UNPKG

@nextcloud/vue

Version:
131 lines (130 loc) 4.15 kB
import { ref } from "vue"; import { r as register, d as t31, a as t } from "./_l10n-BEfeU7gr.mjs"; import { N as NcButton } from "./NcButton-CWPBzbcC.mjs"; import { N as NcIconSvgWrapper } from "./NcIconSvgWrapper-BreCg8pX.mjs"; import NcLoadingIcon from "../Components/NcLoadingIcon.mjs"; import { n as normalizeComponent } from "./_plugin-vue2_normalizer-DU4iP6Vu.mjs"; register(t31); const _sfc_main = { __name: "NcDialogButton", props: { /** * The function that will be called when the button is pressed. * If the function returns `false` the click is ignored and the dialog will not be closed, * which is the default behavior of "reset"-buttons. * * @type {() => unknown|false|Promise<unknown|false>} */ callback: { type: Function, required: false, default: () => { } }, /** * The label of the button */ label: { type: String, required: true }, /** * Optional inline SVG icon for the button */ icon: { type: String, required: false, default: void 0 }, /** * The button type, see NcButton. * * @deprecated The usage for setting the color variant is deprecated and will be removed with v9. * @type {'button'|'submit'|'reset'|'primary'|'secondary'|'error'|'warning'|'success'} */ type: { type: String, required: false, default: "secondary", validator: (type) => typeof type === "string" && ["button", "submit", "reset", "primary", "secondary", "tertiary", "error", "warning", "success"].includes(type) }, /** * See `nativeType` of `NcButton`. * * @deprecated use `type` instead - will removed with v9 */ nativeType: { type: String, required: false, default: "button", validator(value) { return ["submit", "reset", "button"].includes(value); } }, /** * If the button should be shown as disabled */ disabled: { type: Boolean, default: false }, /** * The button variant, see NcButton. * * @type {'primary'|'secondary'|'tertiary'|'error'|'warning'|'success'} * @since 8.24.0 */ variant: { type: String, required: false, default: "secondary", validator: (type) => typeof type === "string" && ["primary", "secondary", "tertiary", "error", "warning", "success"].includes(type) } }, emits: ["click"], setup(__props, { emit }) { const props = __props; const isLoading = ref(false); async function handleClick(e) { if (isLoading.value) { return; } isLoading.value = true; try { const fallback = props.nativeType === "reset" ? false : void 0; const result = await props.callback?.() ?? fallback; if (result !== false) { emit("click", e, result); } } finally { isLoading.value = false; } } return { __sfc: true, props, emit, isLoading, handleClick, t, NcButton, NcIconSvgWrapper, NcLoadingIcon }; } }; var _sfc_render = function render() { var _vm = this, _c = _vm._self._c, _setup = _vm._self._setupProxy; return _c(_setup.NcButton, { attrs: { "aria-label": _vm.label, "disabled": _vm.disabled, "type": _vm.type, "native-type": _vm.nativeType, "variant": _vm.variant }, on: { "click": _setup.handleClick }, scopedSlots: _vm._u([{ key: "icon", fn: function() { return [_vm._t("icon", function() { return [_setup.isLoading ? _c(_setup.NcLoadingIcon, { attrs: { "name": _setup.t("Loading …") /* TRANSLATORS: The button is in a loading state*/ } }) : _vm.icon !== void 0 ? _c(_setup.NcIconSvgWrapper, { attrs: { "svg": _vm.icon } }) : _vm._e()]; })]; }, proxy: true }], null, true) }, [_vm._v(" " + _vm._s(_vm.label) + " ")]); }; var _sfc_staticRenderFns = []; var __component__ = /* @__PURE__ */ normalizeComponent( _sfc_main, _sfc_render, _sfc_staticRenderFns, false, null, null ); const NcDialogButton = __component__.exports; export { NcDialogButton as N }; //# sourceMappingURL=NcDialogButton-DtGSMhif.mjs.map