mixins

LESS mixin recursion error to convert pixels to rems

余生长醉 提交于 2019-11-28 11:28:24
问题 I am trying to make a mixin to propery convert pixels to relative ems. I would like it to be flexible enough to allow any property to be used with any number of pixel values. Any ideas on how to add multiple values to a single property without the recursion error I'm creating inside the for loop? desired usage example 1: .pixels-to-rems(font-size; 10); desired output: font-size: 10px; font-size: 1rem; desired usage example 2: .pixels-to-rems(padding; 10,0,20,10); desired output: padding: 10px

Less mixin with optional parameters

大憨熊 提交于 2019-11-28 09:41:15
I have a Less mixin defined as: .fontStyle(@family, @size, @weight: normal, @style: normal, @color: #ffffff, @letter-spacing: normal) { font-family: @family; font-size: @size; color: @color; font-weight: @weight; font-style: @style; letter-spacing: @letter-spacing; } How can I define usage like: .fontStyle('NimbusSansNovCon-Reg', 12px, , , , 0.1em); I.E. use the defaults for @weight , @style , @color To supply a parameter that far down the string of arguments, you have to also supply the expected variable it is to define. So this: .fontStyle('NimbusSansNovCon-Reg', 12px, @letter-spacing: 0.1em

Dynamically define a variable in LESS CSS

你离开我真会死。 提交于 2019-11-28 09:14:19
I am trying to create a mixin that dynamically defines variables in LESS CSS, by actually assigning them a composite name. The simplified use-case (not the real one): .define(@var){ @foo{var}: 0; } Then one would call the mixin as such: .define('Bar'){ @fooBar: 0; } Since this kind of string interpolation is possible while using selectors names, I was wondering if the same would be possible for variable names; so far, I have had no luck with various syntaxes I tried (other than the above, I tried escaping, quoting, using the ~ prefix and so on). Edit I just tried one more thing, and I feel I

How to set keyframes name in LESS

半世苍凉 提交于 2019-11-28 08:57:21
I try to set up this LESS mixin for CSS animation keyframes: .keyframes(@name, @from, @to) {; @-webkit-keyframes "@name" { from { @from; } to { @to; } } } but there is some problem with name pharse, is there any option to do this corectly? As of LESS >= 1.7 you can use variables for keyframe keywords (names). Some changes have been made in LESS 1.7 to how directives work, which allows to use variables for the name/keyword of @keyframes (so the example from the question should work now). DEMO Unfortunately keyframes names can not be dynamically generated in LESS <= 1.6 Hence, the normal way of

When does for call the iterator method?

痞子三分冷 提交于 2019-11-28 08:21:16
问题 This question is in the same ballpark as this other on making blocks iterable, but seems to reveal a different problem with mixins (or a different misunderstanding of the syntax on my part). What Iterable does is to make a data structure effectively iterable, that is, you can create loops by preceding it with for . Iterable serves as an API for objects that can be iterated with the for construct and related iteration constructs, like hyper operators. So let's try to put this to practice: my

Getting a list of classes that include a module

僤鯓⒐⒋嵵緔 提交于 2019-11-28 07:01:38
问题 I have a mixin for which I would like to get a list of all the classes that have included it. In the mixin module, I did the following: module MyModule def self.included(base) @classes ||= [] @classes << base.name end def self.classes @classes end end class MyClass include MyModule end This works pretty well: > MyModule.classes #=> nil > MyClass.new #=> #<MyClass ...> > MyModule.classes #=> ["MyClass"] Now, I would like to extract this part out into a separate module that can be included in

What's the difference between mixin() and extend() in Javascript libraries

十年热恋 提交于 2019-11-28 06:56:38
I'm looking through various libraries, and seeing extend() pop up a lot, but I'm also seeing mixin() show up. YUI has both mixins and extensions. What's the difference between these two concepts? When would I decide between a mixin and extending an object? Thanks, Matt Mixins don't work with instanceof but extends do. Mixins allow multiple inheritance but by faking it, not by properly chaining the prototypes. I'll show an Ext-JS example but the concept applies to any class library that provides mixins, they all just copy properties to the object instead of chaining the prototype. Ext.define(

LESS CSS Pass mixin as a parameter to another mixin

青春壹個敷衍的年華 提交于 2019-11-28 05:59:23
Is there any way to pass one mixin or style's declaration to another mixin as an input parameter? Let's take a look at an example with animation keyframes. Following is how we define keyframes in pure CSS: @-moz-keyframes some-name { from { color: red; } to { color: blue; } } @-webkit-keyframes some-name { from { color: red; } to { color: blue; } } @keyframes some-name { from { color: red; } to { color: blue; } } Idea is to simplify these declarations using mixins, so we can have something like following: .keyframes(name, from, to) { // here we need somehow to reproduce structure // that we

Bootstrap 3 mixin multiple make-*-column

旧城冷巷雨未停 提交于 2019-11-28 02:07:04
I'm using an specific mixin trying to make my code more clear. So instead of using: <div class="col-lg-3 col-md-5 col-sm-6 col-xs-12"> I'm using: <div class="stackOverflowRocksIt"> and in my mixins.less: .stackOverflowRocksIt{ .make-lg-column(3); .make-md-column(4); .make-sm-column(6); .make-xs-column(12); } It works properly with XS and SM viewports, but not when I resize to MD or LG (then is taking the SM size). Is this the proper way to create columns for different viewports sizes? Any idea? You should re-order your mixin calls: .stackOverflowRocksIt { .make-xs-column(12); .make-sm-column(6

Compostions and mixins in JS

只谈情不闲聊 提交于 2019-11-28 01:40:38
I got some trouble with compostions and mixin . For examples, lets imagine that we have a AHero and Hero1 object. All heroes can move, so AHero.move() is a thing. And now, at a moment of the dev, I want to add the possibility to stun and beStunned. So I make a new object that look like this ( called stunTrait) : { stunned : false, stun(), beStun, } And I decide to give to possiblity to heroes to stun and beStunned. So I do a mixin : class AHero extends stunTrait(superclass). Now I want that a stunned hero can not move. So in Ahero : move(){ if(this.stunned) return; ... } Later I find out stun