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

Convert with-cssed, with-csx, with-styled-jsx examples to TypeScript #43018

Merged
merged 3 commits into from Nov 17, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/with-cssed/.gitignore
Expand Up @@ -34,3 +34,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# cssed compilation artifacts
.*.module.css
File renamed without changes.
11 changes: 8 additions & 3 deletions examples/with-cssed/package.json
Expand Up @@ -6,11 +6,16 @@
"start": "next start"
},
"dependencies": {
"@types/react": "^16.9.48",
"babel-plugin-macros": "^2.8.0",
"cssed": "^1.1.2",
"babel-plugin-macros": "^3.1.0",
"cssed": "^1.1.5",
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"typescript": "^4.9.3"
}
}
Expand Up @@ -31,13 +31,14 @@ const styles = css`

export default function Home() {
const [isDark, setDark] = useState(false)

return (
<>
<Head>
<title>With cssed</title>
</Head>
<div
onClick={() => setDark(!isDark)}
onClick={() => setDark((prevState) => !prevState)}
className={styles.box + ' ' + (isDark ? styles.dark : styles.light)}
>
Cssed demo
Expand Down
20 changes: 20 additions & 0 deletions examples/with-cssed/tsconfig.json
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
9 changes: 8 additions & 1 deletion examples/with-cxs/package.json
Expand Up @@ -6,9 +6,16 @@
"start": "next start"
},
"dependencies": {
"cxs": "^3.0.0",
"cxs": "^6.2.0",
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/cxs": "^6.2.1",
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"typescript": "^4.9.3"
}
}
27 changes: 0 additions & 27 deletions examples/with-cxs/pages/_document.js

This file was deleted.

35 changes: 35 additions & 0 deletions examples/with-cxs/pages/_document.tsx
@@ -0,0 +1,35 @@
import type { DocumentContext, DocumentInitialProps } from 'next/document'
import Document, { Html, Head, Main, NextScript } from 'next/document'
import cxs from 'cxs'

export default class MyDocument extends Document {
static async getInitialProps(
ctx: DocumentContext
): Promise<DocumentInitialProps> {
const initialProps = await Document.getInitialProps(ctx)
const styles = cxs.css()
cxs.reset()

return {
...initialProps,
styles: (
<>
{initialProps.styles}
<style dangerouslySetInnerHTML={{ __html: styles }} />
</>
),
}
}

render() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}
@@ -1,12 +1,4 @@
import cxs from 'cxs/lite'

// Using cxs/lite on both the server and client,
// the styles will need to be rehydrated.
if (typeof window !== 'undefined') {
const styleTag = document.getElementById('cxs-style')
const serverCss = styleTag.innerHTML
cxs.rehydrate(serverCss)
}
import cxs from 'cxs'

const cx = {
root: cxs({
Expand Down
20 changes: 20 additions & 0 deletions examples/with-cxs/tsconfig.json
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
6 changes: 6 additions & 0 deletions examples/with-styled-jsx/package.json
Expand Up @@ -9,5 +9,11 @@
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"typescript": "^4.9.3"
}
}
20 changes: 20 additions & 0 deletions examples/with-styled-jsx/tsconfig.json
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}