dev: compact styling
This commit is contained in:
No files matched your search
@@ -0,0 +1,75 @@
|
||||
<script setup lang="ts">
|
||||
import type { FormErrors } from '~/types/error'
|
||||
import FieldGroup from '~/components/pub/my-ui/form/field-group.vue'
|
||||
import Field from '~/components/pub/my-ui/form/field.vue'
|
||||
import Label from '~/components/pub/my-ui/form/label.vue'
|
||||
import { Input } from '~/components/pub/ui/input'
|
||||
import { cn } from '~/lib/utils'
|
||||
|
||||
import * as DE from '~/components/pub/my-ui/doc-entry'
|
||||
|
||||
const props = defineProps<{
|
||||
fieldName: string
|
||||
label?: string
|
||||
placeholder?: string
|
||||
hint?: string
|
||||
modelValue?: File | null
|
||||
accept?: string[]
|
||||
maxSizeMb?: number
|
||||
errors?: FormErrors
|
||||
class?: string
|
||||
isRequired?: boolean
|
||||
isDisabled?: boolean
|
||||
icons?: string
|
||||
}>()
|
||||
|
||||
const hintMsg = computed(() => {
|
||||
if (props.hint) return props.hint
|
||||
if (props.accept) {
|
||||
return `${props.accept.map((ext) => '.' + ext.replace(/^\./, '')).join(', ')}, maksimal ${props.maxSizeMb} MB`
|
||||
}
|
||||
return 'Gunakan file yang sesuai'
|
||||
})
|
||||
|
||||
async function onFileChange(event: Event, handleChange: (value: any) => void) {
|
||||
const target = event.target as HTMLInputElement
|
||||
const file = target.files?.[0]
|
||||
|
||||
handleChange(file)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DE.Cell>
|
||||
<DE.Label
|
||||
v-if="label !== ''"
|
||||
:label-for="fieldName"
|
||||
:is-required="isRequired && !isDisabled"
|
||||
>
|
||||
{{ label }} ({{ hintMsg }})
|
||||
</DE.Label>
|
||||
<DE.Field
|
||||
:id="fieldName"
|
||||
:errors="errors"
|
||||
>
|
||||
<FormField
|
||||
v-slot="{ componentField, handleChange }"
|
||||
:name="fieldName"
|
||||
>
|
||||
<FormItem>
|
||||
<FormControl class="flex flex-col">
|
||||
<Input
|
||||
@change="onFileChange($event, handleChange)"
|
||||
type="file"
|
||||
:disabled="isDisabled"
|
||||
v-bind="componentField"
|
||||
:placeholder="placeholder"
|
||||
:class="cn('focus:border-primary focus:ring-2 focus:ring-primary focus:ring-offset-0')"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
</FormField>
|
||||
</DE.Field>
|
||||
</DE.Cell>
|
||||
</template>
|
||||
@@ -6,12 +6,15 @@ import Label from '~/components/pub/my-ui/form/label.vue'
|
||||
import { Input } from '~/components/pub/ui/input'
|
||||
import { cn } from '~/lib/utils'
|
||||
|
||||
import * as DE from '~/components/pub/my-ui/doc-entry'
|
||||
|
||||
const props = defineProps<{
|
||||
fieldName: string
|
||||
placeholder: string
|
||||
label: string
|
||||
errors?: FormErrors
|
||||
class?: string
|
||||
colSpan?: number
|
||||
numericOnly?: boolean
|
||||
maxLength?: number
|
||||
isRequired?: boolean
|
||||
@@ -42,15 +45,15 @@ function handleInput(event: Event) {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FieldGroup>
|
||||
<Label
|
||||
<DE.Cell :col-span="colSpan || 1">
|
||||
<DE.Label
|
||||
v-if="label !== ''"
|
||||
:label-for="fieldName"
|
||||
:is-required="isRequired && !isDisabled"
|
||||
>
|
||||
{{ label }}
|
||||
</Label>
|
||||
<Field
|
||||
</DE.Label>
|
||||
<DE.Field
|
||||
:id="fieldName"
|
||||
:errors="errors"
|
||||
>
|
||||
@@ -77,6 +80,6 @@ function handleInput(event: Event) {
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
</FormField>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</DE.Field>
|
||||
</DE.Cell>
|
||||
</template>
|
||||
@@ -46,7 +46,7 @@ const wrapperClass = computed(() => [
|
||||
props.stacked ? '' : positionWrapMap[props.position],
|
||||
])
|
||||
|
||||
const labelClass = computed(() => [props.stacked ? 'block mb-1 text-sm font-normal' : positionChildMap[props.position]])
|
||||
const labelClass = computed(() => [props.stacked ? 'block mb-1 font-normal' : positionChildMap[props.position]])
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -116,7 +116,7 @@ watch(
|
||||
<SelectTrigger
|
||||
:class="
|
||||
cn(
|
||||
'rounded-md px-3 py-2 focus:outline-none focus:ring-1 focus:ring-black dark:focus:ring-white',
|
||||
'rounded-md focus:outline-none focus:ring-1 focus:ring-black dark:focus:ring-white',
|
||||
{
|
||||
'cursor-not-allowed bg-gray-100 opacity-50': isDisabled,
|
||||
'bg-white text-black dark:bg-gray-800 dark:text-white': !isDisabled,
|
||||
@@ -132,7 +132,7 @@ watch(
|
||||
<SelectValue
|
||||
:placeholder="placeholder || 'Pilih item'"
|
||||
:class="
|
||||
cn('text-sm', {
|
||||
cn('', {
|
||||
'text-gray-400': !props.modelValue,
|
||||
'text-black dark:text-white': props.modelValue,
|
||||
'text-gray-500': isDisabled,
|
||||
|
||||
Reference in New Issue
Block a user