docs/_snippets/button-story.md
import React, { useState } from 'react';
import { Button } from './Button';
export default {
component: Button,
};
const ButtonWithHooks = () => {
// Sets the hooks for both the label and primary props
const [value, setValue] = useState('Secondary');
const [isPrimary, setIsPrimary] = useState(false);
// Sets a click handler to change the label's value
const handleOnChange = () => {
if (!isPrimary) {
setIsPrimary(true);
setValue('Primary');
}
};
return <Button primary={isPrimary} onClick={handleOnChange} label={value} />;
};
export const Primary = {
render: () => <ButtonWithHooks />,
};
import React, { useState } from 'react';
// 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 { Button } from './Button';
const meta = {
component: Button,
} satisfies Meta<typeof Button>;
export default meta;
type Story = StoryObj<typeof meta>;
const ButtonWithHooks = () => {
// Sets the hooks for both the label and primary props
const [value, setValue] = useState('Secondary');
const [isPrimary, setIsPrimary] = useState(false);
// Sets a click handler to change the label's value
const handleOnChange = () => {
if (!isPrimary) {
setIsPrimary(true);
setValue('Primary');
}
};
return <Button primary={isPrimary} onClick={handleOnChange} label={value} />;
};
export const Primary = {
render: () => <ButtonWithHooks />,
} satisfies Story;
import React, { useState } from 'react';
import preview from '../.storybook/preview';
import { Button } from './Button';
const meta = preview.meta({
component: Button,
});
const ButtonWithHooks = () => {
// Sets the hooks for both the label and primary props
const [value, setValue] = useState('Secondary');
const [isPrimary, setIsPrimary] = useState(false);
// Sets a click handler to change the label's value
const handleOnChange = () => {
if (!isPrimary) {
setIsPrimary(true);
setValue('Primary');
}
};
return <Button primary={isPrimary} onClick={handleOnChange} label={value} />;
};
export const Primary = meta.story({
render: () => <ButtonWithHooks />,
});
import React, { useState } from 'react';
import preview from '../.storybook/preview';
import { Button } from './Button';
const meta = preview.meta({
component: Button,
});
const ButtonWithHooks = () => {
// Sets the hooks for both the label and primary props
const [value, setValue] = useState('Secondary');
const [isPrimary, setIsPrimary] = useState(false);
// Sets a click handler to change the label's value
const handleOnChange = () => {
if (!isPrimary) {
setIsPrimary(true);
setValue('Primary');
}
};
return <Button primary={isPrimary} onClick={handleOnChange} label={value} />;
};
export const Primary = meta.story({
render: () => <ButtonWithHooks />,
});
import { createSignal } from 'solid-js';
import { Button } from './Button';
export default {
component: Button,
};
const ButtonWithHooks = () => {
// Sets the signals for both the label and primary props
const [value, setValue] = createSignal('Secondary');
const [isPrimary, setIsPrimary] = createSignal(false);
// Sets a click handler to change the label's value
const handleOnChange = () => {
if (!isPrimary()) {
setIsPrimary(true);
setValue('Primary');
}
};
return <Button primary={isPrimary()} onClick={handleOnChange} label={value()} />;
};
export const Primary = {
render: () => <ButtonWithHooks />,
};
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
import { createSignal } from 'solid-js';
import { Button } from './Button';
const meta = {
component: Button,
} satisfies Meta<typeof Button>;
export default meta;
type Story = StoryObj<typeof meta>;
const ButtonWithHooks = () => {
// Sets the signals for both the label and primary props
const [value, setValue] = createSignal('Secondary');
const [isPrimary, setIsPrimary] = createSignal(false);
// Sets a click handler to change the label's value
const handleOnChange = () => {
if (!isPrimary()) {
setIsPrimary(true);
setValue('Primary');
}
};
return <Button primary={isPrimary()} onClick={handleOnChange} label={value()} />;
};
export const Primary = {
render: () => <ButtonWithHooks />,
} satisfies Story;