Skip to content

Commit

Permalink
docs: add storybook themes customization for pages (#185)
Browse files Browse the repository at this point in the history
* docs: add storybook themes customization for pages

* fix: page components to apply themes correctly

* test: update snapshot
  • Loading branch information
tonai authored Jun 3, 2024
1 parent 4752614 commit 2ac4fa2
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 22 deletions.
6 changes: 6 additions & 0 deletions .changeset/wicked-hornets-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'storybook-pages': patch
'@smile/haring-react': patch
---

fix FoldableColumnLayout and SearchResults styles to apply themes correclty
15 changes: 15 additions & 0 deletions .storybook/WithProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DefaultMantineColor } from '@mantine/core';
import type { StoryContext, StoryFn } from '@storybook/react';
import type { ReactElement } from 'react';

Expand All @@ -12,8 +13,22 @@ export default function WithProvider(
context: StoryContext,
): ReactElement {
const {
args,
globals: { theme },
title,
} = context;

const isPage = title.toLowerCase().startsWith('3-custom/pages/');
if (isPage) {
return (
<Provider
primaryColor={args.themePrimaryColor as DefaultMantineColor}
secondaryColor={args.themeSecondaryColor as DefaultMantineColor}
>
<Story />
</Provider>
);
}
return (
<Provider>
<MantineProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
padding: 40px 64px 0 64px;
position: relative;
width: 100%;
border-radius: 0;

/*noinspection CssInvalidAtRule*/
@mixin smaller-than $mantine-breakpoint-md {
Expand All @@ -18,6 +19,10 @@
}
}

.boxWithoutMotif {
background: transparent;
}

.collapseButton {
/*noinspection CssInvalidAtRule*/
@mixin smaller-than $mantine-breakpoint-md {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const meta = {
parameters: {
layout: 'fullscreen',
},
title: '3-Custom/Layouts/FoldableColumnLayout',
title: '3-custom/Layouts/FoldableColumnLayout',
} satisfies Meta<typeof Cmp>;

export default meta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from '@mantine/core';
import type { ReactElement, ReactNode } from 'react';

import { Box, Button, Container, Grid, Switch, Text } from '@mantine/core';
import { Button, Container, Grid, Paper, Switch, Text } from '@mantine/core';
import { useUncontrolled } from '@mantine/hooks';
import { CaretDown, CaretUp } from '@phosphor-icons/react';
import { NestedProvider, useMainTheme } from '@smile/haring-react-shared';
Expand Down Expand Up @@ -66,9 +66,10 @@ export function FoldableColumnLayout(
return (
<>
<NestedProvider theme={theme}>
<Box
className={`${classes.box} ${boxMotif ? classes.boxWithMotif : ''}`}
color="primary"
<Paper
className={`${classes.box} ${
boxMotif ? classes.boxWithMotif : classes.boxWithoutMotif
}`}
{...boxProps}
>
{Boolean(boxMotif) && (
Expand Down Expand Up @@ -108,7 +109,7 @@ export function FoldableColumnLayout(
</Grid.Col>
)}
</Grid>
</Box>
</Paper>
</NestedProvider>
<div
className={`${classes.collapseButton} ${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ exports[`FoldableColumnLayout matches snapshot 1`] = `
id=":r0:"
>
<div
class="undefined "
color="primary"
class="undefined undefined m_1b7284a3 mantine-Paper-root"
>
<style
data-mantine-styles="inline"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import type { Meta, StoryObj } from '@storybook/react';

import { sharedMeta } from '../pages-story';

import { BrowsingPage as Cmp } from './BrowsingPage';

const meta = {
...sharedMeta,
args: { themePrimaryColor: 'cyan', themeSecondaryColor: 'gray' },
component: Cmp,
parameters: {
layout: 'fullscreen',
},
title: '3-Custom/Pages/BrowsingPage',
title: '3-custom/Pages/BrowsingPage',
} satisfies Meta<typeof Cmp>;

export default meta;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use client';

import type { Meta, StoryObj } from '@storybook/react';

import { sharedMeta } from '../pages-story';

import { DashboardPage as Cmp } from './DashboardPage';

const meta = {
...sharedMeta,
component: Cmp,
parameters: {
layout: 'fullscreen',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'use client';

import type { Meta, StoryObj } from '@storybook/react';

import { sharedMeta } from '../pages-story';

import { DocumentDetails as Cmp } from './DocumentDetails';

const meta = {
...sharedMeta,
component: Cmp,
parameters: {
layout: 'fullscreen',
},
title: '3-Custom/Pages/DocumentDetails',
title: '3-custom/Pages/DocumentDetails',
} satisfies Meta<typeof Cmp>;

export default meta;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { Meta, StoryObj } from '@storybook/react';

import { sharedMeta } from '../pages-story';

import { SearchResults as Cmp } from './SearchResults';

const meta = {
...sharedMeta,
component: Cmp,
parameters: {
layout: 'fullscreen',
},
title: '3-Custom/Pages/SearchResults',
title: '3-custom/Pages/SearchResults',
} satisfies Meta<typeof Cmp>;

export default meta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,8 @@ export function SearchResults(): ReactElement {
</AppShell.Header>
<AppShell.Main>
<FoldableColumnLayout
boxMotif={<Motif style={{ fill: '#868E96' }} />}
boxProps={{
p: { lg: '48px 64px' },
style: { background: theme.colors.gray[8] },
}}
boxMotif={<Motif />}
boxProps={{ p: { lg: '48px 64px' } }}
isColumnVisible={isColumnVisible}
onChangeIsColumnVisible={setIsColumnVisible}
sidebarContent={
Expand Down
17 changes: 17 additions & 0 deletions packages/storybook-pages/src/Pages/pages-story.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DEFAULT_THEME } from '@mantine/core';

const colorOptions = Object.keys(DEFAULT_THEME.colors);

export const sharedMeta = {
argTypes: {
themePrimaryColor: {
control: 'select',
options: colorOptions,
},
themeSecondaryColor: {
control: 'select',
options: colorOptions,
},
},
args: { themePrimaryColor: 'cyan', themeSecondaryColor: 'gray' },
};
5 changes: 3 additions & 2 deletions turbo/generators/templates/pageStory.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use client';

import type { Meta, StoryObj } from '@storybook/react';

import { sharedMeta } from '../pages-story';

import { {{pascalCase name}} as Cmp } from './{{pascalCase name}}';

const meta = {
...sharedMeta,
component: Cmp,
parameters: {
layout: 'fullscreen',
Expand Down

0 comments on commit 2ac4fa2

Please sign in to comment.