This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Dominique Wirz <[email protected]>
- Loading branch information
Showing
17 changed files
with
529 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,56 @@ | ||
import { Section } from './section'; | ||
import Link from 'next/link'; | ||
import { FC } from 'react'; | ||
|
||
export const Navigation: FC = () => ( | ||
<Section | ||
title="Navigation" | ||
variants={[ | ||
{ | ||
title: 'Meta', | ||
children: ( | ||
<ul style={{ listStyle: 'none', padding: 0 }}> | ||
<li> | ||
<Link href="/">Home</Link> | ||
</li> | ||
<li> | ||
<Link href="/storybook/index.html">Storybook</Link> | ||
</li> | ||
</ul> | ||
), | ||
}, | ||
{ | ||
title: 'Test Server Only Approach', | ||
children: ( | ||
<ul style={{ listStyle: 'none', padding: 0 }}> | ||
<li> | ||
<Link href="/test/50">50 Elements</Link> | ||
</li> | ||
<li> | ||
<Link href="/test/100">100 Elements</Link> | ||
</li> | ||
<li> | ||
<Link href="/test/200">200 Elements</Link> | ||
</li> | ||
<li> | ||
<Link href="/test/500">500 Elements</Link> | ||
</li> | ||
</ul> | ||
), | ||
}, | ||
{ | ||
title: 'Todo App', | ||
children: ( | ||
<ul style={{ listStyle: 'none', padding: 0 }}> | ||
<li> | ||
<Link href="/todo/wrapper">Wrapper Approach</Link> | ||
</li> | ||
<li> | ||
<Link href="/todo/server-only">Server Only Approach</Link> | ||
</li> | ||
</ul> | ||
), | ||
}, | ||
]} | ||
/> | ||
); |
This file contains 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
This file contains 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
This file contains 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,15 @@ | ||
import type { Metadata } from 'next'; | ||
import './styles.css'; | ||
import { Navigation } from '../navigation'; | ||
import { FC, PropsWithChildren } from 'react'; | ||
|
||
export const metadata: Metadata = { title: 'Todo - Next.js ABC Web Components App' }; | ||
|
||
const Layout: FC<PropsWithChildren> = ({ children }) => ( | ||
<> | ||
<Navigation /> | ||
<div id="todo">{children}</div> | ||
</> | ||
); | ||
|
||
export default Layout; |
This file contains 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,16 @@ | ||
'use client'; | ||
|
||
import { AbcTodoInput } from 'abc-web-components-react-wrapper'; | ||
import { WithRSCFallback } from 'abc-web-components-react-wrapper/client'; | ||
import { ComponentProps, FC } from 'react'; | ||
import { useTodo } from './use-todo'; | ||
|
||
export const Input: FC<ComponentProps<typeof WithRSCFallback>> = ({ rsc }) => { | ||
const { list, setList } = useTodo(); | ||
|
||
return ( | ||
<WithRSCFallback rsc={rsc}> | ||
<AbcTodoInput onTodoInputSubmit={({ detail }) => setList([...list, { text: detail, checked: false }])} /> | ||
</WithRSCFallback> | ||
); | ||
}; |
This file contains 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,33 @@ | ||
'use client'; | ||
|
||
import { AbcTodoItem } from 'abc-web-components-react-wrapper'; | ||
import { WithRSCFallback } from 'abc-web-components-react-wrapper/client'; | ||
import { ComponentProps, FC } from 'react'; | ||
import { useTodo } from './use-todo'; | ||
|
||
export const List: FC<ComponentProps<typeof WithRSCFallback>> = ({ rsc }) => { | ||
const { list, setList } = useTodo(); | ||
|
||
return ( | ||
<WithRSCFallback rsc={rsc}> | ||
{list.map(({ checked, text }, index) => { | ||
const props = { checked, text, index }; | ||
|
||
return ( | ||
<AbcTodoItem | ||
{...props} | ||
key={index} | ||
onTodoItemChecked={({ detail }) => { | ||
const copyList = [...list]; | ||
copyList[detail].checked = !copyList[detail].checked; | ||
setList(copyList); | ||
}} | ||
onTodoItemRemove={({ detail }) => { | ||
setList([...list.slice(0, detail), ...list.slice(detail + 1)]); | ||
}} | ||
/> | ||
); | ||
})} | ||
</WithRSCFallback> | ||
); | ||
}; |
This file contains 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,28 @@ | ||
import { AbcTodoInputServerOnly, AbcTodoItemServerOnly } from 'abc-web-components-react-wrapper'; | ||
import { FC } from 'react'; | ||
import { Input } from './input'; | ||
import { List } from './list'; | ||
import { TodoProvider } from './use-todo'; | ||
|
||
const list = [ | ||
{ text: 'my initial todo', checked: false }, | ||
{ text: 'Learn about Web Components', checked: true }, | ||
]; | ||
|
||
const Page: FC = () => ( | ||
<TodoProvider list={list}> | ||
<h1>Todos Stencil</h1> | ||
<section> | ||
<Input rsc={<AbcTodoInputServerOnly />} /> | ||
<ul id="list-container"> | ||
<List | ||
rsc={list.map((props, index) => ( | ||
<AbcTodoItemServerOnly key={index} {...props} index={index} /> | ||
))} | ||
/> | ||
</ul> | ||
</section> | ||
</TodoProvider> | ||
); | ||
|
||
export default Page; |
This file contains 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,23 @@ | ||
'use client'; | ||
|
||
import { FC, PropsWithChildren, createContext, useContext, useState } from 'react'; | ||
|
||
type TodoItem = { text: string; checked: boolean }; | ||
|
||
const TodoContext = createContext({} as { list: TodoItem[]; setList: (list: TodoItem[]) => void }); | ||
|
||
export const TodoProvider: FC<PropsWithChildren<{ list: TodoItem[] }>> = ({ children, list: initialList }) => { | ||
const [list, setList] = useState(initialList); | ||
|
||
return <TodoContext.Provider value={{ list, setList }}>{children}</TodoContext.Provider>; | ||
}; | ||
|
||
export const useTodo = () => { | ||
const context = useContext(TodoContext); | ||
|
||
if (!context.list) { | ||
throw new Error('useTodo must be used within a TodoProvider'); | ||
} | ||
|
||
return context; | ||
}; |
This file contains 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,22 @@ | ||
#todo h1 { | ||
font-size: 100px; | ||
font-weight: 100; | ||
text-align: center; | ||
color: rgba(175, 47, 47, 0.15); | ||
} | ||
|
||
#todo section { | ||
background: #fff; | ||
margin: 130px 0 40px 0; | ||
position: relative; | ||
box-shadow: | ||
0 2px 4px 0 rgba(0, 0, 0, 0.2), | ||
0 25px 50px 0 rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
#list-container { | ||
margin: 0; | ||
padding: 0; | ||
list-style: none; | ||
border-top: 1px solid #e6e6e6; | ||
} |
This file contains 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,48 @@ | ||
'use client'; | ||
|
||
import { AbcTodoInput, AbcTodoItem } from 'abc-web-components-react-wrapper'; | ||
import { AbcWrapper } from 'abc-web-components-react-wrapper/client'; | ||
import { FC, useState } from 'react'; | ||
|
||
type TodoItem = { text: string; checked: boolean }; | ||
const INITIAL_TODOS: TodoItem[] = [ | ||
{ text: 'my initial todo', checked: false }, | ||
{ text: 'Learn about Web Components', checked: true }, | ||
]; | ||
|
||
const Page: FC = () => { | ||
const [list, setList] = useState<TodoItem[]>(INITIAL_TODOS); | ||
|
||
return ( | ||
<AbcWrapper> | ||
<h1>Todos Stencil</h1> | ||
<section> | ||
<AbcTodoInput | ||
onTodoInputSubmit={({ detail }) => { | ||
setList([...list, { text: detail, checked: false }]); | ||
}} | ||
/> | ||
<ul id="list-container"> | ||
{list.map(({ checked, text }, index) => ( | ||
<AbcTodoItem | ||
key={index} | ||
checked={checked} | ||
text={text} | ||
index={index} | ||
onTodoItemChecked={({ detail }) => { | ||
const copyList = [...list]; | ||
copyList[detail].checked = !copyList[detail].checked; | ||
setList(copyList); | ||
}} | ||
onTodoItemRemove={({ detail }) => { | ||
setList([...list.slice(0, detail), ...list.slice(detail + 1)]); | ||
}} | ||
/> | ||
))} | ||
</ul> | ||
</section> | ||
</AbcWrapper> | ||
); | ||
}; | ||
|
||
export default Page; |
Oops, something went wrong.