Skip to content

Commit

Permalink
feat: add BaseList and BaseListItem components
Browse files Browse the repository at this point in the history
  • Loading branch information
stafyniaksacha committed Aug 12, 2023
1 parent c57288d commit 04d49c8
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
42 changes: 42 additions & 0 deletions components/base/BaseList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script lang="ts">
// const slots = useSlots()
// const hasMedia = computed(() => {
// return slots.default?.().some((vnode) => {
// console.log(vnode)
// return typeof vnode.type !== 'string'
// })
// })
export default defineComponent({
props: {
/**
* If the list should be ordered.
*/
ordered: {
type: Boolean,
default: false,
},
},
setup(props, { slots }) {
return () => {
const ordered = props.ordered ? 'nui-list-ol' : 'nui-list-ul'
const children = slots.default?.()
const hasMedia = children?.some((vnode) => {
return typeof vnode.type !== 'string'
})
return h(
'div',
{
class: [
'nui-list',
hasMedia && 'nui-list-media',
!hasMedia && `nui-list-base ${ordered}`,
],
},
children
)
}
},
})
</script>
49 changes: 49 additions & 0 deletions components/base/BaseListItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script setup lang="ts">
const props = defineProps<{
/**
* The title of the list item.
*/
title?: string
/**
* The subtitle of the list item.
*/
subtitle?: string
}>()
const slots = useSlots()
const hasTitle = computed(() => {
return Boolean(props.title || 'title' in slots)
})
const hasSubtitle = computed(() => {
return Boolean(props.subtitle || 'subtitle' in slots)
})
</script>

<template>
<div class="nui-list-item">
<slot />

<div v-if="hasTitle || hasSubtitle">
<BaseHeading
v-if="hasTitle"
as="h6"
weight="medium"
size="md"
lead="tight"
>
<slot name="title">{{ props.title }}</slot>
</BaseHeading>
<BaseParagraph
v-if="hasSubtitle"
size="xs"
class="text-muted-500 dark:text-muted-400"
>
<slot name="subtitle">{{ props.subtitle }}</slot>
</BaseParagraph>
</div>

<div class="ms-auto">
<slot name="end" />
</div>
</div>
</template>

0 comments on commit 04d49c8

Please sign in to comment.