Skip to content
Snippets Groups Projects
Select Git revision
  • f951e4aa9e2d05cd16ef80f7063ee7c2deb97bcf
  • main default protected
  • fix-textinput-label-styling
  • feature/add_tabs
  • v2.9.0
  • v2.8.0
  • v2.7.0
  • v2.6.0
  • v2.5.0
  • v2.4.0
  • v2.3.0
  • v2.2.0
  • v2.1.1
  • v2.1.0
  • v2.0.0
  • v1.10.0
  • v1.9.1
  • v1.9.0
  • v1.8.4
  • v1.8.3
  • v1.8.2
  • v1.8.1
  • v1.8.0
  • v1.7.0
24 results

Button.stories.tsx

Blame
  • Alissa Cheng's avatar
    Alissa Cheng authored and Klaas Kliffen committed
    BREAKING CHANGE: changed icon names to PascalCase
    848ae258
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Button.stories.tsx 2.30 KiB
    import { Meta, StoryObj } from "@storybook/react";
    import { useState } from "react";
    import Button from "src/components/Button.tsx";
    import { iconNameOptions } from "src/components/Icon.tsx";
    import { colorOptions } from "src/components/utils/colors.ts";
    import Typography from "src/components/Typography.tsx";
    import TextInput from "src/components/TextInput.tsx";
    
    /** Use buttons as triggers for actions that are used in forms, toolbars, dialog footers and as stand-alone action triggers. Try to avoid the usage of buttons for navigation. The main difference between actions and navigation is that Actions are operations performed on objects, while Navigation refers to elements on the screen or view that take you to another context in the application. */
    const meta = {
      title: "Components/Button",
      component: Button,
      argTypes: {
        color: { control: "radio", options: colorOptions },
        onClick: () => {},
      },
    } satisfies Meta;
    
    export default meta;
    
    export const TextOnlyButton: StoryObj = {
      args: {
        label: "Click me!",
        color: "primary",
      },
    };
    
    export const IconButton: StoryObj = {
      args: {
        label: "Download",
        color: "primary",
        icon: "Download",
      },
      argTypes: {
        icon: { control: "select", options: iconNameOptions },
      },
    };
    
    export const DisabledButton: StoryObj = {
      args: {
        label: "You can't click me!",
        isDisabled: true,
      },
    };
    
    /** In order for the Button to listen for Enter keypress, mostly used for submitting forms. Provide `type="submit"` to the Button component, and wrap it in a `<form>` element. For the native form element, you might also want to use an `onSubmit` with `preventDefault` and `stopPropagation` so the page does not reload. But there are also form libraries that take care of that. */
    export const SubmitButton = () => {
      const [value, setValue] = useState("");
      const [count, setCount] = useState(0);
      return (
        <form
          onSubmit={(e) => {
            e.preventDefault();
            e.stopPropagation();
          }}
          className="max-w-md flex flex-col gap-2"
        >
          <TextInput value={value} onValueChange={setValue} />
          <Button
            label="Submit"
            type="submit"
            onClick={() => setCount(count + 1)}
          />
          <Typography
            text={`You have submitted ${count} times!`}
            variant="paragraph"
          />
        </form>
      );
    };