Skip to content

Commit

Permalink
Move CustomControl to his own file.
Browse files Browse the repository at this point in the history
  • Loading branch information
francois2metz committed Apr 27, 2024
1 parent 47799cb commit 8dd4444
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 43 deletions.
43 changes: 1 addition & 42 deletions lib/components/controls/custom.control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import {
defineComponent,
h,
inject,
nextTick,
onBeforeUnmount,
type PropType,
ref,
Ref,
type SlotsType,
Teleport,
watch,
Expand All @@ -17,48 +15,9 @@ import {
type PositionProp,
PositionValues,
} from "@/lib/components/controls/position.enum";
import type { ControlPosition, IControl } from "maplibre-gl";
import { isInitializedSymbol, mapSymbol } from "@/lib/types";
import { usePositionWatcher } from "@/lib/composable/usePositionWatcher";

class CustomControl implements IControl {
public static readonly CONTROL_CLASS = "maplibregl-ctrl";
public static readonly CONTROL_GROUP_CLASS = "maplibregl-ctrl-group";

public readonly container: HTMLDivElement;

constructor(
private isAdded: Ref<boolean>,
noClasses: boolean,
) {
this.container = document.createElement("div");
this.setClasses(noClasses);
}

getDefaultPosition(): ControlPosition {
return Position.TOP_LEFT;
}

onAdd(): HTMLElement {
nextTick(() => (this.isAdded.value = true));
return this.container;
}

onRemove(): void {
this.isAdded.value = false;
this.container.remove();
}

setClasses(noClasses: boolean) {
if (noClasses) {
this.container.classList.remove(CustomControl.CONTROL_CLASS);
this.container.classList.remove(CustomControl.CONTROL_GROUP_CLASS);
} else {
this.container.classList.add(CustomControl.CONTROL_CLASS);
this.container.classList.add(CustomControl.CONTROL_GROUP_CLASS);
}
}
}
import { CustomControl } from "@/lib/components/controls/custom";

export default /*#__PURE__*/ defineComponent({
name: "MglCustomControl",
Expand Down
47 changes: 47 additions & 0 deletions lib/components/controls/custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { ControlPosition, IControl } from "maplibre-gl";
import {
nextTick,
Ref,
} from "vue";
import {
Position,
} from "@/lib/components/controls/position.enum";

export class CustomControl implements IControl {
public static readonly CONTROL_CLASS = "maplibregl-ctrl";
public static readonly CONTROL_GROUP_CLASS = "maplibregl-ctrl-group";

public readonly container: HTMLDivElement;

constructor(
private isAdded: Ref<boolean>,
noClasses: boolean,
) {
this.container = document.createElement("div");
this.setClasses(noClasses);
}

getDefaultPosition(): ControlPosition {
return Position.TOP_LEFT;
}

onAdd(): HTMLElement {
nextTick(() => (this.isAdded.value = true));
return this.container;
}

onRemove(): void {
this.isAdded.value = false;
this.container.remove();
}

setClasses(noClasses: boolean) {
if (noClasses) {
this.container.classList.remove(CustomControl.CONTROL_CLASS);
this.container.classList.remove(CustomControl.CONTROL_GROUP_CLASS);
} else {
this.container.classList.add(CustomControl.CONTROL_CLASS);
this.container.classList.add(CustomControl.CONTROL_GROUP_CLASS);
}
}
}
2 changes: 1 addition & 1 deletion lib/components/controls/styleSwitch.control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
mapSymbol,
type StyleSwitchItem,
} from "@/lib/types";
import { CustomControl } from "@/lib/components/controls/custom.control";
import { CustomControl } from "@/lib/components/controls/custom";
import { usePositionWatcher } from "@/lib/composable/usePositionWatcher";
import { MglButton } from "@/lib/components";
import { ButtonType } from "@/lib/components/button.component";
Expand Down

0 comments on commit 8dd4444

Please sign in to comment.