diff --git a/docs/components/input/examples/FwbInputExampleSuffix.vue b/docs/components/input/examples/FwbInputExampleSuffix.vue index 0424dfd8..4b6af2cf 100644 --- a/docs/components/input/examples/FwbInputExampleSuffix.vue +++ b/docs/components/input/examples/FwbInputExampleSuffix.vue @@ -1,32 +1,100 @@ diff --git a/src/components/FwbInput/FwbInput.vue b/src/components/FwbInput/FwbInput.vue index 962ad294..513f56df 100644 --- a/src/components/FwbInput/FwbInput.vue +++ b/src/components/FwbInput/FwbInput.vue @@ -4,10 +4,13 @@ v-if="label" :class="labelClasses" >{{ label }} -
+
@@ -18,11 +21,11 @@ :type="type" :required="required" :autocomplete="autocomplete" - :class="[inputClasses, $slots.prefix ? 'pl-10' : '']" + :class="[inputClasses]" >
@@ -79,7 +82,7 @@ const props = withDefaults(defineProps(), { const model = useVModel(props, 'modelValue') -const { inputClasses, labelClasses } = useInputClasses(toRefs(props)) +const { inputClasses, inputBlockClasses, labelClasses } = useInputClasses(toRefs(props)) const validationWrapperClasses = computed(() => twMerge( 'mt-2 text-sm', diff --git a/src/components/FwbInput/composables/useInputClasses.ts b/src/components/FwbInput/composables/useInputClasses.ts index 772364b4..de682ed8 100644 --- a/src/components/FwbInput/composables/useInputClasses.ts +++ b/src/components/FwbInput/composables/useInputClasses.ts @@ -10,8 +10,12 @@ import { const baseLabelClasses = 'block mb-2 text-sm font-medium' // INPUT -const defaultInputClasses = - 'bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500' +const defaultInputClasses = 'block flex-grow w-full p-0 bg-transparent text-inherit ring-offset-0 ring-0 border-0 focus:ring-offset-0 focus:ring-0 focus:border-0' + +// BLOCK +const defaultBlockClasses = + 'has-[input:focus]:ring-offset-0 has-[input:focus]:ring-1 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg has-[input:focus]:ring-blue-500 has-[input:focus]:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:has-[input:focus]:ring-blue-500 dark:has-[input:focus]:border-blue-500' + const disabledInputClasses = 'cursor-not-allowed bg-gray-100' const inputSizeClasses: Record = { lg: 'p-4', @@ -19,8 +23,8 @@ const inputSizeClasses: Record = { sm: 'p-2 text-sm', } -const successInputClasses = 'bg-green-50 border-green-500 dark:border-green-500 text-green-900 dark:text-green-400 placeholder-green-700 dark:placeholder-green-500 focus:ring-green-500 focus:border-green-500' -const errorInputClasses = 'bg-red-50 border-red-500 text-red-900 placeholder-red-700 focus:ring-red-500 focus:border-red-500 dark:text-red-500 dark:placeholder-red-500 dark:border-red-500' +const successInputClasses = 'bg-green-50 border-green-500 dark:border-green-500 text-green-900 dark:text-green-400 placeholder-green-700 dark:placeholder-green-500 has-[input:focus]:ring-green-500 has-[input:focus]:border-green-500' +const errorInputClasses = 'bg-red-50 border-red-500 text-red-900 placeholder-red-700 has-[input:focus]:ring-red-500 has-[input:focus]:border-red-500 dark:text-red-500 dark:placeholder-red-500 dark:border-red-500' export type UseInputClassesProps = { size: Ref @@ -29,10 +33,11 @@ export type UseInputClassesProps = { } export function useInputClasses (props: UseInputClassesProps): { + inputBlockClasses: Ref inputClasses: Ref labelClasses: Ref } { - const inputClasses = computed(() => { + const inputBlockClasses = computed(() => { const vs = props.validationStatus.value const classByStatus = vs === validationStatusMap.Success @@ -42,13 +47,16 @@ export function useInputClasses (props: UseInputClassesProps): { : '' return twMerge( - defaultInputClasses, + defaultBlockClasses, classByStatus, - inputSizeClasses[props.size.value], props.disabled.value ? disabledInputClasses : '', ) }) + const inputClasses = computed(() => { + return twMerge(defaultInputClasses, inputSizeClasses[props.size.value]) + }) + const labelClasses = computed(() => { const vs = props.validationStatus.value const classByStatus = vs === validationStatusMap.Success @@ -61,6 +69,7 @@ export function useInputClasses (props: UseInputClassesProps): { }) return { + inputBlockClasses, inputClasses, labelClasses, }