@clone handle to copy/clone properties
See original GitHub issueAfter start reading this thread from @adamwathan I got to wonder if something could be done like this.
So @adamwathan points out a missing possibility to copy out the properties from a class rather than extending it, helping out the possibility of creating utilities and inject them in components easily, "mixin’ free some of the most popular CSS frameworks out there.
I’ve found that this feature was being addressed back in 2015 at #1852 , but it was with another a purpose (maybe that why it was closed?)
So normally we @extend SASS like this:
.foo {
@extend .baz;
background-color: green;
}
.bar {
color: blue;
}
.baz {
color: red;
}
That outputs the the following CSS:
.foo {
background-color: green;
}
.bar {
color: blue;
}
.baz, .foo {
color: red;
}
But what if we can @clone another class properties, pretty much like LESS?
.foo {
@clone .baz; // or @copy .baz;
background-color: green;
}
.bar {
color: blue;
}
.baz {
color: red;
}
That the will output this:
.foo {
color: red;
background-color: green;
}
.bar {
color: blue;
}
.baz {
color: red;
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:29 (6 by maintainers)
Top Results From Across the Web
Object Cloning - Manual - PHP
An object copy is created by using the clone keyword (which calls the object's __clone() method if possible). $copy_of_object = clone $object;. When...
Read more >Methods for deep cloning objects in JavaScript - LogRocket Blog
There are several ways to shallow clone objects in JavaScript, but deep cloning objects is trickier. We highlight several methods to do so....
Read more >Cloning any javascript object by copying all own properties
This will create all the properties present in the original object onto the clone, as well as their values. Now the problem is,...
Read more >JS Copy an Object – How to Clone an Obj in JavaScript
An alternative to the spread operator is the Object.assign() method. You use this method to copy the values and properties from one or...
Read more >Java Object clone() Method - Cloning in Java - DigitalOcean
Cloning is the process of creating a copy of an Object. ... (Employee) emp.clone(); // Check whether the emp and clonedEmp attributes are ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Having to rewrite (or hack) third-party (S)CSS and wrap everything in mixins isn’t practical.
That’s your opinion, but people nevertheless seek this feature, and it’s a key reason why some choose LESS instead.
For one, the precedence issues caused by
@import
in my opinion are somewhat undeniable.How about extending
@include
to allow something like@include .foo
?Or think of some other way to make this functionality (or something even better) available.
Simply dismissing the feature entirely seems a little too easy - people often ask for this feature, in fact a few developers on our team want to go back to LESS for this.
I think there is a real need here, that is not covered by
@extend
- can’t we think of some way to address that need without “violating CSS semantics”?It’s not easy to rewrite or hack all third-party CSS (or SCSS) files.