From bb23ff21f693b623e76c935d8ea4fb58ac57d36c Mon Sep 17 00:00:00 2001 From: Max Hoffmann Date: Wed, 27 Sep 2023 19:37:51 -0700 Subject: [PATCH] Convert CollidableEvent to typescript --- .changeset/calm-kangaroos-jump.md | 5 +++ ...{CollidableEvent.js => CollidableEvent.ts} | 31 +++++++++++++++++-- .../CollidableEvent/{index.js => index.ts} | 0 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 .changeset/calm-kangaroos-jump.md rename src/Plugins/Collidable/CollidableEvent/{CollidableEvent.js => CollidableEvent.ts} (57%) rename src/Plugins/Collidable/CollidableEvent/{index.js => index.ts} (100%) diff --git a/.changeset/calm-kangaroos-jump.md b/.changeset/calm-kangaroos-jump.md new file mode 100644 index 00000000..56174fde --- /dev/null +++ b/.changeset/calm-kangaroos-jump.md @@ -0,0 +1,5 @@ +--- +'@shopify/draggable': patch +--- + +Convert CollidableEvent to typescript diff --git a/src/Plugins/Collidable/CollidableEvent/CollidableEvent.js b/src/Plugins/Collidable/CollidableEvent/CollidableEvent.ts similarity index 57% rename from src/Plugins/Collidable/CollidableEvent/CollidableEvent.js rename to src/Plugins/Collidable/CollidableEvent/CollidableEvent.ts index 1f5e68ea..9c3f7228 100644 --- a/src/Plugins/Collidable/CollidableEvent/CollidableEvent.js +++ b/src/Plugins/Collidable/CollidableEvent/CollidableEvent.ts @@ -1,14 +1,31 @@ import AbstractEvent from 'shared/AbstractEvent'; +import {DragEvent, DragEventData} from '../../../Draggable/DragEvent'; + +interface CollidableEventData { + dragEvent: DragEvent; +} + /** * Base collidable event * @class CollidableEvent * @module CollidableEvent * @extends AbstractEvent */ -export class CollidableEvent extends AbstractEvent { +export class CollidableEvent< + T extends CollidableEventData, +> extends AbstractEvent { static type = 'collidable'; + /** + * CollidableEvent constructor. + * @constructs CollidableEvent + * @param {CollidableEventData} data - Event data + */ + constructor(public data: T) { + super(data); + } + /** * Drag event that triggered this colliable event * @property dragEvent @@ -20,13 +37,17 @@ export class CollidableEvent extends AbstractEvent { } } +interface CollidableInEventData extends CollidableEventData { + collidingElement: HTMLElement; +} + /** * Collidable in event * @class CollidableInEvent * @module CollidableInEvent * @extends CollidableEvent */ -export class CollidableInEvent extends CollidableEvent { +export class CollidableInEvent extends CollidableEvent { static type = 'collidable:in'; /** @@ -40,13 +61,17 @@ export class CollidableInEvent extends CollidableEvent { } } +interface CollidableOutEventData extends CollidableEventData { + collidingElement: HTMLElement; +} + /** * Collidable out event * @class CollidableOutEvent * @module CollidableOutEvent * @extends CollidableEvent */ -export class CollidableOutEvent extends CollidableEvent { +export class CollidableOutEvent extends CollidableEvent { static type = 'collidable:out'; /** diff --git a/src/Plugins/Collidable/CollidableEvent/index.js b/src/Plugins/Collidable/CollidableEvent/index.ts similarity index 100% rename from src/Plugins/Collidable/CollidableEvent/index.js rename to src/Plugins/Collidable/CollidableEvent/index.ts