Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSC: Add css files to the example #8905

Merged
merged 2 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/cli/src/commands/experimental/setupRscHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,41 @@ export const handler = async ({ force, verbose }) => {
})
},
},
{
title: 'Adding CSS files...',
task: async () => {
const files = [
{
template: 'Counter.css.template',
path: 'Counter.css',
},
{
template: 'Counter.module.css.template',
path: 'Counter.module.css',
},
{
template: 'App.css.template',
path: 'App.css',
},
{
template: 'App.module.css.template',
path: 'App.module.css',
},
]

files.forEach((file) => {
const template = fs.readFileSync(
path.resolve(__dirname, 'templates', 'rsc', file.template),
'utf-8'
)
const filePath = path.join(rwPaths.web.src, file.path)

writeFile(filePath, template, {
overwriteExisting: force,
})
})
},
},
{
title: 'Updating index.html...',
task: async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1 {
text-decoration: underline;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.title {
color: green;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import { Assets } from '@redwoodjs/vite/assets'
import { ProdRwRscServerGlobal } from '@redwoodjs/vite/rwRscGlobal'

// @ts-expect-error no types
import styles from './App.module.css'
import { Counter } from './Counter'

import './App.css'

// TODO (RSC) Something like this will probably be needed
// const RwRscGlobal = import.meta.env.PROD ? ProdRwRscServerGlobal : DevRwRscServerGlobal;

globalThis.rwRscGlobal = new ProdRwRscServerGlobal()

const App = ({ name = 'Anonymous' }) => {
return (
<div style={{ border: '3px red dashed', margin: '1em', padding: '1em' }}>
<h1>Hello {name}!!</h1>
<h3>This is a server component.</h3>
<Counter />
</div>
<>
{/* TODO (RSC) <Assets /> should be part of the router later */}
<Assets />
<div style={{ border: '3px red dashed', margin: '1em', padding: '1em' }}>
<h1 className={styles.title}>Hello {name}!!</h1>
<h3>This is a server component.</h3>
<Counter />
</div>
</>
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* This should affect all h3 elements on the page, both server components and
* client components. This is just standard CSS stuff
*/
h3 {
color: orange;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.header {
font-style: italic;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import React from 'react'

// @ts-expect-error no types
import styles from './Counter.module.css'
import './Counter.css'

export const Counter = () => {
const [count, setCount] = React.useState(0)

return (
<div style={{ border: '3px blue dashed', margin: '1em', padding: '1em' }}>
<p>Count: {count}</p>
<button onClick={() => setCount((c) => c + 1)}>Increment</button>
<h3>This is a client component.</h3>
<h3 className={styles.header}>This is a client component.</h3>
</div>
)
}