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

@miraidesigns/textfield

v1.0.2

Published

Mirai Designs Framework: Textfield module

Downloads

4

Readme

Textfields

Text fields allow for text based inputs.


HTML

<div class="mdf-textfield">
    <label for="textfield" class="mdf-textfield__label">Label</label>
    <input id="textfield" class="mdf-textfield__input" type="text">
</div>

Sass

// Include default styles without configuration
@forward '@miraidesigns/textfield/styles';
// Configure appearance
@use '@miraidesigns/textfield' with (
    $variable: value
);

@include textfield.styles();

TypeScript

import { MDFTextfield } from '@miraidesigns/textfield';

new MDFTextfield(document.querySelector('.mdf-textfield'));

Examples

Some basic examples on how the module can be used.

Icons

Icons are a great way to add visual information to your input, like a search icon for example.

<!-- Leading icon -->
<div class="mdf-textfield mdf-textfield--icon-leading">
    <label for="textfield" class="mdf-textfield__label">Label</label>
    <input id="textfield" class="mdf-textfield__input" type="text">
    <svg class="mdf-textfield__icon">
        <use href="icons.svg#search"></use>
    </svg>
</div>

<!-- Trailing icon -->
<div class="mdf-textfield mdf-textfield--icon-trailing">
    <label for="textfield" class="mdf-textfield__label">Label</label>
    <input id="textfield" class="mdf-textfield__input" type="text">
    <svg class="mdf-textfield__icon">
        <use href="icons.svg#lock"></use>
    </svg>
</div>

Counters

Display the current character count and character limit.

<div class="mdf-textfield mdf-textfield--has-helper">
    <label for="textfield-counter" class="mdf-textfield__label">Text field</label>
    <input id="textfield-counter" class="mdf-textfield__input" type="text" maxlength="30">
    <div class="mdf-textfield__helper-line">
        <span class="mdf-textfield__helper mdf-textfield__helper--counter"></span>
    </div>
</div>

Textareas

Textareas automatically grow in size to accommodate their content.

<div class="mdf-textfield mdf-textfield--textarea">
    <label for="textarea" class="mdf-textfield__label">Textarea</label>
    <textarea id="textarea" class="mdf-textfield__input" rows="1"></textarea>
</div>

Passwords

Password fields allow to toggle between hidden and plain text.

<div class="mdf-textfield mdf-textfield--has-helper mdf-textfield--icon-trailing">
    <label for="password-field" class="mdf-textfield__label">Password</label>
    <input id="password-field" class="mdf-textfield__input" type="password" minlength="8" maxlength="12" pattern="[a-zA-Z0-9]+">
    <div class="mdf-textfield__helper-line">
        <span class="mdf-textfield__helper"></span>
    </div>

    <button class="mdf-textfield__button mdf-textfield__button--toggle">
        <svg class="mdf-textfield__icon" viewBox="0 0 24 24" aria-hidden="true">
            <use href="icons.svg#visibility"></use>
            <use class="mdf-hidden" href="icons.svg#visibility-off"></use>
        </svg>
    </button>
</div>

Implementation

Classes

| Name | Type | Description | | -------------------------------- | ---------------- | -------------------------------------------------------------------------------------------------- | | mdf-textfield | Parent | Contains the input elements | | mdf-textfield--condensed | Modifier | Reduce the input's height | | mdf-textfield--stretch | Modifier | Stretches the input to the width of its parent | | mdf-textfield--disabled | Modifier | Greys out the input, stops all interaction with the element | | mdf-textfield--state-success | Modifier | Used in input validation, changes input colors to green | | mdf-textfield--state-warning | Modifier | Used in input validation, changes input colors to yellow | | mdf-textfield--state-error | Modifier | Used in input validation, changes input colors to red | | mdf-textfield--textarea | Modifier | For textarea elements | | mdf-textfield--number | Modifier | For number input elements | | mdf-textfield--has-helper | Modifier | Prepare the input for helper text (also used for error messages) | | mdf-textfield--icon-leading | Modifier | Prepare the input for a leading icon | | mdf-textfield--icon-trailing | Modifier | Prepare the input for a trailing icon | | mdf-textfield__label | Child | Label element, child to .mdf-textfield | | mdf-textfield__label--floating | Modifier | Moves the label above the input | | mdf-textfield__label--focus | Modifier | Focus styles for the label | | mdf-textfield__label--shake | Modifier | Play the shake animation | | mdf-textfield__input | Child | Input element. Child to .mdf-textfield | | mdf-textfield__icon | Child | Icon element. Child to .mdf-textfield | | mdf-textfield__button | Child | Button element. Child to .mdf-textfield | | mdf-textfield__helper-line | Parent / Child | Contains the helper text and text counter. Child to .mdf-textfield | | mdf-textfield__helper | Child | Helper text, used to display useful information and errors. Child to .mdf-textfield__helper-line | | mdf-textfield__helper--counter | Modifier | Used for the character counter |

Properties

| Name | Type | Description | | -------------------- | ------------------ | ------------------------------------------------------------------------ | | .counter | HTMLElement | Returns the counter element | | .helper | HTMLElement | Returns the helper element | | .input | HTMLInputElement | Returns the input element | | .label | HTMLElement | Returns the label element | | .leadingIcon | HTMLElement | Returns the leading icon element | | .toggle | HTMLElement | Returns the password toggle element | | .trailingIcon | HTMLElement | Returns the trailing icon element | | .type | string | Get or set the input's type | | .value | string | Get or set the input's value | | .length | number | Get the value's current length | | .minLength | number | Get or set the input's minLength | | .maxLength | number | Get or set the input's maxLength | | .min | string | Get or set the input's min | | .max | string | Get or set the input's max | | .step | string | Get or set the input's step | | .pattern | string | Get or set the input's pattern | | .required | boolean | Get or set the input's required state | | .disabled | boolean | Get or set the input's disabled state | | .prefix | string | Get or set the prefix text | | .suffix | string | Get or set the suffix text | | .message | string | Get or set the helper message | | .validate | boolean | Get or set if the input should use validation (defaults to true) | | .state | string | Get the current input state | | .setState(state) | (string): void | Set the current input state. Valid value are Success Warning Error | | .clearState() | (): void | Clear the current input state | | .setError(error) | (string): void | Set Error state and display the given error message | | .clearError() | (): void | Clear input state and remove message | | .floatLabel(float) | (boolean): void | Float the label or restore the default position | | .focusLabel(focus) | (boolean): void | Focus the label or remove focus from it | | .shakeLabel() | (): void | Shake the label to indicate an invalid input |