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

tailwindcss-fl

v0.3.0

Published

TailwindCSS fluid utility classes

Downloads

109

Readme

tailwindcss-fl

TailwindCSS plugin to generate fluid utility classes by leveraging existing config.

Motivation

  • Increase productivity by writing less markup
  • Increase readability with more concise class lists
  • Increase consistency by using ratios to scale down
  • Enable smooth scaling between sizes rather than sizes jumping between breakpoints

Media query classes

<div class="m-4 lg:m-6 xl:m-8 max-w-sm lg:max-w-lg xl:max-w-xl">
    <h2 class="text-base lg:text-2xl xl:text-4xl">
        <!-- -->
    </h2>
</div>

Fluid classes

<div class="fl:m-8 fl:max-w-xl">
    <h2 class="fl:text-4xl">
        <!-- -->
    </h2>
</div>

Installation

$ npm install tailwindcss-fl

Add to tailwind.config.js

module.exports = {
    plugins: [
        require('tailwindcss-fl')({
            screenMin: 'screens.sm',
            screenMax: 'screens.xl',
            defaultRatio: 1.618,
        }),
    ],
}

Utilities

Out the box, the following classes are generated.

Key | Classes --- | ------- fontSize | fl:text-{ keys } margin | fl:{ m, mt, mr, mb, ml, mx, my, -m, -mt, -mr, -mb, -ml, -mx, -my }-{ keys } padding | fl:{ p, pt, pr, pb, pl, px, py }-{ keys } space | fl:{ space-x, space-y }-{ keys } gap | fl:gap-{ keys } width | fl:w-{ keys } maxWidth | fl:max-w-{ keys } height | fl:h-{ keys } top/right/bottom/left/inset | fl:{top, right, bottom, left, inset, -top, -right, -bottom, -left, -inset}-{ keys } borderWidth | fl:border-{t, r, b, l}-{ keys } borderRadius | fl:rounded-{ keys }

Custom classes defined in tailwind.config.js under theme: {} will be used to generate the fluid utility classes.

List of generated classes using the default provided by tailwind

Config

Below is the full default config.

{
    prefix: 'fl',
    separator: ':',
    defaultRatio: 1.618,
    screenMin: 'screens.sm',
    screenMax: 'screens.xl',
    rootRem: 16,
    clamp: true,
    extend: true,
    variants: [],
    theme: { },
}

Option | Type | Description ------ | ---- | ----------- prefix | String | Class name prefix for fluid classes. separator | String | Class name sepator for fluid classes. defaultRatio | Number | Scale down using golden ratio 1.618. screenMin | Array | Screen size to scale from. screens.{key} or custom rem/px value. screenMax | Array | Screen size to scale to. screens.{key} or custom rem/px value. rootRem | Number | 1rem is equal to 16px. Default should work for most cases. clamp | Boolean | Enable the use of clamp() to avoid using media queries. extend | Boolean or Array | Extend existing class values, or provide an array of keys to extend, ['margin', 'padding']. variants | Array | Tailwind variants, not recommended. theme | Object | Detailed in depth below.

Theme

theme: { } allows for more fine-tuned control of fluid classes.

Using defaultRatio only

Define a defaultRatio to be applied to all classes under a specific key.

theme: {
    maxWidth: 2,
    padding: 1.5,
},

The default ratios are applied to classes fl:max-w-{ keys } and fl:{ p, pt, pr, pb, pl, px, py }-{ keys }

List of generated classes with properties and ratios

Using defaultRatio and/or a custom config

For more control, a config object can be used to target specific utility classes, the same way tailwind does.

This is especially useful for fontSize because smaller font sizes should not scale down much.

theme: {
    fontSize: {
        defaultRatio: 1.125,
        config: {
            'base': 1.125,
            'lg': 1.125,
            'xl': 1.25,
            '2xl': 1.25,
            '3xl': 1.35,
            '4xl': 1.35,
            '5xl': 1.5,
            '6xl': 1.5,
        },
    },
},

Class names can be grouped for the same ratio.

theme: {
    fontSize: {
        defaultRatio: 1.125,
        config: {
            'base lg': 1.125,
            'xl 2xl': 1.25,
            '3xl 4xl': 1.35,
            '5xl 6xl': 1.618,
        },
    },
},

The custom ratios are applied to classes fl:text-{ keys }

List of generated classes with properties and ratios

Passing an array to custom config

The power of the plugin is extending existing utilities using ratios.

However, an array of [min, max, screenMin, screenMax] can also be passed, either to overwrite an existing class, or to create a new custom class.

Parameters are based on postcss-range-value.

Param | Type | Description ----- | ---- | ----------- min(required) | String or Number | rem/px value or a scale down ratio max(required) | String or Number | rem/px value or a scale up ratio screenMin | String | screens.{key} or rem/px value screenMax | String | screens.{key} or rem/px value

Some examples below

theme: {
    maxWidth: {
        defaultRatio: 2,
        config: {
            /* scale down by 2x resulting in 12rem to 24rem between default screen sizes */
            '12/24': [2, '24rem'],

            /* scale up by 2x resulting in 24rem to 48rem between default screen sizes */
            '24/48': ['24rem', 2],

            /* scale from 32rem to 64rem between screens.md and screens.lg */
            '32/64': ['32rem', '64rem', 'screens.md', 'screens.lg'],
        },
    },
},

The custom values are added to classes fl:max-w-{ keys }

List of generated classes with properties and ratios

Fin

Feature requests, questions, hatemail? @ the person who has already spent too much time building this.