mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
impr: Miglioramenti ai manager
- Aggiunti constructor della classe base nella classe derivata - Alcune proprietà dei manager sono ora protected invece che private - Migliorata identificazione loading button (non si basa più sul tipo ma su un attributo custom) - Migliorata tipizzazione
This commit is contained in:
@@ -21,8 +21,8 @@ type Attributes = JSXElement<Button> & {
|
||||
|
||||
export class LoadingButton extends Component<Attributes> {
|
||||
view() {
|
||||
return ( // @ts-ignore
|
||||
<mwc-button type="loading-button" {...this.attrs.all()}>
|
||||
return (
|
||||
<mwc-button data-component-type="loading-button" {...this.attrs.all()}>
|
||||
<span slot="icon" style="display: inline;">
|
||||
<mwc-circular-progress
|
||||
indeterminate
|
||||
|
@@ -4,9 +4,10 @@ import {Manager} from './Manager';
|
||||
|
||||
export class CircularProgressManager extends Manager {
|
||||
static selector = 'mwc-circular-progress';
|
||||
static filter = (element: CircularProgress) => element.closest('mwc-button').type !== 'loading-button';
|
||||
static filter = (element: CircularProgress) => element.closest('mwc-button')?.dataset.componentType !== 'loading-button';
|
||||
|
||||
constructor(private loading: CircularProgress) {
|
||||
constructor(protected loading: CircularProgress) {
|
||||
super(loading);
|
||||
}
|
||||
|
||||
public show() {
|
||||
|
@@ -5,7 +5,8 @@ import {Manager} from './Manager';
|
||||
export class DialogManager extends Manager {
|
||||
static selector = 'dialog';
|
||||
|
||||
constructor(private dialog: Dialog) {
|
||||
constructor(protected dialog: Dialog) {
|
||||
super(dialog);
|
||||
}
|
||||
|
||||
public show(dialog: Dialog) {
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import {Button} from '@material/mwc-button';
|
||||
import {CircularProgress} from '@material/mwc-circular-progress';
|
||||
import {CircularProgressManager} from '@osm/Components/Managers';
|
||||
|
||||
export class LoadingButtonManager extends CircularProgressManager {
|
||||
static selector = 'mwc-button[type="loading-button"]';
|
||||
|
||||
private loading: CircularProgress;
|
||||
static selector = 'mwc-button[data-component-type="loading-button"]';
|
||||
|
||||
constructor(private button: Button) {
|
||||
this.loading = button.querySelector('mwc-circular-progress');
|
||||
const loading = button.querySelector('mwc-circular-progress');
|
||||
if (loading) {
|
||||
super(loading);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,11 @@
|
||||
export type ComponentManager =
|
||||
{new(element: any | HTMLElement): Manager}
|
||||
& Omit<typeof Manager, 'new'>;
|
||||
|
||||
export abstract class Manager {
|
||||
abstract static selector: string;
|
||||
static filter: (element: HTMLElement) => boolean = () => true;
|
||||
static selector: string;
|
||||
static filter: (element: any | HTMLElement) => boolean = () => true;
|
||||
|
||||
protected constructor(protected element: HTMLElement) {
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import type {Dialog as MWCDialog} from '@material/mwc-dialog';
|
||||
import {Menu as MWCMenu} from '@material/mwc-menu';
|
||||
import {
|
||||
CircularProgressManager,
|
||||
ComponentManager,
|
||||
DialogManager,
|
||||
LoadingButtonManager
|
||||
} from '@osm/Components/Managers';
|
||||
@@ -51,7 +52,11 @@ function loadTriggers() {
|
||||
}
|
||||
|
||||
function loadManagers() {
|
||||
const managers = [DialogManager, CircularProgressManager, LoadingButtonManager];
|
||||
const managers: ComponentManager[] = [
|
||||
DialogManager,
|
||||
CircularProgressManager,
|
||||
LoadingButtonManager
|
||||
];
|
||||
|
||||
for (const Manager of managers) {
|
||||
for (const element of document.querySelectorAll<HTMLElement>(Manager.selector)) {
|
||||
|
10
resources/js/globals.d.ts
vendored
10
resources/js/globals.d.ts
vendored
@@ -18,11 +18,7 @@ import {LinearProgress as MWCLinearProgress} from '@material/mwc-linear-progress
|
||||
import {List as MWCList} from '@material/mwc-list';
|
||||
import {ListItem as MWCListItem} from '@material/mwc-list/mwc-list-item.js';
|
||||
import {Menu as MWCMenu} from '@material/mwc-menu';
|
||||
import {
|
||||
CircularProgressManager,
|
||||
DialogManager,
|
||||
LoadingButtonManager
|
||||
} from '@osm/Components/Managers';
|
||||
import {Manager} from '@osm/Components/Managers';
|
||||
import type cash from 'cash-dom';
|
||||
import type Mithril from 'mithril';
|
||||
import type router from 'ziggy-js';
|
||||
@@ -41,13 +37,11 @@ import {
|
||||
TopAppBar
|
||||
} from './WebComponents';
|
||||
|
||||
type ComponentManager = CircularProgressManager | DialogManager | LoadingButtonManager;
|
||||
|
||||
declare global {
|
||||
const route: typeof router;
|
||||
|
||||
let app: {
|
||||
components: Record<string, ComponentManager>
|
||||
components: Record<string, Manager>
|
||||
events: Record<string, Event>,
|
||||
locale: string,
|
||||
modules: OpenSTAManager.Modules,
|
||||
|
Reference in New Issue
Block a user