noph-ui 0.16.22 → 0.16.24

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.
@@ -174,6 +174,8 @@
174
174
  position: relative;
175
175
  padding: 0;
176
176
  box-sizing: border-box;
177
+ color: var(--np-color-on-surface);
178
+ text-decoration: none;
177
179
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
178
180
  border-radius: var(--border-radius);
179
181
  background-color: var(--background-color);
@@ -150,6 +150,7 @@
150
150
  padding: 0.75rem 1rem;
151
151
  min-height: 3.5rem;
152
152
  gap: 1rem;
153
+ text-decoration: none;
153
154
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
154
155
  color: var(--np-item-label-text-color, var(--np-color-on-surface));
155
156
  box-sizing: border-box;
@@ -58,6 +58,8 @@
58
58
  .np-navigation-drawer-item {
59
59
  cursor: pointer;
60
60
  font-family: inherit;
61
+ color: var(--np-color-on-surface);
62
+ text-decoration: none;
61
63
  border: 0;
62
64
  background: none;
63
65
  align-items: center;
@@ -49,6 +49,8 @@
49
49
  gap: 0.25rem;
50
50
  display: flex;
51
51
  flex-direction: column;
52
+ color: var(--np-color-on-surface);
53
+ text-decoration: none;
52
54
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
53
55
  }
54
56
  .np-navigation-action:focus-visible {
@@ -10,19 +10,20 @@
10
10
  onclick,
11
11
  onkeydown,
12
12
  value,
13
+ href,
13
14
  variant = 'primary',
14
15
  ...attributes
15
16
  }: TabProps = $props()
16
17
  let activeTab: { value: string | number; node: HTMLElement } = getContext('activeTab')
17
18
  let isActive = $derived(activeTab.value === value)
18
19
 
19
- const setTabActive = (el: HTMLDivElement) => {
20
+ const setTabActive = (el: HTMLElement) => {
20
21
  const oldTab = activeTab.node as HTMLElement | undefined
21
22
  const oldIndicator = oldTab?.querySelector('.np-indicator') as HTMLElement
22
23
  const oldIndicatorRect = oldIndicator?.getBoundingClientRect()
23
24
  if (oldIndicatorRect) {
24
- const newIndicator = el.querySelector('.np-indicator') as HTMLElement
25
- newIndicator.style.setProperty(
25
+ const newIndicator = el.querySelector<HTMLElement>('.np-indicator')
26
+ newIndicator?.style.setProperty(
26
27
  '--np-tab-indicator-start',
27
28
  `${oldIndicatorRect.x - newIndicator.getBoundingClientRect().x}px`,
28
29
  )
@@ -30,38 +31,28 @@
30
31
  activeTab.value = value
31
32
  activeTab.node = el
32
33
  }
33
- </script>
34
-
35
- <div
36
- {@attach (el) => {
34
+ const setActiveTab = (el: HTMLElement) => {
37
35
  if (isActive) {
38
36
  activeTab.node = el
39
37
  }
40
- }}
41
- {...attributes}
42
- tabindex={isActive ? 0 : -1}
43
- role="tab"
44
- class={[
45
- 'np-tab',
46
- variant === 'secondary' && 'np-tab-secondary',
47
- isActive && 'np-tab-content-active',
48
- attributes.class,
49
- ]}
50
- onclick={(event) => {
38
+ }
39
+ const onClick = (event: MouseEvent & { currentTarget: EventTarget & HTMLElement }) => {
51
40
  setTabActive(event.currentTarget)
52
41
  if (onclick) {
53
42
  onclick(event)
54
43
  }
55
- }}
56
- onkeydown={(event) => {
44
+ }
45
+ const onKeyDown = (event: KeyboardEvent & { currentTarget: EventTarget & HTMLElement }) => {
57
46
  if (event.key === 'Enter' || event.key === ' ') {
58
47
  setTabActive(event.currentTarget)
59
48
  }
60
49
  if (onkeydown) {
61
50
  onkeydown(event)
62
51
  }
63
- }}
64
- >
52
+ }
53
+ </script>
54
+
55
+ {#snippet content()}
65
56
  <div
66
57
  class="np-tab-content"
67
58
  style={variant === 'secondary' ? '--np-indicator-radius: 0;--_indicator-gap: 0' : ''}
@@ -84,7 +75,44 @@
84
75
  </div>
85
76
  <div class="focus-area"></div>
86
77
  <Ripple />
87
- </div>
78
+ {/snippet}
79
+
80
+ {#if href}
81
+ <a
82
+ {@attach setActiveTab}
83
+ {...attributes}
84
+ tabindex={isActive ? 0 : -1}
85
+ role="tab"
86
+ {href}
87
+ class={[
88
+ 'np-tab',
89
+ variant === 'secondary' && 'np-tab-secondary',
90
+ isActive && 'np-tab-content-active',
91
+ attributes.class,
92
+ ]}
93
+ onclick={onClick}
94
+ onkeydown={onKeyDown}
95
+ >
96
+ {@render content()}
97
+ </a>
98
+ {:else}
99
+ <div
100
+ {@attach setActiveTab}
101
+ {...attributes}
102
+ tabindex={isActive ? 0 : -1}
103
+ role="tab"
104
+ class={[
105
+ 'np-tab',
106
+ variant === 'secondary' && 'np-tab-secondary',
107
+ isActive && 'np-tab-content-active',
108
+ attributes.class,
109
+ ]}
110
+ onclick={onClick}
111
+ onkeydown={onKeyDown}
112
+ >
113
+ {@render content()}
114
+ </div>
115
+ {/if}
88
116
 
89
117
  <style>
90
118
  .np-tab {
@@ -94,9 +122,7 @@
94
122
  justify-content: center;
95
123
  font-family: inherit;
96
124
  box-sizing: border-box;
97
- -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
98
- background-color: transparent;
99
- border-width: 0;
125
+ text-decoration: none;
100
126
  position: relative;
101
127
  cursor: pointer;
102
128
  padding: 0 1rem;
@@ -3,13 +3,7 @@
3
3
  import { setContext } from 'svelte'
4
4
  import type { TabsProps } from './types.ts'
5
5
 
6
- let {
7
- children,
8
- element = $bindable(),
9
- value = $bindable(),
10
- onkeydown,
11
- ...attributes
12
- }: TabsProps = $props()
6
+ let { children, element = $bindable(), value = $bindable(), ...attributes }: TabsProps = $props()
13
7
  let active = $state({
14
8
  value: value,
15
9
  node: element?.firstChild as HTMLElement | undefined,
@@ -21,10 +15,9 @@
21
15
  })
22
16
  </script>
23
17
 
24
- <div>
18
+ <div {...attributes} class={[attributes.class]}>
25
19
  <div
26
- {...attributes}
27
- class={['np-tabs', attributes.class]}
20
+ class={['np-tabs']}
28
21
  role="tablist"
29
22
  tabindex="-1"
30
23
  bind:this={element}
@@ -38,9 +31,6 @@
38
31
  index < 0 ? tabs[tabs.length - 1] : index >= tabs.length ? tabs[0] : tabs[index]
39
32
  newTab.focus()
40
33
  }
41
- if (onkeydown) {
42
- onkeydown(event)
43
- }
44
34
  }}
45
35
  >
46
36
  {@render children?.()}
@@ -1,9 +1,10 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
- export interface TabProps extends HTMLAttributes<HTMLDivElement> {
3
+ export interface TabProps extends HTMLAttributes<HTMLElement> {
4
4
  variant?: 'primary' | 'secondary';
5
5
  inlineIcon?: boolean;
6
6
  value: string | number;
7
+ href?: string;
7
8
  icon?: Snippet;
8
9
  }
9
10
  export interface TabsProps extends HTMLAttributes<HTMLDivElement> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noph-ui",
3
- "version": "0.16.22",
3
+ "version": "0.16.24",
4
4
  "license": "MIT",
5
5
  "homepage": "https://noph.dev",
6
6
  "repository": {