Skip to content

Commit 845150e

Browse files
authored
feat(icon): support duotone icons
Thanks to @testinfected who prepared a PR to create duotone icons in create-fomantic-icons script The changes are adopted from his PR This PR prepares FUI to support Font Awesome duotone icons . As those need a pro plan, the generation of related selectors is disabled by default (as the duotone icon list is also empty by default) and one has to set variationInconDuotone: true as well as generate the icon.variables via fomantic/create-fomantic-icons before being able to use them in FUI When used, such icons can benefit from a color combination to be set via primary-secondary classname logic. For example <!-- This will show a duotone icon inheriting the default text color --> <i class="camera duotone icon"></i> <!-- This will show a duotone icon inheriting the single purple color --> <i class="purple camera duotone icon"></i> <!-- THIS however will show a duotone icon having a red primary and a purple secondary icon --> <i class="red-purple camera duotone icon"></i>
1 parent a927bd2 commit 845150e

File tree

3 files changed

+95
-5
lines changed

3 files changed

+95
-5
lines changed

src/definitions/elements/icon.less

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ i.emphasized.icon:not(.disabled), i.emphasized.icons:not(.disabled) {
163163
transform: scale(1, -1);
164164
}
165165

166-
& when(@variationIconGroups) {
166+
& when (@variationIconGroups) {
167167
.icons i.flipped.icon:not(.corner):not(:first-child),
168168
.icons i.horizontally.flipped.icon:not(.corner):not(:first-child) {
169169
transform: translateX(-50%) translateY(-50%) scale(-1, 1);
@@ -194,7 +194,7 @@ i.emphasized.icon:not(.disabled), i.emphasized.icons:not(.disabled) {
194194
transform: rotate(180deg);
195195
}
196196

197-
& when(@variationIconGroups) {
197+
& when (@variationIconGroups) {
198198
.icons i.rotated.rotated.icon:not(.corner):not(:first-child),
199199
.icons i.right.rotated.icon:not(.corner):not(:first-child),
200200
.icons i.clockwise.rotated.icon:not(.corner):not(:first-child) {
@@ -245,7 +245,7 @@ i.emphasized.icon:not(.disabled), i.emphasized.icons:not(.disabled) {
245245
transform: scale(1, -1) rotate(180deg);
246246
}
247247

248-
& when(@variationIconGroups) {
248+
& when (@variationIconGroups) {
249249
.icons i.rotated.flipped.icon:not(.corner):not(:first-child),
250250
.icons i.right.rotated.flipped.icon:not(.corner):not(:first-child),
251251
.icons i.clockwise.rotated.flipped.icon:not(.corner):not(:first-child) {
@@ -529,6 +529,16 @@ i.icons {
529529
});
530530
};
531531

532+
.generateSecondaryIcons(@map) {
533+
each(@map,{
534+
@escapedKey: replace(@key,'^([0-9])','\3$1 ');
535+
@normalizedKey: replace(@escapedKey,'_','.','g');
536+
i.icon.@{normalizedKey}::after {
537+
content: "@{value}";
538+
}
539+
});
540+
};
541+
532542
& when (@variationIconDeprecated) {
533543

534544
/* Deprecated *In/Out Naming Conflict) */
@@ -584,7 +594,7 @@ i.icons {
584594
}
585595
}
586596

587-
& when(@variationIconBrand) {
597+
& when (@variationIconBrand) {
588598
/*******************************
589599
Brand Icons
590600
*******************************/
@@ -598,4 +608,68 @@ i.icons {
598608
}
599609
}
600610

611+
& when (@variationIconDuotone) {
612+
/*******************************
613+
Duotone Icons
614+
*******************************/
615+
616+
/* Make duotone icons use the proper font */
617+
i.icon.duotone {
618+
font-family: @duotoneFontName;
619+
/* To position the secondary layer on top of the first layer */
620+
position: relative;
621+
}
622+
623+
/* Set the default opacity levels and colors for each layer */
624+
i.icon.duotone::before {
625+
color: @duotonePrimaryColor;
626+
opacity: @duotonePrimaryOpacity;
627+
}
628+
629+
i.icon.duotone::after {
630+
/* Position secondary layer to the left, centered horizontally and aligned vertically to flex with different line heights */
631+
position: absolute;
632+
left: 0;
633+
top: 50%;
634+
transform: translateY(-50%);
635+
text-align: center;
636+
637+
color: @duotoneSecondaryColor;
638+
opacity: @duotoneSecondaryOpacity;
639+
}
640+
641+
.generateIcons(@icon-duotone-map,false);
642+
.generateSecondaryIcons(@icon-duotone-secondary-map);
643+
644+
& when (@variationIconAliases) {
645+
646+
/* Aliases */
647+
.generateIcons(@icon-duotone-aliases-map,false);
648+
.generateSecondaryIcons(@icon-duotone-secondary-aliases-map);
649+
}
650+
651+
/*
652+
* Colors for duotone icons, in the form `primary-secondary`(e.g. `black-grey duotone icon`).
653+
*/
654+
& when not (@variationIconColors = false) {
655+
each(@variationIconColors, {
656+
@color: @value;
657+
@c: @colors[@@color][color];
658+
@l: @colors[@@color][light];
659+
660+
i.icon.duotone[class*="@{color}-"]::before,
661+
i.icon.duotone[class*="-@{color}"]::after {
662+
color: @c;
663+
}
664+
665+
& when (@variationIconInverted) {
666+
i.icon.inverted.duotone[class*="@{color}-"]::before,
667+
i.icon.inverted.duotone[class*="-@{color}"]::after {
668+
color: @l;
669+
}
670+
}
671+
})
672+
}
673+
}
674+
601675
.loadUIOverrides();

src/themes/default/elements/icon.variables

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Icons are order A-Z in their group, Solid, Outline, Thin (Pro only) and Brand
4141
@outlineFontName: 'outline-icons';
4242
@thinFontName: 'thin-icons';
4343
@brandFontName: 'brand-icons';
44+
@duotoneFontName: 'duotone-icons';
4445

4546
@fonts: {
4647
@solid: {
@@ -2062,6 +2063,14 @@ ycombinator: \f23b;
20622063
youtube_play: \f167;
20632064
};
20642065

2066+
@icon-duotone-map: {
2067+
};
2068+
@icon-duotone-secondary-map: {
2069+
};
2070+
@icon-duotone-aliases-map: {
2071+
};
2072+
@icon-duotone-secondary-aliases-map: {
2073+
};
20652074

20662075
/*--------------
20672076
Definition
@@ -2117,3 +2126,9 @@ youtube_play: \f167;
21172126
@big: 2em;
21182127
@huge: 4em;
21192128
@massive: 8em;
2129+
2130+
/* Duotone specifics */
2131+
@duotonePrimaryColor: inherit;
2132+
@duotonePrimaryOpacity: 1;
2133+
@duotoneSecondaryColor: inherit;
2134+
@duotoneSecondaryOpacity: 0.4;

src/themes/default/globals/variation.variables

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
@variationIconAliases: true;
9292
@variationIconOutline: true;
9393
@variationIconBrand: true;
94-
@variationIconThin: true; /* Font Awesome Pro only */
94+
@variationIconThin: false; /* Font Awesome Pro only */
95+
@variationIconDuotone: false; /* Font Awesome Pro only */
9596
@variationIconDisabled: true;
9697
@variationIconInverted: true;
9798
@variationIconLoading: true;

0 commit comments

Comments
 (0)