Skip to content

Commit

Permalink
Moved Button types to a new file (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
advl authored Dec 13, 2024
1 parent 4014730 commit 062a8ba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
32 changes: 2 additions & 30 deletions packages/ds-react-core/src/ui/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@
import type React from "react";

import type Props from "./types.js";
import "./styles.css";

// TODO: this is how appearance could work as enum
//
// export enum ButtonAppearance {
// DEFAULT = "default",
// BASE = "base",
// POSITIVE = "positive",
// NEGATIVE = "negative",
// LINK = "link",
// }

export interface ButtonProps {
/* A unique identifier for the button */
id?: string;
/** Additional CSS classes */
className?: string;
/** The visual style of the button */
appearance?: "neutral" | "base" | "positive" | "negative" | "link";
/** Button contents */
label: string;
/** Optional click handler */
onClick?: () => void;
}

// combine custom props with all native button element attributes
export type ButtonPropsType = ButtonProps &
React.ButtonHTMLAttributes<HTMLButtonElement>;

/** Buttons are clickable elements used to perform an action. */
const Button = ({
id,
className,
appearance,
label,
...props
}: ButtonPropsType): React.ReactElement => {
}: Props): React.ReactElement => {
return (
<button
id={id}
Expand Down
6 changes: 5 additions & 1 deletion packages/ds-react-core/src/ui/Button/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { default as Button, type ButtonProps } from "./Button.js";
export { default as Button } from "./Button.js";
export type {
default as ButtonProps,
BaseProps as ButtonBaseProps,
} from "./types.js";
29 changes: 29 additions & 0 deletions packages/ds-react-core/src/ui/Button/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type React from "react";

// TODO: this is how appearance could work as enum
//
// export enum ButtonAppearance {
// DEFAULT = "default",
// BASE = "base",
// POSITIVE = "positive",
// NEGATIVE = "negative",
// LINK = "link",
// }
//

export interface BaseProps {
/* A unique identifier for the button */
id?: string;
/** Additional CSS classes */
className?: string;
/** The visual style of the button */
appearance?: "neutral" | "base" | "positive" | "negative" | "link";
/** Button contents */
label: string;
/** Optional click handler */
onClick?: () => void;
}

type Props = BaseProps & React.ButtonHTMLAttributes<HTMLButtonElement>;

export default Props;

0 comments on commit 062a8ba

Please sign in to comment.