@djcali570/component-lib 0.1.4 → 0.1.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.
package/README.md CHANGED
@@ -230,6 +230,7 @@ onUpdate={(v) => dialogUpdated(v)}
230
230
 
231
231
 
232
232
  # Updates
233
+ #### 0.1.5 - Fixed issue where Accordion did not handle dynamic content.
233
234
  #### 0.1.4 - Updated Accordion component to add innerPadding prop.
234
235
  #### 0.1.3 - Updated Time Picker to allow binding to timeText.
235
236
  #### 0.1.2 - Fixed some minor styling issues with Dialog component.
@@ -6,17 +6,17 @@
6
6
  let {
7
7
  colorScheme: partialColorScheme = {},
8
8
  title,
9
- panel,
9
+ panel,
10
10
  iconWidth = '1.2rem',
11
11
  iconHeight = '1.2rem',
12
- innerPadding = '0.5rem'
12
+ innerPadding = '0.5rem'
13
13
  }: {
14
14
  colorScheme?: Partial<Accordion5ColorScheme>;
15
15
  title?: Snippet;
16
- panel: Snippet;
16
+ panel: Snippet;
17
17
  iconWidth?: string;
18
18
  iconHeight?: string;
19
- innerPadding?: string;
19
+ innerPadding?: string;
20
20
  } = $props();
21
21
 
22
22
  // Default colorScheme
@@ -34,22 +34,53 @@
34
34
  let panelHeight = $state('0px'); // Store dynamic height
35
35
  let panelRef: HTMLDivElement | undefined = $state(); // Reference to inner panel
36
36
 
37
- // Toggle panel and update height
38
- function showPanel() {
39
- status = !status;
37
+ // Debounce utility to limit frequent updates
38
+ function debounce<T extends (...args: any[]) => void>(fn: T, delay: number) {
39
+ let timeout: ReturnType<typeof setTimeout>;
40
+ return (...args: Parameters<T>) => {
41
+ clearTimeout(timeout);
42
+ timeout = setTimeout(() => fn(...args), delay);
43
+ };
44
+ }
45
+
46
+ // Update panel height
47
+ const updateHeight = () => {
40
48
  if (status && panelRef) {
41
- // Set max-height to content height when opening
42
49
  panelHeight = `${panelRef.scrollHeight}px`;
43
50
  } else {
44
- // Reset to 0 when closing
45
51
  panelHeight = '0px';
46
52
  }
53
+ };
54
+
55
+ // Debounced height update
56
+ const debouncedUpdateHeight = debounce(updateHeight, 100);
57
+
58
+ // Toggle panel and update height
59
+ function showPanel() {
60
+ status = !status;
61
+ requestAnimationFrame(updateHeight); // Update height after status change
47
62
  }
48
63
 
49
- // Update height on content change (if panel content is dynamic)
64
+ // Observe panel content size changes
65
+ $effect(() => {
66
+ if (!panelRef) return;
67
+
68
+ const observer = new ResizeObserver(() => {
69
+ debouncedUpdateHeight();
70
+ });
71
+
72
+ observer.observe(panelRef);
73
+
74
+ // Cleanup observer on component destroy
75
+ return () => {
76
+ observer.disconnect();
77
+ };
78
+ });
79
+
80
+ // Update height when status changes
50
81
  $effect(() => {
51
82
  if (status && panelRef) {
52
- panelHeight = `${panelRef.scrollHeight}px`;
83
+ debouncedUpdateHeight();
53
84
  }
54
85
  });
55
86
  </script>
@@ -60,10 +91,10 @@
60
91
  --acc5-bgColor: {colorScheme.bgColor};
61
92
  --acc5-textColor: {colorScheme.textColor};
62
93
  --acc5-triggerColor: {colorScheme.triggerColor};
63
- --acc5-panelBgColor: {colorScheme.panelBgColor};
64
- --acc5-IconWidth: {iconWidth};
65
- --acc5-IconHeight: {iconHeight};
66
- --acc5-InnerPadding: {innerPadding}
94
+ --acc5-panelBgColor: {colorScheme.panelBgColor};
95
+ --acc5-IconWidth: {iconWidth};
96
+ --acc5-IconHeight: {iconHeight};
97
+ --acc5-InnerPadding: {innerPadding}
67
98
  "
68
99
  >
69
100
  <button onclick={showPanel}>
@@ -97,14 +128,14 @@
97
128
 
98
129
  <style>
99
130
  .accordion5 {
100
- width: 100%;
131
+ width: 100%;
101
132
  margin: 0 auto;
102
133
  border-radius: 0.5rem;
103
134
  overflow: hidden;
104
135
  }
105
136
 
106
137
  button {
107
- width: 100%;
138
+ width: 100%;
108
139
  padding: var(--acc5-InnerPadding);
109
140
  font-size: 1rem;
110
141
  cursor: pointer;
@@ -148,11 +179,12 @@
148
179
  background-color: var(--acc5-panelBgColor);
149
180
  transition: max-height 400ms ease-in-out;
150
181
  }
182
+
151
183
  .panel-head-icon.open {
152
184
  transform: rotate(180deg);
153
185
  }
154
186
 
155
187
  .accPanel-inner {
156
- padding-block: 0.5rem; /* Add padding to ensure content is visible */
188
+ padding-block: 0.5rem;
157
189
  }
158
190
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djcali570/component-lib",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",