Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Button types #1903

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/odyssey-react-mui/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { MuiPropsContext } from "./MuiPropsContext";
import { Tooltip } from "./Tooltip";

export const buttonSizeValues = ["small", "medium", "large"] as const;
export const buttonTypeValues = ["button", "submit", "reset"] as const;
export const buttonVariantValues = [
"primary",
"secondary",
Expand Down Expand Up @@ -75,6 +76,10 @@ export type ButtonProps = {
* The tooltip text for the Button if it's icon-only
*/
tooltipText?: string;
/**
* The type of the HTML button element
*/
type?: (typeof buttonTypeValues)[number];
/**
* The variant of the Button
*/
Expand All @@ -94,6 +99,7 @@ const Button = ({
startIcon,
text = "",
tooltipText,
type = "button",
variant,
}: ButtonProps) => {
const muiProps = useContext(MuiPropsContext);
Expand All @@ -112,12 +118,16 @@ const Button = ({
onClick={onClick}
size={size}
startIcon={startIcon}
type={type}
variant={variant}
>
{text}
</MuiButton>
),
[
ariaLabel,
ariaLabelledBy,
ariaDescribedBy,
endIcon,
id,
isDisabled,
Expand All @@ -126,10 +136,8 @@ const Button = ({
size,
startIcon,
text,
type,
variant,
ariaLabel,
ariaLabelledBy,
ariaDescribedBy,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { Meta, StoryObj } from "@storybook/react";
import {
Button,
buttonSizeValues,
buttonTypeValues,
buttonVariantValues,
AddIcon,
} from "@okta/odyssey-react-mui";
Expand All @@ -31,6 +32,30 @@ const storybookMeta: Meta<ButtonProps> = {
title: "MUI Components/Button",
component: Button,
argTypes: {
endIcon: {
control: {
type: "select",
},
options: Object.keys(icons),
mapping: icons,
description: "An optional icon to display at the end of the button",
table: {
type: {
summary: "<Icon />",
},
defaultValue: "",
},
},
id: {
control: null,
description: "An optional ID for the button",
table: {
type: {
summary: "string",
},
defaultValue: "",
},
},
isDisabled: {
control: "boolean",
description: "If `true`, the button is disabled",
Expand All @@ -51,6 +76,16 @@ const storybookMeta: Meta<ButtonProps> = {
},
},
},
onClick: {
action: true,
description: "Callback fired when the button is clicked",
table: {
type: {
summary: "(() => void)",
},
defaultValue: "",
},
},
size: {
options: buttonSizeValues,
control: { type: "radio" },
Expand Down Expand Up @@ -78,30 +113,6 @@ const storybookMeta: Meta<ButtonProps> = {
defaultValue: "",
},
},
endIcon: {
control: {
type: "select",
},
options: Object.keys(icons),
mapping: icons,
description: "An optional icon to display at the end of the button",
table: {
type: {
summary: "<Icon />",
},
defaultValue: "",
},
},
id: {
control: null,
description: "An optional ID for the button",
table: {
type: {
summary: "string",
},
defaultValue: "",
},
},
text: {
control: "text",
description:
Expand All @@ -124,6 +135,20 @@ const storybookMeta: Meta<ButtonProps> = {
defaultValue: "",
},
},
type: {
options: buttonTypeValues,
control: { type: "radio" },
description: "The type of the HTML button element.",
defaultValue: "button",
table: {
type: {
summary: buttonTypeValues.join(" | "),
},
defaultValue: {
summary: "button",
},
},
},
variant: {
options: buttonVariantValues,
control: { type: "radio" },
Expand All @@ -138,16 +163,6 @@ const storybookMeta: Meta<ButtonProps> = {
},
},
},
onClick: {
action: true,
description: "Callback fired when the button is clicked",
table: {
type: {
summary: "(() => void)",
},
defaultValue: "",
},
},
},
args: {
text: "Add crew",
Expand Down