svelte-ant-design 0.5.1 → 0.6.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 +15 -5
- package/dist/Select/Select.svelte +2 -0
- package/dist/Tooltip/README.md +127 -0
- package/dist/Tooltip/Tooltip.svelte +251 -0
- package/dist/Tooltip/Tooltip.svelte.d.ts +44 -0
- package/dist/Tooltip/types.d.ts +17 -0
- package/dist/Tooltip/types.js +16 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/internal/clickable.d.ts +1 -0
- package/dist/internal/clickable.js +13 -0
- package/dist/internal/contrast.d.ts +16 -0
- package/dist/internal/contrast.js +38 -0
- package/dist/internal/popup/Popup.svelte +114 -11
- package/dist/internal/popup/Popup.svelte.d.ts +9 -0
- package/dist/internal/popup/layers.d.ts +4 -0
- package/dist/internal/popup/layers.js +54 -4
- package/dist/internal/popup/placement.d.ts +7 -1
- package/dist/internal/popup/placement.js +2 -1
- package/dist/internal/popup/triggers.js +14 -0
- package/dist/tokens.css +71 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -18,7 +18,15 @@ Ant Design.
|
|
|
18
18
|
|
|
19
19
|
## Status
|
|
20
20
|
|
|
21
|
-
Version `0.
|
|
21
|
+
Version `0.6.0`. Available components: `Button`, `Checkbox` (with `CheckboxGroup`), `Input` (with `InputTextArea`, `InputPassword`, `InputSearch` and `InputOTP`), `Select` (with `SelectOption` and `SelectOptGroup`), `Switch`, `Tooltip`. More components are planned.
|
|
22
|
+
|
|
23
|
+
## Browser support
|
|
24
|
+
|
|
25
|
+
Chrome 89, Firefox 85 and Safari 15.4, and newer versions. The tests of every change run in the latest Chromium, Firefox
|
|
26
|
+
and WebKit. The lowest versions run in a smoke test before a release (`npm run test:floor`: Chromium 90, the nearest
|
|
27
|
+
build to Chrome 89 that is available, Firefox 85 and WebKit 15.4). Not tested: a real Safari on macOS or iOS, and touch
|
|
28
|
+
devices. A newer feature that an older browser lacks falls back to the plain look: the high-contrast block (before
|
|
29
|
+
Firefox 89 and in Safari), `color-scheme` (before Firefox 96) and `overscroll-behavior` (before Safari 16).
|
|
22
30
|
|
|
23
31
|
## Installation
|
|
24
32
|
|
|
@@ -52,13 +60,15 @@ Vite in `tests/packaging`; other bundlers are not covered.
|
|
|
52
60
|
See the [Button](https://prostreyd.github.io/ant-design-svelte/components/button/),
|
|
53
61
|
[Checkbox](https://prostreyd.github.io/ant-design-svelte/components/checkbox/),
|
|
54
62
|
[Input](https://prostreyd.github.io/ant-design-svelte/components/input/),
|
|
55
|
-
[Select](https://prostreyd.github.io/ant-design-svelte/components/select/)
|
|
56
|
-
[Switch](https://prostreyd.github.io/ant-design-svelte/components/switch/)
|
|
63
|
+
[Select](https://prostreyd.github.io/ant-design-svelte/components/select/),
|
|
64
|
+
[Switch](https://prostreyd.github.io/ant-design-svelte/components/switch/) and
|
|
65
|
+
[Tooltip](https://prostreyd.github.io/ant-design-svelte/components/tooltip/) pages of the documentation site for
|
|
57
66
|
examples and the API tables, or [`src/lib/Button/README.md`](./src/lib/Button/README.md),
|
|
58
67
|
[`src/lib/Checkbox/README.md`](./src/lib/Checkbox/README.md),
|
|
59
68
|
[`src/lib/Input/README.md`](./src/lib/Input/README.md),
|
|
60
|
-
[`src/lib/Select/README.md`](./src/lib/Select/README.md)
|
|
61
|
-
[`src/lib/Switch/README.md`](./src/lib/Switch/README.md)
|
|
69
|
+
[`src/lib/Select/README.md`](./src/lib/Select/README.md),
|
|
70
|
+
[`src/lib/Switch/README.md`](./src/lib/Switch/README.md) and
|
|
71
|
+
[`src/lib/Tooltip/README.md`](./src/lib/Tooltip/README.md) in the repository.
|
|
62
72
|
|
|
63
73
|
### Colors and contrast
|
|
64
74
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { onMount, untrack, type Snippet } from 'svelte';
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
import Popup from '../internal/popup/Popup.svelte';
|
|
5
|
+
import { clickable } from '../internal/clickable.js';
|
|
5
6
|
import { resolveOption } from '../internal/options.js';
|
|
6
7
|
import { classList, styleText } from '../internal/semantic.js';
|
|
7
8
|
import { setSelectContext, type Registration } from './context.js';
|
|
@@ -799,6 +800,7 @@
|
|
|
799
800
|
classNames?.listItem
|
|
800
801
|
)}
|
|
801
802
|
style={styleText(styles?.listItem)}
|
|
803
|
+
use:clickable
|
|
802
804
|
onclick={() => selectEntry(entry)}
|
|
803
805
|
onmousemove={() => {
|
|
804
806
|
if (activeValue === entry.value || isDisabled) return;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Tooltip
|
|
2
|
+
|
|
3
|
+
A short text tip for an element, with Ant Design-inspired styles and a Svelte 5 API. It shows on hover and on
|
|
4
|
+
keyboard focus, never takes focus, and is placed next to its trigger by the popup primitive of the library (12
|
|
5
|
+
placements, flipping at the edge of the screen, an arrow, following scroll and resize).
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
Import the design tokens once in the application entry point:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import 'svelte-ant-design/tokens.css';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```svelte
|
|
16
|
+
<script lang="ts">
|
|
17
|
+
import { Button, Tooltip } from 'svelte-ant-design';
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<Tooltip title="Saves the draft">
|
|
21
|
+
<Button type="primary">Save</Button>
|
|
22
|
+
</Tooltip>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The child is **one element**. The tooltip wraps it in an element that has no box of its own (`display: contents`), so
|
|
26
|
+
the layout does not change; the tip is placed next to the first element inside. Text alone cannot be a trigger.
|
|
27
|
+
|
|
28
|
+
Control it from the parent with `bind:open`; `onopenchange` reports the changes the user causes:
|
|
29
|
+
|
|
30
|
+
```svelte
|
|
31
|
+
<script lang="ts">
|
|
32
|
+
let open = $state(false);
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<Tooltip bind:open title="Controlled" onopenchange={(next) => console.log(next)}>
|
|
36
|
+
<Button>Hover, focus or press the other button</Button>
|
|
37
|
+
</Tooltip>
|
|
38
|
+
<Button onclick={() => (open = !open)}>Toggle</Button>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
With no child, `anchor` places the tip at an element you hold:
|
|
42
|
+
|
|
43
|
+
```svelte
|
|
44
|
+
<Tooltip title="Here" anchor={element} open trigger={[]} />
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Props
|
|
48
|
+
|
|
49
|
+
| Prop | Type | Default | Description |
|
|
50
|
+
|------|------|---------|-------------|
|
|
51
|
+
| `title` | `string \| number \| Snippet \| null` | — | The text or the content. A string is text, never HTML. Empty (`undefined`, `null`, `''`) means no tooltip: it never opens, even with `open`. `0` is shown. |
|
|
52
|
+
| `children` | `Snippet` | — | The trigger: one element. |
|
|
53
|
+
| `open` | `boolean` (`$bindable`) | `false` | Whether the tip is shown. `bind:open` for two-way use; a plain value is the initial state. |
|
|
54
|
+
| `onopenchange` | `(open: boolean) => void` | — | Called once per change the user causes (trigger, `Escape`, press outside), not for a change the parent makes. |
|
|
55
|
+
| `placement` | `'top' \| 'topLeft' \| 'topRight' \| 'bottom' \| 'bottomLeft' \| 'bottomRight' \| 'left' \| 'leftTop' \| 'leftBottom' \| 'right' \| 'rightTop' \| 'rightBottom'` | `'top'` | The side of the trigger plus the alignment. Mirrored in right-to-left layouts, flipped at the edge of the screen. |
|
|
56
|
+
| `trigger` | `'hover' \| 'focus' \| 'click' \| 'contextMenu'`, or an array of them | `['hover', 'focus']` | What opens it. An empty array means it is only controlled. |
|
|
57
|
+
| `mouseEnterDelay` | `number` | `0.1` | Seconds before it shows on hover. |
|
|
58
|
+
| `mouseLeaveDelay` | `number` | `0.1` | Seconds before it hides after the pointer left. The pointer may move into the tip and rest in it. |
|
|
59
|
+
| `arrow` | `boolean \| { pointAtCenter: boolean }` | `true` | Shows an arrow; `pointAtCenter` points it at the middle of the trigger. |
|
|
60
|
+
| `autoAdjustOverflow` | `boolean` | `true` | Flip to the opposite side when there is no room, and shift along the edge for an unaligned placement. |
|
|
61
|
+
| `color` | `string` | — | One of the 13 preset names or any CSS color for the background; the text color follows. |
|
|
62
|
+
| `zIndex` | `number` | — | Overrides the z-index of the tooltip layer (`--ads-tooltip-z-index`, 1070). |
|
|
63
|
+
| `container` | `HTMLElement \| ((anchor: HTMLElement \| null) => HTMLElement)` | `document.body` | Where the tip is moved to. |
|
|
64
|
+
| `destroyOnHidden` | `boolean` | `false` | Remove the content from the DOM on every close. |
|
|
65
|
+
| `classNames` | `Partial<Record<'root' \| 'container' \| 'arrow', string>>` | — | Extra classes for the parts. |
|
|
66
|
+
| `styles` | `Partial<Record<'root' \| 'container' \| 'arrow', Record<string, string \| number>>>` | — | Inline styles for the parts. Names are kebab-case or custom properties; numbers are written as they are. |
|
|
67
|
+
| `anchor` | `HTMLElement \| null` | — | The element to place the tip next to, instead of the first element of `children`. |
|
|
68
|
+
|
|
69
|
+
Invalid values: `placement` and every value of `trigger` are checked. While developing (and in tests) an invalid
|
|
70
|
+
value throws a `RangeError`; in a production build the tooltip uses `top` and `hover` instead.
|
|
71
|
+
|
|
72
|
+
The parts: `root` is the positioned element, `container` the visible box, `arrow` the little square that points at the
|
|
73
|
+
trigger. On `root` the `styles` are set one property at a time, so the placement is kept.
|
|
74
|
+
|
|
75
|
+
### Colors
|
|
76
|
+
|
|
77
|
+
`color` takes one of the 13 preset names of the palette (`pink`, `red`, `yellow`, `orange`, `cyan`, `green`, `blue`,
|
|
78
|
+
`purple`, `geekblue`, `magenta`, `volcano`, `gold`, `lime`) or any CSS color (`#hex`, `rgb()`, `hsl()`, `var(--x)`). A
|
|
79
|
+
name from the list is a preset, so write `#0000ff` for the CSS blue. The backgrounds of the presets are the ones of
|
|
80
|
+
Ant Design, in the light and the dark theme. **The text is black or white, whichever contrasts more with the
|
|
81
|
+
background** (Ant Design draws white on every preset, which is below 4.5:1 on 11 of the 13 in the light theme), so
|
|
82
|
+
every preset and every custom color reaches 4.5:1. The presets are the tokens `--ads-tooltip-preset-<name>` and
|
|
83
|
+
`--ads-tooltip-preset-<name>-text`; the arrow follows the background. A color the browser cannot parse leaves the
|
|
84
|
+
default box (white on `#262626`, which is the 85% black of Ant Design over a white page; `#424242` in the dark theme).
|
|
85
|
+
|
|
86
|
+
## Accessibility
|
|
87
|
+
|
|
88
|
+
- The tip has `role="tooltip"` and an `id`. While it is shown, the trigger has `aria-describedby` pointing at it, merged
|
|
89
|
+
with a value you set yourself. When the trigger itself cannot take focus (a `<label>` around a checkbox, the box of a
|
|
90
|
+
`Select`) the attribute goes to the first focusable element inside it, because that is the element a screen reader
|
|
91
|
+
reads. The attribute is removed when the tip closes, so it never points at an id that is not on the page.
|
|
92
|
+
- It opens on keyboard focus as well as on hover (Ant Design for React: hover only), and closes when focus leaves.
|
|
93
|
+
`Escape` closes it and focus stays on the trigger. The tip never takes focus and is not in the Tab order, and the
|
|
94
|
+
pointer can move into it and rest there.
|
|
95
|
+
- **The trigger has to be focusable for the keyboard to reach the tip.** A `Button`, a link or a field is; a plain
|
|
96
|
+
`<span>` needs `tabindex="0"`.
|
|
97
|
+
- **A tooltip describes; it does not name.** An icon-only button still needs `aria-label`.
|
|
98
|
+
- Do not put links, buttons or other controls in a tooltip: it closes when focus leaves the trigger.
|
|
99
|
+
- Contrast: the default box is 15.1:1 on a white page and 10.0:1 in the dark theme; the text of the presets and of a
|
|
100
|
+
custom `color` reaches 4.5:1 (see Colors).
|
|
101
|
+
- In forced-colors modes such as Windows High Contrast the box and the arrow are drawn with a border in a system color.
|
|
102
|
+
- Under `prefers-reduced-motion: reduce` the animation is off. Positions use logical properties and the sides mirror in
|
|
103
|
+
right-to-left layouts.
|
|
104
|
+
- A tooltip on a **disabled button** shows its tip: checked in Chromium, Firefox and WebKit, current and at the lowest
|
|
105
|
+
supported versions (Chromium 90, Firefox 85, WebKit 15.4; not in a real Safari). A `<span>` around a control that
|
|
106
|
+
swallows pointer events by itself is the safe form.
|
|
107
|
+
- On a touch screen a tap shows the tip and runs the action, and a tap elsewhere closes it. The mouse events that a
|
|
108
|
+
browser sends after a tap (`mouseenter`, then at once `mouseleave`) do not close it.
|
|
109
|
+
- **Not checked:** with a real screen reader, and on a real touch device (touch is tested with emulated touch and a
|
|
110
|
+
swipe in Chromium only).
|
|
111
|
+
|
|
112
|
+
## Scope decisions and differences from Ant Design
|
|
113
|
+
|
|
114
|
+
- The trigger defaults to hover and focus (React: hover only); the 13 preset colors get a contrasting text color, where
|
|
115
|
+
Ant Design draws white.
|
|
116
|
+
- `defaultOpen`, `fresh`, `forceAlign`, `align` and the function form of `classNames` / `styles` (React), `arrowPointAtCenter`,
|
|
117
|
+
`overlayClassName`, `overlayStyle`, `overlayInnerStyle` and `destroyTooltipOnHide` (Vue, and old React names) and the
|
|
118
|
+
Angular methods `show()`, `hide()` and `updatePosition()` are not implemented: `bind:open`, `classNames` / `styles` as
|
|
119
|
+
objects and the automatic following of the layout cover them.
|
|
120
|
+
- `anchor` takes the place of Angular's `nzTooltipOrigin`. The `ConfigProvider` settings and `tooltip.unique` come with a
|
|
121
|
+
ConfigProvider component.
|
|
122
|
+
- See [`specs/tooltip.md`](../../../specs/tooltip.md) for the full comparison and the reasoning.
|
|
123
|
+
|
|
124
|
+
## Live examples
|
|
125
|
+
|
|
126
|
+
Interactive examples of every option, with their code and the API table, are on the
|
|
127
|
+
[documentation site](https://prostreyd.github.io/ant-design-svelte/components/tooltip/).
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { contrastText } from '../internal/contrast.js';
|
|
4
|
+
import { isProduction } from '../internal/env.js';
|
|
5
|
+
import { resolveOption } from '../internal/options.js';
|
|
6
|
+
import Popup from '../internal/popup/Popup.svelte';
|
|
7
|
+
import { popupTriggers } from '../internal/popup/triggers.js';
|
|
8
|
+
import { POPUP_PLACEMENTS } from '../internal/popup/types.js';
|
|
9
|
+
import { classList, styleText } from '../internal/semantic.js';
|
|
10
|
+
import {
|
|
11
|
+
TOOLTIP_PRESET_COLORS,
|
|
12
|
+
type TooltipArrow,
|
|
13
|
+
type TooltipClassNames,
|
|
14
|
+
type TooltipContainer,
|
|
15
|
+
type TooltipPlacement,
|
|
16
|
+
type TooltipPresetColor,
|
|
17
|
+
type TooltipStyles,
|
|
18
|
+
type TooltipTrigger
|
|
19
|
+
} from './types.js';
|
|
20
|
+
|
|
21
|
+
type TooltipProps = {
|
|
22
|
+
/**
|
|
23
|
+
* The text or the content of the tip. Empty (`undefined`, `null`, `''`) means no tooltip: it never opens, even when
|
|
24
|
+
* `open` is `true`. `0` is shown.
|
|
25
|
+
*/
|
|
26
|
+
title?: string | number | Snippet | null;
|
|
27
|
+
/** The trigger: one element. The tooltip is placed next to it and listens to it. */
|
|
28
|
+
children?: Snippet;
|
|
29
|
+
/** Whether the tooltip is shown. `bind:open` for two-way use; a plain `open={x}` is the initial value. */
|
|
30
|
+
open?: boolean;
|
|
31
|
+
/** Called once per change caused by the user (trigger, Escape, outside press), not for a change made by the parent. */
|
|
32
|
+
onopenchange?: (open: boolean) => void;
|
|
33
|
+
/** Preferred placement. Mirrored in right-to-left layouts, flipped at the edge of the screen. */
|
|
34
|
+
placement?: TooltipPlacement;
|
|
35
|
+
/** What opens it: one value or several. An empty array means it is only controlled. Default hover and focus. */
|
|
36
|
+
trigger?: TooltipTrigger | readonly TooltipTrigger[];
|
|
37
|
+
/** Delay before it shows on hover, in seconds. */
|
|
38
|
+
mouseEnterDelay?: number;
|
|
39
|
+
/** Delay before it hides after the pointer left, in seconds. The pointer may rest in the panel. */
|
|
40
|
+
mouseLeaveDelay?: number;
|
|
41
|
+
/** Shows an arrow. `{ pointAtCenter: true }` points it at the middle of the trigger. */
|
|
42
|
+
arrow?: TooltipArrow;
|
|
43
|
+
/** Flip to the opposite side when there is no room, and shift along the edge for an unaligned placement. */
|
|
44
|
+
autoAdjustOverflow?: boolean;
|
|
45
|
+
/** One of the 13 preset names, or any CSS color for the background. The text color follows. */
|
|
46
|
+
color?: string;
|
|
47
|
+
/** Overrides the z-index of the tooltip layer. */
|
|
48
|
+
zIndex?: number;
|
|
49
|
+
/** Where the panel is moved to. Default `document.body`. */
|
|
50
|
+
container?: TooltipContainer;
|
|
51
|
+
/** Remove the content from the DOM on every close. Default: it stays mounted after the first opening. */
|
|
52
|
+
destroyOnHidden?: boolean;
|
|
53
|
+
/** Extra classes for the `root`, `container` and `arrow` parts. */
|
|
54
|
+
classNames?: TooltipClassNames;
|
|
55
|
+
/** Inline styles for the `root`, `container` and `arrow` parts. */
|
|
56
|
+
styles?: TooltipStyles;
|
|
57
|
+
/** The element to place the tooltip next to, instead of the first element of `children`. */
|
|
58
|
+
anchor?: HTMLElement | null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const uid = $props.id();
|
|
62
|
+
|
|
63
|
+
let {
|
|
64
|
+
title,
|
|
65
|
+
children,
|
|
66
|
+
open = $bindable(false),
|
|
67
|
+
onopenchange,
|
|
68
|
+
placement = 'top',
|
|
69
|
+
trigger = ['hover', 'focus'],
|
|
70
|
+
mouseEnterDelay = 0.1,
|
|
71
|
+
mouseLeaveDelay = 0.1,
|
|
72
|
+
arrow = true,
|
|
73
|
+
autoAdjustOverflow = true,
|
|
74
|
+
color,
|
|
75
|
+
zIndex,
|
|
76
|
+
container,
|
|
77
|
+
destroyOnHidden = false,
|
|
78
|
+
classNames,
|
|
79
|
+
styles,
|
|
80
|
+
anchor
|
|
81
|
+
}: TooltipProps = $props();
|
|
82
|
+
|
|
83
|
+
const TRIGGERS = ['hover', 'focus', 'click', 'contextMenu'] as const;
|
|
84
|
+
const panelId = $derived(`ads-tooltip-${uid}`);
|
|
85
|
+
|
|
86
|
+
/** The panel (the positioned root of the popup), once it has been created by the first opening. */
|
|
87
|
+
let panel = $state<HTMLElement | null>(null);
|
|
88
|
+
/** The first element inside the wrapper: what the tooltip is placed next to, unless `anchor` is given. */
|
|
89
|
+
let firstElement = $state<HTMLElement | null>(null);
|
|
90
|
+
|
|
91
|
+
const resolvedPlacement = $derived(
|
|
92
|
+
resolveOption('Tooltip', 'placement', placement, POPUP_PLACEMENTS, 'top') as TooltipPlacement
|
|
93
|
+
);
|
|
94
|
+
const triggers = $derived(
|
|
95
|
+
(Array.isArray(trigger) ? [...trigger] : [trigger]).map((value) =>
|
|
96
|
+
resolveOption('Tooltip', 'trigger', value, TRIGGERS, 'hover')
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const hasTitle = $derived(title !== undefined && title !== null && title !== '');
|
|
101
|
+
const anchorElement = $derived(anchor ?? firstElement);
|
|
102
|
+
/** Open, and there is something to show. A parent that sets `open` with an empty title gets no panel. */
|
|
103
|
+
const popupOpen = $derived(open && hasTitle);
|
|
104
|
+
|
|
105
|
+
/** Changes the open state on behalf of the user. The parent may refuse (a function binding). */
|
|
106
|
+
function setOpen(next: boolean): void {
|
|
107
|
+
if (open === next) return;
|
|
108
|
+
open = next;
|
|
109
|
+
onopenchange?.(next);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Follows the first element of the wrapper while it changes (an `{#if}` swaps the child, a list re-renders).
|
|
113
|
+
function track(node: HTMLElement): () => void {
|
|
114
|
+
const read = () => {
|
|
115
|
+
firstElement = node.firstElementChild instanceof HTMLElement ? node.firstElementChild : null;
|
|
116
|
+
if (!firstElement && !isProduction() && node.textContent?.trim()) {
|
|
117
|
+
console.warn('Tooltip: the child must be one element; a text-only child cannot be a trigger.');
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
read();
|
|
121
|
+
const observer = new MutationObserver(read);
|
|
122
|
+
observer.observe(node, { childList: true });
|
|
123
|
+
return () => observer.disconnect();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// What can take focus. The description belongs to the element that does: a `Checkbox` is a label with an input inside,
|
|
127
|
+
// and a screen reader reads the description of the input, not the one of the label around it.
|
|
128
|
+
const FOCUSABLE =
|
|
129
|
+
'a[href], area[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), ' +
|
|
130
|
+
'textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable=""], [contenteditable="true"]';
|
|
131
|
+
|
|
132
|
+
// `aria-describedby` on the trigger only while the panel exists: a reference to an id that is not on the page is
|
|
133
|
+
// what accessibility scanners report. The trigger is the first element, or the first focusable element inside it;
|
|
134
|
+
// a trigger with nothing to focus (a plain `<span>`) gets it itself. A value the consumer already set is kept, and a
|
|
135
|
+
// rewrite of the attribute by the consumer's own markup is repaired.
|
|
136
|
+
$effect(() => {
|
|
137
|
+
const anchorTarget = anchorElement;
|
|
138
|
+
if (!popupOpen || panel === null || anchorTarget === null) return;
|
|
139
|
+
const target = anchorTarget.matches(FOCUSABLE) ? anchorTarget : (anchorTarget.querySelector<HTMLElement>(FOCUSABLE) ?? anchorTarget);
|
|
140
|
+
const id = panelId;
|
|
141
|
+
const tokens = () => (target.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean);
|
|
142
|
+
const add = () => {
|
|
143
|
+
const list = tokens();
|
|
144
|
+
if (!list.includes(id)) target.setAttribute('aria-describedby', [...list, id].join(' '));
|
|
145
|
+
};
|
|
146
|
+
add();
|
|
147
|
+
const observer = new MutationObserver(add);
|
|
148
|
+
observer.observe(target, { attributes: true, attributeFilter: ['aria-describedby'] });
|
|
149
|
+
return () => {
|
|
150
|
+
observer.disconnect();
|
|
151
|
+
const rest = tokens().filter((token) => token !== id);
|
|
152
|
+
if (rest.length > 0) target.setAttribute('aria-describedby', rest.join(' '));
|
|
153
|
+
else target.removeAttribute('aria-describedby');
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const preset = $derived(
|
|
158
|
+
color !== undefined && (TOOLTIP_PRESET_COLORS as readonly string[]).includes(color) ? (color as TooltipPresetColor) : null
|
|
159
|
+
);
|
|
160
|
+
/** A color that is not a preset, and that the browser understands. Anything else leaves the default box. */
|
|
161
|
+
const custom = $derived(
|
|
162
|
+
color && preset === null && typeof CSS !== 'undefined' && CSS.supports('color', color) ? color : null
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
// The text of a custom color: black or white, whichever contrasts more, read from the color the browser resolved
|
|
166
|
+
// on the visible box (so `rgb()`, `hsl()` and `var(--x)` all work). A preset has its text in a token.
|
|
167
|
+
let boxElement = $state<HTMLElement | null>(null);
|
|
168
|
+
// An effect, not a derived value: the color has to be read from the DOM after the box has been painted with it.
|
|
169
|
+
// eslint-disable-next-line svelte/prefer-writable-derived
|
|
170
|
+
let customText = $state<string | null>(null);
|
|
171
|
+
$effect(() => {
|
|
172
|
+
customText = boxElement === null || custom === null ? null : contrastText(getComputedStyle(boxElement).backgroundColor);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const colorStyle = $derived(
|
|
176
|
+
preset !== null
|
|
177
|
+
? `--ads-tooltip-bg: var(--ads-tooltip-preset-${preset}); --ads-tooltip-color: var(--ads-tooltip-preset-${preset}-text)`
|
|
178
|
+
: custom !== null
|
|
179
|
+
? `--ads-tooltip-bg: ${custom}${customText ? `; --ads-tooltip-color: ${customText}` : ''}`
|
|
180
|
+
: undefined
|
|
181
|
+
);
|
|
182
|
+
// The arrow takes the background of the box, so a color or a token set on the tooltip colors both.
|
|
183
|
+
const frameStyle = $derived(styleText('--ads-popup-arrow-bg: var(--ads-tooltip-bg)', colorStyle));
|
|
184
|
+
const containerClass = $derived(
|
|
185
|
+
classList('ads-tooltip', preset !== null && `ads-tooltip-preset-${preset}`, classNames?.container)
|
|
186
|
+
);
|
|
187
|
+
</script>
|
|
188
|
+
|
|
189
|
+
<span class="ads-tooltip-trigger" {@attach track} {@attach popupTriggers({
|
|
190
|
+
trigger: triggers,
|
|
191
|
+
open: () => open,
|
|
192
|
+
setOpen: (next) => setOpen(next),
|
|
193
|
+
mouseEnterDelay,
|
|
194
|
+
mouseLeaveDelay,
|
|
195
|
+
panel: () => panel,
|
|
196
|
+
disabled: !hasTitle
|
|
197
|
+
})}>{@render children?.()}</span>
|
|
198
|
+
|
|
199
|
+
<Popup
|
|
200
|
+
bind:open={() => popupOpen, setOpen}
|
|
201
|
+
bind:panel
|
|
202
|
+
anchor={hasTitle ? anchorElement : null}
|
|
203
|
+
placement={resolvedPlacement}
|
|
204
|
+
{autoAdjustOverflow}
|
|
205
|
+
{arrow}
|
|
206
|
+
{container}
|
|
207
|
+
{zIndex}
|
|
208
|
+
{destroyOnHidden}
|
|
209
|
+
layer="tooltip"
|
|
210
|
+
id={panelId}
|
|
211
|
+
role="tooltip"
|
|
212
|
+
style={frameStyle}
|
|
213
|
+
rootClass={classNames?.root}
|
|
214
|
+
rootStyle={styles?.root}
|
|
215
|
+
arrowClass={classNames?.arrow}
|
|
216
|
+
arrowStyle={styles?.arrow}
|
|
217
|
+
>
|
|
218
|
+
<div class={containerClass} style={styleText(styles?.container)} bind:this={boxElement}>
|
|
219
|
+
{#if typeof title === 'function'}{@render title()}{:else}{title}{/if}
|
|
220
|
+
</div>
|
|
221
|
+
</Popup>
|
|
222
|
+
|
|
223
|
+
<style>
|
|
224
|
+
/* No box of its own: the child lays out as if the wrapper were not there. */
|
|
225
|
+
.ads-tooltip-trigger {
|
|
226
|
+
display: contents;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.ads-tooltip {
|
|
230
|
+
box-sizing: border-box;
|
|
231
|
+
min-height: var(--ads-tooltip-min-height);
|
|
232
|
+
max-width: var(--ads-tooltip-max-width);
|
|
233
|
+
padding: var(--ads-tooltip-padding);
|
|
234
|
+
border-radius: min(var(--ads-tooltip-radius), 8px);
|
|
235
|
+
color: var(--ads-tooltip-color);
|
|
236
|
+
background: var(--ads-tooltip-bg);
|
|
237
|
+
font-family: var(--ads-font-family);
|
|
238
|
+
font-size: var(--ads-font-size);
|
|
239
|
+
line-height: 1.5714285714285714;
|
|
240
|
+
text-align: start;
|
|
241
|
+
overflow-wrap: break-word;
|
|
242
|
+
word-wrap: break-word;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/* Colors are replaced by the system colors: without a border the box would melt into the page. */
|
|
246
|
+
@media (forced-colors: active) {
|
|
247
|
+
.ads-tooltip {
|
|
248
|
+
border: 1px solid CanvasText;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
</style>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import { type TooltipArrow, type TooltipClassNames, type TooltipContainer, type TooltipPlacement, type TooltipStyles, type TooltipTrigger } from './types.js';
|
|
3
|
+
type TooltipProps = {
|
|
4
|
+
/**
|
|
5
|
+
* The text or the content of the tip. Empty (`undefined`, `null`, `''`) means no tooltip: it never opens, even when
|
|
6
|
+
* `open` is `true`. `0` is shown.
|
|
7
|
+
*/
|
|
8
|
+
title?: string | number | Snippet | null;
|
|
9
|
+
/** The trigger: one element. The tooltip is placed next to it and listens to it. */
|
|
10
|
+
children?: Snippet;
|
|
11
|
+
/** Whether the tooltip is shown. `bind:open` for two-way use; a plain `open={x}` is the initial value. */
|
|
12
|
+
open?: boolean;
|
|
13
|
+
/** Called once per change caused by the user (trigger, Escape, outside press), not for a change made by the parent. */
|
|
14
|
+
onopenchange?: (open: boolean) => void;
|
|
15
|
+
/** Preferred placement. Mirrored in right-to-left layouts, flipped at the edge of the screen. */
|
|
16
|
+
placement?: TooltipPlacement;
|
|
17
|
+
/** What opens it: one value or several. An empty array means it is only controlled. Default hover and focus. */
|
|
18
|
+
trigger?: TooltipTrigger | readonly TooltipTrigger[];
|
|
19
|
+
/** Delay before it shows on hover, in seconds. */
|
|
20
|
+
mouseEnterDelay?: number;
|
|
21
|
+
/** Delay before it hides after the pointer left, in seconds. The pointer may rest in the panel. */
|
|
22
|
+
mouseLeaveDelay?: number;
|
|
23
|
+
/** Shows an arrow. `{ pointAtCenter: true }` points it at the middle of the trigger. */
|
|
24
|
+
arrow?: TooltipArrow;
|
|
25
|
+
/** Flip to the opposite side when there is no room, and shift along the edge for an unaligned placement. */
|
|
26
|
+
autoAdjustOverflow?: boolean;
|
|
27
|
+
/** One of the 13 preset names, or any CSS color for the background. The text color follows. */
|
|
28
|
+
color?: string;
|
|
29
|
+
/** Overrides the z-index of the tooltip layer. */
|
|
30
|
+
zIndex?: number;
|
|
31
|
+
/** Where the panel is moved to. Default `document.body`. */
|
|
32
|
+
container?: TooltipContainer;
|
|
33
|
+
/** Remove the content from the DOM on every close. Default: it stays mounted after the first opening. */
|
|
34
|
+
destroyOnHidden?: boolean;
|
|
35
|
+
/** Extra classes for the `root`, `container` and `arrow` parts. */
|
|
36
|
+
classNames?: TooltipClassNames;
|
|
37
|
+
/** Inline styles for the `root`, `container` and `arrow` parts. */
|
|
38
|
+
styles?: TooltipStyles;
|
|
39
|
+
/** The element to place the tooltip next to, instead of the first element of `children`. */
|
|
40
|
+
anchor?: HTMLElement | null;
|
|
41
|
+
};
|
|
42
|
+
declare const Tooltip: import("svelte").Component<TooltipProps, {}, "open">;
|
|
43
|
+
type Tooltip = ReturnType<typeof Tooltip>;
|
|
44
|
+
export default Tooltip;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PopupArrow, PopupContainer, PopupPlacement, PopupTrigger } from '../internal/popup/types.js';
|
|
2
|
+
import type { SemanticStyle } from '../internal/semantic.js';
|
|
3
|
+
/** The 12 placements: the side of the trigger plus the alignment (`topLeft`: above, left edges aligned). */
|
|
4
|
+
export type TooltipPlacement = PopupPlacement;
|
|
5
|
+
/** What opens the tooltip. An array combines them; an empty array means the tooltip is only controlled. */
|
|
6
|
+
export type TooltipTrigger = PopupTrigger;
|
|
7
|
+
/** `true` shows the arrow; `{ pointAtCenter: true }` points it at the middle of the trigger instead of its aligned edge. */
|
|
8
|
+
export type TooltipArrow = PopupArrow;
|
|
9
|
+
/** Where the panel is moved to: an element, or a function that returns it. Default `document.body`. */
|
|
10
|
+
export type TooltipContainer = PopupContainer;
|
|
11
|
+
/** The 13 preset colors of the Ant Design palette. */
|
|
12
|
+
export declare const TOOLTIP_PRESET_COLORS: readonly ["pink", "red", "yellow", "orange", "cyan", "green", "blue", "purple", "geekblue", "magenta", "volcano", "gold", "lime"];
|
|
13
|
+
export type TooltipPresetColor = (typeof TOOLTIP_PRESET_COLORS)[number];
|
|
14
|
+
/** The named parts that `classNames` and `styles` address. */
|
|
15
|
+
export type TooltipSemanticName = 'root' | 'container' | 'arrow';
|
|
16
|
+
export type TooltipClassNames = Partial<Record<TooltipSemanticName, string>>;
|
|
17
|
+
export type TooltipStyles = Partial<Record<TooltipSemanticName, SemanticStyle>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** The 13 preset colors of the Ant Design palette. */
|
|
2
|
+
export const TOOLTIP_PRESET_COLORS = [
|
|
3
|
+
'pink',
|
|
4
|
+
'red',
|
|
5
|
+
'yellow',
|
|
6
|
+
'orange',
|
|
7
|
+
'cyan',
|
|
8
|
+
'green',
|
|
9
|
+
'blue',
|
|
10
|
+
'purple',
|
|
11
|
+
'geekblue',
|
|
12
|
+
'magenta',
|
|
13
|
+
'volcano',
|
|
14
|
+
'gold',
|
|
15
|
+
'lime'
|
|
16
|
+
];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.6.0";
|
|
2
2
|
export { default as Button } from './Button/Button.svelte';
|
|
3
3
|
export { default as Switch } from './Switch/Switch.svelte';
|
|
4
4
|
export { default as Checkbox } from './Checkbox/Checkbox.svelte';
|
|
@@ -6,6 +6,7 @@ export { default as CheckboxGroup } from './Checkbox/CheckboxGroup.svelte';
|
|
|
6
6
|
export { default as Select } from './Select/Select.svelte';
|
|
7
7
|
export { default as SelectOption } from './Select/SelectOption.svelte';
|
|
8
8
|
export { default as SelectOptGroup } from './Select/SelectOptGroup.svelte';
|
|
9
|
+
export { default as Tooltip } from './Tooltip/Tooltip.svelte';
|
|
9
10
|
export { default as Input } from './Input/Input.svelte';
|
|
10
11
|
export { default as InputOTP } from './Input/InputOTP.svelte';
|
|
11
12
|
export { default as InputPassword } from './Input/InputPassword.svelte';
|
|
@@ -16,3 +17,5 @@ export type { SelectAllowClear, SelectClassNames, SelectFieldNames, SelectFocusO
|
|
|
16
17
|
export type { CheckboxClassNames, CheckboxGroupClassNames, CheckboxGroupSemanticName, CheckboxGroupStyles, CheckboxOption, CheckboxSemanticName, CheckboxStyles, CheckboxValue } from './Checkbox/types.js';
|
|
17
18
|
export type { SwitchClassNames, SwitchSemanticName, SwitchSize, SwitchStyles } from './Switch/types.js';
|
|
18
19
|
export type { ButtonHTMLType, ButtonIconPlacement, ButtonLoading, ButtonShape, ButtonSize, ButtonType } from './Button/types.js';
|
|
20
|
+
export { TOOLTIP_PRESET_COLORS } from './Tooltip/types.js';
|
|
21
|
+
export type { TooltipArrow, TooltipClassNames, TooltipContainer, TooltipPlacement, TooltipPresetColor, TooltipSemanticName, TooltipStyles, TooltipTrigger } from './Tooltip/types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Public API of the library. Components are re-exported from here.
|
|
2
|
-
export const VERSION = '0.
|
|
2
|
+
export const VERSION = '0.6.0';
|
|
3
3
|
export { default as Button } from './Button/Button.svelte';
|
|
4
4
|
export { default as Switch } from './Switch/Switch.svelte';
|
|
5
5
|
export { default as Checkbox } from './Checkbox/Checkbox.svelte';
|
|
@@ -7,8 +7,10 @@ export { default as CheckboxGroup } from './Checkbox/CheckboxGroup.svelte';
|
|
|
7
7
|
export { default as Select } from './Select/Select.svelte';
|
|
8
8
|
export { default as SelectOption } from './Select/SelectOption.svelte';
|
|
9
9
|
export { default as SelectOptGroup } from './Select/SelectOptGroup.svelte';
|
|
10
|
+
export { default as Tooltip } from './Tooltip/Tooltip.svelte';
|
|
10
11
|
export { default as Input } from './Input/Input.svelte';
|
|
11
12
|
export { default as InputOTP } from './Input/InputOTP.svelte';
|
|
12
13
|
export { default as InputPassword } from './Input/InputPassword.svelte';
|
|
13
14
|
export { default as InputSearch } from './Input/InputSearch.svelte';
|
|
14
15
|
export { default as InputTextArea } from './Input/InputTextArea.svelte';
|
|
16
|
+
export { TOOLTIP_PRESET_COLORS } from './Tooltip/types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function clickable(node: HTMLElement): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes WebKit send the `click` of a tap to an element that is not a link, a button or a field.
|
|
3
|
+
*
|
|
4
|
+
* In WebKit a tap on such an element sends no `click` (and no `mousedown`) unless the element has a click listener
|
|
5
|
+
* of its own, a `tabindex` or an `onclick` attribute. Svelte does not put the listener of `onclick` on the element:
|
|
6
|
+
* it puts one on the document (event delegation), which WebKit does not count, so a `div` with an `onclick` in
|
|
7
|
+
* Svelte cannot be tapped. An empty listener on the element itself is enough; the real handler stays where it is.
|
|
8
|
+
* Use it as `use:clickable` on an element whose `onclick` is the only way to act on it, such as an option of a list.
|
|
9
|
+
*/
|
|
10
|
+
const noop = () => { };
|
|
11
|
+
export function clickable(node) {
|
|
12
|
+
node.addEventListener('click', noop);
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Picks a text color for a background (specs/tooltip.md, decision 3b): black or white, whichever contrasts more.
|
|
3
|
+
* For any background the better of the two reaches at least 4.58:1, so WCAG AA text (4.5:1) is always possible.
|
|
4
|
+
*/
|
|
5
|
+
export declare const TEXT_ON_DARK = "#ffffff";
|
|
6
|
+
export declare const TEXT_ON_LIGHT = "#000000";
|
|
7
|
+
/** The relative luminance (WCAG) of an sRGB color given as 0 to 255 channels. */
|
|
8
|
+
export declare function luminance(r: number, g: number, b: number): number;
|
|
9
|
+
/**
|
|
10
|
+
* Reads a color the way `getComputedStyle` writes it: `rgb(r, g, b)`, `rgba(r, g, b, a)` (comma or space separated)
|
|
11
|
+
* or `color(srgb r g b)` with 0 to 1 channels. Returns `null` for anything else. The alpha is ignored: the page
|
|
12
|
+
* behind a translucent tooltip is not known.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseComputedColor(value: string): [number, number, number] | null;
|
|
15
|
+
/** The text color for a computed background color, or `null` when the color cannot be read. */
|
|
16
|
+
export declare function contrastText(background: string): string | null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Picks a text color for a background (specs/tooltip.md, decision 3b): black or white, whichever contrasts more.
|
|
3
|
+
* For any background the better of the two reaches at least 4.58:1, so WCAG AA text (4.5:1) is always possible.
|
|
4
|
+
*/
|
|
5
|
+
export const TEXT_ON_DARK = '#ffffff';
|
|
6
|
+
export const TEXT_ON_LIGHT = '#000000';
|
|
7
|
+
function channel(value) {
|
|
8
|
+
const v = value / 255;
|
|
9
|
+
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
10
|
+
}
|
|
11
|
+
/** The relative luminance (WCAG) of an sRGB color given as 0 to 255 channels. */
|
|
12
|
+
export function luminance(r, g, b) {
|
|
13
|
+
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Reads a color the way `getComputedStyle` writes it: `rgb(r, g, b)`, `rgba(r, g, b, a)` (comma or space separated)
|
|
17
|
+
* or `color(srgb r g b)` with 0 to 1 channels. Returns `null` for anything else. The alpha is ignored: the page
|
|
18
|
+
* behind a translucent tooltip is not known.
|
|
19
|
+
*/
|
|
20
|
+
export function parseComputedColor(value) {
|
|
21
|
+
const text = value.trim().toLowerCase();
|
|
22
|
+
const rgb = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/.exec(text);
|
|
23
|
+
if (rgb)
|
|
24
|
+
return [Number(rgb[1]), Number(rgb[2]), Number(rgb[3])];
|
|
25
|
+
const srgb = /^color\(\s*srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/.exec(text);
|
|
26
|
+
if (srgb)
|
|
27
|
+
return [Number(srgb[1]) * 255, Number(srgb[2]) * 255, Number(srgb[3]) * 255];
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
/** The text color for a computed background color, or `null` when the color cannot be read. */
|
|
31
|
+
export function contrastText(background) {
|
|
32
|
+
const parsed = parseComputedColor(background);
|
|
33
|
+
if (!parsed)
|
|
34
|
+
return null;
|
|
35
|
+
const l = luminance(...parsed);
|
|
36
|
+
// White contrasts at least as much as black while (1.05 / (l + 0.05)) >= ((l + 0.05) / 0.05).
|
|
37
|
+
return 1.05 / (l + 0.05) >= (l + 0.05) / 0.05 ? TEXT_ON_DARK : TEXT_ON_LIGHT;
|
|
38
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { untrack, type Snippet } from 'svelte';
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
import { resolveOption } from '../options.js';
|
|
5
|
-
import { classList } from '../semantic.js';
|
|
5
|
+
import { classList, styleText, type SemanticStyle } from '../semantic.js';
|
|
6
6
|
import { registerLayer } from './layers.js';
|
|
7
7
|
import { computePlacement, type Box } from './placement.js';
|
|
8
8
|
import {
|
|
@@ -56,6 +56,14 @@
|
|
|
56
56
|
id?: string;
|
|
57
57
|
/** Extra classes of the frame. */
|
|
58
58
|
class?: string;
|
|
59
|
+
/** Extra classes of the root, the positioned element that holds the frame (Tooltip `classNames.root`). */
|
|
60
|
+
rootClass?: string;
|
|
61
|
+
/** Inline styles of the root, set one property at a time so they never wipe the placement. */
|
|
62
|
+
rootStyle?: SemanticStyle;
|
|
63
|
+
/** Extra classes of the arrow. */
|
|
64
|
+
arrowClass?: string;
|
|
65
|
+
/** Inline style of the arrow. */
|
|
66
|
+
arrowStyle?: SemanticStyle;
|
|
59
67
|
/** Inline style of the frame. */
|
|
60
68
|
style?: string;
|
|
61
69
|
onmousedown?: HTMLAttributes<HTMLDivElement>['onmousedown'];
|
|
@@ -84,6 +92,10 @@
|
|
|
84
92
|
id,
|
|
85
93
|
class: customClass,
|
|
86
94
|
style: customStyle,
|
|
95
|
+
rootClass,
|
|
96
|
+
rootStyle,
|
|
97
|
+
arrowClass,
|
|
98
|
+
arrowStyle,
|
|
87
99
|
onmousedown,
|
|
88
100
|
children,
|
|
89
101
|
...rest
|
|
@@ -95,7 +107,7 @@
|
|
|
95
107
|
const arrowOn = $derived(arrow !== false);
|
|
96
108
|
const pointAtCenter = $derived(typeof arrow === 'object' && arrow.pointAtCenter);
|
|
97
109
|
const frameId = $derived(id ?? `ads-popup-${uid}`);
|
|
98
|
-
const panelClass = $derived(
|
|
110
|
+
const panelClass = $derived(classList('ads-popup', `ads-popup-${resolvedLayer}`, rootClass));
|
|
99
111
|
|
|
100
112
|
/** The panel exists in the DOM: from the first opening (never on the server), until `destroyOnHidden` removes it. */
|
|
101
113
|
let mounted = $state(false);
|
|
@@ -221,6 +233,19 @@
|
|
|
221
233
|
if (panel) panel.style.zIndex = zIndex === undefined ? '' : String(zIndex);
|
|
222
234
|
});
|
|
223
235
|
|
|
236
|
+
// The styles of the root are written one property at a time: a `style` attribute written by Svelte would wipe the
|
|
237
|
+
// transform, the z-index and the sizes that the placement writes on the same element. The ones that left the
|
|
238
|
+
// object are removed again.
|
|
239
|
+
let appliedRootStyle: string[] = [];
|
|
240
|
+
$effect(() => {
|
|
241
|
+
const element = panel;
|
|
242
|
+
if (!element) return;
|
|
243
|
+
const next = Object.entries(rootStyle ?? {}).filter(([, value]) => value !== '' && value !== undefined && value !== null);
|
|
244
|
+
for (const name of appliedRootStyle) if (!next.some(([key]) => key === name)) element.style.removeProperty(name);
|
|
245
|
+
for (const [name, value] of next) element.style.setProperty(name, String(value));
|
|
246
|
+
appliedRootStyle = next.map(([name]) => name);
|
|
247
|
+
});
|
|
248
|
+
|
|
224
249
|
function measureAnchor(): Box {
|
|
225
250
|
if (anchorElement) {
|
|
226
251
|
const rect = anchorElement.getBoundingClientRect();
|
|
@@ -248,13 +273,31 @@
|
|
|
248
273
|
return anchorElement === null;
|
|
249
274
|
}
|
|
250
275
|
|
|
276
|
+
/** The height of the arrow in px, for the placement (the shape in the css is a little lower: its tip is rounded). */
|
|
277
|
+
const ARROW_SIZE = 8;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* The largest corner radius of the frame or of what is inside it, in px (the box of a Tooltip is inside the frame). The
|
|
281
|
+
* arrow of an aligned placement stands further from the edge when the corner is rounder. A radius in per cent counts as its
|
|
282
|
+
* number, which for a pill pushes the arrow to the middle, where it belongs.
|
|
283
|
+
*/
|
|
284
|
+
function cornerRadius(frame: HTMLElement): number {
|
|
285
|
+
let largest = 0;
|
|
286
|
+
for (const element of [frame, ...Array.from(frame.children)]) {
|
|
287
|
+
const style = getComputedStyle(element);
|
|
288
|
+
for (const corner of [style.borderTopLeftRadius, style.borderTopRightRadius, style.borderBottomRightRadius, style.borderBottomLeftRadius]) {
|
|
289
|
+
largest = Math.max(largest, parseFloat(corner) || 0);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return largest;
|
|
293
|
+
}
|
|
294
|
+
|
|
251
295
|
/** Measures and places the panel. Runs only while the panel exists and is shown. */
|
|
252
296
|
function update(): void {
|
|
253
297
|
const element = panel as HTMLElement;
|
|
254
298
|
const frameElement = frame as HTMLElement;
|
|
255
299
|
const box = measureAnchor();
|
|
256
|
-
const
|
|
257
|
-
const arrowSize = arrowOn ? parseFloat(computed.getPropertyValue('--ads-popup-arrow-size')) || 8 : 0;
|
|
300
|
+
const arrowSize = arrowOn ? ARROW_SIZE : 0;
|
|
258
301
|
|
|
259
302
|
// The panel is in the same space as its anchor: in the page, so that the page moves both in the same frame
|
|
260
303
|
// (decision 13), unless the anchor stays on the screen, and then so does the panel.
|
|
@@ -277,7 +320,11 @@
|
|
|
277
320
|
offset: offset ?? (arrowOn ? arrowSize + 2 : 4),
|
|
278
321
|
autoAdjustOverflow,
|
|
279
322
|
rtl,
|
|
280
|
-
|
|
323
|
+
// The middle of the arrow of an aligned placement, from the aligned edge: the radius of the corner and 8 px above or below
|
|
324
|
+
// the anchor (14 px at the radius 6, as in Ant Design Vue), and the radius and 7 px beside it, where the tip is one line
|
|
325
|
+
// high and the arrow has to be seen near the top or the bottom without looking like a piece stuck on at the corner
|
|
326
|
+
// (13 px at the radius 6; the 10 px of the Vue demo left a notch at the corner of a tip with a translucent edge).
|
|
327
|
+
arrow: arrowOn ? { size: arrowSize, pointAtCenter, edge: cornerRadius(frameElement) + 8, sideEdge: cornerRadius(frameElement) + 7 } : null
|
|
281
328
|
});
|
|
282
329
|
|
|
283
330
|
// Nothing is written when the placement did not change: while the page scrolls the two numbers differ only by
|
|
@@ -392,7 +439,7 @@
|
|
|
392
439
|
>
|
|
393
440
|
{@render children?.()}
|
|
394
441
|
{#if arrowOn}
|
|
395
|
-
<div class="ads-popup-arrow" aria-hidden="true"><span></span></div>
|
|
442
|
+
<div class="ads-popup-arrow" aria-hidden="true"><span class={arrowClass} style={styleText(arrowStyle)}></span></div>
|
|
396
443
|
{/if}
|
|
397
444
|
</div>
|
|
398
445
|
</div>
|
|
@@ -489,7 +536,12 @@
|
|
|
489
536
|
}
|
|
490
537
|
}
|
|
491
538
|
|
|
492
|
-
/*
|
|
539
|
+
/*
|
|
540
|
+
* The arrow is a triangle that stands on the outer edge of the frame that faces the anchor: as wide as two sizes and one
|
|
541
|
+
* size high, so its sides are at 45 degrees. It is only the half that sticks out. (It used to be a whole rotated
|
|
542
|
+
* square behind the frame, and a frame with a translucent background showed the other half through it, as a darker
|
|
543
|
+
* diamond inside the box.) The wrapper is a point at the edge; each side below places the triangle against it.
|
|
544
|
+
*/
|
|
493
545
|
.ads-popup-arrow {
|
|
494
546
|
position: absolute;
|
|
495
547
|
width: 0;
|
|
@@ -497,15 +549,66 @@
|
|
|
497
549
|
pointer-events: none;
|
|
498
550
|
}
|
|
499
551
|
|
|
552
|
+
/*
|
|
553
|
+
* The arrow is a soft bump on the outer edge of the frame that faces the anchor, as in Ant Design: a rounded tip and
|
|
554
|
+
* concave edges that flare out at the base, so that its base flows into the edge of the frame and into the curve of a
|
|
555
|
+
* rounded corner beside it. A straight triangle with a flat base cannot do that: close to a rounded corner it leaves a
|
|
556
|
+
* notch, and the base is a hairline away from the frame. It is 16 px wide at the base and about 7 px high; the shape is
|
|
557
|
+
* drawn once, for this size, and cut out of a box with `clip-path`. (It used to be a whole rotated square behind the frame,
|
|
558
|
+
* which a translucent frame showed through as a darker diamond.) The wrapper is a point at the edge; each side below
|
|
559
|
+
* places the shape against it.
|
|
560
|
+
*
|
|
561
|
+
* The base of the shape goes one pixel into the frame, past its edge (only the base: beside it the frame has a rounded corner
|
|
562
|
+
* and the shape must not stick out of it). Browsers put the edge of a box and the edge of a clipped shape
|
|
563
|
+
* on pixels by different rules, and at a pixel ratio such as 125% or 150% they miss each other by a device pixel, which
|
|
564
|
+
* leaves a hairline of the page between the arrow and the frame. The overlap closes it, and it is not seen where the
|
|
565
|
+
* frame and the arrow have the same opaque color. A translucent color (a custom `color` of a Tooltip with an alpha) shows
|
|
566
|
+
* the overlap as a slightly darker line.
|
|
567
|
+
*/
|
|
500
568
|
.ads-popup-arrow > span {
|
|
501
569
|
position: absolute;
|
|
502
570
|
top: 0;
|
|
503
571
|
left: 0;
|
|
504
|
-
z-index: -1;
|
|
505
|
-
width: calc(var(--ads-popup-arrow-size) * 1.4142);
|
|
506
|
-
height: calc(var(--ads-popup-arrow-size) * 1.4142);
|
|
507
572
|
background: var(--ads-popup-arrow-bg, currentColor);
|
|
508
|
-
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/* Colors are replaced by the system colors: the arrow is filled with the color of the border of the box. */
|
|
576
|
+
@media (forced-colors: active) {
|
|
577
|
+
.ads-popup-arrow > span {
|
|
578
|
+
background: CanvasText;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/* The panel is above the anchor: the arrow is on its bottom edge and points down. The base is at (9.5, 1) of the box. */
|
|
583
|
+
.ads-popup-frame[data-side='top'] > .ads-popup-arrow > span {
|
|
584
|
+
width: 19px;
|
|
585
|
+
height: 8.5px;
|
|
586
|
+
transform: translate(-9.5px, -1px);
|
|
587
|
+
clip-path: path('M 0.2574 1 A 3 3 0 0 1 2.3787 1.8787 L 8.0858 7.5858 A 2 2 0 0 0 10.9142 7.5858 L 16.6213 1.8787 A 3 3 0 0 1 18.7426 1 L 17.5 1 L 17.5 0 L 1.5 0 L 1.5 1 Z');
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/* Below the anchor: on the top edge, pointing up. The base is at (9.5, 7.5). */
|
|
591
|
+
.ads-popup-frame[data-side='bottom'] > .ads-popup-arrow > span {
|
|
592
|
+
width: 19px;
|
|
593
|
+
height: 8.5px;
|
|
594
|
+
transform: translate(-9.5px, -7.5px);
|
|
595
|
+
clip-path: path('M 18.7426 7.5 A 3 3 0 0 1 16.6213 6.6213 L 10.9142 0.9142 A 2 2 0 0 0 8.0858 0.9142 L 2.3787 6.6213 A 3 3 0 0 1 0.2574 7.5 L 1.5 7.5 L 1.5 8.5 L 17.5 8.5 L 17.5 7.5 Z');
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/* To the left of the anchor: on the right edge, pointing right. The base is at (1, 9.5). */
|
|
599
|
+
.ads-popup-frame[data-side='left'] > .ads-popup-arrow > span {
|
|
600
|
+
width: 8.5px;
|
|
601
|
+
height: 19px;
|
|
602
|
+
transform: translate(-1px, -9.5px);
|
|
603
|
+
clip-path: path('M 1 18.7426 A 3 3 0 0 1 1.8787 16.6213 L 7.5858 10.9142 A 2 2 0 0 0 7.5858 8.0858 L 1.8787 2.3787 A 3 3 0 0 1 1 0.2574 L 1 1.5 L 0 1.5 L 0 17.5 L 1 17.5 Z');
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/* To the right of the anchor: on the left edge, pointing left. The base is at (7.5, 9.5). */
|
|
607
|
+
.ads-popup-frame[data-side='right'] > .ads-popup-arrow > span {
|
|
608
|
+
width: 8.5px;
|
|
609
|
+
height: 19px;
|
|
610
|
+
transform: translate(-7.5px, -9.5px);
|
|
611
|
+
clip-path: path('M 7.5 0.2574 A 3 3 0 0 1 6.6213 2.3787 L 0.9142 8.0858 A 2 2 0 0 0 0.9142 10.9142 L 6.6213 16.6213 A 3 3 0 0 1 7.5 18.7426 L 7.5 17.5 L 8.5 17.5 L 8.5 1.5 L 7.5 1.5 Z');
|
|
509
612
|
}
|
|
510
613
|
|
|
511
614
|
.ads-popup-frame[data-side='top'] > .ads-popup-arrow {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import { type SemanticStyle } from '../semantic.js';
|
|
3
4
|
import { type PopupAnchor, type PopupArrow, type PopupContainer, type PopupDismiss, type PopupLayer, type PopupPlacement, type PopupSource } from './types.js';
|
|
4
5
|
type PopupProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'style' | 'id' | 'onmousedown'> & {
|
|
5
6
|
/** Whether the panel is shown. Use `bind:open` for two-way use. */
|
|
@@ -40,6 +41,14 @@ type PopupProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 's
|
|
|
40
41
|
id?: string;
|
|
41
42
|
/** Extra classes of the frame. */
|
|
42
43
|
class?: string;
|
|
44
|
+
/** Extra classes of the root, the positioned element that holds the frame (Tooltip `classNames.root`). */
|
|
45
|
+
rootClass?: string;
|
|
46
|
+
/** Inline styles of the root, set one property at a time so they never wipe the placement. */
|
|
47
|
+
rootStyle?: SemanticStyle;
|
|
48
|
+
/** Extra classes of the arrow. */
|
|
49
|
+
arrowClass?: string;
|
|
50
|
+
/** Inline style of the arrow. */
|
|
51
|
+
arrowStyle?: SemanticStyle;
|
|
43
52
|
/** Inline style of the frame. */
|
|
44
53
|
style?: string;
|
|
45
54
|
onmousedown?: HTMLAttributes<HTMLDivElement>['onmousedown'];
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
* are open: a press outside closes the popups it is outside of, and Escape closes the topmost one only.
|
|
6
6
|
* A popup opened from inside another popup (a Select inside a Popover) is its child: a press in the child
|
|
7
7
|
* is inside the parent as well, so the parent stays open while the child is used.
|
|
8
|
+
*
|
|
9
|
+
* A mouse or a pen presses on `pointerdown`. A finger is decided when it comes up, and only if it was a tap:
|
|
10
|
+
* a finger that goes down may be about to scroll the page, and closing at that moment would close the popup
|
|
11
|
+
* under the user's hand (decision 14).
|
|
8
12
|
*/
|
|
9
13
|
export type DismissReason = 'outsidePress' | 'escape';
|
|
10
14
|
export interface Layer {
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
* are open: a press outside closes the popups it is outside of, and Escape closes the topmost one only.
|
|
6
6
|
* A popup opened from inside another popup (a Select inside a Popover) is its child: a press in the child
|
|
7
7
|
* is inside the parent as well, so the parent stays open while the child is used.
|
|
8
|
+
*
|
|
9
|
+
* A mouse or a pen presses on `pointerdown`. A finger is decided when it comes up, and only if it was a tap:
|
|
10
|
+
* a finger that goes down may be about to scroll the page, and closing at that moment would close the popup
|
|
11
|
+
* under the user's hand (decision 14).
|
|
8
12
|
*/
|
|
9
13
|
const stack = [];
|
|
10
14
|
/** The open popups, the oldest first. The last one is the topmost. */
|
|
@@ -32,14 +36,58 @@ export function isInsideLayer(layer, target) {
|
|
|
32
36
|
return true;
|
|
33
37
|
return stack.some((other) => other !== layer && parentOf(other) === layer && isInsideLayer(other, target));
|
|
34
38
|
}
|
|
39
|
+
/** How far a finger may move and still be a tap, in CSS pixels. */
|
|
40
|
+
const TAP_SLOP = 10;
|
|
41
|
+
let touch = null;
|
|
42
|
+
function outsideLayers(target) {
|
|
43
|
+
return [...stack].reverse().filter((layer) => layer.outsidePress() && !isInsideLayer(layer, target));
|
|
44
|
+
}
|
|
45
|
+
function endTouch() {
|
|
46
|
+
touch = null;
|
|
47
|
+
document.removeEventListener('pointermove', onTouchMove, true);
|
|
48
|
+
document.removeEventListener('pointerup', onTouchUp, true);
|
|
49
|
+
document.removeEventListener('pointercancel', endTouch, true);
|
|
50
|
+
}
|
|
51
|
+
/** A finger that moves is scrolling or dragging, not pressing. */
|
|
52
|
+
function onTouchMove(event) {
|
|
53
|
+
const { id, x, y } = touch;
|
|
54
|
+
if (event.pointerId === id && Math.hypot(event.clientX - x, event.clientY - y) > TAP_SLOP)
|
|
55
|
+
endTouch();
|
|
56
|
+
}
|
|
57
|
+
function onTouchUp(event) {
|
|
58
|
+
const { id, layers } = touch;
|
|
59
|
+
if (event.pointerId !== id)
|
|
60
|
+
return;
|
|
61
|
+
endTouch();
|
|
62
|
+
// A popup may have closed since the finger went down.
|
|
63
|
+
for (const layer of layers)
|
|
64
|
+
if (stack.includes(layer))
|
|
65
|
+
layer.dismiss('outsidePress');
|
|
66
|
+
}
|
|
35
67
|
function onPointerDown(event) {
|
|
36
68
|
// A press on the document always has a node as its target.
|
|
37
69
|
const target = event.target;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
layer.
|
|
70
|
+
if (event.pointerType !== 'touch') {
|
|
71
|
+
// Topmost first. A copy, because a dismissal may unregister a layer.
|
|
72
|
+
for (const layer of [...stack].reverse()) {
|
|
73
|
+
if (layer.outsidePress() && !isInsideLayer(layer, target))
|
|
74
|
+
layer.dismiss('outsidePress');
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
42
77
|
}
|
|
78
|
+
// A second finger: a pinch, or a scroll with two fingers.
|
|
79
|
+
if (touch) {
|
|
80
|
+
endTouch();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const layers = outsideLayers(target);
|
|
84
|
+
if (layers.length === 0)
|
|
85
|
+
return;
|
|
86
|
+
touch = { id: event.pointerId, x: event.clientX, y: event.clientY, layers };
|
|
87
|
+
document.addEventListener('pointermove', onTouchMove, { capture: true, passive: true });
|
|
88
|
+
document.addEventListener('pointerup', onTouchUp, true);
|
|
89
|
+
// The browser takes the touch for scrolling the page: it cancels the pointer.
|
|
90
|
+
document.addEventListener('pointercancel', endTouch, true);
|
|
43
91
|
}
|
|
44
92
|
function onKeyDown(event) {
|
|
45
93
|
if (event.key !== 'Escape' || event.defaultPrevented || event.isComposing)
|
|
@@ -56,6 +104,8 @@ function listen() {
|
|
|
56
104
|
document.addEventListener('keydown', onKeyDown);
|
|
57
105
|
}
|
|
58
106
|
function unlisten() {
|
|
107
|
+
if (touch)
|
|
108
|
+
endTouch();
|
|
59
109
|
document.removeEventListener('pointerdown', onPointerDown, true);
|
|
60
110
|
document.removeEventListener('keydown', onKeyDown);
|
|
61
111
|
}
|
|
@@ -31,8 +31,14 @@ export interface ArrowInput {
|
|
|
31
31
|
size: number;
|
|
32
32
|
/** Point at the middle of the anchor even for an aligned placement. */
|
|
33
33
|
pointAtCenter: boolean;
|
|
34
|
-
/** Distance from the aligned edge of the panel to the middle of the arrow, for an aligned placement. */
|
|
34
|
+
/** Distance from the aligned edge of the panel to the middle of the arrow, for an aligned placement above or below the anchor. */
|
|
35
35
|
edge: number;
|
|
36
|
+
/**
|
|
37
|
+
* The same for a panel beside the anchor (`leftTop`, `rightBottom`, ...). Those panels are usually one line high, so the
|
|
38
|
+
* distance of the other axis would put the arrow in the middle and `rightTop`, `right` and `rightBottom` would look the
|
|
39
|
+
* same. Defaults to `edge`.
|
|
40
|
+
*/
|
|
41
|
+
sideEdge?: number;
|
|
36
42
|
}
|
|
37
43
|
export interface PlacementInput {
|
|
38
44
|
anchor: Box;
|
|
@@ -96,7 +96,8 @@ export function computePlacement(input) {
|
|
|
96
96
|
const anchorCenter = anchorStart + anchorSize / 2;
|
|
97
97
|
let wanted = anchorCenter;
|
|
98
98
|
if (align !== 'center' && !input.arrow.pointAtCenter) {
|
|
99
|
-
|
|
99
|
+
const edge = horizontal ? input.arrow.edge : (input.arrow.sideEdge ?? input.arrow.edge);
|
|
100
|
+
wanted = align === 'start' ? edge : panelSize - edge;
|
|
100
101
|
// An arrow that would point past the anchor points at its middle instead.
|
|
101
102
|
if (wanted < anchorStart || wanted > anchorStart + anchorSize)
|
|
102
103
|
wanted = anchorCenter;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** How long after a touch the mouse events are the compatibility events of that touch, in milliseconds. */
|
|
2
|
+
const TOUCH_COMPAT_MS = 800;
|
|
1
3
|
export function popupTriggers(options) {
|
|
2
4
|
return (anchor) => {
|
|
3
5
|
if (options.disabled || options.trigger.length === 0)
|
|
@@ -37,12 +39,23 @@ export function popupTriggers(options) {
|
|
|
37
39
|
panel.addEventListener('mouseenter', enterPanel);
|
|
38
40
|
panel.addEventListener('mouseleave', leavePanel);
|
|
39
41
|
};
|
|
42
|
+
// A finger has no "leaving". After a tap the browser sends compatibility mouse events (`mouseenter`, then at once
|
|
43
|
+
// `mouseleave`), and the second one would close what the first one opened. The tip of a tap stays until a tap
|
|
44
|
+
// somewhere else, or `Escape`, or the focus leaving (the popup closes it on an outside tap).
|
|
45
|
+
let touchedAt = -Infinity;
|
|
46
|
+
const onPointerDown = (event) => {
|
|
47
|
+
if (event.pointerType === 'touch')
|
|
48
|
+
touchedAt = performance.now();
|
|
49
|
+
};
|
|
50
|
+
const afterTouch = () => performance.now() - touchedAt < TOUCH_COMPAT_MS;
|
|
40
51
|
const onMouseEnter = () => {
|
|
41
52
|
bindPanel();
|
|
42
53
|
enter();
|
|
43
54
|
};
|
|
44
55
|
const onMouseLeave = () => {
|
|
45
56
|
bindPanel();
|
|
57
|
+
if (afterTouch())
|
|
58
|
+
return;
|
|
46
59
|
leave();
|
|
47
60
|
};
|
|
48
61
|
const onFocusIn = () => request(true, 0);
|
|
@@ -65,6 +78,7 @@ export function popupTriggers(options) {
|
|
|
65
78
|
listeners.push([type, listener]);
|
|
66
79
|
};
|
|
67
80
|
if (has('hover')) {
|
|
81
|
+
add('pointerdown', onPointerDown);
|
|
68
82
|
add('mouseenter', onMouseEnter);
|
|
69
83
|
add('mouseleave', onMouseLeave);
|
|
70
84
|
}
|
package/dist/tokens.css
CHANGED
|
@@ -95,7 +95,12 @@
|
|
|
95
95
|
--ads-popover-z-index: 1030;
|
|
96
96
|
--ads-dropdown-z-index: 1050;
|
|
97
97
|
--ads-tooltip-z-index: 1070;
|
|
98
|
-
|
|
98
|
+
|
|
99
|
+
/* Tooltip: the sizes of the Ant Design token documentation (React 6.7.0, checked on 2026-11-13). */
|
|
100
|
+
--ads-tooltip-radius: 6px;
|
|
101
|
+
--ads-tooltip-padding: 6px 8px;
|
|
102
|
+
--ads-tooltip-min-height: 32px;
|
|
103
|
+
--ads-tooltip-max-width: 250px;
|
|
99
104
|
|
|
100
105
|
/* Switch */
|
|
101
106
|
--ads-switch-height: 22px;
|
|
@@ -262,6 +267,42 @@
|
|
|
262
267
|
--ads-select-tag-color-disabled: rgba(0, 0, 0, 0.25);
|
|
263
268
|
--ads-select-group-label-color: rgba(0, 0, 0, 0.45);
|
|
264
269
|
--ads-select-empty-color: rgba(0, 0, 0, 0.45);
|
|
270
|
+
|
|
271
|
+
/*
|
|
272
|
+
* Tooltip colors: the values measured on the Ant Design demo (React 6.7.0, 2026-11-13, light theme). The text of a
|
|
273
|
+
* preset is the one of black and white that contrasts more with its background (specs/tooltip.md, decision 3b), so
|
|
274
|
+
* every pair reaches 4.5:1 here, in the dark theme and with `tokens-accessible.css`, which needs no entry for it.
|
|
275
|
+
*/
|
|
276
|
+
/* The 85% black of Ant Design (colorBgSpotlight), over a white page: 38 in each channel. Opaque on purpose, so that the arrow
|
|
277
|
+
can overlap the box by a pixel without a darker line (see the arrow of the popup). */
|
|
278
|
+
--ads-tooltip-bg: #262626;
|
|
279
|
+
--ads-tooltip-color: #ffffff;
|
|
280
|
+
--ads-tooltip-preset-pink: #eb2f96;
|
|
281
|
+
--ads-tooltip-preset-pink-text: #000000;
|
|
282
|
+
--ads-tooltip-preset-red: #f5222d;
|
|
283
|
+
--ads-tooltip-preset-red-text: #000000;
|
|
284
|
+
--ads-tooltip-preset-yellow: #fadb14;
|
|
285
|
+
--ads-tooltip-preset-yellow-text: #000000;
|
|
286
|
+
--ads-tooltip-preset-orange: #fa8c16;
|
|
287
|
+
--ads-tooltip-preset-orange-text: #000000;
|
|
288
|
+
--ads-tooltip-preset-cyan: #13c2c2;
|
|
289
|
+
--ads-tooltip-preset-cyan-text: #000000;
|
|
290
|
+
--ads-tooltip-preset-green: #52c41a;
|
|
291
|
+
--ads-tooltip-preset-green-text: #000000;
|
|
292
|
+
--ads-tooltip-preset-blue: #1677ff;
|
|
293
|
+
--ads-tooltip-preset-blue-text: #000000;
|
|
294
|
+
--ads-tooltip-preset-purple: #722ed1;
|
|
295
|
+
--ads-tooltip-preset-purple-text: #ffffff;
|
|
296
|
+
--ads-tooltip-preset-geekblue: #2f54eb;
|
|
297
|
+
--ads-tooltip-preset-geekblue-text: #ffffff;
|
|
298
|
+
--ads-tooltip-preset-magenta: #eb2f96;
|
|
299
|
+
--ads-tooltip-preset-magenta-text: #000000;
|
|
300
|
+
--ads-tooltip-preset-volcano: #fa541c;
|
|
301
|
+
--ads-tooltip-preset-volcano-text: #000000;
|
|
302
|
+
--ads-tooltip-preset-gold: #faad14;
|
|
303
|
+
--ads-tooltip-preset-gold-text: #000000;
|
|
304
|
+
--ads-tooltip-preset-lime: #a0d911;
|
|
305
|
+
--ads-tooltip-preset-lime-text: #000000;
|
|
265
306
|
}
|
|
266
307
|
|
|
267
308
|
:root[data-theme='dark'] {
|
|
@@ -370,4 +411,33 @@
|
|
|
370
411
|
--ads-select-tag-color-disabled: rgba(255, 255, 255, 0.3);
|
|
371
412
|
--ads-select-group-label-color: rgba(255, 255, 255, 0.55);
|
|
372
413
|
--ads-select-empty-color: rgba(255, 255, 255, 0.55);
|
|
414
|
+
|
|
415
|
+
--ads-tooltip-bg: #424242;
|
|
416
|
+
--ads-tooltip-color: #ffffff;
|
|
417
|
+
--ads-tooltip-preset-pink: #cb2b83;
|
|
418
|
+
--ads-tooltip-preset-pink-text: #ffffff;
|
|
419
|
+
--ads-tooltip-preset-red: #d32029;
|
|
420
|
+
--ads-tooltip-preset-red-text: #ffffff;
|
|
421
|
+
--ads-tooltip-preset-yellow: #d8bd14;
|
|
422
|
+
--ads-tooltip-preset-yellow-text: #000000;
|
|
423
|
+
--ads-tooltip-preset-orange: #d87a16;
|
|
424
|
+
--ads-tooltip-preset-orange-text: #000000;
|
|
425
|
+
--ads-tooltip-preset-cyan: #13a8a8;
|
|
426
|
+
--ads-tooltip-preset-cyan-text: #000000;
|
|
427
|
+
--ads-tooltip-preset-green: #49aa19;
|
|
428
|
+
--ads-tooltip-preset-green-text: #000000;
|
|
429
|
+
--ads-tooltip-preset-blue: #1668dc;
|
|
430
|
+
--ads-tooltip-preset-blue-text: #ffffff;
|
|
431
|
+
--ads-tooltip-preset-purple: #642ab5;
|
|
432
|
+
--ads-tooltip-preset-purple-text: #ffffff;
|
|
433
|
+
--ads-tooltip-preset-geekblue: #2b4acb;
|
|
434
|
+
--ads-tooltip-preset-geekblue-text: #ffffff;
|
|
435
|
+
--ads-tooltip-preset-magenta: #cb2b83;
|
|
436
|
+
--ads-tooltip-preset-magenta-text: #ffffff;
|
|
437
|
+
--ads-tooltip-preset-volcano: #d84a1b;
|
|
438
|
+
--ads-tooltip-preset-volcano-text: #000000;
|
|
439
|
+
--ads-tooltip-preset-gold: #d89614;
|
|
440
|
+
--ads-tooltip-preset-gold-text: #000000;
|
|
441
|
+
--ads-tooltip-preset-lime: #8bbb11;
|
|
442
|
+
--ads-tooltip-preset-lime-text: #000000;
|
|
373
443
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-ant-design",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "An independent UI component library for Svelte 5, inspired by Ant Design.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -54,11 +54,13 @@
|
|
|
54
54
|
"package": "svelte-package",
|
|
55
55
|
"prepublishOnly": "npm run lint && npm run check && npm run test && npm run package",
|
|
56
56
|
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
57
|
-
"check:docs": "npm run check -w docs",
|
|
57
|
+
"check:docs": "npm run check -w docs && node scripts/check-quality-matrix.mjs",
|
|
58
58
|
"test": "vitest run",
|
|
59
59
|
"test:coverage": "vitest run --coverage",
|
|
60
60
|
"test:watch": "vitest",
|
|
61
61
|
"test:e2e": "playwright test",
|
|
62
|
+
"test:affected": "node scripts/test-affected.mjs",
|
|
63
|
+
"test:floor": "node scripts/floor/run.mjs",
|
|
62
64
|
"test:docs": "npm run verify -w docs && npm run test:e2e -w docs",
|
|
63
65
|
"test:mutation": "node scripts/mutation-test.mjs",
|
|
64
66
|
"lint": "eslint ."
|