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

Fix/tooltip tools #5692

Merged
merged 4 commits into from
Feb 21, 2019
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
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