@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.
- package/README.md +17 -0
- package/components/mu-element.d.ts +107 -0
- package/components/mu-element.js +4 -0
- package/components/mu-icon.d.ts +25 -0
- package/components/mu-icon.js +65 -0
- package/components/mu-range-fill.d.ts +48 -0
- package/components/mu-range-fill.js +94 -0
- package/components/mu-range-thumb-value.d.ts +48 -0
- package/components/mu-range-thumb-value.js +137 -0
- package/components/mu-range-thumb.d.ts +120 -0
- package/components/mu-range-thumb.js +305 -0
- package/components/mu-range.d.ts +206 -0
- package/components/mu-range.js +661 -0
- package/components/mu-select-item.d.ts +29 -0
- package/components/mu-select-item.js +124 -0
- package/components/mu-select-items.d.ts +218 -0
- package/components/mu-select-items.js +570 -0
- package/components/mu-select-label-content.d.ts +38 -0
- package/components/mu-select-label-content.js +159 -0
- package/components/mu-select-label.d.ts +52 -0
- package/components/mu-select-label.js +352 -0
- package/components/mu-select.d.ts +63 -0
- package/components/mu-select.js +347 -0
- package/components/mu-transparent.d.ts +56 -0
- package/components/mu-transparent.js +75 -0
- package/components/mu-trigger.d.ts +129 -0
- package/components/mu-trigger.js +175 -0
- package/decorators.d.ts +34 -0
- package/decorators.js +50 -0
- package/index.d.ts +15 -0
- package/index.js +17 -0
- package/mu-element-CZDI_RCY.js +1117 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Under Development
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm i @mustib/web-components@alpha
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
This library is under development and is not ready for production use yet.
|
|
10
|
+
|
|
11
|
+
You can clone the repository, run `pnpm install` then `pnpm dev`, and open your browser to view the demos.
|
|
12
|
+
|
|
13
|
+
This package contains web components that are built using the amazing [Lit](https://lit.dev/) library and it is required to be installed as a peer dependency.
|
|
14
|
+
|
|
15
|
+
it's built from the ground up to be very easy to use, extend, and with customization in mind as it doesn't force any restrictions.
|
|
16
|
+
|
|
17
|
+
you are free to even use your own markup, styles, and logic if you want and, still have everything work out of the box, or even customize a specific feature.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import { closestPierce, EventAction } from '@mustib/utils/browser';
|
|
3
|
+
|
|
4
|
+
type Elements = [
|
|
5
|
+
'mu-select-item',
|
|
6
|
+
'mu-select-items',
|
|
7
|
+
'mu-transparent',
|
|
8
|
+
'mu-trigger',
|
|
9
|
+
'mu-select',
|
|
10
|
+
'mu-select-label',
|
|
11
|
+
'mu-select-label-content',
|
|
12
|
+
'mu-keyboard-trigger',
|
|
13
|
+
'mu-keyboard-trigger-key',
|
|
14
|
+
'mu-range',
|
|
15
|
+
'mu-range-fill',
|
|
16
|
+
'mu-range-thumb',
|
|
17
|
+
'mu-range-thumb-value',
|
|
18
|
+
'mu-icon'
|
|
19
|
+
];
|
|
20
|
+
declare abstract class MUElement extends LitElement {
|
|
21
|
+
#private;
|
|
22
|
+
static closestPierce: typeof closestPierce;
|
|
23
|
+
static register(this: {
|
|
24
|
+
new (): MUElement;
|
|
25
|
+
}, tagName: Elements[number]): void;
|
|
26
|
+
static css: {
|
|
27
|
+
focus: any;
|
|
28
|
+
};
|
|
29
|
+
static cssColors: any;
|
|
30
|
+
static cssBase: any;
|
|
31
|
+
disabled: boolean;
|
|
32
|
+
readonly: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* If true, do not add {@link https://mustib.github.io/mustib-utils/v2/utilities/browser/eventaction/ event action} attributes
|
|
35
|
+
*
|
|
36
|
+
* By default mu-element will call `_addEventActionAttributes` in connectedCallback if it is not undefined and `noEventActionAttributes` is false
|
|
37
|
+
*/
|
|
38
|
+
private noEventActionAttributes;
|
|
39
|
+
/**
|
|
40
|
+
* This function is used to add {@link https://mustib.github.io/mustib-utils/v2/utilities/browser/eventaction/ event action} attributes for all related elements belongs to this element
|
|
41
|
+
*
|
|
42
|
+
* It is called in connectedCallback if `noEventActionAttributes` is false
|
|
43
|
+
*/
|
|
44
|
+
protected abstract _addEventActionAttributes?(): void;
|
|
45
|
+
/**
|
|
46
|
+
* This object should be used if the element supports {@link https://mustib.github.io/mustib-utils/v2/utilities/browser/eventaction/ event action}.
|
|
47
|
+
*
|
|
48
|
+
* `mu-element` will automatically add events when element is connected and remove them when element is disconnected
|
|
49
|
+
*/
|
|
50
|
+
abstract eventActionData: undefined | {
|
|
51
|
+
eventAction: EventAction<unknown>;
|
|
52
|
+
/**
|
|
53
|
+
* A list of default events names to add {@link https://mustib.github.io/mustib-utils/v2/utilities/browser/eventaction/ event action} listeners
|
|
54
|
+
*/
|
|
55
|
+
events: string[];
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* A user customizable list of events names to add {@link https://mustib.github.io/mustib-utils/v2/utilities/browser/eventaction/ event action} listeners if the element has the `eventActionData` property
|
|
59
|
+
*/
|
|
60
|
+
protected readonly eventActionEvents?: string[];
|
|
61
|
+
get interactable(): boolean;
|
|
62
|
+
muId: string;
|
|
63
|
+
constructor();
|
|
64
|
+
generateIsReadyPromise({ timeout, onTimeout }?: {
|
|
65
|
+
timeout?: number;
|
|
66
|
+
onTimeout?: () => void;
|
|
67
|
+
}): Readonly<{
|
|
68
|
+
status: "success" | "fail" | "pending";
|
|
69
|
+
resolved: boolean;
|
|
70
|
+
promise: Promise<boolean>;
|
|
71
|
+
resolve: () => void;
|
|
72
|
+
}>;
|
|
73
|
+
getMuElementById(id: string): {
|
|
74
|
+
element: MUElement;
|
|
75
|
+
} | undefined;
|
|
76
|
+
closestPierce(selector: string): HTMLElement | null;
|
|
77
|
+
/**
|
|
78
|
+
* This method gets the next or previous navigable item from the given index.
|
|
79
|
+
*
|
|
80
|
+
* If an item not found and switchBack is true, it will go the other direction to find an item
|
|
81
|
+
*
|
|
82
|
+
* It takes An optional object with the following properties:
|
|
83
|
+
* - `fromIndex` - The index to start searching from.
|
|
84
|
+
*
|
|
85
|
+
* - `direction` - The direction to search in, can be (`next` or `prev`).
|
|
86
|
+
*
|
|
87
|
+
* - `switchBack` - A boolean Whether to search in the other direction if an item is not found.
|
|
88
|
+
*
|
|
89
|
+
* - `items` - The array of items to search in.
|
|
90
|
+
*
|
|
91
|
+
* - `isNavigable` - A function that takes an item and returns a boolean indicating whether the item is navigable.
|
|
92
|
+
*
|
|
93
|
+
* - `shouldBreak` - An optional function that takes an item and returns a boolean indicating whether to break the loop.
|
|
94
|
+
*/
|
|
95
|
+
getNavigationItem<T>(data: {
|
|
96
|
+
fromIndex?: number;
|
|
97
|
+
direction: 'next' | 'prev';
|
|
98
|
+
switchBack?: boolean;
|
|
99
|
+
items: T[];
|
|
100
|
+
isNavigable: (item: T) => boolean;
|
|
101
|
+
shouldBreak?: (item: T) => boolean;
|
|
102
|
+
}): T | undefined;
|
|
103
|
+
connectedCallback(): void;
|
|
104
|
+
disconnectedCallback(): void;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { MUElement };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CSSResultGroup, PropertyValues } from 'lit';
|
|
2
|
+
import { MUElement } from './mu-element.js';
|
|
3
|
+
import '@mustib/utils/browser';
|
|
4
|
+
|
|
5
|
+
declare class MuIcon extends MUElement {
|
|
6
|
+
static styles?: CSSResultGroup | undefined;
|
|
7
|
+
eventActionData: undefined;
|
|
8
|
+
_addEventActionAttributes: undefined;
|
|
9
|
+
static icons: {
|
|
10
|
+
downArrow: any;
|
|
11
|
+
close: any;
|
|
12
|
+
closeLine: any;
|
|
13
|
+
noImage: any;
|
|
14
|
+
};
|
|
15
|
+
name?: keyof typeof MuIcon.icons;
|
|
16
|
+
protected firstUpdated(_changedProperties: PropertyValues): void;
|
|
17
|
+
protected render(): unknown;
|
|
18
|
+
}
|
|
19
|
+
declare global {
|
|
20
|
+
interface HTMLElementTagNameMap {
|
|
21
|
+
'mu-icon': MuIcon;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { MuIcon };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { M as MUElement, _ as __decorate } from '../mu-element-CZDI_RCY.js';
|
|
2
|
+
import { css, html } from 'lit';
|
|
3
|
+
import { staticProperty } from '../decorators.js';
|
|
4
|
+
import 'lit/decorators.js';
|
|
5
|
+
|
|
6
|
+
class MuIcon extends MUElement {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.eventActionData = undefined;
|
|
10
|
+
this._addEventActionAttributes = undefined;
|
|
11
|
+
}
|
|
12
|
+
firstUpdated(_changedProperties) {
|
|
13
|
+
const iconName = this.name;
|
|
14
|
+
if (!iconName || !MuIcon.icons[iconName]) {
|
|
15
|
+
console.warn(`There is no icon named (${iconName})`, this);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
render() {
|
|
19
|
+
const name = this.name;
|
|
20
|
+
const icon = name && Reflect.has(MuIcon.icons, name) ? MuIcon.icons[name] : MuIcon.icons['noImage'];
|
|
21
|
+
return name ? html `
|
|
22
|
+
<div id='container' part='container'>
|
|
23
|
+
${icon}
|
|
24
|
+
</div>
|
|
25
|
+
` : undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
MuIcon.styles = [MUElement.cssBase, css `
|
|
29
|
+
:host {
|
|
30
|
+
display: inline-block;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#container {
|
|
34
|
+
--icon-fill: var(--mu-icon-fill, currentColor);
|
|
35
|
+
--icon-size: var(--mu-icon-size, calc(var(--mu-base-rem) * 1.6));
|
|
36
|
+
display: flex;
|
|
37
|
+
place-items: center;
|
|
38
|
+
fill: var(--icon-fill);
|
|
39
|
+
width: var(--icon-size);
|
|
40
|
+
height: var(--icon-size);
|
|
41
|
+
transition: all 0.1s ease-in-out;
|
|
42
|
+
}
|
|
43
|
+
`
|
|
44
|
+
];
|
|
45
|
+
MuIcon.icons = {
|
|
46
|
+
downArrow: html `
|
|
47
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 122.88 63.9" style="enable-background:new 0 0 122.88 63.9" xml:space="preserve"><style type="text/css">.st0{fill-rule:evenodd;clip-rule:evenodd;}</style><g><polygon class="st0" points="61.44,63.9 122.88,0 0,0 61.44,63.9"/></g></svg>
|
|
48
|
+
`,
|
|
49
|
+
close: html `
|
|
50
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 121.31 122.876" enable-background="new 0 0 121.31 122.876" xml:space="preserve">
|
|
51
|
+
<g><path fill-rule="evenodd" clip-rule="evenodd" d="M90.914,5.296c6.927-7.034,18.188-7.065,25.154-0.068 c6.961,6.995,6.991,18.369,0.068,25.397L85.743,61.452l30.425,30.855c6.866,6.978,6.773,18.28-0.208,25.247 c-6.983,6.964-18.21,6.946-25.074-0.031L60.669,86.881L30.395,117.58c-6.927,7.034-18.188,7.065-25.154,0.068 c-6.961-6.995-6.992-18.369-0.068-25.397l30.393-30.827L5.142,30.568c-6.867-6.978-6.773-18.28,0.208-25.247 c6.983-6.963,18.21-6.946,25.074,0.031l30.217,30.643L90.914,5.296L90.914,5.296z"/></g></svg>
|
|
52
|
+
`,
|
|
53
|
+
closeLine: html `
|
|
54
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="122.878px" height="122.88px" viewBox="0 0 122.878 122.88" enable-background="new 0 0 122.878 122.88" xml:space="preserve"><g><path d="M1.426,8.313c-1.901-1.901-1.901-4.984,0-6.886c1.901-1.902,4.984-1.902,6.886,0l53.127,53.127l53.127-53.127 c1.901-1.902,4.984-1.902,6.887,0c1.901,1.901,1.901,4.985,0,6.886L68.324,61.439l53.128,53.128c1.901,1.901,1.901,4.984,0,6.886 c-1.902,1.902-4.985,1.902-6.887,0L61.438,68.326L8.312,121.453c-1.901,1.902-4.984,1.902-6.886,0 c-1.901-1.901-1.901-4.984,0-6.886l53.127-53.128L1.426,8.313L1.426,8.313z"/></g></svg>
|
|
55
|
+
`,
|
|
56
|
+
noImage: html `
|
|
57
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 115.19 123.38" style="enable-background:new 0 0 115.19 123.38" xml:space="preserve"><style type="text/css">.st0{fill-rule:evenodd;clip-rule:evenodd;stroke:#000000;stroke-width:0.5;stroke-miterlimit:2.6131;}</style><g><path class="st0" d="M93.13,79.5c12.05,0,21.82,9.77,21.82,21.82c0,12.05-9.77,21.82-21.82,21.82c-12.05,0-21.82-9.77-21.82-21.82 C71.31,89.27,81.08,79.5,93.13,79.5L93.13,79.5z M8.08,0.25h95.28c2.17,0,4.11,0.89,5.53,2.3c1.42,1.42,2.3,3.39,2.3,5.53v70.01 c-2.46-1.91-5.24-3.44-8.25-4.48V9.98c0-0.43-0.16-0.79-0.46-1.05c-0.26-0.26-0.66-0.46-1.05-0.46H9.94 c-0.43,0-0.79,0.16-1.05,0.46C8.63,9.19,8.43,9.58,8.43,9.98v70.02h0.03l31.97-30.61c1.28-1.18,3.29-1.05,4.44,0.23 c0.03,0.03,0.03,0.07,0.07,0.07l26.88,31.8c-4.73,5.18-7.62,12.08-7.62,19.65c0,3.29,0.55,6.45,1.55,9.4H8.08 c-2.17,0-4.11-0.89-5.53-2.3s-2.3-3.39-2.3-5.53V8.08c0-2.17,0.89-4.11,2.3-5.53S5.94,0.25,8.08,0.25L8.08,0.25z M73.98,79.35 l3.71-22.79c0.3-1.71,1.91-2.9,3.62-2.6c0.66,0.1,1.25,0.43,1.71,0.86l17.1,17.97c-2.18-0.52-4.44-0.79-6.78-0.79 C85.91,71.99,79.13,74.77,73.98,79.35L73.98,79.35z M81.98,18.19c3.13,0,5.99,1.28,8.03,3.32c2.07,2.07,3.32,4.9,3.32,8.03 c0,3.13-1.28,5.99-3.32,8.03c-2.07,2.07-4.9,3.32-8.03,3.32c-3.13,0-5.99-1.28-8.03-3.32c-2.07-2.07-3.32-4.9-3.32-8.03 c0-3.13,1.28-5.99,3.32-8.03C76.02,19.44,78.86,18.19,81.98,18.19L81.98,18.19z M85.82,88.05l19.96,21.6 c1.58-2.39,2.5-5.25,2.5-8.33c0-8.36-6.78-15.14-15.14-15.14C90.48,86.17,87.99,86.85,85.82,88.05L85.82,88.05z M100.44,114.58 l-19.96-21.6c-1.58,2.39-2.5,5.25-2.5,8.33c0,8.36,6.78,15.14,15.14,15.14C95.78,116.46,98.27,115.78,100.44,114.58L100.44,114.58z"/></g></svg>
|
|
58
|
+
`
|
|
59
|
+
};
|
|
60
|
+
__decorate([
|
|
61
|
+
staticProperty()
|
|
62
|
+
], MuIcon.prototype, "name", void 0);
|
|
63
|
+
MuIcon.register('mu-icon');
|
|
64
|
+
|
|
65
|
+
export { MuIcon };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CSSResultGroup } from 'lit';
|
|
2
|
+
import { MUElement } from './mu-element.js';
|
|
3
|
+
import '@mustib/utils/browser';
|
|
4
|
+
|
|
5
|
+
declare class MuRangeFill extends MUElement {
|
|
6
|
+
static styles: CSSResultGroup;
|
|
7
|
+
eventActionData: undefined;
|
|
8
|
+
_addEventActionAttributes: undefined;
|
|
9
|
+
/**
|
|
10
|
+
* A string represents the name of the thumb element that this fill is related to.
|
|
11
|
+
*
|
|
12
|
+
* it can be linked to two thumbs at the same time by adding a comma with no space between the two names.
|
|
13
|
+
*
|
|
14
|
+
* if no mane, it will be linked to the thumb that has the same index
|
|
15
|
+
*
|
|
16
|
+
* @example 'thumb1'
|
|
17
|
+
* @example 'thumb1,thumb2'
|
|
18
|
+
*/
|
|
19
|
+
for?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The type of the fill.
|
|
22
|
+
*
|
|
23
|
+
* `start` fill from the minimum value of the thumb to the value of the thumb.
|
|
24
|
+
*
|
|
25
|
+
* `end` fill from the value of the thumb to the maximum value of the thumb.
|
|
26
|
+
*
|
|
27
|
+
* `both` fill from the minimum value of the thumb to the maximum value of the thumb.
|
|
28
|
+
*
|
|
29
|
+
* @default 'start'
|
|
30
|
+
*/
|
|
31
|
+
type: 'start' | 'end' | 'both';
|
|
32
|
+
readonly container: HTMLDivElement;
|
|
33
|
+
/**
|
|
34
|
+
* Sets the percentage value of the fill.
|
|
35
|
+
*
|
|
36
|
+
* it takes a percentage array of two numbers, where the minimum number is the start percentage and the maximum number is the end percentage
|
|
37
|
+
*/
|
|
38
|
+
setPercentage(percentage: [number, number]): void;
|
|
39
|
+
/**
|
|
40
|
+
* Sets the axis of the fill.
|
|
41
|
+
*
|
|
42
|
+
* for internal use only by mu-range
|
|
43
|
+
*/
|
|
44
|
+
setAxis(axis: 'x' | '-x' | 'y' | '-y'): void;
|
|
45
|
+
render(): unknown;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { MuRangeFill };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { M as MUElement, _ as __decorate } from '../mu-element-CZDI_RCY.js';
|
|
2
|
+
import { css, html } from 'lit';
|
|
3
|
+
import { property, query } from 'lit/decorators.js';
|
|
4
|
+
import '../decorators.js';
|
|
5
|
+
|
|
6
|
+
class MuRangeFill extends MUElement {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.eventActionData = undefined;
|
|
10
|
+
this._addEventActionAttributes = undefined;
|
|
11
|
+
/**
|
|
12
|
+
* The type of the fill.
|
|
13
|
+
*
|
|
14
|
+
* `start` fill from the minimum value of the thumb to the value of the thumb.
|
|
15
|
+
*
|
|
16
|
+
* `end` fill from the value of the thumb to the maximum value of the thumb.
|
|
17
|
+
*
|
|
18
|
+
* `both` fill from the minimum value of the thumb to the maximum value of the thumb.
|
|
19
|
+
*
|
|
20
|
+
* @default 'start'
|
|
21
|
+
*/
|
|
22
|
+
this.type = 'start';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Sets the percentage value of the fill.
|
|
26
|
+
*
|
|
27
|
+
* it takes a percentage array of two numbers, where the minimum number is the start percentage and the maximum number is the end percentage
|
|
28
|
+
*/
|
|
29
|
+
setPercentage(percentage) {
|
|
30
|
+
const start = Math.min(...percentage);
|
|
31
|
+
const end = Math.max(...percentage);
|
|
32
|
+
this.container.style.setProperty('--start', `${start}%`);
|
|
33
|
+
this.container.style.setProperty('--end', `${end}%`);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Sets the axis of the fill.
|
|
37
|
+
*
|
|
38
|
+
* for internal use only by mu-range
|
|
39
|
+
*/
|
|
40
|
+
setAxis(axis) {
|
|
41
|
+
this.updateComplete.then(() => {
|
|
42
|
+
this.container.setAttribute('axis', axis);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
render() {
|
|
46
|
+
return html `
|
|
47
|
+
<div id='container' part='container'></div>
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
MuRangeFill.styles = [MUElement.cssBase, css `
|
|
52
|
+
#container {
|
|
53
|
+
--range-fill-background-color: var(--mu-range-fill-background-color, var(--mu-color-500));
|
|
54
|
+
--start: 25%;
|
|
55
|
+
--end: 50%;
|
|
56
|
+
position: absolute;
|
|
57
|
+
background-color: var(--range-fill-background-color);
|
|
58
|
+
inset: 0;
|
|
59
|
+
transition: all 50ms ease-in;
|
|
60
|
+
border-radius: 9999px;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#container[axis='x'] {
|
|
64
|
+
left: var(--start);
|
|
65
|
+
right: calc(100% - var(--end));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#container[axis='-x'] {
|
|
69
|
+
right: var(--start);
|
|
70
|
+
left: calc(100% - var(--end));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#container[axis='y'] {
|
|
74
|
+
bottom: var(--start);
|
|
75
|
+
top: calc(100% - var(--end));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#container[axis='-y'] {
|
|
79
|
+
top: var(--start);
|
|
80
|
+
bottom: calc(100% - var(--end));
|
|
81
|
+
}
|
|
82
|
+
`];
|
|
83
|
+
__decorate([
|
|
84
|
+
property()
|
|
85
|
+
], MuRangeFill.prototype, "for", void 0);
|
|
86
|
+
__decorate([
|
|
87
|
+
property()
|
|
88
|
+
], MuRangeFill.prototype, "type", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
query('#container', true)
|
|
91
|
+
], MuRangeFill.prototype, "container", void 0);
|
|
92
|
+
MuRangeFill.register('mu-range-fill');
|
|
93
|
+
|
|
94
|
+
export { MuRangeFill };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CSSResultGroup } from 'lit';
|
|
2
|
+
import { MUElement } from './mu-element.js';
|
|
3
|
+
import '@mustib/utils/browser';
|
|
4
|
+
|
|
5
|
+
declare class MuRangeThumbValue extends MUElement {
|
|
6
|
+
static styles: CSSResultGroup;
|
|
7
|
+
eventActionData: undefined;
|
|
8
|
+
_addEventActionAttributes: undefined;
|
|
9
|
+
/**
|
|
10
|
+
* A boolean that indicated if the position of the value should be on the opposite side.
|
|
11
|
+
*
|
|
12
|
+
* so if the default value position is left, it will be right
|
|
13
|
+
* and the default is top, it will be bottom, etc
|
|
14
|
+
*/
|
|
15
|
+
reversed: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* A string representing the type of the value to display.
|
|
18
|
+
*
|
|
19
|
+
* - unit: The value will be displayed as a number with one decimal place.
|
|
20
|
+
* - percentage: The value will be displayed as a percentage with two decimal places.
|
|
21
|
+
* - percentage:round: The value will be displayed as a rounded percentage.
|
|
22
|
+
*
|
|
23
|
+
* @default 'unit'
|
|
24
|
+
*/
|
|
25
|
+
type: 'unit' | 'percentage' | 'percentage:round';
|
|
26
|
+
container: HTMLElement;
|
|
27
|
+
/**
|
|
28
|
+
* A getter for the element that should contain the value.
|
|
29
|
+
*
|
|
30
|
+
* it can be any element that has the attribute `data-is="content"`.
|
|
31
|
+
*
|
|
32
|
+
* that element's text content will be replaced with the value.
|
|
33
|
+
*
|
|
34
|
+
* @default this
|
|
35
|
+
*/
|
|
36
|
+
get contentEl(): Element;
|
|
37
|
+
setValue(data: {
|
|
38
|
+
percentage: number;
|
|
39
|
+
value: number;
|
|
40
|
+
}): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Sets the axis of the value.
|
|
43
|
+
*/
|
|
44
|
+
setAxis(axis: 'x' | 'y'): Promise<void>;
|
|
45
|
+
render(): unknown;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { MuRangeThumbValue };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { M as MUElement, _ as __decorate } from '../mu-element-CZDI_RCY.js';
|
|
2
|
+
import { css, html } from 'lit';
|
|
3
|
+
import { property, query } from 'lit/decorators.js';
|
|
4
|
+
import '../decorators.js';
|
|
5
|
+
|
|
6
|
+
class MuRangeThumbValue extends MUElement {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.eventActionData = undefined;
|
|
10
|
+
this._addEventActionAttributes = undefined;
|
|
11
|
+
/**
|
|
12
|
+
* A boolean that indicated if the position of the value should be on the opposite side.
|
|
13
|
+
*
|
|
14
|
+
* so if the default value position is left, it will be right
|
|
15
|
+
* and the default is top, it will be bottom, etc
|
|
16
|
+
*/
|
|
17
|
+
this.reversed = false;
|
|
18
|
+
/**
|
|
19
|
+
* A string representing the type of the value to display.
|
|
20
|
+
*
|
|
21
|
+
* - unit: The value will be displayed as a number with one decimal place.
|
|
22
|
+
* - percentage: The value will be displayed as a percentage with two decimal places.
|
|
23
|
+
* - percentage:round: The value will be displayed as a rounded percentage.
|
|
24
|
+
*
|
|
25
|
+
* @default 'unit'
|
|
26
|
+
*/
|
|
27
|
+
this.type = 'unit';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A getter for the element that should contain the value.
|
|
31
|
+
*
|
|
32
|
+
* it can be any element that has the attribute `data-is="content"`.
|
|
33
|
+
*
|
|
34
|
+
* that element's text content will be replaced with the value.
|
|
35
|
+
*
|
|
36
|
+
* @default this
|
|
37
|
+
*/
|
|
38
|
+
get contentEl() {
|
|
39
|
+
return this.querySelector('[data-is="content"]') || this;
|
|
40
|
+
}
|
|
41
|
+
async setValue(data) {
|
|
42
|
+
await this.updateComplete;
|
|
43
|
+
switch (this.type) {
|
|
44
|
+
case "percentage":
|
|
45
|
+
// keep two decimal places
|
|
46
|
+
this.contentEl.textContent = `${(Math.trunc(data.percentage * 100) / 100)}%`;
|
|
47
|
+
break;
|
|
48
|
+
case "percentage:round":
|
|
49
|
+
this.contentEl.textContent = `${Math.round(data.percentage)}%`;
|
|
50
|
+
break;
|
|
51
|
+
case "unit":
|
|
52
|
+
// keep one decimal place
|
|
53
|
+
this.contentEl.textContent = `${(Math.trunc(data.value * 10) / 10)}`;
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
this.type;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Sets the axis of the value.
|
|
62
|
+
*/
|
|
63
|
+
async setAxis(axis) {
|
|
64
|
+
await this.updateComplete;
|
|
65
|
+
this.container.setAttribute('axis', axis);
|
|
66
|
+
}
|
|
67
|
+
render() {
|
|
68
|
+
return html `
|
|
69
|
+
<div id='container' part='container'>
|
|
70
|
+
<slot></slot>
|
|
71
|
+
</div>
|
|
72
|
+
`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
MuRangeThumbValue.styles = [MUElement.cssBase, css `
|
|
76
|
+
:host([reversed]) #container[axis='x'] {
|
|
77
|
+
top: 100%;
|
|
78
|
+
bottom: unset;
|
|
79
|
+
margin-block-start: var(--gap, calc(var(--mu-base-rem) * .5));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
:host(:not([reversed])) #container[axis='x'] {
|
|
83
|
+
bottom: 100%;
|
|
84
|
+
margin-block-end: var(--gap, calc(var(--mu-base-rem) * .5));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
:host(:not([reversed])) #container[axis='y'] {
|
|
88
|
+
left: 100%;
|
|
89
|
+
right: unset;
|
|
90
|
+
margin-inline-start: var(--gap, calc(var(--mu-base-rem) * .5));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
:host([reversed]) #container[axis='y'] {
|
|
94
|
+
left: unset;
|
|
95
|
+
right: 100%;
|
|
96
|
+
margin-inline-end: var(--gap, calc(var(--mu-base-rem) * .5));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
#container[axis='x'] {
|
|
100
|
+
left: 50%;
|
|
101
|
+
transform: translateX(-50%);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
#container[axis='y'] {
|
|
105
|
+
top: 50%;
|
|
106
|
+
transform: translateY(-50%);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
#container {
|
|
110
|
+
--range-thumb-value-background-color: var(--mu-range-thumb-value--background-color, var(--range-thumb-background-color, var(--mu-color-500)));
|
|
111
|
+
position: absolute;
|
|
112
|
+
display: flex;
|
|
113
|
+
place-content: center;
|
|
114
|
+
padding: .25ch .5ch;
|
|
115
|
+
border-radius: var(--mu-base-rem);
|
|
116
|
+
background-color: var(--range-thumb-value-background-color);
|
|
117
|
+
box-shadow: var(--range-thumb-shadow);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@media (prefers-color-scheme: light) {
|
|
121
|
+
:host {
|
|
122
|
+
color: var(--mu-color-100);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
`];
|
|
126
|
+
__decorate([
|
|
127
|
+
property({ type: Boolean })
|
|
128
|
+
], MuRangeThumbValue.prototype, "reversed", void 0);
|
|
129
|
+
__decorate([
|
|
130
|
+
property()
|
|
131
|
+
], MuRangeThumbValue.prototype, "type", void 0);
|
|
132
|
+
__decorate([
|
|
133
|
+
query('#container', true)
|
|
134
|
+
], MuRangeThumbValue.prototype, "container", void 0);
|
|
135
|
+
MuRangeThumbValue.register('mu-range-thumb-value');
|
|
136
|
+
|
|
137
|
+
export { MuRangeThumbValue };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { CSSResultGroup, PropertyValues } from 'lit';
|
|
2
|
+
import { MUElement } from './mu-element.js';
|
|
3
|
+
import { MuRangeThumbValue } from './mu-range-thumb-value.js';
|
|
4
|
+
import '@mustib/utils/browser';
|
|
5
|
+
|
|
6
|
+
declare class MuRangeThumb extends MUElement {
|
|
7
|
+
static styles?: CSSResultGroup | undefined;
|
|
8
|
+
eventActionData: undefined;
|
|
9
|
+
_addEventActionAttributes: undefined;
|
|
10
|
+
/**
|
|
11
|
+
* A set of related mu-range-thumb-value elements
|
|
12
|
+
*/
|
|
13
|
+
_valueElements: Set<MuRangeThumbValue>;
|
|
14
|
+
_isRangeReady: Readonly<{
|
|
15
|
+
status: "success" | "fail" | "pending";
|
|
16
|
+
resolved: boolean;
|
|
17
|
+
promise: Promise<boolean>;
|
|
18
|
+
resolve: () => void;
|
|
19
|
+
}>;
|
|
20
|
+
axis: 'x' | 'y' | '-x' | '-y';
|
|
21
|
+
/**
|
|
22
|
+
* The minimum value that the thumb can have.
|
|
23
|
+
*/
|
|
24
|
+
minValue: number;
|
|
25
|
+
/**
|
|
26
|
+
* The maximum value that the thumb can have.
|
|
27
|
+
*/
|
|
28
|
+
maxValue: number;
|
|
29
|
+
/**
|
|
30
|
+
* The current value of the thumb.
|
|
31
|
+
*/
|
|
32
|
+
value: number;
|
|
33
|
+
step: number;
|
|
34
|
+
name?: string;
|
|
35
|
+
/**
|
|
36
|
+
* A boolean indicates if the thumb is focused.
|
|
37
|
+
*
|
|
38
|
+
* for internal use only by mu-range
|
|
39
|
+
*/
|
|
40
|
+
focused: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* A string indicates how range handles other thumbs intersecting with with thumb.
|
|
43
|
+
*
|
|
44
|
+
* `prevent` is the default behavior, and it means do not allow other thumbs intersecting this thumb to pass.
|
|
45
|
+
*
|
|
46
|
+
* `pass-over` means allow other thumbs to pass over this thumb so they can have a free movement.
|
|
47
|
+
*/
|
|
48
|
+
intersectBehavior: 'prevent' | 'pass-over';
|
|
49
|
+
/**
|
|
50
|
+
* A boolean indicates if the thumb should be completely ignored when interacting with the range.
|
|
51
|
+
*
|
|
52
|
+
* When `true`, the thumb will not be active when the user interacts with the range, and other non-transparent thumbs will be active instead.
|
|
53
|
+
*
|
|
54
|
+
* It's like setting `readonly` or `disabled` on the thumb, but instead of nothing being active, other thumbs will be active.
|
|
55
|
+
*/
|
|
56
|
+
transparent: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* A boolean indicates if the thumb should force the step when interacting with the range.
|
|
59
|
+
*/
|
|
60
|
+
forceStep: boolean;
|
|
61
|
+
container?: HTMLElement;
|
|
62
|
+
/**
|
|
63
|
+
* The minimum and maximum value of the closest mu-range element.
|
|
64
|
+
*
|
|
65
|
+
* Which is used to calculate the percentage of the thumb position correctly.
|
|
66
|
+
*
|
|
67
|
+
* for internal use only by mu-range
|
|
68
|
+
*/
|
|
69
|
+
_range: [minValue: number, maxValue: number];
|
|
70
|
+
get range(): [number, number];
|
|
71
|
+
set range(value: [number, number]);
|
|
72
|
+
constructor();
|
|
73
|
+
/**
|
|
74
|
+
* returns an object containing the width and height of the thumb
|
|
75
|
+
*/
|
|
76
|
+
get size(): {
|
|
77
|
+
width: number;
|
|
78
|
+
height: number;
|
|
79
|
+
};
|
|
80
|
+
connectedCallback(): void;
|
|
81
|
+
_slotChangeHandler: () => void;
|
|
82
|
+
/**
|
|
83
|
+
* Updates the value of related mu-range-thumb-value elements
|
|
84
|
+
*/
|
|
85
|
+
_updateValueElements(): void;
|
|
86
|
+
getUpdateComplete(): Promise<boolean>;
|
|
87
|
+
/**
|
|
88
|
+
* Returns a boolean indicating if the value is valid to be set.
|
|
89
|
+
*/
|
|
90
|
+
isValidValue(value: number): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Sets the value of the thumb and returns a boolean indicating if the value was changed.
|
|
93
|
+
* @param value The value to set
|
|
94
|
+
* @returns A boolean indicating if the value was changed
|
|
95
|
+
*/
|
|
96
|
+
setValue(value: number): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Sets the value of the thumb from a percentage and returns a boolean indicating if the value was changed.
|
|
99
|
+
* @param percentage The percentage to set
|
|
100
|
+
* @returns A boolean indicating if the value was changed
|
|
101
|
+
*/
|
|
102
|
+
setValueFromPercentage(percentage: number): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Converts a given value to a percentage based on the current range and returns it.
|
|
105
|
+
*/
|
|
106
|
+
getPercentageFromValue(value: number): number;
|
|
107
|
+
/**
|
|
108
|
+
* Updates the axis of related mu-range-thumb-value elements
|
|
109
|
+
*/
|
|
110
|
+
updateValueElementsAxis(): void;
|
|
111
|
+
updated(_changedProperties: PropertyValues<this>): Promise<void>;
|
|
112
|
+
render(): unknown;
|
|
113
|
+
}
|
|
114
|
+
declare global {
|
|
115
|
+
interface HTMLElementTagNameMap {
|
|
116
|
+
'mu-range-thumb': MuRangeThumb;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { MuRangeThumb };
|