Files
3x-ui/frontend/src/components/form/HeaderMapEditor.stories.tsx
T
MHSanaei 7078abc14a feat(frontend): make Storybook a validated, fully covered component workbench
Storybook existed only as an undocumented local tool: 9 of 24 reusable components had stories, autodocs pages were bare prop tables, nothing built or tested the stories, and no contributor doc mentioned the workbench existed.

Every reusable component under src/components/ now has a co-located story with enriched autodocs (component descriptions plus per-prop argTypes, kept as string metadata since the repo bans line comments). Stories double as headless Chromium tests through the Storybook vitest addon, with axe accessibility checks enforced as errors and play-function interaction tests covering the modals, the RHF field bridge, the config block, and the select-all buttons. The preview now mirrors the panel's real theme DOM (body class, shared AntD theme config, seeded theme storage) so what stories render matches production.

CI and make verify gain a static Storybook build as a compile gate, and the frontend test job installs Chromium so story tests run on every PR. Contributor docs (frontend README, CONTRIBUTING, agent guides) document the workbench, the story conventions, and the Controls setup. Node engines move to 24 LTS and gen:api drops the type-stripping flags that Node 24 makes default.
2026-07-14 03:37:21 +02:00

77 lines
2.3 KiB
TypeScript

import { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import HeaderMapEditor, { type HeaderMapValue } from './HeaderMapEditor';
const meta = {
title: 'Form/HeaderMapEditor',
component: HeaderMapEditor,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component:
'Row-based editor for Xray HTTP header maps, used in the inbound/outbound stream forms. Mode `v1` emits one string per header name (WS / HTTPUpgrade / Hysteria masquerade); mode `v2` emits string arrays so headers can repeat (TCP HTTP camouflage request/response).',
},
},
},
argTypes: {
mode: { description: 'Wire shape: `v1` = string per name, `v2` = string[] per name (repeatable headers).' },
value: { description: 'Header map in the wire shape matching `mode`; converted to editable rows internally.' },
onChange: { description: 'Called with the rebuilt wire-shape map after every row edit, add, or remove.' },
},
} satisfies Meta<typeof HeaderMapEditor>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Empty: Story = {
args: { mode: 'v1', onChange: () => undefined },
};
export const WsHostHeaders: Story = {
args: {
mode: 'v1',
value: {
Host: 'cdn.example.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
},
onChange: () => undefined,
},
};
export const TcpCamouflageRequest: Story = {
args: {
mode: 'v2',
value: {
Accept: ['text/html,application/xhtml+xml', 'application/json'],
'Accept-Encoding': ['gzip, deflate'],
Connection: ['keep-alive'],
Pragma: ['no-cache'],
},
onChange: () => undefined,
},
};
function WireShapeDemo() {
const [value, setValue] = useState<HeaderMapValue>({
Accept: ['text/html', 'application/json'],
'X-Forwarded-For': ['203.0.113.7'],
});
return (
<div style={{ maxWidth: 560 }}>
<HeaderMapEditor mode="v2" value={value} onChange={setValue} />
<pre style={{ marginTop: 16, padding: 12, borderRadius: 8, background: 'rgba(128, 128, 128, 0.12)' }}>
{JSON.stringify(value ?? {}, null, 2)}
</pre>
</div>
);
}
export const LiveWireShape: Story = {
args: { mode: 'v2', onChange: () => undefined },
render: () => <WireShapeDemo />,
};