@estiva-app/ui 0.77.0 → 0.78.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/ui",
3
- "version": "0.77.0",
3
+ "version": "0.78.0",
4
4
  "description": "Estiva's design tokens (the contract) and a small set of primitives (a convenience) for every Estiva app.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/registry.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "kind": "package",
5
5
  "repo": "estiva-ui",
6
6
  "package": "@estiva-app/ui",
7
- "packageVersion": "0.77.0",
7
+ "packageVersion": "0.78.0",
8
8
  "exports": 203,
9
9
  "typeExports": 197,
10
10
  "files": null
@@ -5611,6 +5611,12 @@
5611
5611
  "required": false,
5612
5612
  "note": "Shown only while the row is pointed at or focused, left of the count: a neutral `Chip`, typically."
5613
5613
  },
5614
+ {
5615
+ "name": "tooltip",
5616
+ "takes": "text",
5617
+ "required": false,
5618
+ "note": "A sentence about the item, in the package's tooltip while the label is pointed at; the row stays one line."
5619
+ },
5614
5620
  {
5615
5621
  "name": "unread",
5616
5622
  "takes": "true/false",
package/src/NavItem.mdx CHANGED
@@ -51,6 +51,14 @@ count — a muted mono number whose tooltip says what it counts.
51
51
 
52
52
  <Canvas of={NavItemStories.WithHintLongLabel} />
53
53
 
54
+ - A sentence about the item, for whoever points at it, is `tooltip`: it
55
+ shows in the package's tooltip while the **label** is pointed at, and the
56
+ row stays one line. The ⋮ and the `action` keep their own tooltips. Absent
57
+ or blank, there is none. A screen with no hover never shows it, so it can
58
+ carry nothing the row needs.
59
+
60
+ <Canvas of={NavItemStories.LabelTooltip} />
61
+
54
62
  - Something new on the row is `unread`: its words and icon brighten, the
55
63
  label is set in medium, and the **UnreadDot** sits at the right.
56
64
  `urgent` with it draws the warning badge in the dot's place. Say "unread"
@@ -122,6 +122,11 @@ export const WithActionAndMenu: Story = {
122
122
  args: { label: 'An item whose label runs much longer than the column has room for', icon: placeholder, action: REMOVE, menu: MENU },
123
123
  }
124
124
 
125
+ /** A sentence about the item: point at the label and it shows in the tooltip. The row stays one line. */
126
+ export const LabelTooltip: Story = {
127
+ args: { icon: placeholder, action: REMOVE, tooltip: 'One sentence saying what this item is about, shown while its label is pointed at.' },
128
+ }
129
+
125
130
  /** A hint and a button: point at it and the chip shows, then the button — a row whose state is a word (here, archived) and which can be taken off the list. */
126
131
  export const WithActionAndHint: Story = {
127
132
  args: { label: 'An item whose label runs much longer than the column has room for', icon: placeholder, action: REMOVE, hint: <Chip type="neutral" label="Archived" /> },
@@ -6,7 +6,7 @@
6
6
  * The reveal on hover and the slide are Chrome's to show.
7
7
  */
8
8
  import { afterEach, describe, expect, it, vi } from 'vitest'
9
- import { cleanup, render, screen } from '@testing-library/react'
9
+ import { cleanup, render, screen, waitFor } from '@testing-library/react'
10
10
  import userEvent from '@testing-library/user-event'
11
11
  import { NavItem } from './NavItem'
12
12
 
@@ -177,3 +177,42 @@ describe('NavItem with a button of its own', () => {
177
177
  expect(container.querySelector('[data-unread]')!.parentElement!.className.split(' ')).toContain('group-hover/nav:opacity-0')
178
178
  })
179
179
  })
180
+
181
+ describe('NavItem with a tooltip', () => {
182
+ it('shows it while the label is pointed at, and none when it is absent or blank', async () => {
183
+ const user = userEvent.setup()
184
+ render(
185
+ <>
186
+ <NavItem href="#" label="Item one" tooltip="A sentence about item one." />
187
+ <NavItem href="#" label="Item two" tooltip=" " />
188
+ <NavItem href="#" label="Item three" />
189
+ </>,
190
+ )
191
+ // The blank and absent ones first, so a tooltip still closing cannot answer for them.
192
+ for (const label of ['Item two', 'Item three']) {
193
+ await user.hover(screen.getByText(label))
194
+ await new Promise((r) => setTimeout(r, 400))
195
+ expect(screen.queryByRole('tooltip')).toBeNull()
196
+ await user.unhover(screen.getByText(label))
197
+ }
198
+ await user.hover(screen.getByText('Item one'))
199
+ expect((await screen.findByRole('tooltip')).textContent).toBe('A sentence about item one.')
200
+ await user.unhover(screen.getByText('Item one'))
201
+ await waitFor(() => expect(screen.queryByRole('tooltip')).toBeNull())
202
+ })
203
+
204
+ it('keeps the row one line, and the label inside the link', () => {
205
+ render(<NavItem href="#" label="Item one" tooltip="A sentence about item one." />)
206
+ const link = screen.getByRole('link', { name: 'Item one' })
207
+ expect(link.contains(screen.getByText('Item one'))).toBe(true)
208
+ expect(link.className.split(' ')).toContain('h-8')
209
+ expect(screen.getByText('Item one').className.split(' ')).toContain('truncate')
210
+ })
211
+
212
+ it('leaves the action its own tooltip: pointing at it shows the action’s, not the label’s', async () => {
213
+ const user = userEvent.setup()
214
+ render(<NavItem href="#" label="Item one" tooltip="A sentence about item one." action={{ icon: <span>x</span>, tooltip: 'Remove from list', onClick: () => {} }} />)
215
+ await user.hover(screen.getByRole('button', { name: 'Remove from list: Item one' }))
216
+ expect((await screen.findByRole('tooltip')).textContent).toBe('Remove from list')
217
+ })
218
+ })
package/src/NavItem.tsx CHANGED
@@ -72,6 +72,8 @@ export interface NavItemProps extends Omit<ComponentPropsWithoutRef<'a'>, 'href'
72
72
  action?: SectionAction
73
73
  /** Shown only while the row is pointed at or focused, left of the count: a neutral `Chip`, typically. */
74
74
  hint?: ReactNode
75
+ /** A sentence about the item, in the package's tooltip while the label is pointed at; the row stays one line. Absent or blank, no tooltip. */
76
+ tooltip?: string
75
77
  /** Something new here: brighter words, the label in medium, and the `UnreadDot` at the right. Say so in the row's own words for assistive tech too. */
76
78
  unread?: boolean
77
79
  /** With `unread`: the warning badge in the dot's place. */
@@ -97,6 +99,7 @@ export function NavItem({
97
99
  menuLabel,
98
100
  action,
99
101
  hint,
102
+ tooltip,
100
103
  unread = false,
101
104
  urgent = false,
102
105
  children,
@@ -163,7 +166,15 @@ export function NavItem({
163
166
  {icon}
164
167
  </span>
165
168
  )}
166
- <span className={cn('flex-1 truncate', unread && 'font-medium')}>{label}</span>
169
+ {tooltip?.trim() ? (
170
+ // On the label alone, not the row: the ⋮ and the action keep their
171
+ // own tooltips, and the two never stand up at once.
172
+ <WithTooltip label={tooltip} inline wrapperClassName="flex min-w-0 flex-1">
173
+ <span className={cn('flex-1 truncate', unread && 'font-medium')}>{label}</span>
174
+ </WithTooltip>
175
+ ) : (
176
+ <span className={cn('flex-1 truncate', unread && 'font-medium')}>{label}</span>
177
+ )}
167
178
  {hint != null && (
168
179
  // Takes room only while it shows, so the label gives way to it.
169
180
  <span className="hidden shrink-0 items-center group-hover/nav:flex group-has-[:focus-visible]/nav:flex">{hint}</span>