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

@loipham/material-density

v14.0.4

Published

Density utilities for Material Components for the web

Downloads

4

Readme

Density

Density subsystem provides adaptive layout to components. Material Design uses low-density space by default but offers high-density space when it improves the user experience. Components with high density enable users to process and take action against large amounts of information in a more manageable way. List, tables, and long forms are components that benefit from increased density.

Design & API Documentation

Installation

npm install @loipham/material-density

NOTE: You do not need to directly depend on @loipham/material-density, use component provided density Sass mixins instead.

Basic Usage

The styles for applying density to button component instance looks like this:

@use "@loipham/material-button";

.my-custom-button {
  // Sets button density scale to `-3`, i.e. button height to `24px`.
  @include button.density(-3);
}

This would apply -3 (high density) to button component instance.

You would indirectly use the Density API through respective component's mixin which takes care of setting appropriate component height.

Here are the components that do provide density Sass mixins:

Density Mixins

Components that supports density provides Sass mixins to customize density for that component. Each density mixin takes in a density scale number, e.g. 0 (the default) or -1 (higher density).

Currently, the density system only allows negative numbers to customize for high density. The lower the density scale, the higher the component density. The exact density scale range depends on the component. If the scale number is unsupported by the component density mixin, the compiler will report an error at build time.

The height or size of a component is calculated with the following formula:

@use "@loipham/material-button";
@use "@loipham/material-density";

$height: button.$height + density.$interval * $density-scale
/// @example 36px + 4px * (-3) => 24px

The density interval is set to 4px for visual consistency.

It is recommended to customize density via the provided density mixins, rather than arbitrarily applying component height.

NOTE: Touch targets are automatically disabled when density mixins are applied, since dense components should be optionally enabled and therefore do not have the same default accessibility requirements.

Component variants

Components that has different variants may have their own density mixin.

For example, Tab Bar has two density mixins:

  • tab-bar.density(): Density mixin for standard tab bar.
  • tab-bar.stacked-density(): Density mixin for tab bar that has icon stacked on top of label.

Similarly, text field provides 3 different density mixins based on its variant.

Nested components

Material component that renders another component inside it needs set its own density scale accordingly. Applying density mixin on parent component does not automatically apply density to its children.

For example, Applying density to data table does not automatically set density scale to row checkbox. You'll have to explicitly set density scale to its children. This'll allow clients to have full control on the layout.

Style Customization

This package is used as utility for other components' density mixins. Customizations provided by this package is not intended to be consumed directly by developers, use component's density mixin instead.

Sass Variables

Variable | Description --- | --- $interval | Density interval between each dense scale. This interval is used for numbered density scale to calculate dense height based on baseline component height. $minimum-scale | Minimum scale supported by density subsystem. This scale always maps to highest dense scale. $maximum-scale | Maximum scale supported by density subsystem. This scale always maps to lowest dense scale. $supported-scales | Supported density scale when density literal is used (For example, minimum).

Sass Functions

Function | Description --- | --- prop-value($density-config, $density-scale, $property-name) | Returns component property value based on given density config and density scale.