Skip to content

Commit

Permalink
refactor(FormGroup): use computed size in all input components
Browse files Browse the repository at this point in the history
  • Loading branch information
romhml committed Aug 3, 2023
1 parent e5e0e59 commit 4751aa9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/runtime/components/forms/Radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<div :class="ui.wrapper">
<div class="flex items-center h-5">
<input
:id="`${name}-${value}`"
v-model="pick"
:name="name"
:required="required"
Expand Down
14 changes: 7 additions & 7 deletions src/runtime/components/forms/Range.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<div :class="wrapperClass">
<input
:id="name"
ref="input"
v-model.number="value"
:name="name"
Expand Down Expand Up @@ -83,7 +82,8 @@ export default defineComponent({
const ui = computed<Partial<typeof appConfig.ui.range>>(() => defu({}, props.ui, appConfig.ui.range))
const { emitFormBlur } = useFormGroup()
const { emitFormBlur, formGroup } = useFormGroup()
const size = computed(() => formGroup?.size?.value ?? props.size)
const value = computed({
get () {
Expand All @@ -102,7 +102,7 @@ export default defineComponent({
const wrapperClass = computed(() => {
return classNames(
ui.value.wrapper,
ui.value.size[props.size]
ui.value.size[size.value]
)
})
Expand All @@ -112,7 +112,7 @@ export default defineComponent({
ui.value.background,
ui.value.rounded,
ui.value.ring.replaceAll('{color}', props.color),
ui.value.size[props.size]
ui.value.size[size.value]
)
})
Expand All @@ -123,7 +123,7 @@ export default defineComponent({
ui.value.thumb.color.replaceAll('{color}', props.color),
ui.value.thumb.ring,
ui.value.thumb.background,
ui.value.thumb.size[props.size]
ui.value.thumb.size[size.value]
)
})
Expand All @@ -132,7 +132,7 @@ export default defineComponent({
ui.value.track.base,
ui.value.track.background,
ui.value.track.rounded,
ui.value.track.size[props.size]
ui.value.track.size[size.value]
)
})
Expand All @@ -141,7 +141,7 @@ export default defineComponent({
ui.value.progress.base,
ui.value.progress.rounded,
ui.value.progress.background.replaceAll('{color}', props.color),
ui.value.progress.size[props.size]
ui.value.progress.size[size.value]
)
})
Expand Down
21 changes: 11 additions & 10 deletions src/runtime/components/forms/Select.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<div :class="ui.wrapper">
<select
:id="name"
:name="name"
:value="modelValue"
:required="required"
Expand Down Expand Up @@ -174,7 +173,9 @@ export default defineComponent({
const ui = computed<Partial<typeof appConfig.ui.select>>(() => defu({}, props.ui, appConfig.ui.select))
const { emitFormBlur } = useFormGroup()
const { emitFormBlur, formGroup } = useFormGroup()
const size = computed(() => formGroup?.size?.value ?? props.size)
const onInput = (event: InputEvent) => {
emit('update:modelValue', (event.target as HTMLInputElement).value)
Expand Down Expand Up @@ -243,11 +244,11 @@ export default defineComponent({
return classNames(
ui.value.base,
ui.value.rounded,
ui.value.size[props.size],
props.padded ? ui.value.padding[props.size] : 'p-0',
ui.value.size[size.value],
props.padded ? ui.value.padding[size.value] : 'p-0',
variant?.replaceAll('{color}', props.color),
(isLeading.value || slots.leading) && ui.value.leading.padding[props.size],
(isTrailing.value || slots.trailing) && ui.value.trailing.padding[props.size]
(isLeading.value || slots.leading) && ui.value.leading.padding[size.value],
(isTrailing.value || slots.trailing) && ui.value.trailing.padding[size.value]
)
})
Expand Down Expand Up @@ -279,15 +280,15 @@ export default defineComponent({
return classNames(
ui.value.icon.leading.wrapper,
ui.value.icon.leading.pointer,
ui.value.icon.leading.padding[props.size]
ui.value.icon.leading.padding[size.value]
)
})
const leadingIconClass = computed(() => {
return classNames(
ui.value.icon.base,
appConfig.ui.colors.includes(props.color) && ui.value.icon.color.replaceAll('{color}', props.color),
ui.value.icon.size[props.size],
ui.value.icon.size[size.value],
props.loading && 'animate-spin'
)
})
Expand All @@ -296,15 +297,15 @@ export default defineComponent({
return classNames(
ui.value.icon.trailing.wrapper,
ui.value.icon.trailing.pointer,
ui.value.icon.trailing.padding[props.size]
ui.value.icon.trailing.padding[size.value]
)
})
const trailingIconClass = computed(() => {
return classNames(
ui.value.icon.base,
appConfig.ui.colors.includes(props.color) && ui.value.icon.color.replaceAll('{color}', props.color),
ui.value.icon.size[props.size],
ui.value.icon.size[size.value],
props.loading && !isLeading.value && 'animate-spin'
)
})
Expand Down
21 changes: 11 additions & 10 deletions src/runtime/components/forms/SelectMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ export default defineComponent({
const popper = computed<PopperOptions>(() => defu({}, props.popper, uiMenu.value.popper as PopperOptions))
const [trigger, container] = usePopper(popper.value)
const { emitFormBlur } = useFormGroup()
const { emitFormBlur, formGroup } = useFormGroup()
const size = computed(() => formGroup?.size?.value ?? props.size)
const query = ref('')
const searchInput = ref<ComponentPublicInstance<HTMLElement>>()
Expand All @@ -316,12 +317,12 @@ export default defineComponent({
ui.value.base,
ui.value.rounded,
'text-left cursor-default',
ui.value.size[props.size],
ui.value.gap[props.size],
props.padded ? ui.value.padding[props.size] : 'p-0',
ui.value.size[size.value],
ui.value.gap[size.value],
props.padded ? ui.value.padding[size.value] : 'p-0',
variant?.replaceAll('{color}', props.color),
(isLeading.value || slots.leading) && ui.value.leading.padding[props.size],
(isTrailing.value || slots.trailing) && ui.value.trailing.padding[props.size],
(isLeading.value || slots.leading) && ui.value.leading.padding[size.value],
(isTrailing.value || slots.trailing) && ui.value.trailing.padding[size.value],
'inline-flex items-center'
)
})
Expand Down Expand Up @@ -354,15 +355,15 @@ export default defineComponent({
return classNames(
ui.value.icon.leading.wrapper,
ui.value.icon.leading.pointer,
ui.value.icon.leading.padding[props.size]
ui.value.icon.leading.padding[size.value]
)
})
const leadingIconClass = computed(() => {
return classNames(
ui.value.icon.base,
appConfig.ui.colors.includes(props.color) && ui.value.icon.color.replaceAll('{color}', props.color),
ui.value.icon.size[props.size],
ui.value.icon.size[size.value],
props.loading && 'animate-spin'
)
})
Expand All @@ -371,15 +372,15 @@ export default defineComponent({
return classNames(
ui.value.icon.trailing.wrapper,
ui.value.icon.trailing.pointer,
ui.value.icon.trailing.padding[props.size]
ui.value.icon.trailing.padding[size.value]
)
})
const trailingIconClass = computed(() => {
return classNames(
ui.value.icon.base,
appConfig.ui.colors.includes(props.color) && ui.value.icon.color.replaceAll('{color}', props.color),
ui.value.icon.size[props.size],
ui.value.icon.size[size.value],
props.loading && !isLeading.value && 'animate-spin'
)
})
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/components/forms/Textarea.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<div :class="ui.wrapper">
<textarea
:id="name"
ref="textarea"
:value="modelValue"
:name="name"
Expand Down Expand Up @@ -112,7 +111,8 @@ export default defineComponent({
const ui = computed<Partial<typeof appConfig.ui.textarea>>(() => defu({}, props.ui, appConfig.ui.textarea))
const { emitFormBlur } = useFormGroup()
const { emitFormBlur, formGroup } = useFormGroup()
const size = computed(() => formGroup?.size?.value ?? props.size)
const autoFocus = () => {
if (props.autofocus) {
Expand Down Expand Up @@ -177,8 +177,8 @@ export default defineComponent({
ui.value.base,
ui.value.rounded,
ui.value.placeholder,
ui.value.size[props.size],
props.padded ? ui.value.padding[props.size] : 'p-0',
ui.value.size[size.value],
props.padded ? ui.value.padding[size.value] : 'p-0',
variant?.replaceAll('{color}', props.color),
!props.resize && 'resize-none'
)
Expand Down

0 comments on commit 4751aa9

Please sign in to comment.