@canonical/svelte-ds-app-launchpad 0.17.1 → 0.20.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 +8 -0
- package/dist/Welcome.mdx +3 -2
- package/dist/components/Breadcrumbs/Breadcrumbs.ssr.test.d.ts +1 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.ssr.test.js +101 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.stories.svelte +139 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.stories.svelte.d.ts +19 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.svelte +107 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.svelte.d.ts +27 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.svelte.test.d.ts +1 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.svelte.test.js +298 -0
- package/dist/components/Breadcrumbs/common/CollapsedItems/CollapsedItems.svelte +43 -0
- package/dist/components/Breadcrumbs/common/CollapsedItems/CollapsedItems.svelte.d.ts +5 -0
- package/dist/components/Breadcrumbs/common/CollapsedItems/index.d.ts +2 -0
- package/dist/components/Breadcrumbs/common/CollapsedItems/index.js +2 -0
- package/dist/components/Breadcrumbs/common/CollapsedItems/styles.css +70 -0
- package/dist/components/Breadcrumbs/common/CollapsedItems/types.d.ts +7 -0
- package/dist/components/Breadcrumbs/common/CollapsedItems/types.js +1 -0
- package/dist/components/Breadcrumbs/common/ExpandedItems/ExpandedItems.svelte +44 -0
- package/dist/components/Breadcrumbs/common/ExpandedItems/ExpandedItems.svelte.d.ts +5 -0
- package/dist/components/Breadcrumbs/common/ExpandedItems/index.d.ts +2 -0
- package/dist/components/Breadcrumbs/common/ExpandedItems/index.js +2 -0
- package/dist/components/Breadcrumbs/common/ExpandedItems/styles.css +37 -0
- package/dist/components/Breadcrumbs/common/ExpandedItems/types.d.ts +14 -0
- package/dist/components/Breadcrumbs/common/ExpandedItems/types.js +1 -0
- package/dist/components/Breadcrumbs/common/common/Item/Item.svelte +26 -0
- package/dist/components/Breadcrumbs/common/common/Item/Item.svelte.d.ts +4 -0
- package/dist/components/Breadcrumbs/common/common/Item/index.d.ts +2 -0
- package/dist/components/Breadcrumbs/common/common/Item/index.js +2 -0
- package/dist/components/Breadcrumbs/common/common/Item/types.d.ts +5 -0
- package/dist/components/Breadcrumbs/common/common/Item/types.js +1 -0
- package/dist/components/Breadcrumbs/common/common/index.d.ts +1 -0
- package/dist/components/Breadcrumbs/common/common/index.js +1 -0
- package/dist/components/Breadcrumbs/common/index.d.ts +2 -0
- package/dist/components/Breadcrumbs/common/index.js +2 -0
- package/dist/components/Breadcrumbs/index.d.ts +2 -0
- package/dist/components/Breadcrumbs/index.js +2 -0
- package/dist/components/Breadcrumbs/styles.css +24 -0
- package/dist/components/Breadcrumbs/types.d.ts +28 -0
- package/dist/components/Breadcrumbs/types.js +2 -0
- package/dist/components/Button/Button.stories.svelte +3 -3
- package/dist/components/Button/Button.svelte +19 -19
- package/dist/components/Button/Button.svelte.test.js +7 -21
- package/dist/components/Button/common/Content/Content.svelte +10 -10
- package/dist/components/Button/common/Content/styles.css +53 -52
- package/dist/components/Button/types.d.ts +1 -1
- package/dist/components/Checkbox/Checkbox.svelte.test.js +0 -1
- package/dist/components/Checkbox/styles.css +2 -2
- package/dist/components/Chip/Chip.stories.svelte +3 -2
- package/dist/components/Chip/Chip.svelte.test.js +20 -4
- package/dist/components/DateTime/DateTime.ssr.test.d.ts +1 -0
- package/dist/components/DateTime/DateTime.ssr.test.js +94 -0
- package/dist/components/DateTime/DateTime.stories.svelte +34 -0
- package/dist/components/DateTime/DateTime.stories.svelte.d.ts +19 -0
- package/dist/components/DateTime/DateTime.svelte +27 -0
- package/dist/components/DateTime/DateTime.svelte.d.ts +12 -0
- package/dist/components/DateTime/DateTime.svelte.test.d.ts +1 -0
- package/dist/components/DateTime/DateTime.svelte.test.js +81 -0
- package/dist/components/DateTime/index.d.ts +2 -0
- package/dist/components/DateTime/index.js +2 -0
- package/dist/components/DateTime/types.d.ts +16 -0
- package/dist/components/DateTime/types.js +2 -0
- package/dist/components/DateTime/utils/formatters.d.ts +1 -0
- package/dist/components/DateTime/utils/formatters.js +5 -0
- package/dist/components/DescriptionList/DescriptionList.ssr.test.d.ts +1 -0
- package/dist/components/DescriptionList/DescriptionList.ssr.test.js +50 -0
- package/dist/components/DescriptionList/DescriptionList.stories.svelte +40 -0
- package/dist/components/DescriptionList/DescriptionList.stories.svelte.d.ts +19 -0
- package/dist/components/DescriptionList/DescriptionList.svelte +43 -0
- package/dist/components/DescriptionList/DescriptionList.svelte.d.ts +18 -0
- package/dist/components/DescriptionList/DescriptionList.svelte.test.d.ts +1 -0
- package/dist/components/DescriptionList/DescriptionList.svelte.test.js +45 -0
- package/dist/components/DescriptionList/common/Item/Item.ssr.test.d.ts +1 -0
- package/dist/components/DescriptionList/common/Item/Item.ssr.test.js +66 -0
- package/dist/components/DescriptionList/common/Item/Item.stories.svelte +34 -0
- package/dist/components/DescriptionList/common/Item/Item.stories.svelte.d.ts +19 -0
- package/dist/components/DescriptionList/common/Item/Item.svelte +21 -0
- package/dist/components/DescriptionList/common/Item/Item.svelte.d.ts +5 -0
- package/dist/components/DescriptionList/common/Item/Item.svelte.test.d.ts +1 -0
- package/dist/components/DescriptionList/common/Item/Item.svelte.test.js +62 -0
- package/dist/components/DescriptionList/common/Item/index.d.ts +2 -0
- package/dist/components/DescriptionList/common/Item/index.js +3 -0
- package/dist/components/DescriptionList/common/Item/styles.css +64 -0
- package/dist/components/DescriptionList/common/Item/types.d.ts +14 -0
- package/dist/components/DescriptionList/common/Item/types.js +2 -0
- package/dist/components/DescriptionList/common/index.d.ts +1 -0
- package/dist/components/DescriptionList/common/index.js +1 -0
- package/dist/components/DescriptionList/context.d.ts +2 -0
- package/dist/components/DescriptionList/context.js +2 -0
- package/dist/components/DescriptionList/index.d.ts +17 -0
- package/dist/components/DescriptionList/index.js +6 -0
- package/dist/components/DescriptionList/styles.css +29 -0
- package/dist/components/DescriptionList/types.d.ts +14 -0
- package/dist/components/DescriptionList/types.js +2 -0
- package/dist/components/Link/Link.ssr.test.d.ts +1 -0
- package/dist/components/Link/Link.ssr.test.js +59 -0
- package/dist/components/Link/Link.stories.svelte +18 -0
- package/dist/components/Link/Link.stories.svelte.d.ts +19 -0
- package/dist/components/Link/Link.svelte +25 -0
- package/dist/components/Link/Link.svelte.d.ts +15 -0
- package/dist/components/Link/Link.svelte.test.d.ts +1 -0
- package/dist/components/Link/Link.svelte.test.js +56 -0
- package/dist/components/Link/index.d.ts +2 -0
- package/dist/components/Link/index.js +2 -0
- package/dist/components/Link/styles.css +19 -0
- package/dist/components/Link/types.d.ts +7 -0
- package/dist/components/Link/types.js +2 -0
- package/dist/components/NumberInput/NumberInput.svelte +11 -11
- package/dist/components/Popover/Popover.ssr.test.d.ts +1 -0
- package/dist/components/Popover/Popover.ssr.test.js +70 -0
- package/dist/components/Popover/Popover.stories.svelte +170 -0
- package/dist/components/Popover/Popover.stories.svelte.d.ts +4 -0
- package/dist/components/Popover/Popover.svelte +103 -0
- package/dist/components/Popover/Popover.svelte.d.ts +36 -0
- package/dist/components/Popover/Popover.svelte.test.d.ts +1 -0
- package/dist/components/Popover/Popover.svelte.test.js +137 -0
- package/dist/components/Popover/index.d.ts +2 -0
- package/dist/components/Popover/index.js +2 -0
- package/dist/components/Popover/styles.css +7 -0
- package/dist/components/Popover/test.fixtures.svelte +25 -0
- package/dist/components/Popover/test.fixtures.svelte.d.ts +26 -0
- package/dist/components/Popover/types.d.ts +58 -0
- package/dist/components/Popover/types.js +2 -0
- package/dist/components/Radio/Radio.svelte.test.js +0 -1
- package/dist/components/RelativeDateTime/RelativeDateTime.ssr.test.d.ts +1 -0
- package/dist/components/RelativeDateTime/RelativeDateTime.ssr.test.js +130 -0
- package/dist/components/RelativeDateTime/RelativeDateTime.stories.svelte +41 -0
- package/dist/components/RelativeDateTime/RelativeDateTime.stories.svelte.d.ts +19 -0
- package/dist/components/RelativeDateTime/RelativeDateTime.svelte +86 -0
- package/dist/components/RelativeDateTime/RelativeDateTime.svelte.d.ts +13 -0
- package/dist/components/RelativeDateTime/RelativeDateTime.svelte.test.d.ts +1 -0
- package/dist/components/RelativeDateTime/RelativeDateTime.svelte.test.js +152 -0
- package/dist/components/RelativeDateTime/index.d.ts +2 -0
- package/dist/components/RelativeDateTime/index.js +2 -0
- package/dist/components/RelativeDateTime/types.d.ts +26 -0
- package/dist/components/RelativeDateTime/types.js +2 -0
- package/dist/components/RelativeDateTime/utils/constants.d.ts +1 -0
- package/dist/components/RelativeDateTime/utils/constants.js +9 -0
- package/dist/components/RelativeDateTime/utils/formatters.d.ts +2 -0
- package/dist/components/RelativeDateTime/utils/formatters.js +9 -0
- package/dist/components/RelativeDateTime/utils/getOptimalRelativeTimeFormatValue.d.ts +15 -0
- package/dist/components/RelativeDateTime/utils/getOptimalRelativeTimeFormatValue.js +21 -0
- package/dist/components/RelativeDateTime/utils/getOptimalRelativeTimeFormatValue.test.d.ts +1 -0
- package/dist/components/RelativeDateTime/utils/getOptimalRelativeTimeFormatValue.test.js +65 -0
- package/dist/components/Spinner/Spinner.stories.svelte +7 -7
- package/dist/components/Spinner/Spinner.svelte +5 -5
- package/dist/components/Spinner/Spinner.svelte.test.js +2 -6
- package/dist/components/Spinner/styles.css +9 -9
- package/dist/components/Switch/Switch.ssr.test.js +0 -1
- package/dist/components/Switch/Switch.svelte.test.js +0 -1
- package/dist/components/TextInput/TextInput.ssr.test.js +6 -1
- package/dist/components/TextInput/TextInput.svelte +11 -11
- package/dist/components/TextInput/TextInput.svelte.test.js +7 -1
- package/dist/components/Textarea/Textarea.stories.svelte +26 -26
- package/dist/components/Textarea/Textarea.svelte +21 -21
- package/dist/components/common/ButtonPrimitive/ButtonPrimitive.svelte.test.js +1 -3
- package/dist/components/common/InputPrimitive/InputPrimitive.ssr.test.js +6 -1
- package/dist/components/common/InputPrimitive/InputPrimitive.svelte.test.js +7 -1
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.js +6 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/modifier-families/styles/density.css +6 -2
- package/dist/styles/index.css +1 -4
- package/dist/test-utils.d.ts +6 -0
- package/dist/test-utils.js +18 -0
- package/dist/usePositionArea.svelte.d.ts +57 -0
- package/dist/usePositionArea.svelte.js +145 -0
- package/package.json +18 -17
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import type { TextareaProps } from "./types.js";
|
|
3
|
+
import { calculateDynamicRows } from "./utils/index.js";
|
|
4
4
|
import "./styles.css";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const componentCssClassName = "ds textarea";
|
|
7
|
+
const defaultRows = 2;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
let {
|
|
10
|
+
class: className,
|
|
11
|
+
value = $bindable(),
|
|
12
|
+
ref = $bindable(),
|
|
13
|
+
rows: rowsProps = [defaultRows, defaultRows * 2 + 1],
|
|
14
|
+
...rest
|
|
15
|
+
}: TextareaProps = $props();
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const dynamicRows = $derived.by(() => {
|
|
18
|
+
if (typeof rowsProps === "number") {
|
|
19
|
+
return rowsProps;
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
if (!value) {
|
|
23
|
+
return rowsProps[0];
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const [minRows, maxRows] = rowsProps;
|
|
27
|
+
return calculateDynamicRows(value, minRows, maxRows);
|
|
28
|
+
});
|
|
29
29
|
</script>
|
|
30
30
|
|
|
31
31
|
<textarea
|
|
@@ -42,9 +42,7 @@ describe("ButtonPrimitive component", () => {
|
|
|
42
42
|
...baseProps,
|
|
43
43
|
class: "test-class",
|
|
44
44
|
});
|
|
45
|
-
await expect
|
|
46
|
-
.element(componentLocator(page))
|
|
47
|
-
.toHaveClass("test-class");
|
|
45
|
+
await expect.element(componentLocator(page)).toHaveClass("test-class");
|
|
48
46
|
});
|
|
49
47
|
it("applies style", async () => {
|
|
50
48
|
const page = render(Component, {
|
|
@@ -42,7 +42,12 @@ describe("InputPrimitive SSR", () => {
|
|
|
42
42
|
const page = render(Component, { props: { ...baseProps } });
|
|
43
43
|
expect(componentLocator(page).type).toBe("text");
|
|
44
44
|
});
|
|
45
|
-
it.each([
|
|
45
|
+
it.each([
|
|
46
|
+
"text",
|
|
47
|
+
"email",
|
|
48
|
+
"url",
|
|
49
|
+
"tel",
|
|
50
|
+
])("accepts %s", (type) => {
|
|
46
51
|
const page = render(Component, {
|
|
47
52
|
props: { type, ...baseProps },
|
|
48
53
|
});
|
|
@@ -38,7 +38,13 @@ describe("InputPrimitive component", () => {
|
|
|
38
38
|
.element(componentLocator(page))
|
|
39
39
|
.toHaveAttribute("type", "text");
|
|
40
40
|
});
|
|
41
|
-
it.each([
|
|
41
|
+
it.each([
|
|
42
|
+
"text",
|
|
43
|
+
"password",
|
|
44
|
+
"email",
|
|
45
|
+
"url",
|
|
46
|
+
"tel",
|
|
47
|
+
])("accepts %s", async (type) => {
|
|
42
48
|
const page = render(Component, { ...baseProps, type });
|
|
43
49
|
await expect
|
|
44
50
|
.element(componentLocator(page))
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
export * from "./Badge/index.js";
|
|
2
|
+
export * from "./Breadcrumbs/index.js";
|
|
2
3
|
export * from "./Button/index.js";
|
|
3
4
|
export * from "./Checkbox/index.js";
|
|
4
5
|
export * from "./Chip/index.js";
|
|
6
|
+
export * from "./DateTime/index.js";
|
|
7
|
+
export * from "./DescriptionList/index.js";
|
|
8
|
+
export * from "./Link/index.js";
|
|
5
9
|
export * from "./NumberInput/index.js";
|
|
10
|
+
export * from "./Popover/index.js";
|
|
6
11
|
export * from "./Radio/index.js";
|
|
12
|
+
export * from "./RelativeDateTime/index.js";
|
|
7
13
|
export * from "./Spinner/index.js";
|
|
8
14
|
export * from "./Switch/index.js";
|
|
9
15
|
export * from "./Textarea/index.js";
|
package/dist/components/index.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
export * from "./Badge/index.js";
|
|
2
|
+
export * from "./Breadcrumbs/index.js";
|
|
2
3
|
export * from "./Button/index.js";
|
|
3
4
|
export * from "./Checkbox/index.js";
|
|
4
5
|
export * from "./Chip/index.js";
|
|
6
|
+
export * from "./DateTime/index.js";
|
|
7
|
+
export * from "./DescriptionList/index.js";
|
|
8
|
+
export * from "./Link/index.js";
|
|
5
9
|
export * from "./NumberInput/index.js";
|
|
10
|
+
export * from "./Popover/index.js";
|
|
6
11
|
export * from "./Radio/index.js";
|
|
12
|
+
export * from "./RelativeDateTime/index.js";
|
|
7
13
|
export * from "./Spinner/index.js";
|
|
8
14
|
export * from "./Switch/index.js";
|
|
9
15
|
export * from "./Textarea/index.js";
|
package/dist/index.css
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
.dense {
|
|
2
|
-
--lp-dimension-padding-block-context: var(
|
|
2
|
+
--lp-dimension-padding-block-context: var(
|
|
3
|
+
--lp-dimension-spacing-block-minimum
|
|
4
|
+
);
|
|
3
5
|
--lp-dimension-padding-inline-context: var(--lp-dimension-spacing-inline-s);
|
|
4
6
|
}
|
|
5
7
|
|
|
6
8
|
.compact {
|
|
7
|
-
--lp-dimension-padding-block-context: var(
|
|
9
|
+
--lp-dimension-padding-block-context: var(
|
|
10
|
+
--lp-dimension-spacing-block-minimum
|
|
11
|
+
);
|
|
8
12
|
--lp-dimension-padding-inline-context: var(--lp-dimension-spacing-inline-xs);
|
|
9
13
|
--lp-typography-context: var(--lp-typography-paragraph-s);
|
|
10
14
|
}
|
package/dist/styles/index.css
CHANGED
|
@@ -34,13 +34,10 @@ body {
|
|
|
34
34
|
border: 0;
|
|
35
35
|
padding: 0;
|
|
36
36
|
margin: 0;
|
|
37
|
-
position: absolute
|
|
37
|
+
position: absolute;
|
|
38
38
|
height: 1px;
|
|
39
39
|
width: 1px;
|
|
40
40
|
overflow: hidden;
|
|
41
|
-
clip: rect(
|
|
42
|
-
1px 1px 1px 1px
|
|
43
|
-
); /* IE6, IE7 - a 0 height clip, off to the bottom right of the visible 1px box */
|
|
44
41
|
clip: rect(
|
|
45
42
|
1px,
|
|
46
43
|
1px,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { userEvent } from "vitest/browser";
|
|
2
|
+
// macOS WebKit (Safari) requires Option+Tab to focus links;
|
|
3
|
+
// plain Tab only cycles form controls.
|
|
4
|
+
export const isWebkitMacOS = /Macintosh/.test(navigator.userAgent) &&
|
|
5
|
+
/AppleWebKit/.test(navigator.userAgent) &&
|
|
6
|
+
!/Chrome|Chromium|Firefox/.test(navigator.userAgent);
|
|
7
|
+
/**
|
|
8
|
+
* Presses Tab (or Option+Tab on macOS WebKit) to move focus to the next
|
|
9
|
+
* focusable element, including links.
|
|
10
|
+
*/
|
|
11
|
+
export async function tabToNextFocusable() {
|
|
12
|
+
if (isWebkitMacOS) {
|
|
13
|
+
await userEvent.keyboard("{Alt>}{Tab}{/Alt}");
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
await userEvent.tab();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ComputePositionConfig, ComputePositionReturn } from "@floating-ui/dom";
|
|
2
|
+
import type { Attachment } from "svelte/attachments";
|
|
3
|
+
export declare const positionAreaFallbackMap: {
|
|
4
|
+
readonly "block-start": "top";
|
|
5
|
+
readonly "block-end": "bottom";
|
|
6
|
+
readonly "block-start span-inline-start": "top-end";
|
|
7
|
+
readonly "block-start span-inline-end": "top-start";
|
|
8
|
+
readonly "block-end span-inline-start": "bottom-end";
|
|
9
|
+
readonly "block-end span-inline-end": "bottom-start";
|
|
10
|
+
readonly "inline-start": "left";
|
|
11
|
+
readonly "inline-end": "right";
|
|
12
|
+
readonly "inline-start span-block-start": "left-end";
|
|
13
|
+
readonly "inline-start span-block-end": "left-start";
|
|
14
|
+
readonly "inline-end span-block-start": "right-end";
|
|
15
|
+
readonly "inline-end span-block-end": "right-start";
|
|
16
|
+
};
|
|
17
|
+
export type PositionArea = keyof typeof positionAreaFallbackMap;
|
|
18
|
+
/**
|
|
19
|
+
* A subset of `position-try-fallbacks` values that should cover the most common fallback strategies.
|
|
20
|
+
*/
|
|
21
|
+
export type PositionTryFallbacks = "flip-inline" | "flip-block" | "flip-inline flip-block" | "flip-inline, flip-block" | "flip-block, flip-inline" | "flip-inline, flip-inline flip-block" | "flip-block, flip-inline flip-block" | "flip-inline, flip-block, flip-inline flip-block" | "flip-block, flip-inline, flip-inline flip-block";
|
|
22
|
+
/**
|
|
23
|
+
* Allows to position a floating target relative to a trigger using CSS `position-area` when available, and automatically falls back to Floating UI when unsupported.
|
|
24
|
+
*
|
|
25
|
+
* Usage:
|
|
26
|
+
* - Attach `triggerAttachment` to the trigger element and `targetAttachment` to the target element you wish to position.
|
|
27
|
+
* - Provide the style returned by `targetStyle()` to the target element.
|
|
28
|
+
* - Control activation via `getActive()`, the desired placement via `getPosition()` and optionally position fallback behavior via `getTryFallbacks()`.
|
|
29
|
+
*
|
|
30
|
+
* @param getPosition - Returns the desired position-area value.
|
|
31
|
+
* @param getActive - Returns whether positioning should be active.
|
|
32
|
+
* @param getTryFallbacks - Optionally returns a position-try-fallbacks value.
|
|
33
|
+
* @returns Attachments to be applied to the trigger and target elements and the target style getter.
|
|
34
|
+
*/
|
|
35
|
+
export declare function usePositionArea(getPosition: () => PositionArea, getActive: () => boolean, getTryFallbacks?: () => PositionTryFallbacks | undefined): {
|
|
36
|
+
triggerAttachment: Attachment<HTMLElement>;
|
|
37
|
+
targetAttachment: Attachment<HTMLElement>;
|
|
38
|
+
targetStyle: () => string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Helper around Floating UI to compute and update the position of a floating target relative to a trigger element.
|
|
42
|
+
*
|
|
43
|
+
* It wires up `autoUpdate`, calls `computePosition` on updates, and forwards the result to the provided callback.
|
|
44
|
+
*
|
|
45
|
+
* Usage:
|
|
46
|
+
* - Attach `triggerAttachment` to the trigger element and `targetAttachment` to the target element you wish to position.
|
|
47
|
+
* - Control activation via `getActive()` and supply options via `getOptions()`.
|
|
48
|
+
*
|
|
49
|
+
* @param getActive - Returns whether positioning should be active.
|
|
50
|
+
* @param getOptions - Supplies options for `computePosition`. If `undefined`, defaults will be used.
|
|
51
|
+
* @param callback - Invoked with the latest computed position.
|
|
52
|
+
* @returns Attachments to be applied to the trigger and target elements.
|
|
53
|
+
*/
|
|
54
|
+
export declare function useFloatingUI(getActive: () => boolean, getOptions: () => Partial<ComputePositionConfig> | undefined, callback: (value: ComputePositionReturn) => void): {
|
|
55
|
+
triggerAttachment: Attachment<HTMLElement>;
|
|
56
|
+
targetAttachment: Attachment<HTMLElement>;
|
|
57
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { autoUpdate, computePosition, flip } from "@floating-ui/dom";
|
|
2
|
+
import { useIsMounted } from "./useIsMounted.svelte.js";
|
|
3
|
+
export const positionAreaFallbackMap = {
|
|
4
|
+
/*
|
|
5
|
+
|
|
6
|
+
+---+---+---+
|
|
7
|
+
| 1 | 2 | 3 |
|
|
8
|
+
+---+---+---+
|
|
9
|
+
| 4 | | 5 |
|
|
10
|
+
+---+---+---+
|
|
11
|
+
| 6 | 7 | 8 |
|
|
12
|
+
+---+---+---+
|
|
13
|
+
|
|
14
|
+
*/
|
|
15
|
+
"block-start": "top", // spans 1, 2, 3
|
|
16
|
+
"block-end": "bottom", // spans 6, 7, 8
|
|
17
|
+
"block-start span-inline-start": "top-end", // spans 1, 2
|
|
18
|
+
"block-start span-inline-end": "top-start", // spans 2, 3
|
|
19
|
+
"block-end span-inline-start": "bottom-end", // spans 6, 7
|
|
20
|
+
"block-end span-inline-end": "bottom-start", // spans 7, 8
|
|
21
|
+
"inline-start": "left", // spans 1, 4, 6
|
|
22
|
+
"inline-end": "right", // spans 3, 5, 8
|
|
23
|
+
"inline-start span-block-start": "left-end", // spans 1, 4
|
|
24
|
+
"inline-start span-block-end": "left-start", // spans 4, 6
|
|
25
|
+
"inline-end span-block-start": "right-end", // spans 3, 5
|
|
26
|
+
"inline-end span-block-end": "right-start", // spans 5, 8
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Allows to position a floating target relative to a trigger using CSS `position-area` when available, and automatically falls back to Floating UI when unsupported.
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* - Attach `triggerAttachment` to the trigger element and `targetAttachment` to the target element you wish to position.
|
|
33
|
+
* - Provide the style returned by `targetStyle()` to the target element.
|
|
34
|
+
* - Control activation via `getActive()`, the desired placement via `getPosition()` and optionally position fallback behavior via `getTryFallbacks()`.
|
|
35
|
+
*
|
|
36
|
+
* @param getPosition - Returns the desired position-area value.
|
|
37
|
+
* @param getActive - Returns whether positioning should be active.
|
|
38
|
+
* @param getTryFallbacks - Optionally returns a position-try-fallbacks value.
|
|
39
|
+
* @returns Attachments to be applied to the trigger and target elements and the target style getter.
|
|
40
|
+
*/
|
|
41
|
+
export function usePositionArea(getPosition, getActive, getTryFallbacks) {
|
|
42
|
+
const isMounted = useIsMounted();
|
|
43
|
+
const needsFallback = $derived.by(() => {
|
|
44
|
+
if (!isMounted.value)
|
|
45
|
+
return false;
|
|
46
|
+
const position = getPosition();
|
|
47
|
+
const tryFallback = getTryFallbacks?.();
|
|
48
|
+
return (!CSS.supports("position-area", position) ||
|
|
49
|
+
// Some versions of Firefox and Chrome seem to report support for `inline-start` and `inline-end`, but they don't actually position the element properly. For now, force the fallback for these values.
|
|
50
|
+
position.startsWith("inline") ||
|
|
51
|
+
(tryFallback !== undefined &&
|
|
52
|
+
!CSS.supports("position-try-fallbacks", tryFallback)));
|
|
53
|
+
});
|
|
54
|
+
const isFloatingUiActive = $derived(needsFallback && getActive());
|
|
55
|
+
const floatingUIConfig = $derived.by(() => {
|
|
56
|
+
const position = getPosition();
|
|
57
|
+
const tryFallback = getTryFallbacks?.();
|
|
58
|
+
if (!tryFallback) {
|
|
59
|
+
return {
|
|
60
|
+
placement: positionAreaFallbackMap[position],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const crossAxis = (position.startsWith("block") && tryFallback.includes("flip-inline")) ||
|
|
64
|
+
(position.startsWith("inline") && tryFallback.includes("flip-block"));
|
|
65
|
+
return {
|
|
66
|
+
placement: positionAreaFallbackMap[position],
|
|
67
|
+
middleware: [
|
|
68
|
+
// This doesn't 100% match the native CSS behavior, but should be close enough for most use cases.
|
|
69
|
+
flip({
|
|
70
|
+
mainAxis: (position.startsWith("block") &&
|
|
71
|
+
tryFallback.includes("flip-block")) ||
|
|
72
|
+
(position.startsWith("inline") &&
|
|
73
|
+
tryFallback.includes("flip-inline")),
|
|
74
|
+
crossAxis,
|
|
75
|
+
flipAlignment: crossAxis,
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
let fallbackPosition = $state({ x: 0, y: 0 });
|
|
81
|
+
const { triggerAttachment, targetAttachment } = useFloatingUI(() => isFloatingUiActive, () => floatingUIConfig, ({ x, y }) => {
|
|
82
|
+
fallbackPosition = { x, y };
|
|
83
|
+
});
|
|
84
|
+
const targetStyle = $derived.by(() => {
|
|
85
|
+
if (needsFallback) {
|
|
86
|
+
return `position: absolute; left: ${fallbackPosition.x}px; top: ${fallbackPosition.y}px;`;
|
|
87
|
+
}
|
|
88
|
+
const tryFallback = getTryFallbacks?.();
|
|
89
|
+
return `position-area: ${getPosition()};${tryFallback ? ` position-try-fallbacks: ${tryFallback};` : ""}`;
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
triggerAttachment,
|
|
93
|
+
targetAttachment,
|
|
94
|
+
targetStyle: () => targetStyle,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Helper around Floating UI to compute and update the position of a floating target relative to a trigger element.
|
|
99
|
+
*
|
|
100
|
+
* It wires up `autoUpdate`, calls `computePosition` on updates, and forwards the result to the provided callback.
|
|
101
|
+
*
|
|
102
|
+
* Usage:
|
|
103
|
+
* - Attach `triggerAttachment` to the trigger element and `targetAttachment` to the target element you wish to position.
|
|
104
|
+
* - Control activation via `getActive()` and supply options via `getOptions()`.
|
|
105
|
+
*
|
|
106
|
+
* @param getActive - Returns whether positioning should be active.
|
|
107
|
+
* @param getOptions - Supplies options for `computePosition`. If `undefined`, defaults will be used.
|
|
108
|
+
* @param callback - Invoked with the latest computed position.
|
|
109
|
+
* @returns Attachments to be applied to the trigger and target elements.
|
|
110
|
+
*/
|
|
111
|
+
export function useFloatingUI(getActive, getOptions, callback) {
|
|
112
|
+
let triggerRef = $state();
|
|
113
|
+
let targetRef = $state();
|
|
114
|
+
const triggerAttachment = (node) => {
|
|
115
|
+
triggerRef = node;
|
|
116
|
+
return () => (triggerRef = undefined);
|
|
117
|
+
};
|
|
118
|
+
const targetAttachment = (node) => {
|
|
119
|
+
targetRef = node;
|
|
120
|
+
return () => (targetRef = undefined);
|
|
121
|
+
};
|
|
122
|
+
$effect(() => {
|
|
123
|
+
if (!getActive())
|
|
124
|
+
return;
|
|
125
|
+
if (!triggerRef || !targetRef)
|
|
126
|
+
return;
|
|
127
|
+
const options = getOptions();
|
|
128
|
+
const cleanup = autoUpdate(triggerRef, targetRef, () => {
|
|
129
|
+
if (!triggerRef || !targetRef)
|
|
130
|
+
return;
|
|
131
|
+
computePosition(triggerRef, targetRef, options)
|
|
132
|
+
.then(callback)
|
|
133
|
+
.catch(() => {
|
|
134
|
+
// Swallow errors from computePosition to avoid unhandled promise rejections.
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
return () => {
|
|
138
|
+
cleanup();
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
return {
|
|
142
|
+
triggerAttachment,
|
|
143
|
+
targetAttachment,
|
|
144
|
+
};
|
|
145
|
+
}
|
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.20.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"import": "./dist/index.js",
|
|
12
12
|
"svelte": "./dist/index.js"
|
|
13
13
|
},
|
|
14
|
-
"./styles.css": "./
|
|
14
|
+
"./styles.css": "./dist/index.css"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
@@ -51,34 +51,35 @@
|
|
|
51
51
|
"storybook": "storybook dev -p 6006 --no-open --host 0.0.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@biomejs/biome": "2.4.
|
|
55
|
-
"@canonical/biome-config
|
|
56
|
-
"@canonical/storybook-helpers": "^0.
|
|
57
|
-
"@canonical/svelte-ssr-test": "^0.
|
|
58
|
-
"@canonical/typescript-config-svelte": "^0.
|
|
59
|
-
"@canonical/webarchitect": "^0.
|
|
60
|
-
"@storybook/addon-docs": "^10.
|
|
61
|
-
"@storybook/addon-svelte-csf": "^5.0.
|
|
54
|
+
"@biomejs/biome": "2.4.6",
|
|
55
|
+
"@canonical/biome-config": "^0.20.0",
|
|
56
|
+
"@canonical/storybook-helpers": "^0.20.0",
|
|
57
|
+
"@canonical/svelte-ssr-test": "^0.20.0",
|
|
58
|
+
"@canonical/typescript-config-svelte": "^0.20.0",
|
|
59
|
+
"@canonical/webarchitect": "^0.20.0",
|
|
60
|
+
"@storybook/addon-docs": "^10.3.1",
|
|
61
|
+
"@storybook/addon-svelte-csf": "^5.0.11",
|
|
62
62
|
"@sveltejs/package": "^2.5.7",
|
|
63
63
|
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
|
64
|
-
"@types/bun": "^1.3.
|
|
64
|
+
"@types/bun": "^1.3.10",
|
|
65
65
|
"@vitest/browser": "^4.0.18",
|
|
66
66
|
"@vitest/browser-playwright": "^4.0.18",
|
|
67
67
|
"playwright": "^1.58.2",
|
|
68
|
-
"storybook": "^10.
|
|
69
|
-
"svelte-check": "^4.
|
|
68
|
+
"storybook": "^10.3.1",
|
|
69
|
+
"svelte-check": "^4.4.5",
|
|
70
70
|
"typescript": "^5.9.3",
|
|
71
|
-
"vite": "^
|
|
71
|
+
"vite": "^8.0.1",
|
|
72
72
|
"vitest": "^4.0.18",
|
|
73
73
|
"vitest-browser-svelte": "^2.0.2"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@canonical/launchpad-design-tokens": "^1.0.23",
|
|
77
|
-
"@canonical/storybook-config": "^0.
|
|
78
|
-
"@canonical/svelte-icons": "^0.0.9"
|
|
77
|
+
"@canonical/storybook-config": "^0.20.0",
|
|
78
|
+
"@canonical/svelte-icons": "^0.0.9",
|
|
79
|
+
"@floating-ui/dom": "^1.7.6"
|
|
79
80
|
},
|
|
80
81
|
"peerDependencies": {
|
|
81
82
|
"svelte": "^5.47.1"
|
|
82
83
|
},
|
|
83
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "1aee634b278922f2aa1cfe2a11d3b14e64280905"
|
|
84
85
|
}
|