@madj2k/fe-frontend-kit 2.0.32 → 2.0.34

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madj2k/fe-frontend-kit",
3
- "version": "2.0.32",
3
+ "version": "2.0.34",
4
4
  "description": "Shared frontend utilities, menus and mixins for projects",
5
5
  "main": "index.js",
6
6
  "style": "index.scss",
@@ -91,8 +91,12 @@
91
91
  ///
92
92
  /// @license
93
93
  /// GNU General Public License v3.0 https://www.gnu.org/licenses/gpl-3.0.en.html
94
+ /// @deprecated
94
95
  ///
95
96
  @mixin toggle-icon($selector: '.toggle') {
97
+
98
+ @warn "toggle-icon() is deprecated. Use toggle() instead.";
99
+
96
100
  #{$selector}:has(.icon:first-child) {
97
101
  line-height: 1; // icon-only toggle buttons
98
102
  }
@@ -250,6 +250,12 @@
250
250
  align-items: center;
251
251
  gap: rem-calc($gap);
252
252
  height: 100%;
253
+
254
+ @warn "nav-toggle-group() is deprecated. Use toggle-group() instead.";
255
+
256
+ @include toggle-group(
257
+ $gap: $gap,
258
+ );
253
259
  }
254
260
 
255
261
 
@@ -309,49 +315,13 @@
309
315
  "icon-plus": unquote('"\\e908"')
310
316
  )
311
317
  ) {
312
- background-color: transparent;
313
- border: 0;
314
- margin: 0;
315
- padding: 0;
316
-
317
- &:has(.nav-toggle-icon) {
318
- display: flex;
319
- align-items: center;
320
-
321
- // variant with icons as font
322
- &[aria-expanded="true"] {
323
- @each $icon-class, $content in $icon-mappings {
324
- .#{$icon-class} {
325
- &:before {
326
- content: $content;
327
- }
328
- }
329
- }
330
- }
331
-
332
- // variant with icons in a sprite
333
- .nav-toggle-icon-opened {
334
- display: none;
335
- }
336
-
337
- &[aria-expanded="true"] {
338
- .nav-toggle-icon-opened {
339
- display: inline-block;
340
- }
341
- .nav-toggle-icon-closed {
342
- display: none;
343
- }
344
- }
345
- }
346
318
 
347
- &-icon:not(:has(svg)),
348
- &-icon svg {
349
- font-size: rem-calc($icon-size);
350
- width: rem-calc($icon-size);
351
- color: $icon-color;
352
- }
319
+ @warn "nav-toggle() is deprecated. Use toggle() instead.";
353
320
 
354
- &-icon svg {
355
- height: 100%;
356
- }
321
+ @include toggle(
322
+ $icon-size: $icon-size,
323
+ $icon-color: $icon-color,
324
+ $icon-mappings: $icon-mappings,
325
+ $icon-selector: '.nav-toggle-icon'
326
+ );
357
327
  }
@@ -0,0 +1,141 @@
1
+
2
+ /* ==================================================
3
+ * Toggle
4
+ * ==================================================*/
5
+ /// Creates a button group container for toggles.
6
+ ///
7
+ /// Used to align toggle buttons and icons horizontally with spacing.
8
+ /// Useful in responsive navigation headers.
9
+ ///
10
+ /// @group Toggle
11
+ ///
12
+ /// @param {Length} $gap - The spacing between toggle elements. Defaults to `$spacer`.
13
+ ///
14
+ /// @example html
15
+ /// <div class="toggle-group">
16
+ /// <button class="toggle" aria-expanded="false">
17
+ /// <i class="toggle-icon icon-hamburger"></i>
18
+ /// </button>
19
+ /// </div>
20
+ ///
21
+ /// @example scss
22
+ /// .toggle-group {
23
+ /// @include toggle-group($gap: 1rem);
24
+ /// }
25
+ ///
26
+ /// @author Steffen Kroggel <developer@steffenkroggel>
27
+ /// @license GNU General Public License v3.0 https://www.gnu.org/licenses/gpl-3.0.en.html
28
+ ///
29
+ @mixin toggle-group(
30
+ $gap: 16px
31
+ ) {
32
+ display: flex;
33
+ align-items: center;
34
+ gap: rem-calc($gap);
35
+ height: 100%;
36
+ }
37
+
38
+
39
+ /// Creates a button element for toggling.
40
+ ///
41
+ /// Features:
42
+ /// - Accessible button with `aria-expanded` state
43
+ /// - Icon switching based on toggle state (e.g., hamburger to close)
44
+ /// - Configurable icon size and colors
45
+ /// - No default background or borders for flexible styling
46
+ /// - Built-in accessibility outline
47
+ ///
48
+ /// @group Toggle
49
+ ///
50
+ /// @param {Length} $icon-size - Size of the icon (width/height). Defaults to `$spacer`.
51
+ /// @param {Color} $icon-color - Icon color (e.g., fill or text color). Defaults to `$color-primary`.
52
+ /// @param {Map} $icon-mappings - Map of icon toggle states (e.g., hamburger → close). Defaults to a predefined map.
53
+ ///
54
+ /// @example html with icon font
55
+ /// <button class="toggle" aria-expanded="false">
56
+ /// <i class="toggle-icon icon-hamburger icon"></i>
57
+ /// </button>
58
+ ///
59
+ /// @example html with icon sprite
60
+ /// <button class="toggle" aria-expanded="false">
61
+ /// <i class="toggle-icon">
62
+ /// <svg class="toggle-icon-opened" aria-hidden="true" focusable="false">
63
+ /// <use href="sprite.svg#search"></use>
64
+ /// </svg>
65
+ /// <svg class="toggle-icon-closed" aria-hidden="true" focusable="false">
66
+ /// <use href="sprite.svg#close"></use>
67
+ /// </svg>
68
+ /// </i>
69
+ /// </button>
70
+ ///
71
+ ///
72
+ /// @example scss
73
+ /// .toggle {
74
+ /// @include toggle(
75
+ /// $icon-size: 1.5rem,
76
+ /// $icon-color: #333,
77
+ /// $icon-mappings: (
78
+ /// "icon-hamburger": "icon-close",
79
+ /// "icon-plus": "icon-minus"
80
+ /// )
81
+ /// );
82
+ /// }
83
+ ///
84
+ /// @author Steffen Kroggel <developer@steffenkroggel>
85
+ /// @license GNU General Public License v3.0 https://www.gnu.org/licenses/gpl-3.0.en.html
86
+ ///
87
+ @mixin toggle(
88
+ $icon-size: 16px,
89
+ $icon-color: var(--bs-primary),
90
+ $icon-mappings: (
91
+ "icon-hamburger": unquote('"\\e905"'),
92
+ "icon-plus": unquote('"\\e908"')
93
+ ),
94
+ $icon-selector: '.toggle-icon'
95
+ ) {
96
+ background-color: transparent;
97
+ border: 0;
98
+ margin: 0;
99
+ padding: 0;
100
+
101
+ &:has(#{$icon-selector}) {
102
+ display: flex;
103
+ align-items: center;
104
+
105
+ // variant with icons as font
106
+ &[aria-expanded="true"] {
107
+ @each $icon-class, $content in $icon-mappings {
108
+ .#{$icon-class} {
109
+ &:before {
110
+ content: $content;
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ // variant with icons in a sprite
117
+ #{$icon-selector}-opened {
118
+ display: none;
119
+ }
120
+
121
+ &[aria-expanded="true"] {
122
+ #{$icon-selector}-opened {
123
+ display: inline-block;
124
+ }
125
+ #{$icon-selector}-closed {
126
+ display: none;
127
+ }
128
+ }
129
+ }
130
+
131
+ #{$icon-selector}:not(:has(svg)),
132
+ #{$icon-selector} svg {
133
+ font-size: rem-calc($icon-size);
134
+ width: rem-calc($icon-size);
135
+ color: $icon-color;
136
+ }
137
+
138
+ #{$icon-selector} svg {
139
+ height: 100%;
140
+ }
141
+ }
@@ -7,5 +7,6 @@
7
7
  @import './nav';
8
8
  @import './page';
9
9
  @import './section';
10
+ @import './toggle';
10
11
  @import './toggle-list';
11
12
  @import './unit';
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * @author Steffen Kroggel <developer@steffenkroggel.de>
13
13
  * @copyright 2025 Steffen Kroggel
14
- * @version 1.0.0
14
+ * @version 1.0.1
15
15
  * @license GNU General Public License v3.0
16
16
  * @see https://www.gnu.org/licenses/gpl-3.0.en.html
17
17
  *
@@ -34,7 +34,7 @@
34
34
  * document.querySelectorAll('.js-element-in-viewport').forEach((el) => {
35
35
  * new Madj2kElementInViewport(el, {
36
36
  * visibleClass: 'is-in-viewport',
37
- * threshold: 1
37
+ * threshold: 0.5
38
38
  * });
39
39
  * });
40
40
  */
@@ -64,6 +64,17 @@ class Madj2kElementInViewport {
64
64
  this.element = element;
65
65
  this.config = { ...this.config, ...config };
66
66
 
67
+ const viewportHeight = window.innerHeight;
68
+ const elementHeight = element.offsetHeight;
69
+
70
+ if (elementHeight > viewportHeight) {
71
+ const adjustedThreshold = (viewportHeight * this.config.threshold) / elementHeight;
72
+ this._log(
73
+ `Element taller than viewport. Original threshold ${this.config.threshold} adjusted to ${adjustedThreshold.toFixed(3)}`
74
+ );
75
+ this.config.threshold = Math.min(adjustedThreshold, 1);
76
+ }
77
+
67
78
  this._log('Initialized with config:', this.config);
68
79
  this._observe();
69
80
  }