@stanlemon/app-template 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/App.tsx +56 -29
- package/src/Input.tsx +16 -10
- package/src/Login.tsx +1 -0
- package/src/Register.tsx +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stanlemon/app-template",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "A template for creating apps using the webdev package.",
|
|
5
5
|
"author": "Stan Lemon <stanlemon@users.noreply.github.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"start": "node app.js",
|
|
10
10
|
"build": "npm run webpack:build",
|
|
11
|
+
"tsc": "tsc",
|
|
11
12
|
"webpack:serve": "webpack serve",
|
|
12
13
|
"webpack:build": "NODE_ENV=production webpack",
|
|
13
14
|
"test": "jest",
|
package/src/App.tsx
CHANGED
|
@@ -22,6 +22,7 @@ export type Session = {
|
|
|
22
22
|
token: string | null;
|
|
23
23
|
user: User | null;
|
|
24
24
|
};
|
|
25
|
+
|
|
25
26
|
export type User = {
|
|
26
27
|
name: string | null;
|
|
27
28
|
email: string | null;
|
|
@@ -78,42 +79,68 @@ export default function App() {
|
|
|
78
79
|
return (
|
|
79
80
|
<SessionContext.Provider value={contextValue}>
|
|
80
81
|
<Header />
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
<
|
|
85
|
-
<em>You are not currently logged in.</em>
|
|
86
|
-
</p>
|
|
82
|
+
{!session && (
|
|
83
|
+
<Row>
|
|
84
|
+
<Column>
|
|
85
|
+
<h2>Login</h2>
|
|
87
86
|
<Login />
|
|
88
|
-
|
|
87
|
+
</Column>
|
|
88
|
+
<Column>
|
|
89
|
+
<h2>Register</h2>
|
|
89
90
|
<Register />
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
</Column>
|
|
92
|
+
</Row>
|
|
93
|
+
)}
|
|
94
|
+
{session?.user && (
|
|
95
|
+
<>
|
|
94
96
|
<p>
|
|
95
97
|
<em>You logged in as {session.user.username}.</em>
|
|
96
98
|
</p>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
</ul>
|
|
99
|
+
<Input
|
|
100
|
+
label="Item"
|
|
101
|
+
name="item"
|
|
102
|
+
value={value}
|
|
103
|
+
onChange={(value) => setValue(value)}
|
|
104
|
+
onEnter={addItem}
|
|
105
|
+
/>
|
|
106
|
+
<button onClick={addItem}>Add</button>
|
|
107
|
+
<ul>
|
|
108
|
+
{items.map((item, i) => (
|
|
109
|
+
<li key={i}>{item}</li>
|
|
110
|
+
))}
|
|
111
|
+
</ul>
|
|
112
|
+
</>
|
|
113
|
+
)}
|
|
113
114
|
</SessionContext.Provider>
|
|
114
115
|
);
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
function
|
|
118
|
-
return
|
|
118
|
+
function Row({ children }: { children: React.ReactNode }) {
|
|
119
|
+
return (
|
|
120
|
+
<div
|
|
121
|
+
style={{
|
|
122
|
+
display: "flex",
|
|
123
|
+
flexDirection: "row",
|
|
124
|
+
flexWrap: "wrap",
|
|
125
|
+
width: "100%",
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
{children}
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function Column({ children }: { children: React.ReactNode }) {
|
|
134
|
+
return (
|
|
135
|
+
<div
|
|
136
|
+
style={{
|
|
137
|
+
display: "flex",
|
|
138
|
+
flexDirection: "column",
|
|
139
|
+
flexBasis: "100%",
|
|
140
|
+
flex: 1,
|
|
141
|
+
}}
|
|
142
|
+
>
|
|
143
|
+
{children}
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
119
146
|
}
|
package/src/Input.tsx
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
export interface Props
|
|
2
|
+
// Inherit everything from input except onChange which we simplify here
|
|
3
|
+
extends Omit<React.ComponentPropsWithRef<"input">, "onChange"> {
|
|
4
|
+
type?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
value?: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
onChange?: (value: string) => void;
|
|
10
|
+
onEnter?: () => void;
|
|
11
|
+
error?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
1
14
|
export default function Input({
|
|
2
15
|
type = "text",
|
|
3
16
|
name,
|
|
@@ -11,16 +24,8 @@ export default function Input({
|
|
|
11
24
|
/* noop */
|
|
12
25
|
},
|
|
13
26
|
error,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
name: string;
|
|
17
|
-
value?: string;
|
|
18
|
-
label?: string;
|
|
19
|
-
placeholder?: string;
|
|
20
|
-
onChange?: (value: string) => void;
|
|
21
|
-
onEnter?: () => void;
|
|
22
|
-
error?: string;
|
|
23
|
-
}) {
|
|
27
|
+
...attrs
|
|
28
|
+
}: Props) {
|
|
24
29
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
|
|
25
30
|
onChange(e.currentTarget.value);
|
|
26
31
|
};
|
|
@@ -41,6 +46,7 @@ export default function Input({
|
|
|
41
46
|
onKeyPress={handleKeyPress}
|
|
42
47
|
placeholder={placeholder}
|
|
43
48
|
value={value}
|
|
49
|
+
{...attrs}
|
|
44
50
|
/>
|
|
45
51
|
{error && <div>{error}</div>}
|
|
46
52
|
</>
|
package/src/Login.tsx
CHANGED