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!: avoid init themes on Faency side causing them not being available on server side #278

Merged
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
26 changes: 6 additions & 20 deletions components/FaencyProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { IdProvider } from '@radix-ui/react-id';
import { customColors, globalCss, PrimaryColor } from '../stitches.config';
import { globalCss } from '../stitches.config';

import RubikLightWoff2 from '../assets/fonts/rubik/Rubik-Light.woff2';
import RubikWoff2 from '../assets/fonts/rubik/Rubik-Regular.woff2';
Expand Down Expand Up @@ -33,7 +33,7 @@ const globalStyles = globalCss({
fontFamily: 'Rubik',
fontWeight: 500,
fontDisplay: 'swap',
src: `local('Rubik-Medium'), url(${RubikMediumWoff2}) format('woff2')`
src: `local('Rubik-Medium'), url(${RubikMediumWoff2}) format('woff2')`,
},
{
fontFamily: 'Rubik',
Expand Down Expand Up @@ -67,7 +67,7 @@ const globalStyles = globalCss({
fontStyle: 'italic',
fontWeight: 500,
fontDisplay: 'swap',
src: `local('Rubik-Medium'), url(${RubikMediumItalicWoff2}) format('woff2')`
src: `local('Rubik-Medium'), url(${RubikMediumItalicWoff2}) format('woff2')`,
},
{
fontFamily: 'Rubik',
Expand All @@ -86,22 +86,8 @@ const globalStyles = globalCss({
],
});

export const FaencyProvider: React.FC<{ primaryColor: PrimaryColor }> = ({
children,
primaryColor,
}) => {
export const FaencyProvider: React.FC = ({ children }) => {
globalStyles();

React.useEffect(() => {
const { dark, light } = customColors(primaryColor);
dark.toString();
light.toString();
}, [primaryColor]);

globalStyles()

return (
<IdProvider>
{children}
</IdProvider>
);
return <IdProvider>{children}</IdProvider>;
};
17 changes: 14 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
export { AccordionRoot, AccordionItem, AccordionTrigger, AccordionContent } from './components/Accordion';
export { RadioAccordionRoot, RadioAccordionItem, RadioAccordionTrigger, RadioAccordionContent } from './components/RadioAccordion';
export {
AccordionRoot,
AccordionItem,
AccordionTrigger,
AccordionContent,
} from './components/Accordion';
export {
RadioAccordionRoot,
RadioAccordionItem,
RadioAccordionTrigger,
RadioAccordionContent,
} from './components/RadioAccordion';
export { Alert } from './components/Alert';
export { AspectRatio } from '@radix-ui/react-aspect-ratio';
export { Badge } from './components/Badge';
Expand Down Expand Up @@ -60,7 +70,8 @@ export {
globalCss,
keyframes,
config,
customColors,
lightTheme,
darkTheme,
} from './stitches.config';

export type { CSS, VariantProps } from './stitches.config';
61 changes: 53 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@
"lint-staged": {
"*.{js,css,md}": "prettier --write"
}
}
}
17 changes: 7 additions & 10 deletions stitches.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Theme as SkeletonTheme } from './components/Skeleton/Skeleton.themes';
import { Theme as DialogTheme } from './components/Dialog/Dialog.themes';
import { Theme as NavigationTheme } from './components/Navigation/Navigation.themes';
import { Theme as TooltipTheme } from './components/Tooltip/Tooltip.themes';
import { Theme as TextareaTheme } from './components/Textarea/Textarea.themes'
import { Theme as TextareaTheme } from './components/Textarea/Textarea.themes';

import { lightColors, darkColors } from './colors';
import getPrimaryColorInfo from './utils/getPrimaryColorInfo';
Expand All @@ -42,7 +42,7 @@ export const colors: Record<string, Property.Color> = {
hiContrast: '$deepBlue11',
loContrast: 'white',
focusOutline: 'hsl(216, 100%, 64%)',
divider: 'hsl(207, 10%, 82%)'
divider: 'hsl(207, 10%, 82%)',
};

const stitches = createStitches({
Expand Down Expand Up @@ -264,10 +264,10 @@ export const { styled, css, createTheme, getCssText, globalCss, keyframes, confi

export const utils = config.utils;

export const customColors = (primary: PrimaryColor) => {
export const darkTheme = (primary: PrimaryColor) => {
const darkPrimaryColor = getPrimaryColorInfo(primary, darkColors);

const darkTheme = createTheme('dark', {
return createTheme('dark', {
colors: {
...darkColors,

Expand Down Expand Up @@ -297,10 +297,12 @@ export const customColors = (primary: PrimaryColor) => {
...TextareaTheme.getDark(darkPrimaryColor),
},
});
};

export const lightTheme = (primary: PrimaryColor) => {
const lightPrimaryColor = getPrimaryColorInfo(primary, lightColors);

const lightTheme = createTheme('light', {
return createTheme('light', {
colors: {
primary: lightPrimaryColor.token,
...AccordionTheme.getLight(lightPrimaryColor),
Expand All @@ -323,9 +325,4 @@ export const customColors = (primary: PrimaryColor) => {
...TextareaTheme.getLight(lightPrimaryColor),
},
});

return {
dark: darkTheme,
light: lightTheme,
};
};