Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position mixin accepts upto 4 arguments and supports 'auto' & 'inherit' values #221

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 59 additions & 4 deletions lib/nib/positions.styl
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
// helper

-type(prop)

type = 'ident'
types = 'auto' 'inherit'

if prop is a 'unit'
type = 'unit'

if prop in types
type = 'unit'

return type

-keys(props)

props = arguments if length(arguments) > 1
keys = ()

for prop in props
if -type(prop) is 'ident'
push(keys, prop)

return keys

-vals(props)

props = arguments if length(arguments) > 1
vals = ()
length = length(props)

for prop, i in props

type = -type(prop)

if type is 'unit'
push(vals, prop)
else
if previous is defined
unless -type(previous) is 'unit'
push(vals,0)

if (i+1) == length
push(vals,0)

previous = prop

return vals

-pos(type, args)
i = 0

keys = -keys(args)
vals = -vals(args)

position: unquote(type)
{args[i]}: args[i + 1] is a 'unit' ? args[i += 1] : 0
{args[i += 1]}: args[i + 1] is a 'unit' ? args[i += 1] : 0

for key, i in keys
{key}: vals[i];


/*
* Position utility.
Expand All @@ -19,7 +72,9 @@
* fixed: top 5px left
* fixed: top left 5px
* fixed: top 5px left 5px
*
* fixed: top 5px left 5px right auto
* fixed: top 5px left 5px right auto bottom inherit
*
*/

fixed()
Expand Down
59 changes: 59 additions & 0 deletions test/cases/positions.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#fixed-0 {
position: fixed;
bottom: 0;
right: 0;
}
#fixed-1 {
position: fixed;
top: 5px;
left: auto;
}
#fixed-2 {
position: fixed;
bottom: 0;
left: 10px;
}
#fixed-3 {
position: fixed;
bottom: 10px;
right: 0;
}
#fixed-4 {
position: fixed;
bottom: 0;
right: 0;
left: 0;
}
#fixed-5 {
position: fixed;
bottom: 0;
right: 5px;
left: 5px;
}
#fixed-6 {
position: fixed;
bottom: 10px;
right: 5px;
left: 5px;
}
#fixed-7 {
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
#fixed-8 {
position: fixed;
top: 0;
bottom: auto;
right: 0;
left: 5px;
}
#fixed-9 {
position: fixed;
top: auto;
bottom: 10px;
right: inherit;
left: 5px;
}
32 changes: 32 additions & 0 deletions test/cases/positions.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

@import 'nib/positions'

#fixed-0
fixed: bottom right

#fixed-1
fixed: top 5px left auto

#fixed-2
fixed: bottom left 10px

#fixed-3
fixed: bottom 10px right

#fixed-4
fixed: bottom right left

#fixed-5
fixed: bottom right 5px left 5px

#fixed-6
fixed: bottom 10px right 5px left 5px

#fixed-7
fixed: top bottom right left

#fixed-8
fixed: top bottom auto right left 5px

#fixed-9
fixed: top auto bottom 10px right inherit left 5px
4 changes: 2 additions & 2 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ describe('integration', function(){
if (err) throw err;
actual.trim().should.equal(css);
});
})
});
});
})
});