-
Notifications
You must be signed in to change notification settings - Fork 12
feat(svelte-ds-app-launchpad): Add Timeline #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
steciuk
wants to merge
5
commits into
feat/upstream-user-avatar
Choose a base branch
from
feat/upstream-timeline
base: feat/upstream-user-avatar
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9bb0b30
feat(svelte-ds-app-launchpad): Add Timeline
steciuk a73de49
Don't draw the connector if Event is the only child.
steciuk 225b331
Check if marker falsy instead of strictly undefined
steciuk f488fd8
Remove aria-hidden attribute from marker div
steciuk 7c08f92
Run formatter
steciuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
packages/svelte/ds-app-launchpad/src/lib/components/Timeline/Timeline.ssr.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* @canonical/generator-ds 0.10.0-experimental.5 */ | ||
|
|
||
| import type { RenderResult } from "@canonical/svelte-ssr-test"; | ||
| import { render } from "@canonical/svelte-ssr-test"; | ||
| import type { ComponentProps } from "svelte"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import Component from "./Timeline.svelte"; | ||
|
|
||
| describe("Timeline SSR", () => { | ||
| const baseProps = {} satisfies ComponentProps<typeof Component>; | ||
|
|
||
| it("doesn't throw", () => { | ||
| expect(() => { | ||
| render(Component, { props: { ...baseProps } }); | ||
| }).not.toThrow(); | ||
| }); | ||
|
|
||
| it("renders", () => { | ||
| const page = render(Component, { props: { ...baseProps } }); | ||
| expect(componentLocator(page)).toBeInstanceOf(page.window.HTMLOListElement); | ||
| }); | ||
|
|
||
| describe("attributes", () => { | ||
| it.each([ | ||
| ["id", "test-id"], | ||
| ["aria-label", "test-aria-label"], | ||
| ])("applies %s", (attribute, expected) => { | ||
| const page = render(Component, { | ||
| props: { ...baseProps, [attribute]: expected }, | ||
| }); | ||
| expect(componentLocator(page).getAttribute(attribute)).toBe(expected); | ||
| }); | ||
|
|
||
| it("applies classes", () => { | ||
| const page = render(Component, { | ||
| props: { ...baseProps, class: "test-class" }, | ||
| }); | ||
| expect(componentLocator(page).classList).toContain("test-class"); | ||
| expect(componentLocator(page).classList).toContain("ds"); | ||
| expect(componentLocator(page).classList).toContain("timeline"); | ||
| }); | ||
|
|
||
| it("applies style", () => { | ||
| const page = render(Component, { | ||
| props: { ...baseProps, style: "color: orange;" }, | ||
| }); | ||
| expect(componentLocator(page).style.color).toBe("orange"); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| function componentLocator(page: RenderResult): HTMLElement { | ||
| return page.getByRole("list"); | ||
| } |
124 changes: 124 additions & 0 deletions
124
packages/svelte/ds-app-launchpad/src/lib/components/Timeline/Timeline.stories.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| <script module lang="ts"> | ||
| import { EditIcon, ForkIcon, SettingsIcon } from "@canonical/svelte-icons"; | ||
| import { defineMeta } from "@storybook/addon-svelte-csf"; | ||
| import { DateTime } from "../DateTime/index.js"; | ||
| import { Timeline } from "./index.js"; | ||
|
|
||
| const { Story } = defineMeta({ | ||
| title: "Components/Timeline", | ||
| tags: ["autodocs"], | ||
| component: Timeline, | ||
| }); | ||
|
|
||
| const user = { | ||
| userName: "Alvarez Daniella", | ||
| userAvatarUrl: "https://assets.ubuntu.com/v1/fca94c45-snap+icon.png", | ||
| }; | ||
| </script> | ||
|
|
||
| <Story name="Default" asChild> | ||
| <Timeline> | ||
| <Timeline.Event marker={user} markerSize="large"> | ||
| {#snippet titleRow()} | ||
| <Timeline.Event.TitleRow leadingText={user.userName}> | ||
| added 1 commit and filed 2 issues | ||
| {#snippet date()} | ||
| <DateTime date="2023-03-15T12:00:00Z" /> | ||
| {/snippet} | ||
| </Timeline.Event.TitleRow> | ||
| {/snippet} | ||
| Implementation of a new feature for Launchpad bug templates | ||
| </Timeline.Event> | ||
| <Timeline.Event> | ||
| {#snippet marker()} | ||
| <EditIcon /> | ||
| {/snippet} | ||
| {#snippet titleRow()} | ||
| <Timeline.Event.TitleRow leadingText={user.userName}> | ||
| did things that are really complex and will probably take a while to | ||
| explain | ||
| {#snippet date()} | ||
| <DateTime date="2023-03-12T12:00:00Z" /> | ||
| {/snippet} | ||
| </Timeline.Event.TitleRow> | ||
| {/snippet} | ||
| <div | ||
| class="placeholder-box" | ||
| style="height: 50px; display: grid; place-content: center;" | ||
| > | ||
| Here is some custom content | ||
| </div> | ||
| </Timeline.Event> | ||
| <Timeline.Event> | ||
| {#snippet titleRow()} | ||
| <Timeline.Event.TitleRow leadingText={user.userName}> | ||
| did some amazing things | ||
| {#snippet date()} | ||
| <DateTime date="2023-03-13T12:00:00Z" /> | ||
| {/snippet} | ||
| </Timeline.Event.TitleRow> | ||
| {/snippet} | ||
| </Timeline.Event> | ||
| <Timeline.Event> | ||
| {#snippet titleRow()} | ||
| <Timeline.Event.TitleRow leadingText={user.userName}> | ||
| did so many things that it could be a blog post, but let's keep it | ||
| short for now and just say that it was a lot | ||
| {#snippet date()} | ||
| <DateTime date="2023-03-14T12:00:00Z" /> | ||
| {/snippet} | ||
| </Timeline.Event.TitleRow> | ||
| {/snippet} | ||
| </Timeline.Event> | ||
| <Timeline.Event markerSize="small"> | ||
| {#snippet marker()} | ||
| <ForkIcon /> | ||
| {/snippet} | ||
| {#snippet titleRow()} | ||
| <Timeline.Event.TitleRow leadingText={user.userName}> | ||
| raised a flag | ||
| {#snippet date()} | ||
| <DateTime date="2023-03-15T12:00:00Z" /> | ||
| {/snippet} | ||
| </Timeline.Event.TitleRow> | ||
| {/snippet} | ||
| The flag was raised | ||
| </Timeline.Event> | ||
| <Timeline.HiddenEvents numHidden={3}> | ||
| <Timeline.HiddenEvents.Link href="?show-all" | ||
| >Show all</Timeline.HiddenEvents.Link | ||
| > | ||
| </Timeline.HiddenEvents> | ||
| <Timeline.Event markerSize="large"> | ||
| {#snippet marker()} | ||
| <SettingsIcon /> | ||
| {/snippet} | ||
| {#snippet titleRow()} | ||
| <Timeline.Event.TitleRow> | ||
| The MP was <span style="color: var(--lp-color-text-default)" | ||
| >Merged</span | ||
| > | ||
| {#snippet date()} | ||
| <DateTime date="2023-03-16T12:00:00Z" /> | ||
| {/snippet} | ||
| </Timeline.Event.TitleRow> | ||
| {/snippet} | ||
| </Timeline.Event> | ||
| <Timeline.Event marker={{ userName: "John Doe" }} markerSize="large"> | ||
| <div | ||
| class="placeholder-box" | ||
| style="height: 150px; display: grid; place-content: center;" | ||
| > | ||
| Content goes here | ||
| </div> | ||
| </Timeline.Event> | ||
| <Timeline.HiddenEvents numHidden={888}> | ||
| <Timeline.HiddenEvents.Link href="?show-more" | ||
| >Show more</Timeline.HiddenEvents.Link | ||
| > | ||
| <Timeline.HiddenEvents.Link href="?show-all" | ||
| >Show all</Timeline.HiddenEvents.Link | ||
| > | ||
| </Timeline.HiddenEvents> | ||
| </Timeline> | ||
| </Story> |
51 changes: 51 additions & 0 deletions
51
packages/svelte/ds-app-launchpad/src/lib/components/Timeline/Timeline.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <!-- @canonical/generator-ds 0.10.0-experimental.2 --> | ||
|
|
||
| <script lang="ts"> | ||
| import type { TimelineProps } from "./types.js"; | ||
| import "./styles.css"; | ||
|
|
||
| const componentCssClassName = "ds timeline"; | ||
|
|
||
| let { class: className, children, ...rest }: TimelineProps = $props(); | ||
| </script> | ||
|
|
||
| <ol class={[componentCssClassName, className]} {...rest}> | ||
| {@render children?.()} | ||
| </ol> | ||
|
|
||
| <!-- @component | ||
| `Timeline` component represents a vertical timeline that displays a series of events in chronological order. | ||
|
|
||
| ## Example Usage | ||
| ```svelte | ||
| <Timeline> | ||
| <Timeline.Event marker={{userName: "Alvarez Daniella"}} markerSize="large"> | ||
| {#snippet titleRow()} | ||
| <Timeline.Event.TitleRow leadingText="Alvarez Daniella"> | ||
| did some cool stuff | ||
| {#snippet date()} | ||
| <DateTime date="2023-03-15" /> | ||
| {/snippet} | ||
| </Timeline.Event.TitleRow> | ||
| {/snippet} | ||
| Description of the stuff that was done. | ||
| </Timeline.Event> | ||
| <Timeline.Event> | ||
| {#snippet marker()} | ||
| <StarredIcon /> | ||
| {/snippet} | ||
| {#snippet titleRow()} | ||
| <Timeline.Event.TitleRow leadingText="Alvarez Daniella"> | ||
| did other amazing things | ||
| {#snippet date()} | ||
| <DateTime date="2023-03-15" /> | ||
| {/snippet} | ||
| </Timeline.Event.TitleRow> | ||
| {/snippet} | ||
| </Timeline.Event> | ||
| <Timeline.HiddenEvents numHidden={3}> | ||
| <Timeline.HiddenEvents.Link href="?show-all">Show all</Timeline.HiddenEvents.Link> | ||
| </Timeline.HiddenEvents> | ||
| </Timeline> | ||
| ``` | ||
| --> | ||
50 changes: 50 additions & 0 deletions
50
packages/svelte/ds-app-launchpad/src/lib/components/Timeline/Timeline.svelte.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* @canonical/generator-ds 0.10.0-experimental.5 */ | ||
|
|
||
| import type { ComponentProps } from "svelte"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import type { Locator } from "vitest/browser"; | ||
| import type { RenderResult } from "vitest-browser-svelte"; | ||
| import { render } from "vitest-browser-svelte"; | ||
| import Component from "./Timeline.svelte"; | ||
|
|
||
| describe("Timeline component", () => { | ||
| const baseProps = {} satisfies ComponentProps<typeof Component>; | ||
|
|
||
| it("renders", async () => { | ||
| const page = render(Component, { ...baseProps }); | ||
| await expect.element(componentLocator(page)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| describe("attributes", () => { | ||
| it.each([ | ||
| ["id", "test-id"], | ||
| ["aria-label", "test-aria-label"], | ||
| ])("applies %s", async (attribute, expected) => { | ||
| const page = render(Component, { ...baseProps, [attribute]: expected }); | ||
| await expect | ||
| .element(componentLocator(page)) | ||
| .toHaveAttribute(attribute, expected); | ||
| }); | ||
|
|
||
| it("applies classes", async () => { | ||
| const page = render(Component, { ...baseProps, class: "test-class" }); | ||
| await expect.element(componentLocator(page)).toHaveClass("test-class"); | ||
| await expect.element(componentLocator(page)).toHaveClass("ds"); | ||
| await expect.element(componentLocator(page)).toHaveClass("timeline"); | ||
| }); | ||
|
|
||
| it("applies style", async () => { | ||
| const page = render(Component, { | ||
| ...baseProps, | ||
| style: "color: orange;", | ||
| }); | ||
| await expect | ||
| .element(componentLocator(page)) | ||
| .toHaveStyle({ color: "orange" }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| function componentLocator(page: RenderResult<typeof Component>): Locator { | ||
| return page.getByRole("list"); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.