@estiva-app/ui 0.113.0 → 0.114.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.113.0",
3
+ "version": "0.114.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.113.0",
7
+ "packageVersion": "0.114.0",
8
8
  "exports": 253,
9
9
  "typeExports": 263,
10
10
  "files": null
@@ -8732,6 +8732,12 @@
8732
8732
  "takes": "text",
8733
8733
  "required": false,
8734
8734
  "note": "Extra classes on the trigger wrapper — e.g."
8735
+ },
8736
+ {
8737
+ "name": "openOnTap",
8738
+ "takes": "true/false",
8739
+ "required": false,
8740
+ "note": "A tap on the trigger opens the card, and a second tap closes it, for a touch screen, where nothing hovers (ACT-4: the dot beside a page's title)."
8735
8741
  }
8736
8742
  ],
8737
8743
  "variants": [
@@ -12361,6 +12367,12 @@
12361
12367
  "takes": "text",
12362
12368
  "required": false,
12363
12369
  "note": null
12370
+ },
12371
+ {
12372
+ "name": "quiet",
12373
+ "takes": "true/false",
12374
+ "required": false,
12375
+ "note": null
12364
12376
  }
12365
12377
  ],
12366
12378
  "variants": [],
@@ -107,6 +107,14 @@ There is no keyboard trigger, by design — see above.
107
107
  | pointer moves into the card | it stays up, and can be scrolled |
108
108
  | pointer leaves both | closes after 200ms |
109
109
  | Escape | closes |
110
+ | a tap on the trigger, with `openOnTap` | opens; a second tap closes it, and it stays closed |
111
+ | a screen reader's double-tap, with `openOnTap` | the same as a tap |
112
+
113
+ A touch screen has no hover, so without `openOnTap` a tap opens nothing: a row's card stays hover-only, because a
114
+ tap on a row opens the row. Pass `openOnTap` when the trigger opens nothing of its own, as a dot beside a page's
115
+ title does.
116
+
117
+ <Canvas of={PreviewCardStories.OnATap} />
110
118
 
111
119
  ## Props
112
120
 
@@ -1,5 +1,6 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite'
2
2
  import { IconSquareRounded } from '@tabler/icons-react'
3
+ import { IconButton } from './IconButton'
3
4
  import { MenuPanel } from './Menu'
4
5
  import { PreviewCard } from './PreviewCard'
5
6
  import { SkeletonBar } from './Skeleton'
@@ -118,6 +119,30 @@ export const OnARow: Story = {
118
119
  ),
119
120
  }
120
121
 
122
+ /**
123
+ * Live, with `openOnTap`: on a touch screen a tap on the trigger opens the
124
+ * card and a second tap closes it; a mouse still opens it by resting. For a
125
+ * trigger that answers a tap with nothing of its own.
126
+ */
127
+ export const OnATap: Story = {
128
+ parameters: { controls: { disable: true } },
129
+ render: () => (
130
+ <PreviewCard
131
+ openOnTap
132
+ content={
133
+ <span className="text-caption text-text-secondary">
134
+ This is the card. A tap on the button opened it, and another tap
135
+ closes it.
136
+ </span>
137
+ }
138
+ >
139
+ <IconButton aria-label="Item one">
140
+ <IconSquareRounded size={16} stroke={1.5} />
141
+ </IconButton>
142
+ </PreviewCard>
143
+ ),
144
+ }
145
+
121
146
  /**
122
147
  * A card taller than its cap scrolls, **and you can reach the scrollbar** —
123
148
  * which is the whole difference between this and a tooltip. Rest the pointer
@@ -7,12 +7,15 @@
7
7
  * tested beside itself. Placement is Floating UI's and is measured in a
8
8
  * browser — jsdom lays nothing out — so what is here is the behaviour.
9
9
  */
10
- import { afterEach, describe, expect, it } from 'vitest'
11
- import { cleanup, render, screen } from '@testing-library/react'
10
+ import { afterEach, describe, expect, it, vi } from 'vitest'
11
+ import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
12
12
  import userEvent from '@testing-library/user-event'
13
13
  import { PreviewCard } from './PreviewCard'
14
14
 
15
- afterEach(cleanup)
15
+ afterEach(() => {
16
+ cleanup()
17
+ vi.useRealTimers()
18
+ })
16
19
 
17
20
  describe('PreviewCard', () => {
18
21
  it('renders its trigger, and nothing of its content, until it opens', () => {
@@ -40,6 +43,72 @@ describe('PreviewCard', () => {
40
43
  expect(screen.queryByText('The rest of it')).toBeNull()
41
44
  })
42
45
 
46
+ it('with openOnTap, a tap on a touch screen opens the card and a second tap closes it', async () => {
47
+ const user = userEvent.setup()
48
+ render(
49
+ <PreviewCard content={<span>The rest of it</span>} openOnTap>
50
+ <span>A dot</span>
51
+ </PreviewCard>,
52
+ )
53
+ const dot = screen.getByText('A dot')
54
+ await user.pointer({ keys: '[TouchA]', target: dot })
55
+ expect(await screen.findByText('The rest of it')).toBeTruthy()
56
+ await user.pointer({ keys: '[TouchA]', target: dot })
57
+ expect(screen.queryByText('The rest of it')).toBeNull()
58
+ })
59
+
60
+ it('with openOnTap on a button, a tap that closes the card stays closed: focus from the tap does not reopen it a moment later', async () => {
61
+ vi.useFakeTimers()
62
+ render(
63
+ <PreviewCard content={<span>The rest of it</span>} openOnTap>
64
+ <button type="button">A dot</button>
65
+ </PreviewCard>,
66
+ )
67
+ const dot = screen.getByRole('button', { name: 'A dot' })
68
+ // A finger's tap on a button, in the order a phone sends it: the press and the lift, then the mouse events made
69
+ // from them, focus on the button and the click. Fired by hand, because user-event waits on a clock this test fakes.
70
+ const tap = () => {
71
+ fireEvent.pointerDown(dot, { pointerType: 'touch' })
72
+ fireEvent.pointerUp(dot, { pointerType: 'touch' })
73
+ fireEvent.mouseDown(dot)
74
+ act(() => dot.focus())
75
+ fireEvent.mouseUp(dot)
76
+ fireEvent.click(dot)
77
+ }
78
+ tap()
79
+ expect(screen.getByText('The rest of it')).toBeTruthy()
80
+ tap()
81
+ expect(screen.queryByText('The rest of it')).toBeNull()
82
+ act(() => {
83
+ vi.advanceTimersByTime(1000)
84
+ })
85
+ expect(screen.queryByText('The rest of it')).toBeNull()
86
+ })
87
+
88
+ it('with openOnTap, a click with no press before it (a screen reader double-tap) opens the card, and another closes it', async () => {
89
+ render(
90
+ <PreviewCard content={<span>The rest of it</span>} openOnTap>
91
+ <button type="button">A dot</button>
92
+ </PreviewCard>,
93
+ )
94
+ const dot = screen.getByRole('button', { name: 'A dot' })
95
+ fireEvent.click(dot)
96
+ expect(screen.queryByText('The rest of it')).not.toBeNull()
97
+ fireEvent.click(dot)
98
+ expect(screen.queryByText('The rest of it')).toBeNull()
99
+ })
100
+
101
+ it('without openOnTap, a tap on a touch screen opens nothing, so a row tapped opens the row', async () => {
102
+ const user = userEvent.setup()
103
+ render(
104
+ <PreviewCard content={<span>The rest of it</span>}>
105
+ <span>A row</span>
106
+ </PreviewCard>,
107
+ )
108
+ await user.pointer({ keys: '[TouchA]', target: screen.getByText('A row') })
109
+ expect(screen.queryByText('The rest of it')).toBeNull()
110
+ })
111
+
43
112
  /*
44
113
  * Not here: "the pointer can move into the card, and it scrolls" — the one
45
114
  * claim that separates this from a tooltip.
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from 'react'
1
+ import { useRef, useState, type PointerEvent, type ReactNode } from 'react'
2
2
  import { PreviewCard as BasePreviewCard } from '@base-ui/react/preview-card'
3
3
  import { cn } from './cn'
4
4
  import { ScrollArea } from './ScrollArea'
@@ -46,6 +46,13 @@ export interface PreviewCardProps {
46
46
  contentClassName?: string
47
47
  /** Extra classes on the trigger wrapper — e.g. `block w-full` for a row. */
48
48
  wrapperClassName?: string
49
+ /**
50
+ * A tap on the trigger opens the card, and a second tap closes it, for a
51
+ * touch screen, where nothing hovers (ACT-4: the dot beside a page's title).
52
+ * A mouse still opens it by resting. Off by default: a row's card stays
53
+ * hover-only, because a tap on a row opens the row.
54
+ */
55
+ openOnTap?: boolean
49
56
  }
50
57
 
51
58
  /** The card's own numbers: 12px from the trigger, 8px clear of every screen
@@ -65,9 +72,40 @@ const OPEN_DELAY = 350
65
72
  * here the card can be reached, so it can. */
66
73
  const CLOSE_DELAY = 200
67
74
 
68
- export function PreviewCard({ content, children, side = 'right', delay = OPEN_DELAY, closeDelay = CLOSE_DELAY, className, contentClassName, wrapperClassName }: PreviewCardProps) {
75
+ export function PreviewCard({ content, children, side = 'right', delay = OPEN_DELAY, closeDelay = CLOSE_DELAY, className, contentClassName, wrapperClassName, openOnTap = false }: PreviewCardProps) {
76
+ // Held here always, so turning `openOnTap` on or off never switches the card between controlled and not; without it
77
+ // every change is Base UI's own (hover, focus, Escape, a press outside), as before.
78
+ const [open, setOpen] = useState(false)
79
+ // The press the next click belongs to: its pointer type, and whether the card was open when it went down. A tap
80
+ // focuses a button inside, and focus may open the card before the click, so the click sets the opposite of what was
81
+ // there before the press, not of what focus just did. The click uses it up.
82
+ const press = useRef<{ pointerType: string; wasOpen: boolean } | undefined>(undefined)
83
+ // The last press's pointer type, which outlives the click: it says whether a focus that opens the card came from a tap.
84
+ const lastPointer = useRef<string | undefined>(undefined)
85
+ const onOpenChange = (next: boolean, details: BasePreviewCard.Root.ChangeEventDetails) => {
86
+ // Base UI opens on focus after its delay, on a timer a tap's close does not cancel: after a touch, a tapped-shut
87
+ // card would open again a moment later. On a touch screen only a tap opens it.
88
+ if (openOnTap && next && details.reason === 'trigger-focus' && lastPointer.current === 'touch') return
89
+ setOpen(next)
90
+ }
91
+ const tapHandlers = openOnTap
92
+ ? {
93
+ onPointerDown: (event: PointerEvent) => {
94
+ press.current = { pointerType: event.pointerType, wasOpen: open }
95
+ lastPointer.current = event.pointerType
96
+ },
97
+ onClick: () => {
98
+ const last = press.current
99
+ press.current = undefined
100
+ // A mouse or a pen opens it by resting, as Base UI treats both as able to hover. A touch, or a click with no
101
+ // press before it (a screen reader's double-tap sends only the click), sets the opposite.
102
+ if (last?.pointerType === 'mouse' || last?.pointerType === 'pen') return
103
+ setOpen(!(last ? last.wasOpen : open))
104
+ },
105
+ }
106
+ : {}
69
107
  return (
70
- <BasePreviewCard.Root>
108
+ <BasePreviewCard.Root open={open} onOpenChange={onOpenChange}>
71
109
  {/* The part renders an `<a>` by default, which a row is not; `render`
72
110
  makes it the wrapper this component has always been, and the trigger
73
111
  inside keeps whatever element it already is. */}
@@ -75,6 +113,7 @@ export function PreviewCard({ content, children, side = 'right', delay = OPEN_DE
75
113
  delay={delay}
76
114
  closeDelay={closeDelay}
77
115
  render={<span className={cn('inline-flex', wrapperClassName)} />}
116
+ {...tapHandlers}
78
117
  >
79
118
  {children}
80
119
  </BasePreviewCard.Trigger>
package/src/UnreadDot.mdx CHANGED
@@ -54,6 +54,7 @@ It does these by itself. Write none of them around it.
54
54
  | The 6px disc in a 24px slot | a sized box around a round div | |
55
55
  | `data-unread`, the attribute tests and photo runs select on | a marker of your own | |
56
56
  | Keeps its size in a tight row | `shrink-0` | |
57
+ | `quiet`: the same 6px as a ring, not marked `data-unread`, for a dot that is always there and has nothing new | a bordered div of your own | |
57
58
 
58
59
  ## Props
59
60
 
@@ -11,6 +11,9 @@ type Story = StoryObj<typeof meta>
11
11
 
12
12
  export const Default: Story = {}
13
13
 
14
+ /** Nothing new: the ring a dot that is always there draws, so the slot does not empty. */
15
+ export const Quiet: Story = { args: { quiet: true } }
16
+
14
17
  /** Beside a line of text, as a list row draws it: the slot keeps the row's height. */
15
18
  export const InARow: Story = {
16
19
  render: (args) => (
@@ -14,4 +14,9 @@ describe('UnreadDot', () => {
14
14
  expect(slot.className).toContain('w-6')
15
15
  expect((slot.firstElementChild as HTMLElement).className).toContain('w-1.5')
16
16
  })
17
+
18
+ it('a quiet dot, with nothing new, is not marked data-unread, so nothing reads it as unread', () => {
19
+ const { container } = render(<UnreadDot quiet />)
20
+ expect((container.firstElementChild as HTMLElement).hasAttribute('data-unread')).toBe(false)
21
+ })
17
22
  })
package/src/UnreadDot.tsx CHANGED
@@ -7,11 +7,16 @@ import { cn } from './cn'
7
7
  *
8
8
  * Purely visual: the row that draws it says "unread" in its own accessible
9
9
  * name, because a coloured disc reads as nothing to a screen reader.
10
+ *
11
+ * `quiet` draws the same 6px as a ring with nothing new: the dot beside a
12
+ * page's title, which is always there because it opens the page's list
13
+ * (ACT-4; the activity indicator prototype Miky approved, 10 November). A
14
+ * quiet dot is not marked `data-unread`.
10
15
  */
11
- export function UnreadDot({ className }: { className?: string }) {
16
+ export function UnreadDot({ className, quiet = false }: { className?: string; quiet?: boolean }) {
12
17
  return (
13
- <div className={cn('flex h-6 w-6 shrink-0 items-center justify-center', className)} data-unread>
14
- <div className="h-1.5 w-1.5 rounded-full bg-accent-primary" />
18
+ <div className={cn('flex h-6 w-6 shrink-0 items-center justify-center', className)} {...(quiet ? {} : { 'data-unread': '' })}>
19
+ <div className={cn('h-1.5 w-1.5 rounded-full', quiet ? 'border border-border-strong' : 'bg-accent-primary')} />
15
20
  </div>
16
21
  )
17
22
  }
@@ -66,7 +66,7 @@ fork freely, owe nothing back, mention it on the package's ticket.
66
66
  |---|---|
67
67
  | A list of verbs from a trigger | **Menu** — Escape, outside-click and the arrow keys come with it |
68
68
  | A panel of *content* from a trigger — a field, a toolbar, a small form | **Popover** — the menu's surface without a menu's keyboard |
69
- | More of a thing on hover | **PreviewCard** — unlike a tooltip, you can point at it; on a sidebar row, **NavItem** `preview` opens it |
69
+ | More of a thing on hover | **PreviewCard** — unlike a tooltip, you can point at it; on a sidebar row, **NavItem** `preview` opens it; `openOnTap` when nothing else on the trigger answers a tap |
70
70
  | A hint on hover or on keyboard focus | **Tooltip** / **WithTooltip** — one `TooltipProvider` at the app root shares the delay |
71
71
  | A strip of controls that act on one thing | **Toolbar** — one Tab stop for the row, arrow keys along it |
72
72
  | Reactions to choose from | **ReactionPicker** — the row; **Reaction** is the pill it produces |
@@ -120,7 +120,7 @@ The same conversation in every app; only its colours are each app's.
120
120
  | A box that can hold more than fits — a list that grows with its data counts, even when today's data fits | **ScrollArea** — its bar is drawn over the content and takes no width |
121
121
  | Text that can run long above things the reader needs, cut behind a fade | **ShowMore** — measures; what fits has no button |
122
122
  | A status, a count or a category, in a small pill | **Chip** — six colour types; the colour is the message, the label makes it legible |
123
- | Something new on a row or a card, no count | **UnreadDot** — the 6px dot in a 24px slot; in a sidebar row, **NavItem** `unread` draws it |
123
+ | Something new on a row or a card, no count | **UnreadDot** — the 6px dot in a 24px slot; in a sidebar row, **NavItem** `unread` draws it; `quiet` for a dot that is always there with nothing new |
124
124
  | One thing — a conversation, a project, an object — as a box you can pick | **Card** — the fill by what it sits on; `href` for a link, `hover="fill"` in a feed, `onPress` when a press opens it |
125
125
  | A section heading, chevron, hover actions, a count beside the title | **SectionHeader** |
126
126
  | A group of rows that opens and closes, and stays how you left it | **CollapsibleSection** — `storageKey` remembers |