@odx/foundation 1.0.0-beta.237 → 1.0.0-beta.238
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/README.md
CHANGED
|
@@ -9,8 +9,7 @@ The `@odx/foundation` package is a core part of the ODX Design System, providing
|
|
|
9
9
|
- **Components**: Reusable web components, including buttons, tables, headers, and more.
|
|
10
10
|
- **i18n**: Internationalization utilities for building multilingual applications, with support for locale changes and translations.
|
|
11
11
|
- **Global Styles**: Comprehensive global styles, including colors, spacing, and themes.
|
|
12
|
-
|
|
13
|
-
### Prerequisites
|
|
12
|
+
- **Browser Support**: <a href="https://web-platform-dx.github.io/web-features/supported-browsers/?targetYear=2024" target="_blank">Baseline 2024</a>
|
|
14
13
|
|
|
15
14
|
### Install
|
|
16
15
|
|
|
@@ -17,7 +17,6 @@ export declare const defaultBreakpoints: {
|
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
export default function setupBreakpoints(breakpointsConfig?: BreakpointConfig[]): () => void;
|
|
20
|
-
export * from './models.js';
|
|
21
|
-
export * from './plugins.js';
|
|
20
|
+
export type * from './models.js';
|
|
22
21
|
export * from './utils.js';
|
|
23
22
|
//# sourceMappingURL=main.d.ts.map
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Signal } from '../signals/main.js';
|
|
2
2
|
import { Breakpoint, BreakpointChange, BreakpointConfig, BreakpointOperator } from './models.js';
|
|
3
3
|
export declare const breakpointDirective: import('../utils/main.js').StringAttributeDirective<"odx-breakpoint">;
|
|
4
|
+
export declare const breakpointClassDirective: import('../utils/main.js').StringAttributeDirective<"odx-breakpoint-class">;
|
|
5
|
+
export declare const breakpointActiveDirective: import('../utils/main.js').BooleanAttributeDirective<"odx-breakpoint-active">;
|
|
4
6
|
export declare function buildBreakpoint(breakpoint: BreakpointConfig, operator?: BreakpointOperator): Breakpoint;
|
|
7
|
+
export declare function generateBreakpointStyles(breakpoints: Breakpoint[]): string;
|
|
5
8
|
export declare function expandBreakpoints(...breakpoints: BreakpointConfig[]): Breakpoint[];
|
|
6
9
|
export declare function observeBreakpoint(breakpoint: Breakpoint, initialValue?: boolean): Signal<Breakpoint & {
|
|
7
10
|
matches: boolean;
|
|
8
11
|
}>;
|
|
9
|
-
export declare function createBreakpointDirectiveUpdater(breakpoints: Breakpoint[], update
|
|
12
|
+
export declare function createBreakpointDirectiveUpdater(breakpoints: Breakpoint[], update?: (target: HTMLElement, change: BreakpointChange) => void): () => void;
|
|
10
13
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/breakpoints.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const BreakpointHideTargetPlugin = (target, change) => {
|
|
5
|
-
target.hidden = !change.matches;
|
|
6
|
-
target.inert = !change.matches;
|
|
7
|
-
};
|
|
8
|
-
const BreakpointClassNamePlugin = (target, change) => {
|
|
9
|
-
const classNames = target.getAttribute("odx-breakpoint-class")?.split(" ") ?? [];
|
|
10
|
-
if (classNames.length === 0) return;
|
|
11
|
-
BreakpointHideTargetPlugin(target, { ...change, matches: true });
|
|
12
|
-
for (const className of classNames) {
|
|
13
|
-
target.classList.toggle(className, change.matches);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
1
|
+
import { effect } from '@preact/signals-core';
|
|
2
|
+
import { signal } from '@odx/foundation/signals';
|
|
3
|
+
import { stringAttributeDirective, booleanAttributeDirective, observeMedia } from '@odx/foundation/utils';
|
|
16
4
|
|
|
17
5
|
const operators = ["<", "<=", ">=", ">"];
|
|
18
6
|
const breakpointDirective = stringAttributeDirective("odx-breakpoint");
|
|
7
|
+
const breakpointClassDirective = stringAttributeDirective("odx-breakpoint-class");
|
|
8
|
+
const breakpointActiveDirective = booleanAttributeDirective({
|
|
9
|
+
name: "odx-breakpoint-active",
|
|
10
|
+
onUpdate: (directive, value) => {
|
|
11
|
+
if (!breakpointClassDirective.applied(directive)) return;
|
|
12
|
+
const classNames = breakpointClassDirective.value(directive)?.split(" ") ?? [];
|
|
13
|
+
for (const className of classNames) {
|
|
14
|
+
directive.classList.toggle(className, value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
19
18
|
function buildBreakpoint(breakpoint, operator) {
|
|
20
19
|
const id = operator ? `${operator}${breakpoint.id}` : breakpoint.id;
|
|
21
20
|
let query = `(min-width: ${breakpoint.min}px) and (max-width: ${breakpoint.max}px)`;
|
|
@@ -35,6 +34,11 @@ function buildBreakpoint(breakpoint, operator) {
|
|
|
35
34
|
}
|
|
36
35
|
return { ...breakpoint, id, operator, query: [query, breakpoint.customQuery].filter(Boolean).join(" and ") };
|
|
37
36
|
}
|
|
37
|
+
function generateBreakpointStyles(breakpoints) {
|
|
38
|
+
const selectors = breakpoints.map((breakpoint) => `[${breakpointDirective.attribute}="${breakpoint.id}"]`);
|
|
39
|
+
const excludedSelectors = [breakpointActiveDirective.selector, breakpointClassDirective.selector].map((selector) => `:not(${selector})`);
|
|
40
|
+
return `:where(${selectors.join(", ")})${excludedSelectors.join("")} { display: none !important; }`;
|
|
41
|
+
}
|
|
38
42
|
function expandBreakpoints(...breakpoints) {
|
|
39
43
|
return breakpoints.flatMap((breakpoint) => [void 0, ...operators].map((operator) => buildBreakpoint(breakpoint, operator)));
|
|
40
44
|
}
|
|
@@ -70,7 +74,8 @@ function createBreakpointDirectiveUpdater(breakpoints, update) {
|
|
|
70
74
|
const directive = directives[i];
|
|
71
75
|
const result = results[breakpointDirective.value(directive) ?? ""];
|
|
72
76
|
if (!result) continue;
|
|
73
|
-
|
|
77
|
+
breakpointActiveDirective.toggle(directive, result.matches);
|
|
78
|
+
update?.(directive, result);
|
|
74
79
|
}
|
|
75
80
|
};
|
|
76
81
|
}
|
|
@@ -82,17 +87,17 @@ const defaultBreakpoints = {
|
|
|
82
87
|
};
|
|
83
88
|
function setupBreakpoints(breakpointsConfig = []) {
|
|
84
89
|
const breakpoints = expandBreakpoints(...Object.values(defaultBreakpoints), ...breakpointsConfig);
|
|
85
|
-
const
|
|
86
|
-
const directiveUpdater = createBreakpointDirectiveUpdater(breakpoints, (target, change) => {
|
|
87
|
-
for (const plugin of plugins) {
|
|
88
|
-
plugin(target, change);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
90
|
+
const directiveUpdater = createBreakpointDirectiveUpdater(breakpoints);
|
|
91
91
|
let mutationObserver;
|
|
92
92
|
let unobserveBreakpoints = () => {
|
|
93
93
|
};
|
|
94
|
+
let stylesElement;
|
|
94
95
|
function initBreakpoints() {
|
|
95
96
|
destroyBreakpoints();
|
|
97
|
+
stylesElement ??= document.createElement("style");
|
|
98
|
+
stylesElement.id = "odx-breakpoint-styles";
|
|
99
|
+
stylesElement.textContent = generateBreakpointStyles(breakpoints);
|
|
100
|
+
document.head.appendChild(stylesElement);
|
|
96
101
|
mutationObserver = new MutationObserver(directiveUpdater);
|
|
97
102
|
unobserveBreakpoints = effect(directiveUpdater);
|
|
98
103
|
mutationObserver.observe(document.documentElement, {
|
|
@@ -103,6 +108,7 @@ function setupBreakpoints(breakpointsConfig = []) {
|
|
|
103
108
|
});
|
|
104
109
|
}
|
|
105
110
|
function destroyBreakpoints() {
|
|
111
|
+
stylesElement && document.head.removeChild(stylesElement);
|
|
106
112
|
unobserveBreakpoints();
|
|
107
113
|
mutationObserver?.disconnect();
|
|
108
114
|
globalThis.removeEventListener("DOMContentLoaded", initBreakpoints);
|
|
@@ -111,4 +117,4 @@ function setupBreakpoints(breakpointsConfig = []) {
|
|
|
111
117
|
return destroyBreakpoints;
|
|
112
118
|
}
|
|
113
119
|
|
|
114
|
-
export {
|
|
120
|
+
export { breakpointActiveDirective, breakpointClassDirective, breakpointDirective, buildBreakpoint, createBreakpointDirectiveUpdater, setupBreakpoints as default, defaultBreakpoints, expandBreakpoints, generateBreakpointStyles, observeBreakpoint };
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@odx/foundation",
|
|
3
3
|
"displayName": "ODX Design System Foundation",
|
|
4
4
|
"description": "A library of Web Component building blocks for ODX",
|
|
5
|
-
"version": "1.0.0-beta.
|
|
5
|
+
"version": "1.0.0-beta.238",
|
|
6
6
|
"author": "Drägerwerk AG & Co.KGaA",
|
|
7
7
|
"license": "SEE LICENSE IN LICENSE",
|
|
8
8
|
"homepage": "https://odx.draeger.com",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@odx/icons": "^4.0.0-rc.49",
|
|
25
|
-
"@odx/design-tokens": "^2.
|
|
25
|
+
"@odx/design-tokens": "^2.3.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@floating-ui/dom": "1.7.4",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"@odx-internal/config-stylelint": "0.0.0",
|
|
36
36
|
"@odx-internal/config-typescript": "0.0.0",
|
|
37
37
|
"@odx-internal/config-vite": "0.0.0",
|
|
38
|
-
"@odx
|
|
39
|
-
"@odx/
|
|
38
|
+
"@odx/design-tokens": "2.3.0",
|
|
39
|
+
"@odx-internal/utils-storybook": "0.0.0"
|
|
40
40
|
},
|
|
41
41
|
"sideEffects": [
|
|
42
42
|
"dist/components-loader.js",
|