@bagelink/vue 0.0.1102 → 0.0.1104
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.
- package/dist/components/form/BglField.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/DatePick.vue.d.ts +23 -0
- package/dist/components/form/inputs/DatePick.vue.d.ts.map +1 -0
- package/dist/components/form/inputs/NumberInput.vue.d.ts +1 -0
- package/dist/components/form/inputs/NumberInput.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/index.d.ts +1 -0
- package/dist/components/form/inputs/index.d.ts.map +1 -1
- package/dist/composables/useFormField.d.ts +11 -0
- package/dist/composables/useFormField.d.ts.map +1 -0
- package/dist/index.cjs +652 -285
- package/dist/index.mjs +652 -285
- package/dist/style.css +187 -6
- package/package.json +1 -1
- package/src/components/form/BglField.vue +6 -41
- package/src/components/form/BglForm.vue +1 -1
- package/src/components/form/inputs/DatePick.vue +344 -250
- package/src/components/form/inputs/NumberInput.vue +13 -1
- package/src/components/form/inputs/index.ts +1 -1
- package/src/composables/useFormField.ts +35 -0
|
@@ -20,6 +20,7 @@ interface NumberInputProps {
|
|
|
20
20
|
helptext?: string
|
|
21
21
|
layout?: NumberLayout
|
|
22
22
|
center?: boolean
|
|
23
|
+
padZero?: number
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
const {
|
|
@@ -37,6 +38,7 @@ const {
|
|
|
37
38
|
helptext,
|
|
38
39
|
layout,
|
|
39
40
|
id,
|
|
41
|
+
padZero,
|
|
40
42
|
} = defineProps<NumberInputProps>()
|
|
41
43
|
|
|
42
44
|
const emit = defineEmits(['update:modelValue'])
|
|
@@ -62,8 +64,12 @@ function decrement() {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
function formatNumber(num: number) {
|
|
67
|
+
let formatted = num.toString()
|
|
68
|
+
if (padZero && padZero > 0) {
|
|
69
|
+
formatted = formatted.padStart(padZero, '0')
|
|
70
|
+
}
|
|
65
71
|
// eslint-disable-next-line regexp/no-unused-capturing-group
|
|
66
|
-
return
|
|
72
|
+
return formatted.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
|
67
73
|
}
|
|
68
74
|
|
|
69
75
|
let formattedValue = $ref('')
|
|
@@ -157,16 +163,22 @@ watch(() => modelValue, (newVal) => {
|
|
|
157
163
|
inset-inline-end: 0;
|
|
158
164
|
margin-top: calc(var(--input-height) / -1);
|
|
159
165
|
line-height: 0;
|
|
166
|
+
display: flex;
|
|
167
|
+
flex-direction: column;
|
|
168
|
+
gap: 0;
|
|
160
169
|
}
|
|
170
|
+
|
|
161
171
|
.top-bgl-ctrl-num-btn{
|
|
162
172
|
margin-top: calc(var(--input-height) / 10) !important;
|
|
163
173
|
}
|
|
164
174
|
.bgl-ctrl-num-btn{
|
|
165
175
|
height: calc(var(--input-height) / 2.5) !important;
|
|
176
|
+
isolation: isolate;
|
|
166
177
|
}
|
|
167
178
|
|
|
168
179
|
.bgl-big-ctrl-num-btn{
|
|
169
180
|
width: 100% !important;
|
|
181
|
+
isolation: isolate;
|
|
170
182
|
}
|
|
171
183
|
.bgl-number-input{
|
|
172
184
|
padding-inline-end: 1.75rem !important;
|
|
@@ -3,7 +3,7 @@ export { default as CheckInput } from './CheckInput.vue'
|
|
|
3
3
|
export { default as CodeEditor } from './CodeEditor/Index.vue'
|
|
4
4
|
export { default as ColorPicker } from './ColorPicker.vue'
|
|
5
5
|
export { default as DateInput } from './DateInput.vue'
|
|
6
|
-
|
|
6
|
+
export { default as DatePick } from './DatePick.vue'
|
|
7
7
|
export { default as DatePicker } from './DatePicker.vue'
|
|
8
8
|
export { default as FileUpload } from './FileUpload.vue'
|
|
9
9
|
export { default as JSONInput } from './JSONInput.vue'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Field } from '@bagelink/vue'
|
|
2
|
+
import { inject, computed } from 'vue'
|
|
3
|
+
import { FORM_STATE_KEY, type BagelFormState } from '../components/form/useBagelFormState'
|
|
4
|
+
|
|
5
|
+
export function useFormField<T = any>(props: {
|
|
6
|
+
field: Field<T>
|
|
7
|
+
fieldID?: string
|
|
8
|
+
modelValue?: any
|
|
9
|
+
}) {
|
|
10
|
+
const formState = inject<BagelFormState<T>>(FORM_STATE_KEY)
|
|
11
|
+
|
|
12
|
+
const fieldData = computed({
|
|
13
|
+
get: () => {
|
|
14
|
+
if (!props.fieldID || !formState) return props.modelValue ?? props.field.defaultValue ?? ''
|
|
15
|
+
const value = formState.getFieldData(props.fieldID)
|
|
16
|
+
if (props.field.$el === 'form' && !value) return {}
|
|
17
|
+
return value ?? ''
|
|
18
|
+
},
|
|
19
|
+
set: (val: any) => {
|
|
20
|
+
if (!props.fieldID || !formState) return
|
|
21
|
+
const currentValue = formState.getFieldData(props.fieldID)
|
|
22
|
+
if (JSON.stringify(val) === JSON.stringify(currentValue)) return
|
|
23
|
+
|
|
24
|
+
if (props.field.onUpdate) {
|
|
25
|
+
props.field.onUpdate(val, currentValue)
|
|
26
|
+
}
|
|
27
|
+
formState.updateField(props.fieldID, val)
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
fieldData,
|
|
33
|
+
formState
|
|
34
|
+
}
|
|
35
|
+
}
|