1.0.5 • Published 2 years ago

@tailwindash/triangle v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@tailwindash/triangle

npm.badge bundlephobia.badge Tailwind Play

Tailwind plugin for building triangles with border attributes.

Showcase

Table of Contents

tailwindash

This package is part of the @tailwindash family. For contributing guideline and more, refer to its readme.

Installation

  1. Make sure you have tailwind setup for your project.

  2. Install @tailwindash/triangle

    npm install -D @tailwindash/triangle
    pnpm add -D @tailwindash/triangle
    yarn add -D @tailwindash/triangle
  3. Add plugin to tailwind config file

    /** @type {import("tailwindcss").Config } */
    const config = {
      plugins: [require('@tailwindash/triangle')],
    };
    
    module.exports = config;

Quick Start

See Tailwind Play. For more customization, see below Documentation.

Documentation

Direction Abbreviation

DirectionAbbreviation
topt
bottomb
leftl
rightr
top lefttl
top righttr
bottom leftbl
bottom rightbr

Class Names

Class nameValuesTypeGroupRequiredDescription
trianglecomponentyesbase class
triangle-...one of {t, b, l, r, tl, tr, bl, br }utilitydirectionyesplacement direction
triangle-...as in tailwind's colorutilitycolornocolor
triangle-...integer from 1 to 10, or as customizedutilityscalenosee Scaling
triangle-w-...as in tailwind's widthutilitysizenowidth
triangle-h-...as in tailwind's heightutilitysizenoheight

Sizing & Scaling

Depending on the direction, triangle will have the following default width & height

DirectionWidthHeight
triangle-{t,b}1rem0.5rem
triangle-{l,r}0.5rem1rem
triangle-{tl,tr,bl,br}1rem1rem

⚠️ Scaling is done by applying css's calc() to width and height, not transform: scale(...)

For example:

<div class="triangle triangle-t triangle-w-5 triangle-h-10 triangle-3"></div>
<!-- The calculation below assumes tailwind's default config -->
<!-- w-5 = 1.25rem -->
<!-- h-10 = 2.5rem -->
<!-- scaling factor = 3 -->
<!-- => triangle width = 1.25rem * 3 -->
<!-- => triangle height = 2.5rem * 3 -->

Below is the default support for scaling. Extend triangle if customization is needed (see Customization).

/** @type {import("tailwindcss").Config } */
const config = {
  theme: {
    triangle: {
      1: '1',
      2: '2',
      3: '3',
      4: '4',
      5: '5',
      6: '6',
      7: '7',
      8: '8',
      9: '9',
      10: '10',
    },
  },
};

Customization

This plugin respects your tailwind config, including prefixes.

For customization of the scaling factor, set or extend the triangle object. Make sure to have a valid factor for css's calc().

/** @type {import("tailwindcss").Config } */
const config = {
  theme: {
    extend: {
      triangle: {
        '1/2': '1/2',
        20: '20',
      },
    },
  },
  plugins: [require('@tailwindash/triangle')],
};

module.exports = config;

Changelog

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago