Skip to content

Commit d0e8bf6

Browse files
committed
ref: use FeedbackComponent and rename methods
1 parent 1fc051f commit d0e8bf6

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

packages/feedback/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class Feedback implements Integration {
156156
*/
157157
public openDialog(): void {
158158
if (this._dialog) {
159-
this._dialog.openDialog();
159+
this._dialog.open();
160160
return;
161161
}
162162

@@ -175,7 +175,7 @@ export class Feedback implements Integration {
175175
*/
176176
public closeDialog = (): void => {
177177
if (this._dialog) {
178-
this._dialog.closeDialog();
178+
this._dialog.close();
179179
}
180180

181181
// TODO: if has default actor, show the button
@@ -251,7 +251,7 @@ export class Feedback implements Integration {
251251

252252
// Hide actor button
253253
if (this._actor) {
254-
this._actor.classList.add('hidden');
254+
this._actor.hide();
255255
}
256256
};
257257
}

packages/feedback/src/types/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,7 @@ export interface FeedbackTheme {
127127
light: BaseTheme;
128128
dark: BaseTheme;
129129
}
130+
131+
export interface FeedbackComponent<T extends HTMLElement> {
132+
$el: T;
133+
}

packages/feedback/src/widget/Actor.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FeedbackConfigurationWithDefaults, FeedbackTheme } from '../types';
1+
import type { FeedbackComponent, FeedbackConfigurationWithDefaults, FeedbackTheme } from '../types';
22
import { Icon } from './Icon';
33
import { createElement as h } from './util/createElement';
44

@@ -8,8 +8,7 @@ interface Props {
88
onClick?: (e: MouseEvent) => void;
99
}
1010

11-
interface ActorReturn {
12-
$el: HTMLButtonElement;
11+
interface ActorComponent extends FeedbackComponent<HTMLButtonElement> {
1312
/**
1413
* Shows the actor element
1514
*/
@@ -23,7 +22,7 @@ interface ActorReturn {
2322
/**
2423
*
2524
*/
26-
export function Actor({ options, theme, onClick }: Props): ActorReturn {
25+
export function Actor({ options, theme, onClick }: Props): ActorComponent {
2726
function _handleClick(e: MouseEvent) {
2827
if (typeof onClick === 'function') {
2928
onClick(e);

packages/feedback/src/widget/Dialog.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getCurrentHub } from '@sentry/core';
22

3-
import type { FeedbackConfigurationWithDefaults, FeedbackFormData } from '../types';
3+
import type { FeedbackComponent, FeedbackConfigurationWithDefaults, FeedbackFormData } from '../types';
44
import { Form } from './Form';
55
import { createElement as h } from './util/createElement';
66

@@ -10,25 +10,39 @@ interface DialogProps {
1010
options: FeedbackConfigurationWithDefaults;
1111
}
1212

13-
interface DialogReturn {
14-
$el: HTMLDialogElement;
13+
interface DialogComponent extends FeedbackComponent<HTMLDialogElement> {
14+
/**
15+
* Disable submit button so that it cannot be clicked
16+
*/
1517
setSubmitDisabled: () => void;
18+
/**
19+
* Enable submit buttons so that it can be clicked
20+
*/
1621
setSubmitEnabled: () => void;
17-
removeDialog: () => void;
18-
openDialog: () => void;
19-
closeDialog: () => void;
22+
/**
23+
* Remove the dialog element from the DOM
24+
*/
25+
remove: () => void;
26+
/**
27+
* Opens and shows the dialog and form
28+
*/
29+
open: () => void;
30+
/**
31+
* Closes the dialog and form
32+
*/
33+
close: () => void;
2034
}
2135

2236
/**
2337
* Feedback dialog component that has the form
2438
*/
25-
export function Dialog({ onCancel, onSubmit, options }: DialogProps): DialogReturn {
39+
export function Dialog({ onCancel, onSubmit, options }: DialogProps): DialogComponent {
2640
let $el: HTMLDialogElement | null = null;
2741

2842
/**
2943
*
3044
*/
31-
function closeDialog() {
45+
function close() {
3246
if ($el) {
3347
$el.open = false;
3448
}
@@ -37,7 +51,7 @@ export function Dialog({ onCancel, onSubmit, options }: DialogProps): DialogRetu
3751
/**
3852
*
3953
*/
40-
function removeDialog() {
54+
function remove() {
4155
if ($el) {
4256
$el.remove();
4357
$el = null;
@@ -47,7 +61,7 @@ export function Dialog({ onCancel, onSubmit, options }: DialogProps): DialogRetu
4761
/**
4862
*
4963
*/
50-
function openDialog() {
64+
function open() {
5165
if ($el) {
5266
$el.open = true;
5367
}
@@ -74,7 +88,7 @@ export function Dialog({ onCancel, onSubmit, options }: DialogProps): DialogRetu
7488
id: 'feedback-dialog',
7589
className: 'dialog',
7690
open: true,
77-
onClick: closeDialog,
91+
onClick: close,
7892
},
7993
h(
8094
'div',
@@ -94,8 +108,8 @@ export function Dialog({ onCancel, onSubmit, options }: DialogProps): DialogRetu
94108
$el,
95109
setSubmitDisabled,
96110
setSubmitEnabled,
97-
removeDialog,
98-
openDialog,
99-
closeDialog,
111+
remove,
112+
open,
113+
close,
100114
};
101115
}

0 commit comments

Comments
 (0)