Git Product home page Git Product logo

twind-react's People

Contributors

sastan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

twind-react's Issues

Add support for mixin with twind/style, the same as in stitches

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`,
    },
  ],
})

Classname not applying on next siblings on styled components

Hi! I'm facing a weird issue when applying padding to siblings div.

What I'm searching to do

Apply padding depending on a prop value (align in my case), and passing this padding through className to a styled component.

The code

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.

Capture d’écran 2021-04-07 à 18 18 46

(screenshot with padding as blue parts)

Reproduced issue in sandbox

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 :)

React.ComponentProps on a StyledComponent is not working properly

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.