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-inputs

v0.5.0

Published

Basic Input Components for No Muss, No Fuss Plug and Play with Svelte

Downloads

8

Readme

npm install size NPM npm

svelte-inputs

Basic Input Components for No Muss, No Fuss Plug and Play with Svelte

Features!

  • Event Callbacks
  • Data binding
  • Input Masking

Contents:

Background

svelte-inputs was made on the idea that there should be simple, straightforward inputs, at a modular level for Svelte. No more fussing about!

svelte-inputs requires Svelte >= 3.0.0

Installation

The easiest and recommended way to install svelte-inputs is with the npm command line.

npm i svelte-inputs

Usage

At the moment, svelte-inputs comes with two (2) basic input modules.

All text inputs support the properties:

  • value
  • placeholder
  • disabled
  • className (see notes on styling)
  • mask

All text inputs support the events:

  • on:change
  • on:focus
  • on:blur
  • on:keyup

Text Inputs are imported with the ES6 import, though Babel is also recommended. It may also be helpful to alias imports for inputs with longer names.

Ex:

import {
  TextInput,
  TextInputWithPlaceholder as InputPlaceholder
} from "svelte-inputs";

TextInput

TextInput is a basic text input. It handles all of the basic properties of a regular input, but with direct bindings to the variables you provide it.

TextInput

Ex: App.svelte

<script>
  import { TextInput } from "svelte-inputs";

  let myvar = "Example!";
</script>
<style>
  ...;
</style>
<TextInput value="{myvar}" />

This passes myvar to the text input for modification. However, without additional properties supplied, any modification on the variable will not be able to be retrieved. In order to get instant updates to myvar, it is recommended to bind the value property to your variable.

Ex:

<TextInput bind:value="{myvar}" />

Alternatively, for complex situations, you may not want the variable to be instantly updated - for example, if you needed additional processing. In this situation, pass a callback method to the on:change property. The callback must be able to consume a custom Svelte event.

Ex:

<script>
  import { TextInput } from "svelte-inputs";

  let myvar = "Example!";

  function myCallback(event) {
    let tmp = event.detail; //get the modified string
    myvar = tmp.trim();
  }
</script>
<style>
  ...;
</style>
<TextInput value="{myvar}" on:change="{myCallback}" />

TextInputWithPlaceholder

Similar to the usage of the basic TextInput, it also provides a placeholder that collapses on focus/entry.

The placeholder property is not required, but it behaves much like a basic TextInput without it.

TextInputWithPlaceholder

Ex:

<script>
  import { TextInputWithPlaceholder as Input } from "svelte-inputs";

  let myvar = "Example!";
  let myplaceholder = "App Name:";
</script>
<style>
  ...;
</style>
<input bind:value="{myvar}" placeholder="{myplaceholder}" />

In keeping with basic Svelte, the placeholder property also supports binding.

Masking

svelte-inputs comes with some basic masking.

A mask can be given to a component through the mask property. This property accepts a config object in the given form below:

{
  mask: "(xxx) xxx-xxxx",
  override: true,
  enforceLength: true,
  alwaysVisible: false,
  defaultChar: ' '
}

Properties

  • mask: String; This is the actual mask that you want to use for the input. x characters denote user input characters. All other characters will be included as part of the mask.
  • override: Boolean; This tells the component whether or not to override the bound value property with the mask (true) or return only the raw characters entered by the user (false). In either case, the mask will still display.
  • enforceLength: Boolean; This determines if the mask should enforce the length of the input based on the length of the mask.
  • alwaysVisible: Boolean; determines if the mask should be visible at all times. If false, the mask will only appear as characters are typed. Default is false.
  • defaultChar: String; The default character (or string) used as a placeholder for each x character in the mask. This only applied to a mask that is also configured to be alwaysVisible: true.

Styling

Because of how Svelte handles scoping of styles in components, in order to override the styling of the elements in the svelte-inputs components, you will need to either force style cascading with the :global style property; or you will need to place your styles in a global stylesheet, such as the default global.css in the sveltejs template (/public/global.css).

Example using :global

<script>
  import { TextInput as Input } from "svelte-inputs";

  let myvar = "Example!";
</script>
<style>
  :global(input) {
    color: blue;
  }
</style>
<input bind:value="{myvar}" />

className

className is a special property that allows you to give special classes to the inputs. Still, to use these classes will require use of one of the methods mentioned above.

Development

If you'd like to contribute to the development of this project and extend the svelte-inputs library, please join us on GitHub!