Skip to content

Commit

Permalink
Add recipe list component
Browse files Browse the repository at this point in the history
  • Loading branch information
ertrzyiks committed Aug 7, 2023
1 parent 6789a0e commit 6ebe2a6
Show file tree
Hide file tree
Showing 10 changed files with 1,017 additions and 38 deletions.
20 changes: 12 additions & 8 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import type { StorybookConfig } from "@storybook/nextjs";
import type { StorybookConfig } from '@storybook/nextjs';

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-onboarding",
"@storybook/addon-interactions",
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-onboarding',
'@storybook/addon-interactions',
{
name: '@storybook/addon-styling',
options: {},
},
],
framework: {
name: "@storybook/nextjs",
name: '@storybook/nextjs',
options: {},
},
docs: {
autodocs: "tag",
autodocs: 'tag',
},
};
export default config;
20 changes: 18 additions & 2 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import type { Preview } from "@storybook/react";
import type { Preview } from '@storybook/react';

import { withThemeByClassName } from '@storybook/addon-styling';

import '../src/app/globals.css';

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},

decorators: [
// Adds theme switching support.
// NOTE: requires setting "darkMode" to "class" in your tailwind config
withThemeByClassName({
themes: {
light: 'light',
dark: 'dark',
},
defaultTheme: 'light',
}),
],
};

export default preview;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@storybook/addon-interactions": "^7.1.1",
"@storybook/addon-links": "^7.1.1",
"@storybook/addon-onboarding": "^1.0.8",
"@storybook/addon-styling": "^1.3.5",
"@storybook/blocks": "^7.1.1",
"@storybook/nextjs": "^7.1.1",
"@storybook/react": "^7.1.1",
Expand Down
17 changes: 9 additions & 8 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PrismaClient } from '@prisma/client'
import Link from 'next/link'
import { RecipeListItem } from '@/components/recipe-list-item/recipe-list-item'
import { RecipeList } from '@/components/recipe-list/recipe-list'
import { Search } from '@/components/search/search'

const prisma = new PrismaClient()
Expand All @@ -17,15 +18,15 @@ export default async function Home() {
<Search />
</div>

<div>
<RecipeList>
{recipes.map((recipe) => (
<div key={recipe.id} className="flex place-items-center">
<Link href={`/${recipe.category.slug}/${recipe.slug}`}>
{recipe.title}
</Link>
</div>
<RecipeListItem
key={recipe.id}
href={`/${recipe.category.slug}/${recipe.slug}`}
title={recipe.title}
/>
))}
</div>
</RecipeList>
</main >
)
}
19 changes: 11 additions & 8 deletions src/app/search/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Link from 'next/link'
import { SearchForm } from '@/components/search-form/search-form'
import { search } from '@/lib/search'
import { RecipeListItem } from '@/components/recipe-list-item/recipe-list-item'
import { RecipeList } from '@/components/recipe-list/recipe-list'

interface Props {
searchParams: { query: string }
Expand All @@ -15,13 +16,15 @@ export default async function Home({ searchParams }: Props) {
<main className="flex flex-col items-center">
<SearchForm query={query} />

{recipes.map((recipe) => (
<div key={recipe.id} className="flex place-items-center">
<Link href={`/${recipe.category.slug}/${recipe.slug}`}>
{recipe.title}
</Link>
</div>
))}
<RecipeList>
{recipes.map((recipe) => (
<RecipeListItem
key={recipe.id}
href={`/${recipe.category.slug}/${recipe.slug}`}
title={recipe.title}
/>
))}
</RecipeList>
</main >
)
}
7 changes: 2 additions & 5 deletions src/components/recipe-list-item/recipe-list-item.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { RecipeListItem } from './recipe-list-item';
const meta = {
title: 'UI/RecipeListItem',
component: RecipeListItem,
parameters: {
layout: 'centered',
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
tags: ['autodocs'],

Expand All @@ -21,7 +18,7 @@ type Story = StoryObj<typeof meta>;
// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const Primary: Story = {
args: {
primary: true,
label: 'Button',
href: '/',
title: 'Spaghetti',
},
};
14 changes: 12 additions & 2 deletions src/components/recipe-list-item/recipe-list-item.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
export function RecipeListItem() {
return <div>Siema</div>
import Link from 'next/link'
interface Props {
href: string
title: string
}

export function RecipeListItem({ href, title }: Props) {
return (
<Link className='block w-full border px-2 py-1' href={href}>
{title}
</Link>
)
}
29 changes: 29 additions & 0 deletions src/components/recipe-list/recipe-list.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Meta, StoryObj } from '@storybook/react';

import { RecipeList } from './recipe-list';
import { RecipeListItem } from '../recipe-list-item/recipe-list-item';

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
const meta = {
title: 'UI/RecipeList',
component: RecipeList,
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
tags: ['autodocs'],

} satisfies Meta<typeof RecipeList>;


export default meta;
type Story = StoryObj<typeof meta>;

// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const Primary: Story = {
args: {
children: [
<RecipeListItem href='/' title='Recipe 1' />,
<RecipeListItem href='/' title='Recipe 2' />,
<RecipeListItem href='/' title='Recipe 3' />,
<RecipeListItem href='/' title='Recipe 4' />,
]
},
};
7 changes: 7 additions & 0 deletions src/components/recipe-list/recipe-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function RecipeList({ children }: { children: React.ReactNode }) {
return (
<div className="flex flex-col gap-2 place-items-center">
{children}
</div>
)
}
Loading

0 comments on commit 6ebe2a6

Please sign in to comment.