Git Product home page Git Product logo

postcss-grid-kiss's Introduction

grid-kiss: Keep CSS Grids simple, stupid

This is a PostCSS plugin aiming to replace the 24 new properties brought by CSS Grids with a single one that you immediately understand when you see it.

Downloads Version Build Status License Discuss about this project on gitter

Table of contents

Examples

Try the different examples and play with the plugin on the playground. Edit the CSS and HTML on the left and the grid will be updated instantly.

Basic website layout

body {
	grid-kiss:
		"+-------------------------------+      "
		"|           header ↑            | 120px"
		"+-------------------------------+      "
		"                                       "
		"+-- 30% ---+  +--- auto --------+      "
		"| .sidebar |  |       main      | auto "
		"+----------+  +-----------------+      "
		"                                       "
		"+-------------------------------+      "
		"|              ↓                | 60px "
		"|         → footer ←            |      "
		"+-------------------------------+      "
}

is converted to:

body > header {
	grid-area: header;
	align-self: start;
}

body > .sidebar {
	grid-area: sidebar;
}

body > main {
	grid-area: main;
}

body > footer {
	grid-area: footer;
	justify-self: center;
	align-self: end;
}

body {
	display: grid;
	align-content: space-between;
	grid-template-rows: 120px 1fr 60px;
	grid-template-columns: 30% 1fr;
	grid-template-areas:
		"header  header"
		"sidebar main  "
		"footer  footer";
}

which displays this kind of grid layout:

example-result

Responsive layouts

Use different grid-kiss declarations in media queries to easily get responsive layouts. It is recommended to start by the grid on small screens, then use media queries to progressively enhance your layouts on wider screens.

responsive-layout

Installation

npm install postcss-grid-kiss --save-dev
yarn add postcss-grid-kiss --dev

Usage

If you never used PostCSS before, read PostCSS usage documentation first.

  • with command line interface :
postcss src/your.css --output dist/compiled.css --use postcss-grid-kiss
  • with Node:
const postcss  = require('postcss'),
      gridkiss = require('postcss-grid-kiss');

postcss([ gridkiss ])
    .process(css, { from: 'src/your.css', to: 'compiled.css' })
    .then(function (result) {
        fs.writeFileSync('compiled.css', result.css);
        if( result.map ) fs.writeFileSync('compiled.css.map', result.map);
    });

Read PostCSS documentation to make it work with Webpack, Gulp or your other build system.

Fallback for older browsers

CSS Grid Layout is a W3C Candidate Recommandation supported in all the evergreen browsers. It is available in Chrome 57, Firefox 52, Safari 10.1, Edge 16 and Opera 44. It is also supported on mobile iOS Safari and Chrome for Android. See Can I Use for more information on browser support.

For browsers not supporting CSS Grid Layout, Grid-kiss proposes a fallback that use absolute positionning and calc() operator. It uses a @supports query to only apply on non-supported browsers, and does not involve JavaScript.

With this fallback, Grid-kiss layouts will work on any browser supporting calc(), which is like 95% of browsers. But you should note that a fallback based on absolute positionning has some limitations:

  • It is only a fallback for grid-kiss declarations. The reason this fallback works is because of the constraints designed by purpose for grid-kiss layouts. Other Grid Layout properties such as grid-gap are not covered by this fallback.
  • New dimensions properties defined in the Grid layout specification such as min-content, max-content, minmax(), fit-content also are not supported
  • Zones with position: absolute are out of the flow. This implies that the container will no longer resize based on the zones content. Grid-kiss tries to calculate the total size of the grid when possible. If one of the rows/columns dimensions is auto or a fraction of the remaining space (fr), the height/width is set to 100%.
  • Grid-kiss adds the property box-sizing: border-box to each zone so that they don't overlap because of their padding or border size. If you don't already use this property, it may change a bit the zones dimensions.
  • The CSS output is significally bigger, between 2x and 3x in size depending on the targeted browsers

Internet Explorer does not support @supports 🙄 , so Grid-kiss needs to add another media query hack that is known to run only on IE: @media screen and (min-width:0\0). This extends support from IE9 to IE11 at the cost of a bigger output size. If you don't care about Internet Explorer support and want to reduce the output size, you should omit IE in your browserslist.

By default, Grid-kiss is looking in your browserslist config for the list of supported browsers and automatically deduce what fallbacks are needed for your project by using Can I Use data. You can override this automatic detection with the fallback option explained below.

Options

Grid-kiss comes with a few options:

postcss([ gridkiss({ ...options }) ])

fallback : add fallback for browsers not supporting CSS Grid Layout

Note: it is recommended to use automatic detection through browserslist instead of using this option. See Fallback section.

If this option is provided, it overrides automatic detection and tells explicitely whether to add or not the fallback styles to the output.

postcss([ gridkiss({ fallback: true }) ]) // always add all fallbacks
postcss([ gridkiss({ fallback: false }) ]) // never add any fallback

optimize - reduce output size

This option (enabled by default) reduces the size of the output while keeping it readable. It does so by merging grid properties and renaming zone identifiers. For complete minification, use it with cssnano.

Set this option to false if you prefer a more verbose and descriptive output. Try to toggle the option in the playground to compare the outputs.

postcss([ gridkiss({ optimize: false }) ])

selectorParser - apply custom transforms to zone selectors

This option receives a function that is applied on the selectors you wrote in the zones. This is useful to add your own transforms or selector syntax, for example to use component names in a component-based framework like Vue or React.

postcss([
  gridkiss({
    selectorParser: function (selector) {
      if (/[A-Z]/.test(selector[0])) {
        return `[data-component-name='${selector}']`
      }
      return selector
    }
  })
])

Alternative styles

These alternative styles for zone syntax are also supported :

  • ┌ ┐ └ ┘ for corners and │ ─ for segments
div {
	grid-kiss:
	"┌──────┐  ┌──────┐         "
	"│      │  │  ↑   │         "
	"│      │  │ bar →│  200px  "
	"│  ↓   │  └──────┘         "
	"│ baz  │              -    "
	"│  ↑   │  ┌──────┐         "
	"│      │  │  ↑   │  200px  "
	"└──────┘  │      │         "
	"          │ foo  │    -    "
	"┌──────┐  │      │         "
	"│ qux  │  │  ↓   │  200px  "
	"│  ↓   │  │      │         "
	"└─20em─┘  └──────┘         "
}
  • ╔ ╗ ╚ ╝ for corners and ║ ═ for segments
main {
	grid-kiss:
	"╔═══════╗  ╔════════════════╗      "
	"║       ║  ║    .article    ║ auto "
	"║   ↑   ║  ╚════════════════╝      "
	"║  nav  ║  ╔════╗  ╔════════╗      "
	"║       ║  ║    ║  ║ aside →║ 240px"
	"╚═ 25% ═╝  ╚════╝  ╚═ 80em ═╝      "
}

Documentation

How to draw a grid

  • Draw the different zones of your grid as shown in the example. You can use some tools like AsciiFlow.
  • Inside every zone, write a selector that matches the corresponding element. See Values accepted for selectors
  • The elements matched have to be direct descendants of the grid element
  • Separate each row by a newline (\n) and give the same indentation level to every row
  • Make sure each row starts and end by a double quote "
  • Make sure the zone corners (+) are correctly aligned. Every index in the rows where a corner character is found creates a new column.
  • Do not hesitate to make large zones with unused space, it may be useful for future modifications
  • Use Insert. key and Multi-cursor if supported by your editor to draw and edit your grids easily

Values accepted for selectors

Inside each zone, you can write a selector to associate a zone to a DOM element. It can be a tag name, a .class, an #id, or any.other[valid]#selector.

Since v1.2.0, selectors in zones may use some shortened notations specific to grid-kiss, although using a class is still the recommended method.

  • :1*:nth-child(1)
  • button:2button:nth-of-type(2)

Since v1.4.0, you can also apply custom transforms and make your own syntax with the selectorParser option

Dimensions of rows

Declare the size of a row by writing the dimension just after the last column of the grid

+------+  +------+ ---
|  ^   |  | .bar | 40em
|      |  +------+ ---
| .baz |
|      |  +------+ ---
|  v   |  |  ^   | 38em
+------+  |      | ---
          | .foo |
+------+  |      | ---
| .qux |  |  v   | 40em
+------+  +------+ ---

The - separators between dimensions are not mandatory, they are only here to make the grid more readable.

Dimensions of columns

Declare the size of a column by writing the dimension inside the top or bottom border of a zone:

+-- 640px --+      +----------+
|  selector |  or  | selector |
+-----------+      +---30%----+

You cannot set the width of a zone occupying more than one column. This would imply some calculations that may or may not have a solution. As an alternative, you can declare the size of a column just after the last row of the grid:

+-------------+ +-----+        +-------------+ +-20%-+
|  .bigzone   | |     |        |  .bigzone   | |     |
+-------------+ +-----+        +-------------+ +-----+
+-----+ +-------------+   or   +-----+ +-------------+
|     | |  .bigzone2  |        |     | |  .bigzone2  |
+-----+ +-------------+        +-20%-+ +-------------+
| 20% | | 60% | | 20% |                | 60% |

The | separators between dimensions are not mandatory, they are only here to make the grid more readable.

Dimensions of gaps

You can also declare the dimension of spacing between zones the same way you do with rows and columns. These spaces are called gaps and act like empty zones. The example below defines gaps of 50px.

+-----+      +-----+      +-----+  ----
| .nw |      | .n  |      | .ne | 100px
+-----+      +-----+      +-----+  ----
                                   50px
+-----+      +-----+      +-----+  ----
| .w  |      |     |      | .e  | 100px
+-----+      +-----+      +-----+  ----
                                   50px
+-----+      +-----+      +-----+  ----
| .sw |      | .s  |      | .se | 100px
+-----+      +-----+      +-----+  ----
|100px| 50px |100px| 50px |100px|

Values accepted for dimensions

Dimensions can be any of the specified values:

  • a non-negative length.

    • 15px
    • 4rem
  • a non-negative percentage value, optionally with a context keyword

    • 20%
    • 25% free25fr
    • 30% grid30%
    • 5% view5vw or 5vh depending on the direction
  • a non-negative number representing a fraction of the free space in the grid container.

    • 55fr
  • max or max-content: a keyword representing the largest maximal content contribution of the grid items occupying the grid track

  • min or min-content: a keyword representing the largest minimal content contribution of the grid items occupying the grid track

  • a range between a minimum and a maximum or minmax(min, max)

    • 100px - 200pxminmax(100px, 200px)
  • > *length* or < *length*: a minimum or maximum value

    • > 100pxminmax(100px, auto)
    • < 50%minmax(auto, 50%)
  • fit *length* or fit-content(*length*): a keyword representing the formula min(max-content, max(auto, length)), which is calculated similar to auto (i.e. minmax(auto, max-content)), except that the track size is clamped at argument length if it is greater than the auto minimum.

    • fit 100pxfit-content(100px)
  • calc( expr ) : an expression using native calc() CSS function

  • var(--name) : a CSS variable interpolation

  • auto: a keyword representing one part of the remaining free space, i.e. 1fr. When used as a maximum value, it is equal to max-content. When used as a minimum value, it it is equal to min-content.

When no value is specified, row and column sizes are set as auto.

Since v2.5.0, you can also apply custom transforms and make your own syntax with the dimensionParser option

Horizontal alignment of the grid

Specifies how all the zones are aligned horizontally inside the grid container. Irrelevant if one of the zones fits all the remaining free space.

  • justify-content: stretch when there are no two consecutive spaces at the beginning or the end of the rows
"+---+ +---+ +---+"
"| a | | b | | c |"
"+---+ +---+ +---+"
"+---+ +---+ +---+"
"| d | | e | | f |"
"+---+ +---+ +---+"
"+---+ +---+ +---+"
"| g | | h | | i |"
"+---+ +---+ +---+"

grid-justify-content-stretch

  • justify-content: start when there are two consecutive spaces or more at the end of the rows
"+---+ +---+ +---+    "
"| a | | b | | c |    "
"+---+ +---+ +---+    "
"+---+ +---+ +---+    "
"| d | | e | | f |    "
"+---+ +---+ +---+    "
"+---+ +---+ +---+    "
"| g | | h | | i |    "
"+---+ +---+ +---+    "

grid-justify-content-start

  • justify-content: end

when there are two consecutive spaces or more at the beginning of the rows

"    +---+ +---+ +---+"
"    | a | | b | | c |"
"    +---+ +---+ +---+"
"    +---+ +---+ +---+"
"    | d | | e | | f |"
"    +---+ +---+ +---+"
"    +---+ +---+ +---+"
"    | g | | h | | i |"
"    +---+ +---+ +---+"

grid-justify-content-end

  • justify-content: center when there are two consecutive spaces or more at the beginning and the end of the rows
"    +---+ +---+ +---+    "
"    | a | | b | | c |    "
"    +---+ +---+ +---+    "
"    +---+ +---+ +---+    "
"    | d | | e | | f |    "
"    +---+ +---+ +---+    "
"    +---+ +---+ +---+    "
"    | g | | h | | i |    "
"    +---+ +---+ +---+    "

grid-justify-content-center

  • justify-content: space-between when there are two consecutive spaces or more between zones
"+---+    +---+    +---+"
"| a |    | b |    | c |"
"+---+    +---+    +---+"
"+---+    +---+    +---+"
"| d |    | e |    | f |"
"+---+    +---+    +---+"
"+---+    +---+    +---+"
"| g |    | h |    | i |"
"+---+    +---+    +---+"

grid-justify-content-space-between

  • justify-content: space-evenly when there are two consecutive spaces or more at the beginning and the end of the rows, and exactly two consecutive spaces between zones
"    +---+  +---+  +---+    "
"    | a |  | b |  | c |    "
"    +---+  +---+  +---+    "
"    +---+  +---+  +---+    "
"    | d |  | e |  | f |    "
"    +---+  +---+  +---+    "
"    +---+  +---+  +---+    "
"    | g |  | h |  | i |    "
"    +---+  +---+  +---+    "

grid-justify-content-space-evenly

  • justify-content: space-around when there are two consecutive spaces or more at the beginning and the end of the rows, and four consecutive spaces or more between zones
"  +---+    +---+    +---+  "
"  | a |    | b |    | c |  "
"  +---+    +---+    +---+  "
"  +---+    +---+    +---+  "
"  | d |    | e |    | f |  "
"  +---+    +---+    +---+  "
"  +---+    +---+    +---+  "
"  | g |    | h |    | i |  "
"  +---+    +---+    +---+  "

grid-justify-content-space-around

Vertical alignment of the grid

Specifies how all the zones are aligned vertically inside the grid container. Irrelevant if one of the zones fits all the remaining free space.

  • align content: stretch when no space rows
"+---+ +---+ +---+"
"| a | | b | | c |"
"+---+ +---+ +---+"
"+---+ +---+ +---+"
"| d | | e | | f |"
"+---+ +---+ +---+"
"+---+ +---+ +---+"
"| g | | h | | i |"
"+---+ +---+ +---+"

grid-align-content-stretch

  • align-content: start when at least one space row at the end
"+---+ +---+ +---+"
"| a | | b | | c |"
"+---+ +---+ +---+"
"+---+ +---+ +---+"
"| d | | e | | f |"
"+---+ +---+ +---+"
"+---+ +---+ +---+"
"| g | | h | | i |"
"+---+ +---+ +---+"
"                 "
"                 "

grid-align-content-start

  • align-content: end when at least one space row at the beginning
"                 "
"                 "
"+---+ +---+ +---+"
"| a | | b | | c |"
"+---+ +---+ +---+"
"+---+ +---+ +---+"
"| d | | e | | f |"
"+---+ +---+ +---+"
"+---+ +---+ +---+"
"| g | | h | | i |"
"+---+ +---+ +---+"

grid-align-content-end

  • align-content: center when at least one space row at the beginning and one space row at the end
"                 "
"+---+ +---+ +---+"
"| a | | b | | c |"
"+---+ +---+ +---+"
"+---+ +---+ +---+"
"| d | | e | | f |"
"+---+ +---+ +---+"
"+---+ +---+ +---+"
"| g | | h | | i |"
"+---+ +---+ +---+"
"                 "

grid-align-content-center

  • align-content: space-between when there is one space row between zones
"+---+ +---+ +---+"
"| a | | b | | c |"
"+---+ +---+ +---+"
"                 "
"+---+ +---+ +---+"
"| d | | e | | f |"
"+---+ +---+ +---+"
"                 "
"+---+ +---+ +---+"
"| g | | h | | i |"
"+---+ +---+ +---+"

grid-align-content-space-between

  • align-content: space-evenly when there is one space row at the beginning, at the end and between zones
"                 "
"+---+ +---+ +---+"
"| a | | b | | c |"
"+---+ +---+ +---+"
"                 "
"+---+ +---+ +---+"
"| d | | e | | f |"
"+---+ +---+ +---+"
"                 "
"+---+ +---+ +---+"
"| g | | h | | i |"
"+---+ +---+ +---+"
"                 "

grid-align-content-space-evenly

  • align-content: space-around when there is one space row at the beginning and at the end, and two space rows between zones
"                 "
"+---+ +---+ +---+"
"| a | | b | | c |"
"+---+ +---+ +---+"
"                 "
"                 "
"+---+ +---+ +---+"
"| d | | e | | f |"
"+---+ +---+ +---+"
"                 "
"                 "
"+---+ +---+ +---+"
"| g | | h | | i |"
"+---+ +---+ +---+"
"                 "

grid-align-content-space-around

Horizontal alignment inside a zone

Each zone can specify an alignment indicator. When no indicators are specified, defaults are stretch horizontally and vertically.

  • justify-self: start with < or
+-------------+    +-------------+
| .item-a  <  | or | .item-a  ←  |
+-------------+    +-------------+

grid-justify-self-start

  • justify-self: end with > or
+-------------+    +-------------+
|  >  .item-a | or |  →  .item-a |
+-------------+    +-------------+

grid-justify-self-end

  • justify-self: stretch with < and > or and in this order
+--------------+    +--------------+
| < .item-a  > | or | ← .item-a  → |
+--------------+    +--------------+

grid-justify-self-stretch

  • justify-self: center with > and < or and in this order
+--------------+    +--------------+
| > .item-a  < | or | → .item-a  ← |
+--------------+    +--------------+

grid-justify-self-center

Vertical alignment inside a zone

  • align-self: start with ^ or
+-------------+    +-------------+
|   .item-a   | or |   .item-a   |
|      ^      |    |      ↑      |
+-------------+    +-------------+

grid-align-self-start

  • align-self: end with v or
+-------------+    +-------------+
|      v      | or |      ↓      |
|   .item-a   |    |   .item-a   |
+-------------+    +-------------+

grid-align-self-end

  • align-self: stretch with ^ and v or and in this order
+-------------+    +-------------+
|      ^      |    |      ↑      |
|   .item-a   | or |   .item-a   |
|      v      |    |      ↓      |
+-------------+    +-------------+

grid-align-self-stretch

  • align-self: center with v and ^ or and in this order
+-------------+    +-------------+
|      v      |    |      ↓      |
|   .item-a   | or |   .item-a   |
|      ^      |    |      ↑      |
+-------------+    +-------------+

grid-align-self-center

New lines and position of alignement characters do not matter. Just make it visually understandable.

Usage with Prettier formatter

People using Prettier code formatter may have issues with the automatic formating of grid-kiss declarations. In that case, write grid-template-kiss instead of grid-kiss. For some reason, Prettier correctly formats the declarations starting with grid-template-***.


Sketchnote


Credits for images : CSS Tricks, @aneveux

postcss-grid-kiss's People

Contributors

dependabot[bot] avatar sylvainpolletvillard avatar

Stargazers

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

Watchers

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

postcss-grid-kiss's Issues

Promotion

I think you wrote really great tool. And a lot of stars show that many people agree with me.

But for my experience, good tools = good code + good marketing :).

We need to promote you :). I think current plan could be:

  1. Reddit post (I could do it tomorrow).
  2. IE support.
  3. CSS Tricks article.

CSS Trick is very open for new ideas. And they have no good tools article for a time. So they could accept. Just write them and ask it (explain why it is important and how people like your project, mention that your already have React port).

CSS Tricks article was a first booster for Autoprefixer promotion :).

I think your project is in very good time for promotion, because many people really want to use Grids. But they need a 3 months for even Chrome support.

You have a pure-CSS fallback and awesome syntax. It you will promote your project in December you could become much more popular. In the end of December will be a dead season, so I highly recommend to post CSS Tricks article in the beginning of December. This could be time sensitive, because right now people thought that “Chrome support will in next year”.

Text recognition is line based instead of string based

My current case is this grid which work perfectly:

grid-kiss:
  "+--------------------------+ --   "
  "| .header                  | 48px "
  "+--------------------------+ --   "
  "+--------+ +---------------+ --   "
  "| .aside | | .main         | auto "
  "+--------+ +---------------+ --   "
  "| 48px   | | auto          |      ";

But my current postcss chain transform it to:

grid-kiss: "+--------------------------+ --   " "| header                   | 48px " "+--------------------------+ --   " "+--------+ +---------------+ --   " "| aside  | | main          | auto " "+--------+ +---------------+ --   " "| 48px   | | auto          |      ";

In fact if we follow how css works, it should works too but here grid-kiss can't parse correctly

Error when rows are delimited by single quotes

That line excludes the usage of single-quotes:

return str.match(/".*"/g).map(row => row.slice(1, row.length - 1));

Thus the following does not work:

body {
	grid-kiss:
		'+-------------------------------+      '
		'|           header ↑            | 120px'
		'+-------------------------------+      '
		'                                       '
		'+-- 30% ---+  +--- auto --------+      '
		'| .sidebar |  |       main      | auto '
		'+----------+  +-----------------+      '
		'                                       '
		'+-------------------------------+      '
		'|              ↓                | 60px '
		'|         → footer ←            |      '
		'+-------------------------------+      '
}

Using the node.js v4 can not run postcss-grid-kiss

@sylvainpolletvillard

This plugin is very good. I tried to use today, found a small problem.The use of simple to describe my situation.

node.js version

v4.7.2

gulpfile.js config

var gulp = require('gulp');
var postcss = require('gulp-postcss');
var cssnext = require('postcss-cssnext');
var gridkiss = require('postcss-grid-kiss');

var browserOptions = {
  browsers: [
  'last 3 versions',
  'ie >= 10',
  'ie_mob >= 10',
  'ff >= 30',
  'chrome >= 34',
  'safari >= 6',
  'opera >= 12.1',
  'ios >= 6',
  'android >= 4.4',
  'bb >= 10',
  ]
};

gulp.task('css', function(){
	var processors = [
		cssnext(browserOptions),
		gridkiss({fallback: true})
	];

	return gulp.src('./src/*.css')
		.pipe(postcss(processors))
		.pipe(gulp.dest('./dest'));
});

gulp.task('html', function (){
  	return gulp.src('./src/*.html')
    	.pipe(gulp.dest('./dest'));
});

gulp.task('watch', function (){
  	gulp.watch('./src/*.html', ['html']);
  	gulp.watch('./src/*.css', ['css']);
});

gulp.task('default', ['watch']);

run gulp in terminal, There will be an error message:

/Applications/XAMPP/xamppfiles/htdocs/workshop/postGrid/node_modules/postcss-grid-kiss/src/main.js:3
const {parse}             = require("./parse");
      ^

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> (/Applications/XAMPP/xamppfiles/htdocs/workshop/postGrid/node_modules/postcss-grid-kiss/index.js:3:12)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

Then I have updated the version of the node.js (v6.9.4). post-grid-kiss can run normally.

I want to say is that there are a lot of people use node 4. So many people can't use this plugin.Would you consider to repair this problem.

Animations

Absolutly loved your project. I use react-spring for animations. I was wondering can I compile at runtime or come up with some trick so the animations will work even with the fallback code?

Any thoughts on this?

PS: Love your OCR idea, myself worked in computer vision for 3yrs; I think if we use machine learning we can go step futher to read the titles as well :)

Thx

Support native CSS custom properties/variables directly for dimensions

Currently, you can input something like:

"+-----------------------------+"
"|                             |"
"+-----------------------------+"
"| calc(var(--my-cool-length)) |"

to get CSS properties to work. This is pretty clumsy, and verbose, but it does work just fine.

Which probably means a syntax like:

"+-----------------------+"
"|                       |"
"+-----------------------+"
"| var(--my-cool-length) |"

// or:
"+---------------------+"
"|                     |"
"+---------------------+"
"| v(--my-cool-length) |"

// my favorite:
"+-------------------+"
"|                   |"
"+-------------------+"
"| v(my-cool-length) |"

should technically work without any issues. I did take a look at the dimension parser and it looks like basically a copy paste of the calc regex. It would probably be fine to enforce one var input pattern. This would be nice feature to have!

There is the matter of Sass, Less, and other non-persistent variables (which are using @ and '$', usually). I also figure these wouldn't be too difficult to add.

One thing you could potentially do to avoid all these issues is to simply allow an escaped dimension, maybe like:

"+----------------+"
"|                |"
"+----------------+"
"| /$cool-length/ |"

// or:
"+----------------+"
"|                |"
"+----------------+"
"| ($cool-length) |"

// or, perhaps resembling 'interpolation' the most:
"+----------------+"
"|                |"
"+----------------+"
"| {$cool-length} |"

That way, custom functions, variables, etc. would be easily supported.

Option to change grid-kiss property

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

I added a property option that permit to change the default "grid-kiss" with "grid-template-kiss" which is more compliant with prettier

Here is the diff that solved my problem:

diff --git a/node_modules/postcss-grid-kiss/lib/main.js b/node_modules/postcss-grid-kiss/lib/main.js
index cf45395..1bc08ac 100644
--- a/node_modules/postcss-grid-kiss/lib/main.js
+++ b/node_modules/postcss-grid-kiss/lib/main.js
@@ -13,6 +13,7 @@ const
 	getFallback = require("./fallback");
 
 const DEFAULTS_OPTIONS = {
+	property: "grid-kiss",
 	optimize: true
 }
 
@@ -30,7 +31,7 @@ module.exports = function (options) {
 	return {
 		postcssPlugin: 'postcss-grid-kiss',
 		Declaration: {
-			"grid-kiss": (decl, { result, Rule, AtRule }) => {
+			[options.property]: (decl, { result, Rule, AtRule }) => {
 				const
 					{ rows, cols, zones, rowIndexes, colIndexes } = parse(decl, options),
 					grid = { props: new Map, rule: decl.parent },

This issue body was partially generated by patch-package.

Autoprefixer for IE 10-11 support

Let’ remove old hacks and use Autoprefixer Grid for IE 10-11 support. New Autoprefixer with grid: true supports even grid-gap and grid-template-area.

Add to PostCSS plugins list

Great work. I was really impressed by this idea.

Feel free to send PR to postcss/postcss with your plugin in docs/plugins.md.

How to use min/min-content? Suggest: add example

Add examples for this options:

  • max or max-content: a keyword representing the largest maximal content contribution of the grid items occupying the grid track

  • min or min-content: a keyword representing the largest minimal content contribution of the grid items occupying the grid track

When I use "min" keyword, I have an error:

grid-kiss:
"+-------------------------------+      "
"|              ↓                |      "
"|         → header ←            | 60px "
"|              ↑                |      "
"+-------------------------------+      "
"+-- 30% ---+  +--- auto --------+ ---- "
"|     ↑    |  |       ↑         |      "
"| .sidebar |  |       .main     | auto "
"|     ↓    |  |       ↓         |      "
"+----------+  +-----------------+ ---  "
"+-------------------------------+ --- "
"|         ← footer →            | min "
"+-------------------------------+ --- "

Error:

Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js??ref--0-2!node_modules/postcss-loader/lib/index.js!css/main.css:
       [0] ./node_modules/css-loader?{"importLoaders":1}!./node_modules/postcss-loader/lib!./css/main.css 4.58 kB {0} [built] [failed] [1 error]

    ERROR in ./node_modules/css-loader?{"importLoaders":1}!./node_modules/postcss-loader/lib!./css/main.css
    Module build failed: Error: Parse error on line 1:
    100% - 60px - min-content
    --------------^
    Expecting 'SUB', 'LPAREN', 'NESTED_CALC', 'NUMBER', 'CSS_VAR', 'LENGTH', 'ANGLE', 'TIME', 'FREQ', 'RES', 'EMS', 'EXS', 'CHS', 'REMS', 'VHS', 'VWS', 'VMINS', 'VMAXS', 'PERCENTAGE', got 'PREFIX'

Possible to overlap zones?

More a question than an issue, but is it possible to have zones overlap? Love the idea of this, but need to be able to have things overlap. :)

Text recognition

We need to go deeper. I propose to introduce a text recognition nodejs plugin. Imagine how would be cool to put a layout drawn on a napkin.

IE 11 doesn't support nested calcs

I was trying out this plugin as it seemed pretty darn awesome and decided to try out those IE claims myself. The first thing I ran into almost immediately is that kiss generates nested calcs for some of the CSS grid fallbacks. This isn't supported in IE (or really many browsers).

https://sylvainpolletvillard.github.io/grid-kiss-playground/index.html with the justify-* removed, for example, generates top: calc(120px + calc(100% - 120px - 60px)); for the footer div.

Use -ms- grid for IE fallback

Technically, IE was the first browser, which support Grid :). His -ms- syntax is very limited. But I found that many features could be implemented. For example, grid-template-areas is not in -ms-, but it is just syntax sugar — you could use different grip properties to set grid child position.

@sylvainpolletvillard do you think it is possible to fallback your awesome plugin for IE using -ms- gird syntax?

Feature idea: Content alignement based on position of the selector inside a zone

Should we align zone content based on position of the selector inside the zone ?

image

Proposed rules:

  • selector on the first line of at least three : align-self: start
  • selector on the last line of at least three: align-self: end
  • selector with zero spaces left and at least two spaces right : justify-self: start
  • selector with zero spaces right and at least two spaces left: justify-self: end

Advantages

  • follow the same principle than for grid alignement ; less concepts to learn
  • simplify the syntax
  • < > ^ v are weird and ↓ ↑ ← → are hard to get on regular keyboards

Disadvantages

  • how to differentiate align/justify-self: center and stretch ?
  • require larger zones / possible redraws
  • 3 rows are required at least to set vertical content alignement

Feedback needed

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.