UNPKG

5.58 kBTypeScriptView Raw
1import WUPBaseElement from "./baseElement";
2declare const tagName = "wup-spin";
3declare global {
4 namespace WUP.Spin {
5 interface Defaults {
6 /** Place inside parent as inline-block otherwise overflow target in the center (`position: relative` is not required);
7 * @defaultValue false */
8 inline?: boolean;
9 /** Virtual padding of parentElement [top, right, bottom, left] or [top/bottom, right/left] in px
10 * @defaultValue [4,4] */
11 overflowOffset: [number, number, number, number] | [number, number];
12 /** Allow to create shadowBox to partially hide target (only for `inline: false`)
13 * @defaultValue true */
14 overflowFade: boolean;
15 /** Allow to reduce size to fit parent (for max-size change css-var --spin-size)
16 * @defaultValue false for inline:true, true for inline:false */
17 fit?: boolean;
18 }
19 interface Options extends Defaults {
20 /** Anchor element that need to oveflow by spinner, by default it's parentElement */
21 overflowTarget?: HTMLElement | null;
22 }
23 interface Attributes {
24 /** Place inside parent as inline-block or overflow target in the center (`position: relative` isnot required);
25 * @defaultValue false */
26 inline?: boolean | "";
27 /** Allow to create shadowBox to partially hide target (only for `inline: false`)
28 * @defaultValue true */
29 overflowFade?: boolean | "";
30 /** Allow to reduce size to fit parent (for max-size change css-var --spin-size)
31 * @defaultValue false for inline:true, true for inline:false */
32 fit?: boolean | "";
33 }
34 interface JSXProps<T extends WUPSpinElement> extends WUP.Base.JSXProps<T>, Attributes {
35 }
36 }
37 interface HTMLElementTagNameMap {
38 [tagName]: WUPSpinElement;
39 }
40 namespace JSX {
41 interface IntrinsicElements {
42 /** Flexible animated element with ability to place over target element without position relative
43 * @see {@link WUPSpinElement} */
44 [tagName]: WUP.Spin.JSXProps<WUPSpinElement>;
45 }
46 }
47}
48/** Flexible animated element with ability to place over target element without position relative
49 * @tutorial Troubleshooting
50 * * when used several spin-types at once: define `--spin-1` & `--spin-2` colors manually per each spin-type
51 * @example
52 * JS/TS
53 * ```js
54 * import WUPSpinElement, { spinUseTwinDualRing } from "web-ui-pack/spinElement";
55 * spinUseTwinDualRing(WUPSpinElement); // to apply another style
56 *
57 * const el = document.body.appendChild(document.createElement('wup-spin'));
58 * el.$options.inline = false;
59 * el.$options.overflowTarget = document.body.appendChild(document.createElement('button'))
60 * ```
61 * HTML
62 * ```html
63 * <button> Loading...
64 * <!-- Default; it's equal to <wup-spin></wup-spin>-->
65 * <wup-spin inline="false" fit="true" overflowfade="true"></wup-spin>
66 * <!-- Inline + fit to parent -->
67 * <wup-spin inline fit></wup-spin>
68 * <!-- OR; it's equal to <wup-spin inline="false" fit="true" overflowfade="false"></wup-spin> -->
69 * <wup-spin overflowfade="false"></wup-spin>
70 * </button>
71 * ```
72 */
73export default class WUPSpinElement<TOptions extends WUP.Spin.Options = WUP.Spin.Options> extends WUPBaseElement<TOptions> {
74 #private;
75 static get observedOptions(): Array<keyof WUP.Spin.Options>;
76 static get observedAttributes(): Array<LowerKeys<WUP.Spin.Attributes>>;
77 static get $styleRoot(): string;
78 static get $styleApplied(): string;
79 static get $style(): string;
80 static $defaults: WUP.Spin.Defaults;
81 static _itemsCount: number;
82 /** Force to update position (when options changed) */
83 $refresh(): void;
84 protected connectedCallback(): void;
85 protected gotRemoved(): void;
86 protected gotRender(): void;
87 protected gotReady(): void;
88 $refFade?: HTMLDivElement;
89 protected gotChanges(propsChanged: Array<keyof WUP.Spin.Options> | null): void;
90 get target(): HTMLElement;
91 get hasRelativeParent(): boolean;
92 /** Update position. Call this method in cases when you changed options */
93 protected updatePosition(): Pick<DOMRect, "width" | "height" | "top" | "left"> | undefined;
94}
95/** Basic function to change spinner-style */
96export declare function spinSetStyle(cls: typeof WUPSpinElement, itemsCount: number, getter: () => string): void;
97/** Apply on class to change spinner-style */
98export declare function spinUseRing(cls: typeof WUPSpinElement): void;
99/** Apply on class to change spinner-style */
100export declare function spinUseDualRing(cls: typeof WUPSpinElement): void;
101/** Apply on class to change spinner-style */
102export declare function spinUseTwinDualRing(cls: typeof WUPSpinElement): void;
103/** Apply on class to change spinner-style */
104export declare function spinUseRoller(cls: typeof WUPSpinElement): void;
105/** Apply on class to change spinner-style */
106export declare function spinUseDotRoller(cls: typeof WUPSpinElement): void;
107/** Apply on class to change spinner-style */
108export declare function spinUseDotRing(cls: typeof WUPSpinElement): void;
109/** Apply on class to change spinner-style */
110export declare function spinUseSpliceRing(cls: typeof WUPSpinElement): void;
111/** Apply on class to change spinner-style */
112export declare function spinUseHash(cls: typeof WUPSpinElement): void;
113export {};