inertia-bootstrap-forms 2.1.21 → 3.0.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.
- package/README.fa.md +468 -0
- package/README.md +322 -714
- package/dist/inertia-bootstrap-forms.cjs.js +1 -0
- package/dist/inertia-bootstrap-forms.es.js +3524 -30
- package/index.d.ts +143 -507
- package/package.json +89 -70
- package/src/AmountInput.vue +81 -76
- package/src/CaptchaInput.vue +87 -88
- package/src/CheckboxButtonInput.vue +56 -69
- package/src/CheckboxInput.vue +60 -79
- package/src/CheckboxToggle.vue +53 -136
- package/src/ChipsInput.vue +157 -0
- package/src/ComboboxInput.vue +556 -0
- package/src/DropzoneInput.vue +125 -103
- package/src/EditorInput.vue +47 -106
- package/src/EmailInput.vue +16 -15
- package/src/FileInput.vue +189 -179
- package/src/FormAdornInput.vue +75 -0
- package/src/FormContainer.vue +288 -251
- package/src/FormField.vue +59 -0
- package/src/FormLabel.vue +27 -27
- package/src/GroupControl.vue +55 -53
- package/src/LocationInput.vue +79 -72
- package/src/MobileInput.vue +21 -13
- package/src/MultiQuantityInput.vue +109 -181
- package/src/OTPInput.vue +144 -76
- package/src/PasswordInput.vue +151 -17
- package/src/PersianDatePickerInput.vue +63 -166
- package/src/QuantityInput.vue +100 -119
- package/src/RangeInput.vue +96 -0
- package/src/SimpleUploader.vue +8 -143
- package/src/StarRatingInput.vue +114 -138
- package/src/SubmitButton.vue +39 -24
- package/src/SwitchInput.vue +58 -83
- package/src/TelInput.vue +86 -120
- package/src/TextAreaInput.vue +29 -33
- package/src/TextInput.vue +42 -51
- package/src/UppyInput.vue +237 -324
- package/src/composables/useBsInstance.js +66 -0
- package/src/composables/useChoice.js +34 -0
- package/src/composables/useDisposables.js +59 -0
- package/src/composables/useField.js +121 -0
- package/src/composables/useFormApi.js +12 -0
- package/src/i18n.js +120 -0
- package/src/index.js +123 -42
- package/src/utils/bootstrap.js +48 -0
- package/src/utils/digits.js +21 -0
- package/src/utils/http.js +15 -0
- package/dist/choices-KiM-I_0P.js +0 -2955
- package/dist/dropdown-yh2aQrbw-XuCU1v1F.js +0 -1543
- package/dist/index-BRtKc2RA.js +0 -604
- package/dist/index-_x4UqcXz.js +0 -4938
- package/dist/inertia-bootstrap-forms.umd.js +0 -19
- package/dist/range-slider-pips-DTDOg3Q9.js +0 -3506
- package/dist/style.css +0 -1
- package/src/css/from-select.scss +0 -384
- package/src/css/loader.gif +0 -0
- package/src/css/location.scss +0 -44
- package/src/css/simple-upload.scss +0 -54
package/src/PasswordInput.vue
CHANGED
|
@@ -1,23 +1,157 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import { computed, defineComponent, nextTick, onMounted, ref, watch } from 'vue';
|
|
3
|
+
import TextInput from './TextInput.vue';
|
|
4
|
+
import FormAdornInput from './FormAdornInput.vue';
|
|
5
|
+
import { fieldProps, useField } from './composables/useField.js';
|
|
6
|
+
import { useBsInstance } from './composables/useBsInstance.js';
|
|
7
|
+
import { useI18n } from './i18n.js';
|
|
4
8
|
|
|
9
|
+
const STRENGTH_MESSAGES = {
|
|
10
|
+
en: { weak: 'Weak', fair: 'Fair', good: 'Good', strong: 'Strong' },
|
|
11
|
+
fa: { weak: 'ضعیف', fair: 'متوسط', good: 'خوب', strong: 'قوی' },
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Password field.
|
|
16
|
+
* - `toggle` adds a show / hide button (Bootstrap 6 form-adorn)
|
|
17
|
+
* - `strength` adds the Bootstrap 6 strength meter under the field (optional)
|
|
18
|
+
*
|
|
19
|
+
* Every other prop / listener (placeholder, size, autocomplete, @change, …) is forwarded to the input.
|
|
20
|
+
*/
|
|
5
21
|
export default defineComponent({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
name: 'PasswordInput',
|
|
23
|
+
components: { TextInput, FormAdornInput },
|
|
24
|
+
inheritAttrs: false,
|
|
25
|
+
emits: ['toggle', 'strength'],
|
|
26
|
+
props: {
|
|
27
|
+
...fieldProps,
|
|
28
|
+
name: { type: String, default: 'password' },
|
|
29
|
+
placeholder: { type: String, default: null },
|
|
30
|
+
/** Show a "reveal password" button. */
|
|
31
|
+
toggle: { type: Boolean, default: false },
|
|
32
|
+
/** Show the password strength meter. */
|
|
33
|
+
strength: { type: Boolean, default: false },
|
|
34
|
+
/** Show the text feedback ("Weak", "Strong", …) under the meter. */
|
|
35
|
+
strengthText: { type: Boolean, default: true },
|
|
36
|
+
/** Override the labels: { weak, fair, good, strong }. */
|
|
37
|
+
strengthMessages: { type: Object, default: null },
|
|
38
|
+
/** Bootstrap Strength options: { minLength, thresholds: [2, 4, 6], weights, scorer(password) => number }. */
|
|
39
|
+
strengthOptions: { type: Object, default: () => ({}) },
|
|
40
|
+
size: { type: String, default: null },
|
|
41
|
+
locale: { type: String, default: null },
|
|
42
|
+
},
|
|
43
|
+
setup(props, { emit, expose }) {
|
|
44
|
+
const { t, locale } = useI18n(() => props.locale);
|
|
45
|
+
// read-only access to the value (so the meter follows form resets / external changes)
|
|
46
|
+
const field = useField(props, () => {});
|
|
47
|
+
|
|
48
|
+
const root = ref(null);
|
|
49
|
+
const meter = ref(null);
|
|
50
|
+
const visible = ref(false);
|
|
51
|
+
|
|
52
|
+
const messages = computed(() => ({
|
|
53
|
+
...(STRENGTH_MESSAGES[locale.value] || STRENGTH_MESSAGES.en),
|
|
54
|
+
...(props.strengthMessages || {}),
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
function toggleVisible() {
|
|
58
|
+
visible.value = !visible.value;
|
|
59
|
+
emit('toggle', visible.value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let offs = [];
|
|
63
|
+
const { instance, create } = useBsInstance(
|
|
64
|
+
'Strength',
|
|
65
|
+
() => (props.strength ? meter.value : null),
|
|
66
|
+
() => ({
|
|
67
|
+
...props.strengthOptions,
|
|
68
|
+
input: root.value?.querySelector('input'),
|
|
69
|
+
messages: messages.value,
|
|
70
|
+
}),
|
|
71
|
+
{
|
|
72
|
+
onCreate(inst, el) {
|
|
73
|
+
const handler = (e) => emit('strength', e.strength ?? null, e.score ?? 0);
|
|
74
|
+
el.addEventListener('strengthChange.bs.strength', handler);
|
|
75
|
+
offs.push(() => el.removeEventListener('strengthChange.bs.strength', handler));
|
|
76
|
+
},
|
|
77
|
+
onDestroy() {
|
|
78
|
+
offs.forEach((off) => off());
|
|
79
|
+
offs = [];
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// the plugin only listens to typing: re-evaluate when the value changes from the outside (reset, server data)
|
|
85
|
+
watch(
|
|
86
|
+
() => field.model.value,
|
|
87
|
+
() => nextTick(() => instance.value?.evaluate())
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
// things the plugin reads when it is created
|
|
91
|
+
watch(
|
|
92
|
+
() => [props.strength, props.toggle, props.strengthText, messages.value, props.strengthOptions],
|
|
93
|
+
async () => {
|
|
94
|
+
await nextTick();
|
|
95
|
+
if (props.strength) create();
|
|
14
96
|
},
|
|
15
|
-
|
|
16
|
-
|
|
97
|
+
{ deep: true }
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
expose({ strength: () => instance.value?.getStrength?.() ?? null });
|
|
101
|
+
|
|
102
|
+
// props that are forwarded to the real input component
|
|
103
|
+
const forwarded = computed(() => ({
|
|
104
|
+
name: props.name,
|
|
105
|
+
modelValue: props.modelValue,
|
|
106
|
+
id: props.id,
|
|
107
|
+
disabled: props.disabled,
|
|
108
|
+
readonly: props.readonly,
|
|
109
|
+
required: props.required,
|
|
110
|
+
invalid: props.invalid,
|
|
111
|
+
size: props.size,
|
|
112
|
+
placeholder: props.placeholder ?? t('password.placeholder'),
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
return { t, root, meter, visible, toggleVisible, forwarded };
|
|
116
|
+
},
|
|
117
|
+
});
|
|
17
118
|
</script>
|
|
119
|
+
|
|
18
120
|
<template>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
121
|
+
<div ref="root" class="password-input">
|
|
122
|
+
<FormAdornInput
|
|
123
|
+
v-if="toggle"
|
|
124
|
+
v-bind="{ ...$attrs, ...forwarded }"
|
|
125
|
+
:type="visible ? 'text' : 'password'"
|
|
126
|
+
autocomplete="current-password"
|
|
127
|
+
>
|
|
128
|
+
<template #end>
|
|
129
|
+
<button
|
|
130
|
+
type="button"
|
|
131
|
+
class="btn-text theme-secondary btn-icon"
|
|
132
|
+
:aria-label="visible ? t('password.hide') : t('password.show')"
|
|
133
|
+
:aria-pressed="visible"
|
|
134
|
+
@click="toggleVisible"
|
|
135
|
+
>
|
|
136
|
+
<svg v-if="!visible" width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
137
|
+
<path d="M1 8s2.5-4.5 7-4.5S15 8 15 8s-2.5 4.5-7 4.5S1 8 1 8Z" /><circle cx="8" cy="8" r="2" />
|
|
138
|
+
</svg>
|
|
139
|
+
<svg v-else width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
140
|
+
<path d="M2 2l12 12M6.6 3.7A7 7 0 0 1 8 3.5C12.5 3.5 15 8 15 8a11 11 0 0 1-2.2 2.6M4 5.4A11 11 0 0 0 1 8s2.5 4.5 7 4.5c1 0 1.9-.2 2.7-.6" />
|
|
141
|
+
</svg>
|
|
142
|
+
</button>
|
|
143
|
+
</template>
|
|
144
|
+
</FormAdornInput>
|
|
145
|
+
<TextInput v-else v-bind="{ ...$attrs, ...forwarded }" type="password" autocomplete="current-password" />
|
|
146
|
+
|
|
147
|
+
<template v-if="strength">
|
|
148
|
+
<div ref="meter" class="strength" aria-hidden="true">
|
|
149
|
+
<div class="strength-segment"></div>
|
|
150
|
+
<div class="strength-segment"></div>
|
|
151
|
+
<div class="strength-segment"></div>
|
|
152
|
+
<div class="strength-segment"></div>
|
|
153
|
+
</div>
|
|
154
|
+
<div v-if="strengthText" class="strength-text" aria-live="polite"></div>
|
|
155
|
+
</template>
|
|
156
|
+
</div>
|
|
157
|
+
</template>
|
|
@@ -1,183 +1,80 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import {
|
|
2
|
+
import { defineAsyncComponent, defineComponent, onMounted, ref, watch } from 'vue';
|
|
3
|
+
import { fieldProps, useField } from './composables/useField.js';
|
|
3
4
|
|
|
4
|
-
const Vue3PersianDatetimePicker = defineAsyncComponent(() =>
|
|
5
|
-
import('vue3-persian-datetime-picker')
|
|
6
|
-
);
|
|
5
|
+
const Vue3PersianDatetimePicker = defineAsyncComponent(() => import('vue3-persian-datetime-picker'));
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Jalali (Persian) date / time picker based on vue3-persian-datetime-picker.
|
|
9
|
+
* Bootstrap 6's own Datepicker does not support the Jalali calendar, so this library is kept on purpose.
|
|
10
|
+
*/
|
|
9
11
|
export default defineComponent({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
name: 'PersianDatePickerInput',
|
|
13
|
+
components: { Vue3PersianDatetimePicker },
|
|
14
|
+
emits: ['update:modelValue', 'change', 'open', 'close'],
|
|
15
|
+
props: {
|
|
16
|
+
...fieldProps,
|
|
17
|
+
/** date | datetime | time | year-month | month */
|
|
18
|
+
calendar: { type: String, default: 'date' },
|
|
19
|
+
view: { type: String, default: 'date' },
|
|
20
|
+
min: { type: String, default: null },
|
|
21
|
+
max: { type: String, default: null },
|
|
22
|
+
range: { type: Boolean, default: false },
|
|
23
|
+
locale: { type: String, default: 'fa' },
|
|
24
|
+
/** Format of the stored value. */
|
|
25
|
+
format: { type: String, default: 'jYYYY/jMM/jDD' },
|
|
26
|
+
/** Format shown in the input (defaults to `format`). */
|
|
27
|
+
inputFormat: { type: String, default: null },
|
|
28
|
+
placeholder: { type: String, default: null },
|
|
29
|
+
inputClass: { type: String, default: 'form-control fanum' },
|
|
30
|
+
/** Extra props forwarded to vue3-persian-datetime-picker. */
|
|
31
|
+
pickerOptions: { type: Object, default: () => ({}) },
|
|
16
32
|
},
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
view: {
|
|
22
|
-
type: String,
|
|
23
|
-
default: 'date',
|
|
24
|
-
},
|
|
25
|
-
disabled: Boolean,
|
|
26
|
-
min: String,
|
|
27
|
-
max: String,
|
|
28
|
-
range: Boolean,
|
|
29
|
-
locale: {
|
|
30
|
-
default: 'fa',
|
|
31
|
-
},
|
|
32
|
-
format: {
|
|
33
|
-
type: String,
|
|
34
|
-
default: 'jYYYY/jMM/jDD',
|
|
35
|
-
},
|
|
36
|
-
inputFormat: {
|
|
37
|
-
type: String,
|
|
38
|
-
default: null,
|
|
39
|
-
},
|
|
40
|
-
simple: {
|
|
41
|
-
type: Boolean,
|
|
42
|
-
default: false,
|
|
43
|
-
},
|
|
44
|
-
placeholder: String,
|
|
45
|
-
},
|
|
46
|
-
setup(props) {
|
|
47
|
-
let form = inject('form', {
|
|
48
|
-
errors: {},
|
|
49
|
-
getID(name) {
|
|
50
|
-
return name;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
let group = inject('group', {});
|
|
33
|
+
setup(props, { emit, expose }) {
|
|
34
|
+
const field = useField(props, emit);
|
|
35
|
+
const ready = ref(false);
|
|
54
36
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
set(value) {
|
|
60
|
-
if (group?.value?.name) {
|
|
61
|
-
group.value.setData(props.name, value);
|
|
62
|
-
} else {
|
|
63
|
-
form.value[props.name] = value;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
37
|
+
onMounted(() => {
|
|
38
|
+
ready.value = true; // the picker needs the DOM, so it is never rendered during SSR
|
|
39
|
+
});
|
|
67
40
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
clear() {
|
|
77
|
-
this.modelValue = null;
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
mounted() {
|
|
81
|
-
_this = this;
|
|
82
|
-
},
|
|
83
|
-
computed: {
|
|
84
|
-
isSsr() {
|
|
85
|
-
return !window || typeof window === 'undefined';
|
|
41
|
+
watch(
|
|
42
|
+
() => field.model.value,
|
|
43
|
+
(now, before) => emit('change', now, before)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
expose({ clear: () => (field.model.value = null) });
|
|
47
|
+
|
|
48
|
+
return { ...field, ready };
|
|
86
49
|
},
|
|
87
|
-
|
|
88
|
-
return this.form.getID(this)
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
data() {
|
|
92
|
-
return {}
|
|
93
|
-
}
|
|
94
|
-
})
|
|
50
|
+
});
|
|
95
51
|
</script>
|
|
96
52
|
|
|
97
53
|
<template>
|
|
98
|
-
<template v-if="!isSsr">
|
|
99
|
-
|
|
100
54
|
<Vue3PersianDatetimePicker
|
|
101
|
-
v-
|
|
55
|
+
v-if="ready"
|
|
56
|
+
v-model="model"
|
|
57
|
+
:name="name"
|
|
58
|
+
:id="inputId"
|
|
102
59
|
:type="calendar"
|
|
60
|
+
:view="view"
|
|
61
|
+
:min="min"
|
|
62
|
+
:max="max"
|
|
63
|
+
:range="range"
|
|
64
|
+
:locale="locale"
|
|
65
|
+
:format="format"
|
|
66
|
+
:input-format="inputFormat || format"
|
|
67
|
+
:placeholder="placeholder"
|
|
68
|
+
:disabled="isDisabled || readonly"
|
|
69
|
+
:input-class="[inputClass, { 'is-invalid': isInvalid }]"
|
|
103
70
|
editable
|
|
104
71
|
jumpminute="15"
|
|
105
|
-
:disabled="form?.processing || disabled"
|
|
106
72
|
:roundminute="true"
|
|
107
|
-
:
|
|
108
|
-
:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
73
|
+
:show-now-btn="true"
|
|
74
|
+
:auto-submit="true"
|
|
75
|
+
v-bind="pickerOptions"
|
|
76
|
+
@open="$emit('open')"
|
|
77
|
+
@close="$emit('close')"
|
|
78
|
+
/>
|
|
79
|
+
<input v-else type="text" class="form-control" :class="{ 'is-invalid': isInvalid }" :placeholder="placeholder" disabled />
|
|
114
80
|
</template>
|
|
115
|
-
<style>
|
|
116
|
-
.vpd-main .vpd-input-group {
|
|
117
|
-
display: block !important;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
.vpd-main .vpd-input-group input {
|
|
121
|
-
padding: 0.375rem 0.75rem !important;
|
|
122
|
-
border-radius: var(--bs-border-radius, .5rem) !important;
|
|
123
|
-
line-height: var(--bs-body-line-height, 1.5) !important;
|
|
124
|
-
border: 1px solid var(--bs-border-color, #dadada) !important
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
.vpd-main .vpd-icon-btn {
|
|
128
|
-
position: absolute;
|
|
129
|
-
right: 5px;
|
|
130
|
-
left: auto;
|
|
131
|
-
top: 0;
|
|
132
|
-
bottom: 0;
|
|
133
|
-
height: 30px;
|
|
134
|
-
min-width: 40px;
|
|
135
|
-
border: 1px solid var(--bs-secondary) !important;
|
|
136
|
-
background-color: var(--bs-secondary-bg) !important;
|
|
137
|
-
color: var(--bs-body-color, #000) !important;
|
|
138
|
-
border-radius: var(--bs-border-radius, .5rem);
|
|
139
|
-
margin: auto;
|
|
140
|
-
transition: all ease 0.3s;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
.vpd-main .vpd-icon-btn svg {
|
|
144
|
-
fill: var(--bs-body-color, #000) !important;
|
|
145
|
-
transition: all ease 0.3s;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
.vpd-main .vpd-icon-btn:hover {
|
|
149
|
-
background-color: var(--bs-secondary) !important;
|
|
150
|
-
color: var(--bs-body-color) !important;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
.vpd-main .vpd-icon-btn:hover svg {
|
|
154
|
-
fill: var(--bs-body-bg, #000) !important;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
.vpd-content {
|
|
158
|
-
color: var(--bs-body-color) !important;
|
|
159
|
-
background-color: var(--bs-body-bg) !important;
|
|
160
|
-
-moz-font-feature-settings: "ss01";
|
|
161
|
-
-webkit-font-feature-settings: "ss01";
|
|
162
|
-
font-feature-settings: "ss01";
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
.vpd-time .vpd-down-arrow-btn, .vpd-time .vpd-up-arrow-btn {
|
|
166
|
-
text-align: center;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
.vpd-time .vpd-down-arrow-btn svg,
|
|
170
|
-
.vpd-time .vpd-up-arrow-btn svg {
|
|
171
|
-
margin: 0 auto;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
.vpd-controls button {
|
|
175
|
-
display: flex;
|
|
176
|
-
align-items: center;
|
|
177
|
-
justify-content: center;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
.vpd-month-label {
|
|
181
|
-
width: 110px;
|
|
182
|
-
}
|
|
183
|
-
</style>
|
package/src/QuantityInput.vue
CHANGED
|
@@ -1,133 +1,114 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { computed, defineComponent, onMounted } from 'vue';
|
|
3
|
+
import { fieldProps, useField } from './composables/useField.js';
|
|
4
|
+
import { useI18n } from './i18n.js';
|
|
5
|
+
import { formatNumber, parseDigits } from './utils/digits.js';
|
|
4
6
|
|
|
7
|
+
/** Numeric stepper: [ − ] [ value ] [ + ] unit. */
|
|
5
8
|
export default defineComponent({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
name: 'QuantityInput',
|
|
10
|
+
emits: ['update:modelValue', 'change', 'input', 'increment', 'decrement', 'focus', 'blur'],
|
|
11
|
+
props: {
|
|
12
|
+
...fieldProps,
|
|
13
|
+
min: { type: Number, default: 0 },
|
|
14
|
+
max: { type: Number, default: null },
|
|
15
|
+
step: { type: Number, default: 1 },
|
|
16
|
+
unit: { type: String, default: null },
|
|
17
|
+
size: { type: String, default: null },
|
|
18
|
+
locale: { type: String, default: null },
|
|
11
19
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
unit: {
|
|
16
|
-
type: String,
|
|
17
|
-
default: 'عدد'
|
|
18
|
-
},
|
|
19
|
-
min: {
|
|
20
|
-
type: Number,
|
|
21
|
-
default: 0
|
|
22
|
-
},
|
|
23
|
-
max: {
|
|
24
|
-
type: Number,
|
|
25
|
-
default: null
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
setup(props) {
|
|
29
|
-
let form = inject('form');
|
|
30
|
-
let group = inject('group', {});
|
|
20
|
+
setup(props, { emit }) {
|
|
21
|
+
const field = useField(props, emit);
|
|
22
|
+
const { t } = useI18n(() => props.locale);
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
24
|
+
const current = computed(() => {
|
|
25
|
+
const n = Number(field.model.value);
|
|
26
|
+
return Number.isFinite(n) ? n : props.min;
|
|
27
|
+
});
|
|
39
28
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
const unitText = computed(() => props.unit ?? t('quantity.unit'));
|
|
30
|
+
const display = computed(() => formatNumber(current.value));
|
|
31
|
+
const lock = computed(() => props.readonly || field.isDisabled.value);
|
|
32
|
+
const canIncrement = computed(() => !lock.value && (props.max === null || current.value + props.step <= props.max));
|
|
33
|
+
const canDecrement = computed(() => !lock.value && current.value - props.step >= props.min);
|
|
43
34
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
} else {
|
|
52
|
-
form.value[props.name] = value;
|
|
35
|
+
function set(next, event, kind) {
|
|
36
|
+
let n = next;
|
|
37
|
+
if (props.max !== null) n = Math.min(n, props.max);
|
|
38
|
+
n = Math.max(n, props.min);
|
|
39
|
+
field.model.value = n;
|
|
40
|
+
if (kind) emit(kind, n);
|
|
41
|
+
field.emitChange(n, event);
|
|
53
42
|
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
43
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
44
|
+
function onInput(event) {
|
|
45
|
+
const parsed = parseDigits(event.target.value);
|
|
46
|
+
field.model.value = parsed === null ? props.min : parsed;
|
|
47
|
+
event.target.value = formatNumber(field.model.value);
|
|
48
|
+
emit('input', field.model.value, event);
|
|
49
|
+
}
|
|
60
50
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
51
|
+
onMounted(() => {
|
|
52
|
+
// A quantity is never empty: initialise it with the minimum
|
|
53
|
+
const v = field.model.value;
|
|
54
|
+
if (v === null || v === undefined || v === '') field.model.value = props.min;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
...field,
|
|
59
|
+
t,
|
|
60
|
+
unitText,
|
|
61
|
+
display,
|
|
62
|
+
canIncrement,
|
|
63
|
+
canDecrement,
|
|
64
|
+
lock,
|
|
65
|
+
increment: (e) => canIncrement.value && set(current.value + props.step, e, 'increment'),
|
|
66
|
+
decrement: (e) => canDecrement.value && set(current.value - props.step, e, 'decrement'),
|
|
67
|
+
onInput,
|
|
68
|
+
clampOnBlur: (e) => set(current.value, e),
|
|
69
|
+
};
|
|
73
70
|
},
|
|
74
|
-
|
|
75
|
-
if ((!this.min || (this.min < this.modelValue)) && this.modelValue > 1) {
|
|
76
|
-
this.modelValue = this.modelValue - 1;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
data() {
|
|
81
|
-
return {}
|
|
82
|
-
}
|
|
83
|
-
})
|
|
71
|
+
});
|
|
84
72
|
</script>
|
|
73
|
+
|
|
85
74
|
<template>
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
75
|
+
<div class="input-group input-group-quantity" :class="{ 'is-invalid': isInvalid }">
|
|
76
|
+
<button
|
|
77
|
+
type="button"
|
|
78
|
+
class="btn-outline theme-secondary btn-icon"
|
|
79
|
+
:disabled="!canIncrement"
|
|
80
|
+
:aria-label="t('quantity.increase')"
|
|
81
|
+
@click="increment"
|
|
82
|
+
>
|
|
83
|
+
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M8 3v10M3 8h10" /></svg>
|
|
84
|
+
</button>
|
|
85
|
+
<input
|
|
86
|
+
:name="name"
|
|
87
|
+
:id="inputId"
|
|
88
|
+
:value="display"
|
|
89
|
+
:readonly="readonly"
|
|
90
|
+
:disabled="isDisabled"
|
|
91
|
+
:aria-invalid="isInvalid || undefined"
|
|
92
|
+
type="tel"
|
|
93
|
+
inputmode="numeric"
|
|
94
|
+
autocomplete="off"
|
|
95
|
+
class="form-control fanum text-center"
|
|
96
|
+
:class="{ 'is-invalid': isInvalid }"
|
|
97
|
+
@input="onInput"
|
|
98
|
+
@change="clampOnBlur"
|
|
99
|
+
@focus="$emit('focus', $event)"
|
|
100
|
+
@blur="$emit('blur', $event)"
|
|
101
|
+
/>
|
|
102
|
+
<button
|
|
103
|
+
type="button"
|
|
104
|
+
class="btn-outline theme-secondary btn-icon"
|
|
105
|
+
:disabled="!canDecrement"
|
|
106
|
+
:aria-label="t('quantity.decrease')"
|
|
107
|
+
@click="decrement"
|
|
108
|
+
>
|
|
109
|
+
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M3 8h10" /></svg>
|
|
110
|
+
</button>
|
|
111
|
+
<span v-if="unitText" class="input-group-text fanum">{{ unitText }}</span>
|
|
112
|
+
<slot name="suffix" />
|
|
113
|
+
</div>
|
|
114
114
|
</template>
|
|
115
|
-
<style>
|
|
116
|
-
|
|
117
|
-
.input-group-quantity .input-group-text,
|
|
118
|
-
.input-group-quantity .btn {
|
|
119
|
-
background-color: var(--bs-body-bg);
|
|
120
|
-
--bs-btn-hover-bg: var(--bs-secondary-bg);
|
|
121
|
-
--bs-btn-active-bg: var(--bs-secondary-bg);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
.input-group-quantity input.form-control {
|
|
125
|
-
border: 0 !important;
|
|
126
|
-
box-shadow: none !important;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
.input-group-quantity .btn svg {
|
|
130
|
-
width: 14px;
|
|
131
|
-
height: 14px;
|
|
132
|
-
}
|
|
133
|
-
</style>
|