generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d31bb06
commit c569b2d
Showing
9 changed files
with
279 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<template> | ||
<div :class="['lvw-input-feedback', {'lvw-without-feedback': !hasFeedback}]"> | ||
<div v-if="hasFeedback" :class="['lvw-feedback', errors !== false ? 'lvw-red' : `lvw-${theme}`]" @click="focusInput"> | ||
{{ finalMessage }} | ||
</div> | ||
<MaxLength v-if="showMaxLength" :id="id" :field="field" :form="form" :show-max-length="showMaxLength" :theme="theme"/> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import {defineComponent, PropType} from "vue"; | ||
import {InertiaForm} from "@inertiajs/vue3/types/useForm"; | ||
import MaxLength from "./MaxLength.vue"; | ||
export default defineComponent({ | ||
name: "InputFeedback", | ||
components: {MaxLength}, | ||
props: { | ||
id: String, | ||
feedback: String, | ||
field: {type: String, required: true}, | ||
form: {type: Object as PropType<InertiaForm<object>>, required: true}, | ||
showMaxLength: Boolean, | ||
theme: String, | ||
}, | ||
computed: { | ||
errors(): string|false | ||
{ | ||
let errors: undefined|string|false = this.form.errors[this.field]; | ||
return errors !== false && (errors === undefined || errors.trim() === '') ? false : errors; | ||
}, | ||
finalMessage(): false|string { | ||
let feedback : string|undefined|false = this.feedback; | ||
return feedback === undefined || feedback.trim() === '' ? false : feedback; | ||
}, | ||
hasFeedback(): boolean { | ||
return this.finalMessage !== false; | ||
}, | ||
}, | ||
methods: { | ||
focusInput() { | ||
document.getElementById(this.id)?.focus(); | ||
}, | ||
}, | ||
}) | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.lvw-input-feedback { | ||
@apply mt-1 w-full flex justify-between items-start gap-2; | ||
&.lvw-without-feedback { | ||
@apply flex-row-reverse; | ||
} | ||
.lvw-feedback { | ||
@apply grow text-sm ps-1; | ||
&.lvw-gray { | ||
@apply text-gray-800/80 | ||
} | ||
&.lvw-green { | ||
@apply text-green-900/80 | ||
} | ||
&.lvw-indigo { | ||
@apply text-indigo-900/80 | ||
} | ||
&.lvw-primary { | ||
@apply text-primary-900/80 | ||
} | ||
&.lvw-slate { | ||
@apply text-slate-900/80 | ||
} | ||
&.lvw-red { | ||
@apply text-red-700/80 | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<template> | ||
<div v-if="maxlength !== null && length !== null && showMaxLength" :class="['lvw-input-maxlength', `lvw-${theme}`]"> | ||
{{ `${fLength}/${fMaxlength}` }} | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import {defineComponent, PropType} from "vue"; | ||
import {InertiaForm} from "@inertiajs/vue3/types/useForm"; | ||
export default defineComponent({ | ||
name: "MaxLength", | ||
props: { | ||
id: String, | ||
field: {type: String, required: true}, | ||
form: {type: Object as PropType<InertiaForm<object>>, required: true}, | ||
showMaxLength: Boolean, | ||
theme: String, | ||
}, | ||
data() { | ||
return { | ||
el: null, | ||
maxlength: null, | ||
length: null, | ||
} | ||
}, | ||
computed: { | ||
fLength(): string { | ||
return Intl.NumberFormat().format(this.length); | ||
}, | ||
fMaxlength(): string { | ||
return Intl.NumberFormat().format(this.maxlength); | ||
}, | ||
limit(): number|null { | ||
if (this.maxlength === null) { | ||
return null; | ||
} | ||
let constant = (1 - (this.maxlength > 1000 ? 100 : this.maxlength / 10) / 100) / 2; | ||
let limit = Math.floor(this.maxlength * constant); | ||
let halfMaxlength = this.maxlength / 2; | ||
if (limit > halfMaxlength) { | ||
limit = Math.floor(this.maxlength / 2); | ||
} | ||
if (this.maxlength > 250) { | ||
limit = 30; | ||
} | ||
return limit; | ||
}, | ||
// attentionLimit(): number|null { | ||
// return this.length >= this.maxlength; | ||
// }, | ||
// warnLimit(): number|null { | ||
// return this.length >= this.maxlength; | ||
// }, | ||
}, | ||
mounted() { | ||
this.init(); | ||
this.getLength(this.form[this.field]); | ||
this.$watch('form.' + this.field, this.getLength); | ||
console.log(this.limit); | ||
}, | ||
methods: { | ||
getLength(word): null | number { | ||
this.length = word?.length ?? 0; | ||
}, | ||
getMaxlength(): null | number { | ||
let maxlength: string | null = this?.el.getAttribute('maxlength'); | ||
return typeof maxlength === 'string' && /^\d+$/.test(maxlength) ? parseInt(maxlength) : null; | ||
}, | ||
init(): void { | ||
this.el = document.getElementById(this.id); | ||
this.maxlength = this.getMaxlength(); | ||
} | ||
}, | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.lvw-input-maxlength { | ||
@apply inline-flex items-center rounded-lg mt-[0.15em] px-[0.3em] py-[0.05em] text-[0.7em] font-medium ; | ||
&.lvw-gray { | ||
@apply bg-gray-600/30 text-gray-700 | ||
} | ||
&.lvw-green { | ||
@apply bg-green-600/30 text-green-700 | ||
} | ||
&.lvw-indigo { | ||
@apply bg-indigo-600/30 text-indigo-700 | ||
} | ||
&.lvw-primary { | ||
@apply bg-primary-600/30 text-primary-700 | ||
} | ||
&.lvw-slate { | ||
@apply bg-slate-600/30 text-slate-700 | ||
} | ||
&.lvw-red { | ||
@apply bg-red-600/30 text-red-700 | ||
} | ||
&.lvw-yellow { | ||
@apply bg-yellow-600/30 text-yellow-700 | ||
} | ||
} | ||
</style> |
Oops, something went wrong.