Skip to content

Commit

Permalink
Slimmed down stories to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Nov 11, 2020
1 parent a5bee74 commit 3c48943
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const decorators = [
]

const sortPriority = {
'Slate/Interfaces/Editor': 1,
'Slate/Concepts/Decorations': 2,
'Slate/Interfaces': 1,
'Slate/Concepts': 2,
}

/** Sort stories in sidebar */
Expand Down
4 changes: 2 additions & 2 deletions src/components/ApiView/ApiView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ const ApiView: React.FC<ApiViewProps> = ({

return (
<div css={componentCss}>
<h1>Editor Interface</h1>
<h1>{title} Interface</h1>
<select value={apiFunction.name} onChange={onApiFunctionChange}>
{apiFunctionList.map((fn) => (
<option key={fn.name} value={fn.name}>
Editor.{fn.name}
{title}.{fn.name}
</option>
))}
</select>
Expand Down
File renamed without changes.
36 changes: 36 additions & 0 deletions src/stories/Interfaces/Interface.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react'
import { Story } from '@storybook/react'
import { ApiView, ApiViewProps } from '../../components'
import {
editorApiFunctions,
nodeApiFunctions,
pathApiFunctions,
} from '../util/api'
import { createStoryFactory, createStoryMeta } from './util'

const meta = createStoryMeta()
export default meta

const InterfaceTemplate: Story<ApiViewProps> = (args) => <ApiView {...args} />

const createEditorStory = createStoryFactory(
() => InterfaceTemplate.bind({}),
'Editor',
editorApiFunctions
)

const createPathStory = createStoryFactory(
() => InterfaceTemplate.bind({}),
'Path',
pathApiFunctions
)

const createNodeStory = createStoryFactory(
() => InterfaceTemplate.bind({}),
'Node',
nodeApiFunctions
)

export const editor = createEditorStory()
export const node = createNodeStory()
export const path = createPathStory()
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions src/stories/Interfaces/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@ import { ApiViewProps } from '../../components'
import { NodeSpecContextDecorator } from '../util'

export function createStoryMeta(interfaceName?: string) {
let persistentValue: Node[] | undefined = undefined

return {
title: interfaceName
? `Slate/Interfaces/${interfaceName}`
: 'Slate/Interfaces',
decorators: [
(Story, context) => {
const [value, setValue] = React.useState<Node[]>(
context.parameters.initialSlateValue
)
return (
<NodeSpecContextDecorator
story={Story}
initialSlateValue={
persistentValue ?? context.parameters.initialSlateValue
}
initialSlateValue={value}
onChange={(value) => {
persistentValue = value
setValue(value)
}}
/>
)
Expand All @@ -38,12 +37,13 @@ export function createStoryFactory<
return function createStory(fnName?: K) {
const story = storyFn()
story.storyName = (fnName as string) ?? label
const title = fnName ? `${label}.${fnName}` : label
if (!fnName) {
fnName = Object.keys(apiFunctions)[0] as K
}
const initialApiFunction = apiFunctions[fnName]!
story.args = {
title: `${label}.${fnName}`,
title,
renderElement,
renderLeaf,
initialApiFunction,
Expand Down

0 comments on commit 3c48943

Please sign in to comment.