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

make addon aware of active prop so storybook renders in its own panel #3

Merged
merged 1 commit into from
Oct 4, 2018
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
7 changes: 5 additions & 2 deletions src/Themes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Theme} from "./types/Theme";
export interface ThemeProps {
channel: any;
api: any;
active: Boolean;
}

interface ThemeState {
Expand All @@ -22,13 +23,15 @@ interface ThemeHandler {

type BaseComponentProps = ThemeProps & ThemeState & ThemeHandler;

const BaseComponent: React.SFC<BaseComponentProps> = ({onSelectTheme, themes, theme}) => (
const BaseComponent: React.SFC<BaseComponentProps> = ({onSelectTheme, themes, theme, active}) => (
active ? (
<div style={RowStyle}>
{themes.map((th, i) => {
const buttonStyle = th === theme ? SelectedButtonStyle : ButtonStyle;
return <div style={buttonStyle} key={i} onClick={() => onSelectTheme(th)}>{th.name}</div>;
}).toArray()}
</div>
</div> )
: (<div />)
);

export const Themes = compose<BaseComponentProps, ThemeProps>(
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/Themes.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("Themes spec", () => {
removeListener: stub(),
};

const component = mount(<Themes api={null} channel={channel} />);
const component = mount(<Themes api={null} active={true} channel={channel} />);
expect(component.render()).toMatchSnapshot();
expect(channel.on.calledOnce).toBeTruthy();
expect(channel.emit.notCalled).toBeTruthy();
Expand Down
2 changes: 1 addition & 1 deletion src/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ addons.register("storybook/themes", (api) => {
// Also need to set a unique name to the panel.
addons.addPanel("storybook/themes/panel", {
title: "Themes",
render: () => (<Themes channel={addons.getChannel()} api={api} />),
render: ({ active }) => (<Themes channel={addons.getChannel()} api={api} active={active} />),
});
});