inertia-bootstrap-forms 1.2.4 → 2.1.2
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/{index-D75YLzF9.js → index-DPnt8V-r.js} +1 -1
- package/dist/{index-CRXhNEv4.js → index-gG_QMV91.js} +287 -269
- package/dist/inertia-bootstrap-forms.es.js +1 -1
- package/dist/inertia-bootstrap-forms.umd.js +5 -5
- package/package.json +2 -2
- package/src/AmountInput.vue +74 -51
- package/src/CheckboxButtonInput.vue +69 -69
- package/src/CheckboxInput.vue +79 -79
- package/src/CheckboxToggle.vue +113 -113
- package/src/FormContainer.vue +180 -180
- package/src/TextInput.vue +51 -51
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inertia-bootstrap-forms",
|
|
3
|
-
"version": "1.2
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Create bootstrap forms with inertia and twitter bootstrap",
|
|
5
5
|
"main": "dist/inertia-bootstrap-forms.cjs.js",
|
|
6
6
|
"module": "dist/inertia-bootstrap-forms.es.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"vue3-persian-datetime-picker": "^1.2.2"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@inertiajs/vue3": ">
|
|
57
|
+
"@inertiajs/vue3": ">3.0",
|
|
58
58
|
"dropzone": "^6.0.0-beta.2",
|
|
59
59
|
"vue": "^3.0"
|
|
60
60
|
},
|
package/src/AmountInput.vue
CHANGED
|
@@ -1,63 +1,86 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import {InputGroup, InputGroupText} from 'vue3-bootstrap-components';
|
|
3
|
-
import {defineComponent, inject} from "vue";
|
|
3
|
+
import {computed, defineComponent, inject} from "vue";
|
|
4
4
|
|
|
5
5
|
export default defineComponent({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
required: Boolean,
|
|
13
|
-
disabled: Boolean,
|
|
14
|
-
readonly: Boolean,
|
|
15
|
-
placeholder: {
|
|
16
|
-
type: String,
|
|
17
|
-
default: 'عدد را وارد کنید'
|
|
18
|
-
},
|
|
19
|
-
unit: {
|
|
20
|
-
type: String,
|
|
21
|
-
default: 'عدد'
|
|
22
|
-
},
|
|
6
|
+
components: {InputGroup, InputGroupText},
|
|
7
|
+
props: {
|
|
8
|
+
name: {
|
|
9
|
+
type: String,
|
|
10
|
+
required: true,
|
|
23
11
|
},
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
required: Boolean,
|
|
13
|
+
disabled: Boolean,
|
|
14
|
+
readonly: Boolean,
|
|
15
|
+
placeholder: {
|
|
16
|
+
type: String,
|
|
17
|
+
default: 'عدد را وارد کنید'
|
|
18
|
+
},
|
|
19
|
+
unit: {
|
|
20
|
+
type: String,
|
|
21
|
+
default: 'عدد'
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
setup(props) {
|
|
25
|
+
let form = inject('form', {
|
|
26
|
+
errors: {},
|
|
27
|
+
getID(name) {
|
|
28
|
+
return name;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
let group = inject('group', {});
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
const modelValue = computed({
|
|
34
|
+
get() {
|
|
35
|
+
return (group.value && form.value[group.value.name]) ? group.value?.getData(props.name) : form.value[props.name];
|
|
36
|
+
},
|
|
37
|
+
set(value) {
|
|
38
|
+
if (group?.value?.name) {
|
|
39
|
+
group.value.setData(props.name, value);
|
|
40
|
+
} else {
|
|
41
|
+
form.value[props.name] = value;
|
|
33
42
|
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
34
45
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
const persianDigits = '۰۱۲۳۴۵۶۷۸۹';
|
|
47
|
+
const arabicDigits = '٠١٢٣٤٥٦٧٨٩';
|
|
48
|
+
function toEnglishDigits(str) {
|
|
49
|
+
return String(str).replace(/[۰-۹٠-٩]/g, (ch) => {
|
|
50
|
+
const pIndex = persianDigits.indexOf(ch);
|
|
51
|
+
if (pIndex !== -1) return pIndex;
|
|
52
|
+
return arabicDigits.indexOf(ch);
|
|
53
|
+
});
|
|
42
54
|
}
|
|
55
|
+
|
|
56
|
+
const displayValue = computed({
|
|
57
|
+
get() {
|
|
58
|
+
const raw = modelValue.value;
|
|
59
|
+
if (raw === null || raw === undefined || raw === '') return '';
|
|
60
|
+
return Number(raw).toLocaleString('en-US');
|
|
61
|
+
},
|
|
62
|
+
set(value) {
|
|
63
|
+
const digitsOnly = toEnglishDigits(value).replace(/\D/g, '');
|
|
64
|
+
modelValue.value = digitsOnly === '' ? null : parseInt(digitsOnly, 10);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return {modelValue, displayValue, form, group};
|
|
69
|
+
},
|
|
43
70
|
})
|
|
44
71
|
</script>
|
|
45
72
|
<template>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
<InputGroupText class="fanum">{{ unit }}</InputGroupText>
|
|
61
|
-
<slot name="suffix"/>
|
|
62
|
-
</InputGroup>
|
|
63
|
-
</template>
|
|
73
|
+
<InputGroup>
|
|
74
|
+
<input
|
|
75
|
+
:name="name"
|
|
76
|
+
v-model="displayValue"
|
|
77
|
+
:class="{'is-invalid': form.errors[name]}"
|
|
78
|
+
:disabled="disabled || form.processing"
|
|
79
|
+
:readonly="readonly"
|
|
80
|
+
:placeholder="placeholder"
|
|
81
|
+
type="tel"
|
|
82
|
+
class="form-control fanum text-start">
|
|
83
|
+
<InputGroupText class="fanum">{{ unit }}</InputGroupText>
|
|
84
|
+
<slot name="suffix"/>
|
|
85
|
+
</InputGroup>
|
|
86
|
+
</template>
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {defineComponent, inject} from "vue";
|
|
3
|
-
|
|
4
|
-
export default defineComponent({
|
|
5
|
-
emits: ['change'],
|
|
6
|
-
props: {
|
|
7
|
-
name: {
|
|
8
|
-
type: String,
|
|
9
|
-
required: true,
|
|
10
|
-
},
|
|
11
|
-
id: {
|
|
12
|
-
type: String,
|
|
13
|
-
default: '',
|
|
14
|
-
required: false,
|
|
15
|
-
},
|
|
16
|
-
value: {
|
|
17
|
-
type: String,
|
|
18
|
-
default: 'yes',
|
|
19
|
-
required: false,
|
|
20
|
-
},
|
|
21
|
-
type: {
|
|
22
|
-
type: String,
|
|
23
|
-
default: 'radio',
|
|
24
|
-
required: false,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
methods:{
|
|
28
|
-
change(e){
|
|
29
|
-
this.$emit('change', e);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
setup(props) {
|
|
33
|
-
let form = inject('form');
|
|
34
|
-
|
|
35
|
-
if (form === undefined) {
|
|
36
|
-
form = {
|
|
37
|
-
errors: {},
|
|
38
|
-
getID(name) {
|
|
39
|
-
return name;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return {form};
|
|
45
|
-
},
|
|
46
|
-
})
|
|
47
|
-
</script>
|
|
48
|
-
<template>
|
|
49
|
-
<label class="btn-label" :for="form.getID(name)+(id || value)" :class="{'active': (form[name] === value || form[name] === true)}">
|
|
50
|
-
<input
|
|
51
|
-
:name="name"
|
|
52
|
-
:id="form.getID(name)+(id || value)"
|
|
53
|
-
v-model="form[name]"
|
|
54
|
-
:class="{'is-invalid': form?.errors[name]}"
|
|
55
|
-
:disabled="form?.processing"
|
|
56
|
-
:type="type"
|
|
57
|
-
:value="value"
|
|
58
|
-
@change="change"
|
|
59
|
-
autocomplete="off"
|
|
60
|
-
class="btn-check">
|
|
61
|
-
<slot/>
|
|
62
|
-
</label>
|
|
63
|
-
</template>
|
|
64
|
-
<style>
|
|
65
|
-
.btn-label:not(.active){
|
|
66
|
-
--bs-bg-opacity: .3;
|
|
67
|
-
opacity: .6;
|
|
68
|
-
}
|
|
69
|
-
</style>
|
|
1
|
+
<script>
|
|
2
|
+
import {defineComponent, inject} from "vue";
|
|
3
|
+
|
|
4
|
+
export default defineComponent({
|
|
5
|
+
emits: ['change'],
|
|
6
|
+
props: {
|
|
7
|
+
name: {
|
|
8
|
+
type: String,
|
|
9
|
+
required: true,
|
|
10
|
+
},
|
|
11
|
+
id: {
|
|
12
|
+
type: String,
|
|
13
|
+
default: '',
|
|
14
|
+
required: false,
|
|
15
|
+
},
|
|
16
|
+
value: {
|
|
17
|
+
type: String,
|
|
18
|
+
default: 'yes',
|
|
19
|
+
required: false,
|
|
20
|
+
},
|
|
21
|
+
type: {
|
|
22
|
+
type: String,
|
|
23
|
+
default: 'radio',
|
|
24
|
+
required: false,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
methods:{
|
|
28
|
+
change(e){
|
|
29
|
+
this.$emit('change', e);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
setup(props) {
|
|
33
|
+
let form = inject('form');
|
|
34
|
+
|
|
35
|
+
if (form === undefined) {
|
|
36
|
+
form = {
|
|
37
|
+
errors: {},
|
|
38
|
+
getID(name) {
|
|
39
|
+
return name;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {form};
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
</script>
|
|
48
|
+
<template>
|
|
49
|
+
<label class="btn-label" :for="form.getID(name)+(id || value)" :class="{'active': (form[name] === value || form[name] === true)}">
|
|
50
|
+
<input
|
|
51
|
+
:name="name"
|
|
52
|
+
:id="form.getID(name)+(id || value)"
|
|
53
|
+
v-model="form[name]"
|
|
54
|
+
:class="{'is-invalid': form?.errors[name]}"
|
|
55
|
+
:disabled="form?.processing"
|
|
56
|
+
:type="type"
|
|
57
|
+
:value="value"
|
|
58
|
+
@change="change"
|
|
59
|
+
autocomplete="off"
|
|
60
|
+
class="btn-check">
|
|
61
|
+
<slot/>
|
|
62
|
+
</label>
|
|
63
|
+
</template>
|
|
64
|
+
<style>
|
|
65
|
+
.btn-label:not(.active){
|
|
66
|
+
--bs-bg-opacity: .3;
|
|
67
|
+
opacity: .6;
|
|
68
|
+
}
|
|
69
|
+
</style>
|
package/src/CheckboxInput.vue
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {computed, defineComponent, inject} from "vue";
|
|
3
|
-
|
|
4
|
-
export default defineComponent({
|
|
5
|
-
props: {
|
|
6
|
-
name: {
|
|
7
|
-
type: String,
|
|
8
|
-
required: true,
|
|
9
|
-
},
|
|
10
|
-
id: {
|
|
11
|
-
type: String,
|
|
12
|
-
default: '',
|
|
13
|
-
required: false,
|
|
14
|
-
},
|
|
15
|
-
value: {
|
|
16
|
-
type: [String, Number],
|
|
17
|
-
default: 'yes',
|
|
18
|
-
required: false,
|
|
19
|
-
},
|
|
20
|
-
type: {
|
|
21
|
-
type: String,
|
|
22
|
-
default: 'checkbox',
|
|
23
|
-
required: false,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
computed: {
|
|
27
|
-
inputID() {
|
|
28
|
-
return this.form.getID(this);
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
setup(props) {
|
|
32
|
-
let form = inject('form', {
|
|
33
|
-
errors: {},
|
|
34
|
-
getID(name) {
|
|
35
|
-
return name;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
let group = inject('group', {});
|
|
39
|
-
|
|
40
|
-
const modelValue = computed({
|
|
41
|
-
get() {
|
|
42
|
-
return (group.value && form.value[group.value.name]) ? group.value?.getData(props.name) : form.value[props.name];
|
|
43
|
-
},
|
|
44
|
-
set(value) {
|
|
45
|
-
if (group?.value?.name) {
|
|
46
|
-
group.value.setData(props.name, value);
|
|
47
|
-
} else {
|
|
48
|
-
form.value[props.name] = value;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return {modelValue, form, group};
|
|
54
|
-
},
|
|
55
|
-
})
|
|
56
|
-
</script>
|
|
57
|
-
<template>
|
|
58
|
-
<div class="form-check">
|
|
59
|
-
<input
|
|
60
|
-
:name="name"
|
|
61
|
-
:id="inputID"
|
|
62
|
-
v-model="modelValue"
|
|
63
|
-
:class="{'is-invalid': form?.errors[name]}"
|
|
64
|
-
:disabled="form?.processing"
|
|
65
|
-
:type="type"
|
|
66
|
-
:value="value"
|
|
67
|
-
@change="e => $emit('change', e)"
|
|
68
|
-
class="form-check-input">
|
|
69
|
-
<label class="form-check-label" :for="inputID">
|
|
70
|
-
<slot/>
|
|
71
|
-
</label>
|
|
72
|
-
</div>
|
|
73
|
-
</template>
|
|
74
|
-
<style>
|
|
75
|
-
.form-check,
|
|
76
|
-
.form-check label {
|
|
77
|
-
cursor: pointer;
|
|
78
|
-
}
|
|
79
|
-
</style>
|
|
1
|
+
<script>
|
|
2
|
+
import {computed, defineComponent, inject} from "vue";
|
|
3
|
+
|
|
4
|
+
export default defineComponent({
|
|
5
|
+
props: {
|
|
6
|
+
name: {
|
|
7
|
+
type: String,
|
|
8
|
+
required: true,
|
|
9
|
+
},
|
|
10
|
+
id: {
|
|
11
|
+
type: String,
|
|
12
|
+
default: '',
|
|
13
|
+
required: false,
|
|
14
|
+
},
|
|
15
|
+
value: {
|
|
16
|
+
type: [String, Number],
|
|
17
|
+
default: 'yes',
|
|
18
|
+
required: false,
|
|
19
|
+
},
|
|
20
|
+
type: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: 'checkbox',
|
|
23
|
+
required: false,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
computed: {
|
|
27
|
+
inputID() {
|
|
28
|
+
return this.form.getID(this);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
setup(props) {
|
|
32
|
+
let form = inject('form', {
|
|
33
|
+
errors: {},
|
|
34
|
+
getID(name) {
|
|
35
|
+
return name;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
let group = inject('group', {});
|
|
39
|
+
|
|
40
|
+
const modelValue = computed({
|
|
41
|
+
get() {
|
|
42
|
+
return (group.value && form.value[group.value.name]) ? group.value?.getData(props.name) : form.value[props.name];
|
|
43
|
+
},
|
|
44
|
+
set(value) {
|
|
45
|
+
if (group?.value?.name) {
|
|
46
|
+
group.value.setData(props.name, value);
|
|
47
|
+
} else {
|
|
48
|
+
form.value[props.name] = value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return {modelValue, form, group};
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
</script>
|
|
57
|
+
<template>
|
|
58
|
+
<div class="form-check">
|
|
59
|
+
<input
|
|
60
|
+
:name="name"
|
|
61
|
+
:id="inputID"
|
|
62
|
+
v-model="modelValue"
|
|
63
|
+
:class="{'is-invalid': form?.errors[name]}"
|
|
64
|
+
:disabled="form?.processing"
|
|
65
|
+
:type="type"
|
|
66
|
+
:value="value"
|
|
67
|
+
@change="e => $emit('change', e)"
|
|
68
|
+
class="form-check-input">
|
|
69
|
+
<label class="form-check-label" :for="inputID">
|
|
70
|
+
<slot/>
|
|
71
|
+
</label>
|
|
72
|
+
</div>
|
|
73
|
+
</template>
|
|
74
|
+
<style>
|
|
75
|
+
.form-check,
|
|
76
|
+
.form-check label {
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
}
|
|
79
|
+
</style>
|
package/src/CheckboxToggle.vue
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {computed, defineComponent, inject} from "vue";
|
|
3
|
-
|
|
4
|
-
export default defineComponent({
|
|
5
|
-
props: {
|
|
6
|
-
name: {
|
|
7
|
-
type: String,
|
|
8
|
-
required: true,
|
|
9
|
-
},
|
|
10
|
-
id: {
|
|
11
|
-
type: String,
|
|
12
|
-
default: '',
|
|
13
|
-
required: false,
|
|
14
|
-
},
|
|
15
|
-
value: {
|
|
16
|
-
type: [String, Number],
|
|
17
|
-
default: 'yes',
|
|
18
|
-
required: false,
|
|
19
|
-
},
|
|
20
|
-
type: {
|
|
21
|
-
type: String,
|
|
22
|
-
default: 'checkbox',
|
|
23
|
-
required: false,
|
|
24
|
-
},
|
|
25
|
-
hideInput: {
|
|
26
|
-
type: Boolean,
|
|
27
|
-
default: false,
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
computed: {
|
|
31
|
-
inputID() {
|
|
32
|
-
return this.form.getID(this) + (this.value || '');
|
|
33
|
-
},
|
|
34
|
-
selectedValue(){
|
|
35
|
-
return (typeof this.modelValue == 'object') ? Object.values(this.modelValue) : (this.modelValue ? [this.modelValue] : null)
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
setup(props) {
|
|
39
|
-
let form = inject('form', {
|
|
40
|
-
errors: {},
|
|
41
|
-
getID(name) {
|
|
42
|
-
return name;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
let group = inject('group', {});
|
|
46
|
-
|
|
47
|
-
const modelValue = computed({
|
|
48
|
-
get() {
|
|
49
|
-
return (group.value && form.value[group.value.name]) ? group.value?.getData(props.name) : form.value[props.name];
|
|
50
|
-
},
|
|
51
|
-
set(value) {
|
|
52
|
-
if (group?.value?.name) {
|
|
53
|
-
group.value.setData(props.name, value);
|
|
54
|
-
} else {
|
|
55
|
-
form.value[props.name] = value;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
return {modelValue, form, group};
|
|
61
|
-
},
|
|
62
|
-
})
|
|
63
|
-
</script>
|
|
64
|
-
<template>
|
|
65
|
-
<label class="form-check-toggle" :class="{'form-check-toggle--active': (selectedValue || []).includes(value)}" :for="inputID">
|
|
66
|
-
<input
|
|
67
|
-
:name="name + (group ? '_' + group?.name + '-'+group?.groupID : '')"
|
|
68
|
-
:id="inputID"
|
|
69
|
-
v-model="modelValue"
|
|
70
|
-
:class="{'is-invalid': form?.errors[name], 'form-check-toggle--input-hide': hideInput}"
|
|
71
|
-
:disabled="form?.processing"
|
|
72
|
-
:type="type"
|
|
73
|
-
:value="value"
|
|
74
|
-
@change="e => $emit('change', e)"
|
|
75
|
-
class="form-check-toggle--input form-check-input">
|
|
76
|
-
<slot/>
|
|
77
|
-
</label>
|
|
78
|
-
</template>
|
|
79
|
-
<style>
|
|
80
|
-
.form-check-toggle {
|
|
81
|
-
position: relative;
|
|
82
|
-
cursor: pointer;
|
|
83
|
-
display: block;
|
|
84
|
-
background-color: var(--bs-body-bg, #ffffff);
|
|
85
|
-
border-radius: var(--bs-border-radius, 1rem);
|
|
86
|
-
min-width: 100px;
|
|
87
|
-
width: 100%;
|
|
88
|
-
padding: 0.5rem 0.75rem;
|
|
89
|
-
font-size: 0.97rem;
|
|
90
|
-
font-weight: 400;
|
|
91
|
-
line-height: 1.7;
|
|
92
|
-
color: var(--bs-body-color, #000000);
|
|
93
|
-
-webkit-appearance: none;
|
|
94
|
-
-moz-appearance: none;
|
|
95
|
-
appearance: none;
|
|
96
|
-
background-clip: padding-box;
|
|
97
|
-
border: var(--bs-border-width, 1px) solid var(--bs-border-color, #eeeeee);
|
|
98
|
-
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
.form-check-toggle.form-check-toggle--active,
|
|
102
|
-
.form-check-toggle:has(input:checked){
|
|
103
|
-
background-color: var(--bs-warning-bg-subtle, #ffda6a);
|
|
104
|
-
border-color: var(--bs-warning-border-subtle, var(--bs-alert-border-color, #fff0c3));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
.form-check-toggle .form-check-toggle--input-hide {
|
|
108
|
-
visibility: hidden;
|
|
109
|
-
position: absolute;
|
|
110
|
-
top: 0;
|
|
111
|
-
right: 0;
|
|
112
|
-
}
|
|
113
|
-
</style>
|
|
1
|
+
<script>
|
|
2
|
+
import {computed, defineComponent, inject} from "vue";
|
|
3
|
+
|
|
4
|
+
export default defineComponent({
|
|
5
|
+
props: {
|
|
6
|
+
name: {
|
|
7
|
+
type: String,
|
|
8
|
+
required: true,
|
|
9
|
+
},
|
|
10
|
+
id: {
|
|
11
|
+
type: String,
|
|
12
|
+
default: '',
|
|
13
|
+
required: false,
|
|
14
|
+
},
|
|
15
|
+
value: {
|
|
16
|
+
type: [String, Number],
|
|
17
|
+
default: 'yes',
|
|
18
|
+
required: false,
|
|
19
|
+
},
|
|
20
|
+
type: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: 'checkbox',
|
|
23
|
+
required: false,
|
|
24
|
+
},
|
|
25
|
+
hideInput: {
|
|
26
|
+
type: Boolean,
|
|
27
|
+
default: false,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
computed: {
|
|
31
|
+
inputID() {
|
|
32
|
+
return this.form.getID(this) + (this.value || '');
|
|
33
|
+
},
|
|
34
|
+
selectedValue(){
|
|
35
|
+
return (typeof this.modelValue == 'object') ? Object.values(this.modelValue) : (this.modelValue ? [this.modelValue] : null)
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
setup(props) {
|
|
39
|
+
let form = inject('form', {
|
|
40
|
+
errors: {},
|
|
41
|
+
getID(name) {
|
|
42
|
+
return name;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
let group = inject('group', {});
|
|
46
|
+
|
|
47
|
+
const modelValue = computed({
|
|
48
|
+
get() {
|
|
49
|
+
return (group.value && form.value[group.value.name]) ? group.value?.getData(props.name) : form.value[props.name];
|
|
50
|
+
},
|
|
51
|
+
set(value) {
|
|
52
|
+
if (group?.value?.name) {
|
|
53
|
+
group.value.setData(props.name, value);
|
|
54
|
+
} else {
|
|
55
|
+
form.value[props.name] = value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return {modelValue, form, group};
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
</script>
|
|
64
|
+
<template>
|
|
65
|
+
<label class="form-check-toggle" :class="{'form-check-toggle--active': (selectedValue || []).includes(value)}" :for="inputID">
|
|
66
|
+
<input
|
|
67
|
+
:name="name + (group ? '_' + group?.name + '-'+group?.groupID : '')"
|
|
68
|
+
:id="inputID"
|
|
69
|
+
v-model="modelValue"
|
|
70
|
+
:class="{'is-invalid': form?.errors[name], 'form-check-toggle--input-hide': hideInput}"
|
|
71
|
+
:disabled="form?.processing"
|
|
72
|
+
:type="type"
|
|
73
|
+
:value="value"
|
|
74
|
+
@change="e => $emit('change', e)"
|
|
75
|
+
class="form-check-toggle--input form-check-input">
|
|
76
|
+
<slot/>
|
|
77
|
+
</label>
|
|
78
|
+
</template>
|
|
79
|
+
<style>
|
|
80
|
+
.form-check-toggle {
|
|
81
|
+
position: relative;
|
|
82
|
+
cursor: pointer;
|
|
83
|
+
display: block;
|
|
84
|
+
background-color: var(--bs-body-bg, #ffffff);
|
|
85
|
+
border-radius: var(--bs-border-radius, 1rem);
|
|
86
|
+
min-width: 100px;
|
|
87
|
+
width: 100%;
|
|
88
|
+
padding: 0.5rem 0.75rem;
|
|
89
|
+
font-size: 0.97rem;
|
|
90
|
+
font-weight: 400;
|
|
91
|
+
line-height: 1.7;
|
|
92
|
+
color: var(--bs-body-color, #000000);
|
|
93
|
+
-webkit-appearance: none;
|
|
94
|
+
-moz-appearance: none;
|
|
95
|
+
appearance: none;
|
|
96
|
+
background-clip: padding-box;
|
|
97
|
+
border: var(--bs-border-width, 1px) solid var(--bs-border-color, #eeeeee);
|
|
98
|
+
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.form-check-toggle.form-check-toggle--active,
|
|
102
|
+
.form-check-toggle:has(input:checked){
|
|
103
|
+
background-color: var(--bs-warning-bg-subtle, #ffda6a);
|
|
104
|
+
border-color: var(--bs-warning-border-subtle, var(--bs-alert-border-color, #fff0c3));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.form-check-toggle .form-check-toggle--input-hide {
|
|
108
|
+
visibility: hidden;
|
|
109
|
+
position: absolute;
|
|
110
|
+
top: 0;
|
|
111
|
+
right: 0;
|
|
112
|
+
}
|
|
113
|
+
</style>
|