0.0.5 • Published 3 years ago

svelte-style-action v0.0.5

Weekly downloads
79
License
MIT
Repository
github
Last release
3 years ago

svelte-style-action

This is a simple Svelte action that makes it easier to manage style attributes without needing to manually concatenate strings together.

This action uses node.style.setProperty to set the property values, which means that the object keys should dash-separated as when typing CSS, not camel-cased. (i.e. font-weight instead of fontWeight). This also means that CSS custom properties work properly.

<script>
  import { style } from 'svelte-style-action';

  const styles = {
    color: 'green',
    '--aVariable': '40px',
    'font-weight': 700
  };

  setTimeout(() => {
    styles = {
      ...styles,
      color: 'red'
    };
  }, 1000);
</script>

<div use:style={styles}>
  Some content
</div>

For convenience, you can also pass a string instead of an object, but you may be better off just setting the style attribute directly in that case.

Check it out in the Svelte REPL!

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago