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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?