-
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
Showing
12 changed files
with
132 additions
and
102 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,57 @@ | ||
<script lang="ts"> | ||
// @ts-expect-error | ||
import appConfig from '#build/app.config'; | ||
import { formField } from '#ui/ui.config'; | ||
import { mergeConfig } from '#ui/utils'; | ||
const config = mergeConfig<typeof formField>( | ||
appConfig.ui?.formField?.strategy, | ||
appConfig.ui?.formField, | ||
formField, | ||
); | ||
type UiConfig = Partial<typeof config> & { strategy?: Strategy }; | ||
</script> | ||
|
||
<script setup lang="ts"> | ||
import UiInputLabel from '#ui/components/forms/FormLabel.vue'; | ||
import { useUI } from '#ui/composables/useUI'; | ||
import type { FormFieldProps, Strategy } from '#ui/types'; | ||
import { Primitive } from 'radix-vue'; | ||
import { twMerge } from 'tailwind-merge'; | ||
import { computed, toRef, withDefaults } from 'vue'; | ||
const props = withDefaults(defineProps<FormFieldProps<UiConfig>>(), { | ||
as: 'div', | ||
class: undefined, | ||
ui: () => ({}) as UiConfig, | ||
}); | ||
const { ui } = useUI('formField', toRef(props, 'ui'), config); | ||
const dataAttrs = computed(() => ({ | ||
'data-error': props.error ? '' : undefined, | ||
'data-disabled-mode': props.readOnly ? 'read-only' : props.disabled ? 'disabled' : undefined, | ||
})); | ||
</script> | ||
|
||
<template> | ||
<Primitive | ||
v-bind="dataAttrs" | ||
:as="props.as" | ||
:as-child="props.asChild" | ||
:class="twMerge(ui.wrapper, props.class, 'group')" | ||
> | ||
<slot name="label"> | ||
<UiInputLabel v-if="props.label" :for="props.name" :mandatory="props.mandatory" :error="props.error">{{ | ||
props.label | ||
}}</UiInputLabel> | ||
</slot> | ||
|
||
<slot /> | ||
|
||
<slot name="message"> | ||
<p v-if="props.message" :id="`${props.name}-hint`" :class="ui.message">{{ props.message }}</p> | ||
</slot> | ||
</Primitive> | ||
</template> |
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
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,14 @@ | ||
import type { PrimitiveProps } from 'radix-vue'; | ||
|
||
export interface FormFieldProps<UiConfig = any> extends PrimitiveProps { | ||
name: string; | ||
label?: string; | ||
error?: boolean; | ||
message?: string; | ||
disabled?: boolean; | ||
readOnly?: boolean; | ||
mandatory?: boolean; | ||
|
||
ui?: UiConfig; | ||
class?: any; | ||
} |
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 |
---|---|---|
@@ -1,24 +1,19 @@ | ||
import type { FormFieldProps } from '#ui/types'; | ||
import type { InputHTMLAttributes } from 'vue'; | ||
import type { PrimitiveProps } from 'radix-vue'; | ||
|
||
export interface InputProps<UiConfig = any> extends PrimitiveProps { | ||
name: string; | ||
label?: string; | ||
error?: boolean; | ||
message?: string; | ||
readOnly?: boolean; | ||
disabled?: boolean; | ||
mandatory?: boolean; | ||
export interface InputProps<UiConfig = any> extends Omit<FormFieldProps, 'ui'> { | ||
prefixIcon?: string; | ||
prefixText?: string; | ||
suffixIcon?: string; | ||
suffixText?: string; | ||
placeholder?: string; | ||
type?: InputHTMLAttributes['type']; | ||
|
||
/** Controlled input value */ | ||
modelValue?: string | number; | ||
|
||
/** Uncontrolled default value */ | ||
defaultValue?: string | number; | ||
type?: InputHTMLAttributes['type']; | ||
|
||
ui?: UiConfig; | ||
class?: any; | ||
} |
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
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,4 @@ | ||
export default /*ui*/ { | ||
wrapper: 'flex flex-col gap-y-1 data-[disabled-mode=disabled]:opacity-70', | ||
message: 'text-xs text-gray-500 group-data-[error]:text-red-600', | ||
}; |
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 |
---|---|---|
@@ -1,20 +1,14 @@ | ||
export default /*ui*/ { | ||
wrapper: 'flex flex-col gap-y-1 data-[disabled-mode=disabled]:opacity-70', | ||
container: { | ||
base: 'flex w-full items-center bg-white group-data-[error]:bg-red-50', | ||
rounded: 'rounded-lg', | ||
ring: 'focus-within:ring-2 focus-within:ring-primary-600 group-data-[error]:focus-within:ring-red-400', | ||
border: 'border border-gray-900/10 group-data-[error]:border-red-800', | ||
}, | ||
font: { | ||
input: | ||
'text-sm text-gray-900 placeholder:text-gray-400 group-data-[error]:text-red-800 group-data-[error]:placeholder:text-red-500', | ||
addons: 'text-sm select-none text-gray-500 peer-focus:text-primary-600 group-data-[error]:text-red-600', | ||
message: 'text-xs text-gray-500 group-data-[error]:text-red-600', | ||
}, | ||
base: 'flex w-full items-center bg-white group-data-[error]:bg-red-50', | ||
rounded: 'rounded-lg', | ||
ring: 'focus-within:ring-2 focus-within:ring-primary-600 group-data-[error]:focus-within:ring-red-400', | ||
border: 'border border-gray-900/10 group-data-[error]:border-red-800', | ||
icon: 'size-4 text-gray-600 peer-focus:text-primary-600 group-data-[error]:text-red-600 group-data-[error]:peer-focus:text-red-600', | ||
addons: 'text-sm select-none text-gray-500 peer-focus:text-primary-600 group-data-[error]:text-red-600', | ||
input: { | ||
base: 'block w-full flex-1 border-0 bg-transparent focus:ring-0 group-data-[disabled-mode=disabled]:cursor-not-allowed', | ||
padding: 'px-2 py-1.5', | ||
font: | ||
'text-sm text-gray-900 placeholder:text-gray-400 group-data-[error]:text-red-800 group-data-[error]:placeholder:text-red-500', | ||
}, | ||
icon: 'size-4 text-gray-600 peer-focus:text-primary-600 group-data-[error]:text-red-600 group-data-[error]:peer-focus:text-red-600', | ||
}; |
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,13 @@ | ||
import UiFormField from '#ui/components/forms/FormField.vue'; | ||
import type { FormFieldProps } from '#ui/types'; | ||
|
||
export const getUiFormFieldProps = (props: any): FormFieldProps => { | ||
const keys = Object.keys(UiFormField.props); | ||
|
||
return keys.reduce((acc, key) => { | ||
if (props[key] !== undefined) { | ||
acc[key] = props[key]; | ||
} | ||
return acc; | ||
}, {}) as FormFieldProps; | ||
}; |