Skip to content

Commit

Permalink
add styled-components and core components
Browse files Browse the repository at this point in the history
  • Loading branch information
amalcaraz committed Mar 5, 2024
1 parent 8a59659 commit 387d64f
Show file tree
Hide file tree
Showing 8 changed files with 511 additions and 127 deletions.
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=${FONTAWESOME_NPM_AUTH_TOKEN}
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BuilderDevTools from "@builder.io/dev-tools/next";

/** @type {import('next').NextConfig} */
const nextConfig = BuilderDevTools()({});
const nextConfig = BuilderDevTools()({ compiler: { styledComponents: true } });

export default nextConfig;
566 changes: 441 additions & 125 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@aleph-front/core": "^1.15.68",
"@builder.io/dev-tools": "^0.2.22",
"@builder.io/react": "^3.2.5",
"@builder.io/sdk": "^2.2.2",
Expand All @@ -20,10 +21,12 @@
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/styled-components": "^5.1.34",
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.1.1",
"postcss": "^8",
"styled-components": "^6.1.8",
"tailwindcss": "^3.3.0",
"typescript": "^5"
}
Expand Down
10 changes: 9 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import StyledComponentsRegistry from './lib/registry'
import ClientThemeProvider from "./lib/provider";

const inter = Inter({ subsets: ["latin"] });

Expand All @@ -16,7 +18,13 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<body className={inter.className}>
<StyledComponentsRegistry>
<ClientThemeProvider>
{children}
</ClientThemeProvider>
</StyledComponentsRegistry>
</body>
</html>
);
}
16 changes: 16 additions & 0 deletions src/app/lib/provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use client'

import { ThemeProvider } from 'styled-components'
import { themes } from '@aleph-front/core'

export default function ClientThemeProvider({
children,
}: {
children: React.ReactNode;
}) {
return (
<ThemeProvider theme={themes.aleph}>
{children}
</ThemeProvider>
)
}
29 changes: 29 additions & 0 deletions src/app/lib/registry.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'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
}) {
// Only create stylesheet once with lazy initial state
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
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>
)
}
10 changes: 10 additions & 0 deletions src/builder-registry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import { builder, Builder } from "@builder.io/react";
import Counter from "./components/Counter/Counter";
import { components as coreComponents } from '@aleph-front/core'

builder.init(process.env.NEXT_PUBLIC_BUILDER_API_KEY!);

Expand All @@ -13,3 +14,12 @@ Builder.registerComponent(Counter, {
},
],
});


const components = Object.entries(coreComponents)

for (const [name, cmp] of components) {
Builder.registerComponent(cmp, {
name,
});
}

0 comments on commit 387d64f

Please sign in to comment.