Skip to content

Commit

Permalink
feat(styling): find way to add colors to SVGs used by the lib (#557)
Browse files Browse the repository at this point in the history
* feat(styling): find way to add colors to SVGs used by the lib
  • Loading branch information
ghiscoding committed Aug 12, 2020
1 parent d6e0bef commit b551caa
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/app/examples/grid-tree-data-hierarchical.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ $icon-width-mdi-plus: 14px;
$icon-width-mdi-arrow-collapse: 14px;
$icon-width-mdi-arrow-expand: 14px;
$icon-width-mdi-close-thick: 12px;
$icon-color-mdi-file-pdf-outline: #f14668;
$icon-color-mdi-file-music-outline: #3298dc;
$icon-color-mdi-file-excel-outline: #1E9F75;
$icon-color-mdi-folder: orange;
$icon-color-mdi-folder-open: orange;

/* You can change the SASS color via the associated variable, BUT it's better to use the recolor @mixing shown down below */
// $icon-color-mdi-file-pdf-outline: #f14668;
// $icon-color-mdi-file-music-outline: #3298dc;
// $icon-color-mdi-file-excel-outline: #1E9F75;
// $icon-color-mdi-folder: orange;
// $icon-color-mdi-folder-open: #ffa500;

/* make sure to add the @import the SlickGrid Theme AFTER the variables changes */
@import '../modules/angular-slickgrid/styles/slickgrid-theme-salesforce.scss';
Expand All @@ -20,3 +22,24 @@ $icon-color-mdi-folder-open: orange;
height: 1.5rem;
width: 1.5rem;
}

.icon.mdi-file-pdf-outline {
/** 1. use `filter` color */
// filter: invert(62%) sepia(93%) saturate(5654%) hue-rotate(325deg) brightness(100%) contrast(90%);

/** 2. or use the SASS @mixin (from Angular-Slickgrid "sass-utilities.scss") that will produce the `filter` color */
@include recolor(#f14668, 0.9);
}

.icon.mdi-folder, .icon.mdi-folder-open {
@include recolor(#ffa500, 0.9);
}
.icon.mdi-file-music-outline {
@include recolor(#3298dc, 0.9);
}
.icon.mdi-file-excel-outline {
@include recolor(#1E9F75, 0.9);
}
.icon.mdi-file-document-outline {
@include recolor(#686868, 0.9);
}
26 changes: 26 additions & 0 deletions src/app/modules/angular-slickgrid/styles/sass-utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,29 @@
$string: '%23' + $string;
@return $string;
}

@mixin recolor($color: #000, $opacity: 1) {
$r: red($color) / 255;
$g: green($color) / 255;
$b: blue($color) / 255;
$a: $opacity;

// grayscale fallback if SVG from data url is not supported
$lightness: lightness($color);
filter: saturate(0%) brightness(0%) invert($lightness) opacity($opacity);

// color filter
$svg-filter-id: "recolor";
filter: url('data:image/svg+xml;utf8,\
<svg xmlns="http://www.w3.org/2000/svg">\
<filter id="#{$svg-filter-id}" color-interpolation-filters="sRGB">\
<feColorMatrix type="matrix" values="\
0 0 0 0 #{$r}\
0 0 0 0 #{$g}\
0 0 0 0 #{$b}\
0 0 0 #{$a} 0\
"/>\
</filter>\
</svg>\
##{$svg-filter-id}');
}

0 comments on commit b551caa

Please sign in to comment.