Live Edit or enabling Controls in MDX format #13477
Replies: 3 comments 9 replies
-
Controls works in MDX using https://storybook.js.org/docs/react/writing-docs/doc-blocks#argstable |
Beta Was this translation helpful? Give feedback.
-
@KenACollins just wanted to give some context towards that particular piece of Documentation and @shilman feel free to correct me at any point. Following the tutorial, you start off with the following set of CSF stories contained within the import React from "react";
import { Avatar } from "./Avatar";
export default {
title: "Design System/Avatar",
component: Avatar,
parameters: {
componentSubtitle:
"Displays an image that represents a user or organization",
},
};
export const Standard = (args) => <Avatar {...args} />;
Standard.args = {
size: "large",
username: "Tom Coleman",
src: "https://avatars2.githubusercontent.com/u/132554",
}; A standard story using args that you can manipulate at will with Storybook Controls. You now are introduced to : import {
Meta,
Story,
Canvas,
ArgsTable,
Preview,
} from "@storybook/addon-docs/blocks";
import { Avatar } from "./Avatar";
<Meta title="Design System/Avatar" component={Avatar} />
# Avatar
## Displays an image that represents a user or organization
Use an avatar for attributing actions or content to specific users.
The user's name should _always_ be present when using Avatar – either printed beside the avatar or in a tooltip.
<Preview withToolbar>
<Story name="standard">
<Avatar
size="large"
username="Tom Coleman"
src="https://avatars2.githubusercontent.com/u/132554"
/>
</Story>
</Preview>
## Usage
Avatar is used to represent a person or an organization. By default the avatar shows an image and gracefully falls back to the first initial of the username. While hydrating the component you may find it useful to render a skeleton template to indicate that Avatar is awaiting data. Avatars can be grouped with the AvatarList component.
### Sizes
4 sizes are supported.
<Story name="sizes">
<div>
<Avatar
size="large"
username="Tom Coleman"
src="https://avatars2.githubusercontent.com/u/132554"
/>
<Avatar
size="medium"
username="Tom Coleman"
src="https://avatars2.githubusercontent.com/u/132554"
/>
<Avatar
size="small"
username="Tom Coleman"
src="https://avatars2.githubusercontent.com/u/132554"
/>
<Avatar
size="tiny"
username="Tom Coleman"
src="https://avatars2.githubusercontent.com/u/132554"
/>
</div>
</Story>
### Default Values
When no image is supplied to the `src` prop, Avatar displays initials.
Avatar should be used sparingly in situations without access to images.
<Story name="initials">
<div>
<Avatar username="Tom Coleman" />
<Avatar username="Dominic Nguyen" />
<Avatar username="Kyle Suss" />
<Avatar username="Michael Shilman" />
</div>
</Story>
### Loading
The loading state is used when the image or username is, well, loading.
<Story name="loading">
<div>
<Avatar size="large" loading />
<Avatar size="medium" loading />
<Avatar size="small" loading />
<Avatar size="tiny" loading />
</div>
</Story>
<ArgsTable story="loading" />
### Playground
Experiment with this story with the Controls addon in the Canvas tab.
export const Template = (args) => <Avatar {...args} />;
<Canvas>
<Story
name="controls"
args={{
loading: false,
size: "tiny",
username: "Dominic Nguyen",
src: "https://avatars2.githubusercontent.com/u/263385",
}}
>
{Template.bind({})}
</Story>
</Canvas> And if you check your Docs tab you'll get this: If you check your Storybook you'll see that you can still see your Stories being shown with the added bonus that in the Docs tab you get a richer experience and so on. You're then told to introduce the following: <ArgsTable of={Avatar} /> Which yields this: This change will allow you to expand the documentation (Docs tab) with the information you get from the props. Allowing you to further document for anyone that consumes the Design System being built. design-systems-avatar-mdx.mp4See the controls story? You get your controls working as they were when you're using JS with Args. A sui generis way of seeing this is the following:
export const standard = () => (
<Avatar
size="large"
username="Tom Coleman"
src="https://avatars2.githubusercontent.com/u/132554"
/>
);
)
Adding this change to that you get the "best of both worlds" ( pardon the bad pun). <ArgsTable story="controls" /> You can use Controls in the Canvas and you get a richer experience and better documentation in the Docs Tab. Which you can expand to your needs. All in all the scope of that particular section is the following:
Sorry for the long description but it seems that was in order and I hope I was able to shed some light on the subject and give you a bit more context. Let us know of any further issues you encounter. |
Beta Was this translation helpful? Give feedback.
-
@jonniebigodes or @shilman - I think this is the final question I have regarding controls! Bear with me. New topic. If this is not possible now, maybe it can be a feature of a future release. I know that the ability to add or exclude arguments within controls has been recently added to the 6.2.0-BETA release through pull request 13898 which you, @shilman, informed me of and helped get that beta release installed. Has any thought gone into making it possible to show all prop types defined in a component in the args table on the Docs tab but a lesser, filtered list within the args table that is used for controls? Here is my conundrum. I have components, as I am sure every developer has, that accept a bunch of arguments that are not capable of being manipulated within the Storybook UI. There could be the function I pass for the onClick event or an image file local to the file structure. From a documentation perspective, on the Docs tab I must explain all the possible arguments that can be passed to the component but the user cannot alter all of them in the controls story. Ideally, I would like to just show the arguments in the controls args table that can be manipulated on the screen. For example, I have a Button component that has 14 arguments but some are functions (onClick, onMouseEnter, etc.), there is an icon file parameter, a QA testing parameter, etc. But things like changing the button label and setting the state from enabled to disabled or from a primary button to a secondary button can be done in the Storybook UI. Rather than overwhelm the user by listing 14 arguments, most of which are not applicable to controls, it would be nice to only show the properties that can be altered to achieve a new button state while at the same time being able to document all possible arguments up above in the MDX file. |
Beta Was this translation helpful? Give feedback.
-
Hi All,
Is there a way to make Live edit or enable Control addon in the MDX format?
I have noticed that in DocsPage it is possible but not in MDX.
This would be a cool feature to have!
What do you guys think?
Beta Was this translation helpful? Give feedback.
All reactions