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: FwbInput: Split input and block classes #325

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/components/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import FwbInputExample from './input/examples/FwbInputExample.vue'
import FwbInputExampleSize from './input/examples/FwbInputExampleSize.vue'
import FwbInputExampleDisabled from './input/examples/FwbInputExampleDisabled.vue'
import FwbInputExampleHelper from './input/examples/FwbInputExampleHelper.vue'
import FwbInputExampleBlockClasses from './input/examples/FwbInputExampleBlockClasses.vue'
import FwbInputExamplePrefix from './input/examples/FwbInputExamplePrefix.vue'
import FwbInputExampleSuffix from './input/examples/FwbInputExampleSuffix.vue'
import FwbInputExampleRequired from './input/examples/FwbInputExampleRequired.vue'
Expand Down Expand Up @@ -103,6 +104,33 @@ const name = ref('')
</script>
```

## Extra CSS classes

Sometimes it is required to add some customization to the input or the input wrapper.
By default, `class` attribute is bound to the input element. To customize the input wrapper you can use the `block-classes` property.
It accepts the values as the `class` attribute

<fwb-input-example-block-classes />
```vue
<template>
<fwb-input
v-model="name"
label="First name"
placeholder="enter your first name"
required
class="bg-green-200"
block-classes="border-2 border-green-500 p-2 rounded-lg"
/>
</template>

<script setup>
import { ref } from 'vue'
import { FwbInput } from 'flowbite-vue'

const name = ref('')
</script>
```

## Slot - Helper

<fwb-input-example-helper />
Expand Down
18 changes: 18 additions & 0 deletions docs/components/input/examples/FwbInputExampleBlockClasses.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<div class="vp-raw">
<fwb-input
v-model="name"
label="First name"
placeholder="enter your first name"
class="bg-green-200"
block-classes="border-2 border-green-500 p-2 rounded-lg"
/>
</div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { FwbInput } from '../../../../src/index'

const name = ref('')
</script>
8 changes: 7 additions & 1 deletion src/components/FwbInput/FwbInput.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<div :class="blockClasses">
<label
v-if="label"
:class="labelClasses"
Expand Down Expand Up @@ -64,8 +64,13 @@ interface InputProps {
type?: InputType
autocomplete?: CommonAutoFill
validationStatus?: ValidationStatus
blockClasses?: string | string[] | Record<string, unknown>
}

defineOptions({
inheritAttrs: false,
})

const props = withDefaults(defineProps<InputProps>(), {
disabled: false,
label: '',
Expand All @@ -75,6 +80,7 @@ const props = withDefaults(defineProps<InputProps>(), {
type: 'text',
autocomplete: 'off',
validationStatus: undefined,
blockClasses: undefined,
})

const model = useVModel(props, 'modelValue')
Expand Down
Loading