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

infield

v0.0.2

Published

HTML infield labels.

Downloads

4

Readme

Infield

Provides an HTML custom element <in-field> for in-field labels.

Getting Started

  • Import the JavaScript library in the browser (to define the custom element).
  • Import or <link> the CSS file (for essential light DOM CSS).

Usage

Example:

<in-field labelpos="inside">
    <label slot="label" for="age">Age</label>
    <input id="age" type="number">
</in-field>

Note: attributes are case-sensitive.

JavaScript API

The JavaScript API only defines a function refreshLayout(): void for <in-field> elements. It's mainly useful if your label changed in a way that might break the layout, or more specifically, if it changed its height. This is not automatic because the vast majority of the time labels are static and small, thus deemed not worth it for performance.

Label Position

Label position can be set with the labelpos attribute. It may be:

  • inside: places the label inside the input.
  • border: places the label in the border of the input (doesn't overlap with the input border).
  • outside: places the label outside of the input.
  • onborder: places the label on the border of the input (overlaps with the input border).

While the main point of this library is inside, providing alternatives is useful for when a label shouldn't be in-field because it helps to maintain a consistent style. This is especially true with overflowing input elements such as <textarea> which can create overlapping with in-field labels, hence, the default value for labelpos is not inside (at the time of writing it's border).

Styling

Parts

The following parts are defined:

  • border: use to style the input border (not the input itself!)
  • label: label slot container.
  • body: default slot container.

Properties

<in-field> elements have CSS properties set that are accessible for their rules, the public ones are:

  • --body-pad is the minimal top padding there must be in the body (usually <input>) so it will not overlap with the label.
  • --inside, --border, --outside, --on-border each are set to 1 (without a unit) when the labelpos corresponds with their name (only one can be set at a time), otherwise 0.

Examples

Set margin on the label but only for inside and border label positions:

in-field::part(label) {
	margin-block-start: calc(1rem * max(var(--inside), var(--border)));
}

Uniform distance between labels and inputs (uniform between label positions):

in-field > :nth-child(2) {
	padding: 1rem;
	padding-block-start: calc(var(--body-pad) + 1rem);
}