Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FormGroup): add size prop and theme options #391

Merged
merged 8 commits into from
Jul 24, 2023
Merged
19 changes: 19 additions & 0 deletions docs/content/3.forms/9.form-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,25 @@ You can also use the `error` prop as a boolean to mark the form element as inval
The `error` prop will automatically set the `color` prop of the form element to `red`.
::

### Size
Use the `size` prop to change the size of the label and the form element.

::component-card
---
props:
size: 'xl'
label: 'Email'
hint: 'Optional'
description: "We'll only use this for spam."
help: 'We will never share your email with anyone else.'
code: >-

<UInput size="xl" placeholder="you@example.com" icon="i-heroicons-envelope" />
henrycunh marked this conversation as resolved.
Show resolved Hide resolved
---

#default
:u-input{placeholder="you@example.com" icon="i-heroicons-envelope" size="xl"}
::
## Props

:component-props
Expand Down
20 changes: 14 additions & 6 deletions src/runtime/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,23 @@ const input = {
const formGroup = {
wrapper: '',
label: {
wrapper: 'flex content-center justify-between',
base: 'block text-sm font-medium text-gray-700 dark:text-gray-200',
wrapper: 'flex content-centerc items-center justify-between',
henrycunh marked this conversation as resolved.
Show resolved Hide resolved
base: 'block font-medium text-gray-700 dark:text-gray-200',
required: 'after:content-[\'*\'] after:ms-0.5 after:text-red-500 dark:after:text-red-400'
},
description: 'text-sm text-gray-500 dark:text-gray-400',
size: {
'2xs': 'text-xs',
xs: 'text-xs',
sm: 'text-sm',
md: 'text-sm',
lg: 'text-sm',
xl: 'text-base'
},
description: 'text-gray-500 dark:text-gray-400',
container: 'mt-1 relative',
hint: 'text-sm text-gray-500 dark:text-gray-400',
help: 'mt-2 text-sm text-gray-500 dark:text-gray-400',
error: 'mt-2 text-sm text-red-500 dark:text-red-400'
hint: 'text-gray-500 dark:text-gray-400',
help: 'mt-2 text-gray-500 dark:text-gray-400',
error: 'mt-2 text-red-500 dark:text-red-400'
}

const textarea = {
Expand Down
13 changes: 10 additions & 3 deletions src/runtime/components/forms/FormGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export default defineComponent({
type: String,
default: null
},
size: {
type: String,
default: () => appConfig.ui.button.default.size,
henrycunh marked this conversation as resolved.
Show resolved Hide resolved
validator (value: string) {
return Object.keys(appConfig.ui.button.size).includes(value)
henrycunh marked this conversation as resolved.
Show resolved Hide resolved
}
},
label: {
type: String,
default: null
Expand Down Expand Up @@ -70,12 +77,12 @@ export default defineComponent({
}))

return () => h('div', { class: [ui.value.wrapper] }, [
props.label && h('div', { class: [ui.value.label.wrapper] }, [
props.label && h('div', { class: [ui.value.label.wrapper, ui.value.size[props.size]] }, [
h('label', { for: props.name, class: [ui.value.label.base, props.required && ui.value.label.required] }, props.label),
props.hint && h('span', { class: [ui.value.hint] }, props.hint)
]),
props.description && h('p', { class: [ui.value.description] }, props.description),
h('div', { class: [!!props.label && ui.value.container] }, [
props.description && h('p', { class: [ui.value.description, ui.value.size[props.size]] }, props.description),
h('div', { class: [!!props.label && ui.value.container, ui.value.size[props.size]] }, [
...clones.value,
props.error && typeof props.error === 'string' ? h('p', { class: [ui.value.error] }, props.error) : props.help ? h('p', { class: [ui.value.help] }, props.help) : null
])
Expand Down