Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ryanve/varam

change CSS var via URL param with this 77 line library called varam
https://github.com/ryanve/varam

css cssvar frontend javascript params technique urlsearchparams

Last synced: about 1 month ago
JSON representation

change CSS var via URL param with this 77 line library called varam

Awesome Lists containing this project

README

        

# varam

[🟣 **online**](https://ryanve.dev/varam) [**latest**](../../releases/latest)

## change CSS var via URL param

### mention desired param

place `data-varam` on any scope to represent CSS `var`

```html

```

- only scoped mentions will change
- scope page via root

```html

```

- combine data with URL params to update matching `var`
- combining `?oil=olive&ink=black` would style each `var`

```css
--oil: olive;
--ink: black;
```

### var your style

```css
background: var(--oil);
color: var(--ink);
```

### code sensible default style

```css
font-size: var(--size, 1em);
writing-mode: var(--mode, horizontal-tb);
```

### code hyperlinks with `&`

```html
?oil=orange&ink=black
```

## [javascript](varam.js)

### automagic

🚥 `varam` automagically runs when you load [varam.js](varam.js)

```html

```

- URL params are read and only read
- CSS var are updated where matching
- [async or defer to your desire](../../releases)

### updating

- performant updating
- we minimize reflow
- [just load the script](#automagic) to go with the flow with real URL
- [updaters](#updaters) return [boolean](#boolean) whether reflow expected
- update if you change dom (otherwise no need)

### updaters

- `varam.flow()` automagic does `varam(location.search)` with real URL
- `varam.reset()` to reset state like `varam("")` but leave URL alone
- `varam.fresh(...)` is how varam performantly interacts with style

### boolean

- `true` when update was made
- `false` when update needless

### help

`varam.help()` for help in your console

### diagnostic

- `varam.meta` content interpreted
- `varam.state` latest state
- `varam.via` paramethod `"flow"` or `"meta"`

### [staging](../../pull/8)

- default checks `location.search` **not meta**
- staging meta simulates alternate search
- **omit meta** unless you're staging

```html

```

## technology

- [`URLSearchParams`](https://mdn.io/URLSearchParams)
- [`location`](https://mdn.io/window-location)
- [`script`](https://mdn.io/the-script-element)
- [`style`](https://mdn.io/CSSStyleDeclaration)
- [`html`](index.html) [`data-`](https://mdn.io/data-attributes)
- [`css`](www.css) [`var`](https://mdn.io/css-var)