@product7/feedback-sdk 1.2.3 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,15 @@
1
1
  import { BaseWidget } from './BaseWidget.js';
2
2
 
3
3
  export class ButtonWidget extends BaseWidget {
4
- constructor(options) {
5
- super({ ...options, type: 'button' });
6
- this.isMinimized = false;
7
- }
8
-
9
- render() {
10
- const button = document.createElement('div');
11
- button.className = `feedback-widget feedback-widget-button theme-${this.options.theme} position-${this.options.position}`;
12
- button.innerHTML = `
4
+ constructor(options) {
5
+ super({ ...options, type: 'button' });
6
+ this.isMinimized = false;
7
+ }
8
+
9
+ _render() {
10
+ const button = document.createElement('div');
11
+ button.className = `feedback-widget feedback-widget-button theme-${this.options.theme} position-${this.options.position}`;
12
+ button.innerHTML = `
13
13
  <button class="feedback-trigger-btn" type="button">
14
14
  <svg class="feedback-icon" width="20" height="20" viewBox="0 0 256 256" fill="currentColor">
15
15
  <path d="M216,80H184V48a16,16,0,0,0-16-16H40A16,16,0,0,0,24,48V176a8,8,0,0,0,13,6.22L72,154V184a16,16,0,0,0,16,16h93.59L219,230.22a8,8,0,0,0,5,1.78,8,8,0,0,0,8-8V96A16,16,0,0,0,216,80ZM66.55,137.78,40,159.25V48H168v88H71.58A8,8,0,0,0,66.55,137.78ZM216,207.25l-26.55-21.47a8,8,0,0,0-5-1.78H88V152h80a16,16,0,0,0,16-16V96h32Z"/>
@@ -30,85 +30,87 @@ export class ButtonWidget extends BaseWidget {
30
30
  </button>
31
31
  `;
32
32
 
33
- if (this.options.customStyles) {
34
- Object.assign(button.style, this.options.customStyles);
35
- }
36
-
37
- return button;
38
- }
39
-
40
- attachEvents() {
41
- const button = this.element.querySelector('.feedback-trigger-btn');
42
- const minimizeIcon = this.element.querySelector('.feedback-minimize-icon');
43
- const expandIcon = this.element.querySelector('.feedback-expand-icon');
44
-
45
- // Add click handlers directly to the icons
46
- minimizeIcon.addEventListener('click', (e) => {
47
- e.stopPropagation();
48
- e.preventDefault();
49
- this.minimize();
50
- });
51
-
52
- expandIcon.addEventListener('click', (e) => {
53
- e.stopPropagation();
54
- e.preventDefault();
55
- this.restore();
56
- });
57
-
58
- // Main button click handler
59
- button.addEventListener('click', (e) => {
60
- // Check if the click originated from an icon
61
- if (e.target.closest('.feedback-minimize-icon') ||
62
- e.target.closest('.feedback-expand-icon')) {
63
- return; // Let the icon handlers deal with it
64
- }
65
-
66
- if (!this.isMinimized) {
67
- this.openPanel();
68
- }
69
- });
70
-
71
- button.addEventListener('mouseenter', () => {
72
- if (!this.state.isSubmitting && !this.isMinimized) {
73
- button.style.transform = 'translateY(-2px)';
74
- }
75
- });
76
-
77
- button.addEventListener('mouseleave', () => {
78
- if (!this.isMinimized) {
79
- button.style.transform = 'translateY(0)';
80
- }
81
- });
82
- }
83
-
84
- minimize() {
85
- this.isMinimized = true;
86
- this.element.classList.add('minimized');
87
- }
88
-
89
- restore() {
90
- this.isMinimized = false;
91
- this.element.classList.remove('minimized');
92
- }
93
-
94
- mount(container) {
95
- super.mount(container);
96
- }
97
-
98
- updateText(text) {
99
- const textEl = this.element?.querySelector('.feedback-text');
100
- if (textEl) {
101
- textEl.textContent = text;
102
- }
103
- }
104
-
105
- updatePosition(position) {
106
- this.options.position = position;
107
- if (this.element) {
108
- this.element.className = this.element.className.replace(
109
- /position-\w+-\w+/,
110
- `position-${position}`
111
- );
112
- }
113
- }
114
- }
33
+ if (this.options.customStyles) {
34
+ Object.assign(button.style, this.options.customStyles);
35
+ }
36
+
37
+ return button;
38
+ }
39
+
40
+ _attachEvents() {
41
+ const button = this.element.querySelector('.feedback-trigger-btn');
42
+ const minimizeIcon = this.element.querySelector('.feedback-minimize-icon');
43
+ const expandIcon = this.element.querySelector('.feedback-expand-icon');
44
+
45
+ // Add click handlers directly to the icons
46
+ minimizeIcon.addEventListener('click', (e) => {
47
+ e.stopPropagation();
48
+ e.preventDefault();
49
+ this.minimize();
50
+ });
51
+
52
+ expandIcon.addEventListener('click', (e) => {
53
+ e.stopPropagation();
54
+ e.preventDefault();
55
+ this.restore();
56
+ });
57
+
58
+ // Main button click handler
59
+ button.addEventListener('click', (e) => {
60
+ // Check if the click originated from an icon
61
+ if (
62
+ e.target.closest('.feedback-minimize-icon') ||
63
+ e.target.closest('.feedback-expand-icon')
64
+ ) {
65
+ return; // Let the icon handlers deal with it
66
+ }
67
+
68
+ if (!this.isMinimized) {
69
+ this.openPanel();
70
+ }
71
+ });
72
+
73
+ button.addEventListener('mouseenter', () => {
74
+ if (!this.state.isSubmitting && !this.isMinimized) {
75
+ button.style.transform = 'translateY(-2px)';
76
+ }
77
+ });
78
+
79
+ button.addEventListener('mouseleave', () => {
80
+ if (!this.isMinimized) {
81
+ button.style.transform = 'translateY(0)';
82
+ }
83
+ });
84
+ }
85
+
86
+ minimize() {
87
+ this.isMinimized = true;
88
+ this.element.classList.add('minimized');
89
+ }
90
+
91
+ restore() {
92
+ this.isMinimized = false;
93
+ this.element.classList.remove('minimized');
94
+ }
95
+
96
+ mount(container) {
97
+ super.mount(container);
98
+ }
99
+
100
+ updateText(text) {
101
+ const textEl = this.element?.querySelector('.feedback-text');
102
+ if (textEl) {
103
+ textEl.textContent = text;
104
+ }
105
+ }
106
+
107
+ updatePosition(position) {
108
+ this.options.position = position;
109
+ if (this.element) {
110
+ this.element.className = this.element.className.replace(
111
+ /position-\w+-\w+/,
112
+ `position-${position}`
113
+ );
114
+ }
115
+ }
116
+ }