Skip to content
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

Add SplitBlock component #299

Merged
merged 7 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions e2e/split-block.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect, test } from "@playwright/test";

const testUrl = "/components/split-block";

test("Should display start slot content", async ({ page }) => {
await page.goto(testUrl);
await expect(page.getByTestId("start")).toHaveText("Start slot content");
});

test("Should display end slot content", async ({ page }) => {
await page.goto(testUrl);
await expect(page.getByTestId("end")).toHaveText("End slot content");
});
8 changes: 8 additions & 0 deletions src/docs/constants/docs.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ export const COMPONENT_ROUTES: ComponentRoute[] = [
"The detail of the layout where the content finds place in two columns.",
},

{
path: "/components/split-block",
title: "Split Block",

description:
"Displays content in a column on mobile devices and in a row on desktops.",
},

{
path: "/components/tag",
title: "Tag",
Expand Down
1 change: 1 addition & 0 deletions src/lib/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export { default as Segment } from "./components/Segment.svelte";
export { default as SegmentButton } from "./components/SegmentButton.svelte";
export { default as SkeletonText } from "./components/SkeletonText.svelte";
export { default as Spinner } from "./components/Spinner.svelte";
export { default as SplitBlock } from "./components/SplitBlock.svelte";
export { default as SplitContent } from "./components/SplitContent.svelte";
export { default as SplitPane } from "./components/SplitPane.svelte";
export { default as Tag } from "./components/Tag.svelte";
Expand Down
38 changes: 38 additions & 0 deletions src/lib/components/SplitBlock.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="split-block">
<div class="start">
<slot name="start" />
</div>
<hr />
<div class="end">
<slot name="end" />
</div>
</div>

<style lang="scss">
@use "../styles/mixins/media";

.split-block {
display: grid;
grid-template-rows: auto 1px auto;
grid-template-columns: auto;
grid-row-gap: var(--padding-2x);

@include media.min-width(large) {
grid-template-columns: 1fr 1px 1fr;
grid-template-rows: auto;
grid-row-gap: 0;
grid-column-gap: var(--padding-2x);
}
}

hr {
margin: 0;
height: 1px;
background: var(--line);

@include media.min-width(large) {
width: 1px;
height: auto;
}
}
</style>
46 changes: 46 additions & 0 deletions src/routes/(split)/components/split-block/+page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script lang="ts">
import SplitBlock from "$lib/components/SplitBlock.svelte";
</script>

# Split Content

This component displays two slots in a column on mobile devices and in a row on desktops, with a 1px separation line.

```javascript
<SplitBlock>
<div slot="start">Content A</div>
<div slot="end">Content B</div>
</SplitBlock>
```

## Properties

No properties

## Slots

| Slot name | Description |
| --------- | ------------------------- |
| `start` | First column on desktop. |
| `end` | Second column on desktop. |

## Showcase

> Colors added for demo purposes

<div class="container">
<SplitBlock>
<div slot="start" class="item" data-tid="start">Start slot content</div>
<div slot="end" class="item" data-tid="end">End slot content</div>
</SplitBlock>
</div>

<style lang="scss">
.container {
background: var(--card-background-contrast);
}

.item {
background: var(--card-background);
}
</style>
11 changes: 11 additions & 0 deletions src/tests/lib/components/SplitBlock.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { render } from "@testing-library/svelte";
import SplitBlockTest from "./SplitBlockTest.svelte";

describe("SplitBlock", () => {
it("should render slotted elements", () => {
const { getByTestId } = render(SplitBlockTest);

expect(getByTestId("content-test-start-slot")).not.toBeNull();
expect(getByTestId("content-test-end-slot")).not.toBeNull();
});
});
8 changes: 8 additions & 0 deletions src/tests/lib/components/SplitBlockTest.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script lang="ts">
import SplitBlock from "$lib/components/SplitBlock.svelte";
</script>

<SplitBlock>
<div data-tid="content-test-start-slot" slot="start" />
<div data-tid="content-test-end-slot" slot="end" />
</SplitBlock>