noph-ui 0.16.23 → 0.17.0

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
@@ -67,6 +67,7 @@ Beta (No breaking changes expected)
67
67
  - Select
68
68
  - Snackbar
69
69
  - Text fields
70
+ - Tabs
70
71
 
71
72
  In progress (Breaking changes expected)
72
73
 
@@ -76,4 +77,3 @@ In progress (Breaking changes expected)
76
77
  - Navigation Drawer (Docs missing)
77
78
  - Navigation Rail (Badge is missing + Docs missing)
78
79
  - Tooltips (Positioning missing)
79
- - Tabs
@@ -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 {
@@ -113,7 +115,7 @@
113
115
 
114
116
  .np-navigation-action-selected .np-navigation-action-label {
115
117
  font-weight: var(--np-navigation-rail-item-selected-font-weight, 700);
116
- color: var(--np-color-on-surface);
118
+ color: var(--np-color-secondary);
117
119
  }
118
120
  .np-touch {
119
121
  height: 56px;
@@ -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;
@@ -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.23",
3
+ "version": "0.17.0",
4
4
  "license": "MIT",
5
5
  "homepage": "https://noph.dev",
6
6
  "repository": {