Files
CHOMPStation2/tgui/packages/tgui_ch/interfaces/TraitTutorial.tsx
2023-06-19 19:41:48 +02:00

85 lines
2.1 KiB
TypeScript

/* eslint-disable react/no-danger */
import { useBackend } from '../backend';
import { Stack, Tabs, Section, Box } from '../components';
import { Window } from '../layouts';
type data = {
namae: string;
names: string[];
descriptions: { key: string; val: string }[];
categories: { key: string; val: string }[];
tutorials: { key: string; val: string }[];
selection: string;
};
export const TraitTutorial = (props, context) => {
const { act, data } = useBackend<data>(context);
return (
<Window width={804} height={426}>
<Window.Content scrollable>
<Section title="Guide to Custom Traits">
<TraitSelection />
</Section>
</Window.Content>
</Window>
);
};
export const TraitSelection = (props, context) => {
const { act, data } = useBackend<data>(context);
const { names, selection } = data;
return (
<Stack>
<Stack.Item shrink>
<Section title="Trait Selection">
<Tabs vertical>
{names.map((name) => (
<Tabs.Tab
key={name}
selected={name === selection}
onClick={() => act('select_trait', { name })}>
<Box inline>{name}</Box>
</Tabs.Tab>
))}
</Tabs>
</Section>
</Stack.Item>
<Stack.Item grow={8}>
{selection && (
<Section title={selection}>
<TraitDescription name={selection} />
</Section>
)}
</Stack.Item>
</Stack>
);
};
export const TraitDescription = (props, context) => {
const { act, data } = useBackend<data>(context);
const { name } = props;
const { descriptions, categories, tutorials } = data;
return (
<Section StackWrap>
<b>Name:</b> {name}
<br />
<b>Category:</b> {categories[name]}
<br />
<b>Description:</b> {descriptions[name]}
<br />
<b>Details & How to Use:</b>
<br />
<br />
<div
dangerouslySetInnerHTML={{
__html: tutorials[name] as unknown as string,
}}
/>
</Section>
);
};