百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

styled-tools

> 前端框架
开源

CSS-in-JS 中的有用插值函数

799 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

CSS-in-JS 中的有用插值函数

styled-tools

适用于 styled-components、emotion、JSS 以及其他 CSS-in-JS 库的有用插值函数。

安装

npm: npm i styled-tools 纱线: yarn add styled-tools

使用方法

javascript
import styled, { css } from "styled-components";
import { prop, ifProp, switchProp } from "styled-tools";

const Button = styled.button`
  color: ${prop("color", "red")};
  font-size: ${ifProp({ size: "large" }, "20px", "14px")};
  background-color: ${switchProp("theme", {
    dark: "blue", 
    darker: "mediumblue", 
    darkest: "darkblue" 
  })};
`;

// renders with color: blue

// renders with color: red

// renders with font-size: 20px

// renders with background-color: mediumblue

一个更复杂的示例:

…

API

目录

  • prop
  • 参数
  • 示例
  • 主题
  • 参数
  • 示例
  • 调色板
  • 参数
  • 示例
  • ifProp
  • 参数
  • 示例
  • ifNotProp
  • 参数
  • 示例
  • withProp
  • 参数
  • 示例
  • switchProp
  • 参数
  • 示例
  • 类型
  • 针头

prop

返回 props[path] 或 defaultValue 的值

Issues· 15 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptcss-in-jsemotionjsslodash

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架