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

@muybuen/type

v1.1.6

Published

![image](https://github.com/johnchourajr/buen-type/assets/6431920/0d383554-fe9a-4177-8907-796d9e5b33c7)

Downloads

15

Readme

image

@muybuen/type

A utility library for managing typographic scales in Tailwind CSS.

Contents

Installation

With NPM

# NPM package with NPM
npm install @muybuen/type

# -or- NPM package with Yarn
yarn add @muybuen/type

# -or- NPM package with PNPM
pnpm add @muybuen/type

With JSR

NPM

# JSR package with NPM
npx jsr add @muybuen/type

# -or- JSR package with Demo
deno add @muybuen/type

# -or- JSR package with Yarn
yarn dlx jsr add @muybuen/type

# -or- JSR package with PNPM
pnpm dlx jsr add @muybuen/type

Usage

Add Plugin

// tailwind.config.js

import { buenTypeTailwind } from "@muybuen/type";

module.exports = {
  //  ...
  plugins: [
    buenTypeTailwind
  ]
};

Custom Type

  1. Define custom styles, using either the default keys. You can also add custom keys.
// type-config.ts

const customHeadlines = {
  'display-xl': {
    fontFamily: "'Inter', 'sans-serif'",
    fontWeight: 'bold',
    clamp: [4.5, 9],
    letterSpacing: '-0.1em',
    lineHeight: 1,
    textTransform: 'uppercase',
  },
  // other headline styles
}

const customTexts = {
  'body': {
    fontFamily: "'Inter', 'sans-serif'",
    fontWeight: 'normal',
    fontSize: '1.1rem'
    letterSpacing: '0em',
    lineHeight: 1.5,
    textTransform: 'none',
  },
  // other text styles
}
  1. Add the custom styles to the plugin
// tailwind.config.ts

import { buenTypeTailwind } from "@muybuen/type";
import { customHeadlines, customTexts } from "./type-config";

function typePlugin({ addUtilities }) {
  buenTypeTailwind({ addUtilities }, {
    customHeadlines,
    customTexts
  });
};

module.exports = {
  //  ...
  plugins: [
    typePlugin
  ]
};
  1. Use tailwind utility classes in the code
// SomeComponent.tsx

export const SomeComponent = () => (
  <div>
    <h1 className="headline-display-xl">Hello World</h1>
    <p className="text-body">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
  </div>
);

Defaults

The default styles provide a basic type scale for further development.

Default Headline Types:

  • display-xxl
  • display-xl
  • display-lg
  • display-md
  • display-sm
  • display-xs

Default Text Types:

  • title
  • paragraph
  • string
  • body
  • caption

Type Properties

| Property | Type | Description | | ---------------- | ------------------ | ------------------------------------------------------------ | | fontFamily | string | The font family to be applied. | | fontWeight | string \| number | The weight of the font. | | lineHeight | string \| number | The height of the line. | | letterSpacing | string | The spacing between letters. | | textTransform | string | The transformation applied to the text (e.g., uppercase). | | fontSize | string | The size of the font. | | clamp | [number, number] | A tuple defining the minimum and maximum sizes for clamping. | | color | string | The color of the text. | | fontStyle | string | The style of the font (e.g., normal, italic, oblique). | | textDecoration | string | Decorations added to the text (e.g., underline). | | textShadow | string | Adds shadow to the text. | | whiteSpace | string | Specifies how white space inside an element is handled. | | wordSpacing | string | The spacing between words. | | textOverflow | string | How overflowed content is signaled to the user. | | direction | string | Sets the text direction (e.g., ltr, rtl). | | writingMode | string | Defines the layout of text (horizontal or vertical). | | textRendering | string | Provides rendering hints to the browser. | | hyphens | string | Specifies how words should be hyphenated. |

Clamp Property

The clamp property is used to set the range for font sizes for a particular type. The first value represents the minimum size, while the second value represents the maximum size. Consequently, the resulting font size will dynamically scale between 1024px and 1440px.

// type-config.ts

const customHeadlines = {
  'display-xl': {
    fontFamily: 'Arial, sans-serif',
    clamp: [4.5, 9],
  },
  // other styles
}

Custom Style Keys

When creating custom type definitions, either the default keys can be used or they can be expanded. They should be written in kebab-case strings.

The following is an example of how to define custom type definitions:

// type-config.ts

const customHeadlines = {
  'custom-display': {
    fontFamily: 'Arial, sans-serif',
    // use stype properties
  },
  // other headline styles
}

const customTexts = {
  'custom-paragraph': {
    fontFamily: 'Arial, sans-serif',
    // use stype properties
  },
  // other text styles
}

When using custom styled keys as tailwind classes, they'll be named as headline-your-key-name. For example, if your key was 'custom-display' in the customHeadlines object, it would be used as 'headline-custom-display' class in tailwind.

Custom Aliases for Styles

If you're replaceing an existing style in the defaults, you can add a custom alias for the style. This is done by adding a classAlias key to the style object.

// type-config.ts

const customHeadlines = {
  'display-xl': {
    fontFamily: 'Arial, sans-serif',
    classAlias: 'primary-headline',
  },
  // other headline styles
}

Disable default type styles

To disable the default type styles, set the disableDefaults option to true.

// tailwind.config.ts

import { buenTypeTailwind } from "@muybuen/type";
import { customHeadlines, customTexts } from "./type-config";

function typePlugin({ addUtilities }) {
  buenTypeTailwind(
    { addUtilities },
    {
      disableDefaults: true,
    },
  );
};

module.exports = {
  //  ...
  plugins: [
    typePlugin
  ]
};

Contributing

This project is maintained by John Choura, but it open to contributions from anyone. See CONTRIBUTORS for a guide on how to contribute.

License

This project is licensed under the MIT License - see the LICENSE file for details.