Skip to content

Commit

Permalink
fix: CSS module doesn't include the root class (#1548)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpbl committed Sep 8, 2022
1 parent 54f5425 commit 2238bcf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
12 changes: 10 additions & 2 deletions packages/react-day-picker/rollup.config.js
Expand Up @@ -67,13 +67,21 @@ const buildConfig = {
src: './src/style.css',
dest: './dist',
rename: 'style.module.css',
transform: (contents) => contents.toString().replace(/\.rdp-/g, '.')
transform: (contents) =>
contents
.toString()
.replace(/\.rdp-/g, '.')
.replace(/\.rdp/g, '.root')
},
{
src: './src/style.css.d.ts',
dest: './dist',
rename: 'style.module.css.d.ts',
transform: (contents) => contents.toString().replace(/rdp-/g, '')
transform: (contents) =>
contents
.toString()
.replace(/\.rdp-/g, '.')
.replace(/\.rdp/g, '.root')
}
]
})
Expand Down
21 changes: 16 additions & 5 deletions website/src/components/RenderExample.tsx
Expand Up @@ -5,6 +5,21 @@ import BrowserOnly from '@docusaurus/BrowserOnly';
import { useColorMode } from '@docusaurus/theme-common';
import root from 'react-shadow';

const style: string = require(`!raw-loader!./shadow-dom-styles.css`).default;
const styleDark: string =
require(`!raw-loader!./shadow-dom-styles-dark.css`).default;
const libStyle: string =
require(`!raw-loader!react-day-picker/dist/style.css`).default;
const libStyleModule =
require(`react-day-picker/dist/style.module.css`).default;

let libStyleModuleRaw: string =
require(`!raw-loader!react-day-picker/dist/style.module.css`).default;
Object.entries(libStyleModule).map(([key, value]) => {
const regExp = new RegExp(`\\.${key}([,: .])+`, 'g');
libStyleModuleRaw = libStyleModuleRaw.replace(regExp, `.${value}$1`);
});

export function RenderExample(props: {
name: string;
rootStyle?: React.CSSProperties;
Expand All @@ -19,15 +34,11 @@ export function RenderExample(props: {
return <pre>{e.message}</pre>;
}
const Component = require(`@site/examples/${props.name}`).default;
const libStyle =
require(`!raw-loader!react-day-picker/dist/style.css`).default;
const style = require(`!raw-loader!./shadow-dom-styles.css`).default;
const styleDark =
require(`!raw-loader!./shadow-dom-styles-dark.css`).default;

return (
<root.div style={props.rootStyle}>
<style type="text/css">{libStyle}</style>
<style type="text/css">{libStyleModuleRaw}</style>
<style type="text/css">{style}</style>
<style type="text/css">{isDarkTheme && styleDark}</style>
<Component />
Expand Down

0 comments on commit 2238bcf

Please sign in to comment.