blob: cf274ab18c1ffe5ca4c0ae504cd65490af7bbb85 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001@import "functions";
2
3/// Triangle helper mixin
4/// Modified from: http://blustemy.io/drawing-pure-css-arrows-with-mixins/
5/// https://css-tricks.com/snippets/sass/css-triangle-mixin/
6/// @param {Direction} $direction - Triangle direction, either `top`, `right`, `bottom` or `left`
7/// @param {Color} $color [currentcolor] - Triangle color
8/// @param {Length} $size [1em] - Triangle size
9@mixin mdlext-arrow($direction: bottom, $base-width: 15px, $length: 10px, $color: inherit, $font-size: inherit) {
10 content: '';
11 width: 0;
12 height: 0;
13 font-size: $font-size;
14 line-height: $font-size;
15 border-#{mdlext-opposite-direction($direction)}: $length solid $color;
16 border-#{mdlext-opposite-direction($direction)}-width: $length;
17 border-#{mdlext-opposite-direction($direction)}-style: solid;
18 border-#{mdlext-opposite-direction($direction)}-color: $color;
19
20 $perpendicular-borders: ($base-width / 2) solid transparent;
21
22 @if $direction == top or $direction == bottom {
23 border-left: $perpendicular-borders;
24 border-right: $perpendicular-borders;
25 }
26 @else if $direction == right or $direction == left {
27 border-bottom: $perpendicular-borders;
28 border-top: $perpendicular-borders;
29 }
30}
31
32/// Hide element while making it readable for screen readers
33/// Copied from HTML5Boilerplate:
34/// https://github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css#L119-L133
35@mixin mdlext-visually-hidden() {
36 border: 0;
37 clip: rect(0 0 0 0);
38 height: 1px;
39 margin: -1px;
40 overflow: hidden;
41 padding: 0;
42 position: absolute;
43 width: 1px;
44}
45
46
47/// Toggle for aria-expanded attribute
48///
49/// @author Leif Olsen
50/// @param {Font} $font-family ['Material Icons'] - Font family
51/// @param {Length} $font-size [24px] - Font size
52/// @param {string} $icon ['+'] - icon to display when 'aria-expanded="false"'
53/// @param {string} $icon-expanded ['-'] - icon to display when 'aria-expanded="true"'
54/// @link https://github.com/google/material-design-icons Modified from '.material-icons' class
55/// @param {Length} $icon-offset [0] - Icon offset
56///
57/// @example - +/- toggle
58/// .plus-minus {
59/// @include mdlext-aria-expanded-toggle($font-family: inherit, $font-size: inherit);
60/// }
61/// <div aria-expanded="false">
62/// <i class="plus-minus"></i>
63/// </div>
64///
65/// @example - Material Icons, expand-more/expand_less
66/// .more-less {
67/// @include mdlext-aria-expanded-toggle($content: 'expand_more', $content-expanded: 'expand_less');
68/// }
69/// <div aria-expanded="true">
70/// <i class="more-less"></i>
71/// </div>
72
73@mixin mdlext-aria-expanded-toggle($font-family: 'Material Icons', $font-size: 24px, $icon: '+', $icon-expanded: '-', $icon-offset: 0) {
74 font-family: $font-family;
75 font-weight: inherit;
76 font-style: inherit;
77 font-size: $font-size; // Preferred icon size
78 display: inline-block;
79 width: 1em;
80 height: 1em;
81 line-height: 1;
82 text-transform: none;
83 letter-spacing: normal;
84 word-wrap: normal;
85 white-space: nowrap;
86 direction: ltr;
87 vertical-align: middle;
88
89 // Support for all WebKit browsers.
90 -webkit-font-smoothing: antialiased;
91 -webkit-font-feature-settings: 'liga';
92
93 // Support for Safari and Chrome.
94 text-rendering: optimizeLegibility;
95
96 // Support for Firefox.
97 -moz-osx-font-smoothing: grayscale;
98
99 // Support for IE.
100 font-feature-settings: 'liga';
101
102 &::after {
103 content: $icon;
104 margin-left: $icon-offset;
105 }
106
107 [aria-expanded='true'] > & {
108 &::after {
109 content: $icon-expanded;
110 margin-left: $icon-offset;
111 }
112 }
113}
114
115
116/// Keyframe mixin
117/// Modified from: http://sassbreak.com/nested-keyframe-rules-sass/
118/// Modified from: http://sassbreak.com/sass-tools-and-snippets/
119///
120/// @example
121///
122/// .some-element {
123/// animation: 10s linear infinite;
124///
125/// @include mdlext-animation-keyframes {
126/// from {
127/// background-position: 0% 0%;
128/// }
129/// to {
130/// background-position: 114.2857% 0%;
131/// }
132/// }
133/// }
134
135@mixin mdlext-animation-keyframes {
136 $animation-name: unique-id();
137 animation-name: $animation-name;
138
139 @keyframes #{$animation-name} {
140 @content;
141 }
142}
143
144
145/// Flexible title mixin
146/// A flexible title consists of three regions, left, middle and right.
147/// The left and right regions are optional and will typically contain state icons
148/// or act as a toolbar. The middle region should contain the title text.
149///
150/// @author Leif Olsen
151/// @param {String} $class - class name
152/// @gutter {Length} [8px] - horizontal spacing between title elements
153///
154/// @example
155///
156/// @include mdlext-flexible-title(my-title) {
157/// overflow: hidden;
158/// background-color: yellow;
159/// &__text {
160/// font-size: 20px;
161/// letter-spacing: 0.02em;
162/// font-weight: 400;
163/// line-height: 1.1;
164/// }
165/// }
166///
167/// <header class="my-title">
168/// <i class="material-icons" role="presentation" style="font-size: 28px;">info</i>
169/// <h2 class="my-title__text">A title</h2>
170/// <span class="my-title__spacer"></span>
171/// <i class="mdlext-aria-expanded-more-less" role="presentation" style="font-size: 28px;"></i>
172/// </header>
173
174@mixin mdlext-flexible-title($class, $gutter: 8px) {
175 .#{$class} {
176 box-sizing: border-box;
177 position: relative;
178 width: 100%;
179 display: flex;
180 align-self: stretch;
181 align-items: center;
182 margin: 0;
183 padding: 0 $gutter;
184
185 &__text,
186 &__text > * {
187 white-space: nowrap;
188 overflow: hidden;
189 text-overflow: ellipsis;
190 }
191
192 > * {
193 box-sizing: border-box;
194 margin: 0;
195 padding: 0 $gutter 0 0;
196 }
197
198 > *:last-child {
199 padding-right: 0;
200 }
201
202 // Used to align elements inside a header or drawer, by growing to fill
203 // remaining space. Commonly used for aligning elements to the right.
204 &__spacer {
205 flex: 1;
206 }
207
208 @content;
209 }
210}
211