Skip to content
Merged
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
20 changes: 5 additions & 15 deletions docs/components/button-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,11 @@ You can also mix buttons with dropdowns inside the button group.
</fwb-dropdown>
<fwb-dropdown text="Dropdown with list">
<fwb-list-group>
<fwb-list-group-item hover>
<a href="#">These</a>
</fwb-list-group-item>
<fwb-list-group-item hover>
<a href="#">are</a>
</fwb-list-group-item>
<fwb-list-group-item hover>
<a href="#">some</a>
</fwb-list-group-item>
<fwb-list-group-item hover>
<a href="#">list</a>
</fwb-list-group-item>
<fwb-list-group-item hover>
<a href="#">items</a>
</fwb-list-group-item>
<fwb-list-group-item href="#"> These </fwb-list-group-item>
<fwb-list-group-item href="#"> are </fwb-list-group-item>
<fwb-list-group-item href="#"> some </fwb-list-group-item>
<fwb-list-group-item href="#"> list </fwb-list-group-item>
<fwb-list-group-item href="#"> items </fwb-list-group-item>
</fwb-list-group>
</fwb-dropdown>
</fwb-button-group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
</fwb-dropdown>
<fwb-dropdown text="Dropdown with list">
<fwb-list-group>
<fwb-list-group-item hover>
<a href="#">These</a>
<fwb-list-group-item href="#">
These
</fwb-list-group-item>
<fwb-list-group-item hover>
<a href="#">are</a>
<fwb-list-group-item href="#">
are
</fwb-list-group-item>
<fwb-list-group-item hover>
<a href="#">some</a>
<fwb-list-group-item href="#">
some
</fwb-list-group-item>
<fwb-list-group-item hover>
<a href="#">list</a>
<fwb-list-group-item href="#">
list
</fwb-list-group-item>
<fwb-list-group-item hover>
<a href="#">items</a>
<fwb-list-group-item href="#">
items
</fwb-list-group-item>
</fwb-list-group>
</fwb-dropdown>
Expand Down
8 changes: 4 additions & 4 deletions docs/components/dropdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@ import { FwbDropdown } from 'flowbite-vue'
<template>
<fwb-dropdown text="Menu" content-class="rounded-lg">
<fwb-list-group class="text-sm text-gray-700 dark:text-gray-200">
<fwb-list-group-item class="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<fwb-list-group-item to="#">
Dashboard
</fwb-list-group-item>
<fwb-list-group-item class="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<fwb-list-group-item href="#">
Settings
</fwb-list-group-item>
<fwb-list-group-item class="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<fwb-list-group-item href="#">
Earnings
</fwb-list-group-item>
<fwb-list-group-item class="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<fwb-list-group-item @click="signOut">
Sign out
</fwb-list-group-item>
</fwb-list-group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
content-wrapper-class="rounded-lg"
>
<fwb-list-group class="text-sm text-gray-700 dark:text-gray-200">
<fwb-list-group-item class="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<fwb-list-group-item to="#">
Dashboard
</fwb-list-group-item>
<fwb-list-group-item class="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<fwb-list-group-item href="#">
Settings
</fwb-list-group-item>
<fwb-list-group-item class="cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<fwb-list-group-item href="#">
Earnings
</fwb-list-group-item>
<fwb-list-group-item class="cursor-pointer border-b-0 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<fwb-list-group-item @click="signOut">
Sign out
</fwb-list-group-item>
</fwb-list-group>
Expand All @@ -24,4 +24,5 @@

<script lang="ts" setup>
import { FwbDropdown, FwbListGroup, FwbListGroupItem } from '../../../../src/index'
const signOut = () => {}
</script>
26 changes: 18 additions & 8 deletions docs/components/list-group.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup>
import FwbListGroupExample from './listGroup/examples/FwbListGroupExample.vue'
import FwbListGroupExampleDisabled from './listGroup/examples/FwbListGroupExampleDisabled.vue'
import FwbListGroupExampleHover from './listGroup/examples/FwbListGroupExampleHover.vue'
import FwbListGroupExampleLink from './listGroup/examples/FwbListGroupExampleLink.vue'
import FwbListGroupExampleIcon from './listGroup/examples/FwbListGroupExampleIcon.vue'
</script>

Expand Down Expand Up @@ -36,17 +36,27 @@ import { FwbListGroup, FwbListGroupItem } from 'flowbite-vue'
</script>
```

## Hover
## Links

<fwb-list-group-example-hover />
:::tip
`href` prop is used for external links. `to` prop is used for internal links. `target` prop is used to set the target attribute for external links, the hover effect is automatically enabled.
:::
<fwb-list-group-example-link />
```vue
<template>
<fwb-list-group>
<fwb-list-group-item active hover>Item 1</fwb-list-group-item>
<fwb-list-group-item hover>Item 2</fwb-list-group-item>
<fwb-list-group-item hover>Item 3</fwb-list-group-item>
<fwb-list-group-item hover>Item 4</fwb-list-group-item>
<fwb-list-group-item hover>Item 5</fwb-list-group-item>
<fwb-list-group-item active href="#">
Link with href (active)
</fwb-list-group-item>
<fwb-list-group-item href="https://flowbite.com" target="__blank">
External link (target blank)
</fwb-list-group-item>
<fwb-list-group-item to="#">
Router link
</fwb-list-group-item>
<fwb-list-group-item>
Regular item (no hover)
</fwb-list-group-item>
</fwb-list-group>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
<fwb-list-group>
<fwb-list-group-item
active
hover
href="#"
>
Item 1
Link with href (active)
</fwb-list-group-item>
<fwb-list-group-item hover>
Item 2
</fwb-list-group-item>
<fwb-list-group-item hover>
Item 3
</fwb-list-group-item>
<fwb-list-group-item hover>
Item 4
<fwb-list-group-item
href="https://flowbite.com"
target="__blank"
>
External link
</fwb-list-group-item>
<fwb-list-group-item hover>
Item 5
<fwb-list-group-item to="#">
Router link
</fwb-list-group-item>
<fwb-list-group-item> Regular item (no hover) </fwb-list-group-item>
</fwb-list-group>
</div>
</template>
Expand Down
62 changes: 54 additions & 8 deletions src/components/FwbListGroup/FwbListGroupItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<template>
<li :class="itemClasses">
<component
:is="componentTag"
:class="itemClasses"
:target="showTarget ? target : undefined"
v-bind="linkAttr ? { [linkAttr]: linkTarget } : {}"
>
<div
v-if="$slots.prefix"
class="mr-2"
Expand All @@ -13,19 +18,16 @@
>
<slot name="suffix" />
</div>
</li>
</component>
</template>

<script lang="ts" setup>
import { toRefs } from 'vue'
import { computed, resolveComponent, toRef, useAttrs } from 'vue'

import { useListGroupItemClasses } from './composables/useListGroupItemClasses'

const attrs = useAttrs()
const props = defineProps({
hover: {
type: Boolean,
default: false,
},
disabled: {
type: Boolean,
default: false,
Expand All @@ -34,7 +36,51 @@ const props = defineProps({
type: Boolean,
default: false,
},
to: {
type: [String, Object],
default: null,
},
href: {
type: String,
default: null,
},
target: {
type: String,
default: '_self',
},
tag: {
type: String,
default: 'li',
},
})

const isLink = computed(() => !!props.href || !!props.to)
const isRouterLink = computed(() => props.tag === 'router-link' || props.tag === 'nuxt-link')
const linkComponent = computed(() => {
if (isRouterLink.value) {
return resolveComponent(props.tag)
}
return props.tag !== 'li' ? props.tag : 'a'
})
const componentTag = computed(() => {
if (!isLink.value) return props.tag
if (props.to) {
return linkComponent.value
}
return 'a'
})
const linkAttr = computed(() => {
if (!isLink.value) return null
return isRouterLink.value
? 'to'
: 'href'
})
const linkTarget = computed(() => props.to || props.href)
const showTarget = computed(() => !!props.href && !props.to)

const disabled = toRef(props, 'disabled')
const active = toRef(props, 'active')
const hover = computed(() => isLink.value || !!attrs.onClick)

const { itemClasses } = useListGroupItemClasses(toRefs(props))
const { itemClasses } = useListGroupItemClasses({ disabled, active, hover })
</script>
Loading