Skip to content

Commit

Permalink
allow <- -> for horizontal alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainpolletvillard committed Nov 2, 2019
1 parent 5da77e9 commit ebe932e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/justify-self.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function getJustifySelf(zone) {

let leftIndicator = zone.content.search(/[←<]/),
rightIndicator = zone.content.search(/[→>]/);
let leftIndicator = zone.content.search(/←|<-*/),
rightIndicator = zone.content.search(/→|-*>/);

if (leftIndicator >= 0 && rightIndicator > leftIndicator)
return "stretch"
Expand Down
2 changes: 1 addition & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function getZones({ rows, cols, colIndexes, rowIndexes, options }) {

function getZoneSelector(zone, options) {
return options.selectorParser(zone.content
.replace(/[^\w]v[^\w]|[^\w#.:\-[\]()]/g, "")
.replace(/[^\w]v[^\w]|→|-*>|←|<-*|[^\w#.:\-[\]()]/g, "")
.replace(/^:(\d+)$/, "*:nth-child($1)") // :2 => *:nth-child(2)
.replace(/(^[\w-]+):(\d+)$/, "$1:nth-of-type($2)") // button:1 => button:nth-of-type(1)
)
Expand Down
26 changes: 26 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,32 @@ test('grid template areas', async t => {

});

test('zone justify-self', async t => {
let output = await process(
`div {
grid-kiss:
"+-----------+ +------------+ "
"| | | ^ | "
"| | | bar -> | "
"| v | +------------+ "
"| baz <-- | "
"| ^ | +------------+ "
"| | | | "
"+-----------+ | | "
" | → foo ← | "
"+-----------+ | | "
"| < qux > | | | "
"| v | | | "
"+-----------+ +------------+ "
}`);

t.is(output["div > baz"]["justify-self"], "start");
t.is(output["div > bar"]["justify-self"], "end");
t.is(output["div > qux"]["justify-self"], "stretch");
t.is(output["div > foo"]["justify-self"], "center");

});

test('zone align-self', async t => {
let output = await process(
`div {
Expand Down

0 comments on commit ebe932e

Please sign in to comment.