Last active
August 29, 2015 14:06
-
-
Save platdesign/2d2bea77fbf29a429a46 to your computer and use it in GitHub Desktop.
SCSS-Mixins for creating "Attribute Modules for CSS"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Defines the global prefix for amcss-modules | |
* @type {String} | |
* @default 'am' | |
*/ | |
$am-prefix: 'am' !default; | |
/** | |
* Helper to store the name of an active module | |
* @type {String} | |
* @default: '' | |
*/ | |
$am-activeModule:''; | |
/** | |
* @type function | |
* @description Helper that returns the prefixed <moduleName>. | |
* @author platdesign <mail@platdesign.de> | |
* | |
* | |
* @param moduleName | |
* @returns | |
* <am-prefix>-<moduleName> | |
* | |
* @example | |
* $moduleName: am-moduleName('btn') | |
* | |
*/ | |
@function am-moduleName($moduleName) { | |
@return $am-prefix + "-" + $moduleName; | |
} | |
/** | |
* @type mixin | |
* @description Creates an amcss-module with a given name. | |
* @author platdesign <mail@platdesign.de> | |
* | |
* | |
* @param moduleName | |
* @returns | |
* [<moduleName>] { | |
* <content> | |
* } | |
* | |
* @example | |
* @include am-module('btn') { | |
* background: #444; | |
* } | |
*/ | |
@mixin am-module($moduleName) { | |
$am-activeModule: $moduleName !global; | |
[#{am-moduleName($moduleName)}] { | |
@content; | |
} | |
} | |
/** | |
* @type mixin | |
* @description Creates an amcss-module-modifier inside of a am-module with a given name. | |
* @author platdesign <mail@platdesign.de> | |
* | |
* | |
* @param modifierName | |
* @returns | |
* &[<moduleName>~="<modifierName>"] { | |
* <content> | |
* } | |
* | |
* @example | |
* @include am-module('btn') { | |
* background: #444; | |
* | |
* @include am-mod('red') { | |
* background: #aa0000; | |
* } | |
* } | |
*/ | |
@mixin am-mod($modifierName) { | |
&[#{am-moduleName($am-activeModule)}~="#{$modifierName}"] { | |
@content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment