类方差权威变体允许“空”值,但不应该

问题描述 投票:0回答:1

我这样使用cva:

export const checkboxVariants = cva('border ...', {
    variants: {
      size: {
        sm: 'h-4 w-4',
        md: 'h-5 w-5',
        lg: 'h-6 w-6',
      },
  },    
  defaultVariants: {
    size: 'md',
  },
});

type CheckboxProps = VariantProps<typeof checkboxVariants>

但是在检查组件 props 时,我可以看到也允许 null 值,并且如果传递 null 则不会应用任何大小类。

如何从可用值中删除 null?

一个问题是在使用中,另一个问题是在故事书中,因为它表明允许 null 并且看起来不太好:

typescript storybook
1个回答
0
投票

我在cva github上留下了询问并收到了下面的回复。 https://github.com/joe-bell/cva/issues/253

朋友们,我想很快就会有补丁。

或者,这里也是替代方案。 从类型的属性中删除 null 或未定义

© www.soinside.com 2019 - 2024. All rights reserved.