{"version":3,"file":"rockButton.js","sources":["../../../Framework/Controls/rockButton.ts"],"sourcesContent":["// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\nimport { computed, defineComponent, PropType, ref } from \"vue\";\r\nimport { isPromise } from \"@Obsidian/Utility/promiseUtils\";\r\nimport { LiteralUnion } from \"@Obsidian/Types/Utility/support\";\r\nimport { BtnType } from \"@Obsidian/Enums/Controls/btnType\";\r\nimport { BtnSize } from \"@Obsidian/Enums/Controls/btnSize\";\r\n\r\nexport default defineComponent({\r\n name: \"RockButton\",\r\n\r\n props: {\r\n isLoading: {\r\n type: Boolean as PropType,\r\n default: false\r\n },\r\n loadingText: {\r\n type: String as PropType,\r\n default: \"Loading...\"\r\n },\r\n type: {\r\n type: String as PropType,\r\n default: \"button\"\r\n },\r\n disabled: {\r\n type: Boolean as PropType,\r\n default: false\r\n },\r\n btnType: {\r\n type: String as PropType>,\r\n default: BtnType.Default\r\n },\r\n btnSize: {\r\n type: String as PropType,\r\n default: BtnSize.Default\r\n },\r\n autoLoading: {\r\n type: Boolean as PropType,\r\n default: false\r\n },\r\n\r\n /**\r\n * Automatically disables the button when it is in a loading state or\r\n * the click handler is processing. This can prevent duplicate clicks.\r\n */\r\n autoDisable: {\r\n type: Boolean as PropType,\r\n default: false\r\n },\r\n\r\n onClick: {\r\n type: Function as PropType<((event: MouseEvent) => void | PromiseLike)>,\r\n required: false\r\n },\r\n\r\n /** Change button proportions to make it a square. Used for buttons with only an icon. */\r\n isSquare: {\r\n type: Boolean as PropType,\r\n default: false\r\n }\r\n },\r\n\r\n emits: [\r\n ],\r\n\r\n setup(props) {\r\n const isProcessing = ref(false);\r\n\r\n const isButtonDisabled = computed((): boolean => {\r\n return props.disabled || (props.autoDisable && isProcessing.value) || props.isLoading;\r\n });\r\n\r\n const isButtonLoading = computed((): boolean => {\r\n return props.isLoading || (props.autoLoading && isProcessing.value);\r\n });\r\n\r\n const typeClass = computed((): string => {\r\n return `btn-${props.btnType}`;\r\n });\r\n\r\n const sizeClass = computed((): string => {\r\n if (!props.btnSize) {\r\n return \"\";\r\n }\r\n\r\n return `btn-${props.btnSize}`;\r\n });\r\n\r\n const cssClass = computed((): string => {\r\n return `btn ${typeClass.value} ${sizeClass.value} ${props.isSquare ? \"btn-square\" : \"\"}`;\r\n });\r\n\r\n const onButtonClick = async (event: MouseEvent): Promise => {\r\n if (isButtonDisabled.value || isButtonLoading.value) {\r\n return;\r\n }\r\n\r\n isProcessing.value = true;\r\n\r\n try {\r\n const clickHandler = props.onClick;\r\n\r\n if (clickHandler) {\r\n const result = clickHandler(event);\r\n\r\n if (isPromise(result)) {\r\n await result;\r\n }\r\n }\r\n }\r\n finally {\r\n isProcessing.value = false;\r\n }\r\n };\r\n\r\n return {\r\n cssClass,\r\n isButtonDisabled,\r\n isButtonLoading,\r\n onButtonClick\r\n };\r\n },\r\n\r\n template: `\r\n`\r\n});\r\n"],"names":["defineComponent","name","props","isLoading","type","Boolean","default","loadingText","String","disabled","btnType","BtnType","Default","btnSize","BtnSize","autoLoading","autoDisable","onClick","Function","required","isSquare","emits","setup","isProcessing","ref","isButtonDisabled","computed","value","isButtonLoading","typeClass","concat","sizeClass","cssClass","onButtonClick","_ref","_asyncToGenerator","event","clickHandler","result","isPromise","_x","apply","arguments","template"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,0CAAeA,eAAe,CAAC;MAC3BC,EAAAA,IAAI,EAAE,YAAY;MAElBC,EAAAA,KAAK,EAAE;MACHC,IAAAA,SAAS,EAAE;M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