项目作者: swapnilmishra

项目描述 :
Attempt to create a simple css-in-js lib
高级语言: JavaScript
项目地址: git://github.com/swapnilmishra/css-in-js.git
创建时间: 2020-01-30T15:45:31Z
项目社区:https://github.com/swapnilmishra/css-in-js

开源协议:

下载


Attempt at creating a simple css-in-js lib

See filename lib/styled.js for the implementation and example/src/App.js for an example usage.

External dependencies used:

Usage with variables

  1. import styled from "lib/styled";
  2. const primaryColor = "white";
  3. const secondaryColor = "red";
  4. const padding = "10px 20px";
  5. const AnotherButton = styled.button`
  6. background-color: ${secondaryColor};
  7. padding: ${padding};
  8. color: ${primaryColor};
  9. `;

Usage with styled-system

  1. import styled from "lib/styled";
  2. import { color } from "styled-system";
  3. const Button = styled.button`
  4. background-color: blue;
  5. padding: 10px 20px;
  6. ${color}
  7. `;
  8. <Button color="red" disabled>
  9. This is styled button
  10. </Button>;

Usage with custom function which returns CSS

  1. import styled from "lib/styled";
  2. const Input = styled.input`
  3. padding: 10px 20px;
  4. background-color: ${props => (props.primary ? "red" : "palevioletred")};
  5. color: white;
  6. `;
  7. <Input type="text" primary />;

Usage with className property

  1. import { css } from "lib/styled";
  2. const bgColor = "black";
  3. const containerCls = css`
  4. background-color: ${bgColor};
  5. width: 50px;
  6. height: 50px;
  7. color: white;
  8. `;
  9. <div className="{containerCls}">Content</div>;

or

  1. import { css } from "lib/styled";
  2. <div
  3. className={css`
  4. background-color: ${props.bgColor};
  5. width: 50px;
  6. height: 50px;
  7. color: white;
  8. `}
  9. >

Extending components

  1. const Input = styled.input`
  2. padding: 10px 20px;
  3. background-color: ${props => (props.primary ? "gray" : "palevioletred")};
  4. color: white;
  5. `;
  6. const AnotherInput = styled(Input)`
  7. background-color: yellow;
  8. color: green;
  9. `;

TODO

  • A bit of writeup