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: Fixes #242 (an action appears in the controls tab as an invalid control type) #246

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
fix: Fixes #242 (an action appears in the controls tab as an invalid …
…control type).

In the controls panel, filter out the non-control args so that e.g. actions do not incorrectly get shown in the controls tab.
  • Loading branch information
lauriharpf committed Jul 28, 2021
commit 12de09a5a233b6ce5fd32ee43ed4f9eb955e3b7a
20 changes: 10 additions & 10 deletions addons/ondevice-controls/src/ControlsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ const ControlsPanel = ({ api }: { api: API }) => {
const storyId = store.getSelection().storyId;
const [argsfromHook, updateArgs, resetArgs] = useArgs(storyId, store);
const { argTypes, parameters } = store.fromId(storyId);
const argsObject = Object.entries(argsfromHook).reduce((prev, [name, value]) => {
const isControl = Boolean(argTypes?.[name]?.control);

const isArgsStory = parameters.__isArgsStory;

const hasControls = Object.values(argTypes).some((arg: ArgType) => arg?.control);
const showWarning = !(hasControls && isArgsStory);
const argsObject = hasControls
? Object.entries(argsfromHook).reduce((prev, [name, value]) => {
return {
return isControl
? {
...prev,
[name]: { ...argTypes?.[name], name, type: argTypes[name]?.control?.type, value },
};
}, {})
: {};
}
: prev;
}, {});
const hasControls = Object.keys(argsObject).length > 0;
const isArgsStory = parameters.__isArgsStory;
const showWarning = !(hasControls && isArgsStory);

return (
<>
Expand Down
3 changes: 3 additions & 0 deletions examples/native/components/ActionExample/Actions.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const ActionButtonMeta: ComponentMeta<typeof ActionButton> = {
argTypes: {
onPress: { action: 'pressed the button' },
},
args: {
text: 'Press me!',
},
};
export default ActionButtonMeta;

Expand Down
5 changes: 3 additions & 2 deletions examples/native/components/ActionExample/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { TouchableOpacity, Text, StyleSheet } from 'react-native';

interface ActionButtonProps {
onPress: () => void;
text: string;
}

export const ActionButton = ({ onPress }: ActionButtonProps) => {
export const ActionButton = ({ onPress, text }: ActionButtonProps) => {
return (
<TouchableOpacity style={styles.container} onPress={onPress}>
<Text style={styles.text}>ActionButton</Text>
<Text style={styles.text}>{text}</Text>
</TouchableOpacity>
);
};
Expand Down