All Projects → jedmao → Postcss Triangle

jedmao / Postcss Triangle

Licence: mit
PostCSS plugin to create a triangle.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Postcss Triangle

postcss-sort-media-queries
PostCSS plugin for combine and sort CSS media queries with mobile first or desktop first methods.
Stars: ✭ 118 (+107.02%)
Mutual labels:  postcss, postcss-plugin
Postcss Sprites
Generate sprites from stylesheets.
Stars: ✭ 402 (+605.26%)
Mutual labels:  postcss, postcss-plugin
postcss-relaxed-unit
🍮Postcss-relaxed-unit is a postcss plugin for unit tranformation and make write css easier with custom unit.
Stars: ✭ 44 (-22.81%)
Mutual labels:  postcss, postcss-plugin
Postcss Alias
PostCSS plugin that allows you to create aliases for CSS properties
Stars: ✭ 47 (-17.54%)
Mutual labels:  postcss, postcss-plugin
Postcss Import
PostCSS plugin to inline @import rules content
Stars: ✭ 1,048 (+1738.6%)
Mutual labels:  postcss, postcss-plugin
postcss-aspect-ratio
A PostCSS plugin to fix an element's dimensions to an aspect ratio.
Stars: ✭ 38 (-33.33%)
Mutual labels:  postcss, postcss-plugin
Postcss Responsive Type
Automagical responsive typography, built on PostCSS
Stars: ✭ 363 (+536.84%)
Mutual labels:  postcss, postcss-plugin
postcss-lazyimagecss
A PostCSS plugin that generates images's CSS width & height properties automatically.
Stars: ✭ 38 (-33.33%)
Mutual labels:  postcss, postcss-plugin
Postcss Position
PostCSS plugin that adds shorthand declarations for position attributes
Stars: ✭ 26 (-54.39%)
Mutual labels:  postcss, postcss-plugin
Purgecss
Remove unused CSS
Stars: ✭ 6,566 (+11419.3%)
Mutual labels:  postcss-plugin, postcss
postcss-typed-css-classes
PostCSS plugin that generates typed entities from CSS classes for chosen programming language.
Stars: ✭ 12 (-78.95%)
Mutual labels:  postcss, postcss-plugin
Postcss Icon
PostCSS plugin that adds `css icons` from icon sets
Stars: ✭ 20 (-64.91%)
Mutual labels:  postcss, postcss-plugin
postcss-define-function
PostCSS plugin for Sass-like function directive
Stars: ✭ 25 (-56.14%)
Mutual labels:  postcss, postcss-plugin
Postcss Banner
PostCSS plugin to add text banner and footer to resulting file
Stars: ✭ 13 (-77.19%)
Mutual labels:  postcss, postcss-plugin
postcss-clean
PostCss plugin to minify your CSS with clean-css
Stars: ✭ 41 (-28.07%)
Mutual labels:  postcss, postcss-plugin
postcss-momentum-scrolling
PostCSS plugin add 'momentum' style scrolling behavior (-webkit-overflow-scrolling: touch) for elements with overflow (scroll, auto) on iOS
Stars: ✭ 69 (+21.05%)
Mutual labels:  postcss, postcss-plugin
postcss-gtk
Processes GTK+ CSS into browser CSS
Stars: ✭ 23 (-59.65%)
Mutual labels:  postcss, postcss-plugin
postcss-font-pack
PostCSS plugin to simplify font declarations by validating only configured font packs are used and adding fallbacks.
Stars: ✭ 18 (-68.42%)
Mutual labels:  postcss, postcss-plugin
Postcss Easing Gradients
PostCSS plugin to create smooth linear-gradients that approximate easing functions.
Stars: ✭ 689 (+1108.77%)
Mutual labels:  postcss, postcss-plugin
Postcss Interpolate
PostCSS plugin for values interpolation between breakpoints.
Stars: ✭ 9 (-84.21%)
Mutual labels:  postcss, postcss-plugin

postcss-triangle

NPM version npm license Travis Build Status codecov Dependency Status

npm

PostCSS plugin to create a triangle.

Introduction

Creating triangles in CSS is entirely complicated, but it doesn't have to be!

Using this plugin, you can create three different types of triangles:

.isosceles-triangle {
	triangle: pointing-<up|down|left|right>;
	width: <length>;
	height: <length>;
	background-color: <color>;
}

.right-isosceles-triangle {
	triangle: right-iso pointing-<up|down|left|right>;
	<width|height>: <length>;
	background-color: <color>;
}

.equilateral-triangle {
	triangle: equilateral pointing-<up|down|left|right>;
	<width|height>: <length>;
	background-color: <color>;
}

Triangle types

All triangle types have the following rules/caveats:

  • You must specify a direction (pointing-up, pointing-down, pointing-left or pointing-right).
  • You must provide a separate background-color declaration. This will transpile into a border-color in the opposite direction in which your triangle points. The background-color helps you forget about all that nonsense and just specify what appears to be the background color, visually.
  • Unfortunately, there is no way to set a triangle's actual border at this time. I considered using the ::before pseudo-class to achieve this; however, it had a defect that was cutting it in half and I gave up. Feel free to submit a pull request with this feature if you have a solution for it.

Now, on to the triangle types!

Isosceles

Isosceles Triangle (Default)

This is the default triangle type. It has two angles the same and two sides the same. The triangle will fit snug inside the width and height box that you define. Here's how you create one:

.isosceles-triangle {
	triangle: pointing-right;
	width: 150px;
	height: 115px;
	background-color: red;
}

This transpiles into:

.isosceles-triangle {
	width: 0;
	height: 0;
	border-style: solid;
	border-color: transparent;
	border-width: 57.5px 0 57.5px 150px;
	border-left-color: red;
}

See it on CodePen!

This creates a triangle with width: 150px; height: 115px; and pointing right.

The isosceles triangle has the following rules/caveats:

  • You must specify both a width and height.

Right-Isosceles

Right-Isosceles Triangle

This triangle has two 45° angles and one 90° angle. The 90° angle is the direction the triangle points. This is great if you want to render a triangle with the sharpest edge possible, because it follows the pixels on your screen exactly, without any additional anti-aliasing.

Iso is short for isosceles, because it's not the most fun word to spell/type; rather, it's only fun if you know how to spell it!

Here's how you create one:

.right-isosceles-triangle {
	triangle: right-iso pointing-down;
	width: 250px;
	background-color: red;
}

This transpiles into:

.right-isosceles-triangle {
	width: 0;
	height: 0;
	border-style: solid;
	border-color: transparent;
	border-width: 125px 125px 0;
	border-top-color: red;
}

See it on CodePen!

This creates a triangle with width: 250px; height: 125px; and pointing down.

The right-isosceles triangle has the following rules/caveats:

  • You must specify either a width or a height.
  • You may not specify both a width and height, because it will calculate the missing dimension for you.

Equilateral

Equilateral Triangle

This triangle's angles are all the same (60°). This means all sides are the same length as well. Here's how you create one:

.equilateral-triangle {
	triangle: equilateral pointing-up;
	height: 100px;
	background-color: red;
}

This transpiles into:

.equilateral-triangle {
	width: 0;
	height: 0;
	border-style: solid;
	border-color: transparent;
	border-width: 0 57.73503px 100px;
	border-bottom-color: red;
}

See it on CodePen!

This creates a triangle with width: 115.47006px; height: 100px; and pointing up.

The equilateral triangle has the following rules/caveats:

  • You must specify either a width or a height.
  • You may not specify both a width and height, because it will calculate the missing dimension for you.

That's about it!

Installation

$ npm install postcss-triangle

Usage

JavaScript

postcss([ require('postcss-triangle')(/* options */) ]);

TypeScript

import * as postcssTriangle from 'postcss-triangle';

postcss([ postcssTriangle(/* options */) ]);

Options

unitPrecision

Type: number
Required: false
Default: 5

When using right-iso or equilateral triangles, calculations will be performed that will most likely turn into fractions. This option allows you to control the number of significant digits after the decimal point (e.g., 1.2354 with a unitPrecision of 2 would yield 1.24, rounding it off nicely).

Testing

Run the following command:

$ npm test

This will build scripts, run tests and generate a code coverage report. Anything less than 100% coverage will throw an error.

Watching

For much faster development cycles, run the following commands in 2 separate processes:

$ npm run build:watch

Compiles TypeScript source into the ./dist folder and watches for changes.

$ npm run watch

Runs the tests in the ./dist folder and watches for changes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].