@mustib/web-components 0.0.0-alpha.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,124 @@
1
+ import { M as MUElement, _ as __decorate } from '../mu-element-CZDI_RCY.js';
2
+ import { property } from 'lit/decorators.js';
3
+ import { css, html } from 'lit';
4
+ import { staticProperty } from '../decorators.js';
5
+
6
+ /**
7
+ * This element is designed to be stateless, its purpose is to provide a means of adding custom markup and attributes
8
+ * without the need for controlling its state externally. It should not be modified by other parties, and its state is
9
+ * solely controlled by its controller.
10
+ */
11
+ class MuSelectItem extends MUElement {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.eventActionData = undefined;
15
+ this.value = this.innerText;
16
+ this.selected = false;
17
+ this.active = false;
18
+ this.filteredOut = false;
19
+ }
20
+ firstUpdated(_changedProperties) {
21
+ if (this.selected) {
22
+ console.warn('selected attribute should not be set on mu-select-item, please follow the proper way to add it through the controller', this);
23
+ }
24
+ if (this.active) {
25
+ console.warn('active attribute should not be set on mu-select-item, please follow the proper way to add it through the controller', this);
26
+ }
27
+ }
28
+ connectedCallback() {
29
+ super.connectedCallback();
30
+ this.setAttribute('role', 'option');
31
+ this.setAttribute('aria-label', this.value);
32
+ }
33
+ _addEventActionAttributes() {
34
+ this.setAttribute('data-items-pointerdown', `#prevent`);
35
+ this.setAttribute('data-items-click', `opened? toggle-select:${this.value}`);
36
+ this.setAttribute('data-items-pointerover', `#prevent && opened? set-active:${this.value}`);
37
+ }
38
+ updated(changed) {
39
+ if (changed.has('selected')) {
40
+ this.ariaSelected = `${!!this.selected}`;
41
+ }
42
+ if (changed.has('disabled')) {
43
+ this.ariaDisabled = `${!!this.disabled}`;
44
+ }
45
+ }
46
+ render() {
47
+ return html `
48
+ <div id='container' part='container'>
49
+ <slot></slot>
50
+ </div>
51
+ `;
52
+ }
53
+ }
54
+ MuSelectItem.styles = [MUElement.cssBase, css `
55
+ :host {
56
+ overflow: hidden;
57
+ }
58
+
59
+ :host([filtered-out]) {
60
+ display: none;
61
+ }
62
+
63
+ :host(:focus-visible) #container {
64
+ ${MUElement.css.focus}
65
+ }
66
+
67
+ :host([active]) #container {
68
+ --select-items-background-color: var(--mu-color-500);
69
+ }
70
+
71
+ :host([selected]) #container {
72
+ --select-items-background-color: var(--mu-color-700);
73
+ }
74
+
75
+ :host([selected][active]) #container {
76
+ --select-items-background-color: var(--mu-color-600);
77
+ }
78
+
79
+ #container {
80
+ --select-items-background-color: var(--mu-select-items-background-color, unset);
81
+ cursor: pointer;
82
+ user-select: none;
83
+ padding: calc(var(--mu-base-rem) * .5) calc(var(--mu-base-rem) * 1.2);
84
+ border-radius: calc(var(--mu-base-rem) * 1);
85
+ transition: all 0.1s ease-in-out;
86
+ background-color: var(--select-items-background-color);
87
+ }
88
+
89
+ @media (prefers-color-scheme: light) {
90
+ :host([active]) #container {
91
+ --select-items-background-color: var(--mu-color-200);
92
+ }
93
+
94
+ :host([selected]) #container {
95
+ --select-items-background-color: var(--mu-color-400);
96
+ }
97
+
98
+ :host([selected][active]) #container {
99
+ --select-items-background-color: var(--mu-color-300);
100
+ }
101
+ }
102
+ `];
103
+ __decorate([
104
+ staticProperty()
105
+ ], MuSelectItem.prototype, "value", void 0);
106
+ __decorate([
107
+ property({
108
+ reflect: true, type: Boolean,
109
+ })
110
+ ], MuSelectItem.prototype, "selected", void 0);
111
+ __decorate([
112
+ property({
113
+ reflect: true, type: Boolean,
114
+ })
115
+ ], MuSelectItem.prototype, "active", void 0);
116
+ __decorate([
117
+ property({
118
+ reflect: true, type: Boolean,
119
+ attribute: 'filtered-out',
120
+ })
121
+ ], MuSelectItem.prototype, "filteredOut", void 0);
122
+ MuSelectItem.register("mu-select-item");
123
+
124
+ export { MuSelectItem };
@@ -0,0 +1,218 @@
1
+ import { MUElement } from './mu-element.js';
2
+ import { PropertyValues } from 'lit';
3
+ import { MuSelectItem } from './mu-select-item.js';
4
+ import { EventAction, GenerateData } from '@mustib/utils/browser';
5
+
6
+ type SelectItem = {
7
+ element: MuSelectItem;
8
+ value: string;
9
+ selected: boolean;
10
+ active: boolean;
11
+ index: number;
12
+ };
13
+ type MuSelectItemsEvents = {
14
+ /**
15
+ * this event is dispatched whenever the user selects an item
16
+ */
17
+ "mu-select-items-change": CustomEvent<{
18
+ /**
19
+ * selected values
20
+ */
21
+ values: string[];
22
+ /**
23
+ * a boolean indicating if the dispatched values are the current selected values of the component,
24
+ *
25
+ * if the component is controlled, this will be false, and the dispatched values are the ones applied by the user.
26
+ *
27
+ * if the component is uncontrolled, this will be true, and the dispatched values are the current selected values of the component.
28
+ */
29
+ isCurrentSelection: boolean;
30
+ }>;
31
+ /**
32
+ * this event is dispatched whenever a slot items change and there are selected items that are no longer in the slot
33
+ */
34
+ "mu-select-items-change-orphans": CustomEvent<{
35
+ /**
36
+ * selected values that are no longer in the slot
37
+ */
38
+ orphanValues: string[];
39
+ /**
40
+ * selected values that are still in the slot
41
+ */
42
+ values: string[];
43
+ }>;
44
+ /**
45
+ * This event is dispatched when the selected items change without user interaction.
46
+ *
47
+ * This happens when the `value` attribute changes or the `defaultValue` attribute is set for the first time.
48
+ *
49
+ * This event is intended for internal usage, so dependent mu elements can update their values.
50
+ *
51
+ * The normal `mu-select-items-change` event is not dispatched in this case, as the controller is already aware of the change.
52
+ *
53
+ * In the default value case, the normal event should not be dispatched either, because the user didn't interact with the select, and the value is forced initially.
54
+ */
55
+ "mu-select-items-change-forced": CustomEvent<{
56
+ /**
57
+ * selected values that are forced
58
+ */
59
+ values: string[];
60
+ }>;
61
+ /**
62
+ * this event is dispatched whenever the active item changes
63
+ */
64
+ "mu-select-items-active-item-change": CustomEvent<{
65
+ id: string | undefined;
66
+ }>;
67
+ };
68
+ type SwitchActiveItemOptions = Partial<{
69
+ /**
70
+ * A `boolean` indicates if the selection should wrap around to the start/end
71
+ */
72
+ switchBack: boolean;
73
+ }>;
74
+ declare class MuSelectItems extends MUElement {
75
+ static styles: any[];
76
+ static eventAction: EventAction<GenerateData<MuSelectItems>>;
77
+ opened: boolean;
78
+ multiple: boolean;
79
+ value?: string[];
80
+ noClearActiveOnClose: boolean;
81
+ defaultValue?: string;
82
+ position: 'absolute' | 'fixed';
83
+ /**
84
+ * Controls how the items container behaves when opened.
85
+ *
86
+ * - `'static'`: Position is calculated once when opened or closed.
87
+ * - `'no-scroll'`: Like static, but page scroll is disabled.
88
+ * - `'dynamic'`: Position is recalculated on scroll.
89
+ *
90
+ * @default 'no-scroll'
91
+ */
92
+ openMode: 'static' | 'no-scroll' | 'dynamic';
93
+ eventActionData: {
94
+ eventAction: EventAction<GenerateData<MuSelectItems>>;
95
+ events: string[];
96
+ };
97
+ _addEventActionAttributes: undefined;
98
+ get isControlled(): boolean | undefined;
99
+ get parentElement(): any;
100
+ protected _resizeObserver?: ResizeObserver;
101
+ protected _isReady: Readonly<{
102
+ status: "success" | "fail" | "pending";
103
+ resolved: boolean;
104
+ promise: Promise<boolean>;
105
+ resolve: () => void;
106
+ }>;
107
+ protected _items: SelectItem[];
108
+ protected _itemsValuesMap: Map<string, SelectItem>;
109
+ protected _itemsElementsMap: Map<MuSelectItem, SelectItem>;
110
+ protected _activeItem?: SelectItem;
111
+ protected _selectedValues: Set<string>;
112
+ get activeValue(): string | undefined;
113
+ getValue(): string[];
114
+ connectedCallback(): void;
115
+ /**
116
+ *
117
+ */
118
+ disconnectedCallback(): void;
119
+ unselect(values: string[]): void;
120
+ unselectAll(): void;
121
+ unselectLatestItem(): void;
122
+ toggleActiveItemSelect(): void;
123
+ /**
124
+ * Calculates the position of the items container.
125
+ */
126
+ protected _calculateSizes: () => void;
127
+ /**
128
+ * Focuses the first navigable item in the given direction.
129
+ *
130
+ * If an active item already exists, it will be focused.
131
+ *
132
+ * Used by parent to focus the first or last navigable item when opened
133
+ */
134
+ focusFirstNavigableItem(direction: 'next' | 'prev'): void;
135
+ protected _getNavigationItem({ direction, switchBack, fromIndex }: {
136
+ fromIndex?: number;
137
+ direction: 'next' | 'prev';
138
+ switchBack: boolean;
139
+ }): SelectItem | undefined;
140
+ /**
141
+ * Add active state to the next or previous item from the current active item.
142
+ */
143
+ switchActiveItem(direction: 'next' | 'prev', options?: SwitchActiveItemOptions): true | undefined;
144
+ protected _addActiveItemState(item: SelectItem | undefined): true | undefined;
145
+ clearFilteredOutItems(): void;
146
+ filterOutItems(value: string): void;
147
+ /**
148
+ * Dispatches an event with the active item id, so parent can update aria-activedescendant
149
+ */
150
+ protected _dispatchActiveItemChange({ id }: {
151
+ id: string | undefined;
152
+ }): void;
153
+ /**
154
+ *
155
+ */
156
+ clearActiveItem(): void;
157
+ /**
158
+ *
159
+ */
160
+ protected getMuSelectItemFromEvent(e: Event): SelectItem | undefined;
161
+ /**
162
+ *
163
+ */
164
+ protected _slotChangeHandler: () => void;
165
+ /**
166
+ *
167
+ */
168
+ protected _addSelectState(item: SelectItem | undefined): void;
169
+ /**
170
+ *
171
+ */
172
+ protected _removeSelectState(item: SelectItem | undefined): void;
173
+ /**
174
+ *
175
+ */
176
+ protected _clearSelectState(): void;
177
+ _dispatchChangeEvent(detail: MuSelectItemsEvents['mu-select-items-change']['detail']): void;
178
+ _debounceDispatchChangeEvent: (detail: MuSelectItemsEvents["mu-select-items-change"]["detail"]) => void;
179
+ /**
180
+ * Modifies the selection state of a specified item.
181
+ * @param type Specifies the operation to perform:
182
+ *
183
+ * `'add'` - Adds the item to the selection.
184
+ *
185
+ * `'add-only'` - Clears previous selections and adds the item.
186
+ *
187
+ * `'remove'` - Removes the item from the selection.
188
+ *
189
+ * `'toggle'` - Toggles the item's selection state.
190
+ *
191
+ * Upon completion, a 'muSelectItemsValueChange' event is dispatched.
192
+ */
193
+ protected _changeSelectState(type: 'add' | 'add-only' | 'remove' | 'toggle', _item: SelectItem | string | undefined): void;
194
+ /**
195
+ * This method is called when the 'value' attribute changes or the first time 'defaultValue' is set.
196
+ *
197
+ * It does not fire the 'mu-select-items-change' event but instead fires the 'mu-select-items-change-forced' event.
198
+ */
199
+ protected _changeSelectStateFromAttributeValue(value: string | undefined | null | string[]): void;
200
+ /**
201
+ * This method handles open state changes
202
+ */
203
+ protected _openChangeHandler(): void;
204
+ protected getUpdateComplete(): Promise<boolean>;
205
+ protected firstUpdated(_changedProperties: PropertyValues<this>): Promise<void>;
206
+ protected updated(changedProperties: PropertyValues<this>): Promise<void>;
207
+ protected render(): unknown;
208
+ }
209
+ declare global {
210
+ interface HTMLElementTagNameMap {
211
+ "mu-select-items": MuSelectItems;
212
+ }
213
+ interface GlobalEventHandlersEventMap extends MuSelectItemsEvents {
214
+ }
215
+ }
216
+
217
+ export { MuSelectItems };
218
+ export type { MuSelectItemsEvents };