-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional logic #4
Comments
I think https://stitches.dev/docs/variants#compound-variants Is there a specific example where the above won't really work? Just curious. |
@kevin-nguyen-mirvac For example:
I would gladly submit a PR for this but my typescript's so so bad... - will try it if there's a chance to have it merged 😃 |
Ahh I understand now, this is pretty cool! This feature though will increase library scope to "Stitch-like API" + more. If it were to be included, I like it being 'opt in' like @edgarasben sample code.
I'll give this a go though. It'll be cool to see if it'll work even if the author decides to not include it in this library |
Yes, {
variants: {
color: 'primary',
destructive: false,
variant: 'solid',
variant: 'subtle',
variant: 'outline'
},
className: 'x'
} However, |
Just an update, I got something working that kind of looks like this. const StyledButton = styled(
"button",
{
base: [
"rounded-lg w-fit font-sans flex justify-center items-center font-semibold",
"leading-none relative",
],
variants: {
size: {
xs: "py-2 px-4",
sm: "py-3 px-6 text-[14px] min-w-[100px]",
md: "py-4 px-5 text-[14px] min-w-[100px]",
lg: "py-5 px-5 text-[16px] min-w-[100px]",
icon: "h-[50px] w-[50px] min-w-[50px] hover:text-line p-0 rounded-full",
},
variant: {
primary: "",
secondary: "",
error: "bg-error text-white",
},
disabled: {
true: "cursor-not-allowed",
},
status: {
idle: "",
loading: "bg-dotted-line text-[transparent]",
success: "bg-success text-[transparent]",
error: "",
},
},
compoundVariants: [
{
variants: {
variant: {
OR: ["primary", "secondary"]
},
status: "idle",
},
className: "text-white bg-black",
},
{
variants: {
variant: "secondary",
status: {
NOT: "idle"
},
},
className: "bg-white border border-dotted-line",
},
{
variants: {
variant: ["primary", "secondary"],
disabled: true,
status: ["idle", "loading"],
},
className: "bg-dotted-line",
},
],
defaultVariants: {
size: "lg",
variant: "primary",
status: "idle",
disabled: false,
},
}
); some major changes are
I'm happy to make this PR if the author thinks it's within the scope of this project. Otherwise I'm working on releasing the below code in maybe my own repo sometime soon. |
Would it be possible to add conditional logic such as AND, OR and NOT?
For example, I would like to only apply padding if the variant is NOT a
link
:NOT:
Other conditional examples
AND:
OR:
The text was updated successfully, but these errors were encountered: