Files
element-plus/packages/components/select-v2/src/useProps.ts
kooriookami 5844947198 refactor(components): [select & select-v2] Refactor components (#15352)
* refactor(components): [select&select-v2] refactor components

* refactor(components): [select-v2]

* refactor(components): update

* refactor(components): update

* refactor(components): [select-v2]

update

* refactor(components): update

* refactor(components): update

* refactor(components): update type

* refactor(components): update

* refactor(components): update

* refactor(components): update style

* refactor(components): update docs

* refactor(components): update

* refactor(components): fix #15323

* refactor(theme-chalk): update

* refactor(components): update

* refactor(components): update

* refactor(components): update

* refactor(components): fix bugs

* fix(components): fix issue

* fix(components): update

* fix(components): fix some bug

* feat(components): update

* feat(components): add tag slot

* feat(components): update

* fix(components): update

* style(theme-chalk): update style

* fix(theme-chalk): update

* feat(theme-chalk): update

* fix(components): update

* feat: update

* feat: update

* feat: update

* feat(components): update
2024-01-10 11:14:58 +08:00

37 lines
940 B
TypeScript

import { computed } from 'vue'
import { get } from 'lodash-unified'
import type { ISelectV2Props } from './token'
import type { Option } from './select.types'
export interface Props {
label?: string
value?: string
disabled?: string
options?: string
}
export const defaultProps: Required<Props> = {
label: 'label',
value: 'value',
disabled: 'disabled',
options: 'options',
}
export function useProps(props: Pick<ISelectV2Props, 'props'>) {
const aliasProps = computed(() => ({ ...defaultProps, ...props.props }))
const getLabel = (option: Option) => get(option, aliasProps.value.label)
const getValue = (option: Option) => get(option, aliasProps.value.value)
const getDisabled = (option: Option) => get(option, aliasProps.value.disabled)
const getOptions = (option: Option) => get(option, aliasProps.value.options)
return {
aliasProps,
getLabel,
getValue,
getDisabled,
getOptions,
}
}