Skip to content

Commit

Permalink
Add support for CSS Modules within Storybook (they weren't rendered p…
Browse files Browse the repository at this point in the history
…roperly before, even though it didn't break)
  • Loading branch information
Vadorequest committed Jan 12, 2021
1 parent b79e94e commit 777c3ce
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,16 @@ module.exports = {
* @see https://github.com/storybookjs/storybook/tree/master/addons/google-analytics
*/
'@storybook/addon-google-analytics',

/**
* Adds support for CSS Modules.
*
* Even though Next Right Now doesn't encourage the use of CSS Modules,
* we thought it's an interesting feature to support, which is natively supported by Next.js.
*
* @see https://www.npmjs.com/package/storybook-css-modules-preset How to configure Storybook to support CSS Modules
* @see https://nextjs.org/docs/basic-features/built-in-css-support#adding-component-level-css How to use CSS Modules with Next.js
*/
'storybook-css-modules-preset',
],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
"open-cli": "6.0.1",
"react-test-renderer": "17.0.1",
"storybook-addon-next-router": "2.0.3",
"storybook-css-modules-preset": "1.0.5",
"ts-jest": "26.4.4",
"typescript": "4.1.3",
"vercel": "21.0.1"
Expand Down
6 changes: 6 additions & 0 deletions src/stories/nrn/utilities/I18nLink.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* This is a basic example to check Storybook supports using CSS Modules */
.red {
margin: 10px;
padding: 10px;
background-color: red;
}
12 changes: 12 additions & 0 deletions src/stories/nrn/utilities/I18nLink.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Meta } from '@storybook/react/types-6-0';
import React from 'react';
import I18nLink, { Props } from '../../../components/i18n/I18nLink';
import styles from './I18nLink.module.css';

export default {
title: 'Utilities/I18nLink',
Expand All @@ -18,6 +19,17 @@ export const SimpleLink: React.VFC<Props> = () => {
);
};

export const LinkWithCSSModule: React.VFC<Props> = () => {
return (
<I18nLink
href={`/`}
className={styles.red}
>
Homepage (red)
</I18nLink>
);
};

export const LinkWithClass: React.VFC<Props> = () => {
return (
<I18nLink
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16161,6 +16161,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/storybook-addon-next-router/-/storybook-addon-next-router-2.0.3.tgz#24cb0233c03749a9b416f5b191bbcd17545a3d3b"
integrity sha512-1/q3ZYpN2Hae8ePL553J4rzVEh2rF+mVPvui2+Q7LEVvCTFgcB3Iow9xCA0P9nxNjg+oPs8Xkpb0ahXkwUAIcQ==

[email protected]:
version "1.0.5"
resolved "https://registry.yarnpkg.com/storybook-css-modules-preset/-/storybook-css-modules-preset-1.0.5.tgz#8963bab91c42a66fc757610323d280d76a06d07b"
integrity sha512-NcGOdU7Woh1RMz7ftaDh6ThePRaW/5Cuh5AH5lK+5D9ue5X9cFxSvkWCZUswcGOS8Z6GNifeTx7UoH6nuWZPFg==

[email protected]:
version "3.0.0"
resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-3.0.0.tgz#22b0a2850cdf6503e73085da1fc7b7d0c2122f2f"
Expand Down

1 comment on commit 777c3ce

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.