Coder Social home page Coder Social logo

postcss-short's Introduction

PostCSS Short PostCSS

NPM Version Build Status Support Chat

PostCSS Short lets you use advanced shorthand properties in CSS.

PostCSS Short has been featured in Smashing Magazine. I hope all of these shorthands are useful and clear to first-time lookers. I hope they improve the readability of your stylesheets and save you development time along the way. Thank you so much for your support.

Features

Size

Declare width and height together with size.

/* before */

.icon {
  size: 48px;
}

/* after */

.icon {
  width: 48px;
  height: 48px;
}

Margin and Padding

Avoid clobbering previous margin or padding values with a skip token.

/* before */

.frame {
  margin: * auto;
}

/* after */

.frame {
  margin-right: auto;
  margin-left: auto;
}

Position

Declare top, right, bottom, and left values in position. Just like before, omit sides with a skip token.

/* before */

.banner {
  position: fixed 0 0 *;
}

/* after */

.banner {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
}

Color

Declare color and background-color together.

/* before */

.canvas {
  color: #abccfc #212231;
}

/* after */

.canvas {
  color: #abccfc;
  background-color: #212231;
}

Overflow

Declare individual x and y values in overflow. Omit sides with a skip token.

/* before */

.scrollable {
  overflow: * auto;
}

/* after */

.scrollable {
  overflow-y: auto;
}

Border

Omit sides within border- properties and fully define individual values on the border property.

/* before */

.container {
  border: 1px 2px / * / #343434;
}

.container--variation {
  border-width: * * 3px;
}

/* after */

.container {
  border-width: 1px 2px;
  border-color: #343434;
}

.container--variation {
  border-bottom-width: 3px;
}

Border Radius

Declare border-radius properties using the clockwise syntax.

/* before */

.container {
  border-bottom-radius: 10px;
}

/* after */

.container {
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}

Font Size

Declare font-size and line-height together.

/* before */

.heading {
  font-size: 1.25em / 2;
}

/* after */

.heading {
  font-size: 1.25em;
  line-height: 2;
}

Font Weight

Declare font-weight with common names.

/* before */

p {
  font-weight: light;
}

/* after */

p {
  font-weight: 300;
}

Usage

Add PostCSS Short to your project:

npm install postcss-short --save-dev

Use PostCSS Short to process your CSS:

const postcssShort = require('postcss-short');

postcssShort.process(YOUR_CSS /*, processOptions, pluginOptions */);

Or use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssShort = require('postcss-short');

postcss([
  postcssShort(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

PostCSS Short runs in all Node environments, with special instructions for:

Node PostCSS CLI Webpack Create React App Gulp Grunt

Plugins

PostCSS Short is powered by the following plugins:

Some of these plugins have more features than are described here.

Options

features

Each plugin’s options may be configured by targeting the plugin’s namespace. Any plugin may be disabled by setting the plugin’s options as false.

postcssShort({
  features: {
    'font-size': {
      prefix: 'x'
    },
    'position': false
  }
});

prefix

The prefix option defines a prefix required by properties being transformed. Wrapping dashes are automatically applied, so that x would transform -x-border.

postcssShort({ prefix: 'x' });
.example-1 {
  -x-border-color: blue blue *;
  -x-color: * #fafafa;
}

/* becomes */

.example-1 {
  border-top-color: blue;
  border-right-color: blue;
  border-left-color: blue;
  background-color: #fafafa;
}

skip

The skip option defines the skip token used to ignore portions of the shorthand.

postcssShort({ skip: '-' });
.example-1 {
  border-color: blue blue -;
  color: - #fafafa;
}

/* becomes */

.example-1 {
  border-top-color: blue;
  border-right-color: blue;
  border-left-color: blue;
  background-color: #fafafa;
}

postcss-short's People

Contributors

jonathantneal avatar ryanzim avatar

Stargazers

Alexey Poltoradnev avatar Gary Gozlan avatar LR avatar Duyb avatar  avatar Rajab Natshah avatar Adriano P avatar Elizabeth Marston avatar Damir avatar Sean P. Myrick V19.1.7.2 avatar Alexey Sidorov avatar Cookie_gg avatar Christoph Kröppl avatar Nikita Popov avatar Joe avatar kctdfh avatar Guilherme Cayres avatar Victor ter Hark avatar ʟᴊᴜɴɢᴍ•ʀᴋ avatar SuperKag avatar Sunny avatar  avatar Hwaphon avatar  avatar Juri Hahn avatar Kevin T. Coughlin avatar Noel Cothren avatar Moe avatar Pankaj Parkar avatar Christopher Van avatar Jianqiu Xiao avatar  avatar DM Creative Studios avatar LiaoLiao avatar Damir Gubaidullin avatar Ram Damera avatar Michaël avatar Guillaume Briday avatar Yakovlev Gleb avatar Tomasz Sodzawiczny avatar Federico avatar Mathieu M-Gosselin avatar Extentus avatar Ivan avatar Ye Miancheng avatar  avatar Julian Xhokaxhiu avatar Rupesh Krishna Jha avatar Mattia Astorino avatar Alex Hafner avatar Sora Morimoto avatar son of toshimichi miki avatar DieGOs avatar Nurassyl Aldanov avatar Joshua_huang avatar Andrew Lisowski avatar wangxingkang avatar Michael Sisk avatar Bruno Stasse avatar Todd Sayre avatar James Zaccardo avatar Dmitrii Balabanov avatar shreyas avatar Sandip B avatar 米大熊 avatar  avatar Robin van der Vleuten avatar Kat Guzmán avatar Sebastian Andil avatar Tommi Finnilä avatar Alessio Felicioni avatar Will Davidow avatar Mike Syomin avatar Christian Takle avatar Alec Larson avatar Alexey A. Zabaykalsky avatar Elliott Mangham avatar Artur Rozwalak avatar Justin Hough avatar Yoshiki Kobayashi avatar  avatar 解夏 avatar Wilfred Hughes avatar balibabu avatar Kateryna avatar Dennis Smuda avatar Jinyoung Kim avatar Sebastian Rothe avatar Shio avatar Debajit Adhikary avatar Piotr Baranek avatar Ivan Čurić avatar Nestor Vera avatar fabs avatar Rinat Arsaev avatar siobhán avatar billyct avatar Marcus McLean avatar Ivan Demidov avatar Camilo Sampedro avatar

Watchers

 avatar scott romack avatar James Cloos avatar Antonio Laguna avatar Krister Kari avatar Rajab Natshah avatar Димон Дурак avatar SuperKag avatar  avatar  avatar Sean P. Myrick V19.1.7.2 avatar

postcss-short's Issues

Allow optional prefix

To prevent clashes with future syntax it would be rad if we could define (with a default) a prefix.

foo {
  -postcss-size: 10px;
}

Break into multiple modules

As per mandatory PostCSS Plugin Guidelines, plugins should do one thing.

Do not create multitool plugins. Few small one-purpose plugins with a plugins pack will be a better solution

postcss-short already overlaps with several other plugins:

https://github.com/jonathantneal/postcss-pseudo-class-enter
https://github.com/seaneking/postcss-position
https://github.com/postcss/postcss-size
https://github.com/postcss/postcss-focus
https://github.com/ben-eb/postcss-minify-font-weight
https://github.com/ben-eb/postcss-colormin

As it is, only the partial shorthands and the text shorthand are unique to postcss-short. Perhaps they could be extracted as postcss-partial-shorthand and postcss-text-property?

Feature request: 'stroke' shorthand

Can I request the ability to use stroke as a shorthand for:

  • stroke
  • stroke-dasharray
  • stroke-dashoffset
  • stroke-width

Input:

.test {
     stroke: red 50 204 1px;
}

Output:

.test {
     stroke: red;
     stroke-dasharray: 50;
     stroke-dashoffset: 204;
     stroke-width: 1px
}

Thank you and great work!

Vue-loader "Invalid CSS after..."

Hi. Thanks for your plugin. However I can't use is my vuejs project.
My config:

{
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
           postcss: {
    options: {
      plugins: [
        require('postcss-preset-env')({
          autoprefixer: {
            grid: true,
          },
          browsers: ['last 2 version'],
        }),
        require('postcss-short')(),
      ],
    },
  }
        },
}```,

It doesn't work

"*" results in error with Sass-Files

I'm using our Plugin with Gulp and Sass:

gulp.task 'styles', ->

  if compileOnly != false
    srcFile = compileOnly
  else
    srcFile = paths.files.sass

  processors = [
    postcssshort()
  ]

  gulp.src([ srcFile ], base: paths.folders.sass)
    .pipe( plumber({ errorHandler: notify.onError("Error: <%= error.message %>") }))
    .pipe(sourcemaps.init())
    .pipe(sass(
      sourcemap: true
    ))
    .pipe(postcss(processors))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest(paths.folders.css))
    .pipe(browserSync.reload(stream: true))
    .pipe notify(
      message: 'Styles task complete'
      title: 'Styles'
      onLast: true)
div
  margin: * auto
  position: absolute 50% *

results in the following error-message:

gulp-notify: [Error running Gulp] Error: src/sass/_components/_base.sass
Error: error reading values after on line 33 of src/sass/_components/_base.sass
margin: * auto;
---------^

Syntax error... what version of node is required?

Just bumped from 1.4.0 to 3.0.3, and am now getting this error when trying to run postcss-short via gulpfile:

ben@dev2 ~/sites/wordpress/cms/assets/themes/crate (master *=) $ gulp
/home/ben/sites/wordpress/cms/assets/themes/crate/node_modules/postcss-short/index.js:17
module.exports = postcss.plugin('postcss-short', (opts = {}) => {
                                                       ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/ben/sites/wordpress/cms/assets/themes/crate/gulpfile.js:124:2)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

This error is severe enough that I assume it's something wrong on my end and not a true bug in postcss-short, but I'm wondering if there's an easy/obvious resolution?

Seems like it's not doing any transformations

Sorry for the "Y NO WORK" issue. Gonna try to be as descriptive as possible.

I'm using the standard gulp + gulp-sass + gulp-postcss setup.
This is the task at hand:

// compile scss for production
gulp.task('styles-production', () =>
  gulp
    .src(src.styles + '/**/*.scss')
    .pipe(plumber({errorHandler}))
    // first postcss pass, before scss compilation, using postcss-scss
    .pipe(
      postcss(
        [
          postcssshort({
            skip: '_'
          })
        ],
        {
          syntax: postcssscss
        }
      )
    )
    // sass compilation
    .pipe(
      sass({
        includePaths: ['./node_modules/']
      })
    )
    // second pass: autoprefixer, cssnano & co
    .pipe(postcss(processors))
    .pipe(gulp.dest(dist.styles)));

I already had complaints about the default * token. Tried splitting the postcss into two steps: pre and post-compilation. After that didn't work, I changed the skip token to _, however it just passes through without any compilation:

// in
margin: _ $gutter/2;
// out
margin: _ 14px;

Any ideas?

Removes !important flag

Hi, I noticed this by accident, but postcss-short I believe is not accounting for the CSS !important flag.

I noticed this with font-size.

For example:

p {
  font-size: inherit !important;
}

Results in:

p {
  font-size: inherit;

I'm not sure if other properties have the same issue, I can check when I get a chance.

Stripping "auto"

Hey Jonathan,

I'm having trouble at the moment using postcss-short as it seems to strip "auto" from values.

Using node v0.12.7 and PostCSS 4.1.16

I tried a short test directly via Node to try and rule out conflicts:

css = ".test { margin: 0 auto; }"

postcss(require('postcss-short')).process(css).then(function (result) {

  result.warnings().forEach(function (warn) {
    console.warn(warn.toString());
  });

  console.log(result.css)

});

This outputs:

.test { margin: 0; }

Has anyone else experienced this?

Thanks!

Config to indicate skipped token

I've been using postcss-position (after having had a @include position() approach, and various @include size(48px) sass mixins for quite some time now to give me this "shorthand" approach.

I used false as my token to indicate to skip the clockwise step. Now you're using *, is there someway I could set a config to use both * and false as I slowly phase out the false, so I can find-replace the @include X? Or just write some funky regex to replace the falses after the @include X, if there aren't enough consensus for this mod?

(I'd also be happy to make the mod as PR, if you're tight for time)

Love the module mate, elegantly executed, clean API and modular!

Feature request: `max-size`

Can I request the ability to use the following:

Input:

.test {
     max-size: 10px 50px;
}

Output:

.test {
     max-width: 10px;
     max-height: 50px
}

Thank you and great work!

"*" properties do not work

When I write something like this:

div {
  margin: * auto;
}

Nothing happens. Everything else works fine.

/ is the worst thing ever, please stop

In JSX and CSS in JS, and CSS in Dart, I use math function and computations inside CSS

Mixing the new '/' syntax with math expressions is horrid.

Some thoughtless people are trying to ruin CSS by making 10.0 / 2 have a bizarre new contextual meaning that does not mix in with the functional syntax, or the language syntax, or with any of the design of any of the languages we work with, or with any math expressions or calculations. It will be the source of annoyance and errors forever, like the original JS bugs of the 1990's

It's really thoughtless and lacking insight.

postcss-short-font-size dependency update

Hello and thank you for your great work. I'm wondering if you are going to update postcss-short-font-size dependency to v2. I believe that second version has better syntax and it will be great to use it with postcss-short pack

Add border-radius

border-radius-left, border-radius-right, border-radius-top, border-radius-bottom

Example for border-radius-top:

/** before */
.class {
  border-radius-top: 2px;
}

/** after */
.class {
  border-top-left-radius: 2px;
  border-top-right-radius: 2px;
}

@jonathantneal

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.