inertia-bootstrap-forms 1.0.0 → 1.0.3

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.
Files changed (37) hide show
  1. package/README.md +46 -0
  2. package/dist/css/from-select.scss +374 -0
  3. package/index.js +49 -0
  4. package/package.json +15 -1
  5. package/{Inputs → src}/AmountInput.vue +1 -2
  6. package/{Inputs → src}/CaptchaInput.vue +11 -6
  7. package/{Inputs/CheckboxInput.vue → src/CheckboxButtonInput.vue} +21 -8
  8. package/src/CheckboxInput.vue +79 -0
  9. package/src/CheckboxToggle.vue +109 -0
  10. package/{Inputs → src}/EditorInput.vue +1 -0
  11. package/{Inputs → src}/EmailInput.vue +1 -1
  12. package/{Inputs → src}/FormContainer.vue +22 -9
  13. package/src/GroupControl.vue +67 -0
  14. package/src/MultiQuantityInput.vue +68 -0
  15. package/src/PersianDatePickerInput.vue +176 -0
  16. package/src/QuantityInput.vue +106 -0
  17. package/src/SecondarySubmitButton.vue +22 -0
  18. package/src/Select2Input.vue +190 -0
  19. package/src/StarRatingInput.vue +158 -0
  20. package/{Inputs → src}/SubmitButton.vue +4 -2
  21. package/src/TextAreaInput.vue +44 -0
  22. package/src/TextInput.vue +51 -0
  23. package/src/locationInput.vue +124 -0
  24. package/Bootstrap/InputGroup.vue +0 -9
  25. package/Bootstrap/InputGroupText.vue +0 -9
  26. package/Inputs/DatePickerInput.vue +0 -137
  27. package/Inputs/Select2Input.vue +0 -193
  28. package/Inputs/TextAreaInput.vue +0 -33
  29. package/Inputs/TextInput.vue +0 -34
  30. package/Inputs/locationInput.vue +0 -122
  31. package/vue-select.css +0 -387
  32. /package/{Inputs → src}/FileInput.vue +0 -0
  33. /package/{Inputs → src}/FormLabel.vue +0 -0
  34. /package/{Inputs → src}/MobileInput.vue +0 -0
  35. /package/{Inputs → src}/PasswordInput.vue +0 -0
  36. /package/{Inputs → src}/TelInput.vue +0 -0
  37. /package/{Inputs → src}/countryCodes.js +0 -0
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # InertiaJS Form Components for Laravel
2
+
3
+ If you're using InertiaJS in Laravel and are tired of creating repetitive forms and numerous components, we've created this package for ourselves and decided to share it with you. Everything is easily usable through Vue.
4
+
5
+ ## Example:
6
+
7
+ ```vue
8
+ <FormContainer v-model="formData">
9
+ <div class="row g-3">
10
+ <div class="col-12 col-sm-6">
11
+ <FormLabel>Name</FormLabel>
12
+ <TextInput name="name" />
13
+ </div>
14
+ <div class="col-12 col-sm-3">
15
+ <FormLabel>Alias</FormLabel>
16
+ <TextInput name="slug"/>
17
+ </div>
18
+ <div class="col-12 col-sm-3">
19
+ <FormLabel>Status</FormLabel>
20
+ <Select2Input name="status" :options="[
21
+ { id: 'active', name: 'Active' },
22
+ { id: 'disable', name: 'Disabled' },
23
+ { id: 'draft', name: 'Draft' }
24
+ ]"/>
25
+ </div>
26
+ <div class="col-12 col-sm-6">
27
+ <FormLabel>New Image</FormLabel>
28
+ <FileInput name="new_thumbnail" />
29
+ </div>
30
+ <div class="col-12">
31
+ <FormLabel>Description</FormLabel>
32
+ <EditorInput name="description" />
33
+ </div>
34
+ <div class="col-12 text-end">
35
+ <SubmitButton />
36
+ </div>
37
+ </div>
38
+ </FormContainer>
39
+ ```
40
+
41
+ This package simplifies form creation and management in your InertiaJS and Laravel applications, reducing redundancy and improving development efficiency.
42
+
43
+ If you need to upload files using the `FileInput` component in Laravel and manage them server-side, use our prepared package:
44
+
45
+ **novinvision/simple-uploader**
46
+
@@ -0,0 +1,374 @@
1
+ /* purgecss start ignore */
2
+ .choices {
3
+ color: var(--bs-body-color);
4
+ position: relative;
5
+ overflow: hidden;
6
+ margin-bottom: 24px;
7
+ font-size: var(--bs-body-font-size)
8
+ }
9
+
10
+ .choices:focus {
11
+ outline: 0
12
+ }
13
+
14
+ .choices:last-child {
15
+ margin-bottom: 0
16
+ }
17
+
18
+ .choices.is-open {
19
+ overflow: visible
20
+ }
21
+
22
+ .choices.is-disabled .choices__inner, .choices.is-disabled .choices__input {
23
+ background-color: #eaeaea;
24
+ cursor: not-allowed;
25
+ -webkit-user-select: none;
26
+ user-select: none
27
+ }
28
+
29
+ .choices.is-disabled .choices__item {
30
+ cursor: not-allowed
31
+ }
32
+
33
+ .choices [hidden] {
34
+ display: none !important
35
+ }
36
+
37
+ .choices[data-type*=select-one] {
38
+ cursor: pointer
39
+ }
40
+
41
+ /**
42
+ //.choices[data-type*=select-one] .choices__inner {
43
+ // padding-bottom: 7.5px
44
+ //}*/
45
+
46
+ .choices[data-type*=select-one] .choices__input {
47
+ display: block;
48
+ width: 100%;
49
+ padding: 10px;
50
+ border-bottom: 1px solid #ddd;
51
+ background-color: #fff;
52
+ margin: 0
53
+ }
54
+
55
+ .choices[data-type*=select-one] .choices__button {
56
+ background-image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjEiIGhlaWdodD0iMjEiIHZpZXdCb3g9IjAgMCAyMSAyMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSIjMDAwIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0yLjU5Mi4wNDRsMTguMzY0IDE4LjM2NC0yLjU0OCAyLjU0OEwuMDQ0IDIuNTkyeiIvPjxwYXRoIGQ9Ik0wIDE4LjM2NEwxOC4zNjQgMGwyLjU0OCAyLjU0OEwyLjU0OCAyMC45MTJ6Ii8+PC9nPjwvc3ZnPg==);
57
+ padding: 0;
58
+ background-size: 8px;
59
+ position: absolute;
60
+ top: 50%;
61
+ right: 0;
62
+ margin-top: -10px;
63
+ margin-right: 25px;
64
+ height: 20px;
65
+ width: 20px;
66
+ border-radius: 10em;
67
+ opacity: .25
68
+ }
69
+
70
+ .choices[data-type*=select-one] .choices__button:focus, .choices[data-type*=select-one] .choices__button:hover {
71
+ opacity: 1
72
+ }
73
+
74
+ .choices[data-type*=select-one] .choices__button:focus {
75
+ box-shadow: 0 0 0 2px #005f75
76
+ }
77
+
78
+ .choices[data-type*=select-one] .choices__item[data-placeholder] .choices__button {
79
+ display: none
80
+ }
81
+
82
+ .choices[data-type*=select-one]::after {
83
+ content: "";
84
+ height: 0;
85
+ width: 0;
86
+ border-style: solid;
87
+ border-color: #333 transparent transparent;
88
+ border-width: 5px;
89
+ position: absolute;
90
+ right: 11.5px;
91
+ top: 50%;
92
+ margin-top: -2.5px;
93
+ pointer-events: none
94
+ }
95
+
96
+ .choices[data-type*=select-one].is-open::after {
97
+ border-color: transparent transparent #333;
98
+ margin-top: -7.5px
99
+ }
100
+
101
+ .choices[data-type*=select-one][dir=rtl]::after {
102
+ left: 11.5px;
103
+ right: auto
104
+ }
105
+
106
+ .choices[data-type*=select-one][dir=rtl] .choices__button {
107
+ right: auto;
108
+ left: 0;
109
+ margin-left: 25px;
110
+ margin-right: 0
111
+ }
112
+
113
+ .choices[data-type*=select-multiple] .choices__inner, .choices[data-type*=text] .choices__inner {
114
+ cursor: text
115
+ }
116
+
117
+ .choices[data-type*=select-multiple] .choices__button, .choices[data-type*=text] .choices__button {
118
+ position: relative;
119
+ display: inline-block;
120
+ margin: 0-4px 0 8px;
121
+ padding-left: .8rem;
122
+ background-image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjEiIGhlaWdodD0iMjEiIHZpZXdCb3g9IjAgMCAyMSAyMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSIjRkZGIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0yLjU5Mi4wNDRsMTguMzY0IDE4LjM2NC0yLjU0OCAyLjU0OEwuMDQ0IDIuNTkyeiIvPjxwYXRoIGQ9Ik0wIDE4LjM2NEwxOC4zNjQgMGwyLjU0OCAyLjU0OEwyLjU0OCAyMC45MTJ6Ii8+PC9nPjwvc3ZnPg==);
123
+ background-size: 8px;
124
+ width: 8px;
125
+ line-height: 1;
126
+ opacity: .75;
127
+ border-radius: 0
128
+ }
129
+
130
+ .choices[data-type*=select-multiple] .choices__button:focus, .choices[data-type*=select-multiple] .choices__button:hover, .choices[data-type*=text] .choices__button:focus, .choices[data-type*=text] .choices__button:hover {
131
+ opacity: 1
132
+ }
133
+
134
+ .choices__inner {
135
+ display: inline-block;
136
+ vertical-align: top;
137
+ width: 100%;
138
+ background-color: var(--bs-body-bg, #ffffff);
139
+ padding: calc(.5rem - 4px) .75rem calc(.5rem - 4px) .75rem;
140
+ border: 1px solid #ddd;
141
+ border-radius: var(--bs-border-radius);
142
+ font-size: var(--bs-body-font-size);
143
+ min-height: 44px;
144
+ overflow: hidden
145
+ }
146
+
147
+ .is-focused .choices__inner, .is-open .choices__inner {
148
+ border-color: #b7b7b7
149
+ }
150
+
151
+ .is-open .choices__inner {
152
+ border-radius: var(--bs-border-radius) var(--bs-border-radius) 0 0
153
+ }
154
+
155
+ .is-flipped.is-open .choices__inner {
156
+ border-radius: 0 0 var(--bs-border-radius) var(--bs-border-radius)
157
+ }
158
+
159
+ .choices__list {
160
+ margin: 0;
161
+ padding-left: 0;
162
+ list-style: none
163
+ }
164
+
165
+ .choices__list--single {
166
+ display: inline-block;
167
+ padding: 4px 16px 4px 4px;
168
+ width: 100%
169
+ }
170
+
171
+ [dir=rtl] .choices__list--single {
172
+ padding-right: 4px;
173
+ padding-left: 16px
174
+ }
175
+
176
+ .choices__list--single .choices__item {
177
+ width: 100%
178
+ }
179
+
180
+ .choices__list--multiple {
181
+ display: inline
182
+ }
183
+
184
+ .choices__list--multiple .choices__item {
185
+ display: inline-block;
186
+ vertical-align: middle;
187
+ border-radius: var(--bs-border-radius);
188
+ padding: 2px 10px;
189
+ line-height:2;
190
+ font-size: .8rem;
191
+ font-weight: 500;
192
+ margin-right: 3.75px;
193
+ margin-bottom: 3.75px;
194
+ background-color: #999999;
195
+ border: 1px solid #999999;
196
+ color: #fff;
197
+ word-break: break-all;
198
+ box-sizing: border-box
199
+ }
200
+
201
+ .choices__list--multiple .choices__item[data-deletable] {
202
+ padding-right: 5px
203
+ }
204
+
205
+ [dir=rtl] .choices__list--multiple .choices__item {
206
+ margin-right: 0;
207
+ margin-left: 3.75px
208
+ }
209
+
210
+ .choices__list--multiple .choices__item.is-highlighted {
211
+ background-color: #004a5c;
212
+ border: 1px solid #003642
213
+ }
214
+
215
+ .is-disabled .choices__list--multiple .choices__item {
216
+ background-color: #aaa;
217
+ border: 1px solid #919191
218
+ }
219
+
220
+ .choices__list--dropdown, .choices__list[aria-expanded] {
221
+ display: none;
222
+ z-index: 3;
223
+ position: absolute;
224
+ width: 100%;
225
+ background-color: #fff;
226
+ border: 1px solid #ddd;
227
+ top: 100%;
228
+ margin-top: -1px;
229
+ border-bottom-left-radius: var(--bs-border-radius);
230
+ border-bottom-right-radius: var(--bs-border-radius);
231
+ overflow: hidden;
232
+ word-break: break-all
233
+ }
234
+
235
+ .is-active.choices__list--dropdown, .is-active.choices__list[aria-expanded] {
236
+ display: block
237
+ }
238
+
239
+ .is-open .choices__list--dropdown, .is-open .choices__list[aria-expanded] {
240
+ border-color: #b7b7b7
241
+ }
242
+
243
+ .is-flipped .choices__list--dropdown, .is-flipped .choices__list[aria-expanded] {
244
+ top: auto;
245
+ bottom: 100%;
246
+ margin-top: 0;
247
+ margin-bottom: -1px;
248
+ border-radius: var(--bs-border-radius) var(--bs-border-radius) 0 0
249
+ }
250
+
251
+ .choices__list--dropdown .choices__list, .choices__list[aria-expanded] .choices__list {
252
+ position: relative;
253
+ max-height: 300px;
254
+ overflow: auto;
255
+ -webkit-overflow-scrolling: touch;
256
+ will-change: scroll-position
257
+ }
258
+
259
+ .choices__list--dropdown .choices__item, .choices__list[aria-expanded] .choices__item {
260
+ position: relative;
261
+ padding: 10px;
262
+ font-size: 14px
263
+ }
264
+
265
+ [dir=rtl] .choices__list--dropdown .choices__item, [dir=rtl] .choices__list[aria-expanded] .choices__item {
266
+ text-align: right
267
+ }
268
+
269
+ @media (min-width: 640px) {
270
+ .choices__list--dropdown .choices__item--selectable[data-select-text], .choices__list[aria-expanded] .choices__item--selectable[data-select-text] {
271
+ padding-right: 100px
272
+ }
273
+ .choices__list--dropdown .choices__item--selectable[data-select-text]::after, .choices__list[aria-expanded] .choices__item--selectable[data-select-text]::after {
274
+ content: attr(data-select-text);
275
+ font-size: 12px;
276
+ opacity: 0;
277
+ position: absolute;
278
+ right: 10px;
279
+ top: 50%;
280
+ transform: translateY(-50%)
281
+ }
282
+ [dir=rtl] .choices__list--dropdown .choices__item--selectable[data-select-text], [dir=rtl] .choices__list[aria-expanded] .choices__item--selectable[data-select-text] {
283
+ text-align: right;
284
+ padding-left: 100px;
285
+ padding-right: 10px
286
+ }
287
+ [dir=rtl] .choices__list--dropdown .choices__item--selectable[data-select-text]::after, [dir=rtl] .choices__list[aria-expanded] .choices__item--selectable[data-select-text]::after {
288
+ right: auto;
289
+ left: 10px
290
+ }
291
+ }
292
+
293
+ .choices__list--dropdown .choices__item--selectable.is-highlighted, .choices__list[aria-expanded] .choices__item--selectable.is-highlighted {
294
+ background-color: #f2f2f2
295
+ }
296
+
297
+ .choices__list--dropdown .choices__item--selectable.is-highlighted::after, .choices__list[aria-expanded] .choices__item--selectable.is-highlighted::after {
298
+ opacity: .5
299
+ }
300
+
301
+ .choices__item {
302
+ cursor: default
303
+ }
304
+
305
+ .choices__item.has-no-choices {
306
+ font-style: italic;
307
+ background-color: var(--bs-tertiary-bg, #f7f7f7);
308
+ color: var(--bs-secondary-color, #666666);
309
+ }
310
+
311
+ .choices__item--selectable {
312
+ cursor: pointer
313
+ }
314
+
315
+ .choices__item--disabled {
316
+ cursor: not-allowed;
317
+ -webkit-user-select: none;
318
+ user-select: none;
319
+ opacity: .5
320
+ }
321
+
322
+ .choices__heading {
323
+ font-weight: 600;
324
+ font-size: 12px;
325
+ padding: 10px;
326
+ border-bottom: 1px solid #f7f7f7;
327
+ color: gray
328
+ }
329
+
330
+ .choices__button {
331
+ text-indent: -9999px;
332
+ appearance: none;
333
+ border: 0;
334
+ background-color: transparent;
335
+ background-repeat: no-repeat;
336
+ background-position: center;
337
+ cursor: pointer
338
+ }
339
+
340
+ .choices__button:focus, .choices__input:focus {
341
+ outline: 0
342
+ }
343
+
344
+ .choices__input {
345
+ display: inline-block;
346
+ vertical-align: baseline;
347
+ background-color: #f9f9f9;
348
+ font-size: var(--bs-body-font-size);
349
+ border: 0;
350
+ border-radius: 0;
351
+ max-width: 100%;
352
+ padding: 4px 0 4px 2px
353
+ }
354
+
355
+ .choices__input::-webkit-search-cancel-button, .choices__input::-webkit-search-decoration, .choices__input::-webkit-search-results-button, .choices__input::-webkit-search-results-decoration {
356
+ display: none
357
+ }
358
+
359
+ .choices__input::-ms-clear, .choices__input::-ms-reveal {
360
+ display: none;
361
+ width: 0;
362
+ height: 0
363
+ }
364
+
365
+ [dir=rtl] .choices__input {
366
+ padding-right: 2px;
367
+ padding-left: 0
368
+ }
369
+
370
+ .choices__placeholder {
371
+ opacity: .5
372
+ }
373
+
374
+ /* purgecss end ignore */
package/index.js ADDED
@@ -0,0 +1,49 @@
1
+ import AmountInput from "./src/AmountInput.vue";
2
+ import CaptchaInput from "./src/CaptchaInput.vue";
3
+ import CheckboxButtonInput from "./src/CheckboxButtonInput.vue";
4
+ import CheckboxInput from "./src/CheckboxInput.vue";
5
+ import CheckboxToggle from "./src/CheckboxToggle.vue";
6
+ import PersianDatePickerInput from "./src/PersianDatePickerInput.vue";
7
+ import EditorInput from "./src/EditorInput.vue";
8
+ import FileInput from "./src/FileInput.vue";
9
+ import EmailInput from "./src/EmailInput.vue";
10
+ import GroupControl from "./src/GroupControl.vue";
11
+ import FormContainer from "./src/FormContainer.vue";
12
+ import FormLabel from "./src/FormLabel.vue";
13
+ import locationInput from "./src/locationInput.vue";
14
+ import MobileInput from "./src/MobileInput.vue";
15
+ import PasswordInput from "./src/PasswordInput.vue";
16
+ import QuantityInput from "./src/QuantityInput.vue";
17
+ import SecondarySubmitButton from "./src/SecondarySubmitButton.vue";
18
+ import Select2Input from "./src/Select2Input.vue";
19
+ import StarRatingInput from "./src/StarRatingInput.vue";
20
+ import SubmitButton from "./src/SubmitButton.vue";
21
+ import TelInput from "./src/TelInput.vue";
22
+ import TextAreaInput from "./src/TextAreaInput.vue";
23
+ import TextInput from "./src/TextInput.vue";
24
+
25
+ export {
26
+ AmountInput,
27
+ CaptchaInput,
28
+ CheckboxButtonInput,
29
+ CheckboxInput,
30
+ CheckboxToggle,
31
+ FileInput,
32
+ EmailInput,
33
+ PersianDatePickerInput,
34
+ EditorInput,
35
+ GroupControl,
36
+ FormContainer,
37
+ locationInput,
38
+ MobileInput,
39
+ PasswordInput,
40
+ QuantityInput,
41
+ SubmitButton,
42
+ SecondarySubmitButton,
43
+ StarRatingInput,
44
+ Select2Input,
45
+ FormLabel,
46
+ TelInput,
47
+ TextAreaInput,
48
+ TextInput,
49
+ }
package/package.json CHANGED
@@ -1,11 +1,17 @@
1
1
  {
2
2
  "name": "inertia-bootstrap-forms",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "Create bootstrap forms with inertia and twitter bootstrap",
5
5
  "main": "index.js",
6
+ "module": "index.js",
7
+ "type": "module",
6
8
  "scripts": {
7
9
  "test": "echo \"Error: no test specified\" && exit 1"
8
10
  },
11
+ "files": [
12
+ "dist/*",
13
+ "src/*"
14
+ ],
9
15
  "author": "NovinVision",
10
16
  "license": "ISC",
11
17
  "repository": {
@@ -21,6 +27,14 @@
21
27
  ],
22
28
  "dependencies": {
23
29
  "vue": "^3.0.0",
30
+ "vue-tel-input": "^9.3.0",
31
+ "@vue-leaflet/vue-leaflet": "^0.10.1",
32
+ "choices.js": "^11.1.0",
33
+ "vue3-persian-datetime-picker": "^1.2.2",
34
+ "vue-final-modal": "^4.5.5",
35
+ "@inertiajs/vue3": "^2.0.3",
36
+ "@tinymce/tinymce-vue": "^6.1.0",
37
+ "vue3-bootstrap-components": "^1.0.4",
24
38
  "vue-select": "^4.0.0-beta.6"
25
39
  },
26
40
  "bugs": {
@@ -1,6 +1,5 @@
1
1
  <script>
2
- import InputGroup from '../Bootstrap/InputGroup.vue';
3
- import InputGroupText from '../Bootstrap/InputGroupText.vue';
2
+ import {InputGroup, InputGroupText} from 'vue3-bootstrap-components';
4
3
  import {inject} from "vue";
5
4
 
6
5
  export default {
@@ -9,6 +9,11 @@ export default {
9
9
  default: 'captcha',
10
10
  required: false,
11
11
  },
12
+ url: {
13
+ type: String,
14
+ default: '/captcha/default',
15
+ required: false,
16
+ },
12
17
  modelValue: '',
13
18
  required: Boolean,
14
19
  placeholder: {
@@ -37,7 +42,7 @@ export default {
37
42
  },
38
43
  async getSrc() {
39
44
  this.loading = true;
40
- this.src = '/captcha/default?t=' + Math.random();
45
+ this.src = this.url + '?t=' + Math.random();
41
46
 
42
47
  let _this = this;
43
48
  setTimeout(function () {
@@ -48,7 +53,7 @@ export default {
48
53
  data() {
49
54
  return {
50
55
  loading: false,
51
- src: '/captcha/default?t=' + Math.random(),
56
+ src: this.url + Math.random(),
52
57
  };
53
58
  }
54
59
  };
@@ -84,8 +89,8 @@ export default {
84
89
  width: 82px;
85
90
  height: 43px;
86
91
  object-fit: contain;
87
- border-top: 1px solid var(--bs-border-color);
88
- border-bottom: 1px solid var(--bs-border-color);
92
+ border-top: 1px solid var(--bs-border-color, #eeeeee);
93
+ border-bottom: 1px solid var(--bs-border-color, #eeeeee);
89
94
  }
90
95
 
91
96
  .input-group-lg.captcha .captcha-holder {
@@ -94,7 +99,7 @@ export default {
94
99
  }
95
100
 
96
101
  .captcha .btn-refresh {
97
- background-color: var(--bs-body-bg);
98
- border-color: var(--bs-border-color) !important;
102
+ background-color: var(--bs-body-bg, #ffffff);
103
+ border-color: var(--bs-border-color, #eeeeee) !important;
99
104
  }
100
105
  </style>
@@ -2,6 +2,7 @@
2
2
  import {inject} from "vue";
3
3
 
4
4
  export default {
5
+ emits: ['change'],
5
6
  props: {
6
7
  name: {
7
8
  type: String,
@@ -19,10 +20,15 @@ export default {
19
20
  },
20
21
  type: {
21
22
  type: String,
22
- default: 'checkbox',
23
+ default: 'radio',
23
24
  required: false,
24
25
  },
25
26
  },
27
+ methods:{
28
+ change(e){
29
+ this.$emit('change', e);
30
+ }
31
+ },
26
32
  setup(props) {
27
33
  let form = inject('form');
28
34
 
@@ -30,6 +36,7 @@ export default {
30
36
  form = {
31
37
  errors: {},
32
38
  getID(name) {
39
+ return name;
33
40
  }
34
41
  };
35
42
  }
@@ -39,18 +46,24 @@ export default {
39
46
  }
40
47
  </script>
41
48
  <template>
42
- <div class="form-check">
49
+ <label class="btn-label" :for="form.getID(name)+(id || value)" :class="{'active': (form[name] === value || form[name] === true)}">
43
50
  <input
44
51
  :name="name"
45
52
  :id="form.getID(name)+(id || value)"
46
- v-model="form[this.name]"
53
+ v-model="form[name]"
47
54
  :class="{'is-invalid': form?.errors[name]}"
48
55
  :disabled="form?.processing"
49
56
  :type="type"
50
57
  :value="value"
51
- class="form-check-input">
52
- <label class="form-check-label" :for="form.getID(name)+(id || value)">
53
- <slot/>
54
- </label>
55
- </div>
58
+ @change="change"
59
+ autocomplete="off"
60
+ class="btn-check">
61
+ <slot/>
62
+ </label>
56
63
  </template>
64
+ <style>
65
+ .btn-label:not(.active){
66
+ --bs-bg-opacity: .3;
67
+ opacity: .6;
68
+ }
69
+ </style>
@@ -0,0 +1,79 @@
1
+ <script>
2
+ import {computed, inject} from "vue";
3
+
4
+ export default {
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 + (group ? '_' + group?.name + '-'+group?.groupID : '')"
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>