Permalink
Browse files

Refactored size and triangle addons to removed duplicated code.

  • Loading branch information...
Phil LaPier
Phil LaPier committed Dec 20, 2012
1 parent 971fb22 commit b3f55d9965522c4ac88378d231672f912b985736
@@ -38,7 +38,6 @@
@import "addons/clearfix";
@import "addons/font-family";
@import "addons/hide-text";
-@import "addons/hidpi-media-query";
@import "addons/html5-input-types";
@import "addons/position";
@import "addons/prefixer";
@@ -1,15 +1,44 @@
-@mixin size($width, $height) {
-
- @if $width == auto {
- width: $width;
- }
- @else if not(unitless($width)) {
- width: $width;
- }
- @if $height == auto {
- height: $height;
- }
- @else if not(unitless($height)) {
- height: $height;
- }
-}
+@mixin size($size) {
+ @if length($size) == 1 {
+ @if $size == auto {
+ width: $size;
+ height: $size;
+ }
+
+ @else if unitless($size) {
+ width: $size + px;
+ height: $size + px;
+ }
+
+ @else if not(unitless($size)) {
+ width: $size;
+ height: $size;
+ }
+ }
+
+ // Width x Height
+ @if length($size) == 2 {
+ $width: nth($size, 1);
+ $height: nth($size, 2);
+
+ @if $width == auto {
+ width: $width;
+ }
+ @else if not(unitless($width)) {
+ width: $width;
+ }
+ @else if unitless($width) {
+ width: $width + px;
+ }
+
+ @if $height == auto {
+ height: $height;
+ }
+ @else if not(unitless($height)) {
+ height: $height;
+ }
+ @else if unitless($height) {
+ height: $height + px;
+ }
+ }
+}
@@ -1,34 +1,45 @@
-@mixin triangle ($width, $color, $direction) {
- width: 0;
- height: 0;
-
- @if $direction == up {
- border-width: $width / 2;
- border-style: solid;
- border-color: transparent transparent $color transparent;
- } @else if $direction == right {
- border-width: $width / 2;
- border-style: solid;
- border-color: transparent transparent transparent $color;
- } @else if $direction == down {
- border-width: $width / 2;
- border-style: solid;
- border-color: $color transparent transparent transparent;
- } @else if $direction == left {
- border-width: $width / 2;
- border-style: solid;
- border-color: transparent $color transparent transparent;
- } @else if $direction == upright {
- border-top: $width solid $color;
- border-left: $width solid transparent ;
- } @else if $direction == upleft {
- border-top: $width solid $color;
- border-right: $width solid transparent ;
- } @else if $direction == downright {
- border-bottom: $width solid $color;
- border-left: $width solid transparent ;
- } @else if $direction == downleft {
- border-bottom: $width solid $color;
- border-right: $width solid transparent ;
- }
-}
+@mixin triangle ($size, $color, $direction) {
+ height: 0;
+ width: 0;
+
+ @if ($direction == up) or ($direction == down) or ($direction == right) or ($direction == left) {
+ border-color: transparent;
+ border-style: solid;
+ border-width: $size / 2;
+
+ @if $direction == up {
+ border-bottom-color: $color;
+
+ } @else if $direction == right {
+ border-left-color: $color;
+
+ } @else if $direction == down {
+ border-top-color: $color;
+
+ } @else if $direction == left {
+ border-right-color: $color;
+ }
+ }
+
+ @else if ($direction == up-right) or ($direction == up-left) {
+ border-top: $size solid $color;
+
+ @if $direction == up-right {
+ border-left: $size solid transparent;
+
+ } @else if $direction == up-left {
+ border-right: $size solid transparent;
+ }
+ }
+
+ @else if ($direction == down-right) or ($direction == down-left) {
+ border-bottom: $size solid $color;
+
+ @if $direction == down-right {
+ border-left: $size solid transparent;
+
+ } @else if $direction == down-left {
+ border-right: $size solid transparent;
+ }
+ }
+}

0 comments on commit b3f55d9

Please sign in to comment.