@canonical/svelte-ds-app-launchpad 0.15.1 → 0.16.0-experimental.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 +16 -2
- package/dist/components/Chip/Chip.ssr.test.js +65 -0
- package/dist/components/Chip/Chip.stories.svelte +125 -0
- package/dist/components/{Example/Example.stories.svelte.d.ts → Chip/Chip.stories.svelte.d.ts} +4 -4
- 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.js +116 -0
- package/dist/components/Chip/__screenshots__/Chip.svelte.test.ts/Chip-component-Initial-Rendering-should-apply-custom-class-and-modifiers-1.png +0 -0
- package/dist/components/Chip/__screenshots__/Chip.svelte.test.ts/Chip-component-Initial-Rendering-should-not-render-a-button-when-dismiss-is-provided-1.png +0 -0
- package/dist/components/Chip/__screenshots__/Chip.svelte.test.ts/Chip-component-Initial-Rendering-should-not-render-a-button-when-readonly-is-provided-1.png +0 -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/index.d.ts +1 -1
- package/dist/components/index.js +1 -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 +72 -0
- package/dist/styles/reset.css +19 -0
- package/package.json +7 -6
- package/LICENSE +0 -166
- package/dist/components/Example/Example.ssr.test.js +0 -48
- 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 → Chip/Chip.ssr.test.d.ts} +0 -0
- /package/dist/components/{Example/Example.svelte.test.d.ts → Chip/Chip.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,65 @@
|
|
|
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 "./Chip.svelte";
|
|
5
|
+
describe("Chip SSR", () => {
|
|
6
|
+
const baseProps = {
|
|
7
|
+
value: "Test",
|
|
8
|
+
"data-testid": "chip",
|
|
9
|
+
};
|
|
10
|
+
describe("basics", () => {
|
|
11
|
+
it("doesn't throw", () => {
|
|
12
|
+
expect(() => render(Component, { props: { ...baseProps } })).not.toThrow();
|
|
13
|
+
});
|
|
14
|
+
it("renders value", () => {
|
|
15
|
+
const page = render(Component, {
|
|
16
|
+
props: { ...baseProps, value: "Essential Content" },
|
|
17
|
+
});
|
|
18
|
+
expect(componentLocator(page).textContent).toContain("Essential Content");
|
|
19
|
+
});
|
|
20
|
+
it("renders as a span by default", () => {
|
|
21
|
+
const page = render(Component, {
|
|
22
|
+
props: { ...baseProps, value: "Span Chip" },
|
|
23
|
+
});
|
|
24
|
+
expect(componentLocator(page)).toBeInstanceOf(page.window.HTMLSpanElement);
|
|
25
|
+
expect(page.queryByRole("button")).toBeNull();
|
|
26
|
+
});
|
|
27
|
+
it("renders lead and value text", () => {
|
|
28
|
+
const page = render(Component, {
|
|
29
|
+
props: { ...baseProps, lead: "Key:", value: "Value" },
|
|
30
|
+
});
|
|
31
|
+
expect(page.getByText("Key:")).toBeTruthy();
|
|
32
|
+
expect(page.getByText("Value")).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe("State Variants", () => {
|
|
36
|
+
it("renders as a button when onclick is provided", () => {
|
|
37
|
+
const page = render(Component, {
|
|
38
|
+
props: { ...baseProps, value: "Clickable", onclick: () => { } },
|
|
39
|
+
});
|
|
40
|
+
expect(page.getByRole("button")).toBeInstanceOf(page.window.HTMLButtonElement);
|
|
41
|
+
});
|
|
42
|
+
it("renders a dismiss button when ondismiss is provided", () => {
|
|
43
|
+
const page = render(Component, {
|
|
44
|
+
props: { ...baseProps, value: "Dismissible", ondismiss: () => { } },
|
|
45
|
+
});
|
|
46
|
+
expect(componentLocator(page)).toBeInstanceOf(page.window.HTMLSpanElement);
|
|
47
|
+
expect(page.getByRole("button", { name: "Dismiss" })).toBeInstanceOf(page.window.HTMLButtonElement);
|
|
48
|
+
});
|
|
49
|
+
it("is non-interactive when readonly", () => {
|
|
50
|
+
const page = render(Component, {
|
|
51
|
+
props: {
|
|
52
|
+
...baseProps,
|
|
53
|
+
value: "Readonly Chip",
|
|
54
|
+
readonly: true,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
expect(componentLocator(page)).toBeInstanceOf(page.window.HTMLSpanElement);
|
|
58
|
+
expect(componentLocator(page).classList.contains("readonly")).toBe(true);
|
|
59
|
+
expect(page.queryByRole("button")).toBeNull();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
function componentLocator(page) {
|
|
64
|
+
return page.getByTestId("chip");
|
|
65
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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 Chip from "./Chip.svelte";
|
|
5
|
+
import { fn } from "storybook/test";
|
|
6
|
+
import { MODIFIER_FAMILIES } from "../../modifier-families";
|
|
7
|
+
import { ArchiveIcon } from "@canonical/svelte-icons";
|
|
8
|
+
|
|
9
|
+
const { Story } = defineMeta({
|
|
10
|
+
title: "Components/Chip",
|
|
11
|
+
component: Chip,
|
|
12
|
+
tags: ["autodocs"],
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<Story
|
|
17
|
+
name="Default interactive chip"
|
|
18
|
+
args={{
|
|
19
|
+
value: "Value",
|
|
20
|
+
onclick: fn(),
|
|
21
|
+
}}
|
|
22
|
+
/>
|
|
23
|
+
|
|
24
|
+
<Story name="Severities">
|
|
25
|
+
{#snippet template(args)}
|
|
26
|
+
{#each MODIFIER_FAMILIES.severity as severity (severity)}
|
|
27
|
+
<Chip
|
|
28
|
+
{...args}
|
|
29
|
+
lead="Severity"
|
|
30
|
+
value={severity}
|
|
31
|
+
{severity}
|
|
32
|
+
onclick={fn()}
|
|
33
|
+
/>
|
|
34
|
+
<br />
|
|
35
|
+
<br />
|
|
36
|
+
{/each}
|
|
37
|
+
{/snippet}
|
|
38
|
+
</Story>
|
|
39
|
+
|
|
40
|
+
<Story
|
|
41
|
+
name="With icon and lead"
|
|
42
|
+
args={{
|
|
43
|
+
lead: "Lead",
|
|
44
|
+
value: "Value",
|
|
45
|
+
severity: "caution",
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
{#snippet template(args)}
|
|
49
|
+
<Chip {...args}>
|
|
50
|
+
{#snippet icon()}
|
|
51
|
+
<ArchiveIcon />
|
|
52
|
+
{/snippet}
|
|
53
|
+
</Chip>
|
|
54
|
+
{/snippet}
|
|
55
|
+
</Story>
|
|
56
|
+
|
|
57
|
+
<Story
|
|
58
|
+
name="Dismissable chip"
|
|
59
|
+
args={{
|
|
60
|
+
lead: "Owner",
|
|
61
|
+
value: "Bob",
|
|
62
|
+
ondismiss: fn(),
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
|
|
66
|
+
<Story
|
|
67
|
+
name="With a badge"
|
|
68
|
+
args={{
|
|
69
|
+
lead: "Lead",
|
|
70
|
+
value: "Value",
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
{#snippet template(args)}
|
|
74
|
+
<Chip {...args}>
|
|
75
|
+
{#snippet badge()}
|
|
76
|
+
<!-- TODO: uncomment once Badge is upstreamed -->
|
|
77
|
+
<!-- <Badge value={42} /> -->
|
|
78
|
+
{/snippet}
|
|
79
|
+
</Chip>
|
|
80
|
+
{/snippet}
|
|
81
|
+
</Story>
|
|
82
|
+
|
|
83
|
+
<Story name="Read-only">
|
|
84
|
+
{#snippet template(args)}
|
|
85
|
+
{#each [undefined, ...MODIFIER_FAMILIES.severity] as severity (severity)}
|
|
86
|
+
<Chip
|
|
87
|
+
{...args}
|
|
88
|
+
lead="Severity"
|
|
89
|
+
value={severity || "default"}
|
|
90
|
+
readonly
|
|
91
|
+
{severity}
|
|
92
|
+
>
|
|
93
|
+
<!-- TODO: uncomment once Badge is upstreamed -->
|
|
94
|
+
<!-- {#snippet badge()} -->
|
|
95
|
+
<!-- <Badge value={420} /> -->
|
|
96
|
+
<!-- {/snippet} -->
|
|
97
|
+
</Chip>
|
|
98
|
+
<br />
|
|
99
|
+
<br />
|
|
100
|
+
{/each}
|
|
101
|
+
{/snippet}
|
|
102
|
+
</Story>
|
|
103
|
+
|
|
104
|
+
<Story
|
|
105
|
+
name="With all the elements"
|
|
106
|
+
tags={["!autodocs"]}
|
|
107
|
+
args={{
|
|
108
|
+
lead: "Lead",
|
|
109
|
+
value: "Value",
|
|
110
|
+
ondismiss: fn(),
|
|
111
|
+
onclick: fn(),
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
{#snippet template(args)}
|
|
115
|
+
<Chip {...args}>
|
|
116
|
+
{#snippet icon()}
|
|
117
|
+
<ArchiveIcon />
|
|
118
|
+
{/snippet}
|
|
119
|
+
<!-- TODO: uncomment once Badge is upstreamed -->
|
|
120
|
+
<!-- {#snippet badge()} -->
|
|
121
|
+
<!-- <Badge value={420} /> -->
|
|
122
|
+
<!-- {/snippet} -->
|
|
123
|
+
</Chip>
|
|
124
|
+
{/snippet}
|
|
125
|
+
</Story>
|
package/dist/components/{Example/Example.stories.svelte.d.ts → Chip/Chip.stories.svelte.d.ts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Chip from "./Chip.svelte";
|
|
2
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
3
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
4
|
$$bindings?: Bindings;
|
|
@@ -12,8 +12,8 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
12
12
|
};
|
|
13
13
|
z_$$bindings?: Bindings;
|
|
14
14
|
}
|
|
15
|
-
declare const
|
|
15
|
+
declare const Chip: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
16
16
|
[evt: string]: CustomEvent<any>;
|
|
17
17
|
}, {}, {}, string>;
|
|
18
|
-
type
|
|
19
|
-
export default
|
|
18
|
+
type Chip = InstanceType<typeof Chip>;
|
|
19
|
+
export default Chip;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<!-- Generated by @canonical/summon:component-svelte v0.1.0 -->
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import { CloseIcon } from "@canonical/svelte-icons";
|
|
5
|
+
import type { ChipProps } from "./types";
|
|
6
|
+
import "./styles.css";
|
|
7
|
+
|
|
8
|
+
const componentCssClassName = "ds chip";
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
class: className,
|
|
12
|
+
density,
|
|
13
|
+
severity,
|
|
14
|
+
readonly,
|
|
15
|
+
lead,
|
|
16
|
+
value,
|
|
17
|
+
icon,
|
|
18
|
+
badge,
|
|
19
|
+
ondismiss,
|
|
20
|
+
onclick,
|
|
21
|
+
...rest
|
|
22
|
+
}: ChipProps = $props();
|
|
23
|
+
|
|
24
|
+
const dismissible = $derived(ondismiss !== undefined);
|
|
25
|
+
const clickable = $derived(onclick !== undefined);
|
|
26
|
+
|
|
27
|
+
const rootElement = $derived(
|
|
28
|
+
dismissible || readonly || !clickable ? "span" : "button",
|
|
29
|
+
);
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<svelte:element
|
|
33
|
+
this={rootElement}
|
|
34
|
+
class={[componentCssClassName, className, density, severity, { readonly }]}
|
|
35
|
+
type={rootElement === "button" ? "button" : undefined}
|
|
36
|
+
{onclick}
|
|
37
|
+
{...rest}
|
|
38
|
+
>
|
|
39
|
+
{#if icon}
|
|
40
|
+
<span class="icon">
|
|
41
|
+
{@render icon()}
|
|
42
|
+
</span>
|
|
43
|
+
{/if}
|
|
44
|
+
{#if lead}
|
|
45
|
+
<span class="lead">
|
|
46
|
+
{lead}
|
|
47
|
+
</span>
|
|
48
|
+
{/if}
|
|
49
|
+
<span class="value">
|
|
50
|
+
{value}
|
|
51
|
+
</span>
|
|
52
|
+
{#if badge}
|
|
53
|
+
<span class="badge">
|
|
54
|
+
{@render badge()}
|
|
55
|
+
</span>
|
|
56
|
+
{/if}
|
|
57
|
+
{#if dismissible}
|
|
58
|
+
<button
|
|
59
|
+
class="dismiss"
|
|
60
|
+
onclick={ondismiss}
|
|
61
|
+
aria-label="Dismiss"
|
|
62
|
+
type="button"
|
|
63
|
+
>
|
|
64
|
+
<CloseIcon class="dismiss-icon" />
|
|
65
|
+
</button>
|
|
66
|
+
{/if}
|
|
67
|
+
</svelte:element>
|
|
68
|
+
|
|
69
|
+
<!-- @component
|
|
70
|
+
`Chip` displays a small actionable pieces of information.
|
|
71
|
+
|
|
72
|
+
## Example Usage
|
|
73
|
+
```svelte
|
|
74
|
+
<Chip value="Value"/>
|
|
75
|
+
<Chip lead="Lead" value="Value" />
|
|
76
|
+
<Chip lead="Lead" value="Value" severity="caution" />
|
|
77
|
+
<Chip
|
|
78
|
+
lead="Lead"
|
|
79
|
+
value="Value"
|
|
80
|
+
readonly
|
|
81
|
+
density="dense"
|
|
82
|
+
severity="caution"
|
|
83
|
+
/>
|
|
84
|
+
```
|
|
85
|
+
-->
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ChipProps } from "./types";
|
|
2
|
+
import "./styles.css";
|
|
3
|
+
/**
|
|
4
|
+
* `Chip` displays a small actionable pieces of information.
|
|
5
|
+
*
|
|
6
|
+
* ## Example Usage
|
|
7
|
+
* ```svelte
|
|
8
|
+
* <Chip value="Value"/>
|
|
9
|
+
* <Chip lead="Lead" value="Value" />
|
|
10
|
+
* <Chip lead="Lead" value="Value" severity="caution" />
|
|
11
|
+
* <Chip
|
|
12
|
+
* lead="Lead"
|
|
13
|
+
* value="Value"
|
|
14
|
+
* readonly
|
|
15
|
+
* density="dense"
|
|
16
|
+
* severity="caution"
|
|
17
|
+
* />
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare const Chip: import("svelte").Component<ChipProps, {}, "">;
|
|
21
|
+
type Chip = ReturnType<typeof Chip>;
|
|
22
|
+
export default Chip;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Generated by @canonical/summon:component-svelte v0.1.0
|
|
2
|
+
import { createRawSnippet } from "svelte";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { render } from "vitest-browser-svelte";
|
|
5
|
+
import Component from "./Chip.svelte";
|
|
6
|
+
describe("Chip component", () => {
|
|
7
|
+
const baseProps = {
|
|
8
|
+
value: "Chip",
|
|
9
|
+
"data-testid": "chip",
|
|
10
|
+
};
|
|
11
|
+
it("renders", async () => {
|
|
12
|
+
const page = render(Component, { ...baseProps });
|
|
13
|
+
await expect.element(componentLocator(page)).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
describe("attributes", () => {
|
|
16
|
+
it.each([
|
|
17
|
+
["id", "test-id"],
|
|
18
|
+
["aria-label", "test-aria-label"],
|
|
19
|
+
])("applies %s", async (attribute, expected) => {
|
|
20
|
+
const page = render(Component, { ...baseProps, [attribute]: expected });
|
|
21
|
+
await expect
|
|
22
|
+
.element(componentLocator(page))
|
|
23
|
+
.toHaveAttribute(attribute, expected);
|
|
24
|
+
});
|
|
25
|
+
it("applies classes", async () => {
|
|
26
|
+
const page = render(Component, { ...baseProps, class: "test-class" });
|
|
27
|
+
await expect.element(componentLocator(page)).toHaveClass("test-class");
|
|
28
|
+
await expect.element(componentLocator(page)).toHaveClass("ds");
|
|
29
|
+
await expect.element(componentLocator(page)).toHaveClass("chip");
|
|
30
|
+
});
|
|
31
|
+
it("applies style", async () => {
|
|
32
|
+
const page = render(Component, {
|
|
33
|
+
...baseProps,
|
|
34
|
+
style: "color: orange;",
|
|
35
|
+
});
|
|
36
|
+
await expect
|
|
37
|
+
.element(componentLocator(page))
|
|
38
|
+
.toHaveStyle({ color: "orange" });
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe("Initial Rendering", () => {
|
|
42
|
+
it("should render with default props as a non-interactive element", async () => {
|
|
43
|
+
const page = render(Component, { ...baseProps, value: "Default Chip" });
|
|
44
|
+
await expect.element(page.getByRole("button")).not.toBeInTheDocument();
|
|
45
|
+
});
|
|
46
|
+
it("should render with a lead element", async () => {
|
|
47
|
+
const page = render(Component, { ...baseProps, lead: "Key", value: "Value" });
|
|
48
|
+
await expect.element(page.getByText("Key")).toBeInTheDocument();
|
|
49
|
+
await expect.element(page.getByText("Value")).toBeInTheDocument();
|
|
50
|
+
});
|
|
51
|
+
it("should render with an icon", async () => {
|
|
52
|
+
const icon = createRawSnippet(() => ({
|
|
53
|
+
render: () => `<div data-testid="custom-icon"></div>`,
|
|
54
|
+
}));
|
|
55
|
+
const page = render(Component, { ...baseProps, value: "Icon Chip", icon });
|
|
56
|
+
await expect.element(page.getByTestId("custom-icon")).toBeInTheDocument();
|
|
57
|
+
});
|
|
58
|
+
it("should apply custom class and modifiers", async () => {
|
|
59
|
+
const page = render(Component, {
|
|
60
|
+
...baseProps,
|
|
61
|
+
value: "Styled Chip",
|
|
62
|
+
class: "extra-class",
|
|
63
|
+
density: "dense",
|
|
64
|
+
severity: "caution",
|
|
65
|
+
});
|
|
66
|
+
await expect.element(componentLocator(page)).toHaveClass("extra-class");
|
|
67
|
+
await expect.element(componentLocator(page)).toHaveClass("dense");
|
|
68
|
+
await expect.element(componentLocator(page)).toHaveClass("caution");
|
|
69
|
+
});
|
|
70
|
+
it("should not render a button when dismiss is provided", async () => {
|
|
71
|
+
const page = render(Component, {
|
|
72
|
+
...baseProps,
|
|
73
|
+
value: "Dismissible",
|
|
74
|
+
ondismiss: () => { },
|
|
75
|
+
});
|
|
76
|
+
await expect
|
|
77
|
+
.element(componentLocator(page))
|
|
78
|
+
.not.toHaveAttribute("type", "button");
|
|
79
|
+
await expect
|
|
80
|
+
.element(page.getByRole("button"))
|
|
81
|
+
.toHaveAccessibleName("Dismiss");
|
|
82
|
+
});
|
|
83
|
+
it("should not render a button when readonly is provided", async () => {
|
|
84
|
+
const page = render(Component, {
|
|
85
|
+
...baseProps,
|
|
86
|
+
value: "Readonly",
|
|
87
|
+
readonly: true,
|
|
88
|
+
onclick: () => { },
|
|
89
|
+
});
|
|
90
|
+
await expect.element(componentLocator(page)).toBeInTheDocument();
|
|
91
|
+
await expect.element(page.getByRole("button")).not.toBeInTheDocument();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe("Interactions & States", () => {
|
|
95
|
+
it("should render a working button when onclick is provided", async () => {
|
|
96
|
+
const onclick = vi.fn();
|
|
97
|
+
const page = render(Component, { ...baseProps, value: "Clickable", onclick });
|
|
98
|
+
const element = page.getByRole("button");
|
|
99
|
+
await expect.element(element).toBeInTheDocument();
|
|
100
|
+
await element.click();
|
|
101
|
+
expect(onclick).toHaveBeenCalled();
|
|
102
|
+
});
|
|
103
|
+
it("should render a working dismiss button when ondismiss is provided", async () => {
|
|
104
|
+
const ondismiss = vi.fn();
|
|
105
|
+
const page = render(Component, { ...baseProps, value: "Dismissible", ondismiss });
|
|
106
|
+
const dissmissButton = page.getByLabelText("Dismiss");
|
|
107
|
+
await expect.element(dissmissButton).toBeInTheDocument();
|
|
108
|
+
await expect.element(dissmissButton).toBeInTheDocument();
|
|
109
|
+
await dissmissButton.click();
|
|
110
|
+
expect(ondismiss).toHaveBeenCalled();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
function componentLocator(page) {
|
|
115
|
+
return page.getByTestId("chip");
|
|
116
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* Generated by @canonical/summon:component-svelte v0.1.0 */
|
|
2
|
+
|
|
3
|
+
.ds.chip {
|
|
4
|
+
display: inline-flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
font: var(--lp-typography-paragraph-s);
|
|
7
|
+
color: var(--lp-color-text-secondary-context, var(--lp-color-text-default));
|
|
8
|
+
border-radius: var(--lp-dimension-radius-full);
|
|
9
|
+
border: var(--lp-dimension-stroke-thickness-default) solid
|
|
10
|
+
var(--lp-color-border-secondary-context, var(--lp-color-border-default));
|
|
11
|
+
background-color: var(
|
|
12
|
+
--lp-color-background-secondary-context,
|
|
13
|
+
var(--lp-color-background-neutral-default)
|
|
14
|
+
);
|
|
15
|
+
padding-block: var(
|
|
16
|
+
--lp-dimension-padding-block-context,
|
|
17
|
+
var(--lp-dimension-spacing-block-xxxs)
|
|
18
|
+
);
|
|
19
|
+
padding-inline: var(
|
|
20
|
+
--lp-dimension-padding-inline-context,
|
|
21
|
+
var(--lp-dimension-spacing-inline-s)
|
|
22
|
+
);
|
|
23
|
+
transition-duration: var(--lp-transition-duration-snap);
|
|
24
|
+
transition-property: background-color, border-color;
|
|
25
|
+
transition-timing-function: var(--lp-transition-timing-ease-in);
|
|
26
|
+
|
|
27
|
+
&:is(button),
|
|
28
|
+
.dismiss {
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
|
|
31
|
+
&:hover {
|
|
32
|
+
background-color: var(
|
|
33
|
+
--lp-color-background-secondary-hover-context,
|
|
34
|
+
var(--lp-color-background-neutral-hover)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&:active {
|
|
39
|
+
background-color: var(
|
|
40
|
+
--lp-color-background-secondary-active-context,
|
|
41
|
+
var(--lp-color-background-neutral-active)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
> .icon {
|
|
47
|
+
display: flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
justify-content: center;
|
|
50
|
+
margin-right: var(--lp-dimension-spacing-inline-xxs);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
> .lead {
|
|
54
|
+
font-variant-caps: all-small-caps;
|
|
55
|
+
font-variant-numeric: oldstyle-nums;
|
|
56
|
+
letter-spacing: var(--lp-typography-letter-spacing-l);
|
|
57
|
+
|
|
58
|
+
& + .value::before {
|
|
59
|
+
content: ": ";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
> .badge {
|
|
64
|
+
margin-inline: var(--lp-dimension-spacing-inline-xs)
|
|
65
|
+
var(--lp-dimension-spacing-inline-minimum);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
> .dismiss {
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
justify-content: center;
|
|
72
|
+
background-color: transparent;
|
|
73
|
+
color: var(--lp-color-text-default);
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
border-radius: var(--lp-dimension-radius-full);
|
|
76
|
+
width: var(--lp-dimension-size-xs);
|
|
77
|
+
height: var(--lp-dimension-size-xs);
|
|
78
|
+
padding-block: var(--lp-dimension-spacing-block-xxxs);
|
|
79
|
+
padding-inline: var(--lp-dimension-spacing-inline-xxxs);
|
|
80
|
+
margin-left: var(--lp-dimension-spacing-inline-xxs);
|
|
81
|
+
border: var(--lp-dimension-stroke-thickness-default) solid transparent;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* TODO: Consider splitting the chip component into two separate components */
|
|
85
|
+
/* Where the read-only local modifier won't be needed anymore. */
|
|
86
|
+
&.readonly {
|
|
87
|
+
--lp-color-border-secondary-context: var(--lp-color-background-default);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ModifierFamily } from "modifier-families";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
4
|
+
/** Either the chip can be clicked or the dismiss button can be clicked.
|
|
5
|
+
* We cannot have both click and dismiss events at the same time.
|
|
6
|
+
*/
|
|
7
|
+
type ChipClickOptions = {
|
|
8
|
+
/** Callback function to handle click events on the chip */
|
|
9
|
+
onclick?: (event: MouseEvent) => void;
|
|
10
|
+
/** Callback function to handle dismiss events on the chip */
|
|
11
|
+
ondismiss?: (event: MouseEvent) => void;
|
|
12
|
+
};
|
|
13
|
+
export interface ChipProps extends Omit<HTMLAttributes<HTMLElement>, "onclick" | "children">, ModifierFamily<["density", "severity"]>, ChipClickOptions {
|
|
14
|
+
/** The value of the chip */
|
|
15
|
+
value: string;
|
|
16
|
+
/** The key of the chip
|
|
17
|
+
* @default no value
|
|
18
|
+
*/
|
|
19
|
+
lead?: string;
|
|
20
|
+
/** The icon of the Chip
|
|
21
|
+
* @default no icon
|
|
22
|
+
*/
|
|
23
|
+
icon?: Snippet | undefined | null;
|
|
24
|
+
/** The badge to be displayed on the Chip */
|
|
25
|
+
badge?: Snippet | undefined | null;
|
|
26
|
+
/** Whether the Chip is read-only */
|
|
27
|
+
readonly?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./Chip/index.js";
|
package/dist/components/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./Chip/index.js";
|
package/dist/index.css
ADDED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./constants.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
.dense {
|
|
2
|
+
--lp-dimension-padding-block-context: var(--lp-dimension-spacing-block-minimum);
|
|
3
|
+
--lp-dimension-padding-inline-context: var(--lp-dimension-spacing-inline-s);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.compact {
|
|
7
|
+
--lp-dimension-padding-block-context: var(--lp-dimension-spacing-block-minimum);
|
|
8
|
+
--lp-dimension-padding-inline-context: var(--lp-dimension-spacing-inline-xs);
|
|
9
|
+
--lp-typography-context: var(--lp-typography-paragraph-s);
|
|
10
|
+
}
|