Skip to content

Commit 00477a5

Browse files
authored
Merge pull request #93 from forumone/1.x-RC
1.1.2
2 parents 45a7440 + 6e4e23a commit 00477a5

File tree

13 files changed

+193
-43
lines changed

13 files changed

+193
-43
lines changed

.storybook/main.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
],
1414
framework: {
1515
name: '@storybook/nextjs',
16-
options: {},
16+
options: { builder: { useSWC: true } },
1717
},
1818
webpackFinal: async config => {
1919
config.plugins.push(
@@ -49,6 +49,16 @@ module.exports = {
4949
parse: YAML.parse,
5050
},
5151
});
52+
config.module.rules.find(
53+
rule => rule.test && rule.test.toString().includes('css'),
54+
).resourceQuery = {
55+
not: /raw/,
56+
};
57+
config.module.rules.push({
58+
test: /\.css$/,
59+
resourceQuery: /raw/,
60+
type: 'asset/source',
61+
});
5262
return config;
5363
},
5464
};

README.nextjs.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ Note that Next v11 comes with the following installed already:
1212
* [Webpack v5](https://webpack.js.org/concepts/)
1313
* [CSS Modules](https://github.com/css-modules/css-modules)
1414

15+
16+
## App Router
17+
The Next.js starter app uses [Next.js's App Router](https://nextjs.org/docs/app/building-your-application/routing#the-app-router),
18+
the newer router that supports React Server Components and shared layouts. See the [Next.js docs](https://nextjs.org/docs/app/building-your-application)
19+
to learn more about the App Router. One important change introduced with the App Router is that components default to being rendered
20+
on the server, so any components that need to use client-side JS, such as useState, useEffect, and event handlers, need the `use client`
21+
directive at the top. [The Next.js docs](https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#when-to-use-server-and-client-components)
22+
have more details about which to use when.
23+
1524
## Getting Started
1625

1726
Ensure that you are using the proper Node version for this app. We currently use v18. Assuming you have [nvm](https://github.com/nvm-sh/nvm) installed locally, you can simply run:
@@ -89,15 +98,15 @@ Runs `next lint`, which runs the ESLint command. This is useful to catch lint er
8998
npm run prettier
9099
```
91100

92-
Runs `prettier --check`, which will check that all files within the `pages` and `source` directories use the Prettier code style from `.prettierrc`. This might be redundant with the `lint` script above, since it extends whatever Prettier rules we have set.
101+
Runs `prettier --check`, which will check that all files within the `app` and `source` directories use the Prettier code style from `.prettierrc`. This might be redundant with the `lint` script above, since it extends whatever Prettier rules we have set.
93102

94103
#### Prettier write
95104

96105
```bash
97106
npm run prettier:write
98107
```
99108

100-
Runs `prettier --write`, which will find and fix all prettier issues found within the `pages` and `source` directories. Note that this will automatically overwrite your files.
109+
Runs `prettier --write`, which will find and fix all prettier issues found within the `app` and `source` directories. Note that this will automatically overwrite your files.
101110

102111
### Run TypeScript compiler (tsc)
103112

@@ -121,5 +130,5 @@ Note that bypassing the Husky check is frowned upon.
121130

122131
## Notes
123132

124-
* Code for the app is currently configured to go into the `pages` directory (for [Next.js pages](https://nextjs.org/docs/basic-features/pages)) and `source` for theming, components, providers, helpers, etc.
133+
* Code for the app is currently configured to go into the `app` directory (for [Next.js pages](https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts)) and `source` for theming, components, providers, helpers, etc.
125134
* The current favicon implementation will probably not display correctly locally in Chrome (v94), but does display correctly in Firefox and Safari. Note that the favicon _does_ display correctly once deployed. Not sure why.

README.project.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@ This is a starter app for [Next.js](https://nextjs.org/) (bootstrapped with [`cr
88
* [Stylelint](https://stylelint.io/)
99
* [Prettier](https://prettier.io/)
1010

11-
Note that Next v13 comes with the following installed already:
11+
Note that Next v14 comes with the following installed already:
1212
* [Webpack v5](https://webpack.js.org/concepts/)
1313
* [CSS Modules](https://github.com/css-modules/css-modules)
1414

15+
## App Router
16+
The Next.js starter app uses [Next.js's App Router](https://nextjs.org/docs/app/building-your-application/routing#the-app-router),
17+
the newer router that supports React Server Components and shared layouts. See the [Next.js docs](https://nextjs.org/docs/app/building-your-application)
18+
to learn more about the App Router. One important change introduced with the App Router is that components default to being rendered
19+
on the server, so any components that need to use client-side JS, such as useState, useEffect, and event handlers, need the `use client`
20+
directive at the top. [The Next.js docs](https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#when-to-use-server-and-client-components)
21+
have more details about which to use when.
22+
1523
## Initial Setup
1624

1725
1. Run [nvm](https://github.com/nvm-sh/nvm) so your local node version matches the project's node version:
@@ -120,15 +128,15 @@ Runs `next lint`, which runs the ESLint command. This is useful to catch lint er
120128
ddev nextjs prettier
121129
```
122130

123-
Runs `prettier --check`, which will check that all files within the `pages` and `source` directories use the Prettier code style from `.prettierrc`. This might be redundant with the `lint` script above, since it extends whatever Prettier rules we have set.
131+
Runs `prettier --check`, which will check that all files within the `app` and `source` directories use the Prettier code style from `.prettierrc`. This might be redundant with the `lint` script above, since it extends whatever Prettier rules we have set.
124132

125133
#### Prettier write
126134

127135
```bash
128136
ddev nextjs prettier:write
129137
```
130138

131-
Runs `prettier --write`, which will find and fix all prettier issues found within the `pages` and `source` directories. Note that this will automatically overwrite your files.
139+
Runs `prettier --write`, which will find and fix all prettier issues found within the `app` and `source` directories. Note that this will automatically overwrite your files.
132140

133141
### Run TypeScript compiler (tsc)
134142

@@ -141,7 +149,7 @@ Runs `tsc --noEmit`, which will compile the TypeScript code without emitting fil
141149

142150
## Notes
143151

144-
* Code for the app is currently configured to go into the `pages` directory (for [Next.js pages](https://nextjs.org/docs/basic-features/pages)) and `source` for theming, components, providers, helpers, etc.
152+
* Code for the app is currently configured to go into the `app` directory (for [Next.js pages](https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts)) and `source` for theming, components, providers, helpers, etc.
145153
* Starting in Next.js v9.4, TypeScript errors do not show up in your browser when running the dev server (i.e. `npm run dev`). However, TS errors will prevent `next build` (i.e. `npm run build`) from running successfully. You can run `npm run lint` and `npm run tsc` to check for issues, which will give you lint and TS errors that will most likely cause your builds to fail. Note also that if you have [`husky`](https://typicode.github.io/husky/#/) installed, these will automatically run when you attempt to commit to a branch.
146154
* The current favicon implementation will probably not display correctly locally in Chrome (v94), but does display correctly in Firefox and Safari. Note that the favicon _does_ display correctly once deployed. Not sure why.
147155

app/about/page.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import { Metadata } from 'next';
12
import Page from '../../source/04-templates/Page/Page';
23

4+
const title = 'About Forum One Next.js Starter App';
5+
6+
export const metadata: Metadata = {
7+
title,
8+
description: 'Next app using TypeScript and Emotion',
9+
};
10+
311
function About() {
4-
const title = 'About Forum One Next.js Starter App';
512
return (
6-
<Page title={title} description="Next app using TypeScript and Emotion">
13+
<Page title={title}>
714
<p>
815
<a href="https://nextjs.org/docs">Next.js</a> app with{' '}
916
<a href="https://www.typescriptlang.org/">TypeScript</a>.

app/page.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
import { Metadata } from 'next';
12
import Image from 'next/image';
23
import heroPlaceholder from '../public/images/hero-placeholder.jpg';
34
import Section from '../source/02-layouts/Section/Section';
45
import HeroBgImage from '../source/03-components/HeroBgImage/HeroBgImage';
56
import Wysiwyg from '../source/03-components/Wysiwyg/Wysiwyg';
67
import LandingPage from '../source/04-templates/LandingPage/LandingPage';
78

9+
const title = 'Forum One Next.js Starter App';
10+
11+
export const metadata: Metadata = {
12+
title,
13+
description: 'Next app using TypeScript and PostCSS',
14+
};
15+
816
function Home() {
9-
const title = 'Forum One Next.js Starter App';
1017
return (
11-
<LandingPage
12-
title={title}
13-
description="Next app using TypeScript and PostCSS"
14-
>
18+
<LandingPage title={title}>
1519
<Section>
1620
<HeroBgImage
1721
hasOverlay={true}

next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
reactStrictMode: true,
77
basePath,
88
eslint: {
9-
dirs: ['source', 'pages'],
9+
dirs: ['source', 'app'],
1010
},
1111
/**
1212
* Custom Webpack Config

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nextjs-project",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",
@@ -10,7 +10,7 @@
1010
"lint": "next lint && stylelint \"source/**/*.css\"",
1111
"prepare": "husky install",
1212
"prettier": "prettier --check pages source/",
13-
"prettier:write": "prettier --write pages source/",
13+
"prettier:write": "prettier --write app source/",
1414
"tsc": "tsc --noEmit",
1515
"test": "npm run lint && npm run tsc",
1616
"component": "node lib/component.js",
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import { Meta, StoryObj } from '@storybook/react';
2+
import { Property } from 'csstype';
3+
import { useEffect, useState } from 'react';
4+
import typographyVarsAsString from '../../00-config/vars/typography.css?raw';
5+
import getCssVariables from '../../06-utility/storybook/getCssVariables';
6+
import styles from './typographic-scale.module.css';
7+
8+
const typographyVars = typographyVarsAsString
9+
.replace(':root {', '')
10+
.replace('}', '')
11+
.split(';')
12+
.map((e: string) => {
13+
return e.trim();
14+
})
15+
.filter((e: string) => e.includes('--responsive-font-size'))
16+
.map((e: string) => {
17+
return e.replace(')', '').split('(').pop();
18+
});
19+
20+
const typographyVarsMax = typographyVars.map((e: string) => {
21+
return e.split(' ').pop();
22+
});
23+
const typographyVarsMin = typographyVars.map((e: string) => {
24+
return e.split(' ', 1).pop();
25+
});
26+
27+
const settings: Meta = {
28+
title: 'Global/Typography/Typographic Scale',
29+
};
30+
31+
interface FontOptions {
32+
[name: string]: Property.FontFamily;
33+
}
34+
35+
interface ResponsiveFontSizeOptions {
36+
[number: number]: string;
37+
}
38+
39+
const TypographicScale: StoryObj = {
40+
render: function Render() {
41+
const [fonts, setFonts] = useState<FontOptions | undefined>(undefined);
42+
const [responsiveFontSizes, setResponsiveFontSizes] = useState<
43+
ResponsiveFontSizeOptions | undefined
44+
>(undefined);
45+
46+
useEffect(() => {
47+
const allVars = getCssVariables();
48+
49+
const fonts = allVars.reduce((allFonts, [key, value]) => {
50+
if (key.indexOf('--font-family') === 0) {
51+
const name =
52+
key.substring(14).charAt(0).toUpperCase() +
53+
key.substring(14).slice(1);
54+
allFonts[name] = value;
55+
}
56+
return allFonts;
57+
}, {} as FontOptions);
58+
setFonts(fonts);
59+
60+
const fontSizes = allVars.reduce(
61+
(allResponsiveFontSizes, [key, value]) => {
62+
if (key.indexOf('--responsive-font-size') === 0) {
63+
const number = parseInt(key.substring(23));
64+
allResponsiveFontSizes[number] = value;
65+
}
66+
return allResponsiveFontSizes;
67+
},
68+
{} as ResponsiveFontSizeOptions,
69+
);
70+
setResponsiveFontSizes(fontSizes);
71+
}, []);
72+
return (
73+
<>
74+
{fonts &&
75+
Object.entries(fonts)
76+
.sort((fontA, fontB) => {
77+
// Sort fonts so that Primary and Secondary (if used) appear at the
78+
// top of the list.
79+
if (fontA[0].toLowerCase().includes('primary')) {
80+
return -1;
81+
}
82+
if (fontB[0].toLowerCase().includes('primary')) {
83+
return 1;
84+
}
85+
if (fontA[0].toLowerCase().includes('secondary')) {
86+
return -1;
87+
}
88+
if (fontB[0].toLowerCase().includes('secondary')) {
89+
return 1;
90+
}
91+
return 0;
92+
})
93+
.map(([name, fontFamily]) => (
94+
<div className={styles['typographic-scale']} key={name}>
95+
<h2 className={styles.heading}>{name}</h2>
96+
<div style={{ fontFamily }}>
97+
{responsiveFontSizes &&
98+
Object.entries(responsiveFontSizes).map(
99+
([number, responsiveFontSize]) => (
100+
<>
101+
<div className={styles.row} key={`${name}-${number}`}>
102+
<div className={styles.label}>{number}</div>
103+
<div
104+
className={styles.preview}
105+
style={{
106+
fontSize: responsiveFontSize,
107+
}}
108+
>
109+
This text goes from{' '}
110+
{typographyVarsMin[parseInt(number) - 1]} to{' '}
111+
{typographyVarsMax[parseInt(number) - 1]}.
112+
</div>
113+
</div>
114+
</>
115+
),
116+
)}
117+
</div>
118+
</div>
119+
))}
120+
</>
121+
);
122+
},
123+
args: {},
124+
};
125+
126+
export default settings;
127+
export { TypographicScale };

source/04-templates/LandingPage/LandingPage.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import Head from 'next/head';
2-
import { ReactNode } from 'react';
1+
import { JSX, ReactNode } from 'react';
32
import { MAIN_ID } from '../../00-config/constants';
43
import Main from '../../02-layouts/Main/Main';
54
import PageTitle from '../../03-components/PageTitle/PageTitle';
@@ -8,28 +7,20 @@ interface PageProps {
87
mainId?: string;
98
title: string;
109
hidePageTitle?: boolean;
11-
description?: string;
1210
children?: ReactNode;
1311
}
1412

1513
function LandingPage({
1614
mainId = MAIN_ID,
1715
title,
1816
hidePageTitle,
19-
description,
2017
children,
2118
}: PageProps): JSX.Element {
2219
return (
23-
<>
24-
<Head>
25-
<title>{title}</title>
26-
{description && <meta name="description" content={description} />}
27-
</Head>
28-
<Main id={mainId}>
29-
{!hidePageTitle && title && <PageTitle pageTitle={title} />}
30-
{children}
31-
</Main>
32-
</>
20+
<Main id={mainId}>
21+
{!hidePageTitle && title && <PageTitle pageTitle={title} />}
22+
{children}
23+
</Main>
3324
);
3425
}
3526

0 commit comments

Comments
 (0)