aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/templates/assets/stylesheets/main/components/_header.scss
blob: e51f3f99f811788f203644b0aa3ca31cf7c99e8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
////
/// Copyright (c) 2016-2023 Martin Donath <martin.donath@squidfunk.com>
///
/// Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
/// and/or sell copies of the Software, and to permit persons to whom the
/// Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
/// DEALINGS
////

// ----------------------------------------------------------------------------
// Rules
// ----------------------------------------------------------------------------

// Header - by default, the header will be sticky and stay always on top of the
// viewport. If this behavior is not desired, just set `position: static`.
.md-header {
  position: sticky;
  inset-inline: 0;
  top: 0;
  z-index: 4;
  display: block;
  color: var(--md-primary-bg-color);
  background-color: var(--md-primary-fg-color);
  // Hack: reduce jitter by adding a transparent box shadow of the same size
  // so the size of the layer doesn't change during animation
  box-shadow:
    0 0           px2rem(4px) rgba(0, 0, 0, 0),
    0 px2rem(4px) px2rem(8px) rgba(0, 0, 0, 0);

  // [print]: Hide header
  @media print {
    display: none;
  }

  // Header is hidden
  &[hidden] {
    transition:
      transform  250ms cubic-bezier(0.8, 0, 0.6, 1),
      box-shadow 250ms;
    transform: translateY(-100%);
  }

  // Header in shadow state, i.e. shadow is visible
  &--shadow {
    box-shadow:
      0 0           px2rem(4px) rgba(0, 0, 0, 0.1),
      0 px2rem(4px) px2rem(8px) rgba(0, 0, 0, 0.2);
    transition:
      transform  250ms cubic-bezier(0.1, 0.7, 0.1, 1),
      box-shadow 250ms;
  }

  // Header wrapper
  &__inner {
    display: flex;
    align-items: center;
    padding: 0 px2rem(4px);
  }

  // Header button
  &__button {
    position: relative;
    z-index: 1;
    padding: px2rem(8px);
    margin: px2rem(4px);
    color: currentcolor;
    vertical-align: middle;
    cursor: pointer;
    outline-color: var(--md-accent-fg-color);
    transition: opacity 250ms;

    // Button on hover
    &:hover {
      opacity: 0.7;
    }

    // Header button is visible
    &:not([hidden]) {
      display: inline-block;
    }

    // Hide outline for pointer devices
    &:not(.focus-visible) {
      outline: none;
      -webkit-tap-highlight-color: transparent;
    }

    // Button with logo, pointing to `config.site_url`
    &.md-logo {
      padding: px2rem(8px);
      margin: px2rem(4px);

      // [tablet -]: Hide button
      @include break-to-device(tablet) {
        display: none;
      }

      // Image or icon
      :is(img, svg) {
        display: block;
        width: auto;
        height: px2rem(24px);
        fill: currentcolor;
      }
    }

    // Button for search
    &[for="__search"] {

      // [tablet landscape +]: Hide button
      @include break-from-device(tablet landscape) {
        display: none;
      }

      // [no-js]: Hide button
      .no-js & {
        display: none;
      }

      // Adjust for right-to-left languages
      [dir="rtl"] & svg {
        transform: scaleX(-1);
      }
    }

    // Button for drawer
    &[for="__drawer"] {

      // [screen +]: Hide button
      @include break-from-device(screen) {
        display: none;
      }
    }
  }

  // Header topic
  &__topic {
    position: absolute;
    display: flex;
    max-width: 100%;
    white-space: nowrap;
    transition:
      transform 400ms cubic-bezier(0.1, 0.7, 0.1, 1),
      opacity   150ms;

    // Second header topic - title of the current page
    & + & {
      z-index: -1;
      pointer-events: none;
      opacity: 0;
      transition:
        transform 400ms cubic-bezier(1, 0.7, 0.1, 0.1),
        opacity   150ms;
      transform: translateX(px2rem(25px));

      // Adjust for right-to-left languages
      [dir="rtl"] & {
        transform: translateX(px2rem(-25px));
      }
    }

    // Adjust font weight of site title
    &:first-child {
      font-weight: 700;
    }
  }

  // Header title
  &__title {
    flex-grow: 1;
    height: px2rem(48px);
    margin-inline-start: px2rem(20px);
    margin-inline-end: px2rem(8px);
    font-size: px2rem(18px);
    line-height: px2rem(48px);

    // Header title in active state, i.e. page title is visible
    &--active .md-header__topic {
      z-index: -1;
      pointer-events: none;
      opacity: 0;
      transition:
        transform 400ms cubic-bezier(1, 0.7, 0.1, 0.1),
        opacity   150ms;
      transform: translateX(px2rem(-25px));

      // Adjust for right-to-left languages
      [dir="rtl"] & {
        transform: translateX(px2rem(25px));
      }

      // Second header topic - title of the current page
      + .md-header__topic {
        z-index: 0;
        pointer-events: initial;
        opacity: 1;
        transition:
          transform 400ms cubic-bezier(0.1, 0.7, 0.1, 1),
          opacity   150ms;
        transform: translateX(0);
      }
    }

    // Add ellipsis in case of overflowing text
    > .md-header__ellipsis {
      position: relative;
      width: 100%;
      height: 100%;
    }
  }

  // Header option
  &__option {
    display: flex;
    flex-shrink: 0;
    max-width: 100%;
    white-space: nowrap;
    transition:
      max-width  0ms 250ms,
      opacity  250ms 250ms;

    // Hide toggle when search is active
    [data-md-toggle="search"]:checked ~ .md-header & {
      max-width: 0;
      opacity: 0;
      transition:
        max-width 0ms,
        opacity   0ms;
    }

    // Hack: Firefox 117 introduces a bug where the browser scrolls the page by
    // a small amount to the top every time the header button is focused. After
    // investigating, we're confident that it seems to be caused by the input
    // field being too close to the border - see https://t.ly/APO8l
    > input {
      bottom: 0;
    }
  }

  // Repository information container
  &__source {
    display: none;

    // [tablet landscape +]: Show repository information
    @include break-from-device(tablet landscape) {
      display: block;
      width: px2rem(234px);
      max-width: px2rem(234px);
      margin-inline-start: px2rem(20px);
    }

    // [screen +]: Adjust spacing of search bar
    @include break-from-device(screen) {
      margin-inline-start: px2rem(28px);
    }
  }
}