Skip to content

Instantly share code, notes, and snippets.

View lvl99's full-sized avatar

Matt Scheurich lvl99

View GitHub Profile
@lvl99
lvl99 / 10-Example-Modal-composable-mixin-class-(simple).less
Created April 7, 2017 13:57
Object-oriented inspired composable LESS mixins. View the article on the blog: http://blog.lvl99.com
// Modal Mixin Class
// @param @ns Namespaces the custom state classes
.ui-lvl99-modal(@ns: ~"lvl99-modal") {
.ui-lvl99-toggleable(@ns);
.-modal-init-default(@rules: {}) {
.-toggleable-init-default(@rules);
}
}
@lvl99
lvl99 / 09-Composable-mixin-piece-init-default-configuration.less
Created April 7, 2017 13:57
Object-oriented inspired composable LESS mixins. View the article on the blog: http://blog.lvl99.com
// Special mixin to apply any default state styles and rules
.-toggleable-init-default(@rules: {}) {
.-toggleable-state-show();
.-toggleable-state-hide();
@rules();
}
@lvl99
lvl99 / 08-Composable-mixin-piece-nested-mixins-defining-classes-and-states.less
Created April 7, 2017 13:57
Object-oriented inspired composable LESS mixins. View the article on the blog: http://blog.lvl99.com
// 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();
@lvl99
lvl99 / 07-Composable-mixin-piece-variables.less
Created April 7, 2017 13:56
Object-oriented inspired composable LESS mixins. View the article on the blog: http://blog.lvl99.com
// Uses the namespace to build custom state classes
@-toggleable-ns-class-show: ~".ui-@{ns}-show";
@-toggleable-ns-class-hide: ~".ui-@{ns}-hide";
@lvl99
lvl99 / 06-Examples-showing-how-composable-mixins-are-instantiated-and-extended.less
Created April 7, 2017 13:56
Object-oriented inspired composable LESS mixins. View the article on the blog: http://blog.lvl99.com
// Modal component
.modal {
.ui-lvl99-toggleable(@ns: ~“modal”);
.-toggleable-init-default();
}
// ... would generate the following CSS
.modal.ui-modal-show {
display: block;
}
@lvl99
lvl99 / 05-Composable-mixin-piece-declaration.less
Created April 7, 2017 13:56
Object-oriented inspired composable LESS mixins. View the article on the blog: http://blog.lvl99.com
.ui-lvl99-toggleable(@ns: ~"lvl99-toggleable"; @-toggleable-display: ~"block") {
// … magic beans follows ...
}
@lvl99
lvl99 / 04-Example-of-instantiating-Toggleable-mixin.less
Created April 7, 2017 13:55
Object-oriented inspired composable LESS mixins. View the article on the blog: http://blog.lvl99.com
// Import and apply the Toggleable Mixin Class to a specific class
.toggleable {
// Imports the mixin and its related mixins and variables
.ui-lvl99-toggleable(@ns: ~"toggleable");
// Initialise the default since we have no other modifications from the normal
.-toggleable-init-default();
}
// Let's do a parametric modification since spans should be displayed using `inline` or `inline-block`
span.toggleable {
@lvl99
lvl99 / 03-Example-Toggleable-composable-mixin-class.less
Created April 7, 2017 13:55
Object-oriented inspired composable LESS mixins. View the article on the blog: http://blog.lvl99.com
// 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: {}) {
@lvl99
lvl99 / 02-Example-of-HTML-when-declaring-CSS-classes-on-elements.html
Created April 7, 2017 13:55
Object-oriented inspired composable LESS mixins. View the article on the blog: http://blog.lvl99.com
<!-- Modal component HTML structure with modal and toggleable classes applied -->
<!-- This is usually the most basic way to combine multiple classes on an element -->
<div id=”example-a” class=”modal toggleable”>
<!-- … oh la la, magic~~~ … -->
</div>
@lvl99
lvl99 / 01-Example-of-ES6-class-extending.js
Created April 7, 2017 13:54
Object-oriented inspired composable LESS mixins. View the article on the blog: http://blog.lvl99.com
class Modal extends Toggleable {
  // … magic goes here …
}