create-rasti 0.0.1 → 0.1.0-alpha.0
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/README.md +21 -2
- package/extras/cn/src/index.js +14 -1
- package/extras/micro-router/README.md +35 -3
- package/extras/micro-router/package.json +1 -1
- package/extras/micro-router/src/index.js +124 -44
- package/extras/rasti-icons/README.md +15 -5
- package/extras/rasti-icons/src/generate.js +95 -49
- package/package.json +9 -6
- package/src/apply/agents.js +68 -0
- package/src/apply/base.js +1 -1
- package/src/apply/description.js +2 -0
- package/src/apply/featuresInclude.js +3 -2
- package/src/apply/index.js +13 -37
- package/src/apply/router.js +2 -2
- package/src/apply/ssr.js +1 -1
- package/src/apply/typescript.js +38 -0
- package/src/args.js +3 -0
- package/src/cli.js +2 -0
- package/src/plan.js +2 -1
- package/src/prompts.js +17 -0
- package/src/utils/template.js +32 -15
- package/src/versions.js +16 -12
- package/templates/AGENTS.md +31 -8
- package/templates/_base/App-cssfun.js +40 -23
- package/templates/_base/App-cssfun.ts +107 -0
- package/templates/_base/App-tailwind.js +39 -22
- package/templates/_base/App-tailwind.ts +77 -0
- package/templates/_base/App.js +39 -22
- package/templates/_base/App.ts +77 -0
- package/templates/_base/components/Button-cssfun.ts +54 -0
- package/templates/_base/components/Button-tailwind.ts +55 -0
- package/templates/_base/components/Button.ts +25 -0
- package/templates/_base/components/Header-cssfun.ts +71 -0
- package/templates/_base/components/Header-tailwind.ts +19 -0
- package/templates/_base/components/Header.ts +19 -0
- package/templates/_base/components/Home-cssfun.ts +101 -0
- package/templates/_base/components/Home-tailwind.ts +38 -0
- package/templates/_base/components/Home.ts +38 -0
- package/templates/_extras/router/components/About-cssfun.ts +45 -0
- package/templates/_extras/router/components/About-tailwind.ts +16 -0
- package/templates/_extras/router/components/About.ts +18 -0
- package/templates/_extras/router/router-setup.js +21 -21
- package/templates/_extras/router/router-setup.ts +52 -0
- package/templates/_features/cssfun/index.html +1 -1
- package/templates/_features/typescript/tsconfig.json +30 -0
- package/templates/spa/index.html +1 -1
- package/templates/spa/src/main.js +1 -2
- package/templates/spa/src/main.ts +14 -0
- package/templates/ssr/app.js +10 -10
- package/templates/ssr/index.html +1 -1
- package/templates/ssr/package.json +1 -1
- package/templates/ssr/src/entry-client.js +2 -1
- package/templates/ssr/src/entry-client.ts +28 -0
- package/templates/ssr/src/entry-server.js +31 -25
- package/templates/ssr/src/entry-server.ts +62 -0
- package/templates/static/scripts/build-static.js +11 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Component, Model } from 'rasti';
|
|
2
|
+
import { css } from 'cssfun';
|
|
3
|
+
import Header from './components/Header.ts';
|
|
4
|
+
import Home from './components/Home.ts';
|
|
5
|
+
{{#if ROUTER}}
|
|
6
|
+
import About from './components/About.ts';
|
|
7
|
+
import { createAppRouter } from './router-setup.ts';
|
|
8
|
+
import type { Location, Router } from './lib/router.js';
|
|
9
|
+
{{#endif}}
|
|
10
|
+
|
|
11
|
+
const { classes } = css({
|
|
12
|
+
'@global' : {
|
|
13
|
+
body : {
|
|
14
|
+
background : 'var(--fun-bg)',
|
|
15
|
+
color : 'var(--fun-text)',
|
|
16
|
+
margin : 0,
|
|
17
|
+
padding : 0
|
|
18
|
+
},
|
|
19
|
+
'a' : {
|
|
20
|
+
color : 'var(--fun-link)',
|
|
21
|
+
textDecoration : 'none',
|
|
22
|
+
transition : 'color 0.2s ease',
|
|
23
|
+
'&:hover' : { color : 'var(--fun-linkHover)', textDecoration : 'underline' }
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
root : {
|
|
27
|
+
fontFamily : 'system-ui, sans-serif',
|
|
28
|
+
minHeight : '100dvh',
|
|
29
|
+
display : 'flex',
|
|
30
|
+
flexDirection : 'column',
|
|
31
|
+
alignItems : 'center',
|
|
32
|
+
gap : 'clamp(24px, 5vw, 40px)',
|
|
33
|
+
maxWidth : '1000px',
|
|
34
|
+
margin : '0 auto',
|
|
35
|
+
padding : 'clamp(20px, 5vw, 48px)',
|
|
36
|
+
boxSizing : 'border-box'
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
interface AppAttributes {
|
|
41
|
+
count: number;
|
|
42
|
+
{{#if ROUTER}}
|
|
43
|
+
location: Location | null;
|
|
44
|
+
{{#endif}}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Application state. Mutating it re-renders `App`. */
|
|
48
|
+
class AppState extends Model<AppAttributes> {}
|
|
49
|
+
interface AppState extends AppAttributes {} // exposes the attributes on the model
|
|
50
|
+
|
|
51
|
+
{{#if ROUTER}}
|
|
52
|
+
/** Options `App` is created with. Rasti keeps the ones it doesn't reserve as props. */
|
|
53
|
+
export interface AppProps {
|
|
54
|
+
/** URL to route on creation (the request URL on the server). */
|
|
55
|
+
url?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
{{#endif}}
|
|
59
|
+
/** Root application component with the global styles. Owns the state and passes values and callbacks down as props. */
|
|
60
|
+
{{#if ROUTER}}
|
|
61
|
+
class App extends Component<AppProps, AppState> {
|
|
62
|
+
/** Set in `onCreate`, which runs in the base constructor: `declare` keeps a field initializer from resetting it. */
|
|
63
|
+
declare router: Router;
|
|
64
|
+
|
|
65
|
+
onCreate(options: AppProps = {}) {
|
|
66
|
+
this.state = new AppState({ location : null, count : 0 });
|
|
67
|
+
this.router = createAppRouter(this.state);
|
|
68
|
+
this.router.navigate(options.url ?? '/', { addToHistory : false });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
onHydrate() {
|
|
72
|
+
this.destroyQueue.push(
|
|
73
|
+
this.router.delegateNavigation(this.el),
|
|
74
|
+
this.router.bindHistory()
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
{{#else}}
|
|
78
|
+
class App extends Component<{}, AppState> {
|
|
79
|
+
onCreate() {
|
|
80
|
+
this.state = new AppState({ count : 0 });
|
|
81
|
+
}
|
|
82
|
+
{{#endif}}
|
|
83
|
+
|
|
84
|
+
/** Created once per instance, so `Home` doesn't re-render for a new callback on every render. */
|
|
85
|
+
handleIncrement = () => {
|
|
86
|
+
this.state!.count++;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
template() {
|
|
90
|
+
const state = this.state!;
|
|
91
|
+
|
|
92
|
+
return this.html`
|
|
93
|
+
<div class="${classes.root}">
|
|
94
|
+
<${Header} />
|
|
95
|
+
{{#if ROUTER}}
|
|
96
|
+
${state.location?.test('/') ?
|
|
97
|
+
this.html`<${Home} count="${state.count}" handleIncrement=${this.handleIncrement} />` :
|
|
98
|
+
this.html`<${About} />`}
|
|
99
|
+
{{#else}}
|
|
100
|
+
<${Home} count="${state.count}" handleIncrement=${this.handleIncrement} />
|
|
101
|
+
{{#endif}}
|
|
102
|
+
</div>
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export default App;
|
|
@@ -10,49 +10,66 @@ import { createAppRouter } from './router-setup.js';
|
|
|
10
10
|
* @typedef {Object} AppState
|
|
11
11
|
* @property {number} count
|
|
12
12
|
{{#if ROUTER}}
|
|
13
|
-
* @property {import('./router
|
|
13
|
+
* @property {import('./lib/router.js').Location | null} location
|
|
14
14
|
{{#endif}}
|
|
15
15
|
*/
|
|
16
|
+
{{#if ROUTER}}
|
|
16
17
|
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
18
|
+
/**
|
|
19
|
+
* Options `App` is created with. Rasti keeps the ones it doesn't reserve as props.
|
|
20
|
+
* @typedef {Object} AppProps
|
|
21
|
+
* @property {string} [url] - URL to route on creation (the request URL on the server).
|
|
19
22
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
{{#endif}}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Root application component. Owns the state and passes values and callbacks down as props.
|
|
23
27
|
{{#if ROUTER}}
|
|
24
|
-
|
|
25
|
-
partial`<${Home} count="${({ state }) => state.count}" handleIncrement="${({ state }) => () => { state.count++; }}" />` :
|
|
26
|
-
partial`<${About} />`}
|
|
28
|
+
* @extends {Component<AppProps, AppState>}
|
|
27
29
|
{{#else}}
|
|
28
|
-
|
|
30
|
+
* @extends {Component<{}, AppState>}
|
|
29
31
|
{{#endif}}
|
|
30
|
-
|
|
32
|
+
*/
|
|
33
|
+
class App extends Component {
|
|
31
34
|
{{#if ROUTER}}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param {Object} [options]
|
|
35
|
-
* @param {string} [options.url] - Initial URL for server-side routing.
|
|
36
|
-
*/
|
|
35
|
+
/** @param {AppProps} [options] */
|
|
37
36
|
onCreate(options = {}) {
|
|
38
37
|
this.state = new Model({ location : null, count : 0 });
|
|
39
38
|
this.router = createAppRouter(this.state);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
this.router.navigate(options.url ?? '/', { addToHistory : false });
|
|
40
|
+
}
|
|
41
|
+
|
|
43
42
|
onHydrate() {
|
|
44
43
|
this.destroyQueue.push(
|
|
45
44
|
this.router.delegateNavigation(this.el),
|
|
46
45
|
this.router.bindHistory()
|
|
47
46
|
);
|
|
48
47
|
}
|
|
49
|
-
});
|
|
50
48
|
{{#else}}
|
|
51
|
-
`.extend({
|
|
52
49
|
onCreate() {
|
|
53
50
|
this.state = new Model({ count : 0 });
|
|
54
51
|
}
|
|
55
|
-
});
|
|
56
52
|
{{#endif}}
|
|
57
53
|
|
|
54
|
+
/** Created once per instance, so `Home` doesn't re-render for a new callback on every render. */
|
|
55
|
+
handleIncrement = () => {
|
|
56
|
+
this.state.count++;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
template() {
|
|
60
|
+
return this.html`
|
|
61
|
+
<div class="font-sans flex min-h-dvh flex-col items-center gap-6 md:gap-10 max-w-[1000px] mx-auto p-5 md:p-12 box-border text-white">
|
|
62
|
+
<${Header} />
|
|
63
|
+
{{#if ROUTER}}
|
|
64
|
+
${this.state.location?.test('/') ?
|
|
65
|
+
this.html`<${Home} count="${this.state.count}" handleIncrement=${this.handleIncrement} />` :
|
|
66
|
+
this.html`<${About} />`}
|
|
67
|
+
{{#else}}
|
|
68
|
+
<${Home} count="${this.state.count}" handleIncrement=${this.handleIncrement} />
|
|
69
|
+
{{#endif}}
|
|
70
|
+
</div>
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
58
75
|
export default App;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Component, Model } from 'rasti';
|
|
2
|
+
import Header from './components/Header.ts';
|
|
3
|
+
import Home from './components/Home.ts';
|
|
4
|
+
{{#if ROUTER}}
|
|
5
|
+
import About from './components/About.ts';
|
|
6
|
+
import { createAppRouter } from './router-setup.ts';
|
|
7
|
+
import type { Location, Router } from './lib/router.js';
|
|
8
|
+
{{#endif}}
|
|
9
|
+
|
|
10
|
+
interface AppAttributes {
|
|
11
|
+
count: number;
|
|
12
|
+
{{#if ROUTER}}
|
|
13
|
+
location: Location | null;
|
|
14
|
+
{{#endif}}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Application state. Mutating it re-renders `App`. */
|
|
18
|
+
class AppState extends Model<AppAttributes> {}
|
|
19
|
+
interface AppState extends AppAttributes {} // exposes the attributes on the model
|
|
20
|
+
|
|
21
|
+
{{#if ROUTER}}
|
|
22
|
+
/** Options `App` is created with. Rasti keeps the ones it doesn't reserve as props. */
|
|
23
|
+
export interface AppProps {
|
|
24
|
+
/** URL to route on creation (the request URL on the server). */
|
|
25
|
+
url?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
{{#endif}}
|
|
29
|
+
/** Root application component. Owns the state and passes values and callbacks down as props. */
|
|
30
|
+
{{#if ROUTER}}
|
|
31
|
+
class App extends Component<AppProps, AppState> {
|
|
32
|
+
/** Set in `onCreate`, which runs in the base constructor: `declare` keeps a field initializer from resetting it. */
|
|
33
|
+
declare router: Router;
|
|
34
|
+
|
|
35
|
+
onCreate(options: AppProps = {}) {
|
|
36
|
+
this.state = new AppState({ location : null, count : 0 });
|
|
37
|
+
this.router = createAppRouter(this.state);
|
|
38
|
+
this.router.navigate(options.url ?? '/', { addToHistory : false });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onHydrate() {
|
|
42
|
+
this.destroyQueue.push(
|
|
43
|
+
this.router.delegateNavigation(this.el),
|
|
44
|
+
this.router.bindHistory()
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
{{#else}}
|
|
48
|
+
class App extends Component<{}, AppState> {
|
|
49
|
+
onCreate() {
|
|
50
|
+
this.state = new AppState({ count : 0 });
|
|
51
|
+
}
|
|
52
|
+
{{#endif}}
|
|
53
|
+
|
|
54
|
+
/** Created once per instance, so `Home` doesn't re-render for a new callback on every render. */
|
|
55
|
+
handleIncrement = () => {
|
|
56
|
+
this.state!.count++;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
template() {
|
|
60
|
+
const state = this.state!;
|
|
61
|
+
|
|
62
|
+
return this.html`
|
|
63
|
+
<div class="font-sans flex min-h-dvh flex-col items-center gap-6 md:gap-10 max-w-[1000px] mx-auto p-5 md:p-12 box-border text-white">
|
|
64
|
+
<${Header} />
|
|
65
|
+
{{#if ROUTER}}
|
|
66
|
+
${state.location?.test('/') ?
|
|
67
|
+
this.html`<${Home} count="${state.count}" handleIncrement=${this.handleIncrement} />` :
|
|
68
|
+
this.html`<${About} />`}
|
|
69
|
+
{{#else}}
|
|
70
|
+
<${Home} count="${state.count}" handleIncrement=${this.handleIncrement} />
|
|
71
|
+
{{#endif}}
|
|
72
|
+
</div>
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default App;
|
package/templates/_base/App.js
CHANGED
|
@@ -10,49 +10,66 @@ import { createAppRouter } from './router-setup.js';
|
|
|
10
10
|
* @typedef {Object} AppState
|
|
11
11
|
* @property {number} count
|
|
12
12
|
{{#if ROUTER}}
|
|
13
|
-
* @property {import('./router
|
|
13
|
+
* @property {import('./lib/router.js').Location | null} location
|
|
14
14
|
{{#endif}}
|
|
15
15
|
*/
|
|
16
|
+
{{#if ROUTER}}
|
|
16
17
|
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
18
|
+
/**
|
|
19
|
+
* Options `App` is created with. Rasti keeps the ones it doesn't reserve as props.
|
|
20
|
+
* @typedef {Object} AppProps
|
|
21
|
+
* @property {string} [url] - URL to route on creation (the request URL on the server).
|
|
19
22
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
{{#endif}}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Root application component. Owns the state and passes values and callbacks down as props.
|
|
23
27
|
{{#if ROUTER}}
|
|
24
|
-
|
|
25
|
-
partial`<${Home} count="${({ state }) => state.count}" handleIncrement="${({ state }) => () => { state.count++; }}" />` :
|
|
26
|
-
partial`<${About} />`}
|
|
28
|
+
* @extends {Component<AppProps, AppState>}
|
|
27
29
|
{{#else}}
|
|
28
|
-
|
|
30
|
+
* @extends {Component<{}, AppState>}
|
|
29
31
|
{{#endif}}
|
|
30
|
-
|
|
32
|
+
*/
|
|
33
|
+
class App extends Component {
|
|
31
34
|
{{#if ROUTER}}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param {Object} [options]
|
|
35
|
-
* @param {string} [options.url] - Initial URL for server-side routing.
|
|
36
|
-
*/
|
|
35
|
+
/** @param {AppProps} [options] */
|
|
37
36
|
onCreate(options = {}) {
|
|
38
37
|
this.state = new Model({ location : null, count : 0 });
|
|
39
38
|
this.router = createAppRouter(this.state);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
this.router.navigate(options.url ?? '/', { addToHistory : false });
|
|
40
|
+
}
|
|
41
|
+
|
|
43
42
|
onHydrate() {
|
|
44
43
|
this.destroyQueue.push(
|
|
45
44
|
this.router.delegateNavigation(this.el),
|
|
46
45
|
this.router.bindHistory()
|
|
47
46
|
);
|
|
48
47
|
}
|
|
49
|
-
});
|
|
50
48
|
{{#else}}
|
|
51
|
-
`.extend({
|
|
52
49
|
onCreate() {
|
|
53
50
|
this.state = new Model({ count : 0 });
|
|
54
51
|
}
|
|
55
|
-
});
|
|
56
52
|
{{#endif}}
|
|
57
53
|
|
|
54
|
+
/** Created once per instance, so `Home` doesn't re-render for a new callback on every render. */
|
|
55
|
+
handleIncrement = () => {
|
|
56
|
+
this.state.count++;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
template() {
|
|
60
|
+
return this.html`
|
|
61
|
+
<div class="app">
|
|
62
|
+
<${Header} />
|
|
63
|
+
{{#if ROUTER}}
|
|
64
|
+
${this.state.location?.test('/') ?
|
|
65
|
+
this.html`<${Home} count="${this.state.count}" handleIncrement=${this.handleIncrement} />` :
|
|
66
|
+
this.html`<${About} />`}
|
|
67
|
+
{{#else}}
|
|
68
|
+
<${Home} count="${this.state.count}" handleIncrement=${this.handleIncrement} />
|
|
69
|
+
{{#endif}}
|
|
70
|
+
</div>
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
58
75
|
export default App;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Component, Model } from 'rasti';
|
|
2
|
+
import Header from './components/Header.ts';
|
|
3
|
+
import Home from './components/Home.ts';
|
|
4
|
+
{{#if ROUTER}}
|
|
5
|
+
import About from './components/About.ts';
|
|
6
|
+
import { createAppRouter } from './router-setup.ts';
|
|
7
|
+
import type { Location, Router } from './lib/router.js';
|
|
8
|
+
{{#endif}}
|
|
9
|
+
|
|
10
|
+
interface AppAttributes {
|
|
11
|
+
count: number;
|
|
12
|
+
{{#if ROUTER}}
|
|
13
|
+
location: Location | null;
|
|
14
|
+
{{#endif}}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Application state. Mutating it re-renders `App`. */
|
|
18
|
+
class AppState extends Model<AppAttributes> {}
|
|
19
|
+
interface AppState extends AppAttributes {} // exposes the attributes on the model
|
|
20
|
+
|
|
21
|
+
{{#if ROUTER}}
|
|
22
|
+
/** Options `App` is created with. Rasti keeps the ones it doesn't reserve as props. */
|
|
23
|
+
export interface AppProps {
|
|
24
|
+
/** URL to route on creation (the request URL on the server). */
|
|
25
|
+
url?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
{{#endif}}
|
|
29
|
+
/** Root application component. Owns the state and passes values and callbacks down as props. */
|
|
30
|
+
{{#if ROUTER}}
|
|
31
|
+
class App extends Component<AppProps, AppState> {
|
|
32
|
+
/** Set in `onCreate`, which runs in the base constructor: `declare` keeps a field initializer from resetting it. */
|
|
33
|
+
declare router: Router;
|
|
34
|
+
|
|
35
|
+
onCreate(options: AppProps = {}) {
|
|
36
|
+
this.state = new AppState({ location : null, count : 0 });
|
|
37
|
+
this.router = createAppRouter(this.state);
|
|
38
|
+
this.router.navigate(options.url ?? '/', { addToHistory : false });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onHydrate() {
|
|
42
|
+
this.destroyQueue.push(
|
|
43
|
+
this.router.delegateNavigation(this.el),
|
|
44
|
+
this.router.bindHistory()
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
{{#else}}
|
|
48
|
+
class App extends Component<{}, AppState> {
|
|
49
|
+
onCreate() {
|
|
50
|
+
this.state = new AppState({ count : 0 });
|
|
51
|
+
}
|
|
52
|
+
{{#endif}}
|
|
53
|
+
|
|
54
|
+
/** Created once per instance, so `Home` doesn't re-render for a new callback on every render. */
|
|
55
|
+
handleIncrement = () => {
|
|
56
|
+
this.state!.count++;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
template() {
|
|
60
|
+
const state = this.state!;
|
|
61
|
+
|
|
62
|
+
return this.html`
|
|
63
|
+
<div class="app">
|
|
64
|
+
<${Header} />
|
|
65
|
+
{{#if ROUTER}}
|
|
66
|
+
${state.location?.test('/') ?
|
|
67
|
+
this.html`<${Home} count="${state.count}" handleIncrement=${this.handleIncrement} />` :
|
|
68
|
+
this.html`<${About} />`}
|
|
69
|
+
{{#else}}
|
|
70
|
+
<${Home} count="${state.count}" handleIncrement=${this.handleIncrement} />
|
|
71
|
+
{{#endif}}
|
|
72
|
+
</div>
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default App;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Component } from 'rasti';
|
|
2
|
+
import type { ComponentPartial } from 'rasti';
|
|
3
|
+
import { css } from 'cssfun';
|
|
4
|
+
import cn from '../lib/cn.js';
|
|
5
|
+
|
|
6
|
+
const { classes } = css({
|
|
7
|
+
root : {
|
|
8
|
+
display : 'inline-flex',
|
|
9
|
+
alignItems : 'center',
|
|
10
|
+
justifyContent : 'center',
|
|
11
|
+
minHeight : '52px',
|
|
12
|
+
minWidth : '200px',
|
|
13
|
+
padding : '0 32px',
|
|
14
|
+
fontSize : '20px',
|
|
15
|
+
fontWeight : '650',
|
|
16
|
+
color : 'inherit',
|
|
17
|
+
background : 'var(--fun-buttonBg)',
|
|
18
|
+
border : '1px solid var(--fun-buttonBorder)',
|
|
19
|
+
borderRadius : '999px',
|
|
20
|
+
cursor : 'pointer',
|
|
21
|
+
boxShadow : 'inset 0 1px 0 rgba(255, 255, 255, 0.1), var(--fun-buttonShadow)',
|
|
22
|
+
backdropFilter : 'blur(16px)',
|
|
23
|
+
transition : 'border-color 0.2s ease, background 0.2s ease, transform 0.15s ease',
|
|
24
|
+
'&:hover' : {
|
|
25
|
+
borderColor : 'var(--fun-buttonHoverBorder)',
|
|
26
|
+
background : 'var(--fun-buttonHoverBg)'
|
|
27
|
+
},
|
|
28
|
+
'&:active' : {
|
|
29
|
+
transform : 'scale(0.985)'
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export interface ButtonProps {
|
|
35
|
+
/** Click handler. */
|
|
36
|
+
handleClick: (event: MouseEvent) => void;
|
|
37
|
+
/** Additional CSS classes. */
|
|
38
|
+
className?: string;
|
|
39
|
+
/** The content between the tags, passed by Rasti. */
|
|
40
|
+
renderChildren: () => ComponentPartial;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Reusable styled button. Renders children via props.renderChildren(). */
|
|
44
|
+
class Button extends Component<ButtonProps> {
|
|
45
|
+
template() {
|
|
46
|
+
return this.html`
|
|
47
|
+
<button class="${cn(classes.root, this.props.className)}" onClick=${this.props.handleClick}>
|
|
48
|
+
${this.props.renderChildren()}
|
|
49
|
+
</button>
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default Button;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Component } from 'rasti';
|
|
2
|
+
import type { ComponentPartial } from 'rasti';
|
|
3
|
+
import cn from '../lib/cn.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The base classes for the button.
|
|
7
|
+
*/
|
|
8
|
+
const BASE_CLASSES = [
|
|
9
|
+
'inline-flex',
|
|
10
|
+
'items-center',
|
|
11
|
+
'justify-center',
|
|
12
|
+
'rounded-full',
|
|
13
|
+
'border',
|
|
14
|
+
'border-white/12',
|
|
15
|
+
'bg-linear-to-b',
|
|
16
|
+
'from-[#5ee9df]/20',
|
|
17
|
+
'to-white/6',
|
|
18
|
+
'text-white',
|
|
19
|
+
'shadow-[inset_0_1px_0_rgba(255,255,255,0.1),0_6px_20px_rgba(0,0,0,0.18)]',
|
|
20
|
+
'backdrop-blur-md',
|
|
21
|
+
'transition-[border-color,background,transform]',
|
|
22
|
+
'duration-200',
|
|
23
|
+
'hover:border-[#5ee9df]/40',
|
|
24
|
+
'hover:from-[#5ee9df]/28',
|
|
25
|
+
'hover:to-white/10',
|
|
26
|
+
'active:scale-[0.985]',
|
|
27
|
+
'active:duration-150',
|
|
28
|
+
'min-h-13',
|
|
29
|
+
'min-w-[200px]',
|
|
30
|
+
'px-8',
|
|
31
|
+
'text-xl',
|
|
32
|
+
'font-[650]'
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
export interface ButtonProps {
|
|
36
|
+
/** Click handler. */
|
|
37
|
+
handleClick: (event: MouseEvent) => void;
|
|
38
|
+
/** Additional CSS classes. */
|
|
39
|
+
className?: string;
|
|
40
|
+
/** The content between the tags, passed by Rasti. */
|
|
41
|
+
renderChildren: () => ComponentPartial;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Reusable styled button. Renders children via props.renderChildren(). */
|
|
45
|
+
class Button extends Component<ButtonProps> {
|
|
46
|
+
template() {
|
|
47
|
+
return this.html`
|
|
48
|
+
<button class="${cn(BASE_CLASSES, this.props.className)}" onClick=${this.props.handleClick}>
|
|
49
|
+
${this.props.renderChildren()}
|
|
50
|
+
</button>
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default Button;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Component } from 'rasti';
|
|
2
|
+
import type { ComponentPartial } from 'rasti';
|
|
3
|
+
import cn from '../lib/cn.js';
|
|
4
|
+
|
|
5
|
+
export interface ButtonProps {
|
|
6
|
+
/** Click handler. */
|
|
7
|
+
handleClick: (event: MouseEvent) => void;
|
|
8
|
+
/** Additional CSS classes. */
|
|
9
|
+
className?: string;
|
|
10
|
+
/** The content between the tags, passed by Rasti. */
|
|
11
|
+
renderChildren: () => ComponentPartial;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Reusable styled button. Renders children via props.renderChildren(). */
|
|
15
|
+
class Button extends Component<ButtonProps> {
|
|
16
|
+
template() {
|
|
17
|
+
return this.html`
|
|
18
|
+
<button class="${cn('button', this.props.className)}" onClick=${this.props.handleClick}>
|
|
19
|
+
${this.props.renderChildren()}
|
|
20
|
+
</button>
|
|
21
|
+
`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default Button;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Component } from 'rasti';
|
|
2
|
+
import { css } from 'cssfun';
|
|
3
|
+
import cn from '../lib/cn.js';
|
|
4
|
+
import Button from './Button.ts';
|
|
5
|
+
|
|
6
|
+
const { classes } = css({
|
|
7
|
+
root : {
|
|
8
|
+
display : 'flex',
|
|
9
|
+
alignItems : 'center',
|
|
10
|
+
width : '100%'
|
|
11
|
+
},
|
|
12
|
+
nav : {
|
|
13
|
+
display : 'flex',
|
|
14
|
+
gap : '16px'
|
|
15
|
+
},
|
|
16
|
+
actions : {
|
|
17
|
+
display : 'flex',
|
|
18
|
+
gap : '10px',
|
|
19
|
+
marginLeft : 'auto'
|
|
20
|
+
},
|
|
21
|
+
showWhenLight : {
|
|
22
|
+
display : 'var(--fun-showWhenLight)'
|
|
23
|
+
},
|
|
24
|
+
showWhenDark : {
|
|
25
|
+
display : 'var(--fun-showWhenDark)'
|
|
26
|
+
},
|
|
27
|
+
buttonSm : {
|
|
28
|
+
minHeight : '40px',
|
|
29
|
+
minWidth : 'auto',
|
|
30
|
+
padding : '0 16px',
|
|
31
|
+
fontSize : '13px',
|
|
32
|
+
fontWeight : '600',
|
|
33
|
+
letterSpacing : '0.01em'
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function setColorScheme(mode: 'light' | 'dark') {
|
|
38
|
+
if (typeof document !== 'undefined') document.documentElement.setAttribute('data-color-scheme', mode);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** App header (cssfun): light/dark theme toggle, and navigation when router is enabled. */
|
|
42
|
+
class Header extends Component {
|
|
43
|
+
template() {
|
|
44
|
+
return this.html`
|
|
45
|
+
<header class="${classes.root}">
|
|
46
|
+
{{#if ROUTER}}
|
|
47
|
+
<nav class="${classes.nav}">
|
|
48
|
+
<a data-router href="/">Home</a>
|
|
49
|
+
<a data-router href="{{ROUTE_ABOUT}}">About</a>
|
|
50
|
+
</nav>
|
|
51
|
+
{{#endif}}
|
|
52
|
+
<div class="${classes.actions}">
|
|
53
|
+
<${Button}
|
|
54
|
+
className=${cn(classes.buttonSm, classes.showWhenDark)}
|
|
55
|
+
handleClick=${() => setColorScheme('light')}
|
|
56
|
+
>
|
|
57
|
+
Light
|
|
58
|
+
</${Button}>
|
|
59
|
+
<${Button}
|
|
60
|
+
className=${cn(classes.buttonSm, classes.showWhenLight)}
|
|
61
|
+
handleClick=${() => setColorScheme('dark')}
|
|
62
|
+
>
|
|
63
|
+
Dark
|
|
64
|
+
</${Button}>
|
|
65
|
+
</div>
|
|
66
|
+
</header>
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default Header;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Component } from 'rasti';
|
|
2
|
+
|
|
3
|
+
/** App header: navigation (when router is enabled). */
|
|
4
|
+
class Header extends Component {
|
|
5
|
+
template() {
|
|
6
|
+
return this.html`
|
|
7
|
+
<header class="flex w-full items-center">
|
|
8
|
+
{{#if ROUTER}}
|
|
9
|
+
<nav class="flex gap-6">
|
|
10
|
+
<a data-router href="/">Home</a>
|
|
11
|
+
<a data-router href="{{ROUTE_ABOUT}}">About</a>
|
|
12
|
+
</nav>
|
|
13
|
+
{{#endif}}
|
|
14
|
+
</header>
|
|
15
|
+
`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default Header;
|