Ver código fonte

refactor: components

Muhammad Iqbal Afandi 3 anos atrás
pai
commit
8084ad3236

+ 27
- 41
resources/js/components/AppAutoComplete.vue Ver arquivo

1
 <script setup>
1
 <script setup>
2
-import { computed } from 'vue'
2
+import { computed, onMounted } from 'vue'
3
 import { Inertia } from '@inertiajs/inertia'
3
 import { Inertia } from '@inertiajs/inertia'
4
 
4
 
5
 const props = defineProps({
5
 const props = defineProps({
6
   label: {
6
   label: {
7
     type: String,
7
     type: String,
8
-    required: true,
9
-  },
10
-  labelClass: {
11
-    type: String,
12
-  },
13
-  disabled: {
14
-    type: Boolean,
15
-    default: false,
16
-  },
17
-  placeholder: {
18
-    type: String,
19
-    required: true,
8
+    required: false,
20
   },
9
   },
21
   error: {
10
   error: {
22
     type: String,
11
     type: String,
23
     default: null,
12
     default: null,
24
   },
13
   },
25
-  field: {
26
-    type: String,
27
-    required: true,
28
-  },
29
   empty: {
14
   empty: {
30
     type: Boolean,
15
     type: Boolean,
31
     default: false,
16
     default: false,
34
     type: String,
19
     type: String,
35
     required: true,
20
     required: true,
36
   },
21
   },
37
-  suggestions: {
38
-    type: Array,
39
-    required: true,
40
-  },
41
-  modelValue: null,
42
 })
22
 })
43
 
23
 
44
 const emit = defineEmits(['update:modelValue'])
24
 const emit = defineEmits(['update:modelValue'])
45
 
25
 
46
 const isError = computed(() => (props.error ? true : false))
26
 const isError = computed(() => (props.error ? true : false))
47
 
27
 
48
-const forLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-'))
49
-
50
 const ariaDescribedbyLabel = computed(
28
 const ariaDescribedbyLabel = computed(
51
-  () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
29
+  () => props.label?.toLowerCase().replace(/\s+/g, '-') + '-error'
52
 )
30
 )
53
 
31
 
32
+let param = props.refreshData.slice(0, -1).replace('-', '_')
33
+
34
+const removeParams = (...params) => {
35
+  const urlParams = new URLSearchParams(location.search)
36
+
37
+  params.forEach((value) => urlParams.delete(value))
38
+
39
+  history.replaceState({}, '', `${location.pathname}?${urlParams}`)
40
+}
41
+
42
+const onInput = (event) => {
43
+  if (event.target.value === '') {
44
+    removeParams(param)
45
+  }
46
+
47
+  emit('update:modelValue', event.target.value)
48
+}
49
+
54
 const onComplete = (event) => {
50
 const onComplete = (event) => {
55
   Inertia.reload({
51
   Inertia.reload({
56
     data: {
52
     data: {
57
-      [props.refreshData.slice(0, -1)]: event.query,
53
+      [param]: event.query,
58
     },
54
     },
59
     only: [props.refreshData],
55
     only: [props.refreshData],
60
   })
56
   })
61
 }
57
 }
62
-
63
-const onSelect = (event) => {
64
-  emit('update:modelValue', event.value)
65
-}
66
 </script>
58
 </script>
67
 
59
 
68
 <template>
60
 <template>
69
   <div class="field">
61
   <div class="field">
70
-    <label :for="forLabel" :class="labelClass">{{ label }}</label>
62
+    <label>{{ label }}</label>
71
 
63
 
72
     <AutoComplete
64
     <AutoComplete
73
       forceSelection
65
       forceSelection
74
       class="w-full"
66
       class="w-full"
75
       inputClass="w-full"
67
       inputClass="w-full"
76
-      :model-value="modelValue"
77
-      :id="forLabel"
78
       :class="{ 'p-invalid': isError }"
68
       :class="{ 'p-invalid': isError }"
79
-      :field="field"
80
-      :placeholder="placeholder"
81
-      :suggestions="suggestions"
82
-      :auto-highlight="true"
83
-      :disabled="disabled"
84
-      @input="$emit('update:modelValue', $event.target.value)"
85
-      @item-select="onSelect"
69
+      v-bind="$attrs"
70
+      @input="onInput"
71
+      @item-select="$emit('update:modelValue', $event.value)"
86
       @complete="onComplete"
72
       @complete="onComplete"
87
     >
73
     >
88
       <template #item="slotProps">
74
       <template #item="slotProps">
98
           'mb-2': empty,
84
           'mb-2': empty,
99
           'p-error': isError,
85
           'p-error': isError,
100
         }"
86
         }"
101
-        :id="ariaDescribedbyLabel"
87
+        :aria-describedby="ariaDescribedbyLabel"
102
       >
88
       >
103
         {{ error }}
89
         {{ error }}
104
       </small>
90
       </small>

+ 1
- 0
resources/js/components/AppDateRangeFilter.vue Ver arquivo

69
     class="w-full"
69
     class="w-full"
70
     selection-mode="range"
70
     selection-mode="range"
71
     date-format="dd/mm/yy"
71
     date-format="dd/mm/yy"
72
+    :placeholder="$attrs.placeholder"
72
     :manual-input="false"
73
     :manual-input="false"
73
     v-model="dates"
74
     v-model="dates"
74
   />
75
   />

+ 6
- 69
resources/js/components/AppDropdown.vue Ver arquivo

6
     type: String,
6
     type: String,
7
     required: false,
7
     required: false,
8
   },
8
   },
9
-  labelClass: {
10
-    type: String,
11
-  },
12
-  disabled: {
13
-    type: Boolean,
14
-    default: false,
15
-  },
16
-  placeholder: {
17
-    type: String,
18
-    required: true,
19
-  },
20
   error: {
9
   error: {
21
     type: String,
10
     type: String,
22
     default: null,
11
     default: null,
23
   },
12
   },
24
-  optionLabel: {
25
-    type: String,
26
-    default: 'label',
27
-  },
28
-  optionValue: {
29
-    type: String,
30
-    default: 'value',
31
-  },
32
-  optionDisabled: {
33
-    type: String,
34
-    default: 'disabled',
35
-  },
36
-  optionGroupChildren: {
37
-    type: String,
38
-    default: null,
39
-  },
40
-  optionGroupLabel: {
41
-    type: String,
42
-    default: null,
43
-  },
44
-  options: {
45
-    type: Array,
46
-    required: true,
47
-  },
48
-  modelValue: null,
49
 })
13
 })
50
 
14
 
51
 const isError = computed(() => (props.error ? true : false))
15
 const isError = computed(() => (props.error ? true : false))
52
 
16
 
53
-const forLabel = computed(() =>
54
-  props.label ? props.label.toLowerCase().replace(/\s+/g, '-') : null
55
-)
56
-
57
 const ariaDescribedbyLabel = computed(
17
 const ariaDescribedbyLabel = computed(
58
   () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
18
   () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
59
 )
19
 )
60
-
61
-const selectedDropdownLabel = (value) => {
62
-  const result = props.options.find((option) => {
63
-    if (option !== null) {
64
-      return option[props.optionValue] == value
65
-    }
66
-  })
67
-
68
-  if (result) {
69
-    return result[props.optionLabel]
70
-  }
71
-}
72
 </script>
20
 </script>
73
 
21
 
74
 <template>
22
 <template>
75
   <div class="field">
23
   <div class="field">
76
-    <label v-if="label" :for="forLabel" :class="labelClass">{{ label }}</label>
24
+    <label v-if="label">{{ label }}</label>
77
 
25
 
78
     <Dropdown
26
     <Dropdown
79
       class="w-full"
27
       class="w-full"
28
+      option-label="label"
29
+      option-value="value"
30
+      option-disabled="disabled"
80
       :class="{ 'p-invalid': isError }"
31
       :class="{ 'p-invalid': isError }"
81
-      :id="forLabel"
82
-      :option-disabled="optionDisabled"
83
-      :option-group-children="optionGroupChildren"
84
-      :option-group-label="optionGroupLabel"
85
-      :option-label="optionLabel"
86
-      :option-value="optionValue"
87
-      :placeholder="placeholder"
88
-      :options="options"
89
-      :model-value="modelValue"
90
-      :disabled="disabled"
32
+      v-bind="$attrs"
91
       @change="$emit('update:modelValue', $event.value)"
33
       @change="$emit('update:modelValue', $event.value)"
92
     >
34
     >
93
-      <template #value="slotProps">
94
-        <div v-if="slotProps.value">
95
-          {{ selectedDropdownLabel(slotProps.value) }}
96
-        </div>
97
-      </template>
98
     </Dropdown>
35
     </Dropdown>
99
 
36
 
100
     <small
37
     <small
101
       v-if="error"
38
       v-if="error"
102
-      :id="ariaDescribedbyLabel"
39
+      :aria-describedby="ariaDescribedbyLabel"
103
       :class="{ 'p-error': isError }"
40
       :class="{ 'p-error': isError }"
104
     >
41
     >
105
       {{ error }}
42
       {{ error }}

+ 3
- 23
resources/js/components/AppEditor.vue Ver arquivo

6
     type: String,
6
     type: String,
7
     required: true,
7
     required: true,
8
   },
8
   },
9
-  labelClass: {
10
-    type: String,
11
-  },
12
-  readOnly: {
13
-    type: Boolean,
14
-    required: false,
15
-  },
16
-  placeholder: {
17
-    type: String,
18
-    required: true,
19
-  },
20
   error: {
9
   error: {
21
     type: String,
10
     type: String,
22
     default: null,
11
     default: null,
23
   },
12
   },
24
-  editorStyle: null,
25
-  modelValue: null,
26
 })
13
 })
27
 
14
 
28
 const isError = computed(() => (props.error ? true : false))
15
 const isError = computed(() => (props.error ? true : false))
29
 
16
 
30
-const forLabel = computed(() =>
31
-  props.label ? props.label.toLowerCase().replace(/\s+/g, '-') : null
32
-)
33
-
34
 const ariaDescribedbyLabel = computed(
17
 const ariaDescribedbyLabel = computed(
35
   () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
18
   () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
36
 )
19
 )
38
 
21
 
39
 <template>
22
 <template>
40
   <div class="field">
23
   <div class="field">
41
-    <label v-if="label" :for="forLabel" :class="labelClass">{{ label }}</label>
24
+    <label v-if="label">{{ label }}</label>
42
 
25
 
43
     <Editor
26
     <Editor
44
-      :read-only="readOnly"
45
-      :model-value="modelValue"
46
-      :editor-style="editorStyle"
47
-      :placeholder="placeholder"
27
+      v-bind="$attrs"
48
       @text-change="$emit('update:modelValue', $event.htmlValue)"
28
       @text-change="$emit('update:modelValue', $event.htmlValue)"
49
     >
29
     >
50
       <template #toolbar>
30
       <template #toolbar>
54
 
34
 
55
     <small
35
     <small
56
       v-if="error"
36
       v-if="error"
57
-      :id="ariaDescribedbyLabel"
37
+      :aria-describedby="ariaDescribedbyLabel"
58
       :class="{ 'p-error': isError }"
38
       :class="{ 'p-error': isError }"
59
     >
39
     >
60
       {{ error }}
40
       {{ error }}

+ 3
- 75
resources/js/components/AppInputNumber.vue Ver arquivo

6
     type: String,
6
     type: String,
7
     required: true,
7
     required: true,
8
   },
8
   },
9
-  labelClass: {
10
-    type: String,
11
-  },
12
-  disabled: {
13
-    type: Boolean,
14
-    default: false,
15
-  },
16
-  placeholder: {
17
-    type: String,
18
-    required: true,
19
-  },
20
   error: {
9
   error: {
21
     type: String,
10
     type: String,
22
     default: null,
11
     default: null,
23
   },
12
   },
24
-  useGrouping: {
25
-    type: Boolean,
26
-    default: true,
27
-  },
28
-  mode: {
29
-    type: String,
30
-    default: 'decimal',
31
-  },
32
-  currency: {
33
-    type: String,
34
-    default: undefined,
35
-  },
36
-  locale: {
37
-    type: String,
38
-    default: undefined,
39
-  },
40
-  currencyDisplay: {
41
-    type: String,
42
-    default: undefined,
43
-  },
44
-  showButtons: {
45
-    type: Boolean,
46
-    default: false,
47
-  },
48
-  min: {
49
-    type: Number,
50
-    default: null,
51
-  },
52
-  max: {
53
-    type: Number,
54
-    default: null,
55
-  },
56
-  step: {
57
-    type: Number,
58
-    default: 1,
59
-  },
60
-  prefix: {
61
-    type: String,
62
-    default: null,
63
-  },
64
-  suffix: {
65
-    type: String,
66
-    default: null,
67
-  },
68
-  modelValue: null,
69
 })
13
 })
70
 
14
 
71
 const isError = computed(() => (props.error ? true : false))
15
 const isError = computed(() => (props.error ? true : false))
72
 
16
 
73
-const forLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-'))
74
-
75
 const ariaDescribedbyLabel = computed(
17
 const ariaDescribedbyLabel = computed(
76
   () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
18
   () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
77
 )
19
 )
79
 
21
 
80
 <template>
22
 <template>
81
   <div class="field">
23
   <div class="field">
82
-    <label :for="forLabel" :class="labelClass">{{ label }}</label>
24
+    <label>{{ label }}</label>
83
 
25
 
84
     <InputNumber
26
     <InputNumber
85
       class="w-full"
27
       class="w-full"
86
       input-class="w-full"
28
       input-class="w-full"
87
-      :currency="currency"
88
-      :currency-display="currencyDisplay"
89
-      :locale="locale"
90
       :class="{ 'p-invalid': isError }"
29
       :class="{ 'p-invalid': isError }"
91
-      :id="forLabel"
92
-      :placeholder="placeholder"
93
-      :model-value="modelValue"
94
-      :disabled="disabled"
95
-      :prefix="prefix"
96
-      :suffix="suffix"
97
-      :step="step"
98
-      :min="min"
99
-      :max="max"
100
-      :mode="mode"
101
-      :use-grouping="useGrouping"
102
-      :show-buttons="showButtons"
30
+      v-bind="$attrs"
103
       @input="$emit('update:modelValue', $event.value)"
31
       @input="$emit('update:modelValue', $event.value)"
104
     />
32
     />
105
 
33
 
106
     <small
34
     <small
107
       v-if="error"
35
       v-if="error"
108
-      :id="ariaDescribedbyLabel"
36
+      :aria-describedby="ariaDescribedbyLabel"
109
       :class="{ 'p-error': isError }"
37
       :class="{ 'p-error': isError }"
110
     >
38
     >
111
       {{ error }}
39
       {{ error }}

+ 3
- 25
resources/js/components/AppInputText.vue Ver arquivo

6
     type: String,
6
     type: String,
7
     required: true,
7
     required: true,
8
   },
8
   },
9
-  labelClass: {
10
-    type: String,
11
-  },
12
-  disabled: {
13
-    type: Boolean,
14
-    default: false,
15
-  },
16
-  placeholder: {
17
-    type: String,
18
-    required: true,
19
-  },
20
-  type: {
21
-    type: String,
22
-    default: 'text',
23
-  },
24
   error: {
9
   error: {
25
     type: String,
10
     type: String,
26
     default: null,
11
     default: null,
27
   },
12
   },
28
-  modelValue: null,
29
 })
13
 })
30
 
14
 
31
 const isError = computed(() => (props.error ? true : false))
15
 const isError = computed(() => (props.error ? true : false))
32
 
16
 
33
-const forLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-'))
34
-
35
 const ariaDescribedbyLabel = computed(
17
 const ariaDescribedbyLabel = computed(
36
   () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
18
   () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
37
 )
19
 )
39
 
21
 
40
 <template>
22
 <template>
41
   <div class="field">
23
   <div class="field">
42
-    <label :for="forLabel" :class="labelClass">{{ label }}</label>
24
+    <label>{{ label }}</label>
43
 
25
 
44
     <InputText
26
     <InputText
45
       class="w-full"
27
       class="w-full"
46
-      :type="type"
47
       :class="{ 'p-invalid': isError }"
28
       :class="{ 'p-invalid': isError }"
48
-      :id="forLabel"
49
-      :model-value="modelValue"
50
-      :placeholder="placeholder"
51
-      :disabled="disabled"
29
+      v-bind="$attrs"
52
       @input="$emit('update:modelValue', $event.target.value)"
30
       @input="$emit('update:modelValue', $event.target.value)"
53
     />
31
     />
54
 
32
 
55
     <small
33
     <small
56
       v-if="error"
34
       v-if="error"
57
-      :id="ariaDescribedbyLabel"
35
+      :aria-describedby="ariaDescribedbyLabel"
58
       :class="{ 'p-error': isError }"
36
       :class="{ 'p-error': isError }"
59
     >
37
     >
60
       {{ error }}
38
       {{ error }}

+ 3
- 41
resources/js/components/AppPassword.vue Ver arquivo

6
     type: String,
6
     type: String,
7
     required: true,
7
     required: true,
8
   },
8
   },
9
-  labelClass: {
10
-    type: String,
11
-  },
12
-  disabled: {
13
-    type: Boolean,
14
-    default: false,
15
-  },
16
-  placeholder: {
17
-    type: String,
18
-    required: true,
19
-  },
20
-  promptLabel: {
21
-    type: String,
22
-    default: 'Masukan kata sandi',
23
-  },
24
-  weakLabel: {
25
-    type: String,
26
-    default: 'Ah Lemah',
27
-  },
28
-  mediumLabel: {
29
-    type: String,
30
-    default: 'Lumayan',
31
-  },
32
-  strongLabel: {
33
-    type: String,
34
-    default: 'Wow Kuat',
35
-  },
36
   error: {
9
   error: {
37
     type: String,
10
     type: String,
38
     default: null,
11
     default: null,
39
   },
12
   },
40
-  modelValue: null,
41
 })
13
 })
42
 
14
 
43
 const isError = computed(() => (props.error ? true : false))
15
 const isError = computed(() => (props.error ? true : false))
44
 
16
 
45
-const forLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-'))
46
-
47
 const ariaDescribedbyLabel = computed(
17
 const ariaDescribedbyLabel = computed(
48
   () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
18
   () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
49
 )
19
 )
51
 
21
 
52
 <template>
22
 <template>
53
   <div class="field">
23
   <div class="field">
54
-    <label :for="forLabel" :class="labelClass">{{ label }}</label>
24
+    <label>{{ label }}</label>
55
 
25
 
56
     <Password
26
     <Password
57
       class="w-full"
27
       class="w-full"
58
       input-class="w-full"
28
       input-class="w-full"
59
       :class="{ 'p-invalid': isError }"
29
       :class="{ 'p-invalid': isError }"
60
-      :promptLabel="promptLabel"
61
-      :weakLabel="weakLabel"
62
-      :mediumLabel="mediumLabel"
63
-      :strongLabel="strongLabel"
64
-      :disabled="disabled"
65
-      :id="forLabel"
66
-      :placeholder="placeholder"
67
-      :toggleMask="true"
68
-      :model-value="modelValue"
30
+      v-bind="$attrs"
69
       @input="$emit('update:modelValue', $event.target.value)"
31
       @input="$emit('update:modelValue', $event.target.value)"
70
     />
32
     />
71
 
33
 
72
     <small
34
     <small
73
       v-if="error"
35
       v-if="error"
74
-      :id="ariaDescribedbyLabel"
36
+      :aria-describedby="ariaDescribedbyLabel"
75
       :class="{ 'p-error': isError }"
37
       :class="{ 'p-error': isError }"
76
     >
38
     >
77
       {{ error }}
39
       {{ error }}

+ 1
- 1
resources/js/components/AppResetFilter.vue Ver arquivo

14
 </script>
14
 </script>
15
 
15
 
16
 <template>
16
 <template>
17
-  <Button label="reset" class="p-button-link" @click="reset()" />
17
+  <Button label="reset" class="p-button-link" @click="reset" />
18
 </template>
18
 </template>

+ 3
- 31
resources/js/components/AppTextArea.vue Ver arquivo

6
     type: String,
6
     type: String,
7
     required: true,
7
     required: true,
8
   },
8
   },
9
-  labelClass: {
10
-    type: String,
11
-  },
12
-  disabled: {
13
-    type: Boolean,
14
-    default: false,
15
-  },
16
-  placeholder: {
17
-    type: String,
18
-    required: true,
19
-  },
20
   error: {
9
   error: {
21
     type: String,
10
     type: String,
22
     default: null,
11
     default: null,
23
   },
12
   },
24
-  rows: {
25
-    type: Number,
26
-    default: 5,
27
-  },
28
-  cols: {
29
-    type: Number,
30
-    default: 30,
31
-  },
32
-  modelValue: null,
33
 })
13
 })
34
 
14
 
35
 const isError = computed(() => (props.error ? true : false))
15
 const isError = computed(() => (props.error ? true : false))
36
 
16
 
37
-const forLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-'))
38
-
39
 const ariaDescribedbyLabel = computed(
17
 const ariaDescribedbyLabel = computed(
40
   () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
18
   () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
41
 )
19
 )
43
 
21
 
44
 <template>
22
 <template>
45
   <div class="field">
23
   <div class="field">
46
-    <label :for="forLabel" :class="labelClass">{{ label }}</label>
24
+    <label>{{ label }}</label>
47
 
25
 
48
     <Textarea
26
     <Textarea
49
       class="w-full"
27
       class="w-full"
50
       :class="{ 'p-invalid': isError }"
28
       :class="{ 'p-invalid': isError }"
51
-      :id="forLabel"
52
-      :model-value="modelValue"
53
-      :placeholder="placeholder"
54
-      :disabled="disabled"
55
-      :auto-resize="true"
56
-      :rows="rows"
57
-      :cols="cols"
29
+      v-bind="$attrs"
58
       @input="$emit('update:modelValue', $event.target.value)"
30
       @input="$emit('update:modelValue', $event.target.value)"
59
     />
31
     />
60
 
32
 
61
     <small
33
     <small
62
       v-if="error"
34
       v-if="error"
63
-      :id="ariaDescribedbyLabel"
35
+      :aria-describedby="ariaDescribedbyLabel"
64
       :class="{ 'p-error': isError }"
36
       :class="{ 'p-error': isError }"
65
     >
37
     >
66
       {{ error }}
38
       {{ error }}