@bagelink/vue 0.0.1100 → 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.
@@ -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 num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
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
- // export { default as DatePick } from './DatePick.vue'
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
+ }