Skip to content

Commit c0c8fcd

Browse files
committed
Add EmptyState
1 parent 1babf74 commit c0c8fcd

File tree

9 files changed

+70
-2
lines changed

9 files changed

+70
-2
lines changed

src/common/components/Badge/Badge.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import "@testing-library/jest-dom";
22
import { render, screen } from "@testing-library/react";
33
import { Badge } from "./Badge";
4+
import { describe, it } from "vitest";
45

56
describe("Badge", () => {
67
it("should render", () => {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
import { EmptyState } from "./EmptyState";
3+
4+
export default {
5+
title: "Components/EmptyState",
6+
component: EmptyState,
7+
} as Meta;
8+
9+
type Story = StoryObj<typeof EmptyState>;
10+
11+
export const Default: Story = {
12+
args: {
13+
titleSlot: "Create your first Spark.",
14+
textSlot:
15+
"Sparks can be of any topic. Use #tags to structure your Sparks. #tags added to the beginning of a Spark are used as context. Try adding your first one.",
16+
},
17+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import "@testing-library/jest-dom";
2+
import { render, screen } from "@testing-library/react";
3+
import { EmptyState } from "./EmptyState";
4+
import { describe, it } from "vitest";
5+
6+
describe("EmptyState", () => {
7+
it("should render", () => {
8+
render(
9+
<EmptyState
10+
titleSlot="Hello world"
11+
textSlot="How are you?"
12+
/>,
13+
);
14+
15+
expect(screen.getByText("Hello world")).toBeInTheDocument();
16+
expect(screen.getByText("How are you?")).toBeInTheDocument();
17+
});
18+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type React from "react";
2+
3+
export type EmptyStateProps = {
4+
titleSlot: React.ReactNode;
5+
textSlot: React.ReactNode;
6+
};
7+
8+
export const EmptyState = (props: EmptyStateProps) => {
9+
const { titleSlot, textSlot } = props;
10+
return (
11+
<div className="flex flex-col gap-4 p-4 text-center">
12+
<span className="font-bold text-lg text-stone-700">
13+
{titleSlot}
14+
</span>
15+
<span className="text-stone-500">{textSlot}</span>
16+
</div>
17+
);
18+
};

src/common/components/FormContainer/FormContainer.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import "@testing-library/jest-dom";
22
import { render, screen } from "@testing-library/react";
33
import userEvent from "@testing-library/user-event";
44
import { FormContainer } from "./FormContainer";
5-
import { it } from "vitest";
5+
import { describe, it } from "vitest";
66

77
describe("FormContainer", () => {
88
it("should render", () => {

src/common/components/IconButton/IconButton.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { render, screen } from "@testing-library/react";
33
import userEvent from "@testing-library/user-event";
44
import { IconButton } from "./IconButton";
55
import { CogIcon } from "../../../assets/icons/CogIcon";
6+
import { describe, it } from "vitest";
67

78
describe("IconButton", () => {
89
it("should render", () => {

src/common/components/Input/Input.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { render, screen } from "@testing-library/react";
33
import userEvent from "@testing-library/user-event";
44
import { type FieldValues, type SubmitHandler, useForm } from "react-hook-form";
55
import { Input } from "./Input";
6-
import { it } from "vitest";
6+
import { describe, it } from "vitest";
77

88
const Wrapper = ({
99
handleSubmit,

src/common/components/TextInput/TextInput.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import "@testing-library/jest-dom";
22
import { render, screen } from "@testing-library/react";
33
import { TextInput } from "./TextInput";
4+
import { describe, it } from "vitest";
45

56
describe("TextInput", () => {
67
it("should render", () => {

src/container/SparkList/SparkList.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { sparkService } from "../../scripts/db/SparkService";
33
import { differenceInCalendarDays, format } from "date-fns";
44
import type Spark from "../../interfaces/Spark";
55
import { stringToHue } from "../../scripts/utils/stringUtils";
6+
import { EmptyState } from "../../common/components/EmptyState/EmptyState";
67

78
type SparkSection = {
89
key: string;
@@ -91,6 +92,17 @@ export const SparkList = () => {
9192
return tmpSections;
9293
}, []);
9394

95+
if (!sections || sections.length <= 0) {
96+
return (
97+
<div className="flex flex-col py-10 bg-white h-full px-8">
98+
<EmptyState
99+
titleSlot="Create your first Spark"
100+
textSlot="Sparks can be of any topic. Use #tags to structure your Sparks. #tags added to the beginning of a Spark are used as context. Try adding your first one."
101+
/>
102+
</div>
103+
);
104+
}
105+
94106
return (
95107
<div className="flex flex-col py-10 bg-white h-full px-8">
96108
{sections?.map((section) => {

0 commit comments

Comments
 (0)