Code Monkey home page Code Monkey logo

ustyled's Introduction

ustyled

Introduction

ustyled(styled-system, util) 是一个基于 CSS-in-JS 的工具库,旨在为 CSS-in-JS 添加类似 styled-system 的编写方式,同时避免使用 styled-system 导致的一些问题。

Features

  • 函数式主题
  • 暗色模式支持
  • 快速应用调色板
  • 按比例排版

Installation

npm i @syfxlin/ustyled

注意事项:目前 ustyled 还处于早期测试阶段,可能会存在一些问题,请避免用于重要的项目中。

Usage

demo/Demo.tsx

Tip

v1 采用了较为激进的方式对样式进行预处理,因此造成了很多问题,导致在一些场景下出现无法处理的情况。 由于不能顾及所有方面,因此采用模板字符串的方式注入主题变量 ${u.color('blue1', 'blue2')}

v2 同时改进了主题的定义方式,如下,你可以通过 prop 定义字段名称,通过 animation-delay: ${u.d(1)}; 方式进行定义, ustyled 会通过 css 将参数处理成字符串,并替换定义的字符,如转换后为 animation-delay: 1s;

export const delay = style({
  prop: ["d", "delay"],
  css: () => (value: string | number) => {
    if (typeof value === "number") {
      return `${value}s`;
    }
    return value;
  },
});

Maintainer

ustyled 由 Otstar Lin 和下列 贡献者 的帮助下撰写和维护。

Otstar Lin - Personal Website · Blog · Github

License

License

根据 Apache License 2.0 许可证开源。

ustyled's People

Contributors

syfxlin avatar

Stargazers

Roman avatar 祀画 avatar Gerardyang avatar

Watchers

 avatar

ustyled's Issues

嵌套响应式支持

目前响应式只能在第一层样式中使用,如果存在 css 选择器,在选择器下的样式不能支持响应式。需要添加支持。

错误解析 media 查询

<div
    css={css`
        width: 100%;
        max-width: 100%;
        margin: auto;
        padding: 0 1rem;

        @media (min-width: ${ctx.theme.breakpoints.sm}px) {
            max-width: ${ctx.theme.breakpoints.sm}px;
        }
    `}
>

以上样式经过解析后会出错,因为 min-width: ${ctx.theme.breakpoints.sm}px 被错误解析成 css property

添加 template string 响应式语法

const getter = styles[kebabToCamel(prop)];
if (getter) {
let val: number | string = `${value}${imp || ""}`.trim();
// @ts-ignore
if (val !== "" && !isNaN(val)) {
val = parseFloat(val);
}
values.push(raw.slice(lastIndex, match.index));
values.push(getter(val));
lastIndex = match.index + match[0].length;
}

/* Example */
.test {
    width: [1, 2, 3];
    height: [1, 2, 3];
}
const values = value.match(/^\s*\[\s*([^\]]+?)\s*\]\s*/);
const arr = values.split(/\s*,\s*/g);

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.