Created
April 7, 2017 13:55
-
-
Save lvl99/11ae72c940eed686252be37a84a832da to your computer and use it in GitHub Desktop.
Object-oriented inspired composable LESS mixins. View the article on the blog: http://blog.lvl99.com
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
// Toggleable Mixin Class | |
// @param @ns Namespaces the custom state classes | |
// @param @-toggleable-display Sets the display property for showing the toggleable | |
.ui-lvl99-toggleable(@ns: ~"lvl99-toggleable"; @-toggleable-display: ~"block") { | |
// Uses the namespace to build custom state classes | |
@-toggleable-ns-class-show: ~".ui-@{ns}-show"; | |
@-toggleable-ns-class-hide: ~".ui-@{ns}-hide"; | |
// Class mixin which contain style definitions for `show` state | |
.-toggleable-class-show(@rules: {}) { | |
display: @-toggleable-display; | |
@rules(); | |
} | |
// Class mixin which contains style definitions for `hide` state | |
.-toggleable-class-hide(@rules: {}) { | |
display: none; | |
@rules(); | |
} | |
// Special mixin to import class definition to the `show` state | |
.-toggleable-state-show(@rules: {}) { | |
&@{-toggleable-ns-class-show} { | |
.-toggleable-class-show(@rules); | |
} | |
} | |
// Special mixin to apply any rules to the `hide` state | |
.-toggleable-state-hide(@rules: {}) { | |
&@{-toggleable-ns-class-hide} { | |
.-toggleable-class-hide(@rules); | |
} | |
} | |
// Special mixin to apply any default state styles and rules | |
.-toggleable-init-default(@rules: {}) { | |
.-toggleable-state-show(); | |
.-toggleable-state-hide(); | |
@rules(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment