|
20 | 20 | <slot name="footer" :formInstance="getCurrentInstance()?.exposed" :model="model"></slot> |
21 | 21 |
|
22 | 22 | </div> |
23 | | - <div :class="form.buttonsClass"> |
| 23 | + <div :class="buttonsClass"> |
24 | 24 | <div> |
25 | 25 | <ConfirmDelete v-if="deleteType" @delete="onDelete" /> |
26 | 26 | </div> |
27 | 27 | <div> |
28 | 28 | <FormLoading v-if="showLoading && loading" /> |
29 | 29 | </div> |
30 | 30 | <div class="flex justify-end"> |
31 | | - <SecondaryButton @click="close" :disabled="loading">Cancel</SecondaryButton> |
| 31 | + <SecondaryButton v-if="showCancel" @click="close" :disabled="loading">Cancel</SecondaryButton> |
32 | 32 | <PrimaryButton type="submit" class="ml-4" :disabled="loading">Save</PrimaryButton> |
33 | 33 | </div> |
34 | 34 | </div> |
|
66 | 66 |
|
67 | 67 | </div> |
68 | 68 | </div> |
69 | | - <div :class="form.buttonsClass"> |
| 69 | + <div :class="buttonsClass"> |
70 | 70 | <div> |
71 | 71 | <ConfirmDelete v-if="deleteType" @delete="onDelete" /> |
72 | 72 | </div> |
73 | 73 | <div> |
74 | 74 | <FormLoading v-if="showLoading && loading" /> |
75 | 75 | </div> |
76 | 76 | <div class="flex justify-end"> |
77 | | - <SecondaryButton @click="close" :disabled="loading">Cancel</SecondaryButton> |
| 77 | + <SecondaryButton v-if="showCancel" @click="close" :disabled="loading">Cancel</SecondaryButton> |
78 | 78 | <PrimaryButton type="submit" class="ml-4" :disabled="loading">Save</PrimaryButton> |
79 | 79 | </div> |
80 | 80 | </div> |
|
91 | 91 | </template> |
92 | 92 |
|
93 | 93 | <script setup lang="ts"> |
94 | | -import type { ApiRequest, ApiResponse, ResponseStatus, ModalProvider, InputProp } from '@/types' |
95 | | -import { computed, getCurrentInstance, nextTick, onMounted, onUnmounted, provide, ref, watch } from 'vue' |
| 94 | +import type { ApiRequest, ApiResponse, ModalProvider, InputProp } from '@/types' |
| 95 | +import type { AutoEditFormProps, AutoEditFormEmits } from '@/components/types' |
| 96 | +import { computed, getCurrentInstance, onMounted, onUnmounted, provide, ref, watch } from 'vue' |
96 | 97 | import { useClient } from '@/use/client' |
97 | 98 | import { toFormValues, useMetadata } from '@/use/metadata' |
98 | 99 | import { form } from './css' |
99 | 100 | import { getTypeName, transition } from '@/use/utils' |
100 | 101 | import { Sole } from '@/use/config' |
101 | 102 | import { ApiResult, HttpMethods, humanize, map, mapGet } from '@servicestack/client' |
102 | 103 |
|
103 | | -const props = withDefaults(defineProps<{ |
104 | | - modelValue: any |
105 | | - type: string|InstanceType<any>|Function |
106 | | - deleteType?: string|InstanceType<any>|Function |
107 | | - formStyle?: "slideOver" | "card" |
108 | | - panelClass?: string |
109 | | - formClass?: string |
110 | | - headingClass?: string |
111 | | - subHeadingClass?: string |
112 | | - heading?: string |
113 | | - subHeading?: string |
114 | | - autosave?: boolean |
115 | | - showLoading?: boolean |
116 | | - configureField?: (field:InputProp) => void |
117 | | - configureFormLayout?: (field:InputProp[]) => void |
118 | | -}>(), { |
| 104 | +const props = withDefaults(defineProps<AutoEditFormProps>(), { |
119 | 105 | formStyle: "slideOver", |
120 | 106 | autosave: true, |
121 | 107 | showLoading: true, |
122 | 108 | }) |
123 | 109 |
|
124 | | -const emit = defineEmits<{ |
125 | | - (e:'done'): void |
126 | | - (e:'save', response:any): () => void |
127 | | - (e:'delete', response:any): () => void |
128 | | - (e:'error', status:ResponseStatus): void |
129 | | -}>() |
| 110 | +const emit = defineEmits<AutoEditFormEmits>() |
130 | 111 |
|
131 | 112 | const formFields = ref() |
132 | 113 | const formFieldsKey = ref(1) |
@@ -179,6 +160,7 @@ const panelClass = computed(() => props.panelClass || form.panelClass(props.form |
179 | 160 | const formClass = computed(() => props.formClass || form.formClass(props.formStyle)) |
180 | 161 | const headingClass = computed(() => props.headingClass || form.headingClass(props.formStyle)) |
181 | 162 | const subHeadingClass = computed(() => props.subHeadingClass || form.subHeadingClass(props.formStyle)) |
| 163 | +const buttonsClass = computed(() => props.buttonsClass || form.buttonsClass) |
182 | 164 |
|
183 | 165 | const dataModel = computed(() => Crud.model(metaType.value)) |
184 | 166 | const title = computed(() => props.heading || typeOf(typeName.value)?.description || |
|
0 commit comments