-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add BaseList and BaseListItem components
- Loading branch information
1 parent
c57288d
commit 04d49c8
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |