mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-11 00:06:25 +08:00
FIX build
This commit is contained in:
parent
fec5773709
commit
cd0b42bc1a
@ -1,7 +1,7 @@
|
|||||||
import React, { FunctionComponent, Key, ReactNode } from 'react';
|
import React, { FunctionComponent, Key, ReactNode } from 'react';
|
||||||
import { styled } from '@storybook/theming';
|
import { styled } from '@storybook/theming';
|
||||||
|
|
||||||
import ListItem, { LinkWrapperType } from './ListItem';
|
import ListItem, { LinkWrapperType, ListItemProps } from './ListItem';
|
||||||
|
|
||||||
const List = styled.div<{}>(
|
const List = styled.div<{}>(
|
||||||
{
|
{
|
||||||
@ -13,12 +13,8 @@ const List = styled.div<{}>(
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
export interface Link {
|
export interface Link extends ListItemProps {
|
||||||
id: string;
|
id: string;
|
||||||
title?: ReactNode;
|
|
||||||
active?: boolean;
|
|
||||||
href?: string | object;
|
|
||||||
onClick?: () => void;
|
|
||||||
isGatsby?: boolean;
|
isGatsby?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,12 +10,14 @@ export default {
|
|||||||
|
|
||||||
export const all = () => (
|
export const all = () => (
|
||||||
<TooltipLinkList
|
<TooltipLinkList
|
||||||
links={
|
links={[
|
||||||
[
|
{ title: 'has icon', left: <ListItemIcon icon="check" />, id: 'icon' },
|
||||||
{ title: 'has icon', left: <ListItemIcon icon="check" /> },
|
{
|
||||||
{ title: 'has imgSrc', left: <ListItemIcon imgSrc="https://via.placeholder.com/20" /> },
|
title: 'has imgSrc',
|
||||||
{ title: 'has neither', left: <ListItemIcon /> },
|
left: <ListItemIcon imgSrc="https://via.placeholder.com/20" />,
|
||||||
] as any // FIXME: TooltipLinkList types
|
id: 'img',
|
||||||
}
|
},
|
||||||
|
{ title: 'has neither', left: <ListItemIcon />, id: 'non' },
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -2,7 +2,6 @@ import React from 'react';
|
|||||||
|
|
||||||
import Sidebar from './Sidebar';
|
import Sidebar from './Sidebar';
|
||||||
import { standardData as standardHeaderData } from './SidebarHeading.stories';
|
import { standardData as standardHeaderData } from './SidebarHeading.stories';
|
||||||
// @ts-ignore
|
|
||||||
import { withRootData } from './SidebarStories.stories';
|
import { withRootData } from './SidebarStories.stories';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { styled } from '@storybook/theming';
|
import { styled } from '@storybook/theming';
|
||||||
import { ScrollArea } from '@storybook/components';
|
import { ScrollArea } from '@storybook/components';
|
||||||
|
import { State } from '@storybook/api';
|
||||||
|
|
||||||
import SidebarHeading, { SidebarHeadingProps } from './SidebarHeading';
|
import SidebarHeading, { SidebarHeadingProps } from './SidebarHeading';
|
||||||
import SidebarStories from './SidebarStories';
|
import SidebarStories from './SidebarStories';
|
||||||
@ -9,7 +11,9 @@ const Heading = styled(SidebarHeading)<SidebarHeadingProps>({
|
|||||||
padding: '20px 20px 12px',
|
padding: '20px 20px 12px',
|
||||||
});
|
});
|
||||||
|
|
||||||
const Stories = styled(SidebarStories)(({ loading }) => (loading ? { marginTop: 8 } : {}));
|
const Stories = styled(({ className, ...rest }) => (
|
||||||
|
<SidebarStories className={className} {...rest} />
|
||||||
|
))(({ loading }) => (loading ? { marginTop: 8 } : {}));
|
||||||
|
|
||||||
const Container = styled.nav({
|
const Container = styled.nav({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
@ -29,7 +33,7 @@ const CustomScrollArea = styled(ScrollArea)({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export interface SidebarProps {
|
export interface SidebarProps {
|
||||||
stories: unknown;
|
stories: State['StoriesHash'];
|
||||||
menu: any[];
|
menu: any[];
|
||||||
storyId?: string;
|
storyId?: string;
|
||||||
menuHighlighted?: boolean;
|
menuHighlighted?: boolean;
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Spaced } from '@storybook/components';
|
||||||
|
|
||||||
|
import SidebarStories from './SidebarStories';
|
||||||
|
import { mockDataset } from './treeview/treeview.mockdata';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
Component: SidebarStories,
|
||||||
|
title: 'UI|Sidebar/SidebarStories',
|
||||||
|
decorators: [s => <Spaced>{s()}</Spaced>],
|
||||||
|
excludeStories: /.*Data$/,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const withRootData = {
|
||||||
|
stories: mockDataset.withRoot,
|
||||||
|
storyId: '1-12-121',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const withRoot = () => (
|
||||||
|
<SidebarStories stories={mockDataset.withRoot} storyId="1-12-121" loading={false} />
|
||||||
|
);
|
||||||
|
|
||||||
|
export const noRootData = {
|
||||||
|
stories: mockDataset.noRoot,
|
||||||
|
storyId: '1-12-121',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const noRoot = () => (
|
||||||
|
<SidebarStories stories={mockDataset.noRoot} storyId="1-12-121" loading={false} />
|
||||||
|
);
|
||||||
|
|
||||||
|
export const emptyData = {
|
||||||
|
stories: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const empty = () => <SidebarStories stories={{}} loading={false} />;
|
||||||
|
|
||||||
|
export const loading = () => <SidebarStories loading stories={{}} />;
|
@ -1,35 +1,165 @@
|
|||||||
import React from 'react';
|
import React, { Fragment, FunctionComponent } from 'react';
|
||||||
import { Spaced } from '@storybook/components';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import SidebarStories from './SidebarStories';
|
import { styled } from '@storybook/theming';
|
||||||
|
import { Placeholder, Link as StyledLink } from '@storybook/components';
|
||||||
|
import { State } from '@storybook/api';
|
||||||
|
import { Location, Link as RouterLink } from '@storybook/router';
|
||||||
|
import { TreeState } from './treeview/treeview';
|
||||||
|
|
||||||
|
import SidebarItem from './SidebarItem';
|
||||||
|
import SidebarSearch from './SidebarSearch';
|
||||||
|
import SidebarSubheading from './SidebarSubheading';
|
||||||
|
|
||||||
|
const Search = styled(SidebarSearch)({
|
||||||
|
margin: '0 20px 1rem',
|
||||||
|
});
|
||||||
|
|
||||||
|
const Subheading = styled(SidebarSubheading)({
|
||||||
|
margin: '0 20px',
|
||||||
|
});
|
||||||
|
|
||||||
|
Subheading.propTypes = {
|
||||||
|
className: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
Subheading.defaultProps = {
|
||||||
|
className: 'sidebar-subheading',
|
||||||
|
};
|
||||||
|
|
||||||
|
const Section = styled.section({
|
||||||
|
'& + section': {
|
||||||
|
marginTop: 20,
|
||||||
|
},
|
||||||
|
'&:last-of-type': {
|
||||||
|
marginBottom: 40,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const List = styled.div();
|
||||||
|
List.displayName = 'List';
|
||||||
|
|
||||||
|
const plain = {
|
||||||
|
color: 'inherit',
|
||||||
|
display: 'block',
|
||||||
|
textDecoration: 'none',
|
||||||
|
userSelect: 'none',
|
||||||
|
};
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { mockDataset } from './treeview/treeview.mockdata';
|
const PlainRouterLink = styled(RouterLink)(plain);
|
||||||
|
// @ts-ignore
|
||||||
|
const PlainLink = styled.a(plain);
|
||||||
|
|
||||||
export default {
|
const Wrapper = styled.div({});
|
||||||
Component: SidebarStories,
|
|
||||||
title: 'UI|Sidebar/SidebarStories',
|
const refinedViewMode = (viewMode: string) => {
|
||||||
decorators: [s => <Spaced>{s()}</Spaced>],
|
return viewMode === 'settings' ? 'story' : viewMode;
|
||||||
excludeStories: /.*Data$/,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const withRootData = {
|
export const Link = ({ id, prefix, name, children, isLeaf, onClick, onKeyUp }) =>
|
||||||
stories: mockDataset.withRoot,
|
isLeaf ? (
|
||||||
storyId: '1-12-121',
|
<Location>
|
||||||
|
{({ viewMode }) => (
|
||||||
|
<PlainRouterLink
|
||||||
|
title={name}
|
||||||
|
id={prefix + id}
|
||||||
|
to={`/${viewMode ? refinedViewMode(viewMode) : 'story'}/${id}`}
|
||||||
|
onKeyUp={onKeyUp}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</PlainRouterLink>
|
||||||
|
)}
|
||||||
|
</Location>
|
||||||
|
) : (
|
||||||
|
<PlainLink title={name} id={prefix + id} onKeyUp={onKeyUp} onClick={onClick}>
|
||||||
|
{children}
|
||||||
|
</PlainLink>
|
||||||
|
);
|
||||||
|
Link.displayName = 'Link';
|
||||||
|
Link.propTypes = {
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
id: PropTypes.string.isRequired,
|
||||||
|
name: PropTypes.string.isRequired,
|
||||||
|
isLeaf: PropTypes.bool.isRequired,
|
||||||
|
prefix: PropTypes.string.isRequired,
|
||||||
|
onKeyUp: PropTypes.func.isRequired,
|
||||||
|
onClick: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const withRoot = () => <SidebarStories stories={mockDataset.withRoot} storyId="1-12-121" />;
|
interface StoriesProps {
|
||||||
|
loading: boolean;
|
||||||
|
stories: State['StoriesHash'];
|
||||||
|
storyId?: undefined | string;
|
||||||
|
className?: undefined | string;
|
||||||
|
}
|
||||||
|
|
||||||
export const noRootData = {
|
const SidebarStories: FunctionComponent<StoriesProps> = React.memo(
|
||||||
stories: mockDataset.noRoot,
|
({ stories, storyId, loading, className, ...rest }) => {
|
||||||
storyId: '1-12-121',
|
const list = Object.entries(stories);
|
||||||
};
|
|
||||||
|
|
||||||
export const noRoot = () => <SidebarStories stories={mockDataset.noRoot} storyId="1-12-121" />;
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<Wrapper className={className}>
|
||||||
|
<SidebarItem loading />
|
||||||
|
<SidebarItem loading />
|
||||||
|
<SidebarItem depth={1} loading />
|
||||||
|
<SidebarItem depth={1} loading />
|
||||||
|
<SidebarItem depth={2} loading />
|
||||||
|
<SidebarItem depth={3} loading />
|
||||||
|
<SidebarItem depth={3} loading />
|
||||||
|
<SidebarItem depth={3} loading />
|
||||||
|
<SidebarItem depth={1} loading />
|
||||||
|
<SidebarItem depth={1} loading />
|
||||||
|
<SidebarItem depth={1} loading />
|
||||||
|
<SidebarItem depth={2} loading />
|
||||||
|
<SidebarItem depth={2} loading />
|
||||||
|
<SidebarItem depth={2} loading />
|
||||||
|
<SidebarItem depth={3} loading />
|
||||||
|
<SidebarItem loading />
|
||||||
|
<SidebarItem loading />
|
||||||
|
</Wrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export const emptyData = {
|
if (list.length < 1) {
|
||||||
stories: {},
|
return (
|
||||||
};
|
<Wrapper className={className}>
|
||||||
|
<Placeholder key="empty">
|
||||||
|
<Fragment key="title">No stories found</Fragment>
|
||||||
|
<Fragment>
|
||||||
|
Learn how to{' '}
|
||||||
|
<StyledLink href="https://storybook.js.org/basics/writing-stories/" target="_blank">
|
||||||
|
write stories
|
||||||
|
</StyledLink>
|
||||||
|
</Fragment>
|
||||||
|
</Placeholder>
|
||||||
|
</Wrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export const empty = () => <SidebarStories stories={{}} />;
|
return (
|
||||||
|
<Wrapper className={className}>
|
||||||
|
<TreeState
|
||||||
|
key="treestate"
|
||||||
|
dataset={stories}
|
||||||
|
prefix="explorer"
|
||||||
|
selectedId={storyId}
|
||||||
|
filter=""
|
||||||
|
List={List}
|
||||||
|
Head={SidebarItem}
|
||||||
|
Link={Link}
|
||||||
|
Leaf={SidebarItem}
|
||||||
|
Title={Subheading}
|
||||||
|
Section={Section}
|
||||||
|
Message={Placeholder}
|
||||||
|
// eslint-disable-next-line react/jsx-no-duplicate-props
|
||||||
|
Filter={Search}
|
||||||
|
{...rest}
|
||||||
|
/>
|
||||||
|
</Wrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export const loading = () => <SidebarStories loading stories={{}} />;
|
export default SidebarStories;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user