svelte-css-vars

:sparkles: Ever wanted to have reactive css variables in svelte? What if I told you there's a way?

Github星跟踪图

svelte-css-vars

Ever wanted to have reactive css variables in svelte? What if I told you there's a way?

svelte-css-vars exposes a svelte action which receives an object of properties that should be treated as css custom properties. By defining this object inside a $:{} reactive block, svelte-css-vars can update those css properties on the fly whenever some of its values change.

Usage

import cssVars from 'svelte-css-vars';

After importing the module, just define the reactive object of your custom properties:

let some_state_variable = true;

$: styleVars = {
  titleColor: some_state_variable ? 'red' : 'blue',
};

And then use the action, passing the object, on the desired element:

<style>
  div {
    color: var(--titleColor);
  }
</style>

<div use:cssVars="{styleVars}">
  <!-- anything here will have access to var(--titleColor) -->
</div>

Example

repl

REPL

主要指标

概览
名称与所有者kaisermann/svelte-css-vars
主编程语言JavaScript
编程语言JavaScript (语言数: 4)
平台
许可证MIT License
所有者活动
创建于2019-08-15 13:17:58
推送于2023-01-04 07:16:25
最后一次提交2021-06-17 13:09:20
发布数2
最新版本名称v0.0.2 (发布于 2021-03-29 17:05:12)
第一版名称v0.0.1 (发布于 2019-08-15 11:10:34)
用户参与
星数239
关注者数6
派生数3
提交数15
已启用问题?
问题数3
打开的问题数1
拉请求数2
打开的拉请求数14
关闭的拉请求数2
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?