Skip to content

Commit 80dca46

Browse files
authored
feat(icon): customizable icons by using maps
This PR moves all icon declarations out of the overrides file and into LESS maps, so the icon selectors are not hardcoded anymore but rendered at compile time. This now offers easy adjustment of (un)-wanted icons by simpy adjusting the related @icon-map maplist in a possible custom themes icon.variables Previously that wasn't really possible, as the default theme overrides were always included, so even if your custom theme only needed a handful of icons you always got the whole set anyway. I did the same for emoji and flag already. The related script for self creation is adjusted in fomantic/create-fomantic-icons#184
1 parent 8b04a71 commit 80dca46

File tree

3 files changed

+2136
-2103
lines changed

3 files changed

+2136
-2103
lines changed

src/definitions/elements/icon.less

Lines changed: 90 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@
2323
Icon
2424
*******************************/
2525
& when (@importIcons) {
26-
@font-face {
27-
font-family: 'Icons';
28-
src: @fallbackSRC;
29-
src: @src;
30-
font-style: normal;
31-
font-weight: @normal;
32-
font-variant: normal;
33-
text-decoration: inherit;
34-
text-transform: none;
35-
}
26+
each(@fonts, {
27+
@font-face {
28+
each(@value,{
29+
@{key}: @value;
30+
});
31+
}
32+
})
3633
}
3734

3835
i.icon {
@@ -44,7 +41,7 @@ i.icon {
4441
width: @width;
4542
height: @height;
4643

47-
font-family: 'Icons';
44+
font-family: @fontName;
4845
font-style: normal;
4946
font-weight: @normal;
5047
text-decoration: inherit;
@@ -519,4 +516,86 @@ i.icons {
519516
}
520517
}
521518

519+
.generateIcons(@map, @fontFamily) {
520+
each(@map,{
521+
@escapedKey: replace(@key,'^([0-9])','\3$1 ');
522+
@normalizedKey: replace(@escapedKey,'_','.','g');
523+
i.icon.@{normalizedKey}::before {
524+
content: "@{value}";
525+
& when not (@fontFamily = false) {
526+
font-family: @fontFamily;
527+
}
528+
}
529+
});
530+
};
531+
532+
& when (@variationIconDeprecated) {
533+
534+
/* Deprecated *In/Out Naming Conflict) */
535+
.generateIcons(@icon-deprecated-map,false);
536+
}
537+
538+
& when (@variationIconSolid) {
539+
/*******************************
540+
Solid Icons
541+
*******************************/
542+
543+
/* Icons */
544+
.generateIcons(@icon-map,false);
545+
& when (@variationIconAliases) {
546+
547+
/* Aliases */
548+
.generateIcons(@icon-aliases-map,false);
549+
}
550+
}
551+
552+
& when (@variationIconOutline) {
553+
/*******************************
554+
Outline Icons
555+
*******************************/
556+
557+
i.icon.outline {
558+
font-family: @outlineFontName;
559+
}
560+
561+
/* Icons */
562+
.generateIcons(@icon-outline-map,false);
563+
& when (@variationIconAliases) {
564+
565+
/* Aliases */
566+
.generateIcons(@icon-outline-aliases-map,false);
567+
}
568+
}
569+
570+
& when (@variationIconThin) {
571+
/*******************************
572+
Thin Icons
573+
*******************************/
574+
575+
/* Icons */
576+
i.icon.thin {
577+
font-family: @thinFontName;
578+
}
579+
.generateIcons(@icon-thin-map,false);
580+
& when (@variationIconAliases) {
581+
582+
/* Aliases */
583+
.generateIcons(@icon-thin-aliases-map,false);
584+
}
585+
}
586+
587+
& when(@variationIconBrand) {
588+
/*******************************
589+
Brand Icons
590+
*******************************/
591+
592+
/* Icons */
593+
.generateIcons(@icon-brand-map,@brandFontName);
594+
& when (@variationIconAliases) {
595+
596+
/* Aliases */
597+
.generateIcons(@icon-brand-aliases-map,@brandFontName);
598+
}
599+
}
600+
522601
.loadUIOverrides();

0 commit comments

Comments
 (0)