Skip to content

Commit 4bc9348

Browse files
authored
Merge pull request #20 from DeterminateSystems/enum-arrays
Convert enums to arrays
2 parents 8feaa6a + c926f3b commit 4bc9348

File tree

6 files changed

+47
-14
lines changed

6 files changed

+47
-14
lines changed

src/Button/Button.stories.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
import { action } from "@storybook/addon-actions";
22
import type { Meta, StoryObj } from "@storybook/react";
33

4-
import Button from "./";
4+
import Button, { buttonColors, buttonSizes } from "./";
55

66
const meta = {
77
title: "Atoms/Button",
88
component: Button,
9+
argTypes: {
10+
id: {
11+
description: "An optional HTML identifier for the button",
12+
control: "text",
13+
},
14+
color: {
15+
description: "The button's color scheme",
16+
control: "select",
17+
options: [...buttonColors],
18+
},
19+
size: {
20+
description: "The button's size",
21+
control: "select",
22+
options: [...buttonSizes],
23+
},
24+
outlined: {
25+
description: "Whether the button is outlined",
26+
control: "boolean",
27+
},
28+
},
929
} satisfies Meta<typeof Button>;
1030

1131
export default meta;

src/Button/index.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import type { FC, PropsWithChildren } from "react";
33
import "./index.scss";
44
import clsx from "clsx";
55

6-
export type ButtonSize = "sm" | "base" | "lg";
7-
export type ButtonColors =
8-
| "primary"
9-
| "secondary"
10-
| "success"
11-
| "info"
12-
| "warning"
13-
| "danger";
6+
export const buttonSizes = ["sm", "base", "lg"] as const;
7+
export type ButtonSize = (typeof buttonSizes)[number];
8+
9+
export const buttonColors = [
10+
"primary",
11+
"secondary",
12+
"success",
13+
"info",
14+
"warning",
15+
"danger",
16+
] as const;
17+
export type ButtonColor = (typeof buttonColors)[number];
1418

1519
export interface ButtonProps {
1620
/**
@@ -26,7 +30,7 @@ export interface ButtonProps {
2630
/**
2731
* The button's color scheme.
2832
*/
29-
color?: ButtonColors;
33+
color?: ButtonColor;
3034

3135
/**
3236
* Whether the button is outlined.

src/CodeBlock/CodeBlock.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Meta, StoryObj } from "@storybook/react";
22

33
import CodeBlock from "./";
4+
import { highlightLanguages } from "../hooks/useHighlight";
45

56
const meta = {
67
title: "Molecules/CodeBlock",
@@ -11,7 +12,7 @@ const meta = {
1112
argTypes: {
1213
language: {
1314
control: "select",
14-
options: ["shell", "yaml", "terraform", "text"],
15+
options: [...highlightLanguages],
1516
},
1617
code: { control: "text" },
1718
allowCopy: { control: "boolean" },

src/CodeFile/CodeFile.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Meta, StoryObj } from "@storybook/react";
22

33
import CodeFile from "./";
4+
import { highlightLanguages } from "../hooks/useHighlight";
45

56
const meta = {
67
title: "Molecules/CodeFile",
@@ -11,7 +12,7 @@ const meta = {
1112
argTypes: {
1213
language: {
1314
control: "select",
14-
options: ["shell", "yaml", "terraform", "text"],
15+
options: [...highlightLanguages],
1516
},
1617
code: { control: "text" },
1718
filename: { control: "text" },

src/Highlight/Highlight.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Meta, StoryObj } from "@storybook/react";
22

33
import Highlight from "./";
4+
import { highlightLanguages } from "../hooks/useHighlight";
45

56
const meta = {
67
title: "Atoms/Highlight",
@@ -11,7 +12,7 @@ const meta = {
1112
argTypes: {
1213
language: {
1314
control: "select",
14-
options: ["shell", "yaml", "terraform", "text"],
15+
options: [...highlightLanguages],
1516
},
1617
code: { control: "text" },
1718
inline: { control: "boolean" },

src/hooks/useHighlight.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import { useMemo } from "react";
1010
/**
1111
* Languages understood by the UI system's highlighter. The `text` option prevents highlighting.
1212
*/
13-
export type HighlightLanguage = "shell" | "yaml" | "terraform" | "text";
13+
export const highlightLanguages = [
14+
"shell",
15+
"yaml",
16+
"terraform",
17+
"text",
18+
] as const;
19+
export type HighlightLanguage = (typeof highlightLanguages)[number];
1420

1521
// Lazily instantiate the Shiki renderer to avoid paying (some) startp costs
1622
let shiki: ReturnType<typeof createHighlighterCoreSync>;

0 commit comments

Comments
 (0)