Giter Site home page Giter Site logo

johnchourajr / buen-type Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 1.22 MB

A utility library for managing typographic scales in Tailwind CSS.

Home Page: https://type.muybuen.dev/

License: MIT License

TypeScript 99.19% JavaScript 0.09% CSS 0.73%
react tailwindcss tailwind-plugin tailwind typography

buen-type's Introduction

image

@buen/type

A utility library for managing typographic scales in Tailwind CSS.

Contents

Installation

NPM

npx jsr add @buen/type

Deno

deno add @buen/type

Yarn

yarn dlx jsr add @buen/type

PNPM

pnpm dlx jsr add @buen/type

Usage

Add Plugin

// tailwind.config.js

import { buenTypeTailwind } from "@buen/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 "@buen/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 "@buen/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.

buen-type's People

Contributors

johnchourajr avatar

Stargazers

Thomas Rosen avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.