@stonecrop/aform 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,32 @@
1
1
  <template>
2
2
  <div class="aform_form-element aform_file-attach aform__grid--full">
3
- <template v-if="files">
4
- <div class="aform_file-attach-feedback">
5
- <p>
6
- You have selected: <b>{{ fileLengthText }}</b>
7
- </p>
8
- <li v-for="file of files" :key="file.name">
9
- {{ file.name }}
10
- </li>
11
- </div>
3
+ <template v-if="mode === 'display'">
4
+ <template v-if="files">
5
+ <div class="aform_file-attach-feedback">
6
+ <p>
7
+ <b>{{ fileLengthText }}</b>
8
+ </p>
9
+ <li v-for="file of files" :key="file.name">{{ file.name }}</li>
10
+ </div>
11
+ </template>
12
+ <span v-else class="aform_display-value">No file selected</span>
13
+ </template>
14
+ <template v-else>
15
+ <template v-if="files">
16
+ <div class="aform_file-attach-feedback">
17
+ <p>
18
+ You have selected: <b>{{ fileLengthText }}</b>
19
+ </p>
20
+ <li v-for="file of files" :key="file.name">
21
+ {{ file.name }}
22
+ </li>
23
+ </div>
24
+ </template>
25
+ <button type="button" class="aform_form-btn" :disabled="mode === 'read'" @click="open()">
26
+ {{ label }}
27
+ </button>
28
+ <button type="button" :disabled="!files || mode === 'read'" class="aform_form-btn" @click="reset()">Reset</button>
12
29
  </template>
13
-
14
- <button type="button" class="aform_form-btn" @click="open()">
15
- {{ label }}
16
- </button>
17
- <button type="button" :disabled="!files" class="aform_form-btn" @click="reset()">Reset</button>
18
30
  </div>
19
31
  </template>
20
32
 
@@ -22,11 +34,14 @@
22
34
  import { useFileDialog } from '@vueuse/core'
23
35
  import { computed } from 'vue'
24
36
 
25
- const { label } = defineProps<{ label: string }>()
37
+ import type { ComponentProps } from '../../types'
38
+
39
+ const { label, mode } = defineProps<ComponentProps>()
26
40
  const { files, open, reset, onChange } = useFileDialog()
27
41
 
28
42
  const fileLengthText = computed(() => {
29
- return `${files.value.length} ${files.value.length === 1 ? 'file' : 'files'}`
43
+ const count = files.value?.length ?? 0
44
+ return `${count} ${count === 1 ? 'file' : 'files'}`
30
45
  })
31
46
 
32
47
  onChange(files => files)
@@ -1,20 +1,26 @@
1
1
  <template>
2
2
  <div class="aform_form-element">
3
- <input
4
- :id="uuid"
5
- v-model="inputNumber"
6
- class="aform_input-field"
7
- type="number"
8
- :disabled="readOnly"
9
- :required="required" />
10
- <label class="aform_field-label" :for="uuid">{{ label }}</label>
11
- <p v-show="validation.errorMessage" class="aform_error" v-html="validation.errorMessage"></p>
3
+ <template v-if="mode === 'display'">
4
+ <span class="aform_display-value">{{ inputNumber ?? '' }}</span>
5
+ <label class="aform_field-label">{{ label }}</label>
6
+ </template>
7
+ <template v-else>
8
+ <input
9
+ :id="uuid"
10
+ v-model="inputNumber"
11
+ class="aform_input-field"
12
+ type="number"
13
+ :disabled="mode === 'read'"
14
+ :required="required" />
15
+ <label class="aform_field-label" :for="uuid">{{ label }}</label>
16
+ <p v-show="validation.errorMessage" class="aform_error" v-html="validation.errorMessage"></p>
17
+ </template>
12
18
  </div>
13
19
  </template>
14
20
 
15
21
  <script setup lang="ts">
16
22
  import { ComponentProps } from '../../types'
17
23
 
18
- const { label, required, readOnly, uuid, validation = { errorMessage: '&nbsp;' } } = defineProps<ComponentProps>()
24
+ const { label, required, mode, uuid, validation = { errorMessage: '&nbsp;' } } = defineProps<ComponentProps>()
19
25
  const inputNumber = defineModel<number>()
20
26
  </script>
@@ -1,15 +1,21 @@
1
1
  <template>
2
2
  <div class="aform_form-element">
3
- <input
4
- :id="uuid"
5
- v-model="inputText"
6
- v-mask="mask"
7
- class="aform_input-field"
8
- :disabled="readOnly"
9
- :maxlength="mask ? (maskFilled ? mask.length : undefined) : undefined"
10
- :required="required" />
11
- <label class="aform_field-label" :for="uuid">{{ label }} </label>
12
- <p v-show="validation.errorMessage" class="aform_error" v-html="validation.errorMessage"></p>
3
+ <template v-if="mode === 'display'">
4
+ <span class="aform_display-value">{{ inputText ?? '' }}</span>
5
+ <label class="aform_field-label">{{ label }}</label>
6
+ </template>
7
+ <template v-else>
8
+ <input
9
+ :id="uuid"
10
+ v-model="inputText"
11
+ v-mask="mask"
12
+ class="aform_input-field"
13
+ :disabled="mode === 'read'"
14
+ :maxlength="mask ? (maskFilled ? mask.length : undefined) : undefined"
15
+ :required="required" />
16
+ <label class="aform_field-label" :for="uuid">{{ label }} </label>
17
+ <p v-show="validation.errorMessage" class="aform_error" v-html="validation.errorMessage"></p>
18
+ </template>
13
19
  </div>
14
20
  </template>
15
21
 
@@ -19,7 +25,7 @@ import { /* inject, */ ref } from 'vue'
19
25
  import { useStringMask as vMask } from '../../directives/mask'
20
26
  import { ComponentProps } from '../../types'
21
27
 
22
- const { label, mask, required, readOnly, uuid, validation = { errorMessage: '&nbsp;' } } = defineProps<ComponentProps>()
28
+ const { label, mask, required, mode, uuid, validation = { errorMessage: '&nbsp;' } } = defineProps<ComponentProps>()
23
29
 
24
30
  // TODO: setup maskFilled as a computed property
25
31
  const maskFilled = ref(true)
@@ -1,5 +1,11 @@
1
1
  import type { TableColumn, TableConfig, TableRow } from '@stonecrop/atable'
2
2
 
3
+ /**
4
+ * The rendering mode for AForm components
5
+ * @public
6
+ */
7
+ export type FormMode = 'edit' | 'read' | 'display'
8
+
3
9
  /**
4
10
  * Defined props for AForm components
5
11
  * @public
@@ -30,10 +36,10 @@ export type ComponentProps = {
30
36
  required?: boolean
31
37
 
32
38
  /**
33
- * Indicate whether elements inside the component are read-only
39
+ * The rendering mode for the component
34
40
  * @public
35
41
  */
36
- readOnly?: boolean
42
+ mode?: FormMode
37
43
 
38
44
  /**
39
45
  * Set a unique identifier for elements inside the component
@@ -79,10 +85,10 @@ export type BaseSchema = {
79
85
  component?: string
80
86
 
81
87
  /**
82
- * A placeholder value for the field
83
- * @beta
88
+ * Per-field rendering mode override; takes precedence over the AForm-level `mode` prop
89
+ * @public
84
90
  */
85
- value?: any
91
+ mode?: FormMode
86
92
  }
87
93
 
88
94
  /**
@@ -232,12 +238,6 @@ export type DoctypeSchema = BaseSchema & {
232
238
  * @public
233
239
  */
234
240
  schema?: SchemaTypes[]
235
-
236
- /**
237
- * Indicate whether the nested form is read-only
238
- * @public
239
- */
240
- readOnly?: boolean
241
241
  }
242
242
 
243
243
  /**
@@ -291,12 +291,6 @@ export type TableDoctypeSchema = BaseSchema & {
291
291
  * @public
292
292
  */
293
293
  rows?: TableRow[]
294
-
295
- /**
296
- * Indicate whether the table is read-only
297
- * @public
298
- */
299
- readOnly?: boolean
300
294
  }
301
295
 
302
296
  /**