docs/_snippets/page-story-args-within-story.md
import { useArgs } from 'storybook/preview-api';
import { Checkbox } from './checkbox';
export default {
title: 'Inputs/Checkbox',
component: Checkbox,
};
export const Example = {
args: {
isChecked: false,
label: 'Try Me!',
},
/**
* ๐ To avoid linting issues, it is recommended to use a function with a capitalized name.
* If you are not concerned with linting, you may use an arrow function.
*/
render: function Render(args) {
const [{ isChecked }, updateArgs] = useArgs();
function onChange() {
updateArgs({ isChecked: !isChecked });
}
return <Checkbox {...args} onChange={onChange} isChecked={isChecked} />;
},
};
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, nextjs-vite, etc.
import type { Meta, StoryObj } from '@storybook/your-framework';
import { useArgs } from 'storybook/preview-api';
import { Checkbox } from './checkbox';
const meta = {
title: 'Inputs/Checkbox',
component: Checkbox,
} satisfies Meta<typeof Checkbox>;
export default meta;
type Story = StoryObj<typeof Checkbox>;
export const Example = {
args: {
isChecked: false,
label: 'Try Me!',
},
/**
* ๐ To avoid linting issues, it is recommended to use a function with a capitalized name.
* If you are not concerned with linting, you may use an arrow function.
*/
render: function Render(args) {
const [{ isChecked }, updateArgs] = useArgs();
function onChange() {
updateArgs({ isChecked: !isChecked });
}
return <Checkbox {...args} onChange={onChange} isChecked={isChecked} />;
},
} satisfies Story;
import { useArgs } from 'storybook/preview-api';
import preview from '../.storybook/preview';
import { Checkbox } from './checkbox';
const meta = preview.meta({
title: 'Inputs/Checkbox',
component: Checkbox,
});
export const Example = meta.story({
args: {
isChecked: false,
label: 'Try Me!',
},
/**
* ๐ To avoid linting issues, it is recommended to use a function with a capitalized name.
* If you are not concerned with linting, you may use an arrow function.
*/
render: function Render(args) {
const [{ isChecked }, updateArgs] = useArgs();
function onChange() {
updateArgs({ isChecked: !isChecked });
}
return <Checkbox {...args} onChange={onChange} isChecked={isChecked} />;
},
});
import { useArgs } from 'storybook/preview-api';
import preview from '../.storybook/preview';
import { Checkbox } from './checkbox';
const meta = preview.meta({
title: 'Inputs/Checkbox',
component: Checkbox,
});
export const Example = meta.story({
args: {
isChecked: false,
label: 'Try Me!',
},
/**
* ๐ To avoid linting issues, it is recommended to use a function with a capitalized name.
* If you are not concerned with linting, you may use an arrow function.
*/
render: function Render(args) {
const [{ isChecked }, updateArgs] = useArgs();
function onChange() {
updateArgs({ isChecked: !isChecked });
}
return <Checkbox {...args} onChange={onChange} isChecked={isChecked} />;
},
});