carbon-design-system / carbon-platform

The "next" version of the Carbon Design System website, as a platform.
https://next.carbondesignsystem.com
Apache License 2.0
21 stars 5 forks source link

Consume Component Storybook Format (CSF) ES6 modules #1475

Open mattrosno opened 2 years ago

mattrosno commented 2 years ago

Summary

What problem (or opportunity) are we solving? Why are we solving it? Is there supporting user conversations or research?

Related to https://github.com/carbon-design-system/carbon-platform/issues/1443, I've been thinking about what (if any) benefits we could get out of consuming Component Storybook Format (CSF) ES6 modules.

Links:

CSF is an open standard based on ES6 modules. It's how we write our Storybook stories. It's supported for all JavaScript frameworks. It allows you to get information about a component without using Storybook, such as:

The Carbon React library does not export stories JS files in its code package, so I haven't tested this, but assuming that stories are exported and available for consumption in Carbon Platform... how could this help us?

Job stories

What value will this deliver?

  1. When searching for a subcomponent in components catalog like TableActionList, I want to find its parent component, so I can view the documentation for how to use the subcomponent.
  2. When viewing the code documentation for a component at a specific version, I want to view which components, properties, and values are available at that specific version, so I don't have to look it up in source code.

Subcomponents

Do we want to index subcomponents? For example, the DataTable component has these child components: Table, TableActionList, TableBatchAction, TableBatchActions, TableBody, TableCell, TableContainer, TableExpandHeader, TableExpandRow, TableExpandedRow, TableHead, TableHeader, TableRow, TableSelectAll, TableSelectRow, TableToolbar, TableToolbarActionTableToolbarContentTableToolbarSearchTableToolbarMenu.

This is information that we could get from CSF. E.g.:

export default {
  title: 'Components/DataTable/Batch Actions',
  component: DataTable,
  subcomponents: {
    TableBatchAction,
    TableBatchActions,
    TableToolbar,
    TableToolbarAction,
    TableToolbarContent,
    TableToolbarSearch,
    TableToolbarMenu,
    Table,
    TableBody,
    TableCell,
    TableContainer,
    TableHead,
    TableHeader,
    TableRow,
  },
  parameters: {
    docs: {
      page: mdx,
    },
  },
};

API documentation

Carbon's website does not surface component API documentation. Storybook is good for this. For example, here is the API documentation for using Accordion, AccordionItem, and AccordionSkeleton:

https://react.carbondesignsystem.com/?path=/docs/components-accordion--default#component-api

At the time of writing this issue, that Storybook site is showing the latest version of Carbon React, @carbon/react@1.16.0.

What if you want to reference the component API for an older version of the Accordion? Our only option is to go all the way back to the last major version and reference this separate Storybook site:

https://v7-react.carbondesignsystem.com/?path=/docs/components-accordion--accordion-story

If we consumed component prop tables directly from source code and not from deployed Storybooks, then we could render a Code tab prop table for any library version, like:

https://next.carbondesignsystem.com/libraries/carbon-react/v11.16.0/assets/accordion

To reiterate the as-is: if you're using a library version that doesn't match deployed Storybook sites, your only option today to reference the exact component API is to reference source code.

Live demo properties

Let's say we wanted to add properties (and their values) to our live demo. We could manually set those in the MDX component, but that would become error-prone to stay up-to-date as the hosted Storybook is updated.

Is there any way that we could take the args table from CSF ES6 modules and use that in our live demos? In theory, yes, but there would still be multiple scenarios where those could get out of sync as the live demo embeds a hosted Storybook regardless of what library version that Storybook is using.

mattrosno commented 2 years ago

At this point, our Storybook demo links and live demos are nice because we just have to update URLs and not have a programatic dependency on CSF modules.

It's my recommendation that we don't pursue this until we know if there are any new embed options in Storybook v7. (For example, it would be great if we could embed controls.)

If we want to index sub-components for search purposes, that's something that we could add to the schema. But that doesn't seem high priority at the moment.

For now, when we have a component like Dropdown, that is actually built using multiple components, we could index that like this in the Carbon React library:

demoLinks:
  - type: storybook
    name: ComboBox
    action: link
    url: https://react.carbondesignsystem.com/?path=/story/components-combobox
  - type: storybook
    name: Dropdown
    action: link
    url: https://react.carbondesignsystem.com/?path=/story/components-dropdown
  - type: storybook
    name: MultiSelect
    action: link
    url: https://react.carbondesignsystem.com/?path=/story/components-multiselect
mattrosno commented 2 years ago

Some notes for context:

image image
tay1orjones commented 2 years ago

The CSF repo does not show versions, but they're iterating on it and it does seem synced with storybook releases

https://storybook.js.org/blog/component-story-format-3-0/