@canonical/svelte-ds-app-launchpad 0.26.0 → 0.27.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/dist/components/NumberInput/types.d.ts +2 -2
- package/dist/components/Popover/Popover.svelte +1 -1
- package/dist/components/SearchBox/SearchBox.svelte +79 -0
- package/dist/components/SearchBox/SearchBox.svelte.d.ts +36 -0
- package/dist/components/SearchBox/common/SearchButton/SearchButton.svelte +31 -0
- package/dist/components/SearchBox/common/SearchButton/SearchButton.svelte.d.ts +5 -0
- package/dist/components/SearchBox/common/SearchButton/index.d.ts +2 -0
- package/dist/components/SearchBox/common/SearchButton/index.js +1 -0
- package/dist/components/SearchBox/common/SearchButton/styles.css +11 -0
- package/dist/components/SearchBox/common/SearchButton/types.d.ts +2 -0
- package/dist/components/SearchBox/common/SearchButton/types.js +1 -0
- package/dist/components/SearchBox/common/index.d.ts +1 -0
- package/dist/components/SearchBox/common/index.js +1 -0
- package/dist/components/SearchBox/context.d.ts +2 -0
- package/dist/components/SearchBox/context.js +2 -0
- package/dist/components/SearchBox/index.d.ts +22 -0
- package/dist/components/SearchBox/index.js +6 -0
- package/dist/components/SearchBox/styles.css +35 -0
- package/dist/components/SearchBox/types.d.ts +26 -0
- package/dist/components/SearchBox/types.js +2 -0
- package/dist/components/Select/Select.svelte +51 -0
- package/dist/components/Select/Select.svelte.d.ts +17 -0
- package/dist/components/Select/index.d.ts +2 -0
- package/dist/components/Select/index.js +3 -0
- package/dist/components/Select/styles.css +161 -0
- package/dist/components/Select/types.d.ts +7 -0
- package/dist/components/Select/types.js +2 -0
- package/dist/components/TextInput/types.d.ts +2 -2
- package/dist/components/Tooltip/Tooltip.svelte +165 -0
- package/dist/components/Tooltip/Tooltip.svelte.d.ts +23 -0
- package/dist/components/Tooltip/index.d.ts +2 -0
- package/dist/components/Tooltip/index.js +3 -0
- package/dist/components/Tooltip/styles.css +111 -0
- package/dist/components/Tooltip/types.d.ts +43 -0
- package/dist/components/Tooltip/types.js +2 -0
- package/dist/components/Tooltip/utils/ChainingManager.d.ts +18 -0
- package/dist/components/Tooltip/utils/ChainingManager.js +29 -0
- package/dist/components/Tooltip/utils/useDelayedOpen.svelte.d.ts +15 -0
- package/dist/components/Tooltip/utils/useDelayedOpen.svelte.js +42 -0
- package/dist/components/Tooltip/utils/useTooltipPosition.svelte.d.ts +24 -0
- package/dist/components/Tooltip/utils/useTooltipPosition.svelte.js +40 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +3 -0
- package/package.json +8 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ModifierFamily } from "../../modifier-families/index.js";
|
|
1
|
+
import type { ModifierFamily, ModifierFamilyValues } from "../../modifier-families/index.js";
|
|
2
2
|
import type { NumberInputPrimitiveProps } from "../common/index.js";
|
|
3
3
|
export interface NumberInputProps extends Omit<NumberInputPrimitiveProps, "type">, ModifierFamily<"severity"> {
|
|
4
|
-
density?: "dense" | "medium"
|
|
4
|
+
density?: Extract<ModifierFamilyValues["density"], "dense" | "medium">;
|
|
5
5
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<!-- @canonical/generator-ds 0.10.0-experimental.4 -->
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import type { SearchBoxProps } from "./types.js";
|
|
5
|
+
import "./styles.css";
|
|
6
|
+
import { InputPrimitive } from "../common/index.js";
|
|
7
|
+
import { SearchButton } from "./common/index.js";
|
|
8
|
+
import { setSearchBoxContext } from "./context.js";
|
|
9
|
+
|
|
10
|
+
const componentCssClassName = "ds search-box";
|
|
11
|
+
|
|
12
|
+
let {
|
|
13
|
+
class: className,
|
|
14
|
+
value = $bindable(),
|
|
15
|
+
children,
|
|
16
|
+
"aria-label": ariaLabel,
|
|
17
|
+
disabled,
|
|
18
|
+
shouldRenderInvalidStyles,
|
|
19
|
+
"data-testid": dataTestId,
|
|
20
|
+
...rest
|
|
21
|
+
}: SearchBoxProps = $props();
|
|
22
|
+
|
|
23
|
+
setSearchBoxContext({
|
|
24
|
+
get disabled() {
|
|
25
|
+
return disabled;
|
|
26
|
+
},
|
|
27
|
+
get "aria-label"() {
|
|
28
|
+
return ariaLabel;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<div class={[componentCssClassName, className]} data-testid={dataTestId}>
|
|
34
|
+
<InputPrimitive
|
|
35
|
+
type="search"
|
|
36
|
+
bind:value
|
|
37
|
+
aria-label={ariaLabel}
|
|
38
|
+
{disabled}
|
|
39
|
+
class={{ "no-invalid-styles": !shouldRenderInvalidStyles }}
|
|
40
|
+
{...rest}
|
|
41
|
+
/>
|
|
42
|
+
{#if children}
|
|
43
|
+
{@render children()}
|
|
44
|
+
{:else}
|
|
45
|
+
<SearchButton />
|
|
46
|
+
{/if}
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<!-- @component
|
|
50
|
+
`SearchBox` is a text input field designed for search functionality.
|
|
51
|
+
|
|
52
|
+
By default, it renders an input and a submit button (`SearchBox.SearchButton`).
|
|
53
|
+
You can override the default button by passing `children`.
|
|
54
|
+
|
|
55
|
+
When `SearchBox.SearchButton` is used inside `SearchBox`, it inherits `aria-label` and `disabled` from `SearchBox` context by default. You can still override those values directly on `SearchBox.SearchButton` when needed.
|
|
56
|
+
|
|
57
|
+
## Example Usage
|
|
58
|
+
### Basic Example
|
|
59
|
+
```svelte
|
|
60
|
+
<SearchBox aria-label="Search articles" placeholder="Ubuntu" />
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Customized SearchButton
|
|
64
|
+
```svelte
|
|
65
|
+
<SearchBox aria-label="Search articles" placeholder="Ubuntu">
|
|
66
|
+
<SearchBox.SearchButton onclick={handleClick} aria-label="Run search" />
|
|
67
|
+
</SearchBox>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### As a search landmark
|
|
71
|
+
To make the `SearchBox` a search landmark wrap it in a [`<form role="search">`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/search_role) or [`<search>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/search)
|
|
72
|
+
```svelte
|
|
73
|
+
<search>
|
|
74
|
+
<form>
|
|
75
|
+
<SearchBox aria-label="Articles" name="q" />
|
|
76
|
+
</form>
|
|
77
|
+
</search>
|
|
78
|
+
```
|
|
79
|
+
-->
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SearchBoxProps } from "./types.js";
|
|
2
|
+
import "./styles.css";
|
|
3
|
+
/**
|
|
4
|
+
* `SearchBox` is a text input field designed for search functionality.
|
|
5
|
+
*
|
|
6
|
+
* By default, it renders an input and a submit button (`SearchBox.SearchButton`).
|
|
7
|
+
* You can override the default button by passing `children`.
|
|
8
|
+
*
|
|
9
|
+
* When `SearchBox.SearchButton` is used inside `SearchBox`, it inherits `aria-label` and `disabled` from `SearchBox` context by default. You can still override those values directly on `SearchBox.SearchButton` when needed.
|
|
10
|
+
*
|
|
11
|
+
* ## Example Usage
|
|
12
|
+
* ### Basic Example
|
|
13
|
+
* ```svelte
|
|
14
|
+
* <SearchBox aria-label="Search articles" placeholder="Ubuntu" />
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* ### Customized SearchButton
|
|
18
|
+
* ```svelte
|
|
19
|
+
* <SearchBox aria-label="Search articles" placeholder="Ubuntu">
|
|
20
|
+
* <SearchBox.SearchButton onclick={handleClick} aria-label="Run search" />
|
|
21
|
+
* </SearchBox>
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* ### As a search landmark
|
|
25
|
+
* To make the `SearchBox` a search landmark wrap it in a [`<form role="search">`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/search_role) or [`<search>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/search)
|
|
26
|
+
* ```svelte
|
|
27
|
+
* <search>
|
|
28
|
+
* <form>
|
|
29
|
+
* <SearchBox aria-label="Articles" name="q" />
|
|
30
|
+
* </form>
|
|
31
|
+
* </search>
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare const SearchBox: import("svelte").Component<SearchBoxProps, {}, "value">;
|
|
35
|
+
type SearchBox = ReturnType<typeof SearchBox>;
|
|
36
|
+
export default SearchBox;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { SearchIcon } from "@canonical/svelte-icons";
|
|
3
|
+
import { ButtonPrimitive } from "../../../common/index.js";
|
|
4
|
+
import type { SearchButtonProps } from "./types.js";
|
|
5
|
+
import "./styles.css";
|
|
6
|
+
import { getSearchBoxContext } from "../../context.js";
|
|
7
|
+
|
|
8
|
+
const componentCssClassName = "ds search-box-search-button";
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
class: className,
|
|
12
|
+
type = "submit",
|
|
13
|
+
disabled,
|
|
14
|
+
"aria-label": ariaLabel,
|
|
15
|
+
...rest
|
|
16
|
+
}: SearchButtonProps = $props();
|
|
17
|
+
|
|
18
|
+
const searchBoxContext = getSearchBoxContext();
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<ButtonPrimitive
|
|
22
|
+
{type}
|
|
23
|
+
class={[componentCssClassName, className]}
|
|
24
|
+
disabled={disabled !== undefined ? disabled : searchBoxContext.disabled}
|
|
25
|
+
aria-label={ariaLabel !== undefined
|
|
26
|
+
? ariaLabel
|
|
27
|
+
: searchBoxContext["aria-label"]}
|
|
28
|
+
{...rest}
|
|
29
|
+
>
|
|
30
|
+
<SearchIcon />
|
|
31
|
+
</ButtonPrimitive>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SearchButton } from "./SearchButton.svelte";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
.ds.search-box-search-button.button-primitive {
|
|
2
|
+
justify-self: end;
|
|
3
|
+
display: grid;
|
|
4
|
+
place-items: center;
|
|
5
|
+
padding: 0;
|
|
6
|
+
--color-background-button-hover: transparent;
|
|
7
|
+
--color-background-button-active: transparent;
|
|
8
|
+
|
|
9
|
+
width: var(--dimension-width-search-box-button);
|
|
10
|
+
margin-inline-end: var(--dimension-gap-search-box);
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./SearchButton/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./SearchButton/index.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SearchButton } from "./common/index.js";
|
|
2
|
+
import { default as SearchBoxRoot } from "./SearchBox.svelte";
|
|
3
|
+
declare const SearchBox: typeof SearchBoxRoot & {
|
|
4
|
+
/**
|
|
5
|
+
* `SearchButton` is the button companion for `SearchBox`.
|
|
6
|
+
*
|
|
7
|
+
* It is available as `SearchBox.SearchButton` and is intended to be used inside `SearchBox` when you want to customize the default button behavior.
|
|
8
|
+
*
|
|
9
|
+
* `disabled` and `aria-label` props can be passed directly to `SearchButton`, but if they are not provided they will reflect their respective values from `SearchBox` context.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```svelte
|
|
13
|
+
* <SearchBox aria-label="Search articles">
|
|
14
|
+
* <SearchBox.SearchButton onclick={handleClick} disabled />
|
|
15
|
+
* </SearchBox>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
SearchButton: typeof SearchButton;
|
|
19
|
+
};
|
|
20
|
+
export type { SearchButtonProps as SearchBoxSearchButtonProps } from "./common/index.js";
|
|
21
|
+
export type { SearchBoxProps } from "./types.js";
|
|
22
|
+
export { SearchBox };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
.ds.search-box {
|
|
2
|
+
--dimension-width-search-box-button: var(--lp-dimension-size-l);
|
|
3
|
+
--dimension-gap-search-box: var(--lp-dimension-spacing-inline-xs);
|
|
4
|
+
|
|
5
|
+
display: grid;
|
|
6
|
+
grid-template-areas: "main";
|
|
7
|
+
|
|
8
|
+
> * {
|
|
9
|
+
grid-area: main;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
> input {
|
|
13
|
+
padding-inline-end: calc(
|
|
14
|
+
2 *
|
|
15
|
+
var(--dimension-gap-search-box) +
|
|
16
|
+
var(--dimension-width-search-box-button)
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
&::-webkit-search-cancel-button {
|
|
20
|
+
display: none;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&.no-invalid-styles {
|
|
24
|
+
--color-background-input-invalid: var(--color-background-input);
|
|
25
|
+
--color-background-input-invalid-hover: var(
|
|
26
|
+
--color-background-input-hover
|
|
27
|
+
);
|
|
28
|
+
--color-background-input-invalid-active: var(
|
|
29
|
+
--color-background-input-active
|
|
30
|
+
);
|
|
31
|
+
--color-border-input-invalid: var(--color-border-input);
|
|
32
|
+
--color-outline-input-invalid: var(--color-outline-input);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { HTMLInputAttributes } from "svelte/elements";
|
|
3
|
+
import type { TextInputPrimitiveProps } from "../common/index.js";
|
|
4
|
+
export interface SearchBoxProps extends Omit<TextInputPrimitiveProps, "type"> {
|
|
5
|
+
/**
|
|
6
|
+
* The accessible name for the input.
|
|
7
|
+
*
|
|
8
|
+
* A search input's purpose is usually clear for sighted users, but screen reader users may not have the same context. Providing an accessible name helps ensure that all users understand the purpose of the input (see: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/search#search_form_labels_and_accessibility).
|
|
9
|
+
*/
|
|
10
|
+
"aria-label": string;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to apply the invalid styles to the input when it fails native validation (`:user-invalid`) or `aria-invalid="true"` is set.
|
|
13
|
+
*
|
|
14
|
+
* @default false
|
|
15
|
+
* This is opt-in because search landmarks often have submission requirements, such as `required` and `minlength`, where you may want to block submission without showing a visual invalid state.
|
|
16
|
+
*/
|
|
17
|
+
shouldRenderInvalidStyles?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The content to render instead of the default `SearchBox.SearchButton`. This is useful when you want to customize the default button behavior, such as adding an `onclick` handler.
|
|
20
|
+
*/
|
|
21
|
+
children?: Snippet<[]>;
|
|
22
|
+
}
|
|
23
|
+
export type SearchBoxContext = {
|
|
24
|
+
disabled: HTMLInputAttributes["disabled"];
|
|
25
|
+
"aria-label": string;
|
|
26
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<!-- @canonical/generator-ds 0.10.0-experimental.3 -->
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import { ChevronDownIcon } from "@canonical/svelte-icons";
|
|
5
|
+
import type { SelectProps } from "./types.js";
|
|
6
|
+
import "./styles.css";
|
|
7
|
+
|
|
8
|
+
const componentCssClassName = "ds select";
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
class: className,
|
|
12
|
+
ref = $bindable(),
|
|
13
|
+
value = $bindable(),
|
|
14
|
+
children,
|
|
15
|
+
severity,
|
|
16
|
+
density,
|
|
17
|
+
"data-testid": dataTestId,
|
|
18
|
+
...rest
|
|
19
|
+
}: SelectProps = $props();
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<!--
|
|
23
|
+
The wrapper is needed to position the chevron icon correctly.
|
|
24
|
+
TODO: Remove the wrapper when:
|
|
25
|
+
- ideally [Customizable select elements](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Customizable_select) are supported across browsers.
|
|
26
|
+
- alternatively, anchor positioning support is widespread enough to position the chevron icon without needing a wrapper element.
|
|
27
|
+
-->
|
|
28
|
+
<div
|
|
29
|
+
class={[componentCssClassName, className, severity, density]}
|
|
30
|
+
data-testid={dataTestId}
|
|
31
|
+
>
|
|
32
|
+
<select bind:value bind:this={ref} {...rest}>
|
|
33
|
+
{@render children?.()}
|
|
34
|
+
</select>
|
|
35
|
+
{#if !rest.multiple}
|
|
36
|
+
<ChevronDownIcon class="chevron" />
|
|
37
|
+
{/if}
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<!-- @component
|
|
41
|
+
`Select` is a styled wrapper around the native HTML `<select>` element.
|
|
42
|
+
|
|
43
|
+
## Example Usage
|
|
44
|
+
```svelte
|
|
45
|
+
<Select bind:value={valueState}>
|
|
46
|
+
<option value="1">Option 1</option>
|
|
47
|
+
<option value="2">Option 2</option>
|
|
48
|
+
<option value="3">Option 3</option>
|
|
49
|
+
</Select>
|
|
50
|
+
```
|
|
51
|
+
-->
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SelectProps } from "./types.js";
|
|
2
|
+
import "./styles.css";
|
|
3
|
+
/**
|
|
4
|
+
* `Select` is a styled wrapper around the native HTML `<select>` element.
|
|
5
|
+
*
|
|
6
|
+
* ## Example Usage
|
|
7
|
+
* ```svelte
|
|
8
|
+
* <Select bind:value={valueState}>
|
|
9
|
+
* <option value="1">Option 1</option>
|
|
10
|
+
* <option value="2">Option 2</option>
|
|
11
|
+
* <option value="3">Option 3</option>
|
|
12
|
+
* </Select>
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
declare const Select: import("svelte").Component<SelectProps, {}, "value" | "ref">;
|
|
16
|
+
type Select = ReturnType<typeof Select>;
|
|
17
|
+
export default Select;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
.ds.select {
|
|
2
|
+
--color-background-select-input-hover: var(
|
|
3
|
+
--lp-color-background-secondary-hover-context,
|
|
4
|
+
var(--lp-color-background-hover)
|
|
5
|
+
);
|
|
6
|
+
--color-background-select-input-active: var(
|
|
7
|
+
--lp-color-background-secondary-active-context,
|
|
8
|
+
var(--lp-color-background-active)
|
|
9
|
+
);
|
|
10
|
+
--color-background-select-input: var(
|
|
11
|
+
--lp-color-background-secondary-context,
|
|
12
|
+
var(--lp-color-background-input)
|
|
13
|
+
);
|
|
14
|
+
--dimension-padding-inline-select-input: var(
|
|
15
|
+
--lp-dimension-spacing-inline-xs
|
|
16
|
+
);
|
|
17
|
+
--dimension-padding-block-select-input: var(
|
|
18
|
+
--lp-dimension-padding-block-context,
|
|
19
|
+
var(--lp-dimension-spacing-block-xxs)
|
|
20
|
+
);
|
|
21
|
+
--color-border-select-input: var(
|
|
22
|
+
--lp-color-border-secondary-context,
|
|
23
|
+
var(--lp-color-border-high-contrast)
|
|
24
|
+
);
|
|
25
|
+
--color-outline-select-input: var(
|
|
26
|
+
--lp-color-border-secondary-context,
|
|
27
|
+
var(--lp-color-border-focus)
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
color: var(--lp-color-text-default);
|
|
31
|
+
font: var(--lp-typography-paragraph-default);
|
|
32
|
+
|
|
33
|
+
display: inline-grid;
|
|
34
|
+
align-items: center;
|
|
35
|
+
grid-template-areas: "select";
|
|
36
|
+
|
|
37
|
+
> * {
|
|
38
|
+
grid-area: select;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
> .chevron {
|
|
42
|
+
justify-self: end;
|
|
43
|
+
margin-inline-end: var(--dimension-padding-inline-select-input);
|
|
44
|
+
pointer-events: none;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
> select {
|
|
48
|
+
appearance: none;
|
|
49
|
+
border: none;
|
|
50
|
+
cursor: pointer;
|
|
51
|
+
color: inherit;
|
|
52
|
+
font: inherit;
|
|
53
|
+
|
|
54
|
+
padding-inline-start: var(--dimension-padding-inline-select-input);
|
|
55
|
+
/* Padding + gap + icon size */
|
|
56
|
+
padding-inline-end: calc(
|
|
57
|
+
var(--dimension-padding-inline-select-input) +
|
|
58
|
+
var(--lp-dimension-spacing-inline-xxxs) +
|
|
59
|
+
1em
|
|
60
|
+
);
|
|
61
|
+
padding-block: var(--dimension-padding-block-select-input);
|
|
62
|
+
border-block-end: var(--lp-dimension-stroke-thickness-default) solid
|
|
63
|
+
var(--color-border-select-input);
|
|
64
|
+
background-color: var(--color-background-select-input);
|
|
65
|
+
outline-color: var(--color-outline-select-input);
|
|
66
|
+
border-radius: var(--lp-dimension-radius-none);
|
|
67
|
+
|
|
68
|
+
transition-duration: var(--lp-transition-duration-snap);
|
|
69
|
+
transition-property: background-color, border-color, outline-color;
|
|
70
|
+
transition-timing-function: var(--lp-transition-timing-ease-in);
|
|
71
|
+
|
|
72
|
+
:not(:disabled) {
|
|
73
|
+
&:hover {
|
|
74
|
+
background-color: var(--color-background-select-input-hover);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&:active,
|
|
78
|
+
&:focus {
|
|
79
|
+
background-color: var(--color-background-select-input-active);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
&:disabled {
|
|
84
|
+
cursor: not-allowed;
|
|
85
|
+
opacity: var(--lp-opacity-muted);
|
|
86
|
+
|
|
87
|
+
+ .chevron {
|
|
88
|
+
opacity: var(--lp-opacity-muted);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
&:user-invalid,
|
|
93
|
+
&[aria-invalid="true"] {
|
|
94
|
+
--color-background-select-input: var(
|
|
95
|
+
--lp-color-background-negative-default
|
|
96
|
+
);
|
|
97
|
+
border-color: var(--lp-color-border-negative);
|
|
98
|
+
outline-color: var(--lp-color-border-negative);
|
|
99
|
+
|
|
100
|
+
&:hover {
|
|
101
|
+
background-color: var(--lp-color-background-negative-hover);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
&:active,
|
|
105
|
+
&:focus {
|
|
106
|
+
background-color: var(--lp-color-background-negative-active);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
&:not([multiple]) {
|
|
111
|
+
option {
|
|
112
|
+
/*
|
|
113
|
+
FIXME(steciuk): The colors currently used for the select background have some baked-in transparency.
|
|
114
|
+
This doesn't play well with how the select element is rendered in Chrome, making the options looked washed out and with very low contrast. This is a temporary workaround that aims to strip the transparency from the color while keeping similar visuals.
|
|
115
|
+
|
|
116
|
+
A better solution would be to update the design tokens to use solid colors, but the currently tokens and modifiers system are soon to be replaced anyway, so it might not be worth the effort.
|
|
117
|
+
*/
|
|
118
|
+
background-color: var(--lp-color-background-default);
|
|
119
|
+
/* biome-ignore lint/suspicious/noDuplicateProperties: Fallback for older chrome versions */
|
|
120
|
+
background-color: color-mix(
|
|
121
|
+
in srgb,
|
|
122
|
+
rgb(from var(--color-background-select-input) r g b / 1) 20%,
|
|
123
|
+
var(--lp-color-background-default) 80%
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
&[multiple] {
|
|
129
|
+
padding: 0;
|
|
130
|
+
|
|
131
|
+
option {
|
|
132
|
+
padding-block: var(--dimension-padding-block-select-input);
|
|
133
|
+
padding-inline: var(--dimension-padding-inline-select-input);
|
|
134
|
+
|
|
135
|
+
&:checked {
|
|
136
|
+
background-color: var(--color-background-select-input-active);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
&.base {
|
|
143
|
+
--lp-color-background-secondary-hover-context: initial;
|
|
144
|
+
--lp-color-background-secondary-active-context: initial;
|
|
145
|
+
--lp-color-background-secondary-context: transparent;
|
|
146
|
+
--lp-color-border-secondary-context: initial;
|
|
147
|
+
|
|
148
|
+
> select {
|
|
149
|
+
border: none;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
&:not([multiple]) {
|
|
153
|
+
> select {
|
|
154
|
+
option {
|
|
155
|
+
/* FIXME(steciuk): Pt. 2 of the transparency workaround */
|
|
156
|
+
background-color: var(--lp-color-background-default);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HTMLSelectAttributes } from "svelte/elements";
|
|
2
|
+
import type { ModifierFamilyValues } from "../../modifier-families/index.js";
|
|
3
|
+
export interface SelectProps extends HTMLSelectAttributes {
|
|
4
|
+
ref?: HTMLSelectElement;
|
|
5
|
+
density?: Extract<ModifierFamilyValues["density"], "dense" | "medium">;
|
|
6
|
+
severity?: ModifierFamilyValues["severity"] | "base";
|
|
7
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ModifierFamily } from "../../modifier-families/index.js";
|
|
1
|
+
import type { ModifierFamily, ModifierFamilyValues } from "../../modifier-families/index.js";
|
|
2
2
|
import type { TextInputPrimitiveProps } from "../common/index.js";
|
|
3
3
|
export interface TextInputProps extends TextInputPrimitiveProps, ModifierFamily<"severity"> {
|
|
4
|
-
density?: "dense" | "medium"
|
|
4
|
+
density?: Extract<ModifierFamilyValues["density"], "dense" | "medium">;
|
|
5
5
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
<!-- @canonical/generator-ds 0.17.1 -->
|
|
2
|
+
|
|
3
|
+
<script lang="ts" module>
|
|
4
|
+
import { ChainingManager } from "./utils/ChainingManager.js";
|
|
5
|
+
|
|
6
|
+
const chainingManager = new ChainingManager(350);
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import type { Attachment } from "svelte/attachments";
|
|
11
|
+
import { createAttachmentKey } from "svelte/attachments";
|
|
12
|
+
import { isEventTargetInElement } from "../../utils/index.js";
|
|
13
|
+
import "./styles.css";
|
|
14
|
+
import type { TooltipProps } from "./types.js";
|
|
15
|
+
import { useDelayedOpen } from "./utils/useDelayedOpen.svelte.js";
|
|
16
|
+
import { useTooltipPosition } from "./utils/useTooltipPosition.svelte.js";
|
|
17
|
+
|
|
18
|
+
const componentCssClassName = "ds tooltip";
|
|
19
|
+
const distanceToTrigger = 12; // px
|
|
20
|
+
|
|
21
|
+
let {
|
|
22
|
+
id: idProp,
|
|
23
|
+
class: className,
|
|
24
|
+
children,
|
|
25
|
+
trigger,
|
|
26
|
+
position = "block-start",
|
|
27
|
+
autoAdjust = true,
|
|
28
|
+
delay = 350,
|
|
29
|
+
onmouseleave,
|
|
30
|
+
onmouseenter,
|
|
31
|
+
...rest
|
|
32
|
+
}: TooltipProps = $props();
|
|
33
|
+
|
|
34
|
+
const fallbackId = $props.id();
|
|
35
|
+
const id = $derived(idProp || fallbackId);
|
|
36
|
+
let tooltipRef = $state<HTMLElement>();
|
|
37
|
+
let triggerRef = $state<HTMLElement>();
|
|
38
|
+
|
|
39
|
+
let isTriggerFocused = $state(false);
|
|
40
|
+
let isTriggerHovered = $state(false);
|
|
41
|
+
let isTooltipHovered = $state(false);
|
|
42
|
+
const open = $derived(
|
|
43
|
+
isTriggerFocused || isTriggerHovered || isTooltipHovered,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const listenersTriggerAttachment: Attachment<HTMLElement> = (element) => {
|
|
47
|
+
triggerRef = element;
|
|
48
|
+
const abortController = new AbortController();
|
|
49
|
+
element.addEventListener("mouseenter", () => (isTriggerHovered = true), {
|
|
50
|
+
signal: abortController.signal,
|
|
51
|
+
});
|
|
52
|
+
element.addEventListener(
|
|
53
|
+
"mouseleave",
|
|
54
|
+
(e) => {
|
|
55
|
+
// Check if hover moved to the tooltip, to avoid any flicker before `mouseenter` on the tooltip is fired and handled
|
|
56
|
+
if (isEventTargetInElement(e.relatedTarget, tooltipRef)) {
|
|
57
|
+
isTooltipHovered = true;
|
|
58
|
+
}
|
|
59
|
+
isTriggerHovered = false;
|
|
60
|
+
},
|
|
61
|
+
{ signal: abortController.signal },
|
|
62
|
+
);
|
|
63
|
+
element.addEventListener("focus", () => (isTriggerFocused = true), {
|
|
64
|
+
signal: abortController.signal,
|
|
65
|
+
});
|
|
66
|
+
element.addEventListener("blur", () => (isTriggerFocused = false), {
|
|
67
|
+
signal: abortController.signal,
|
|
68
|
+
});
|
|
69
|
+
return () => {
|
|
70
|
+
triggerRef = undefined;
|
|
71
|
+
abortController.abort();
|
|
72
|
+
isTriggerHovered = false;
|
|
73
|
+
isTriggerFocused = false;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const tooltipOnmouseenter: typeof onmouseenter = (e) => {
|
|
78
|
+
onmouseenter?.(e);
|
|
79
|
+
isTooltipHovered = true;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const tooltipOnmouseleave: typeof onmouseleave = (e) => {
|
|
83
|
+
onmouseleave?.(e);
|
|
84
|
+
// Check if hover moved to the trigger, to avoid any flicker before `mouseenter` on the trigger is fired and handled
|
|
85
|
+
if (isEventTargetInElement(e.relatedTarget, triggerRef))
|
|
86
|
+
isTriggerHovered = true;
|
|
87
|
+
isTooltipHovered = false;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const {
|
|
91
|
+
triggerAttachment: tooltipPositionTriggerAttachment,
|
|
92
|
+
targetAttachment,
|
|
93
|
+
tooltipPosition,
|
|
94
|
+
getTooltipPlacement,
|
|
95
|
+
} = useTooltipPosition(
|
|
96
|
+
// Start positioning even before the tooltip is actually shown (`delayedOpen`)
|
|
97
|
+
() => open,
|
|
98
|
+
() => position,
|
|
99
|
+
() => autoAdjust,
|
|
100
|
+
distanceToTrigger,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const getDelayedOpen = useDelayedOpen(
|
|
104
|
+
() => open,
|
|
105
|
+
() => delay,
|
|
106
|
+
chainingManager,
|
|
107
|
+
);
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
<svelte:window
|
|
111
|
+
onkeydown={(event) => {
|
|
112
|
+
if (event.key === "Escape") {
|
|
113
|
+
// If escape is pressed, close the tooltip no matter what caused it to open
|
|
114
|
+
isTriggerFocused = false;
|
|
115
|
+
isTriggerHovered = false;
|
|
116
|
+
isTooltipHovered = false;
|
|
117
|
+
}
|
|
118
|
+
}}
|
|
119
|
+
/>
|
|
120
|
+
|
|
121
|
+
{@render trigger({
|
|
122
|
+
"aria-describedby": id,
|
|
123
|
+
[createAttachmentKey()]: tooltipPositionTriggerAttachment,
|
|
124
|
+
[createAttachmentKey()]: listenersTriggerAttachment,
|
|
125
|
+
})}
|
|
126
|
+
|
|
127
|
+
<div
|
|
128
|
+
bind:this={tooltipRef}
|
|
129
|
+
{id}
|
|
130
|
+
role="tooltip"
|
|
131
|
+
class={[componentCssClassName, className]}
|
|
132
|
+
style:display={open /* Flip to block immediately, so it can be positioned even before shown */
|
|
133
|
+
? "block"
|
|
134
|
+
: "none"}
|
|
135
|
+
style:visibility={getDelayedOpen() ? "visible" : "hidden"}
|
|
136
|
+
{@attach targetAttachment}
|
|
137
|
+
style:top={tooltipPosition.top}
|
|
138
|
+
style:left={tooltipPosition.left}
|
|
139
|
+
style:--distance-to-trigger={`${distanceToTrigger}px`}
|
|
140
|
+
data-placement={getTooltipPlacement()}
|
|
141
|
+
onmouseenter={tooltipOnmouseenter}
|
|
142
|
+
onmouseleave={tooltipOnmouseleave}
|
|
143
|
+
{...rest}
|
|
144
|
+
>
|
|
145
|
+
{@render children()}
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
<!-- @component
|
|
149
|
+
`Tooltip` are non-interactive elements that aim to provide additional information about a specific element or action.
|
|
150
|
+
|
|
151
|
+
Tooltip requires JavaScript to function correctly. If JavaScript is disabled, the tooltip content will not be accessible.
|
|
152
|
+
TODO(no-js): Investigate how to handle tooltips without JavaScript.
|
|
153
|
+
|
|
154
|
+
The tooltip enables a short "chaining" window (~350ms) after it closes. If any tooltip's trigger is hovered or focused within this window, the tooltip bypasses `delay` and opens immediately.
|
|
155
|
+
|
|
156
|
+
## Example Usage
|
|
157
|
+
```svelte
|
|
158
|
+
<Tooltip position="block-start" delay={500} autoAdjust={true}>
|
|
159
|
+
{#snippet trigger(triggerProps)}
|
|
160
|
+
<Button {...triggerProps}>Hover or focus me</Button>
|
|
161
|
+
{/snippet}
|
|
162
|
+
I am a tooltip!
|
|
163
|
+
</Tooltip>
|
|
164
|
+
```
|
|
165
|
+
-->
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "./styles.css";
|
|
2
|
+
import type { TooltipProps } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* `Tooltip` are non-interactive elements that aim to provide additional information about a specific element or action.
|
|
5
|
+
*
|
|
6
|
+
* Tooltip requires JavaScript to function correctly. If JavaScript is disabled, the tooltip content will not be accessible.
|
|
7
|
+
* TODO(no-js): Investigate how to handle tooltips without JavaScript.
|
|
8
|
+
*
|
|
9
|
+
* The tooltip enables a short "chaining" window (~350ms) after it closes. If any tooltip's trigger is hovered or focused within this window, the tooltip bypasses `delay` and opens immediately.
|
|
10
|
+
*
|
|
11
|
+
* ## Example Usage
|
|
12
|
+
* ```svelte
|
|
13
|
+
* <Tooltip position="block-start" delay={500} autoAdjust={true}>
|
|
14
|
+
* {#snippet trigger(triggerProps)}
|
|
15
|
+
* <Button {...triggerProps}>Hover or focus me</Button>
|
|
16
|
+
* {/snippet}
|
|
17
|
+
* I am a tooltip!
|
|
18
|
+
* </Tooltip>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare const Tooltip: import("svelte").Component<TooltipProps, {}, "">;
|
|
22
|
+
type Tooltip = ReturnType<typeof Tooltip>;
|
|
23
|
+
export default Tooltip;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
.ds.tooltip {
|
|
2
|
+
--color-background-tooltip: var(--lp-color-background-alt-reversed);
|
|
3
|
+
--dimension-offset-tooltip-arrow: var(--lp-dimension-spacing-inline-m);
|
|
4
|
+
--dimension-height-tooltip-arrow: var(--lp-dimension-size-xxxs);
|
|
5
|
+
position: absolute;
|
|
6
|
+
width: max-content;
|
|
7
|
+
/* TODO(z-index-tokens): Should we tokenize z-indexes? What would they be used for except the tooltip? */
|
|
8
|
+
z-index: 10;
|
|
9
|
+
background-color: var(--color-background-tooltip);
|
|
10
|
+
font: var(--lp-typography-paragraph-s);
|
|
11
|
+
color: var(--lp-color-text-reversed);
|
|
12
|
+
padding-inline: var(--lp-dimension-spacing-inline-m);
|
|
13
|
+
padding-block: var(--lp-dimension-spacing-block-xs);
|
|
14
|
+
|
|
15
|
+
&::before {
|
|
16
|
+
/* Filler to allow moving the hover from the trigger to the tooltip */
|
|
17
|
+
/* TODO: The filler is always of tooltip width/height, which in case the tooltip is bigger than the trigger in cross axis, will cause it to not disappear even if mouse hover is perceived to be outside bounds of both elements. This doesn't seem to be a major problem, but ideally the filler would match the smaller element's dimensions */
|
|
18
|
+
content: "";
|
|
19
|
+
position: absolute;
|
|
20
|
+
display: block;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&::after {
|
|
24
|
+
/* Tooltip arrow */
|
|
25
|
+
content: "";
|
|
26
|
+
position: absolute;
|
|
27
|
+
border-width: var(--dimension-height-tooltip-arrow);
|
|
28
|
+
border-style: solid;
|
|
29
|
+
border-color: transparent;
|
|
30
|
+
pointer-events: none;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&[data-placement^="top"] {
|
|
34
|
+
/* top, top-start, top-end */
|
|
35
|
+
&::before {
|
|
36
|
+
bottom: calc(-1 * var(--distance-to-trigger));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&::after {
|
|
40
|
+
border-top-color: var(--color-background-tooltip);
|
|
41
|
+
top: 100%;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&[data-placement^="bottom"] {
|
|
46
|
+
/* bottom, bottom-start, bottom-end */
|
|
47
|
+
&::before {
|
|
48
|
+
top: calc(-1 * var(--distance-to-trigger));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&::after {
|
|
52
|
+
border-bottom-color: var(--color-background-tooltip);
|
|
53
|
+
bottom: 100%;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&[data-placement^="top"],
|
|
58
|
+
&[data-placement^="bottom"] {
|
|
59
|
+
&::before {
|
|
60
|
+
width: 100%;
|
|
61
|
+
left: 0;
|
|
62
|
+
height: var(--distance-to-trigger);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
&[data-placement$="start"]::after {
|
|
66
|
+
left: var(--dimension-offset-tooltip-arrow);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&[data-placement$="end"]::after {
|
|
70
|
+
right: var(--dimension-offset-tooltip-arrow);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&[data-placement="top"]::after,
|
|
75
|
+
&[data-placement="bottom"]::after {
|
|
76
|
+
left: 50%;
|
|
77
|
+
transform: translateX(-50%);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
&[data-placement^="left"] {
|
|
81
|
+
&::before {
|
|
82
|
+
width: var(--distance-to-trigger);
|
|
83
|
+
right: calc(-1 * var(--distance-to-trigger));
|
|
84
|
+
height: 100%;
|
|
85
|
+
top: 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&::after {
|
|
89
|
+
border-left-color: var(--color-background-tooltip);
|
|
90
|
+
left: 100%;
|
|
91
|
+
top: 50%;
|
|
92
|
+
transform: translateY(-50%);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
&[data-placement^="right"] {
|
|
97
|
+
&::before {
|
|
98
|
+
width: var(--distance-to-trigger);
|
|
99
|
+
left: calc(-1 * var(--distance-to-trigger));
|
|
100
|
+
height: 100%;
|
|
101
|
+
top: 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
&::after {
|
|
105
|
+
border-right-color: var(--color-background-tooltip);
|
|
106
|
+
right: 100%;
|
|
107
|
+
top: 50%;
|
|
108
|
+
transform: translateY(-50%);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { Attachment } from "svelte/attachments";
|
|
3
|
+
import type { SvelteHTMLElements } from "svelte/elements";
|
|
4
|
+
import type { PositionArea } from "../../useFunctions/usePositionArea.svelte.js";
|
|
5
|
+
type BaseProps = Omit<SvelteHTMLElements["div"], "children">;
|
|
6
|
+
export type TooltipTriggerProps = {
|
|
7
|
+
"aria-describedby": string;
|
|
8
|
+
[key: symbol]: Attachment<HTMLElement>;
|
|
9
|
+
};
|
|
10
|
+
export interface TooltipProps extends BaseProps {
|
|
11
|
+
/**
|
|
12
|
+
* Elements that trigger the tooltip when hovered or focused.
|
|
13
|
+
*
|
|
14
|
+
* Snippet arguments:
|
|
15
|
+
* - `triggerProps`: Props that should be spread on the trigger element to make it control the tooltip:
|
|
16
|
+
* - `aria-describedby`: The id of the tooltip element. Setting this attribute on the trigger element enables assistive technologies to associate the tooltip with the trigger;
|
|
17
|
+
* - attachments allow the tooltip to listen to events on the trigger element (hover, focus) and position the tooltip relative to the trigger element.
|
|
18
|
+
*/
|
|
19
|
+
trigger: Snippet<[triggerProps: TooltipTriggerProps]>;
|
|
20
|
+
/**
|
|
21
|
+
* Content to be displayed inside the tooltip. It should not contain interactive elements (see: https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/)
|
|
22
|
+
*/
|
|
23
|
+
children: Snippet<[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Tooltip position. This is a subset of valid CSS [<position-area>](https://developer.mozilla.org/en-US/docs/Web/CSS/position-area) keyword combinations.
|
|
26
|
+
*
|
|
27
|
+
* @default "block-start"
|
|
28
|
+
*/
|
|
29
|
+
position?: PositionArea;
|
|
30
|
+
/**
|
|
31
|
+
* If set to true, the tooltip will try to find an alternative position if the preferred position does not fit in the viewport.
|
|
32
|
+
*
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
autoAdjust?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Delay in milliseconds before showing the tooltip after the user hovers or focuses the trigger element.
|
|
38
|
+
*
|
|
39
|
+
* @default 350
|
|
40
|
+
*/
|
|
41
|
+
delay?: number;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages the chaining state for tooltips, allowing for a grace period during which tooltips can be shown without delay.
|
|
3
|
+
*/
|
|
4
|
+
export declare class ChainingManager {
|
|
5
|
+
/**
|
|
6
|
+
* The duration (in milliseconds) for which chaining remains active after being set to true.
|
|
7
|
+
*/
|
|
8
|
+
private readonly chainingThreshold;
|
|
9
|
+
private _chaining;
|
|
10
|
+
private chainingTimeout;
|
|
11
|
+
constructor(
|
|
12
|
+
/**
|
|
13
|
+
* The duration (in milliseconds) for which chaining remains active after being set to true.
|
|
14
|
+
*/
|
|
15
|
+
chainingThreshold: number);
|
|
16
|
+
set chaining(value: boolean);
|
|
17
|
+
get chaining(): boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages the chaining state for tooltips, allowing for a grace period during which tooltips can be shown without delay.
|
|
3
|
+
*/
|
|
4
|
+
export class ChainingManager {
|
|
5
|
+
chainingThreshold;
|
|
6
|
+
_chaining = false;
|
|
7
|
+
chainingTimeout = null;
|
|
8
|
+
constructor(
|
|
9
|
+
/**
|
|
10
|
+
* The duration (in milliseconds) for which chaining remains active after being set to true.
|
|
11
|
+
*/
|
|
12
|
+
chainingThreshold) {
|
|
13
|
+
this.chainingThreshold = chainingThreshold;
|
|
14
|
+
}
|
|
15
|
+
set chaining(value) {
|
|
16
|
+
this._chaining = value;
|
|
17
|
+
if (this.chainingTimeout !== null)
|
|
18
|
+
clearTimeout(this.chainingTimeout);
|
|
19
|
+
if (value) {
|
|
20
|
+
this.chainingTimeout = setTimeout(() => {
|
|
21
|
+
this._chaining = false;
|
|
22
|
+
this.chainingTimeout = null;
|
|
23
|
+
}, this.chainingThreshold);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
get chaining() {
|
|
27
|
+
return this._chaining;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ChainingManager } from "./ChainingManager.js";
|
|
2
|
+
/**
|
|
3
|
+
* Manage a tooltip's delayed open state, supporting a short-lived "chaining" mode
|
|
4
|
+
* where successive tooltips open without delay.
|
|
5
|
+
*
|
|
6
|
+
* The returned getter reflects whether the tooltip should currently be considered open
|
|
7
|
+
* (after any applied delay). When `getOpen()` becomes false the delayed state resets and
|
|
8
|
+
* briefly enables chaining for the next open.
|
|
9
|
+
*
|
|
10
|
+
* @param getOpen - Reactive getter indicating the raw (immediate) open intent.
|
|
11
|
+
* @param getDelay - Reactive getter providing the delay in milliseconds before showing.
|
|
12
|
+
* @param chainingManager - Shared manager tracking whether chaining is active.
|
|
13
|
+
* @returns A function that returns the (possibly delayed) open boolean.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useDelayedOpen(getOpen: () => boolean, getDelay: () => number, chainingManager: ChainingManager): () => boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { untrack } from "svelte";
|
|
2
|
+
/**
|
|
3
|
+
* Manage a tooltip's delayed open state, supporting a short-lived "chaining" mode
|
|
4
|
+
* where successive tooltips open without delay.
|
|
5
|
+
*
|
|
6
|
+
* The returned getter reflects whether the tooltip should currently be considered open
|
|
7
|
+
* (after any applied delay). When `getOpen()` becomes false the delayed state resets and
|
|
8
|
+
* briefly enables chaining for the next open.
|
|
9
|
+
*
|
|
10
|
+
* @param getOpen - Reactive getter indicating the raw (immediate) open intent.
|
|
11
|
+
* @param getDelay - Reactive getter providing the delay in milliseconds before showing.
|
|
12
|
+
* @param chainingManager - Shared manager tracking whether chaining is active.
|
|
13
|
+
* @returns A function that returns the (possibly delayed) open boolean.
|
|
14
|
+
*/
|
|
15
|
+
export function useDelayedOpen(getOpen, getDelay, chainingManager) {
|
|
16
|
+
let delayedOpen = $state(getOpen());
|
|
17
|
+
$effect(() => {
|
|
18
|
+
if (getOpen()) {
|
|
19
|
+
if (chainingManager.chaining) {
|
|
20
|
+
// If chaining, open immediately without delay
|
|
21
|
+
delayedOpen = true;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const delayTimeout = setTimeout(() => {
|
|
25
|
+
delayedOpen = true;
|
|
26
|
+
// Do not rerun if delay changes, apply the new delay only to the next open change
|
|
27
|
+
}, untrack(getDelay));
|
|
28
|
+
return () => clearTimeout(delayTimeout);
|
|
29
|
+
}
|
|
30
|
+
delayedOpen = false;
|
|
31
|
+
});
|
|
32
|
+
let firstRun = true;
|
|
33
|
+
$effect(() => {
|
|
34
|
+
// Each time the tooltip closes, enable chaining for a short period
|
|
35
|
+
// Skip first run. Be sure to read `delayedOpen` first to ensure the effect runs again when it changes
|
|
36
|
+
if (!delayedOpen && !firstRun) {
|
|
37
|
+
chainingManager.chaining = true;
|
|
38
|
+
}
|
|
39
|
+
firstRun = false;
|
|
40
|
+
});
|
|
41
|
+
return () => delayedOpen;
|
|
42
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Placement } from "@floating-ui/dom";
|
|
2
|
+
import { type PositionArea } from "../../../useFunctions/usePositionArea.svelte.js";
|
|
3
|
+
/**
|
|
4
|
+
* Compute reactive tooltip positioning using Floating UI, with optional automatic flipping.
|
|
5
|
+
*
|
|
6
|
+
* @param getActive - Getter indicating if the tooltip should currently be positioned.
|
|
7
|
+
* @param getPosition - Getter returning the preferred logical position area.
|
|
8
|
+
* @param getAutoAdjust - Getter determining whether the tooltip may flip to remain in viewport.
|
|
9
|
+
* @param distanceToTrigger - Pixel offset distance between trigger element and tooltip.
|
|
10
|
+
* @returns
|
|
11
|
+
* - triggerAttachment - Attachment to be applied to the tooltip trigger element.
|
|
12
|
+
* - targetAttachment - Attachment to be applied to the tooltip target element.
|
|
13
|
+
* - tooltipPosition - Reactive style object containing the current position of the tooltip.
|
|
14
|
+
* - getTooltipPlacement - Getter for the current placement of the tooltip (after any auto-adjustment).
|
|
15
|
+
*/
|
|
16
|
+
export declare function useTooltipPosition(getActive: () => boolean, getPosition: () => PositionArea, getAutoAdjust: () => boolean, distanceToTrigger: number): {
|
|
17
|
+
triggerAttachment: import("svelte/attachments").Attachment<HTMLElement>;
|
|
18
|
+
targetAttachment: import("svelte/attachments").Attachment<HTMLElement>;
|
|
19
|
+
tooltipPosition: {
|
|
20
|
+
top: string;
|
|
21
|
+
left: string;
|
|
22
|
+
};
|
|
23
|
+
getTooltipPlacement: () => Placement;
|
|
24
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { flip, offset } from "@floating-ui/dom";
|
|
2
|
+
import { positionAreaFallbackMap, useFloatingUI, } from "../../../useFunctions/usePositionArea.svelte.js";
|
|
3
|
+
/**
|
|
4
|
+
* Compute reactive tooltip positioning using Floating UI, with optional automatic flipping.
|
|
5
|
+
*
|
|
6
|
+
* @param getActive - Getter indicating if the tooltip should currently be positioned.
|
|
7
|
+
* @param getPosition - Getter returning the preferred logical position area.
|
|
8
|
+
* @param getAutoAdjust - Getter determining whether the tooltip may flip to remain in viewport.
|
|
9
|
+
* @param distanceToTrigger - Pixel offset distance between trigger element and tooltip.
|
|
10
|
+
* @returns
|
|
11
|
+
* - triggerAttachment - Attachment to be applied to the tooltip trigger element.
|
|
12
|
+
* - targetAttachment - Attachment to be applied to the tooltip target element.
|
|
13
|
+
* - tooltipPosition - Reactive style object containing the current position of the tooltip.
|
|
14
|
+
* - getTooltipPlacement - Getter for the current placement of the tooltip (after any auto-adjustment).
|
|
15
|
+
*/
|
|
16
|
+
export function useTooltipPosition(getActive, getPosition, getAutoAdjust, distanceToTrigger) {
|
|
17
|
+
const tooltipPosition = $state({ top: "auto", left: "auto" });
|
|
18
|
+
let tooltipPlacement = $derived(positionAreaFallbackMap[getPosition()]);
|
|
19
|
+
const floatingUiConfig = $derived({
|
|
20
|
+
placement: positionAreaFallbackMap[getPosition()],
|
|
21
|
+
middleware: [
|
|
22
|
+
offset(distanceToTrigger),
|
|
23
|
+
getAutoAdjust() &&
|
|
24
|
+
flip({
|
|
25
|
+
fallbackAxisSideDirection: "start",
|
|
26
|
+
}),
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
const { triggerAttachment, targetAttachment } = useFloatingUI(getActive, () => floatingUiConfig, ({ x, y, placement }) => {
|
|
30
|
+
tooltipPosition.top = `${y}px`;
|
|
31
|
+
tooltipPosition.left = `${x}px`;
|
|
32
|
+
tooltipPlacement = placement;
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
triggerAttachment,
|
|
36
|
+
targetAttachment,
|
|
37
|
+
tooltipPosition,
|
|
38
|
+
getTooltipPlacement: () => tooltipPlacement,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -11,6 +11,8 @@ export * from "./NumberInput/index.js";
|
|
|
11
11
|
export * from "./Popover/index.js";
|
|
12
12
|
export * from "./Radio/index.js";
|
|
13
13
|
export * from "./RelativeDateTime/index.js";
|
|
14
|
+
export * from "./SearchBox/index.js";
|
|
15
|
+
export * from "./Select/index.js";
|
|
14
16
|
export * from "./SidePanel/index.js";
|
|
15
17
|
export * from "./Spinner/index.js";
|
|
16
18
|
export * from "./Switch/index.js";
|
|
@@ -18,4 +20,5 @@ export * from "./Table/index.js";
|
|
|
18
20
|
export * from "./Textarea/index.js";
|
|
19
21
|
export * from "./TextInput/index.js";
|
|
20
22
|
export * from "./Timeline/index.js";
|
|
23
|
+
export * from "./Tooltip/index.js";
|
|
21
24
|
export * from "./UserAvatar/index.js";
|
package/dist/components/index.js
CHANGED
|
@@ -11,6 +11,8 @@ export * from "./NumberInput/index.js";
|
|
|
11
11
|
export * from "./Popover/index.js";
|
|
12
12
|
export * from "./Radio/index.js";
|
|
13
13
|
export * from "./RelativeDateTime/index.js";
|
|
14
|
+
export * from "./SearchBox/index.js";
|
|
15
|
+
export * from "./Select/index.js";
|
|
14
16
|
export * from "./SidePanel/index.js";
|
|
15
17
|
export * from "./Spinner/index.js";
|
|
16
18
|
export * from "./Switch/index.js";
|
|
@@ -18,4 +20,5 @@ export * from "./Table/index.js";
|
|
|
18
20
|
export * from "./Textarea/index.js";
|
|
19
21
|
export * from "./TextInput/index.js";
|
|
20
22
|
export * from "./Timeline/index.js";
|
|
23
|
+
export * from "./Tooltip/index.js";
|
|
21
24
|
export * from "./UserAvatar/index.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/svelte-ds-app-launchpad",
|
|
3
3
|
"description": "Launchpad-specific components for the Pragma design system.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.27.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@biomejs/biome": "2.4.9",
|
|
63
|
-
"@canonical/biome-config": "^0.
|
|
63
|
+
"@canonical/biome-config": "^0.27.0",
|
|
64
64
|
"@canonical/design-tokens": "^0.6.0",
|
|
65
|
-
"@canonical/storybook-config": "^0.
|
|
66
|
-
"@canonical/storybook-helpers": "^0.
|
|
67
|
-
"@canonical/svelte-ssr-test": "^0.
|
|
68
|
-
"@canonical/typescript-config-svelte": "^0.
|
|
69
|
-
"@canonical/webarchitect": "^0.
|
|
65
|
+
"@canonical/storybook-config": "^0.27.0",
|
|
66
|
+
"@canonical/storybook-helpers": "^0.27.0",
|
|
67
|
+
"@canonical/svelte-ssr-test": "^0.27.0",
|
|
68
|
+
"@canonical/typescript-config-svelte": "^0.27.0",
|
|
69
|
+
"@canonical/webarchitect": "^0.27.0",
|
|
70
70
|
"@storybook/addon-docs": "^10.3.1",
|
|
71
71
|
"@storybook/addon-svelte-csf": "^5.0.11",
|
|
72
72
|
"@sveltejs/package": "^2.5.7",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"peerDependencies": {
|
|
91
91
|
"svelte": "^5.47.1"
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "5df5709bf7cb6f2016be2f6eba8391637e2e2a0c"
|
|
94
94
|
}
|