mixins

ES 6 Classes - Mixins

最后都变了- 提交于 2019-12-29 09:42:11
问题 I'm coming up with View (HTML markup) and Utility (JavaScript - behavior) architecture and creating atomic classes for composing views and utilities using ES6 Class. There will be a need that multiple utility classes can be composed/mixed into a single view class. How can ES6 Class API provide a way to mix-in class(es) into another/main class. I've looked at Object.assign but that is for objects and not at class-level. 回答1: JavaScript classes right now and hopefully also in future only can be

java traits or mixins pattern?

限于喜欢 提交于 2019-12-29 05:50:08
问题 Is there a way to emulate mixins or traits in java? basically, I need a way to do multiple inheritance so I can add common business logic to several classes 回答1: I would encapsulate all of the business logic into a new class BusinessLogic and have each class that needs BusinessLogic make calls to the class. If you need a single rooted heirarchy for your classes that make calls to BusinessLogic , you'll have to create an interface as well ( BusinessLogicInterface ?) In pseudo-code: interface

CSS-Less class extend class with pseudo class

六眼飞鱼酱① 提交于 2019-12-29 05:13:06
问题 I was wondering how I could do something like the following with less css: .btn { color : black; } .btn:hover { color : white; } .btn-foo { .btn; &:hover { .btn:hover; } } Of-course this is just an example, what need to point is if there is any way to extend the pseudo-class in order to avoid re-type the properties of :hover pseudo class everywhere I need them. I know I could create a mixin for that but I'm wondering if I could avoid it. Thanks 回答1: UPDATE: If you can't modify external files

Sass variable default scope

江枫思渺然 提交于 2019-12-29 04:16:12
问题 I have a problem with using variable defaults in Sass across scopes. My test example is: @mixin foo { $val: 'red' !default; .bar { color: $val; } } @include foo; .class1 { $val: 'green'; @include foo; .class11 { @include foo; } } $val: 'black'; .class2 { @include foo; } .class3 { $val: 'blue'; @include foo; } .class4 { @include foo; } It is compiles to: .bar { color: "red"; } .class1 .bar { color: "red"; } .class1 .class11 .bar { color: "red"; } .class2 .bar { color: "black"; } .class3 .bar {

Javascript mixins when using the module pattern

删除回忆录丶 提交于 2019-12-28 03:06:05
问题 I've been using the module pattern for a while, but recently have started wanting to mix in functions and properties into them to increase code re-use. I've read some good resources on the subject, but still am a bit uncertain as to the best approach. Here is a module: var myModule = function () { var privateConfigVar = "Private!"; //"constructor" function module() {} module.publicMethod = function () { console.log('public'); } function privateMethod1() { console.log('private'); } return

LessCss dynamic variables based on ancestor class

拥有回忆 提交于 2019-12-27 16:10:55
问题 I have a page template which has a branding class on the body element: <body class="brand-africa"> <h1>Africa</h1> </body> Using the following Less, I can use a variable for the brand colour and apply it to the color of a CSS selector: @brand-default: #649d84; @brand-africa: #df6f20; @brand-nz: #444; .brand-color { .brand-default & { color: @brand-default; } .brand-africa & { color: @brand-africa; } .brand-nz & { color: @brand-nz; } } h1 { .brand-color; } This works well, but sometimes I want

LessCss dynamic variables based on ancestor class

我只是一个虾纸丫 提交于 2019-12-27 16:09:01
问题 I have a page template which has a branding class on the body element: <body class="brand-africa"> <h1>Africa</h1> </body> Using the following Less, I can use a variable for the brand colour and apply it to the color of a CSS selector: @brand-default: #649d84; @brand-africa: #df6f20; @brand-nz: #444; .brand-color { .brand-default & { color: @brand-default; } .brand-africa & { color: @brand-africa; } .brand-nz & { color: @brand-nz; } } h1 { .brand-color; } This works well, but sometimes I want

Extending Twitter's Bootstrap 2.x default grid (span classes) with less mixins

穿精又带淫゛_ 提交于 2019-12-25 11:24:12
问题 So I think I'm just starting to understand less and bootstrap. I am building a responsive theme and one of the issues I have is I have a span with a 1px border, this 1px border naturally increases the width and throws the whole thing off, of course I could just slap another class on the span to override the width:300 setting and make it 299, however because it's a responsive theme I would have to write several classes for various screen widths. I just tried writing a mixin into less bootstrap

Foundation Variables and Mixins Not Working Correctly

心不动则不痛 提交于 2019-12-25 05:29:13
问题 I have Foundation installed with Bower, and I'm including the path in my gulp task like so: .pipe(sass({ includePaths: [ 'bower_components/foundation/scss' ], outputStyle: 'expanded' }) When I @import 'foundation'; into my stylesheet it seems to work fine. But when I start to reference its SASS variables or mixins I start getting errors like the one below: Error: unbound variable $medium-up Any idea why this is happening? Thanks in advance! 回答1: You need to @import 'foundation/settings';

Box arrow to take background colour of respective box

最后都变了- 提交于 2019-12-25 02:49:12
问题 I'll try to explain this as simple as possible: For this example I want the arrow of each box to take the background colour of its respective box automatically by only adding red, black, grey classes to the box. I could easily do: .box.red { &:before { ... border-bottom: 1px solid $red; } } .box.black { &:before { ... border-bottom: 1px solid $black; } } .box.grey { &:before { ... border-bottom: 1px solid $grey; } } But this implies that for every different colour I create I'll have to change