@estiva-app/ui 0.92.0 → 0.92.1
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/dist/Button.d.ts +11 -1
- package/dist/Button.d.ts.map +1 -1
- package/dist/index.js +46 -47
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
- package/registry.json +13 -1
- package/src/Button.mdx +25 -3
- package/src/Button.stories.tsx +15 -1
- package/src/Button.test.tsx +33 -0
- package/src/Button.tsx +65 -49
package/package.json
CHANGED
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.92.
|
|
7
|
+
"packageVersion": "0.92.1",
|
|
8
8
|
"exports": 210,
|
|
9
9
|
"typeExports": 213,
|
|
10
10
|
"files": null
|
|
@@ -869,6 +869,18 @@
|
|
|
869
869
|
"required": false,
|
|
870
870
|
"note": "Why the action cannot succeed right now."
|
|
871
871
|
},
|
|
872
|
+
{
|
|
873
|
+
"name": "href",
|
|
874
|
+
"takes": "text",
|
|
875
|
+
"required": false,
|
|
876
|
+
"note": "A link that looks like a button: an anchor, so the address stays real for a modified click, a new tab or \"copy link address\", as `IconButton` and `Link` keep it."
|
|
877
|
+
},
|
|
878
|
+
{
|
|
879
|
+
"name": "external",
|
|
880
|
+
"takes": "true/false",
|
|
881
|
+
"required": false,
|
|
882
|
+
"note": "With `href`: another site, or another app."
|
|
883
|
+
},
|
|
872
884
|
{
|
|
873
885
|
"name": "children",
|
|
874
886
|
"takes": "anything",
|
package/src/Button.mdx
CHANGED
|
@@ -28,7 +28,9 @@ The push-button for an action: a verb, clicked once — "Create", "Save",
|
|
|
28
28
|
|
|
29
29
|
- An icon with no label → **IconButton**.
|
|
30
30
|
- Going somewhere rather than doing something → **Link**; **Tabs** or
|
|
31
|
-
**Breadcrumb** when it is a view or a trail.
|
|
31
|
+
**Breadcrumb** when it is a view or a trail. A way somewhere that must
|
|
32
|
+
stand as a button (the way out to another app) is this Button with
|
|
33
|
+
`href`, still a link.
|
|
32
34
|
- Choosing a value → **Select**. Acting from a popover list → **MenuItem**.
|
|
33
35
|
- A control the person may never be allowed to use is **absent, not
|
|
34
36
|
disabled**. `disabled` is for *momentarily* unavailable — and it says why,
|
|
@@ -62,6 +64,26 @@ import { IconPlus } from '@tabler/icons-react'
|
|
|
62
64
|
wrapper — what a caller gets is the `<button>`, and a `Menu.Trigger` or
|
|
63
65
|
a `Dialog.Close` can be it.
|
|
64
66
|
|
|
67
|
+
- **A link that looks like a button**: give it `href`. It draws an `<a>`
|
|
68
|
+
with the same look, so a modified click, a new tab and "copy link
|
|
69
|
+
address" work. `external` opens another site or another app in a new
|
|
70
|
+
tab, with `noopener noreferrer`, as Link's does. A link cannot be
|
|
71
|
+
disabled: with `disabled` or `disabledReason` it is the button again,
|
|
72
|
+
and says why.
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { Button, WithTooltip } from '@estiva-app/ui'
|
|
76
|
+
import { IconExternalLink } from '@tabler/icons-react'
|
|
77
|
+
|
|
78
|
+
<WithTooltip label="Open in the app that owns it">
|
|
79
|
+
<Button href={url} external size="small" leadingIcon={<IconExternalLink stroke={1.5} className="size-3.5" />}>
|
|
80
|
+
Open
|
|
81
|
+
</Button>
|
|
82
|
+
</WithTooltip>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
<Canvas of={ButtonStories.OpensAnotherApp} />
|
|
86
|
+
|
|
65
87
|
- `variant="resolve"` is `primary` in every theme but Signal, where it is
|
|
66
88
|
outlined at rest and green when pointed at — the Resolve button. `IconButton`
|
|
67
89
|
has the same look.
|
|
@@ -75,7 +97,7 @@ It does these by itself. Write none of them around it.
|
|
|
75
97
|
|
|
76
98
|
| It does | So you never write | Refused when written by hand |
|
|
77
99
|
|---|---|---|
|
|
78
|
-
| Says what it is to assistive technology: a button | `role="button"` | ✓ |
|
|
100
|
+
| Says what it is to assistive technology: a button, or a link with `href` | `role="button"` | ✓ |
|
|
79
101
|
| Is reachable with Tab, also when it is disabled with a reason | a `tabIndex` | ✓ |
|
|
80
102
|
| Presses on Enter and Space, and does nothing while disabled | a key handler | |
|
|
81
103
|
| Keeps its 32px (24px small) in a scrolling column | `shrink-0` | |
|
|
@@ -85,7 +107,7 @@ It does these by itself. Write none of them around it.
|
|
|
85
107
|
| Key | Does |
|
|
86
108
|
|---|---|
|
|
87
109
|
| Tab | Onto the button, also when it is disabled with a reason; never when it is plain `disabled`. |
|
|
88
|
-
| Space / Enter | The action. Nothing while disabled. |
|
|
110
|
+
| Space / Enter | The action. Nothing while disabled. With `href`, Enter follows the link, as on any link. |
|
|
89
111
|
|
|
90
112
|
## Props
|
|
91
113
|
|
package/src/Button.stories.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
-
import { IconPlus } from '@tabler/icons-react'
|
|
2
|
+
import { IconExternalLink, IconPlus } from '@tabler/icons-react'
|
|
3
3
|
import { Button } from './Button'
|
|
4
4
|
|
|
5
5
|
const meta = {
|
|
@@ -86,3 +86,17 @@ export const AllVariants: Story = {
|
|
|
86
86
|
|
|
87
87
|
/** `resolve`: primary, and in Signal outlined at rest and green when pointed at — Resolve. */
|
|
88
88
|
export const Resolve: Story = { args: { variant: 'resolve', children: 'Resolve' } }
|
|
89
|
+
|
|
90
|
+
/** With `href` it is a link that looks like a button: Ctrl-click, a new tab and "copy link address" work as on any link. */
|
|
91
|
+
export const AsALink: Story = { args: { href: '#', children: 'Go to the list' } }
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* `external`: another site or another app, in a new tab. The small quiet button with the external-link icon is the
|
|
95
|
+
* way out to the app that owns a file; its tooltip names that app.
|
|
96
|
+
*/
|
|
97
|
+
export const OpensAnotherApp: Story = {
|
|
98
|
+
args: { href: 'https://example.com', external: true, size: 'small', leadingIcon: <IconExternalLink stroke={1.5} className="size-3.5" />, children: 'Open' },
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** A link cannot be disabled: with `disabledReason` (or `disabled`) it draws as the button, and says why. */
|
|
102
|
+
export const ALinkWithAReason: Story = { args: { href: 'https://example.com', external: true, disabledReason: 'Sign in to open it', children: 'Open' } }
|
package/src/Button.test.tsx
CHANGED
|
@@ -135,4 +135,37 @@ describe('Button', () => {
|
|
|
135
135
|
expect(button.getAttribute('data-x')).toBe('y')
|
|
136
136
|
expect(button.classList.contains('mt-2')).toBe(true)
|
|
137
137
|
})
|
|
138
|
+
|
|
139
|
+
it('with an address it is a link a person can follow; another app opens in a new tab', () => {
|
|
140
|
+
render(
|
|
141
|
+
<>
|
|
142
|
+
<Button href="/list">Go to the list</Button>
|
|
143
|
+
<Button href="https://example.com/file" external size="small">
|
|
144
|
+
Open
|
|
145
|
+
</Button>
|
|
146
|
+
</>,
|
|
147
|
+
)
|
|
148
|
+
const inPlace = screen.getByRole('link', { name: 'Go to the list' })
|
|
149
|
+
expect(inPlace.getAttribute('href')).toBe('/list')
|
|
150
|
+
expect(inPlace.hasAttribute('target')).toBe(false)
|
|
151
|
+
const out = screen.getByRole('link', { name: 'Open' })
|
|
152
|
+
expect(out.getAttribute('href')).toBe('https://example.com/file')
|
|
153
|
+
expect(out.getAttribute('target')).toBe('_blank')
|
|
154
|
+
expect(out.getAttribute('rel')).toBe('noopener noreferrer')
|
|
155
|
+
expect(screen.queryByRole('button')).toBeNull()
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('a link that cannot be followed right now is the button, saying why', async () => {
|
|
159
|
+
const user = userEvent.setup()
|
|
160
|
+
render(
|
|
161
|
+
<Button href="https://example.com/file" external disabledReason="Sign in to open it">
|
|
162
|
+
Open
|
|
163
|
+
</Button>,
|
|
164
|
+
)
|
|
165
|
+
expect(screen.queryByRole('link')).toBeNull()
|
|
166
|
+
const button = screen.getByRole('button', { name: 'Open' })
|
|
167
|
+
expect(button.getAttribute('aria-disabled')).toBe('true')
|
|
168
|
+
await user.hover(button)
|
|
169
|
+
expect((await screen.findByRole('tooltip')).textContent).toBe('Sign in to open it')
|
|
170
|
+
})
|
|
138
171
|
})
|
package/src/Button.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ComponentPropsWithRef, ReactNode } from 'react'
|
|
2
2
|
import { Button as BaseButton } from '@base-ui/react/button'
|
|
3
|
+
import { useInAppClick } from './AppProvider'
|
|
3
4
|
import { cn } from './cn'
|
|
4
5
|
import { useFormBusy } from './formBusy'
|
|
5
6
|
import { TooltipTrigger } from './Tooltip'
|
|
@@ -56,6 +57,16 @@ export interface ButtonProps extends ComponentPropsWithRef<'button'> {
|
|
|
56
57
|
/** Why the action cannot succeed right now. Disables the button, keeps it
|
|
57
58
|
* reachable by keyboard, and shows the reason as a tooltip on hover. */
|
|
58
59
|
disabledReason?: string
|
|
60
|
+
/**
|
|
61
|
+
* A link that looks like a button: an anchor, so the address stays real for a
|
|
62
|
+
* modified click, a new tab or "copy link address", as `IconButton` and `Link`
|
|
63
|
+
* keep it. A router app's `navigate` (AppProvider) moves in place. A link
|
|
64
|
+
* cannot be disabled, so while it would be (`disabled`, `disabledReason`, a
|
|
65
|
+
* busy Form) it is the button (Katerina, 30 October).
|
|
66
|
+
*/
|
|
67
|
+
href?: string
|
|
68
|
+
/** With `href`: another site, or another app. Opens in a new tab, with `noopener noreferrer`, as `Link`'s does. */
|
|
69
|
+
external?: boolean
|
|
59
70
|
children: ReactNode
|
|
60
71
|
}
|
|
61
72
|
|
|
@@ -68,59 +79,64 @@ export function Button({
|
|
|
68
79
|
disabled,
|
|
69
80
|
disabledReason,
|
|
70
81
|
type = 'button',
|
|
82
|
+
href,
|
|
83
|
+
external = false,
|
|
71
84
|
...props
|
|
72
85
|
}: ButtonProps) {
|
|
73
86
|
const hasLeadingIcon = !!leadingIcon
|
|
74
87
|
// Inside a busy Form: switched off, and looking it (formBusy.ts).
|
|
75
88
|
const formBusy = useFormBusy()
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
89
|
+
const unusable = disabled || !!disabledReason || formBusy
|
|
90
|
+
const anchor = props as unknown as ComponentPropsWithRef<'a'>
|
|
91
|
+
const inApp = useInAppClick(href, anchor.onClick)
|
|
92
|
+
const look = (off: boolean) =>
|
|
93
|
+
cn(
|
|
94
|
+
// No `self-center` here, deliberately — `IconButton` needs it and this
|
|
95
|
+
// does not, and the difference is the `h-8` / `h-6` on the next two
|
|
96
|
+
// lines. `align-items: stretch` only stretches a child whose cross
|
|
97
|
+
// size is `auto`; a Button always states its height, so a stretching
|
|
98
|
+
// parent cannot change it. Measured in Chrome on 2026-09-12, in the
|
|
99
|
+
// 260px row of Finding 49: 32px with `self-center` and 32px without.
|
|
100
|
+
// What the class DID do was override the caller on the other axis —
|
|
101
|
+
// in a column it beats the parent's `items-start`, which centred the
|
|
102
|
+
// four actions in Ship's `ProjectRail` and the trigger in five of
|
|
103
|
+
// this package's own story frames, each of which asks for the top.
|
|
104
|
+
// A control does not get to decide where its caller puts it.
|
|
105
|
+
'inline-flex items-center justify-center gap-1 rounded-md transition-colors font-sans font-medium',
|
|
106
|
+
size === 'default' && 'h-8 min-h-8 text-btn-default',
|
|
107
|
+
size === 'small' && 'h-6 min-h-6 text-btn-small',
|
|
108
|
+
// Extra right padding beside a leading icon, for optical balance.
|
|
109
|
+
size === 'default' && (hasLeadingIcon ? 'pl-2 pr-3' : 'px-2'),
|
|
110
|
+
size === 'small' && (hasLeadingIcon ? 'pl-1.5 pr-2' : 'px-1.5'),
|
|
111
|
+
!off && (variant === 'primary' || variant === 'resolve') && 'bg-accent-primary hover:bg-accent-hover text-text-inverse cursor-pointer signal:font-semibold',
|
|
112
|
+
// @estiva-escape(no-copied-look): W2 (Katerina, 24 September: leave alone): an outlined button shares four words with Reaction's pill by coincidence
|
|
113
|
+
!off && variant === 'outlined' && 'border border-border-default hover:bg-bg-hover text-text-primary cursor-pointer',
|
|
114
|
+
!off && variant === 'muted' && 'hover:bg-bg-hover text-text-primary cursor-pointer',
|
|
115
|
+
!off && variant === 'destructive' && 'hover:bg-error-muted text-error-default cursor-pointer',
|
|
116
|
+
off && 'bg-bg-disabled text-text-disabled',
|
|
117
|
+
// `pointer-events-none` only where the button is truly out of reach.
|
|
118
|
+
// With a `disabledReason` the button IS the tooltip's trigger, and a
|
|
119
|
+
// trigger the pointer cannot land on never opens one — Base UI already
|
|
120
|
+
// swallows the click (`focusableWhenDisabled` gives `aria-disabled`
|
|
121
|
+
// and a prevented `onClick`), so nothing else needs it.
|
|
122
|
+
off && !disabledReason && 'pointer-events-none',
|
|
123
|
+
off && variant === 'outlined' && 'border border-border-default',
|
|
124
|
+
// Disabled too, as it always drew.
|
|
125
|
+
variant === 'resolve' &&
|
|
126
|
+
'signal:bg-transparent signal:border signal:border-border-default signal:text-text-primary signal:shadow-none signal:hover:bg-success-muted signal:hover:border-success-outline signal:hover:text-success-default signal:transition-colors',
|
|
127
|
+
className,
|
|
128
|
+
)
|
|
129
|
+
const button =
|
|
130
|
+
href && !unusable ? (
|
|
131
|
+
<a href={href} {...(external ? { target: '_blank', rel: 'noopener noreferrer' } : {})} className={look(false)} {...anchor} onClick={inApp}>
|
|
132
|
+
{leadingIcon}
|
|
133
|
+
{children}
|
|
134
|
+
</a>
|
|
135
|
+
) : (
|
|
136
|
+
<BaseButton type={type} disabled={unusable} focusableWhenDisabled={!!disabledReason} className={(state) => look(state.disabled)} {...props}>
|
|
137
|
+
{leadingIcon}
|
|
138
|
+
{children}
|
|
139
|
+
</BaseButton>
|
|
140
|
+
)
|
|
125
141
|
return disabledReason ? <TooltipTrigger label={disabledReason}>{button}</TooltipTrigger> : button
|
|
126
142
|
}
|