@kth/style 0.11.4 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ interface Options {
2
+ threshold: number;
3
+ className: string;
4
+ }
5
+ export declare class ScrollObserver {
6
+ /** Sets a class in an element when the window scroll is below a treshold */
7
+ static setClass(element: HTMLElement | null, options?: Options): void;
8
+ }
9
+ export {};
@@ -1 +1,2 @@
1
1
  export { MenuPanel } from "./components/MenuPanel";
2
+ export { ScrollObserver } from "./components/ScrollObserver";
package/dist/cjs/index.js CHANGED
@@ -97,4 +97,27 @@ class MenuPanel {
97
97
  }
98
98
  }
99
99
 
100
+ const DEFAULT_OPTIONS = {
101
+ threshold: 32,
102
+ className: "collapsed",
103
+ };
104
+ function toggleClass(element, { threshold, className }) {
105
+ if (window.scrollY > threshold) {
106
+ element?.classList.add(className);
107
+ }
108
+ else {
109
+ element?.classList.remove(className);
110
+ }
111
+ }
112
+ class ScrollObserver {
113
+ /** Sets a class in an element when the window scroll is below a treshold */
114
+ static setClass(element, options = DEFAULT_OPTIONS) {
115
+ toggleClass(element, options);
116
+ window.addEventListener("scroll", () => {
117
+ toggleClass(element, options);
118
+ });
119
+ }
120
+ }
121
+
100
122
  exports.MenuPanel = MenuPanel;
123
+ exports.ScrollObserver = ScrollObserver;
@@ -0,0 +1,9 @@
1
+ interface Options {
2
+ threshold: number;
3
+ className: string;
4
+ }
5
+ export declare class ScrollObserver {
6
+ /** Sets a class in an element when the window scroll is below a treshold */
7
+ static setClass(element: HTMLElement | null, options?: Options): void;
8
+ }
9
+ export {};
@@ -1 +1,2 @@
1
1
  export { MenuPanel } from "./components/MenuPanel";
2
+ export { ScrollObserver } from "./components/ScrollObserver";
package/dist/esm/index.js CHANGED
@@ -95,4 +95,26 @@ class MenuPanel {
95
95
  }
96
96
  }
97
97
 
98
- export { MenuPanel };
98
+ const DEFAULT_OPTIONS = {
99
+ threshold: 32,
100
+ className: "collapsed",
101
+ };
102
+ function toggleClass(element, { threshold, className }) {
103
+ if (window.scrollY > threshold) {
104
+ element?.classList.add(className);
105
+ }
106
+ else {
107
+ element?.classList.remove(className);
108
+ }
109
+ }
110
+ class ScrollObserver {
111
+ /** Sets a class in an element when the window scroll is below a treshold */
112
+ static setClass(element, options = DEFAULT_OPTIONS) {
113
+ toggleClass(element, options);
114
+ window.addEventListener("scroll", () => {
115
+ toggleClass(element, options);
116
+ });
117
+ }
118
+ }
119
+
120
+ export { MenuPanel, ScrollObserver };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kth/style",
3
- "version": "0.11.4",
3
+ "version": "0.12.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "exports": {
@@ -1,5 +1,6 @@
1
1
  @use "../tokens/colors.scss";
2
2
  @use "../tokens/spacing.scss";
3
+ @use "../tokens/sizing.scss";
3
4
  @use "../utils/mixins.scss";
4
5
 
5
6
  @layer kth-style {
@@ -22,11 +23,25 @@
22
23
  }
23
24
  }
24
25
 
26
+ :root {
27
+ --height-header: 6rem;
28
+ }
29
+
25
30
  .kth-header {
31
+ position: absolute;
32
+
33
+ // TODO: convert to its own token
34
+ z-index: 10;
35
+ top: var(--height-kpm, 0);
26
36
  color: var(--color-text);
27
37
  background: var(--color-background);
28
38
  padding-block: spacing.$space-16;
29
- position: relative;
39
+ width: 100%;
40
+ transition: padding-block 500ms cubic-bezier(0.05, 0.7, 0.1, 1);
41
+
42
+ .kth-logotype {
43
+ transition: all 200ms linear;
44
+ }
30
45
 
31
46
  &__container {
32
47
  @include mixins.container;
@@ -47,4 +62,23 @@
47
62
  display: none;
48
63
  }
49
64
  }
65
+
66
+ // Fixed header in mobile
67
+ @media (max-width: sizing.$breakpoint-64) {
68
+ .kth-header {
69
+ position: fixed;
70
+ }
71
+
72
+ .kth-header.collapsed {
73
+ padding-block: spacing.$space-8;
74
+
75
+ // TODO: Define this shadow as a token
76
+ box-shadow: 0 0.125rem 0.5rem 0 rgb(0 0 0 /0.15);
77
+
78
+ .kth-logotype {
79
+ block-size: 0rem;
80
+ opacity: 0;
81
+ }
82
+ }
83
+ }
50
84
  }
@@ -1,7 +1,18 @@
1
1
  @use "../utils/mixins.scss";
2
2
 
3
3
  @layer kth-style {
4
+ :root {
5
+ --height-kpm: 2.5rem;
6
+ }
7
+
4
8
  .kth-kpm {
9
+ position: fixed;
10
+ width: 100%;
11
+ // TODO: Convert to its own token
12
+ z-index: 10;
13
+ background: var(--color-background);
14
+ top: 0;
15
+
5
16
  &__container {
6
17
  @include mixins.container;
7
18
  display: flex;
@@ -1,14 +1,19 @@
1
1
  @use "../tokens/spacing.scss";
2
+ @use "../tokens/sizing.scss";
2
3
 
3
4
  @layer kth-style {
4
5
  a.kth-logotype,
5
6
  figure.kth-logotype {
7
+ overflow: hidden;
6
8
  display: inline-block;
7
9
  block-size: 4rem;
8
10
  inline-size: 4rem;
9
11
  border: none;
10
12
  margin: 0;
11
- margin-inline-end: spacing.$space-32;
13
+
14
+ @media (min-width: sizing.$breakpoint-64) {
15
+ margin-inline-end: spacing.$space-32;
16
+ }
12
17
  padding: 0;
13
18
 
14
19
  // Defensive measurement:
@@ -18,11 +23,14 @@
18
23
  > figure {
19
24
  block-size: 100%;
20
25
  inline-size: 100%;
26
+ position: relative;
21
27
  }
22
28
 
23
29
  img {
24
- block-size: 100%;
25
- inline-size: 100%;
30
+ position: absolute;
31
+ bottom: 0;
32
+ block-size: 4rem;
33
+ inline-size: 4rem;
26
34
  }
27
35
  }
28
36
  }
@@ -91,7 +91,17 @@ $generate-css: true !default;
91
91
  color: var(--color-text);
92
92
  background: var(--color-background);
93
93
  min-height: 100vh;
94
- margin: 0;
94
+ margin-inline: 0;
95
+
96
+ // `--height-kpm` is set by (new) KPM or `kpm.scss`
97
+ // `--kpm-bar-height` is the old (current) name for the variable set by KPM
98
+ // default value is 0 (no kpm at all)
99
+
100
+ // `--height-header` is set when including `header.scss`
101
+ // default value is 0 (no header)
102
+ margin-block-start: calc(
103
+ var(--height-kpm, --kpm-bar-height, 0) + var(--height-header, 0)
104
+ );
95
105
  }
96
106
 
97
107
  @include reset;