-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
UI: Add links to documentation and videos in UI #25565
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e9d3168
Add API function to get versioned docs URL
be3ae37
Add docs link to sidebar menu; Fix left icons
4d8f835
Add new empty state to interactions panel
39e6fd8
Add icons to argstable to match other empty states
bffee5b
WIP: saving progress on renderer
d04198c
Add option to add renderer to url
26371a5
stringify injected globals
9f23041
Remove unneeded function
d355f59
Update code/addons/interactions/src/constants.ts
2321701
Merge branch 'next' into shaun/jit-learning
e17a7c6
Refactor logic for adding renderer globals
ac8a243
Add tests for framework utils
ecbeadc
Merge branch 'next' into shaun/jit-learning
4b8dc74
Add global vars to typings def
0735b1f
Remove unused import
627138b
Fix CI errors
cca6109
Normalize path for npm packages
e7d1e05
Merge branch 'next' into shaun/jit-learning
c40673e
Mock getDocsUrl
a6fe163
Remove unused import
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { Link } from '@storybook/components'; | ||
import { DocumentIcon, VideoIcon } from '@storybook/icons'; | ||
import { Consumer, useStorybookApi } from '@storybook/manager-api'; | ||
import { styled } from '@storybook/theming'; | ||
|
||
import { DOCUMENTATION_LINK, TUTORIAL_VIDEO_LINK } from '../constants'; | ||
|
||
const Wrapper = styled.div(({ theme }) => ({ | ||
height: '100%', | ||
display: 'flex', | ||
padding: 0, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
flexDirection: 'column', | ||
gap: 15, | ||
background: theme.background.content, | ||
})); | ||
|
||
const Content = styled.div({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: 4, | ||
maxWidth: 415, | ||
}); | ||
|
||
const Title = styled.div(({ theme }) => ({ | ||
fontWeight: theme.typography.weight.bold, | ||
fontSize: theme.typography.size.s2 - 1, | ||
textAlign: 'center', | ||
color: theme.textColor, | ||
})); | ||
|
||
const Description = styled.div(({ theme }) => ({ | ||
fontWeight: theme.typography.weight.regular, | ||
fontSize: theme.typography.size.s2 - 1, | ||
textAlign: 'center', | ||
color: theme.textMutedColor, | ||
})); | ||
|
||
const Links = styled.div(({ theme }) => ({ | ||
display: 'flex', | ||
fontSize: theme.typography.size.s2 - 1, | ||
gap: 25, | ||
})); | ||
|
||
const Divider = styled.div(({ theme }) => ({ | ||
width: 1, | ||
height: 16, | ||
backgroundColor: theme.appBorderColor, | ||
})); | ||
|
||
export const Empty = () => { | ||
const [isLoading, setIsLoading] = useState(true); | ||
const api = useStorybookApi(); | ||
const docsUrl = api.getDocsUrl({ | ||
subpath: DOCUMENTATION_LINK, | ||
versioned: true, | ||
renderer: true, | ||
}); | ||
|
||
// We are adding a small delay to avoid flickering when the story is loading. | ||
// It takes a bit of time for the controls to appear, so we don't want | ||
// to show the empty state for a split second. | ||
useEffect(() => { | ||
const load = setTimeout(() => { | ||
setIsLoading(false); | ||
}, 100); | ||
|
||
return () => clearTimeout(load); | ||
}, []); | ||
|
||
if (isLoading) return null; | ||
|
||
return ( | ||
<Wrapper> | ||
<Content> | ||
<Title>Interaction testing</Title> | ||
<Description> | ||
Interaction tests allow you to verify the functional aspects of UIs. Write a play function | ||
for your story and you'll see it run here. | ||
</Description> | ||
</Content> | ||
<Links> | ||
<Link href={TUTORIAL_VIDEO_LINK} target="_blank" withArrow> | ||
<VideoIcon /> Watch 8m video | ||
</Link> | ||
<Divider /> | ||
<Consumer> | ||
{({ state }) => ( | ||
<Link href={docsUrl} target="_blank" withArrow> | ||
<DocumentIcon /> Read docs | ||
</Link> | ||
)} | ||
</Consumer> | ||
</Links> | ||
</Wrapper> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export const ADDON_ID = 'storybook/interactions'; | ||
export const PANEL_ID = `${ADDON_ID}/panel`; | ||
|
||
export const TUTORIAL_VIDEO_LINK = 'https://youtu.be/Waht9qq7AoA'; | ||
export const DOCUMENTATION_LINK = 'writing-tests/interaction-testing'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import path from 'node:path'; | ||
import { describe, it, expect } from 'vitest'; | ||
|
||
import { | ||
pluckNameFromConfigProperty, | ||
pluckStorybookPackageFromPath, | ||
pluckThirdPartyPackageFromPath, | ||
} from './framework'; | ||
|
||
describe('UTILITIES: Framework information', () => { | ||
describe('UTILITY: pluckNameFromConfigProperty', () => { | ||
it('should return undefined if the property is undefined', () => { | ||
expect(pluckNameFromConfigProperty(undefined)).toBe(undefined); | ||
}); | ||
|
||
it('should return the name if the property is a string', () => { | ||
expect(pluckNameFromConfigProperty('foo')).toBe('foo'); | ||
}); | ||
|
||
it('should return the name if the property is an object', () => { | ||
expect(pluckNameFromConfigProperty({ name: 'foo' })).toBe('foo'); | ||
}); | ||
}); | ||
|
||
describe('UTILITY: pluckStorybookPackageFromPath', () => { | ||
it('should return the package name if the path is a storybook package', () => { | ||
const packagePath = path.join(process.cwd(), 'node_modules', '@storybook', 'foo'); | ||
expect(pluckStorybookPackageFromPath(packagePath)).toBe('@storybook/foo'); | ||
}); | ||
|
||
it('should return undefined if the path is not a storybook package', () => { | ||
const packagePath = path.join(process.cwd(), 'foo'); | ||
expect(pluckStorybookPackageFromPath(packagePath)).toBe(undefined); | ||
}); | ||
}); | ||
|
||
describe('UTILITY: pluckThirdPartyPackageFromPath', () => { | ||
it('should return the package name if the path is a third party package', () => { | ||
const packagePath = path.join(process.cwd(), 'node_modules', 'bar'); | ||
expect(pluckThirdPartyPackageFromPath(packagePath)).toBe('bar'); | ||
}); | ||
|
||
it('should return the given path if the path is not a third party package', () => { | ||
const packagePath = path.join(process.cwd(), 'foo', 'bar', 'baz'); | ||
expect(pluckThirdPartyPackageFromPath(packagePath)).toBe(packagePath); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import path from 'path'; | ||
import type { Options } from '@storybook/types'; | ||
|
||
interface PropertyObject { | ||
name: string; | ||
options?: Record<string, any>; | ||
} | ||
|
||
type Property = string | PropertyObject | undefined; | ||
|
||
export const pluckNameFromConfigProperty = (property: Property) => { | ||
if (!property) { | ||
return undefined; | ||
} | ||
|
||
return typeof property === 'string' ? property : property.name; | ||
}; | ||
|
||
// For replacing Windows backslashes with forward slashes | ||
const normalizePath = (packagePath: string) => packagePath.replaceAll(path.sep, '/'); | ||
|
||
export const pluckStorybookPackageFromPath = (packagePath: string) => | ||
normalizePath(packagePath).match(/(@storybook\/.*)$/)?.[1]; | ||
|
||
export const pluckThirdPartyPackageFromPath = (packagePath: string) => | ||
normalizePath(packagePath).split('node_modules/')[1] ?? packagePath; | ||
|
||
export const buildFrameworkGlobalsFromOptions = async (options: Options) => { | ||
const globals: Record<string, any> = {}; | ||
|
||
const { renderer, builder } = await options.presets.apply('core'); | ||
|
||
const rendererName = pluckNameFromConfigProperty(renderer); | ||
if (rendererName) { | ||
globals.STORYBOOK_RENDERER = | ||
pluckStorybookPackageFromPath(rendererName) ?? pluckThirdPartyPackageFromPath(rendererName); | ||
} | ||
|
||
const builderName = pluckNameFromConfigProperty(builder); | ||
if (builderName) { | ||
globals.STORYBOOK_BUILDER = | ||
pluckStorybookPackageFromPath(builderName) ?? pluckThirdPartyPackageFromPath(builderName); | ||
} | ||
|
||
const framework = pluckNameFromConfigProperty(await options.presets.apply('framework')); | ||
if (framework) { | ||
globals.STORYBOOK_FRAMEWORK = framework; | ||
} | ||
|
||
return globals; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️