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

Migrate component docs #304

Open
thien-do opened this issue Jul 28, 2024 · 0 comments
Open

Migrate component docs #304

thien-do opened this issue Jul 28, 2024 · 0 comments
Assignees

Comments

@thien-do
Copy link
Owner

thien-do commented Jul 28, 2024

At the develop branch, the Button component is migrated as an example. Let's migrate the rest of them.

image image

Use the guide below to migrate them.

Migration Guide

  1. To define stories, use object (StoryObj) instead of function (StoryFn):
// Before
export const Foo = (): JSX.Element => { ... }

// After
export const Foo: StoryObj = {
  render: () => {
    return ...
  }
}
  1. For the return type, use ReactElement instead of JSX.Element. However, if the function is already typed, such as via StoryObj.render, then we don't need to provide an explicit return type:
export const Foo: StoryObj = {
  // Already typed
  render: () => {
    return ...
  }
}
  1. For story description, use JSDoc instead of Utils.story. Remember to unescape the grave accent ("`") character:
// Before
export const Foo = () => ...

Utils.story(Foo, { desc: `
Hello \`world\`
` });

// After
/**
 * Hello `world`
 */
export const Foo: StoryObj = { render }
  1. When writing descriptions, manually break lines at sentences or clauses, not at arbitrary fixed column like 80 or 100:
// Before
`
This is a sentence. This is
another sentence, with 2 clauses.
`

// After
/**
 * This is a sentence.
 * This is another sentence,
 * with 2 clauses.
 */
  1. In meta, use docsMetaParameters instead of Utils.page.component:
// Before
const meta = {}

Utils.page.component(meta, {
  shots
})

// After
const meta = {
  parameters: docsMetaParameters({
    gallery
  })
}
  1. In meta, use docsMetaArgTypes instead of Utils.arg:
// Before
const meta = {
  argTypes: {
    size: Utils.arg(Button.sizes, "Visual"),
    disabled: Utils.arg("boolean", "Functional"),
    id: Utils.arg(null, "Functional"),
  }
}

// After
const meta = {
  argTypes: docsMetaArgTypes({
    Visual: {
      size: Button.sizes,
    },
    Functional: {
      disabled: "boolean",
      id: false
    },
  })
}
  1. For primary story, provide the component type
    instead of defining the props interface again:
// Before
interface Props { }

export const Primary = (props: Props) => { }

// After
export const Primary: StoryObj<typeof Button> = {
  render: (props) => { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants