/
Bybaleshqa
/
Forktest
Обзор
Документация
Войти
/
Bybaleshqa
/
Forktest
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/card/src/utils.ts
54 строки
1 KB
Denis Svyatovets
fix(card): типы добавлены в экспорт пакета
11 дек 2024, 17:32
11 дек 2024, 17:32
fef5887
Код
Авторство
О чём код?
import { ButtonAriaActionEventHandler } from '@v-uik/hooks' import { CardKindProps, CardSelectableProps, CardClickableProps } from './types' import type { ComponentPropsWithRefFix } from '@v-uik/common' import { CardKind } from './constants' export const isSelectable = ( value: CardKindProps ): value is CardSelectableProps => value.kind === CardKind.selectable export const isClickable = ( value: CardKindProps ): value is CardClickableProps => value.kind === CardKind.clickable export const getInputProps = ( props: CardKindProps ): ComponentPropsWithRefFix<'input'> | undefined => { if (!isSelectable(props)) { return undefined } return { checked: props.checked, onChange: props?.onChange, name: props.name, ...(props?.inputProps ?? {}), } } export const getClickableProps = ( props: CardKindProps ): | (Omit<ComponentPropsWithRefFix<'div'>, 'onClick'> & { onClick?: ButtonAriaActionEventHandler<HTMLDivElement> }) | undefined => { if (!isClickable(props)) { return undefined } return { ...props.buttonProps, onClick: props?.onClick, } } export const getOmittedParams = (props: CardKindProps) => { if (isSelectable(props)) { return ['checked', 'onChange', 'inputProps', 'kind', 'disabled'] } else if (isClickable(props)) { return ['kind', 'buttonProps', 'onClick', 'disabled'] } return ['kind'] }