Skip to content

Can we have this new addition in less or do we already have such things... #1679

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

Closed
mohammedzamakhan opened this issue Nov 26, 2013 · 1 comment

Comments

@mohammedzamakhan
Copy link

Addition to LessJS
Lets use $buttons as an example. Its primarily $modules
$buttons{
#btn
}
.btn{
}
$button-sml{
}
$button-med{
}
$button-lar{
}
}
How it all works!?
When ever it finds "$buttons{}" block in the code, it ignores the whole block, if it is not explicitly called.
if we import $buttons, we can use any syntax to import for example:
module $buttons;
It gets all the content of the block as well as the sub block contents. In our example code, #btn,.btn as well as sub-modules $button-sml, $button-med, $button-lar.
if we import sub module in our code, like:
module $buttons.$button-sml;
It gets al the content of the block i.e. #btn, .btn and also only $buttons.$button-sml block content

@seven-phases-max
Copy link
Member

Please use backticks to format your code.
If I understand it right this feature already exists in LESS: "parametric namespace" (which essentially is just a parametric mixin containing another mixins), for example:


// define "module":

#buttons() {
    #btn {
        /* ... */
    }

    .btn {
        /* ... */
    }

    .pin() {
        color: red;
    }

    .button-sml() {
        // ...
    }

    .button-med() {
        // ...
    }

    .button-lar() {
        #tab {
            value: boo;
        }
    }
}

// ................
// usage:

#buttons(); // import "module", a.k.a "using namespace"

div {
    .pin;
}

span {
    // import "submodule", note that it does not include parent namespace "contents":
    #buttons.button-lar(); 
}

#tab {
    // import "submodule" including its parent "contents":
    #buttons;.button-lar(); 
}

Basically, a combination of parametric and non-parametric mixins, their nesting and expand/unlock order can be used to create virtually any "namespace/module" system one can imagine (see also this Q&A).
There're a few (relatively minor) issues with "parametric namespaces" though: #996, #1316, #1525.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants