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

chore(examples): updated the example of with-styled-components #70796

Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
"use client";

import Link from "next/link";
import { Container, Main, Title, Description } from "@/components/sharedstyles";
import {
Container,
Main,
Title,
Description,
} from "../_components/sharedstyles";

export default function About() {
return (
Expand Down
15 changes: 15 additions & 0 deletions examples/with-styled-components/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ReactNode } from "react";
import StyledComponentsRegistry from "@/lib/styled-components-registry";
import ClientLayout from "@/lib/client-layout";

export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>
<StyledComponentsRegistry>
<ClientLayout>{children}</ClientLayout>
</StyledComponentsRegistry>
</body>
</html>
);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"use client";
import Head from "next/head";
import {
Container,
Main,
Title,
Description,
CodeTag,
} from "@/components/sharedstyles";
import Cards from "@/components/cards";
} from "./_components/sharedstyles";
import Cards from "./_components/cards";

export default function Home() {
return (
Expand All @@ -23,7 +24,7 @@ export default function Home() {

<Description>
Get started by editing
<CodeTag>pages/index.tsx</CodeTag>
<CodeTag>app/page.tsx</CodeTag>
</Description>

<Cards />
Expand Down
21 changes: 21 additions & 0 deletions examples/with-styled-components/lib/client-layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use client";

import { ReactNode } from "react";
import { ThemeProvider, type DefaultTheme } from "styled-components";
import GlobalStyle from "@/app/_components/globalstyles";

const theme: DefaultTheme = {
colors: {
primary: "#111",
secondary: "#0070f3",
},
};

export default function ClientLayout({ children }: { children: ReactNode }) {
return (
<ThemeProvider theme={theme}>
<GlobalStyle />
{children}
</ThemeProvider>
);
}
27 changes: 27 additions & 0 deletions examples/with-styled-components/lib/styled-components-registry.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use client";

import React, { useState } from "react";
import { useServerInsertedHTML } from "next/navigation";
import { ServerStyleSheet, StyleSheetManager } from "styled-components";

export default function StyledComponentsRegistry({
children,
}: {
children: React.ReactNode;
}) {
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet());

useServerInsertedHTML(() => {
const styles = styledComponentsStyleSheet.getStyleElement();
styledComponentsStyleSheet.instance.clearTag();
return <>{styles}</>;
});

if (typeof window !== "undefined") return <>{children}</>;

return (
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}>
{children}
</StyleSheetManager>
);
}
2 changes: 1 addition & 1 deletion examples/with-styled-components/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
10 changes: 0 additions & 10 deletions examples/with-styled-components/next.config.js

This file was deleted.

14 changes: 14 additions & 0 deletions examples/with-styled-components/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-check

/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
/* config options here */
reactStrictMode: true,
compiler: {
styledComponents: true,
},
};

export default nextConfig;
14 changes: 7 additions & 7 deletions examples/with-styled-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
},
"dependencies": {
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"styled-components": "^6.1.0"
"react": "^18.3.1",
"react-dom": "^18.3.1",
"styled-components": "^6.1.13"
},
"devDependencies": {
"@types/node": "^18.18.3",
"@types/react": "^18.2.33",
"@types/react-dom": "^18.2.14",
"typescript": "^5.2.2"
"@types/node": "^22.7.4",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.0",
"typescript": "^5.6.2"
}
}
21 changes: 0 additions & 21 deletions examples/with-styled-components/pages/_app.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions examples/with-styled-components/pages/_document.tsx

This file was deleted.

17 changes: 14 additions & 3 deletions examples/with-styled-components/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand All @@ -15,8 +15,19 @@
"incremental": true,
"paths": {
"@/*": ["./*"]
}
},
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "styled.d.ts"],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"styled.d.ts",
".next/types/**/*.ts"
],
"exclude": ["node_modules"]
}
Loading