|
| 1 | +@use "sass:map"; |
| 2 | +// Icon SCSS mixin |
| 3 | +@mixin icon( |
| 4 | + $glyph: "", |
| 5 | + $size: $icon-size, |
| 6 | + $style: $icon-style, |
| 7 | + $position: "before", |
| 8 | + $partial: false |
| 9 | +) { |
| 10 | + // We're setting this on the parent tag, so that it could get overwritten via data-icon=* |
| 11 | + @if $glyph != "" { |
| 12 | + & { |
| 13 | + --icon-glyph-#{$position}: "#{$glyph}"; |
| 14 | + } |
| 15 | + } |
| 16 | + |
| 17 | + &::#{$position} { |
| 18 | + --icon-font-family: "#{"icons-" + $size + "-" + $style}", |
| 19 | + "missing-icons" !important; |
| 20 | + |
| 21 | + font-size: var( |
| 22 | + --icon-font-size-#{$position}, |
| 23 | + var(--icon-font-size, #{to-rem($pxValue: $size)}) |
| 24 | + ); |
| 25 | + |
| 26 | + @if $position == "before" { |
| 27 | + margin-inline-end: var(--icon-margin-after, #{$icon-content-space}); |
| 28 | + } |
| 29 | + @if $position == "after" { |
| 30 | + margin-inline-start: var( |
| 31 | + --icon-margin-before, |
| 32 | + #{$icon-content-space} |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + content: var(--icon-glyph-#{$position}); |
| 37 | + @supports (content: ""/"") { |
| 38 | + // Hiding icon from screenreaders |
| 39 | + // We couldn't just add the following code line and expect an forgiving behaviour of unsupporting browser to ignore this declaration, but need to wrap it into an @supports due to a bug in WebKit / older versions of Safari: https://github.com/db-ui/core/pull/766 |
| 40 | + content: var(--icon-glyph-#{$position}) / ""; // https://www.w3.org/TR/css-content-3/#alt |
| 41 | + } |
| 42 | + |
| 43 | + @if $partial { |
| 44 | + & { |
| 45 | + display: inline-block; |
| 46 | + /*** icon - partial ***/ |
| 47 | + // * use !important to prevent issues with browser extensions that change fonts |
| 48 | + font-family: var(--icon-font-family) !important; |
| 49 | + font-style: normal; |
| 50 | + font-variant: normal; |
| 51 | + |
| 52 | + font-weight: normal; // CSS variables fallback |
| 53 | + font-weight: var(--icon-font-weight, normal); |
| 54 | + line-height: 1; |
| 55 | + text-transform: none; |
| 56 | + vertical-align: middle; |
| 57 | + |
| 58 | + /* stylelint-disable */ |
| 59 | + // * Better Font Rendering =========== |
| 60 | + -webkit-font-smoothing: antialiased; |
| 61 | + -moz-osx-font-smoothing: grayscale; |
| 62 | + /* stylelint-enable */ |
| 63 | + |
| 64 | + // Hiding icon from screenreaders |
| 65 | + /* stylelint-disable */ |
| 66 | + -webkit-alt: ""; |
| 67 | + /* stylelint-enable */ |
| 68 | + alt: ""; |
| 69 | + speak: none; // Hiding icon from screenreaders, fallback by older notation |
| 70 | + speak: never; // Hiding icon from screenreaders |
| 71 | + } |
| 72 | + @media aural { |
| 73 | + content: none; |
| 74 | + } |
| 75 | + @media speech { |
| 76 | + content: none; |
| 77 | + } |
| 78 | + } @else { |
| 79 | + @extend %icon; |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +// SCSS mixin for elements that text should get hidden in favour of only displaying the included icon |
| 85 | +@mixin is-icon-text-replace($position: "before") { |
| 86 | + & { |
| 87 | + font-size: 0; |
| 88 | + } |
| 89 | + |
| 90 | + @if $position == "before" { |
| 91 | + &::before { |
| 92 | + --icon-margin-after: 0; |
| 93 | + } |
| 94 | + } @else { |
| 95 | + &::after { |
| 96 | + --icon-margin-before: 0; |
| 97 | + } |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +// Icon glyph mixin |
| 102 | +@function glyph($glyph) { |
| 103 | + @return map.get($icon-glyphs, $glyph); |
| 104 | +} |
| 105 | + |
| 106 | +// Icon meta data mixin |
| 107 | +@mixin iconMeta($size: $icon-size, $style: $icon-style, $position: "before") { |
| 108 | + &::#{$position} { |
| 109 | + --icon-font-family: "#{"icons-" + $size + "-" + $style}", |
| 110 | + "missing-icons" !important; |
| 111 | + --icon-font-size: #{to-rem($pxValue: $size)}; |
| 112 | + } |
| 113 | +} |
0 commit comments