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

feat: nested grouping of stories with "group/story" syntax #486

Merged
merged 9 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 1 addition & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ built-storybooks
.yarn
!.remarkrc.js
!.babelrc.js
!.eslintrc.js
!.eslintrc-markdown.js
.eslintrc.js
!.jest.config.js
!.storybook
examples/expo-example/metro.config.js
Expand Down
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
root: true,
extends: '@react-native',

// overrides: [...conf.overrides, { files: ['*.ts', '*.tsx'], rules: { 'no-undef': 'off' } }],
rules: {
'react-native/no-inline-styles': 'off',
},
};
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ node_modules
*.log
.idea
*.iml
.vscode/*
!.vscode/launch.json
*.sw*
npm-shrinkwrap.json
dist
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
2 changes: 1 addition & 1 deletion examples/expo-example/App.tsx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './.storybook/Storybook';
export { default } from './.storybook';
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { ComponentMeta, ComponentStoryObj } from '@storybook/react-native';
import { Text } from 'react-native';
import React from 'react';

const MyComponent = ({ text }) => <Text>{text}</Text>;

export default {
title: 'Chat/Message',
component: MyComponent,
} as ComponentMeta<typeof MyComponent>;

export const MessageFirst: ComponentStoryObj<typeof MyComponent> = {
args: {
text: 'Hello',
},
};

export const MessageSecond: ComponentStoryObj<typeof MyComponent> = {
args: {
text: 'Message two',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { ComponentMeta, ComponentStoryObj } from '@storybook/react-native';
import { Text } from 'react-native';
import React from 'react';

const MyComponent = ({ text }) => <Text>{text}</Text>;

export default {
title: 'Chat/Message/bubble',
component: MyComponent,
} as ComponentMeta<typeof MyComponent>;

export const First: ComponentStoryObj<typeof MyComponent> = {
args: {
text: 'First',
},
};

export const Second: ComponentStoryObj<typeof MyComponent> = {
storyName: 'Second Story',
args: {
text: 'Second',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { ComponentMeta, ComponentStoryObj } from '@storybook/react-native';
import { Text } from 'react-native';
import React from 'react';

const MyComponent = ({ text }) => <Text>{text}</Text>;

export default {
title: 'Chat/MessageInput',
component: MyComponent,
} as ComponentMeta<typeof MyComponent>;

export const Basic: ComponentStoryObj<typeof MyComponent> = {
args: {
text: 'Hello',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { ComponentMeta, ComponentStoryObj } from '@storybook/react-native';
import { Text } from 'react-native';
import React from 'react';

const MyComponent = ({ text }) => <Text>{text}</Text>;

export default {
title: 'Chat/Message/Reactions',
component: MyComponent,
} as ComponentMeta<typeof MyComponent>;

export const MessageOne: ComponentStoryObj<typeof MyComponent> = {
args: {
text: 'Hello',
},
};

export const MessageTwo: ComponentStoryObj<typeof MyComponent> = {
args: {
text: 'Message two',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { ComponentMeta, ComponentStoryObj } from '@storybook/react';
import StoryListView from '@storybook/react-native/dist/preview/components/StoryListView/StoryListView';

export default {
title: 'StoryListView',
component: StoryListView,
} as ComponentMeta<typeof StoryListView>;

export const Basic: ComponentStoryObj<typeof StoryListView> = {
args: {
storyIndex: {
stories: {
'chat-message--message-first': {
id: 'chat-message--message-first',
importPath: './components/NestingExample/ChatMessage.stories.tsx',
name: 'Message First',
title: 'Chat/Message',
},
'chat-message--message-second': {
id: 'chat-message--message-second',
importPath: './components/NestingExample/ChatMessage.stories.tsx',
name: 'Message Second',
title: 'Chat/Message',
},
'chat-message-bubble--first': {
id: 'chat-message-bubble--first',
importPath: './components/NestingExample/ChatMessageBubble.stories.tsx',
name: 'First',
title: 'Chat/Message/bubble',
},
'chat-message-bubble--second': {
id: 'chat-message-bubble--second',
importPath: './components/NestingExample/ChatMessageBubble.stories.tsx',
name: 'Second Story',
title: 'Chat/Message/bubble',
},
'chat-message-reactions--message-one': {
id: 'chat-message-reactions--message-one',
importPath: './components/NestingExample/ChatMessageReactions.stories.tsx',
name: 'Message One',
title: 'Chat/Message/Reactions',
},
'chat-message-reactions--message-two': {
id: 'chat-message-reactions--message-two',
importPath: './components/NestingExample/ChatMessageReactions.stories.tsx',
name: 'Message Two',
title: 'Chat/Message/Reactions',
},
'chat-messageinput--basic': {
id: 'chat-messageinput--basic',
importPath: './components/NestingExample/ChatMessageMessageInput.stories.tsx',
name: 'Basic',
title: 'Chat/MessageInput',
},
'storylistview--basic': {
id: 'storylistview--basic',
importPath: './components/NestingExample/StoryList.stories.tsx',
name: 'Basic',
title: 'StoryListView',
},
'text-control--basic': {
id: 'text-control--basic',
importPath: './components/ControlExamples/Text/Text.stories.tsx',
name: 'Basic',
title: 'Text control',
},
},
v: 3,
},
},
};
2 changes: 1 addition & 1 deletion examples/expo-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"expo": "^48.0.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.71.3",
"react-native": "0.71.8",
"react-native-safe-area-context": "4.5.0",
"react-native-web": "~0.18.10"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
"test": "jest"
},
"jest": {
"modulePathIgnorePatterns": [
"dist/"
],
"moduleFileExtensions": [
"ts",
"tsx",
Expand Down Expand Up @@ -72,6 +75,7 @@
},
"devDependencies": {
"@types/react": "~18.0.27",
"@types/jest": "^29.4.3",
"babel-jest": "^29.4.3",
"jest": "^29.4.3",
"react-test-renderer": "18.2.0"
Expand Down
25 changes: 23 additions & 2 deletions packages/react-native/src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useTheme as useEmotionTheme } from 'emotion-theming';
import type { Theme } from './preview/components/Shared/theme';

import type { ReactNativeFramework } from './types/types-6.0';
import { StoryIndexEntry } from '@storybook/client-api';

const storyContextAtom = atom(null as StoryContext<ReactNativeFramework> | null);

Expand Down Expand Up @@ -41,11 +42,31 @@ export function useIsStorySelected(storyId: string) {
}

/**
* Hook that indicates if `title` is the currently selected story section.
* Hook that indicates if story kind (title) is the currently selected story section.
*/
export function useIsStorySectionSelected(title: string) {
return useAtomValue(
useMemo(() => atom((get) => get(storyContextAtom)?.title === title), [title])
useMemo(
() =>
atom((get) => {
const contextTitle = get(storyContextAtom)?.title;
return contextTitle === title || contextTitle?.startsWith(`${title}/`);
}),
[title]
)
);
}

export function useIsChildSelected(entries: StoryIndexEntry[]) {
return useAtomValue(
useMemo(
() =>
atom((get) => {
const contextId = get(storyContextAtom)?.id;
return !!entries.find(({ id }) => id === contextId);
}),
[entries]
)
Comment on lines +60 to +69
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not super clear from reading the calling code whether item.stories is a stable reference. Does it only change when Storybook core needs to update (because of HMR or whatever else)?

Copy link
Member Author

@dannyhw dannyhw Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When filtering the tree can be recreated, its based on the 'data' state which gets set when filtering

);
}

Expand Down
Loading