tw-in-js / twind-react Goto Github PK
View Code? Open in Web Editor NEWTwind react styled components inspired by stitches
License: MIT License
Twind react styled components inspired by stitches
License: MIT License
Add support for mixin with twind/style, the same as in stitches
import { style } from "twind/style";
const blockMixin = style({
base: "block w-full",
variants: {
inline: "inline-block w-auto"
}
});
const Button = const Button = styled("button", blockMixin, {
base: `
appearance-none border-none bg-transparent
rounded-full px-2.5
`,
variants: {
size: {
sm: `text-sm h-6`,
md: `text-base h-9`,
},
variant: {
gray: `
bg-gray-500
hover:bg-gray-600
`,
primary: `
text-white bg-purple-500
hover:bg-purple-600
`,
},
outlined: {
true: `bg-transparent ring-1`,
},
},
defaults: {
variant: "gray",
size: "sm",
},
matches: [
{
variant: "gray",
outlined: true,
use: `ring-gray-500`,
},
{
variant: "primary",
outlined: true,
use: `text-purple-500 ring-gray-500 hover:text-white`,
},
],
})
Hi! I'm facing a weird issue when applying padding to siblings div.
Apply padding
depending on a prop value (align
in my case), and passing this padding
through className
to a styled component.
I have four Items
with various align
value:
<Item align="left" />
<Item align="justify" />
<Item align="right" />
<Item align="left" />
textPadding
is set depending on align
value, and pass via className
to StyledItem
.
const Item = (props: { align: string }) => {
const textPadding = props.align === "left" ? "pl-2" : "pr-2";
return (
<StyledItem className={tw`${textPadding}`}>
<NestedContent />
</StyledItem>
);
};
StyledItem
is a twind/react styled component.
const StyledItem = styled("div", {
base: `bg-indigo-600 w-full h-7`
});
From here, I should have the 1st and 4th Item
components with pl-2
(because align === "left"
) and the 2nd and 3rd Item
components with pr-2
(because align !== "left"
).
But the result is different: the 4th Item
component has pr-2
applied.
(screenshot with padding as blue parts)
https://codesandbox.io/s/relaxed-lederberg-9euwo?file=/src/App.tsx
What do you think? It's because we add style through className
to a styled component?
Thanks a lot :)
Is this repo still under active development? I noticed that the last commit was from over 7 months ago.
Is twind-react
prod ready?
Thanks in regards!
When trying to extract the props type of a StyledComponent, it makes them incompatible with the component itself :
import { styled, tw } from "@twind/react";
import * as React from "react";
const BaseButton = styled("button", {
base: tw`
inline-flex items-center
px-4 py-2
border border-transparent
text-sm font-medium
rounded-md shadow-sm
text-white bg-indigo-600
hover:bg-indigo-700
focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500
`,
});
type BaseButtonProps = React.ComponentProps<typeof BaseButton>;
export type ButtonProps = BaseButtonProps & { icon?: React.ReactNode };
export const Button = (props: ButtonProps) => {
const { icon, ...baseButtonProps } = props;
return <BaseButton {...baseButtonProps}></BaseButton>;
};
Typescript error on the BaseButton
component receiving baseButtonProps
:
Type '{ tw?: Token; css?: CSSRules | undefined; class?: string | undefined; className?: string | undefined; as?: ElementType<any> | undefined; }' is not assignable to type 'IntrinsicAttributes'.
Types of property 'css' are incompatible.
Type 'CSSRules | undefined' is not assignable to type 'InterpolationWithTheme<any>'.
Type 'CSSRules' is not assignable to type 'InterpolationWithTheme<any>'.
Type 'CSSRules' is not assignable to type 'Keyframes'.
Type 'CSSRules' is missing the following properties from type '{ name: string; styles: string; anim: number; toString: () => string; }': name, styles, animts(2322)
@twind/preact
is already there:
https://github.com/tw-in-js/use-twind-with/tree/main/packages/preact
Look like the styled() combines all utilities class into one such as ".tw-1baguyc",
Therefore the important does not correctly apply. 🐛
Here is reproduce sandbox. The text should blue
https://codesandbox.io/s/twind-react-styled-forked-rfq2u?file=/src/App.js
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.