@canonical/svelte-ds-app-launchpad 0.15.1 → 0.16.0-experimental.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/dist/components/Badge/Badge.ssr.test.js +113 -0
- package/dist/components/Badge/Badge.stories.svelte +60 -0
- package/dist/components/Badge/Badge.stories.svelte.d.ts +19 -0
- package/dist/components/Badge/Badge.svelte +49 -0
- package/dist/components/Badge/Badge.svelte.d.ts +14 -0
- package/dist/components/Badge/Badge.svelte.test.js +120 -0
- package/dist/components/Badge/index.d.ts +2 -0
- package/dist/components/Badge/index.js +2 -0
- package/dist/components/Badge/styles.css +12 -0
- package/dist/components/Badge/types.d.ts +15 -0
- package/dist/components/Badge/types.js +1 -0
- package/dist/components/Button/Button.ssr.test.d.ts +1 -0
- package/dist/components/Button/Button.ssr.test.js +88 -0
- package/dist/components/Button/Button.stories.svelte +143 -0
- package/dist/components/Button/Button.stories.svelte.d.ts +19 -0
- package/dist/components/Button/Button.svelte +63 -0
- package/dist/components/Button/Button.svelte.d.ts +21 -0
- package/dist/components/Button/Button.svelte.test.d.ts +1 -0
- package/dist/components/Button/Button.svelte.test.js +150 -0
- package/dist/components/Button/common/Content/Content.svelte +30 -0
- package/dist/components/Button/common/Content/Content.svelte.d.ts +5 -0
- package/dist/components/Button/common/Content/index.d.ts +2 -0
- package/dist/components/Button/common/Content/index.js +1 -0
- package/dist/components/Button/common/Content/styles.css +60 -0
- package/dist/components/Button/common/Content/types.d.ts +8 -0
- package/dist/components/Button/common/Content/types.js +1 -0
- package/dist/components/Button/index.d.ts +2 -0
- package/dist/components/Button/index.js +2 -0
- package/dist/components/Button/styles.css +73 -0
- package/dist/components/Button/types.d.ts +10 -0
- package/dist/components/Button/types.js +1 -0
- package/dist/components/Checkbox/Checkbox.ssr.test.d.ts +1 -0
- package/dist/components/Checkbox/Checkbox.ssr.test.js +74 -0
- package/dist/components/Checkbox/Checkbox.stories.svelte +105 -0
- package/dist/components/Checkbox/Checkbox.stories.svelte.d.ts +19 -0
- package/dist/components/Checkbox/Checkbox.svelte +74 -0
- package/dist/components/Checkbox/Checkbox.svelte.d.ts +60 -0
- package/dist/components/Checkbox/Checkbox.svelte.test.d.ts +1 -0
- package/dist/components/Checkbox/Checkbox.svelte.test.js +116 -0
- package/dist/components/Checkbox/index.d.ts +2 -0
- package/dist/components/Checkbox/index.js +1 -0
- package/dist/components/Checkbox/styles.css +63 -0
- package/dist/components/Checkbox/types.d.ts +16 -0
- package/dist/components/Checkbox/types.js +1 -0
- package/dist/components/Chip/Chip.ssr.test.d.ts +1 -0
- package/dist/components/Chip/Chip.ssr.test.js +65 -0
- package/dist/components/Chip/Chip.stories.svelte +123 -0
- package/dist/components/Chip/Chip.stories.svelte.d.ts +19 -0
- package/dist/components/Chip/Chip.svelte +85 -0
- package/dist/components/Chip/Chip.svelte.d.ts +22 -0
- package/dist/components/Chip/Chip.svelte.test.d.ts +1 -0
- package/dist/components/Chip/Chip.svelte.test.js +116 -0
- package/dist/components/Chip/index.d.ts +2 -0
- package/dist/components/Chip/index.js +2 -0
- package/dist/components/Chip/styles.css +89 -0
- package/dist/components/Chip/types.d.ts +29 -0
- package/dist/components/Chip/types.js +1 -0
- package/dist/components/NumberInput/NumberInput.ssr.test.d.ts +1 -0
- package/dist/components/NumberInput/NumberInput.ssr.test.js +84 -0
- package/dist/components/NumberInput/NumberInput.stories.svelte +67 -0
- package/dist/components/NumberInput/NumberInput.stories.svelte.d.ts +4 -0
- package/dist/components/NumberInput/NumberInput.svelte +36 -0
- package/dist/components/NumberInput/NumberInput.svelte.d.ts +18 -0
- package/dist/components/NumberInput/NumberInput.svelte.test.d.ts +1 -0
- package/dist/components/NumberInput/NumberInput.svelte.test.js +96 -0
- package/dist/components/NumberInput/index.d.ts +2 -0
- package/dist/components/NumberInput/index.js +2 -0
- package/dist/components/NumberInput/styles.css +26 -0
- package/dist/components/NumberInput/types.d.ts +5 -0
- package/dist/components/NumberInput/types.js +1 -0
- package/dist/components/Radio/Radio.ssr.test.d.ts +1 -0
- package/dist/components/Radio/Radio.ssr.test.js +75 -0
- package/dist/components/Radio/Radio.stories.svelte +93 -0
- package/dist/components/Radio/Radio.stories.svelte.d.ts +19 -0
- package/dist/components/Radio/Radio.svelte +69 -0
- package/dist/components/Radio/Radio.svelte.d.ts +64 -0
- package/dist/components/Radio/Radio.svelte.test.d.ts +1 -0
- package/dist/components/Radio/Radio.svelte.test.js +101 -0
- package/dist/components/Radio/index.d.ts +2 -0
- package/dist/components/Radio/index.js +1 -0
- package/dist/components/Radio/styles.css +42 -0
- package/dist/components/Radio/types.d.ts +16 -0
- package/dist/components/Radio/types.js +1 -0
- package/dist/components/Spinner/Spinner.ssr.test.d.ts +1 -0
- package/dist/components/Spinner/Spinner.ssr.test.js +29 -0
- package/dist/components/Spinner/Spinner.stories.svelte +16 -0
- package/dist/components/{Example/Example.stories.svelte.d.ts → Spinner/Spinner.stories.svelte.d.ts} +4 -4
- package/dist/components/Spinner/Spinner.svelte +25 -0
- package/dist/components/Spinner/Spinner.svelte.d.ts +13 -0
- package/dist/components/Spinner/Spinner.svelte.test.d.ts +1 -0
- package/dist/components/Spinner/Spinner.svelte.test.js +29 -0
- package/dist/components/Spinner/index.d.ts +2 -0
- package/dist/components/Spinner/index.js +2 -0
- package/dist/components/Spinner/styles.css +14 -0
- package/dist/components/Spinner/types.d.ts +2 -0
- package/dist/components/Spinner/types.js +1 -0
- package/dist/components/Switch/Switch.ssr.test.d.ts +1 -0
- package/dist/components/Switch/Switch.ssr.test.js +99 -0
- package/dist/components/Switch/Switch.stories.svelte +93 -0
- package/dist/components/Switch/Switch.stories.svelte.d.ts +19 -0
- package/dist/components/Switch/Switch.svelte +89 -0
- package/dist/components/Switch/Switch.svelte.d.ts +65 -0
- package/dist/components/Switch/Switch.svelte.test.d.ts +1 -0
- package/dist/components/Switch/Switch.svelte.test.js +144 -0
- package/dist/components/Switch/index.d.ts +2 -0
- package/dist/components/Switch/index.js +1 -0
- package/dist/components/Switch/styles.css +41 -0
- package/dist/components/Switch/types.d.ts +16 -0
- package/dist/components/Switch/types.js +1 -0
- package/dist/components/TextInput/TextInput.ssr.test.d.ts +1 -0
- package/dist/components/TextInput/TextInput.ssr.test.js +85 -0
- package/dist/components/TextInput/TextInput.stories.svelte +96 -0
- package/dist/components/TextInput/TextInput.stories.svelte.d.ts +4 -0
- package/dist/components/TextInput/TextInput.svelte +21 -0
- package/dist/components/TextInput/TextInput.svelte.d.ts +5 -0
- package/dist/components/TextInput/TextInput.svelte.test.d.ts +1 -0
- package/dist/components/TextInput/TextInput.svelte.test.js +112 -0
- package/dist/components/TextInput/index.d.ts +2 -0
- package/dist/components/TextInput/index.js +2 -0
- package/dist/components/TextInput/styles.css +26 -0
- package/dist/components/TextInput/types.d.ts +5 -0
- package/dist/components/TextInput/types.js +1 -0
- package/dist/components/Textarea/Textarea.ssr.test.d.ts +1 -0
- package/dist/components/{Example/Example.ssr.test.js → Textarea/Textarea.ssr.test.js} +18 -17
- package/dist/components/Textarea/Textarea.stories.svelte +58 -0
- package/dist/components/Textarea/Textarea.stories.svelte.d.ts +19 -0
- package/dist/components/Textarea/Textarea.svelte +38 -0
- package/dist/components/Textarea/Textarea.svelte.d.ts +5 -0
- package/dist/components/Textarea/Textarea.svelte.test.d.ts +1 -0
- package/dist/components/Textarea/Textarea.svelte.test.js +90 -0
- package/dist/components/Textarea/index.d.ts +2 -0
- package/dist/components/Textarea/index.js +2 -0
- package/dist/components/Textarea/styles.css +62 -0
- package/dist/components/Textarea/types.d.ts +23 -0
- package/dist/components/Textarea/types.js +1 -0
- package/dist/components/Textarea/utils/calculateDynamicRows.d.ts +6 -0
- package/dist/components/Textarea/utils/calculateDynamicRows.js +36 -0
- package/dist/components/Textarea/utils/calculateDynamicRows.svelte.test.d.ts +1 -0
- package/dist/components/Textarea/utils/calculateDynamicRows.svelte.test.js +148 -0
- package/dist/components/Textarea/utils/index.d.ts +1 -0
- package/dist/components/Textarea/utils/index.js +1 -0
- package/dist/components/common/ButtonPrimitive/ButtonPrimitive.ssr.test.d.ts +1 -0
- package/dist/components/common/ButtonPrimitive/ButtonPrimitive.ssr.test.js +71 -0
- package/dist/components/common/ButtonPrimitive/ButtonPrimitive.svelte +43 -0
- package/dist/components/common/ButtonPrimitive/ButtonPrimitive.svelte.d.ts +5 -0
- package/dist/components/common/ButtonPrimitive/ButtonPrimitive.svelte.test.d.ts +1 -0
- package/dist/components/common/ButtonPrimitive/ButtonPrimitive.svelte.test.js +77 -0
- package/dist/components/common/ButtonPrimitive/index.d.ts +2 -0
- package/dist/components/common/ButtonPrimitive/index.js +2 -0
- package/dist/components/common/ButtonPrimitive/styles.css +47 -0
- package/dist/components/common/ButtonPrimitive/types.d.ts +5 -0
- package/dist/components/common/ButtonPrimitive/types.js +1 -0
- package/dist/components/common/InputPrimitive/InputPrimitive.ssr.test.d.ts +1 -0
- package/dist/components/common/InputPrimitive/InputPrimitive.ssr.test.js +95 -0
- package/dist/components/common/InputPrimitive/InputPrimitive.svelte +22 -0
- package/dist/components/common/InputPrimitive/InputPrimitive.svelte.d.ts +5 -0
- package/dist/components/common/InputPrimitive/InputPrimitive.svelte.test.d.ts +1 -0
- package/dist/components/common/InputPrimitive/InputPrimitive.svelte.test.js +85 -0
- package/dist/components/common/InputPrimitive/index.d.ts +2 -0
- package/dist/components/common/InputPrimitive/index.js +2 -0
- package/dist/components/common/InputPrimitive/styles.css +69 -0
- package/dist/components/common/InputPrimitive/types.d.ts +14 -0
- package/dist/components/common/InputPrimitive/types.js +1 -0
- package/dist/components/common/index.d.ts +2 -0
- package/dist/components/common/index.js +2 -0
- package/dist/components/index.d.ts +10 -1
- package/dist/components/index.js +10 -1
- package/dist/index.css +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/modifier-families/constants.d.ts +4 -0
- package/dist/modifier-families/constants.js +4 -0
- package/dist/modifier-families/index.d.ts +2 -0
- package/dist/modifier-families/index.js +1 -0
- package/dist/modifier-families/styles/density.css +10 -0
- package/dist/modifier-families/styles/index.css +2 -0
- package/dist/modifier-families/styles/severity.css +87 -0
- package/dist/modifier-families/types.d.ts +26 -0
- package/dist/modifier-families/types.js +1 -0
- package/dist/styles/font-faces.css +26 -0
- package/dist/styles/index.css +73 -0
- package/dist/styles/reset.css +19 -0
- package/dist/useIsMounted.svelte.d.ts +3 -0
- package/dist/useIsMounted.svelte.js +12 -0
- package/package.json +13 -11
- package/dist/components/Example/Example.stories.svelte +0 -12
- package/dist/components/Example/Example.svelte +0 -62
- package/dist/components/Example/Example.svelte.d.ts +0 -12
- package/dist/components/Example/Example.svelte.test.js +0 -42
- package/dist/components/Example/index.d.ts +0 -2
- package/dist/components/Example/index.js +0 -3
- package/dist/components/Example/types.d.ts +0 -5
- package/dist/components/Example/types.js +0 -2
- /package/dist/components/{Example/Example.ssr.test.d.ts → Badge/Badge.ssr.test.d.ts} +0 -0
- /package/dist/components/{Example/Example.svelte.test.d.ts → Badge/Badge.svelte.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -10,14 +10,28 @@ Launchpad-specific components for the Pragma design system. This package provide
|
|
|
10
10
|
bun add @canonical/svelte-ds-app-launchpad
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
Import the main styles in your project's layout file (e.g. `routes/+layout.svelte`):
|
|
14
|
+
|
|
15
|
+
```svelte
|
|
16
|
+
<script lang="ts">
|
|
17
|
+
import "@canonical/svelte-ds-app-launchpad/styles.css";
|
|
18
|
+
|
|
19
|
+
import "@canonical/launchpad-design-tokens/dist/css/dimension/responsive.css";
|
|
20
|
+
import "@canonical/launchpad-design-tokens/dist/css/typography/responsive.css";
|
|
21
|
+
import "@canonical/launchpad-design-tokens/dist/css/opacity/opacity.css";
|
|
22
|
+
import "@canonical/launchpad-design-tokens/dist/css/transition/preferred.css";
|
|
23
|
+
import "@canonical/launchpad-design-tokens/dist/css/color/light.css"; // dark.css or system.css
|
|
24
|
+
</script>
|
|
25
|
+
```
|
|
26
|
+
|
|
13
27
|
## Usage
|
|
14
28
|
|
|
15
29
|
```typescript
|
|
16
30
|
<script lang="ts">
|
|
17
|
-
import {
|
|
31
|
+
import { Chip } from "@canonical/svelte-ds-app-launchpad";
|
|
18
32
|
</script>
|
|
19
33
|
|
|
20
|
-
<
|
|
34
|
+
<Chip lead="Hello" value="world!" />
|
|
21
35
|
```
|
|
22
36
|
|
|
23
37
|
## Development
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Generated by @canonical/summon:component-svelte v0.1.0
|
|
2
|
+
import { render } from "@canonical/svelte-ssr-test";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import Component from "./Badge.svelte";
|
|
5
|
+
describe("Badge SSR", () => {
|
|
6
|
+
const baseProps = {
|
|
7
|
+
value: 42,
|
|
8
|
+
"data-testid": "badge",
|
|
9
|
+
};
|
|
10
|
+
describe("basics", () => {
|
|
11
|
+
it("doesn't throw", () => {
|
|
12
|
+
expect(() => {
|
|
13
|
+
render(Component, { props: { ...baseProps } });
|
|
14
|
+
}).not.toThrow();
|
|
15
|
+
});
|
|
16
|
+
it("renders", () => {
|
|
17
|
+
const page = render(Component, { props: { ...baseProps } });
|
|
18
|
+
expect(componentLocator(page)).toBeInstanceOf(page.window.HTMLSpanElement);
|
|
19
|
+
expect(componentLocator(page).textContent).toContain("42");
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe("attributes", () => {
|
|
23
|
+
it.each([
|
|
24
|
+
["id", "test-id"],
|
|
25
|
+
["aria-label", "test-aria-label"],
|
|
26
|
+
])("applies %s", (attribute, expected) => {
|
|
27
|
+
const page = render(Component, {
|
|
28
|
+
props: { ...baseProps, [attribute]: expected },
|
|
29
|
+
});
|
|
30
|
+
expect(componentLocator(page).getAttribute(attribute)).toBe(expected);
|
|
31
|
+
});
|
|
32
|
+
it("applies classes", () => {
|
|
33
|
+
const page = render(Component, {
|
|
34
|
+
props: { ...baseProps, class: "test-class" },
|
|
35
|
+
});
|
|
36
|
+
expect(componentLocator(page).classList).toContain("test-class");
|
|
37
|
+
expect(componentLocator(page).classList).toContain("ds");
|
|
38
|
+
expect(componentLocator(page).classList).toContain("badge");
|
|
39
|
+
});
|
|
40
|
+
it("applies style", () => {
|
|
41
|
+
const page = render(Component, {
|
|
42
|
+
props: { ...baseProps, style: "color: orange;" },
|
|
43
|
+
});
|
|
44
|
+
expect(componentLocator(page).style.color).toBe("orange");
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe("Display value", () => {
|
|
48
|
+
it("displays the capped variant by default", () => {
|
|
49
|
+
const page = render(Component, {
|
|
50
|
+
props: { ...baseProps, value: 10000 },
|
|
51
|
+
});
|
|
52
|
+
expect(componentLocator(page).textContent).toBe("999+");
|
|
53
|
+
});
|
|
54
|
+
describe("capped", () => {
|
|
55
|
+
it("displays 0 for negative values", () => {
|
|
56
|
+
const page = render(Component, {
|
|
57
|
+
props: { ...baseProps, value: -1, variant: "capped" },
|
|
58
|
+
});
|
|
59
|
+
expect(componentLocator(page).textContent).toBe("0");
|
|
60
|
+
});
|
|
61
|
+
it("rounds to the nearest integer", () => {
|
|
62
|
+
const page = render(Component, {
|
|
63
|
+
props: { ...baseProps, value: 42.6, variant: "capped" },
|
|
64
|
+
});
|
|
65
|
+
expect(componentLocator(page).textContent).toBe("43");
|
|
66
|
+
});
|
|
67
|
+
it("displays the values up to 999", () => {
|
|
68
|
+
const page = render(Component, {
|
|
69
|
+
props: { ...baseProps, value: 999, variant: "capped" },
|
|
70
|
+
});
|
|
71
|
+
expect(componentLocator(page).textContent).toBe("999");
|
|
72
|
+
});
|
|
73
|
+
it("caps the value at 999", () => {
|
|
74
|
+
const page = render(Component, {
|
|
75
|
+
props: { ...baseProps, value: 10000, variant: "capped" },
|
|
76
|
+
});
|
|
77
|
+
expect(componentLocator(page).textContent).toBe("999+");
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
describe("rounded", () => {
|
|
81
|
+
it("displays 0 for negative values", () => {
|
|
82
|
+
const page = render(Component, {
|
|
83
|
+
props: { ...baseProps, value: -1, variant: "rounded" },
|
|
84
|
+
});
|
|
85
|
+
expect(componentLocator(page).textContent).toBe("0");
|
|
86
|
+
});
|
|
87
|
+
it("rounds to the nearest integer", () => {
|
|
88
|
+
const page = render(Component, {
|
|
89
|
+
props: { ...baseProps, value: 42.6, variant: "rounded" },
|
|
90
|
+
});
|
|
91
|
+
expect(componentLocator(page).textContent).toBe("43");
|
|
92
|
+
});
|
|
93
|
+
it.each([
|
|
94
|
+
[0, "0"],
|
|
95
|
+
[42.6, "43"],
|
|
96
|
+
[999, "999"],
|
|
97
|
+
[1_000, "1K"],
|
|
98
|
+
[1_500, "1.5K"],
|
|
99
|
+
[2_500_000, "2.5M"],
|
|
100
|
+
[1_000_000_000, "1B"],
|
|
101
|
+
[1_234_567_890_123, "1.2T"],
|
|
102
|
+
])("displays %d as %s", (input, expected) => {
|
|
103
|
+
const page = render(Component, {
|
|
104
|
+
props: { ...baseProps, value: input, variant: "rounded" },
|
|
105
|
+
});
|
|
106
|
+
expect(componentLocator(page).textContent).toBe(expected);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
function componentLocator(page) {
|
|
112
|
+
return page.getByTestId("badge");
|
|
113
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
// Generated by @canonical/summon:component-svelte v0.1.0
|
|
3
|
+
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
4
|
+
import { MODIFIER_FAMILIES } from "../../modifier-families";
|
|
5
|
+
import Badge from "./Badge.svelte";
|
|
6
|
+
|
|
7
|
+
const { Story } = defineMeta({
|
|
8
|
+
title: "Components/Badge",
|
|
9
|
+
component: Badge,
|
|
10
|
+
tags: ["autodocs"],
|
|
11
|
+
argTypes: {
|
|
12
|
+
value: { control: { type: "number", min: 0, step: 1 } },
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<Story name="Default" args={{ value: 42 }} />
|
|
18
|
+
|
|
19
|
+
<Story
|
|
20
|
+
name="Capped"
|
|
21
|
+
argTypes={{ value: { table: { disable: true } } }}
|
|
22
|
+
args={{ variant: "capped" }}
|
|
23
|
+
>
|
|
24
|
+
{#snippet template(args)}
|
|
25
|
+
<div class="row">
|
|
26
|
+
{#each [0, 42, 999, 2100] as value (value)}
|
|
27
|
+
<Badge {...args} {value} />
|
|
28
|
+
{/each}
|
|
29
|
+
</div>
|
|
30
|
+
{/snippet}
|
|
31
|
+
</Story>
|
|
32
|
+
|
|
33
|
+
<Story
|
|
34
|
+
name="Rounded"
|
|
35
|
+
argTypes={{ value: { table: { disable: true } } }}
|
|
36
|
+
args={{ variant: "rounded" }}
|
|
37
|
+
>
|
|
38
|
+
{#snippet template(args)}
|
|
39
|
+
<div class="row">
|
|
40
|
+
{#each [0, 42, 999, 2100, 10_000, 251_110, 8_899_500, 1_111_111_111, 98_123_456_789_890] as value (value)}
|
|
41
|
+
<Badge {...args} {value} />
|
|
42
|
+
{/each}
|
|
43
|
+
</div>
|
|
44
|
+
{/snippet}
|
|
45
|
+
</Story>
|
|
46
|
+
|
|
47
|
+
<Story
|
|
48
|
+
name="Severities"
|
|
49
|
+
argTypes={{ severity: { table: { disable: true } } }}
|
|
50
|
+
args={{ value: 42 }}
|
|
51
|
+
>
|
|
52
|
+
{#snippet template(args)}
|
|
53
|
+
{#each MODIFIER_FAMILIES.severity as severity (severity)}
|
|
54
|
+
<div class="row">
|
|
55
|
+
<Badge {...args} {severity} />
|
|
56
|
+
{severity || "default"}
|
|
57
|
+
</div>
|
|
58
|
+
{/each}
|
|
59
|
+
{/snippet}
|
|
60
|
+
</Story>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Badge from "./Badge.svelte";
|
|
2
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
+
$$bindings?: Bindings;
|
|
5
|
+
} & Exports;
|
|
6
|
+
(internal: unknown, props: {
|
|
7
|
+
$$events?: Events;
|
|
8
|
+
$$slots?: Slots;
|
|
9
|
+
}): Exports & {
|
|
10
|
+
$set?: any;
|
|
11
|
+
$on?: any;
|
|
12
|
+
};
|
|
13
|
+
z_$$bindings?: Bindings;
|
|
14
|
+
}
|
|
15
|
+
declare const Badge: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
}, {}, {}, string>;
|
|
18
|
+
type Badge = InstanceType<typeof Badge>;
|
|
19
|
+
export default Badge;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<!-- Generated by @canonical/summon:component-svelte v0.1.0 -->
|
|
2
|
+
|
|
3
|
+
<script lang="ts" module>
|
|
4
|
+
const roundedValueFormatter = new Intl.NumberFormat("en-US", {
|
|
5
|
+
notation: "compact",
|
|
6
|
+
compactDisplay: "short",
|
|
7
|
+
minimumFractionDigits: 0,
|
|
8
|
+
maximumFractionDigits: 1,
|
|
9
|
+
});
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import type { BadgeProps } from "./types";
|
|
14
|
+
import "./styles.css";
|
|
15
|
+
|
|
16
|
+
const componentCssClassName = "ds badge";
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
class: className,
|
|
20
|
+
value,
|
|
21
|
+
variant = "capped",
|
|
22
|
+
severity,
|
|
23
|
+
...rest
|
|
24
|
+
}: BadgeProps = $props();
|
|
25
|
+
|
|
26
|
+
const displayValue = $derived.by(() => {
|
|
27
|
+
const nonNegativeInt = Math.round(Math.max(value, 0));
|
|
28
|
+
|
|
29
|
+
if (variant === "capped") {
|
|
30
|
+
return nonNegativeInt > 999 ? "999+" : nonNegativeInt;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return roundedValueFormatter.format(nonNegativeInt);
|
|
34
|
+
});
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<span class={[componentCssClassName, className, severity]} {...rest}>
|
|
38
|
+
{displayValue}
|
|
39
|
+
</span>
|
|
40
|
+
|
|
41
|
+
<!-- @component
|
|
42
|
+
`Badge` is a visual indicator for numeric values. It is static and not interactive.
|
|
43
|
+
|
|
44
|
+
## Example Usage
|
|
45
|
+
```svelte
|
|
46
|
+
<Badge value={42} severity="caution" />
|
|
47
|
+
<Badge value={2351} variant="rounded" />
|
|
48
|
+
```
|
|
49
|
+
-->
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BadgeProps } from "./types";
|
|
2
|
+
import "./styles.css";
|
|
3
|
+
/**
|
|
4
|
+
* `Badge` is a visual indicator for numeric values. It is static and not interactive.
|
|
5
|
+
*
|
|
6
|
+
* ## Example Usage
|
|
7
|
+
* ```svelte
|
|
8
|
+
* <Badge value={42} severity="caution" />
|
|
9
|
+
* <Badge value={2351} variant="rounded" />
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
declare const Badge: import("svelte").Component<BadgeProps, {}, "">;
|
|
13
|
+
type Badge = ReturnType<typeof Badge>;
|
|
14
|
+
export default Badge;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Generated by @canonical/summon:component-svelte v0.1.0
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { render } from "vitest-browser-svelte";
|
|
4
|
+
import Component from "./Badge.svelte";
|
|
5
|
+
describe("Badge component", () => {
|
|
6
|
+
const baseProps = {
|
|
7
|
+
value: 42,
|
|
8
|
+
"data-testid": "badge",
|
|
9
|
+
};
|
|
10
|
+
it("renders", async () => {
|
|
11
|
+
const page = render(Component, { ...baseProps });
|
|
12
|
+
await expect.element(componentLocator(page)).toBeInTheDocument();
|
|
13
|
+
});
|
|
14
|
+
describe("attributes", () => {
|
|
15
|
+
it.each([
|
|
16
|
+
["id", "test-id"],
|
|
17
|
+
["aria-label", "test-aria-label"],
|
|
18
|
+
])("applies %s", async (attribute, expected) => {
|
|
19
|
+
const page = render(Component, { ...baseProps, [attribute]: expected });
|
|
20
|
+
await expect
|
|
21
|
+
.element(componentLocator(page))
|
|
22
|
+
.toHaveAttribute(attribute, expected);
|
|
23
|
+
});
|
|
24
|
+
it("applies classes", async () => {
|
|
25
|
+
const page = render(Component, { ...baseProps, class: "test-class" });
|
|
26
|
+
await expect.element(componentLocator(page)).toHaveClass("test-class");
|
|
27
|
+
await expect.element(componentLocator(page)).toHaveClass("ds");
|
|
28
|
+
await expect.element(componentLocator(page)).toHaveClass("badge");
|
|
29
|
+
});
|
|
30
|
+
it("applies style", async () => {
|
|
31
|
+
const page = render(Component, {
|
|
32
|
+
...baseProps,
|
|
33
|
+
style: "color: orange;",
|
|
34
|
+
});
|
|
35
|
+
await expect
|
|
36
|
+
.element(componentLocator(page))
|
|
37
|
+
.toHaveStyle({ color: "orange" });
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe("Display value", () => {
|
|
41
|
+
it("displays the capped variant by default", async () => {
|
|
42
|
+
const page = render(Component, { ...baseProps, value: 10000 });
|
|
43
|
+
await expect.element(componentLocator(page)).toHaveTextContent("999+");
|
|
44
|
+
});
|
|
45
|
+
describe("capped", () => {
|
|
46
|
+
it("displays 0 for negative values", async () => {
|
|
47
|
+
const page = render(Component, {
|
|
48
|
+
...baseProps,
|
|
49
|
+
value: -1,
|
|
50
|
+
variant: "capped",
|
|
51
|
+
});
|
|
52
|
+
await expect.element(componentLocator(page)).toHaveTextContent("0");
|
|
53
|
+
});
|
|
54
|
+
it("rounds to the nearest integer", async () => {
|
|
55
|
+
const page = render(Component, {
|
|
56
|
+
...baseProps,
|
|
57
|
+
value: 42.6,
|
|
58
|
+
variant: "capped",
|
|
59
|
+
});
|
|
60
|
+
await expect.element(componentLocator(page)).toHaveTextContent("43");
|
|
61
|
+
});
|
|
62
|
+
it("displays the values up to 999", async () => {
|
|
63
|
+
const page = render(Component, {
|
|
64
|
+
...baseProps,
|
|
65
|
+
value: 999,
|
|
66
|
+
variant: "capped",
|
|
67
|
+
});
|
|
68
|
+
await expect.element(componentLocator(page)).toHaveTextContent("999");
|
|
69
|
+
});
|
|
70
|
+
it("caps the value at 999", async () => {
|
|
71
|
+
const page = render(Component, {
|
|
72
|
+
...baseProps,
|
|
73
|
+
value: 10000,
|
|
74
|
+
variant: "capped",
|
|
75
|
+
});
|
|
76
|
+
await expect.element(componentLocator(page)).toHaveTextContent("999+");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe("rounded", () => {
|
|
80
|
+
it("displays 0 for negative values", async () => {
|
|
81
|
+
const page = render(Component, {
|
|
82
|
+
...baseProps,
|
|
83
|
+
value: -1,
|
|
84
|
+
variant: "rounded",
|
|
85
|
+
});
|
|
86
|
+
await expect.element(componentLocator(page)).toHaveTextContent("0");
|
|
87
|
+
});
|
|
88
|
+
it("rounds to the nearest integer", async () => {
|
|
89
|
+
const page = render(Component, {
|
|
90
|
+
...baseProps,
|
|
91
|
+
value: 42.6,
|
|
92
|
+
variant: "rounded",
|
|
93
|
+
});
|
|
94
|
+
await expect.element(componentLocator(page)).toHaveTextContent("43");
|
|
95
|
+
});
|
|
96
|
+
it.each([
|
|
97
|
+
[0, "0"],
|
|
98
|
+
[42.6, "43"],
|
|
99
|
+
[999, "999"],
|
|
100
|
+
[1_000, "1K"],
|
|
101
|
+
[1_500, "1.5K"],
|
|
102
|
+
[2_500_000, "2.5M"],
|
|
103
|
+
[1_000_000_000, "1B"],
|
|
104
|
+
[1_234_567_890_123, "1.2T"],
|
|
105
|
+
])("displays %d as %s", async (input, expected) => {
|
|
106
|
+
const page = render(Component, {
|
|
107
|
+
...baseProps,
|
|
108
|
+
value: input,
|
|
109
|
+
variant: "rounded",
|
|
110
|
+
});
|
|
111
|
+
await expect
|
|
112
|
+
.element(componentLocator(page))
|
|
113
|
+
.toHaveTextContent(expected);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
function componentLocator(page) {
|
|
119
|
+
return page.getByTestId("badge");
|
|
120
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* Generated by @canonical/summon:component-svelte v0.1.0 */
|
|
2
|
+
|
|
3
|
+
.ds.badge {
|
|
4
|
+
background-color: var(
|
|
5
|
+
--lp-color-background-context,
|
|
6
|
+
var(--lp-color-text-default)
|
|
7
|
+
);
|
|
8
|
+
color: var(--lp-color-text-context, var(--lp-color-text-reversed));
|
|
9
|
+
border-radius: var(--lp-dimension-radius-full);
|
|
10
|
+
padding-inline: var(--lp-dimension-spacing-inline-xxs);
|
|
11
|
+
font: var(--lp-typography-paragraph-xs-strong);
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ModifierFamily } from "modifier-families";
|
|
2
|
+
import type { SvelteHTMLElements } from "svelte/elements";
|
|
3
|
+
export interface BadgeProps extends Omit<SvelteHTMLElements["span"], "children">, ModifierFamily<"severity"> {
|
|
4
|
+
/**
|
|
5
|
+
* The non-negative integer value displayed within the badge. Negative values will be clamped to 0. Floats will be rounded.
|
|
6
|
+
*/
|
|
7
|
+
value: number;
|
|
8
|
+
/**
|
|
9
|
+
* - `capped` should be used whenever the amount of items is only relevant for small values. If the `value` is larger than 999, it will be displayed as `999+`.
|
|
10
|
+
* - `rounded` should be used whenever differences between large amounts of items are relevant. Values larger than 999 will be displayed as `1K`, `2.5M`, etc.
|
|
11
|
+
*
|
|
12
|
+
* @default "capped"
|
|
13
|
+
*/
|
|
14
|
+
variant?: "capped" | "rounded";
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { render } from "@canonical/svelte-ssr-test";
|
|
2
|
+
import { createRawSnippet } from "svelte";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import Component from "./Button.svelte";
|
|
5
|
+
describe("Button SSR", () => {
|
|
6
|
+
const baseProps = {
|
|
7
|
+
children: createRawSnippet(() => ({
|
|
8
|
+
render: () => `<span>Button</span>`,
|
|
9
|
+
})),
|
|
10
|
+
"data-testid": "button",
|
|
11
|
+
};
|
|
12
|
+
describe("basics", () => {
|
|
13
|
+
it("doesn't throw", () => {
|
|
14
|
+
expect(() => {
|
|
15
|
+
render(Component, { props: { ...baseProps } });
|
|
16
|
+
}).not.toThrow();
|
|
17
|
+
});
|
|
18
|
+
it("renders as a button by default", () => {
|
|
19
|
+
const page = render(Component, { props: { ...baseProps } });
|
|
20
|
+
expect(componentLocator(page)).toBeInstanceOf(page.window.HTMLButtonElement);
|
|
21
|
+
});
|
|
22
|
+
it("renders as an anchor when href is provided", () => {
|
|
23
|
+
const page = render(Component, {
|
|
24
|
+
props: { ...baseProps, href: "https://example.com" },
|
|
25
|
+
});
|
|
26
|
+
const link = page.getByRole("link");
|
|
27
|
+
expect(link).toBeInstanceOf(page.window.HTMLAnchorElement);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe("attributes", () => {
|
|
31
|
+
it.each([
|
|
32
|
+
["id", "test-id"],
|
|
33
|
+
["aria-label", "test-aria-label"],
|
|
34
|
+
])("applies %s", (attribute, expected) => {
|
|
35
|
+
const page = render(Component, {
|
|
36
|
+
props: { ...baseProps, [attribute]: expected },
|
|
37
|
+
});
|
|
38
|
+
expect(componentLocator(page).getAttribute(attribute)).toBe(expected);
|
|
39
|
+
});
|
|
40
|
+
it("applies classes", () => {
|
|
41
|
+
const page = render(Component, {
|
|
42
|
+
props: { class: "test-class", ...baseProps },
|
|
43
|
+
});
|
|
44
|
+
expect(componentLocator(page).classList).toContain("test-class");
|
|
45
|
+
expect(componentLocator(page).classList).toContain("ds");
|
|
46
|
+
expect(componentLocator(page).classList).toContain("button");
|
|
47
|
+
});
|
|
48
|
+
it("applies style", () => {
|
|
49
|
+
const page = render(Component, {
|
|
50
|
+
props: { style: "color: orange;", ...baseProps },
|
|
51
|
+
});
|
|
52
|
+
expect(componentLocator(page).style.color).toBe("orange");
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe("modifiers", () => {
|
|
56
|
+
it("applies severity class", () => {
|
|
57
|
+
const page = render(Component, {
|
|
58
|
+
props: { ...baseProps, severity: "brand" },
|
|
59
|
+
});
|
|
60
|
+
expect(componentLocator(page).classList).toContain("brand");
|
|
61
|
+
});
|
|
62
|
+
it("applies density class", () => {
|
|
63
|
+
const page = render(Component, {
|
|
64
|
+
props: { ...baseProps, density: "dense" },
|
|
65
|
+
});
|
|
66
|
+
expect(componentLocator(page).classList).toContain("dense");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe("disabled state", () => {
|
|
70
|
+
it("disables the button when disabled", () => {
|
|
71
|
+
const page = render(Component, {
|
|
72
|
+
props: { ...baseProps, disabled: true },
|
|
73
|
+
});
|
|
74
|
+
expect(componentLocator(page).hasAttribute("disabled")).toBe(true);
|
|
75
|
+
expect(componentLocator(page).classList).toContain("explicit-disabled");
|
|
76
|
+
});
|
|
77
|
+
it("disables the button when loading", () => {
|
|
78
|
+
const page = render(Component, {
|
|
79
|
+
props: { ...baseProps, loading: true },
|
|
80
|
+
});
|
|
81
|
+
expect(componentLocator(page).hasAttribute("disabled")).toBe(true);
|
|
82
|
+
expect(componentLocator(page).classList).toContain("loading");
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
function componentLocator(page) {
|
|
87
|
+
return page.getByTestId("button");
|
|
88
|
+
}
|