-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(examples): updated the example of with-styled-components (#70796)
This PR updates the with-styled-components example to use the App Router. Here are the changes that have been made: - Renamed the `pages` folder to the `app` folder. - Updated the routing for `/` & `/about` files to align with the App Router. - Added the `layout.tsx` file as part of the App Router. - Updated the `package.json` file. The following actions were performed as part of this PR: - Ran `pnpm prettier-check` with no issues found. - Executed the `pnpm check-examples` script. CC: @samcx --------- Co-authored-by: samcx <[email protected]>
- Loading branch information
1 parent
e8011b5
commit 7474f10
Showing
16 changed files
with
111 additions
and
74 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 8 additions & 1 deletion
9
...es/with-styled-components/pages/about.tsx → ...with-styled-components/app/about/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
examples/with-styled-components/lib/styled-components-registry.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters