-
Notifications
You must be signed in to change notification settings - Fork 410
RI-7640: Storybook and Playground #5062
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
base: main
Are you sure you want to change the base?
Changes from 146 commits
d377072
3a3696b
ba385ab
049a991
3c3b65f
1832c1a
e5ed77b
8026a6c
36e23a1
e2a9bfe
f580b98
192aa1f
e9358e0
f1051e2
31da78e
40cbb55
75db002
52771a4
d07d5d2
eee47b2
aaaa43b
6301a55
05ef986
88bfbe9
4966145
226baf2
1acb93a
e836924
f744afc
0f0e74f
a02015d
5c04afc
321112b
735ad96
42a16fb
6803376
4e1f2d3
c4045c9
4937213
f33e3da
d4ef6ef
85ab56d
47ab453
0d1e8ee
38a54bb
88c342b
5775639
b58bb78
b916a2a
03855eb
eaa652e
e78731f
e098586
12f628a
f976c0c
8c831cb
822c0e9
d24f422
78f808d
51a6f74
c311f89
12a402b
02aa2aa
4893c44
355db6c
96a592a
f043f43
4817dfc
1d6d38a
7ef621e
3b897fa
ba26fac
6db7083
960bcc9
ba662a9
ee882ea
79e5e29
ecefce7
93c5de6
c9aeaf9
c2df435
97b2d46
901d5ec
7de2983
6553188
ffda0f7
839830c
66a4de2
4f09c94
b3ba28e
a4ca899
5f12ecf
0c385bd
e98b604
5fc5800
84a3d21
0b87f59
4cb33d0
1469bda
662ee58
bf3ddfe
384bdff
62f8a72
01d6ef4
debba5d
face974
1320c70
e075507
7f0bbd4
bd05295
c7bb583
59650e0
6d9f45f
f93a9a7
e3f0b73
0dd6e01
483390b
4c6983b
a7f885d
b993a06
9508198
65736aa
2e64134
f08ae61
8416742
5c86907
030f3f0
907799f
a061b08
5d79c26
42e9f44
6f299db
b7f9784
39f44b7
9cbbaf1
aebbb0d
a1bde87
219ab51
eda6306
62b099d
f2cff8a
17d8991
24534e1
f17bd58
0b084fd
86df9b6
03d428e
4aede66
a05dfa3
8fc9907
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,3 +87,6 @@ static/ | |
|
|
||
| .env* | ||
| .npmrc | ||
|
|
||
| *storybook.log | ||
| storybook-static | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import React, { FC, PropsWithChildren } from 'react' | ||
| import { StoryContext } from '@storybook/react-vite' | ||
|
|
||
| export interface Parameters { | ||
| storyLayout?: FC<PropsWithChildren<{ storyContext: StoryContext }>> | ||
| } | ||
|
|
||
| /** | ||
| * Note: for use in Storybook preview config | ||
| * | ||
| * Define parameters.storyLayout as React component, and it will be used as root layout of the story | ||
| */ | ||
| export const RootStoryLayout = ({ | ||
| children, | ||
| storyContext, | ||
| }: Required<PropsWithChildren<{ storyContext: StoryContext }>>) => { | ||
| const { storyLayout } = storyContext.parameters | ||
| if (!storyLayout) { | ||
| return <>{children}</> | ||
| } | ||
| if (React.isValidElement(storyLayout)) { | ||
| // @ts-ignore | ||
| return React.cloneElement(storyLayout, { storyContext }, children) | ||
| } | ||
|
|
||
| const StoryLayout = storyLayout | ||
| return <StoryLayout storyContext={storyContext}>{children}</StoryLayout> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { createContext, useContext } from 'react' | ||
| import { StoryContext } from '@storybook/react-vite' | ||
|
|
||
| const Context = createContext<StoryContext | null>(null) | ||
|
|
||
| export const StoryContextProvider = Context.Provider | ||
|
|
||
| export const useStoryContext = () => { | ||
| const context = useContext(Context) | ||
| if (!context) | ||
| throw new Error('useStoryContext must be used within StoryContextProvider') | ||
| return context | ||
| } | ||
|
|
||
| export const useStoryParameter = <T>(parameterKey: string): T | undefined => | ||
| useStoryContext().parameters[parameterKey] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import styled from 'styled-components' | ||
| import { Theme } from 'uiSrc/components/base/theme/types' | ||
|
|
||
| export const StyledContainer = styled.div` | ||
| padding: 50px; | ||
| height: max-content; | ||
| overflow: hidden; | ||
| overflow-y: auto; | ||
| background-color: ${({ theme }: { theme: Theme }) => | ||
| theme.semantic.color.background.neutral100}; | ||
| border: 2px solid | ||
| ${({ theme }: { theme: Theme }) => theme.semantic.color.border.neutral500}; | ||
| ` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import type { StorybookConfig } from '@storybook/react-vite' | ||
| import { mergeConfig } from 'vite' | ||
| import vc from './vite.config' | ||
|
|
||
| const config: StorybookConfig = { | ||
| async viteFinal(inlineConfig) { | ||
| // return the customized config | ||
| return mergeConfig(inlineConfig, vc) | ||
| }, | ||
| stories: [ | ||
| '../stories/**/*.mdx', | ||
| '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)', | ||
| '../redisinsight/ui/src/**/*.stories.@(js|jsx|mjs|ts|tsx)', | ||
| '../redisinsight/ui/src/**/*.mdx', | ||
| ], | ||
| addons: [ | ||
| '@storybook/addon-a11y', | ||
| '@storybook/addon-docs', | ||
| '@storybook/addon-links', | ||
| '@storybook/addon-themes', | ||
| ], | ||
| framework: { | ||
| name: '@storybook/react-vite', | ||
| options: {}, | ||
| }, | ||
| } | ||
| export default config |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <script> | ||
| window.global = window; | ||
| </script> | ||
| <style> | ||
| :root { | ||
| /* | ||
| Insert global variables here: | ||
| colors, sizes, fonts, etc. | ||
| */ | ||
| } | ||
|
|
||
| body { | ||
| min-height: 100vh; | ||
| } | ||
|
|
||
| .sbdocs-wrapper div:has(>div>.toc-wrapper){ | ||
| width:14rem; | ||
| } | ||
|
|
||
| .sbdocs-wrapper div:has(>.toc-wrapper){ | ||
| width:fit-content; | ||
| margin-right:1rem; | ||
| } | ||
|
|
||
| .sbdocs-wrapper .toc-wrapper .toc-list-item { | ||
| padding-block: 5px; | ||
| } | ||
|
|
||
| .sb-errordisplay pre code { | ||
| background-color: transparent; | ||
| } | ||
|
|
||
| .docblock-argstable [type='checkbox'][role='switch'] { | ||
| display: none; | ||
| } | ||
|
|
||
| pre:has(.docblock-source), pre.prismjs{ | ||
| max-height: none; /*fix code block scroll*/ | ||
| } | ||
|
|
||
| .docblock-source [data-radix-scroll-area-viewport], | ||
| .docs-story + div [data-radix-scroll-area-viewport]{ | ||
| max-height: 80vh; /*add max height of code block*/ | ||
| } | ||
|
|
||
| </style> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import React from 'react' | ||
| import type { Parameters, Preview } from '@storybook/react-vite' | ||
| import { withThemeFromJSXProvider } from '@storybook/addon-themes' | ||
| import { | ||
| createGlobalStyle, | ||
| ThemeProvider as StyledThemeProvider, | ||
| } from 'styled-components' | ||
| import { CommonStyles, themeDark, themeLight, themeOld } from '@redis-ui/styles' | ||
| import 'modern-normalize/modern-normalize.css' | ||
| import '@redis-ui/styles/normalized-styles.css' | ||
| import '@redis-ui/styles/fonts.css' | ||
| import { RootStoryLayout } from './RootStoryLayout' | ||
| import { StoryContextProvider } from './Story.context' | ||
| import { useStoryContext } from 'storybook/internal/preview-api' | ||
| import { TooltipProvider } from '@redis-ui/components' | ||
| import { type Theme } from 'uiSrc/components/base/theme/types' | ||
| // import { store } from 'uiSrc/utils/test-utils' | ||
| import { Provider } from 'react-redux' | ||
| import { store } from 'uiSrc/slices/store' | ||
| import Router from 'uiSrc/Router' | ||
|
|
||
| const parameters: Parameters = { | ||
| parameters: { | ||
| layout: 'centered', | ||
| }, | ||
| actions: { argTypesRegex: '^on[A-Z].*' }, | ||
| controls: { | ||
| disableSaveFromUI: true, | ||
| matchers: { | ||
| color: /(background|color)$/i, | ||
| date: /Date$/, | ||
| }, | ||
| expanded: true, | ||
| sort: 'requiredFirst', | ||
| exclude: ['theme'], | ||
| }, | ||
| docs: { | ||
| toc: true, | ||
| controls: { | ||
| sort: 'requiredFirst', | ||
| }, | ||
| }, | ||
| options: { | ||
| storySort: { | ||
| method: 'alphabetical', | ||
| order: ['Getting Started', 'Playground', '*'], | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| const GlobalStoryStyles = createGlobalStyle` | ||
| .sb-show-main, .docs-story { | ||
| background: ${({ theme }: { theme: Theme }) => theme.globals.body.bgColor}; | ||
| color: ${({ theme }: { theme: Theme }) => theme.globals.body.textColor}; | ||
| } | ||
| ` | ||
|
|
||
| const preview: Preview = { | ||
| parameters, | ||
| decorators: [ | ||
| (Story) => ( | ||
| <StoryContextProvider value={useStoryContext()}> | ||
| <Router> | ||
| <Provider store={store}> | ||
| <TooltipProvider> | ||
| <RootStoryLayout storyContext={useStoryContext()}> | ||
| <CommonStyles /> | ||
| <Story /> | ||
| </RootStoryLayout> | ||
| </TooltipProvider> | ||
| </Provider> | ||
| </Router> | ||
| </StoryContextProvider> | ||
| ), | ||
| withThemeFromJSXProvider({ | ||
| themes: { | ||
| light: themeLight, | ||
| dark: themeDark, | ||
| obsolete: themeOld, | ||
| }, | ||
| defaultTheme: 'light', | ||
| Provider: StyledThemeProvider, | ||
| GlobalStyles: GlobalStoryStyles, | ||
| }), | ||
| ], | ||
| } | ||
|
|
||
| export default preview |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { create } from '@storybook/theming/create'; | ||
|
|
||
| export default create({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do we use this? I don't see the Redis title/logo/colors anywhere. I have changed all the values below, and still I see the default Storybook UI, so I think this file is not loaded properly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is within the canvas if anywhere. I copied it from redis-ui storybook setup |
||
| base: 'light', | ||
|
|
||
| brandTitle: 'Redis UI', | ||
| brandUrl: 'https://github.com/redislabsdev/redis-ui', | ||
| brandImage: 'logo.svg', | ||
| brandTarget: '_blank', | ||
|
|
||
| colorPrimary: '#001D2D', | ||
| colorSecondary: '#FF4438', | ||
|
|
||
| // UI | ||
| appBg: '#001D2D', | ||
|
|
||
| // Toolbar default and active colors | ||
| barBg: '#F0F0F0', | ||
| textMutedColor: '#5C707A' | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "extends": "../tsconfig.json", | ||
| "compilerOptions": { | ||
| "jsx": "react", | ||
| "types": ["node", "vite/client"], | ||
| "module": "ESNext" | ||
| }, | ||
| "include": [ | ||
| "./**/*" | ||
| ] | ||
| } |
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.
Nice, we use Redis UI to style Stroybook as well 😀