{"version":3,"file":"rockButton.obs.js","sources":["../../../Framework/Controls/rockButton.obs"],"sourcesContent":["<!-- Copyright by the Spark Development Network; Licensed under the Rock Community License -->\n<template>\n <button ref=\"element\" :class=\"cssClass\" :disabled=\"isButtonDisabled\" @click=\"onButtonClick\" :type=\"type\" v-bind=\"tooltipAttrs\" :data-shortcut-key=\"shortcutKey\">\n <template v-if=\"isButtonLoading\">\n <slot name=\"loading\" v-if=\"$slots.loading || loadingText\">{{ loadingText }}</slot>\n <slot v-else />\n <template v-if=\"!disableLoadingIndicator\"> \n <LoadingIndicator isSmall class=\"d-inline\" />\n </template>\n </template>\n <slot v-else />\n </button>\n</template>\n\n<script setup lang=\"ts\">\n import { computed, onBeforeUnmount, PropType, ref, watch } from \"vue\";\n import { isPromise } from \"@Obsidian/Utility/promiseUtils\";\n import { LiteralUnion } from \"@Obsidian/Types/Utility/support\";\n import { BtnType } from \"@Obsidian/Enums/Controls/btnType\";\n import { BtnSize } from \"@Obsidian/Enums/Controls/btnSize\";\n import { tooltip, destroyTooltip } from \"@Obsidian/Utility/tooltip\";\n import LoadingIndicator from \"./loadingIndicator.obs\";\n\n const props = defineProps({\n isLoading: {\n type: Boolean as PropType<boolean>,\n default: false\n },\n loadingText: {\n type: String as PropType<string>,\n default: \"\"\n },\n type: {\n type: String as PropType<\"button\" | \"submit\" | \"reset\">,\n default: \"button\"\n },\n disabled: {\n type: Boolean as PropType<boolean>,\n default: false\n },\n btnType: {\n type: String as PropType<LiteralUnion<BtnType>>,\n default: BtnType.Default\n },\n btnSize: {\n type: String as PropType<BtnSize>,\n default: BtnSize.Default\n },\n autoLoading: {\n type: Boolean as PropType<boolean>,\n default: false\n },\n\n /**\n * Automatically disables the button when it is in a loading state or\n * the click handler is processing. This can prevent duplicate clicks.\n */\n autoDisable: {\n type: Boolean as PropType<boolean>,\n default: false\n },\n\n onClick: {\n type: Function as PropType<((event: MouseEvent) => void | PromiseLike<void>)>,\n required: false\n },\n\n /** Change button proportions to make it a square. Used for buttons with only an icon. */\n isSquare: {\n type: Boolean as PropType<boolean>,\n default: false\n },\n\n /** This gets turned into a tooltip as well as being the accessibility title */\n title: {\n type: String\n },\n\n shortcutKey: {\n type: String as PropType<string>,\n default: \"\"\n },\n\n disableLoadingIndicator: {\n type: Boolean,\n default: false\n }\n });\n\n const isProcessing = ref(false);\n const element = ref();\n\n const isButtonDisabled = computed((): boolean => {\n return props.disabled || (props.autoDisable && isProcessing.value) || props.isLoading;\n });\n\n const isButtonLoading = computed((): boolean => {\n return props.isLoading || (props.autoLoading && isProcessing.value);\n });\n\n const typeClass = computed((): string => {\n return `btn-${props.btnType}`;\n });\n\n const sizeClass = computed((): string => {\n if (!props.btnSize) {\n return \"\";\n }\n\n return `btn-${props.btnSize}`;\n });\n\n const cssClass = computed((): string => {\n return `btn ${typeClass.value} ${sizeClass.value} ${props.isSquare ? \"btn-square\" : \"\"}`;\n });\n\n const tooltipAttrs = computed(() => {\n if (props.title) {\n return {\n title: props.title,\n \"data-toggle\": \"tooltip\"\n };\n }\n return {};\n });\n\n watch([element, () => props.title], () => {\n if (props.title && element.value) {\n tooltip(element.value);\n }\n });\n\n onBeforeUnmount(() => {\n destroyTooltip(element.value);\n });\n\n const onButtonClick = async (event: MouseEvent): Promise<void> => {\n if (isButtonDisabled.value || isButtonLoading.value) {\n return;\n }\n\n isProcessing.value = true;\n\n try {\n const clickHandler = props.onClick;\n\n if (clickHandler) {\n const result = clickHandler(event);\n\n if (isPromise(result)) {\n await result;\n }\n }\n }\n finally {\n isProcessing.value = false;\n }\n };\n</script>\n"],"names":["props","__props","isProcessing","ref","element","isButtonDisabled","computed","disabled","autoDisable","value","isLoading","isButtonLoading","autoLoading","typeClass","concat","btnType","sizeClass","btnSize","cssClass","isSquare","tooltipAttrs","title","watch","tooltip","onBeforeUnmount","destroyTooltip","onButtonClick","_ref","_asyncToGenerator","event","clickHandler","onClick","result","isPromise","_x","apply","arguments"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;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