Skip to content

Commit

Permalink
feat(dynamic-input): 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 f86adc3 commit 373732c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/dynamic-input/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
export { dynamicInputProps, default as NDynamicInput } from './src/DynamicInput'
export type { DynamicInputProps } from './src/DynamicInput'
export type { DynamicInputProps, DynamicInputSlots } from './src/DynamicInput'
export type {
DynamicInputActionSlotOptions,
DynamicInputDefaultSlotOptions
} from './src/interface'
13 changes: 12 additions & 1 deletion src/dynamic-input/src/DynamicInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type { ThemeProps } from '../../_mixins'
import type { ExtractPublicPropTypes, MaybeArray } from '../../_utils'
import type { ButtonProps } from '../../button'
import type { DynamicInputTheme } from '../styles'
import type { OnUpdateValue } from './interface'
import type {
DynamicInputActionSlotOptions,
DynamicInputDefaultSlotOptions,
OnUpdateValue
} from './interface'
import { createId } from 'seemly'
import { useMergedState } from 'vooks'
import {
Expand Down Expand Up @@ -88,6 +92,13 @@ export const dynamicInputProps = {

export type DynamicInputProps = ExtractPublicPropTypes<typeof dynamicInputProps>

export interface DynamicInputSlots {
action?: (options: DynamicInputActionSlotOptions) => any
default?: (options: DynamicInputDefaultSlotOptions) => any
'create-button-default'?: any
'create-button-icon'?: any
}

export default defineComponent({
name: 'DynamicInput',
props: dynamicInputProps,
Expand Down
13 changes: 13 additions & 0 deletions src/dynamic-input/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@ export const dynamicInputInjectionKey
= createInjectionKey<DynamicInputInjection>('n-dynamic-input')

export type OnUpdateValue = <T>(value: T[]) => void

export interface DynamicInputDefaultSlotOptions {
value: any
index: number
}

export interface DynamicInputActionSlotOptions {
value: any
index: number
create: (index: number) => void
remove: (index: number) => void
move: (type: 'up' | 'down', index: number) => void
}

0 comments on commit 373732c

Please sign in to comment.