Skip to content

Commit

Permalink
fix(react): relagate theming to storybook alone
Browse files Browse the repository at this point in the history
  • Loading branch information
jrea committed Apr 5, 2024
1 parent 11fc06e commit 5318b19
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,13 @@ mergedTheme.unstable_sxConfig = {
...muiSxConfig,
...joySxConfig,
};
export default mergedTheme;

export default {
theme: mergedTheme,
defaultMode: 'dark',
slotProps: {
provider: {
defaultMode: 'dark',
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Stack from '@mui/joy/Stack';
import Input from '@mui/joy/Input';

import { NileProvider } from '../context';
import theme from '../../.storybook/themeConfig';

import GoogleLoginButton from './GoogleLoginButton';

Expand All @@ -17,7 +18,7 @@ export default meta;

export function Basic() {
return (
<NileProvider>
<NileProvider {...theme}>
<div style={{ maxWidth: '20rem', margin: '0 auto' }}>
<GoogleLoginButton />
</div>
Expand All @@ -28,7 +29,7 @@ export function Basic() {
export function BasicWithTenantNameProvider() {
const [newTenant, setNewTenant] = React.useState<string | undefined>();
return (
<NileProvider>
<NileProvider {...theme}>
<div style={{ maxWidth: '20rem', margin: '0 auto' }}>
<Stack gap={2}>
<Stack>
Expand Down Expand Up @@ -57,7 +58,7 @@ export function AlphaVersionWithOutProvider() {

export function AlphaVersionWithProvider() {
return (
<NileProvider>
<NileProvider {...theme}>
<div style={{ maxWidth: '20rem', margin: '0 auto' }}>
<GoogleLoginButton />
</div>
Expand Down
9 changes: 7 additions & 2 deletions packages/react/src/LoginForm/UserLoginForm.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { Meta } from '@storybook/react';
import Stack from '@mui/joy/Stack';

import theme from '../../.storybook/themeConfig';
import LoginForm from '../../src/LoginForm';
import { NileProvider } from '../../src/context';

Expand All @@ -14,8 +15,12 @@ export default meta;

export function Basic() {
return (
<NileProvider>
<Stack sx={{ maxWidth: '20rem', margin: '0 auto' }} spacing={2}>
<NileProvider {...theme}>
<Stack
sx={{ maxWidth: '20rem', margin: '0 auto' }}
spacing={2}
data-joy-color-scheme="dark"
>
<LoginForm onSuccess={() => alert('success!')} />
</Stack>
</NileProvider>
Expand Down
20 changes: 16 additions & 4 deletions packages/react/src/SSO/SSO.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import Typography from '@mui/joy/Typography';
import { Meta } from '@storybook/react';

import { NileProvider } from '../context';
import theme from '../../.storybook/themeConfig';

import BaseSSOForm, { Okta } from '.';

Expand All @@ -14,9 +16,16 @@ export default meta;

export function BasicSSO() {
return (
<NileProvider>
<div style={{ maxWidth: '20rem', margin: '0 auto' }}>
<NileProvider {...theme}>
<div
style={{ maxWidth: '20rem', margin: '0 auto' }}
data-joy-color-scheme="dark"
>
<Typography>Some kind of cool explaination</Typography>
<BaseSSOForm
configurationGuide={
<Typography>Some kind of cool explaination</Typography>
}
providerName="placeholder"
onSuccess={() => alert('success!')}
/>
Expand All @@ -26,8 +35,11 @@ export function BasicSSO() {
}
export function OktaSSO() {
return (
<NileProvider>
<div style={{ maxWidth: '20rem', margin: '0 auto' }}>
<NileProvider {...theme}>
<div
style={{ maxWidth: '20rem', margin: '0 auto' }}
data-joy-color-scheme="dark"
>
<Okta
onSuccess={() => {
alert('success!');
Expand Down
8 changes: 6 additions & 2 deletions packages/react/src/SignUpForm/NewUserSignUp.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { Meta } from '@storybook/react';

import { NileProvider } from '../context';
import theme from '../../.storybook/themeConfig';

import SignUpForm from '.';

Expand All @@ -14,8 +15,11 @@ export default meta;

export function Basic() {
return (
<NileProvider>
<div style={{ maxWidth: '20rem', margin: '0 auto' }}>
<NileProvider {...theme}>
<div
style={{ maxWidth: '20rem', margin: '0 auto' }}
data-joy-color-scheme="dark"
>
<SignUpForm onSuccess={() => alert('success!')} />
</div>
</NileProvider>
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/UserTenantList/UserList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { Meta } from '@storybook/react';

import { NileProvider } from '../context';
import theme from '../../.storybook/themeConfig';

import UserList from '.';

Expand All @@ -22,7 +23,7 @@ const users = [
];
export function Basic() {
return (
<NileProvider tenantId="tenantId">
<NileProvider {...theme} tenantId="tenantId" data-joy-color-scheme="dark">
<UserList data={users} />
</NileProvider>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const NileProvider = (props: NileProviderProps) => {
const {
children,
theme,
slotProps,
tenantId,
QueryProvider = BaseQueryProvider,
basePath = 'https://api.thenile.dev',
Expand All @@ -55,7 +56,7 @@ export const NileProvider = (props: NileProviderProps) => {

return (
<QueryProvider>
<ThemeProvider theme={theme}>
<ThemeProvider slotProps={slotProps?.provider} theme={theme}>
<Provider value={values}>{children}</Provider>
</ThemeProvider>
</QueryProvider>
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/context/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import CssBaseline from '@mui/material/CssBaseline';
import { Theme } from '@mui/joy/styles';
import { CssVarsProvider as JoyCssVarsProvider } from '@mui/joy/styles';

import defaultTheme from './config';

export default function Themer({
theme,
children,
slotProps,
}: {
theme?: Theme;
children: JSX.Element;
slotProps?: Record<string, string>;
}) {
return (
<JoyCssVarsProvider theme={theme ?? defaultTheme} defaultMode="dark">
<JoyCssVarsProvider {...slotProps} theme={theme}>
<CssBaseline enableColorScheme />
{children}
</JoyCssVarsProvider>
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/context/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export type NileContext = NileReactConfig & {
export type NileProviderProps = NileReactConfig & {
children: JSX.Element | JSX.Element[];
theme?: Theme;
slotProps?: {
provider?: Record<string, string>;
};
QueryProvider?: (props: { children: JSX.Element }) => JSX.Element;
api?: Browser;
};
3 changes: 0 additions & 3 deletions packages/react/src/lib/SimpleForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ export default function SimpleForm(props: {
endDecorator={
field.value ? options[0].label : options[1].label
}
sx={{
'--Switch-thumbSize': '28px',
}}
/>
);
}}
Expand Down
2 changes: 1 addition & 1 deletion packages/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig",
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"include": ["src/**/*", "test", "src/**/*.stories.tsx"],
"include": ["src/**/*", "test", "src/**/*.stories.tsx", ".storybook/config.ts"],
"compilerOptions": {
"jsx": "react",
"lib": ["dom", "esnext"],
Expand Down

0 comments on commit 5318b19

Please sign in to comment.