npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-inline-style

v1.0.0

Published

inline styles for svelte components

Downloads

18

Readme

svelte-inline-style

Efficiently apply inline styles to Svelte components.

NPM users: please consider the Github README for the latest description of this package (as updating the docs would otherwise always require a new NPM package version)

Just a small note: if you like this module and plan to use it, consider "starring" this repository (you will find the "Star" button on the top right of this page), so that I know which of my repositories to take most care of.

Installation

npm install svelte-inline-style

Usage

It is recommended to import the package within a module context:

<script context="module">
  import style from 'svelte-inline-style'
</script>

<script>
  let styles = {
    fontSize:'22px',   // use camel-cased CSS property names...
    fontWeight:'bold'  // ...and start with a small letter
  }
</script>

<div use:style={styles}>...</div>

Try yourself

Experiment with svelte-inline-style using the Svelte REPL

Background Information

Sometimes it is necessary to add inline styles to a Svelte component rather than to rely on a stylesheet and just switch classes.

A straightforward approach could be to use style attributes:

<div style="font-size:{fontsize}px; font-weight:{fontweight}">...</div>

but this one would first require to construct a string which would then have to parsed by the browser before the actual changes could be made.

Another solution has been shown by mouse484 in package svelte-inline-css: with the aid of Svelte "actions" inline styles may be directly set on the HTML elements created to represent Svelte components:

<script>
  import style from 'svelte-inline-css'

  export let styles = {
    'font-size':'22px',
    'font-weight':'bold'
  }
</script>

<div use:style={styles}>...</div>

This solution works great, but - again - requires some string processing before the actual style can be applied: svelte-inline-css expects kebab-cased CSS property names which first have to be converted to camel-cased identifiers before they may be set.

This implementation therefore suggests a third alternative, which seems "more natural": start with camel-cased CSS property names right away and apply them to HTML elements without prior conversion.

<script>
  import style from './svelte-inline-style.js'

  export let styles = {
    fontSize:'22px',
    fontWeight:'bold'
  }
</script>

<div use:style={styles}>...</div>

Build Instructions

You may easily build this package yourself.

Just install NPM according to the instructions for your platform and follow these steps:

  1. either clone this repository using git or download a ZIP archive with its contents to your disk and unpack it there
  2. open a shell and navigate to the root directory of this repository
  3. run npm install in order to install the complete build environment
  4. execute npm run build to create a new build

You may also look into the author's build-configuration-study for a general description of his build environment.

License

MIT License