Files
frontend/src/shared/ui/Button.stories.tsx
T
ksv741 72d7835227 chore: finish frontend ESLint migration #18
Enable every plugin recommended preset and replace Biome with ESLint formatting.

Preserve API contracts and JSX whitespace; verify source, tests, builds and tooling.
2026-09-28 16:36:40 +03:00

60 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Meta, StoryObj } from "@storybook/react-vite";
import { Button, type ButtonProps } from "@mantine/core";
import { expect, fn, userEvent, within } from "storybook/test";
type ButtonStoryArguments = ButtonProps & { onClick: () => void };
const meta = {
args: {
children: "Выполнить пример",
disabled: false,
loading: false,
onClick: fn(),
variant: "filled",
},
argTypes: {
children: { control: "text" },
disabled: { control: "boolean" },
loading: { control: "boolean" },
onClick: { control: false },
variant: { control: "select", options: ["filled", "default", "subtle"] },
},
component: Button,
parameters: {
docs: {
description: {
component:
"Прямой Mantine Button с общей темой WealthLedger, без wrapper. Filled — основное действие; default — вторичное действие/retry; subtle — малозаметное вспомогательное действие. Radius md, primary blue и keyboard focus приходят из темы. Дайте кнопке доступное имя; loading означает mutation, disabled — недоступное действие. Loading/disabled не исполняют callback. Actions и interaction проверяют локальный callback, не API recovery.",
},
},
},
tags: ["autodocs"],
title: "Design System/Components/Button",
} satisfies Meta<ButtonStoryArguments>;
export default meta;
type Story = StoryObj<ButtonStoryArguments>;
export const Primary: Story = {
name: "Основное действие",
play: async ({ args, canvasElement }) => {
const button = within(canvasElement).getByRole("button", {
name: typeof args.children === "string" ? args.children : undefined,
});
button.focus();
await expect(button).toHaveFocus();
await userEvent.keyboard("{Enter}");
await expect(args.onClick).toHaveBeenCalled();
},
};
export const Secondary: Story = {
args: { variant: "default" },
name: "Вторичное действие",
};
export const Subtle: Story = {
args: { variant: "subtle" },
name: "Вспомогательное действие",
};
export const Loading: Story = { args: { loading: true }, name: "Выполнение" };
export const Disabled: Story = { args: { disabled: true }, name: "Недоступно" };