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

@tnthung/svelte-component

v0.0.4

Published

A Simple Svelte Component Library

Downloads

1

Readme

This library is built for the purpose of reducing code duplication in the multiple projects that I work on. The components are written as generic as possible, so that they can be used in different projects.

Action

  1. clickOut

clickOut

This action is used to detect if a click event is happened outside of the element. To use this action, simply add use:clickOut={callback} to the DOM element. The callback function takes no arguments and will be called when a click event is detected outside of the element.

<script>
  import { clickOut } from 'svelte-components'
  let show = false
</script>

<button on:click={() => show = true}>Show</button>

{#if show}
  <div use:clickOut={() => show = false}>
    <p>Click outside of this element to close it</p>
  </div>
{/if}

Function

  1. normalizeClass
  2. normalizeStyle
  3. stylable

normalizeClass

This function is used to normalize the HTML class attribute. It takes in a string and remove all extra spaces and new lines.

| Name | Type | Default | Description | | --- | --- | --- | --- | | classes | string | | The classes to be normalized. |

import { normalizeClass } from 'svelte-components'

const class = normalizeClass(`
  class1 class2
  class3
`); // class = 'class1 class2 class3'

normalizeStyle

This function is used to normalize the HTML style attribute. It takes in a string and remove all extra spaces, new lines and the comments.

| Name | Type | Default | Description | | --- | --- | --- | --- | | styles | string | | The styles to be normalized. |

import { normalizeStyle } from 'svelte-components'

const style = normalizeStyle(`
  color: red;
  /* This is a comment */
  background-color: blue;
`); // style = 'color: red; background-color: blue;'

stylable

This function is mainly be used for building the svelte component by giving them the ability to be styled externally. It takes 4 arguments, and exposes 4 props to the component. By the given name, if name is "", then

  1. class
  2. style
  3. class-extra
  4. style-extra

will be exposed to the component. If name is non-empty string, then

  1. class-${name}
  2. style-${name}
  3. class-${name}-extra
  4. style-${name}-extra

will be exposed to the component.

The props with no -extra suffix will fully replace the default classes or styles. The props with -extra suffix will be appended to the default classes or styles.

The defaultClass and defaultStyle arguments will be normalized first before being applied to the component.

Notice that, for classes to take effect, they have to be defined in the global scope (using :global or <style global>).

| Name | Type | Default | Description | | --- | --- | --- | --- | | props | Object | | Pass the svelte $$props magic variable to this argument. | | name | string | | The name of the part to be styled. ("" for main partition) | | defaultClass | string | | The default classes to be applied to the part. | | defaultStyle | string | | The default styles to be applied to the part. |

<!-- Defining Component.svelte -->
<script>
  import { stylable } from 'svelte-components'
</script>

<div {...stylable($$props, "", "", "")}>          <!-- Exposing `class`,      `style`,      `class-extra`,      `style-extra`      props -->
  <span {...stylable($$props, "span", "", "")}/>  <!-- Exposing `class-span`, `style-span`, `class-span-extra`, `style-span-extra` props -->
</div>
<!-- Using the component -->
<script>
  import Component from './Component.svelte'
</script>

<Component
  class="class1 class2"
  style-extra="color: red;"
  class-span-extra="class3"/>

Component

  1. Divisor
  2. Labeled

Divisor

This component is used to create a simple divisor line with rounded edge.

Props

| Name | Type | Default | Description | | --- | --- | --- | --- | | gap? | number | 5 (in px) | The gap between the line and the text | | color? | string | #888 | The color of the line | | thickness? | number | 3 (in px) | The thickness of the line | | direction? | string | horizontal | The direction of the line. Can be horizontal or vertical |

<script>
  import { Divisor } from 'svelte-components'
</script>

<Divisor />

Labeled

This component added a label to the element. The label can be positioned on the top, bottom, left, or right of the element. Like regular label tag, by clicking on the label, the element will be focused.

Props

| Name | Type | Default | Description | | --- | --- | --- | --- | | gap? | number | 5 (in px) | The gap between the element and the label | | label? | string | '' | The text of the label | | position? | string | top | The position of the label. Can be top, bottom, left, or right |

<script>
  import { Labeled } from 'svelte-components'
</script>

<Labeled label="Label">
  <input type="text" />
</Labeled>