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

fix(next): fixed issue for multi pages next applications #702

Merged
merged 1 commit into from
Apr 16, 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
7 changes: 7 additions & 0 deletions examples/next/src/app/another-page/page.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.main {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
}
28 changes: 28 additions & 0 deletions examples/next/src/app/another-page/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Metadata } from 'next';
import { Button } from '@/components/Button';
import { Main } from '@/components/Main';
import { createUseStyle } from '@morfeo/css';
import { Link } from '@/components/Link';

export const metadata: Metadata = {
title: 'Morfeo | NextJS',
description: '',
};

const useStyle = createUseStyle({
componentName: 'Card',
p: 'm',
my: 'xl',
});

export default function AnotherPage() {
const { className, style } = useStyle();
return (
<Main>
<div className={className} style={style}>
<Button>Here is another page</Button>
</div>
<Link href="/">{'<- '}Go back</Link>
</Main>
);
}
2 changes: 2 additions & 0 deletions examples/next/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;300;400;500;600;700;800;900&display=swap');

*, *::before, *::after {
box-sizing: border-box;
}
Expand Down
8 changes: 5 additions & 3 deletions examples/next/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Metadata } from 'next';
import { Button } from '@/components/Button';
import { Card } from '@/components/Card';
import styles from './page.module.css';
import { Main } from '@/components/Main';
import { Link } from '@/components/Link';

export const metadata: Metadata = {
title: 'Morfeo | NextJS',
Expand All @@ -13,7 +14,7 @@ export const metadata: Metadata = {

export default function Home() {
return (
<main className={styles.main}>
<Main>
<Card direction="left">
<Card direction="right">
<Card direction="left">
Expand All @@ -27,6 +28,7 @@ export default function Home() {
</Card>
</Card>
</Card>
</main>
<Link href="/another-page">Go to another page</Link>
</Main>
);
}
7 changes: 0 additions & 7 deletions examples/next/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
'use client';

import { ButtonHTMLAttributes, DetailedHTMLProps, useState } from 'react';
import { Montserrat } from 'next/font/google';
import { useButton } from './Button.morfeo';

type ButtonProps = DetailedHTMLProps<
ButtonHTMLAttributes<HTMLButtonElement>,
HTMLButtonElement
>;

const montserrat = Montserrat({
subsets: ['latin'],
});

const variants = ['primary', 'secondary'] as const;

export const Button: React.FC<ButtonProps> = props => {
const [variantIndex, setVariantIndex] = useState<number>(0);

const { className, style } = useButton({
variant: variants[variantIndex],
className: montserrat.className,
style: montserrat.style,
});

function onClick() {
Expand Down
15 changes: 15 additions & 0 deletions examples/next/src/components/Link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createUseStyle } from '@morfeo/css';
import NextLink from 'next/link';
import { ComponentProps } from 'react';

type LinkProps = ComponentProps<typeof NextLink>;

const useLink = createUseStyle({
componentName: 'Typography',
variant: 'link',
});

export const Link: React.FC<LinkProps> = props => {
const { className, style } = useLink();
return <NextLink {...props} className={className} style={style} />;
};
20 changes: 20 additions & 0 deletions examples/next/src/components/Main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createUseStyle } from '@morfeo/css';
import { DetailedHTMLProps, HTMLAttributes } from 'react';

type CardProps = DetailedHTMLProps<
HTMLAttributes<HTMLDivElement>,
HTMLDivElement
>;

const useMain = createUseStyle({
display: 'flex',
minHeight: '100vh',
alignItems: 'center',
flexDirection: 'column',
justifyContent: 'center',
});

export const Main: React.FC<CardProps> = props => {
const { className, style } = useMain();
return <div {...props} className={className} style={style} />;
};
2 changes: 2 additions & 0 deletions examples/react/src/App.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;300;400;500;600;700;800;900&display=swap');

*, *::before, *::after {
box-sizing: border-box;
}
Expand Down
11 changes: 6 additions & 5 deletions packages/compiler/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ export const MORFEO_CSS_PATH = path.join(
'morfeo.css',
);

if (!fs.existsSync(path.dirname(MORFEO_CSS_PATH))) {
fs.mkdirSync(path.dirname(MORFEO_CSS_PATH));
}

fs.writeFileSync(MORFEO_CSS_PATH, ``);

export const MORFEO_VIRTUAL_MODULE_PREFIX = 'virtual:morfeo';

function createCssWriter() {
let css = '';
if (!fs.existsSync(path.dirname(MORFEO_CSS_PATH))) {
fs.mkdirSync(path.dirname(MORFEO_CSS_PATH));
}

fs.writeFileSync(MORFEO_CSS_PATH, ``);

function collect(content: string) {
css += content;
Expand Down