Skip to content

Commit

Permalink
feat(list): add slots type (tusen-ai#6599)
Browse files Browse the repository at this point in the history
  • Loading branch information
nailiable committed Dec 7, 2024
1 parent 83d9bc5 commit 8b0c79d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/list/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { listProps, default as NList } from './src/List'
export type { ListProps } from './src/List'
export type { ListProps, ListSlots } from './src/List'
export { default as NListItem } from './src/ListItem'
export type { ListItemSlots } from './src/ListItem'
9 changes: 8 additions & 1 deletion src/list/src/List.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CSSProperties, PropType, Ref } from 'vue'
import type { CSSProperties, PropType, Ref, SlotsType } from 'vue'
import type { ThemeProps } from '../../_mixins'
import type { ListTheme } from '../styles'
import { computed, defineComponent, h, provide, toRef } from 'vue'
Expand All @@ -24,6 +24,12 @@ export const listProps = {

export type ListProps = ExtractPublicPropTypes<typeof listProps>

export interface ListSlots {
default?: any
footer?: any
header?: any
}

interface ListInjection {
showDividerRef: Ref<boolean>
mergedClsPrefixRef: Ref<string>
Expand All @@ -34,6 +40,7 @@ export const listInjectionKey = createInjectionKey<ListInjection>('n-list')
export default defineComponent({
name: 'List',
props: listProps,
slots: Object as SlotsType<ListSlots>,
setup(props) {
const { mergedClsPrefixRef, inlineThemeDisabled, mergedRtlRef }
= useConfig(props)
Expand Down
8 changes: 8 additions & 0 deletions src/list/src/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import type { SlotsType } from 'vue'
import { defineComponent, h, inject } from 'vue'
import { throwError } from '../../_utils'
import { listInjectionKey } from './List'

export interface ListItemSlots {
default?: any
prefix?: any
suffix?: any
}

export default defineComponent({
name: 'ListItem',
slots: Object as SlotsType<ListItemSlots>,
setup() {
const listInjection = inject(listInjectionKey, null)
if (!listInjection) {
Expand Down

0 comments on commit 8b0c79d

Please sign in to comment.