@momentum-design/components 0.125.1 → 0.126.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,7 @@
1
+ import ResponsiveSettingsProvider from './responsivesettingsprovider.component';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ ['mdc-responsivesettingsprovider']: ResponsiveSettingsProvider;
5
+ }
6
+ }
7
+ export default ResponsiveSettingsProvider;
@@ -0,0 +1,4 @@
1
+ import ResponsiveSettingsProvider from './responsivesettingsprovider.component';
2
+ import { TAG_NAME } from './responsivesettingsprovider.constants';
3
+ ResponsiveSettingsProvider.register(TAG_NAME);
4
+ export default ResponsiveSettingsProvider;
@@ -0,0 +1,11 @@
1
+ import type { ResponsiveMediaType, ResponsivePopoverPositions, ResponsiveSettings } from './responsivesettingsprovider.types';
2
+ declare class ResponsiveSettingsContext {
3
+ media: ResponsiveMediaType;
4
+ forceFullscreenDialog: boolean;
5
+ popoverPositioning: ResponsivePopoverPositions;
6
+ static context: {
7
+ __context__: ResponsiveSettings;
8
+ };
9
+ constructor(options?: Partial<ResponsiveSettings>);
10
+ }
11
+ export default ResponsiveSettingsContext;
@@ -0,0 +1,14 @@
1
+ import { createContext } from '@lit/context';
2
+ import { DEFAULTS, TAG_NAME } from './responsivesettingsprovider.constants';
3
+ class ResponsiveSettingsContext {
4
+ // constructor to allow setting the defaultThemeClass
5
+ constructor(options = {}) {
6
+ this.media = DEFAULTS.MEDIA;
7
+ this.forceFullscreenDialog = DEFAULTS.FORCE_FULLSCREEN_DIALOG;
8
+ this.popoverPositioning = DEFAULTS.POPOVER_POSITIONING;
9
+ Object.assign(this, options); // assign provided options to
10
+ }
11
+ }
12
+ // create typed lit context as part of the ThemeProviderContext
13
+ ResponsiveSettingsContext.context = createContext(TAG_NAME);
14
+ export default ResponsiveSettingsContext;
@@ -0,0 +1,65 @@
1
+ import { Provider } from '../../models';
2
+ import type { ResponsiveMediaType, ResponsivePopoverPositions, ResponsiveSettings } from './responsivesettingsprovider.types';
3
+ /**
4
+ * `mdc-responsivesettingsprovider` is a provider component that supplies responsive settings
5
+ * context to its child components.
6
+ *
7
+ * This component does not make any assumptions about how the values are determined. Values can be set
8
+ * based on media queries or other device detection mechanisms.This way consumer can mix and match
9
+ * different settings depending on their target devices and use cases.
10
+ *
11
+ * For example, when the device has table screen size/resolution, but because it is fixed dialog like
12
+ * popovers provide better user experience.
13
+ *
14
+ * ## Responsive settings
15
+ *
16
+ * ### Media
17
+ *
18
+ * Generic media type to enforce responsive behavior in child components.
19
+ * Consumer component can use the media type from the context or
20
+ * just use CSS selector like [media="mobile"] to apply responsive styles.
21
+ *
22
+ * It is "unknown" by default so components can fall back to there default behavior.
23
+ *
24
+ * ### Popover Positioning
25
+ *
26
+ * By default, popovers are positioned close to the trigger element. But on small screens (e.g.: mobile devices),
27
+ * it is often better to show popovers/menus at the center of the screen like dialogs.
28
+ *
29
+ * ### Force Fullscreen Dialog
30
+ *
31
+ * Some components like dialogs can be shown in fullscreen mode on small screens for better user experience.
32
+ *
33
+ * @tagname mdc-responsivesettingsprovider
34
+ */
35
+ declare class ResponsiveSettingsProvider extends Provider<ResponsiveSettings> {
36
+ constructor();
37
+ /**
38
+ * Context object of the ResponsiveSettingsProvider, to be consumed by child components
39
+ */
40
+ static get Context(): {
41
+ __context__: ResponsiveSettings;
42
+ };
43
+ /**
44
+ * Determines whether dialogs should be forced to fullscreen mode.
45
+ */
46
+ forceFullscreenDialog: boolean;
47
+ /** @internal */
48
+ private privatePopoverPositioning;
49
+ /**
50
+ * The popover positioning for responsive settings.
51
+ * @default 'float'
52
+ */
53
+ set popoverPositioning(value: ResponsivePopoverPositions);
54
+ get popoverPositioning(): ResponsivePopoverPositions;
55
+ /** @internal */
56
+ private privateMedia;
57
+ /**
58
+ * The media type for responsive settings.
59
+ * @default 'unknown'
60
+ */
61
+ set media(value: ResponsiveMediaType);
62
+ get media(): ResponsiveMediaType;
63
+ protected updateContext(): void;
64
+ }
65
+ export default ResponsiveSettingsProvider;
@@ -0,0 +1,122 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { property } from 'lit/decorators.js';
11
+ import { Provider } from '../../models';
12
+ import ResponsiveSettingsContext from './responsiveSettingsContext';
13
+ import { DEFAULTS, VALID_MEDIA_VALUES, VALID_POPOVER_POSITIONING_VALUES } from './responsivesettingsprovider.constants';
14
+ /**
15
+ * `mdc-responsivesettingsprovider` is a provider component that supplies responsive settings
16
+ * context to its child components.
17
+ *
18
+ * This component does not make any assumptions about how the values are determined. Values can be set
19
+ * based on media queries or other device detection mechanisms.This way consumer can mix and match
20
+ * different settings depending on their target devices and use cases.
21
+ *
22
+ * For example, when the device has table screen size/resolution, but because it is fixed dialog like
23
+ * popovers provide better user experience.
24
+ *
25
+ * ## Responsive settings
26
+ *
27
+ * ### Media
28
+ *
29
+ * Generic media type to enforce responsive behavior in child components.
30
+ * Consumer component can use the media type from the context or
31
+ * just use CSS selector like [media="mobile"] to apply responsive styles.
32
+ *
33
+ * It is "unknown" by default so components can fall back to there default behavior.
34
+ *
35
+ * ### Popover Positioning
36
+ *
37
+ * By default, popovers are positioned close to the trigger element. But on small screens (e.g.: mobile devices),
38
+ * it is often better to show popovers/menus at the center of the screen like dialogs.
39
+ *
40
+ * ### Force Fullscreen Dialog
41
+ *
42
+ * Some components like dialogs can be shown in fullscreen mode on small screens for better user experience.
43
+ *
44
+ * @tagname mdc-responsivesettingsprovider
45
+ */
46
+ class ResponsiveSettingsProvider extends Provider {
47
+ constructor() {
48
+ // initialise the context by running the Provider constructor:
49
+ super({
50
+ context: ResponsiveSettingsContext.context,
51
+ initialValue: new ResponsiveSettingsContext({
52
+ media: DEFAULTS.MEDIA,
53
+ popoverPositioning: DEFAULTS.POPOVER_POSITIONING,
54
+ forceFullscreenDialog: DEFAULTS.FORCE_FULLSCREEN_DIALOG,
55
+ }),
56
+ });
57
+ /**
58
+ * Determines whether dialogs should be forced to fullscreen mode.
59
+ */
60
+ this.forceFullscreenDialog = DEFAULTS.FORCE_FULLSCREEN_DIALOG;
61
+ /** @internal */
62
+ this.privatePopoverPositioning = DEFAULTS.POPOVER_POSITIONING;
63
+ /** @internal */
64
+ this.privateMedia = DEFAULTS.MEDIA;
65
+ }
66
+ /**
67
+ * Context object of the ResponsiveSettingsProvider, to be consumed by child components
68
+ */
69
+ static get Context() {
70
+ return ResponsiveSettingsContext.context;
71
+ }
72
+ /**
73
+ * The popover positioning for responsive settings.
74
+ * @default 'float'
75
+ */
76
+ set popoverPositioning(value) {
77
+ if (VALID_POPOVER_POSITIONING_VALUES.includes(value)) {
78
+ this.privatePopoverPositioning = value;
79
+ }
80
+ }
81
+ get popoverPositioning() {
82
+ return this.privatePopoverPositioning;
83
+ }
84
+ /**
85
+ * The media type for responsive settings.
86
+ * @default 'unknown'
87
+ */
88
+ set media(value) {
89
+ if (VALID_MEDIA_VALUES.includes(value)) {
90
+ this.privateMedia = value;
91
+ }
92
+ }
93
+ get media() {
94
+ return this.privateMedia;
95
+ }
96
+ updateContext() {
97
+ var _a, _b, _c;
98
+ if (((_a = this.context.value) === null || _a === void 0 ? void 0 : _a.media) !== this.privateMedia ||
99
+ ((_b = this.context.value) === null || _b === void 0 ? void 0 : _b.popoverPositioning) !== this.privatePopoverPositioning ||
100
+ ((_c = this.context.value) === null || _c === void 0 ? void 0 : _c.forceFullscreenDialog) !== this.forceFullscreenDialog) {
101
+ this.context.value.media = this.media;
102
+ this.context.value.popoverPositioning = this.popoverPositioning;
103
+ this.context.value.forceFullscreenDialog = this.forceFullscreenDialog;
104
+ this.context.updateObservers();
105
+ }
106
+ }
107
+ }
108
+ __decorate([
109
+ property({ type: Boolean, attribute: 'force-fullscreen-dialog', reflect: true }),
110
+ __metadata("design:type", Boolean)
111
+ ], ResponsiveSettingsProvider.prototype, "forceFullscreenDialog", void 0);
112
+ __decorate([
113
+ property({ type: String, attribute: 'popover-positioning', reflect: true }),
114
+ __metadata("design:type", String),
115
+ __metadata("design:paramtypes", [String])
116
+ ], ResponsiveSettingsProvider.prototype, "popoverPositioning", null);
117
+ __decorate([
118
+ property({ type: String, attribute: 'media', reflect: true }),
119
+ __metadata("design:type", String),
120
+ __metadata("design:paramtypes", [String])
121
+ ], ResponsiveSettingsProvider.prototype, "media", null);
122
+ export default ResponsiveSettingsProvider;
@@ -0,0 +1,9 @@
1
+ import type { ResponsiveMediaType, ResponsivePopoverPositions } from './responsivesettingsprovider.types';
2
+ export declare const TAG_NAME: "mdc-responsivesettingsprovider";
3
+ export declare const DEFAULTS: {
4
+ readonly FORCE_FULLSCREEN_DIALOG: false;
5
+ readonly POPOVER_POSITIONING: "float";
6
+ readonly MEDIA: "unknown";
7
+ };
8
+ export declare const VALID_POPOVER_POSITIONING_VALUES: ResponsivePopoverPositions[];
9
+ export declare const VALID_MEDIA_VALUES: ResponsiveMediaType[];
@@ -0,0 +1,9 @@
1
+ import utils from '../../utils/tag-name';
2
+ export const TAG_NAME = utils.constructTagName('responsivesettingsprovider');
3
+ export const DEFAULTS = {
4
+ FORCE_FULLSCREEN_DIALOG: false,
5
+ POPOVER_POSITIONING: 'float',
6
+ MEDIA: 'unknown',
7
+ };
8
+ export const VALID_POPOVER_POSITIONING_VALUES = ['float', 'dialog'];
9
+ export const VALID_MEDIA_VALUES = ['unknown', 'mobile', 'desktop', 'tablet'];
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Defines the type of media device.
3
+ * - 'unknown' - Represents an unknown device type.
4
+ * - 'desktop' - Represents desktop devices.
5
+ * - 'tablet' - Represents tablet devices.
6
+ * - 'mobile' - Represents mobile devices.
7
+ */
8
+ export type ResponsiveMediaType = 'unknown' | 'mobile' | 'desktop' | 'tablet';
9
+ /**
10
+ * Defines how popovers are positioned within the dialog.
11
+ * - 'float': Popovers are positioned next to the triggering element.
12
+ * - 'dialog': Popovers are positioned at the center of the scree like dialogs.
13
+ */
14
+ export type ResponsivePopoverPositions = 'float' | 'dialog';
15
+ /**
16
+ * Context type for ResponsiveSettingsProvider, combining responsive settings options with the current media type.
17
+ */
18
+ export type ResponsiveSettings = {
19
+ /** Enforced media device type. */
20
+ media: ResponsiveMediaType;
21
+ /** If true, dialogs will be forced to fullscreen mode on small screens. */
22
+ forceFullscreenDialog: boolean;
23
+ /** Defines how popovers are positioned. */
24
+ popoverPositioning: ResponsivePopoverPositions;
25
+ };