Skip to content

Commit 73151f6

Browse files
committed
[Map] Define IconTypes and IconType in TypeScript
1 parent dd20dbe commit 73151f6

File tree

7 files changed

+43
-15
lines changed

7 files changed

+43
-15
lines changed

src/Map/assets/dist/abstract_map_controller.d.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@ export type Point = {
33
lat: number;
44
lng: number;
55
};
6+
export type Identifier = string;
7+
export type WithIdentifier<T extends Record<string, unknown>> = T & {
8+
'@id': Identifier;
9+
};
10+
export declare const IconTypes: {
11+
readonly Url: "url";
12+
readonly InlineSvg: "inline-svg";
13+
readonly UxIcon: "ux-icon";
14+
};
15+
export type IconType = (typeof IconTypes)[keyof typeof IconTypes];
616
export type Icon = {
717
content: string;
8-
type: 'url' | 'inline-svg' | 'ux-icon';
18+
type: IconType;
919
width: number;
1020
height: number;
1121
};
12-
export type Identifier = string;
13-
export type WithIdentifier<T extends Record<string, unknown>> = T & {
14-
'@id': Identifier;
15-
};
1622
export type MarkerDefinition<MarkerOptions, InfoWindowOptions> = WithIdentifier<{
1723
position: Point;
1824
title: string | null;

src/Map/assets/dist/abstract_map_controller.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { Controller } from '@hotwired/stimulus';
22

3+
const IconTypes = {
4+
Url: 'url',
5+
InlineSvg: 'inline-svg',
6+
UxIcon: 'ux-icon',
7+
};
38
class default_1 extends Controller {
49
constructor() {
510
super(...arguments);
@@ -102,4 +107,4 @@ default_1.values = {
102107
options: Object,
103108
};
104109

105-
export { default_1 as default };
110+
export { IconTypes, default_1 as default };

src/Map/assets/src/abstract_map_controller.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { Controller } from '@hotwired/stimulus';
22

33
export type Point = { lat: number; lng: number };
4+
export type Identifier = string;
5+
export type WithIdentifier<T extends Record<string, unknown>> = T & { '@id': Identifier };
6+
7+
export const IconTypes = {
8+
Url: 'url',
9+
InlineSvg: 'inline-svg',
10+
UxIcon: 'ux-icon',
11+
} as const;
12+
export type IconType = (typeof IconTypes)[keyof typeof IconTypes];
413
export type Icon = {
514
content: string;
6-
type: 'url' | 'inline-svg' | 'ux-icon';
15+
type: IconType;
716
width: number;
817
height: number;
918
};
10-
export type Identifier = string;
11-
export type WithIdentifier<T extends Record<string, unknown>> = T & { '@id': Identifier };
1219

1320
export type MarkerDefinition<MarkerOptions, InfoWindowOptions> = WithIdentifier<{
1421
position: Point;

src/Map/src/Bridge/Google/assets/dist/map_controller.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { Loader } from '@googlemaps/js-api-loader';
22
import { Controller } from '@hotwired/stimulus';
33

4+
const IconTypes = {
5+
Url: 'url',
6+
InlineSvg: 'inline-svg',
7+
UxIcon: 'ux-icon',
8+
};
49
class default_1 extends Controller {
510
constructor() {
611
super(...arguments);
@@ -278,7 +283,7 @@ class map_controller extends default_1 {
278283
}
279284
doCreateIcon({ definition, element, }) {
280285
const { content, type, width, height } = definition;
281-
if (type === 'inline-svg') {
286+
if (type === IconTypes.InlineSvg) {
282287
const icon = this.parser.parseFromString(content, 'image/svg+xml').documentElement;
283288
element.content = icon;
284289
}

src/Map/src/Bridge/Google/assets/src/map_controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import type { LoaderOptions } from '@googlemaps/js-api-loader';
1111
import { Loader } from '@googlemaps/js-api-loader';
12-
import AbstractMapController from '@symfony/ux-map';
12+
import AbstractMapController, { IconTypes } from '@symfony/ux-map';
1313
import type {
1414
Icon,
1515
InfoWindowWithoutPositionDefinition,
@@ -313,7 +313,7 @@ export default class extends AbstractMapController<
313313
element: google.maps.marker.AdvancedMarkerElement;
314314
}): void {
315315
const { content, type, width, height } = definition;
316-
if (type === 'inline-svg') {
316+
if (type === IconTypes.InlineSvg) {
317317
const icon = this.parser.parseFromString(content, 'image/svg+xml').documentElement;
318318
element.content = icon;
319319
} else {

src/Map/src/Bridge/Leaflet/assets/dist/map_controller.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { Controller } from '@hotwired/stimulus';
22
import 'leaflet/dist/leaflet.min.css';
33
import * as L from 'leaflet';
44

5+
const IconTypes = {
6+
Url: 'url',
7+
InlineSvg: 'inline-svg',
8+
UxIcon: 'ux-icon',
9+
};
510
class default_1 extends Controller {
611
constructor() {
712
super(...arguments);
@@ -202,7 +207,7 @@ class map_controller extends default_1 {
202207
}
203208
doCreateIcon({ definition, element, }) {
204209
const { content, type, width, height } = definition;
205-
const icon = type === 'inline-svg'
210+
const icon = type === IconTypes.InlineSvg
206211
? L.divIcon({ html: content, iconSize: [width, height] })
207212
: L.icon({ iconUrl: content, iconSize: [width, height] });
208213
element.setIcon(icon);

src/Map/src/Bridge/Leaflet/assets/src/map_controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import AbstractMapController from '@symfony/ux-map';
1+
import AbstractMapController, { IconTypes } from '@symfony/ux-map';
22
import type {
33
Icon,
44
InfoWindowWithoutPositionDefinition,
@@ -187,7 +187,7 @@ export default class extends AbstractMapController<
187187
}): void {
188188
const { content, type, width, height } = definition;
189189
const icon =
190-
type === 'inline-svg'
190+
type === IconTypes.InlineSvg
191191
? L.divIcon({ html: content, iconSize: [width, height] })
192192
: L.icon({ iconUrl: content, iconSize: [width, height] });
193193
element.setIcon(icon);

0 commit comments

Comments
 (0)