Skip to content

Commit

Permalink
Merge pull request #3 from actraiser/master
Browse files Browse the repository at this point in the history
make addon aware of active prop so storybook renders in its own panel
  • Loading branch information
echoulen authored Oct 4, 2018
2 parents fbbd6d9 + da283ce commit c99c208
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
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} />),
});
});

0 comments on commit c99c208

Please sign in to comment.