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

@shortcm/floating-label

v0.44.1

Published

The Material Components for the web floating-label component

Downloads

2

Readme

Floating Label

Floating labels display the type of input a field requires. Every Text Field and Select should have a label, except for full-width text fields, which use the input's placeholder attribute instead. Labels are aligned with the input line and always visible. They can be resting (when a field is inactive and empty) or floating. The label is a text caption or description for the Text Field.

Design & API Documentation

Installation

npm install @material/floating-label

Basic Usage

HTML Structure

<label class="mdc-floating-label" for="my-text-field-id">Hint text</label>

Styles

@import "@material/floating-label/mdc-floating-label";

JavaScript Instantiation

import {MDCFloatingLabel} from '@material/floating-label';

const floatingLabel = new MDCFloatingLabel(document.querySelector('.mdc-floating-label'));

Variants

Avoid Dynamic ID Generation

If you're using the JavaScript-enabled version of floating label, you can avoid needing to assign a unique id to each <input> by wrapping mdc-text-field__input within a <label>:

<label class="mdc-text-field">
  <input type="text" class="mdc-text-field__input">
  <span class="mdc-floating-label">Hint Text</span>
  <div class="mdc-text-field__bottom-line"></div>
</label>

NOTE: This method also works with <select>.

Style Customization

CSS Classes

CSS Class | Description --- | --- mdc-floating-label | Mandatory. mdc-floating-label--float-above | Indicates the label is floating in the floating position. mdc-floating-label--shake | Shakes the label.

Sass Mixins

Mixin | Description --- | --- mdc-floating-label-ink-color($color) | Customizes the ink color of the label. mdc-floating-label-fill-color($color) | Customizes the fill color of the label. mdc-floating-label-shake-keyframes($modifier, $positionY, $positionX, $scale) | Generates a CSS @keyframes at-rule for an invalid label shake. Used in conjunction with the mdc-floating-label-shake-animation mixin. mdc-floating-label-shake-animation($modifier) | Applies shake keyframe animation to label. mdc-floating-label-float-position($positionY, $positionX, $scale) | Sets position of label when floating. mdc-floating-label-max-width($max-width) | Sets the max width of the label.

MDCFloatingLabel Properties and Methods

Method Signature | Description --- | --- shake(shouldShake: boolean) => void | Proxies to the foundation's shake() method. float(shouldFloat: boolean) => void | Proxies to the foundation's float() method. getWidth() => number | Proxies to the foundation's getWidth() method.

Usage Within Frameworks

If you are using a JavaScript framework, such as React or Angular, you can create a Floating Label for your framework. Depending on your needs, you can use the Simple Approach: Wrapping MDC Web Vanilla Components, or the Advanced Approach: Using Foundations and Adapters. Please follow the instructions here.

MDCFloatingLabelAdapter

Method Signature | Description --- | --- addClass(className: string) => void | Adds a class to the label element. removeClass(className: string) => void | Removes a class from the label element. getWidth() => number | Returns the width of the label element.

MDCFloatingLabelFoundation

Method Signature | Description --- | --- shake(shouldShake: boolean) | Shakes or stops shaking the label, depending on the value of shouldShake. float(shouldFloat: boolean) | Floats or docks the label, depending on the value of shouldFloat. getWidth() => number | Returns the width of the label element.