noph-ui 0.17.10 → 0.17.11

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.
@@ -15,7 +15,19 @@
15
15
  ...attributes
16
16
  }: TabProps = $props()
17
17
  let activeTab: { value: string | number; node: HTMLElement } = getContext('activeTab')
18
- let isActive = $derived(activeTab.value === value)
18
+ let element: HTMLElement | undefined = $state()
19
+ let isActive = $state(activeTab.value === value)
20
+
21
+ $effect(() => {
22
+ if (activeTab.value === value) {
23
+ if (element && element !== activeTab.node) {
24
+ setTabActive(element)
25
+ }
26
+ isActive = true
27
+ } else {
28
+ isActive = false
29
+ }
30
+ })
19
31
 
20
32
  const setTabActive = (el: HTMLElement) => {
21
33
  const oldTab = activeTab.node as HTMLElement | undefined
@@ -27,10 +39,12 @@
27
39
  '--np-tab-indicator-start',
28
40
  `${oldIndicatorRect.x - newIndicator.getBoundingClientRect().x}px`,
29
41
  )
42
+ newIndicator?.style.setProperty('--np-tab-indicator-width', `${oldIndicatorRect.width}px`)
30
43
  }
31
44
  activeTab.value = value
32
45
  activeTab.node = el
33
46
  }
47
+
34
48
  const setActiveTab = (el: HTMLElement) => {
35
49
  if (isActive) {
36
50
  activeTab.node = el
@@ -83,6 +97,7 @@
83
97
  {...attributes}
84
98
  tabindex={isActive ? 0 : -1}
85
99
  role="tab"
100
+ bind:this={element}
86
101
  {href}
87
102
  class={[
88
103
  'np-tab',
@@ -101,6 +116,7 @@
101
116
  {...attributes}
102
117
  tabindex={isActive ? 0 : -1}
103
118
  role="tab"
119
+ bind:this={element}
104
120
  class={[
105
121
  'np-tab',
106
122
  variant === 'secondary' && 'np-tab-secondary',
@@ -177,9 +193,11 @@
177
193
 
178
194
  @keyframes slide {
179
195
  0% {
196
+ width: var(--np-tab-indicator-width, 100%);
180
197
  transform: translateX(var(--np-tab-indicator-start));
181
198
  }
182
199
  100% {
200
+ width: 100%;
183
201
  transform: translateX(0);
184
202
  }
185
203
  }
@@ -13,6 +13,9 @@
13
13
  $effect(() => {
14
14
  value = active.value
15
15
  })
16
+ $effect(() => {
17
+ active.value = value
18
+ })
16
19
  </script>
17
20
 
18
21
  <div {...attributes} class={[attributes.class]}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noph-ui",
3
- "version": "0.17.10",
3
+ "version": "0.17.11",
4
4
  "license": "MIT",
5
5
  "homepage": "https://noph.dev",
6
6
  "repository": {