Skip to content

feat: upgrade storybook #696

Merged
merged 27 commits into from Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5925e52
chore: upgrade version
reme3d2y Jun 9, 2021
33c20a9
chrome: make this works
reme3d2y Jun 10, 2021
7ede5b5
chore: fix bugs
reme3d2y Jun 11, 2021
e9c63aa
feat(storybook): sort stories by alphabet (#708)
koretskyhub Jun 29, 2021
35a9d03
feat(storybook): make "Docs" tab default (#707)
koretskyhub Jun 29, 2021
0b27b52
Feat/change story docs structure (#714)
koretskyhub Jun 29, 2021
7ded959
Feat/live edit storybook docs (#716)
koretskyhub Jul 6, 2021
8f163c0
chore: fix case
reme3d2y Jul 6, 2021
74d9277
Merge branch 'master' into feat/upgrade-storybook
reme3d2y Jul 6, 2021
1b24f2a
chore: update stories
reme3d2y Jul 7, 2021
7ff9691
chore: update & fix screenshots
reme3d2y Jul 7, 2021
8333cce
chore: fix select test
reme3d2y Jul 7, 2021
129620c
chore: stories
reme3d2y Jul 7, 2021
bc5d769
chore: stories
reme3d2y Jul 7, 2021
5988a3b
docs: add changelogs (#722)
dmitrsavk Jul 7, 2021
195980d
chore: global styles
reme3d2y Jul 7, 2021
42e9d00
chore: changelog story
reme3d2y Jul 7, 2021
4b6d72f
chore: sorting
reme3d2y Jul 7, 2021
3f31413
chore: styles
reme3d2y Jul 7, 2021
32e5042
chore: styles
reme3d2y Jul 7, 2021
388cd5d
chore: fix import
reme3d2y Jul 8, 2021
7901460
feat: show theme-switcher in all tabs
reme3d2y Jul 8, 2021
b21a79f
chore: update sb & drop addon-actions
reme3d2y Jul 8, 2021
fbad889
chore: drop button inverted themes
reme3d2y Jul 8, 2021
e5bd6af
chore: update vars stories
reme3d2y Jul 8, 2021
fafd904
chore: styles
reme3d2y Jul 8, 2021
316d57e
chore: remove relative imports
reme3d2y Jul 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .storybook/addons/theme-switcher/register.js
Expand Up @@ -29,7 +29,7 @@ const Addon = () => {
return (
themes.length > 0 && (
<div className='tool'>
<span className='label'>Theme:</span>
<span className='label'>Выбор темы: </span>
<Form.Select size={1} onChange={handleChange} className='select' value={theme}>
{['default'].concat(themes).map(themeName => (
<option
Expand All @@ -48,7 +48,7 @@ const Addon = () => {
addons.register(ADDON_ID, () => {
addons.add(ADDON_ID, {
type: types.TOOL,
match: ({ viewMode }) => viewMode === 'story',
match: () => true,
render: () => <Addon />,
paramKey: ADDON_ID,
});
Expand Down
11 changes: 11 additions & 0 deletions .storybook/blocks/changelog/changelog.tsx
@@ -0,0 +1,11 @@
import React, { FC, ReactNode } from 'react';

import styles from './index.module.css';

type Props = {
content: ReactNode;
};

export const Changelog: FC<Props> = ({ content }) => {
return <div className={styles.changelog}>{content}</div>;
};
57 changes: 57 additions & 0 deletions .storybook/blocks/changelog/index.module.css
@@ -0,0 +1,57 @@
/* stylelint-disable selector-pseudo-class-no-unknown */

@import '../../../packages/vars/src/index.css';

.changelog {
& h1:global(.sbdocs):first-child {
display: none;

& + p {
display: none;
}
}

& h1:global(.sbdocs) {
@mixin headline_medium;

margin: var(--gap-2xl) 0 var(--gap-m);
color: var(--color-light-text-primary);
border-bottom: 1px solid var(--color-light-border-secondary);

& a {
@mixin headline_medium;

border: none;
}
}

& h2:global(.sbdocs) {
@mixin headline_xsmall;

border: 0;
box-shadow: none;
padding: 0;
margin: 0;
margin-bottom: var(--gap-s);
padding-bottom: var(--gap-xs);
border-bottom: 1px solid var(--color-light-border-secondary);

&:after {
display: none;
}

& a {
@mixin headline_xsmall;

border: none;
}

& + p {
margin-bottom: var(--gap-xl);
}
}

& h3:global(.sbdocs) {
margin-top: var(--gap-m);
}
}
1 change: 1 addition & 0 deletions .storybook/blocks/changelog/index.ts
@@ -0,0 +1 @@
export * from './changelog';
2 changes: 1 addition & 1 deletion .storybook/blocks/component-header/ComponentHeader.tsx
Expand Up @@ -2,7 +2,7 @@ import React, { ReactNode } from 'react';
import { Title } from '@storybook/addon-docs/blocks';
import { Status } from 'storybook/blocks/status';

import styles from './ComponentHeader.css';
import styles from './ComponentHeader.module.css';

type ComponentHeaderProps = {
name: string;
Expand Down
11 changes: 8 additions & 3 deletions .storybook/blocks/example/LiveExample.tsx
Expand Up @@ -2,7 +2,6 @@ import React, { FC, useState } from 'react';
import { LiveProvider, LiveEditor, LivePreview } from 'react-live';
import { ActionBar } from '@storybook/components';
import { PrismTheme } from 'prism-react-renderer';

import { ErrorSection } from './ErrorSection';
import globalScope from './utils/scope';

Expand Down Expand Up @@ -30,7 +29,7 @@ export const LiveExample: FC<LiveExampleProps> = ({
window.open(
`${
window.parent.location.pathname
}?path=/docs/гайдлайны-песочница--page/code=${encodeURIComponent(code)}`,
}?path=/docs/компоненты-песочница--page/code=${encodeURIComponent(code)}`,
);
};

Expand All @@ -45,10 +44,16 @@ export const LiveExample: FC<LiveExampleProps> = ({
},
];

const code2 = code
.split('\n')
.filter(line => line.startsWith('//') === false)
.join('\n')
.trim();

return (
<LiveProvider
code={code}
noInline={code.startsWith('<') === false}
noInline={code2.startsWith('<') === false && code2.startsWith('//') === false}
theme={theme}
scope={{
...globalScope,
Expand Down
3 changes: 2 additions & 1 deletion .storybook/blocks/example/index.module.css
Expand Up @@ -46,9 +46,10 @@
& button {
justify-content: center;
min-width: 110px;
transition: 0.2s ease;
transition: box-shadow 0.2s ease;

&:focus {
outline: 0;
box-shadow: none;
}

Expand Down
11 changes: 9 additions & 2 deletions .storybook/blocks/example/utils/scope.ts
@@ -1,6 +1,8 @@
import { ComponentType } from 'react';
import * as grid from '../../grid';
import * as glyph from '@alfalab/icons-glyph';
import * as dateUtils from 'date-fns';
import * as knobs from '@storybook/addon-knobs';

const req = require.context(
'../../../../packages',
Expand All @@ -12,11 +14,14 @@ const isComponent = (component: any) =>
['function', 'object'].some(t => typeof component === t) &&
['displayName', '$$typeof'].some(p => p in component);

const isComponentsMap = (component: any) =>
component && Object.values(component).some(isComponent)

const components = req.keys().reduce((acc: Record<string, ComponentType<unknown>>, key) => {
Object.entries(req(key)).forEach(([componentName, component]: [string, any]) => {
if (isComponent(component)) {
// if (isComponent(component) || isComponentsMap(component)) {
acc[componentName] = component;
}
// }
});

return acc;
Expand All @@ -26,4 +31,6 @@ export default {
...components,
...grid,
...glyph,
...dateUtils,
...knobs,
};
2 changes: 1 addition & 1 deletion .storybook/blocks/grid/Col.tsx
@@ -1,7 +1,7 @@
import React, { InputHTMLAttributes, useCallback, ChangeEvent, ReactNode } from 'react';
import cn from 'classnames';

import styles from './Col.css';
import styles from './Col.module.css';

type ColProps = {
children?: ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion .storybook/blocks/grid/Container.tsx
@@ -1,7 +1,7 @@
import React, { ReactNode } from 'react';
import cn from 'classnames';

import styles from './Container.css';
import styles from './Container.module.css';

type ContainerProps = {
children?: ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion .storybook/blocks/grid/Row.tsx
@@ -1,7 +1,7 @@
import React, { InputHTMLAttributes, useCallback, ChangeEvent, ReactNode } from 'react';
import cn from 'classnames';

import styles from './Row.css';
import styles from './Row.module.css';

type RowProps = {
children?: ReactNode;
Expand Down
1 change: 1 addition & 0 deletions .storybook/blocks/index.ts
@@ -1,3 +1,4 @@
export * from './changelog';
export * from './css-vars';
export * from './component-header';
export * from './status';
Expand Down
2 changes: 1 addition & 1 deletion .storybook/blocks/status/Status.tsx
@@ -1,7 +1,7 @@
import React, { ReactNode } from 'react';
import cn from 'classnames';

import styles from './Status.css';
import styles from './Status.module.css';

const STATUS = {
1: 'Draft',
Expand Down
45 changes: 31 additions & 14 deletions .storybook/blocks/tabs/component.tsx
@@ -1,29 +1,42 @@
import React, { FC, useState, useMemo, useCallback, ReactNode } from 'react';
import React, {
FC,
useState,
useMemo,
useCallback,
ReactNode,
isValidElement,
ReactElement,
} from 'react';
import { TabsResponsive, Tab, TabsResponsiveProps } from '@alfalab/core-components-tabs';
import { Changelog } from '../changelog';

enum TabName {
DESCRIPTION = 'DESCRIPTION',
PROPS = 'PROPS',
CSS_VARS = 'CSS_VARS',
CHANGELOG = 'CHANGELOG',
}

const TabTitle = {
[TabName.DESCRIPTION]: 'Описание',
[TabName.PROPS]: 'Свойства',
[TabName.CSS_VARS]: 'CSS-переменные',
[TabName.CHANGELOG]: 'Что нового',
};

type Props = {
description: ReactNode;
props: ReactNode;
cssVars?: ReactNode;
changelog?: string;
defaultSelected?: TabName;
};

export const Tabs: FC<Props> = ({
description,
props,
cssVars,
changelog,
defaultSelected = TabName.DESCRIPTION,
}) => {
const [selected, setSelected] = useState(defaultSelected);
Expand All @@ -36,24 +49,28 @@ export const Tabs: FC<Props> = ({
);

const renderTabs = (): TabsResponsiveProps['children'] => {
const result = [
return [
<Tab title={TabTitle[TabName.DESCRIPTION]} id={TabName.DESCRIPTION}>
<div style={{ marginTop: '40px' }}>{description}</div>
</Tab>,
<Tab title={TabTitle[TabName.PROPS]} id={TabName.PROPS}>
{props}
</Tab>,
];

if (cssVars) {
result.push(
props ? (
<Tab title={TabTitle[TabName.PROPS]} id={TabName.PROPS}>
{props}
</Tab>
) : null,
cssVars ? (
<Tab title={TabTitle[TabName.CSS_VARS]} id={TabName.CSS_VARS}>
<div style={{ marginTop: '40px' }}>{cssVars}</div>
</Tab>,
);
}

return result;
</Tab>
) : null,
changelog ? (
<Tab title={TabTitle[TabName.CHANGELOG]} id={TabName.CHANGELOG}>
<div style={{ marginTop: '40px' }}>
<Changelog content={changelog} />
</div>
</Tab>
) : null,
].filter(isValidElement) as ReactElement[];
};

const tabs = useMemo(() => renderTabs(), [description, props, cssVars]);
Expand Down