-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rkrupinski/example
example
- Loading branch information
Showing
24 changed files
with
1,740 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,64 @@ | ||
# @rkrupinski/react | ||
|
||
An experimental, lightweight [React](https://react.dev/) alternative. | ||
|
||
- [Getting started](#getting-started) | ||
|
||
## Getting started | ||
|
||
Install: | ||
|
||
``` | ||
yarn add @rkrupinski/react | ||
``` | ||
|
||
Make sure to set: | ||
|
||
```json | ||
{ | ||
"jsx": "react" | ||
} | ||
``` | ||
|
||
in your `tsconfig.json` -> `"compilerOptions"`. | ||
|
||
Now you're all set: | ||
|
||
```tsx | ||
/* @jsx createElement */ | ||
/* @jsxFrag Fragment */ | ||
|
||
import { | ||
render, | ||
useState, | ||
useEffect, | ||
createElement, | ||
Fragment, | ||
type FC, | ||
} from "@rkrupinski/react"; | ||
|
||
const App: FC = () => { | ||
const [clicked, setClicked] = useState(0); | ||
|
||
useEffect(() => { | ||
console.log(`Clicked ${clicked} times`); | ||
}, [clicked]); | ||
|
||
return ( | ||
<> | ||
<h1>Hello!</h1> | ||
<button | ||
onClick={() => { | ||
setClicked((c) => c + 1); | ||
}} | ||
> | ||
{clicked} | ||
</button> | ||
</> | ||
); | ||
}; | ||
|
||
const root = document.querySelector("#root") as HTMLElement; | ||
|
||
render(<App />, root); | ||
``` |
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 @@ | ||
"@rkrupinski/prettierconfig" |
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,3 @@ | ||
# @rkrupinski/react | ||
|
||
- [Docs](https://github.com/rkrupinski/react#readme) |
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,18 @@ | ||
{ | ||
"name": "example", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"clean": "rm -rf dist", | ||
"start": "parcel src/index.html --open", | ||
"build": "parcel build src/index.html" | ||
}, | ||
"dependencies": { | ||
"@rkrupinski/react": "*", | ||
"todomvc-app-css": "2.4.2" | ||
}, | ||
"devDependencies": { | ||
"@rkrupinski/prettierconfig": "1.0.1", | ||
"parcel": "2.9.3" | ||
} | ||
} |
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,43 @@ | ||
/* @jsx createElement */ | ||
|
||
import { | ||
createElement, | ||
useState, | ||
useCallback, | ||
type FC, | ||
} from '@rkrupinski/react'; | ||
|
||
export type TodoInputProps = { | ||
onNewTodo: (text: string) => void; | ||
}; | ||
|
||
export const TodoInput: FC<TodoInputProps> = ({ onNewTodo }) => { | ||
const [text, setText] = useState(''); | ||
|
||
const handleInput = useCallback( | ||
(e: any) => { | ||
setText(e.target.value); | ||
}, | ||
[setText], | ||
); | ||
|
||
const handleKeyDown = useCallback( | ||
(e: any) => { | ||
if (e.keyCode !== 13) return; | ||
|
||
onNewTodo(e.target.value); | ||
setText(''); | ||
}, | ||
[onNewTodo, setText], | ||
); | ||
|
||
return ( | ||
<input | ||
value={text} | ||
onInput={handleInput} | ||
onKeyDown={handleKeyDown} | ||
className="new-todo" | ||
placeholder="What needs to be done?" | ||
/> | ||
); | ||
}; |
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 @@ | ||
export * from './TodoInput'; |
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,26 @@ | ||
/* @jsx createElement */ | ||
|
||
import { createElement, type FC } from '@rkrupinski/react'; | ||
|
||
import type { Todo } from '../../types'; | ||
|
||
export type TodoItemProps = { | ||
data: Todo; | ||
onToggle: (todo: Todo) => void; | ||
onDestroy: (todo: Todo) => void; | ||
}; | ||
|
||
export const TodoItem: FC<TodoItemProps> = ({ data, onToggle, onDestroy }) => ( | ||
<li className={data.completed ? 'completed' : ''}> | ||
<div className="view"> | ||
<input | ||
className="toggle" | ||
type="checkbox" | ||
checked={data.completed} | ||
onChange={() => onToggle(data)} | ||
/> | ||
<label>{data.body}</label> | ||
<button className="destroy" onClick={() => onDestroy(data)} /> | ||
</div> | ||
</li> | ||
); |
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 @@ | ||
export * from './TodoItem'; |
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,25 @@ | ||
/* @jsx createElement */ | ||
|
||
import { createElement, type FC } from '@rkrupinski/react'; | ||
|
||
import type { Todo } from '../../types'; | ||
import { TodoItem } from '../TodoItem'; | ||
|
||
export type TodoListProps = { | ||
todos: Todo[]; | ||
onToggle: (todo: Todo) => void; | ||
onDestroy: (todo: Todo) => void; | ||
}; | ||
|
||
export const TodoList: FC<TodoListProps> = ({ todos, onToggle, onDestroy }) => ( | ||
<ul className="todo-list"> | ||
{todos.map(todo => ( | ||
<TodoItem | ||
key={todo.id} | ||
data={todo} | ||
onToggle={onToggle} | ||
onDestroy={onDestroy} | ||
/> | ||
))} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './TodoList'; |
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,26 @@ | ||
/* @jsx createElement */ | ||
|
||
import { createElement, type FC } from '@rkrupinski/react'; | ||
|
||
import { view, type View } from '../../types'; | ||
|
||
export type TodoNavProps = { | ||
current: View; | ||
onChange: (newView: View) => void; | ||
}; | ||
|
||
export const TodoNav: FC<TodoNavProps> = ({ current, onChange }) => ( | ||
<ul className="filters"> | ||
{view.map(v => ( | ||
<li key={v}> | ||
<a | ||
className={v === current ? 'selected' : ''} | ||
href={`#${v}`} | ||
onClick={() => onChange(v)} | ||
> | ||
{v} | ||
</a> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './TodoNav'; |
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,36 @@ | ||
/* @jsx createElement */ | ||
/* @jsxFrag Fragment */ | ||
|
||
import { | ||
createElement, | ||
Fragment, | ||
useCallback, | ||
type FC, | ||
} from '@rkrupinski/react'; | ||
|
||
export type ToggleAllProps = { | ||
all: boolean; | ||
onToggle: (all: boolean) => void; | ||
}; | ||
|
||
export const ToggleAll: FC<ToggleAllProps> = ({ all, onToggle }) => { | ||
const handleToggle = useCallback( | ||
(e: any) => { | ||
onToggle(e.target.checked); | ||
}, | ||
[onToggle], | ||
); | ||
|
||
return ( | ||
<> | ||
<input | ||
id="toggle-all" | ||
className="toggle-all" | ||
type="checkbox" | ||
checked={all} | ||
onChange={handleToggle} | ||
/> | ||
<label for="toggle-all" /> | ||
</> | ||
); | ||
}; |
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 @@ | ||
export * from './ToggleAll'; |
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,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>@rkrupinski/react</title> | ||
<script type="module" src="index.tsx"></script> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
Oops, something went wrong.