Skip to content

Commit

Permalink
Merge pull request #5692 from storybooks/fix/tooltip-tools
Browse files Browse the repository at this point in the history
Fix/tooltip tools
  • Loading branch information
shilman authored Feb 21, 2019
2 parents 81afc43 + 3480bc0 commit cedc39f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 44 deletions.
2 changes: 1 addition & 1 deletion addons/a11y/src/components/ColorBlindness.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const ColorIcon = styled.span(
class ColorBlindness extends Component {
state = {
expanded: false,
filter: false,
filter: null,
};

setFilter = filter => {
Expand Down
67 changes: 26 additions & 41 deletions addons/backgrounds/src/containers/BackgroundSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ const createBackgroundSelectorItem = memoize(1000)(
})
);

const getSelectedBackgroundColor = (
list: BackgroundConfig[],
currentSelectedValue: string
): string => {
const getSelectedBackgroundColor = (list: BackgroundConfig[], currentSelectedValue: string): string => {
if (!list.length) {
return 'transparent';
}
Expand All @@ -54,36 +51,30 @@ const getSelectedBackgroundColor = (
return 'transparent';
};

const getDisplayableState = memoize(10)(
(props: BackgroundToolProps, state: BackgroundToolState, change) => {
const data = props.api.getCurrentStoryData();
const list: BackgroundConfig[] = (data && data.parameters && data.parameters[PARAM_KEY]) || [];

const selectedBackgroundColor = getSelectedBackgroundColor(list, state.selected);

let availableBackgroundSelectorItems: BackgroundSelectorItem[] = [];

if (selectedBackgroundColor !== 'transparent') {
availableBackgroundSelectorItems.push(
createBackgroundSelectorItem('reset', 'Clear background', 'transparent', false, change)
);
}

if (list.length) {
availableBackgroundSelectorItems = [
...availableBackgroundSelectorItems,
...list.map(({ name, value }) =>
createBackgroundSelectorItem(null, name, value, true, change)
),
];
}

return {
items: availableBackgroundSelectorItems,
selectedBackgroundColor,
};
const getDisplayableState = memoize(10)((props: BackgroundToolProps, state: BackgroundToolState, change) => {
const data = props.api.getCurrentStoryData();
const list: BackgroundConfig[] = (data && data.parameters && data.parameters[PARAM_KEY]) || [];

const selectedBackgroundColor = getSelectedBackgroundColor(list, state.selected);

let availableBackgroundSelectorItems: BackgroundSelectorItem[] = [];

if (selectedBackgroundColor !== 'transparent') {
availableBackgroundSelectorItems.push(createBackgroundSelectorItem('reset', 'Clear background', 'transparent', null, change));
}
);

if (list.length) {
availableBackgroundSelectorItems = [
...availableBackgroundSelectorItems,
...list.map(({ name, value }) => createBackgroundSelectorItem(null, name, value, true, change)),
];
}

return {
items: availableBackgroundSelectorItems,
selectedBackgroundColor,
};
});

interface BackgroundToolProps {
api: {
Expand Down Expand Up @@ -128,11 +119,7 @@ export class BackgroundSelector extends Component<BackgroundToolProps, Backgroun

render() {
const { expanded } = this.state;
const { items, selectedBackgroundColor } = getDisplayableState(
this.props,
this.state,
this.change
);
const { items, selectedBackgroundColor } = getDisplayableState(this.props, this.state, this.change);

return items.length ? (
<Fragment>
Expand All @@ -149,9 +136,7 @@ export class BackgroundSelector extends Component<BackgroundToolProps, Backgroun
placement="top"
trigger="click"
tooltipShown={expanded}
onVisibilityChange={(newVisibility: boolean) =>
this.setState({ expanded: newVisibility })
}
onVisibilityChange={(newVisibility: boolean) => this.setState({ expanded: newVisibility })}
tooltip={<TooltipLinkList links={items} />}
closeOnClick
>
Expand Down
2 changes: 1 addition & 1 deletion addons/storysource/src/StoryPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default class StoryPanel extends Component {
const story = this.createPart(storyRows, stylesheet, useInlineStyles);
const storyKey = `${first}-${last}`;

if (areLocationsEqual(location, currentLocation)) {
if (location && currentLocation && areLocationsEqual(location, currentLocation)) {
return (
<SelectedStoryHighlight key={storyKey} ref={this.setSelectedStoryRef}>
{story}
Expand Down
2 changes: 1 addition & 1 deletion addons/viewport/src/Tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const getState = memoize(10)((props, state, change) => {
id: 'rotate',
title: 'Rotate viewport',
onClick: () => {
change({ isRotated: !state.isRotate, expanded: false });
change({ isRotated: !state.isRotated, expanded: false });
},
},
]
Expand Down

0 comments on commit cedc39f

Please sign in to comment.