How to change color from params with Typescript? #808
Unanswered
spencerchang
asked this question in
Help
Replies: 1 comment
-
Hi @spencerchang you need to give For example: import { Input } from '@nextui-org/react';
import type { InputProps, SimpleColors } from '@nextui-org/react';
type Helper = {
// one of the SimpleColors
color?: SimpleColors;
// one of the InputProps['color'] which is SimpleColors
// color?: InputProps['color'];
// default, error and undefined only
// color?: 'default' | 'error';
};
const Index = () => {
const helper: Helper = { color: 'default' };
return <Input color={helper.color ?? 'primary'} />;
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm sure my params is one of color's string.
EX1:
color="primary" -> ok
EX2:
let colorPrimary:string = "primary"
color={colorPrimary} -> fail
(property) status?: "error" | "secondary" | "default" | "primary" | "success" | "warning" | undefined
Type 'string' is not assignable to type '"error" | "secondary" | "default" | "primary" | "success" | "warning" | undefined'.ts(2322)
Beta Was this translation helpful? Give feedback.
All reactions