question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Documentation: Describe how to use sass to aggregate multiple vuetify css classes

See original GitHub issue

Problem to solve

Keeping things DRY with CSS.

Currently when multiple vuetify classes (e.g. .text-caption .text-left .font-weight-thin) are used in numerous places in a page, these all have to be edited and maintained individually causing orders of magnitude more edits, and bugs.

A solution was searched for and asked on discord but answers were not forthcoming.

A naive implementation caused a sass build time error:

 ERROR  in ./components/Section.vue?vue&type=style&index=0&id=1b21a30e&scoped=true&lang=sass&

Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: The target selector was not found.
Use "@extend .text-caption !optional" to avoid this error.
   ╷
97 │   @extend .text-caption
   │   ^^^^^^^^^^^^^^^^^^^^^
   ╵

Proposed solution

Describe how to use sass to create aggregate class definitions. Correct the following code and place within the documentation.

<style scoped lang="sass">

@import '~vuetify/src/styles/styles.sass'

.section-text
  @extend .text-caption
  @extend .text-left
  @extend .font-weight-thin
...

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
KaelWDcommented, Nov 19, 2020

You don’t. You would have to import ~vuetify/src/styles/main.sass instead as that actually contains the classes you want to extend, but then you will get duplicated styles:
https://stackoverflow.com/q/58905949/2074736
https://github.com/webpack-contrib/sass-loader/issues/145#issuecomment-173984354

.section-text
  $properties: map-deep-get($utilities, 'typography', 'property')
  @for $i from 1 through length($properties)
    $property: nth($properties, $i)
    $value: nth(map-get($typography, 'caption'), $i)
    @if $value != false
      #{$property}: $value

  text-align: left
  font-weight: map-get($font-weights, 'thin')

or

@mixin extend-utility($class, $utility, $values) {
  @include generate-utility(map-merge(map-get($utilities, $utility), (
    class: $class,
    values: (
      null: $values
    )
  )), '');
}

@include extend-utility('section-text', 'typography', map-get($typography, 'caption'));

.section-text {
  text-align: left;
  font-weight: map-get($font-weights, 'thin') !important;
}
1reaction
KaelWDcommented, Feb 20, 2021

Depending on how https://github.com/sass/sass/issues/2745 is implemented (if ever) this might eventually be possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SASS variables - Vuetify
Once installed, create a folder called sass , scss or styles in your src directory with a file named variables. scss or variables....
Read more >
Vue - Mixing SASS with SCSS, with Vuetify as an Example
A guide on mixing Sass-syntax and SCSS-syntax within a single Vue project, and how it can conflict with vendor Sass files, such as...
Read more >
SASS combine multiple classes from vuetify's flex utilities
In my sass code, I tried to combine the classes together using @extend @import '~vuetify/src/styles/styles.sass' @import ...
Read more >
justify-self - CSS: Cascading Style Sheets - MDN Web Docs
The CSS justify-self property sets the way a box is justified inside its ... In the following example we have a simple 2...
Read more >
Vuetify [Feature Request] Can not apply hover with rowspan ...
class ="elevation-1". 9. > 10. <template slot="headers" slot-scope="props">. 11. <tr>. 12. <th. 13. v-for="header in props.headers". 14. :key="header.text".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found