Giter Site home page Giter Site logo

postcss-each-variables's Introduction

postcss-each-variables Build Status

PostCSS plugin enabling variable mapping for @each.

Install

npm install --save-dev postcss-each-variables

Usage

postcss([ require('postcss-each-variables') ])

Note: you must include postcss-each-variables before other at-rules plugins.

Before

:root {
	--breakpoints: (
		sm: 576px,
		md: 768px,
		lg: 992px,
		xl: 1200px
	);
}

@each $key, $value in var(--breakpoints) {
	.container-$(key) {
		max-width: $(value);
	}
}

After

:root {
	--breakpoints: (
		sm: 576px,
		md: 768px,
		lg: 992px,
		xl: 1200px
	);
}

@each $key, $value in (sm, md, lg, xl), (576px, 768px, 992px, 1200px) {
	.container-$(key) {
		max-width: $(value);
	}
}

See PostCSS docs for examples for your environment.

postcss-each-variables's People

Contributors

awcross avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

postcss-each-variables's Issues

Doesn't work as expected

mix.js('resources/js/app.js', 'public/js')
   .postCss('resources/css/app.css', 'public/css', [
      require('postcss-import'), 
      require('postcss-svg'),
      require('postcss-mixins'),
      require('postcss-each-variables'),
      require('postcss-extend'),
      require('postcss-nested'),
      require('tailwindcss'),     
      require('autoprefixer'),
    ]);

I have this in input css file

:root {
	--icons: (
		check:				url("../views/components/svg/listicons.svg#check"),
		check-rounded: 		url("../views/components/svg/listicons.svg#check-rounded"),
		check-squared: 		url("../views/components/svg/listicons.svg#check-squared"),
		checklist: 			url("../views/components/svg/listicons.svg#checklist"),
		chevron: 			url("../views/components/svg/listicons.svg#chevron"),
		thumb-up-outline: 	url("../views/components/svg/listicons.svg#thumb-up-outline"),
		thumb-up-solid: 	url("../views/components/svg/listicons.svg#thumb-up-solid"),
		tools: 				url("../views/components/svg/listicons.svg#tools")
	);
}


@each $key, $value in var(--icons) {
	.svg-list-$(key) {
		content: $(value);
	}
}

And I have following output

:root {
  --icons: (
		check:				url(/images/listicons.svg?2a63c466cf4a3dc372356d34ce53757d#check),
		check-rounded: 		url(/images/listicons.svg?2a63c466cf4a3dc372356d34ce53757d#check-rounded),
		check-squared: 		url(/images/listicons.svg?2a63c466cf4a3dc372356d34ce53757d#check-squared),
		checklist: 			url(/images/listicons.svg?2a63c466cf4a3dc372356d34ce53757d#checklist),
		chevron: 			url(/images/listicons.svg?2a63c466cf4a3dc372356d34ce53757d#chevron),
		thumb-up-outline: 	url(/images/listicons.svg?2a63c466cf4a3dc372356d34ce53757d#thumb-up-outline),
		thumb-up-solid: 	url(/images/listicons.svg?2a63c466cf4a3dc372356d34ce53757d#thumb-up-solid),
		tools: 				url(/images/listicons.svg?2a63c466cf4a3dc372356d34ce53757d#tools)
	);
}

@each $key, $value in (check,check-rounded,check-squared,checklist,chevron,thumb-up-outline,thumb-up-solid,tools), (url("../views/components/svg/listicons.svg#check"),url("../views/components/svg/listicons.svg#check-rounded"),url("../views/components/svg/listicons.svg#check-squared"),url("../views/components/svg/listicons.svg#checklist"),url("../views/components/svg/listicons.svg#chevron"),url("../views/components/svg/listicons.svg#thumb-up-outline"),url("../views/components/svg/listicons.svg#thumb-up-solid"),url("../views/components/svg/listicons.svg#tools")) {
  .svg-list-$(key) {
    content: $(value);
  }
}

To me it seems like @each loop didn't launched. I expected to have 8 separate styles on the output from .svg-list-check to .svg-list-tools. What is wrong with my code?

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.