mirror of
https://github.com/wavetermdev/backup.git
synced 2026-04-22 15:26:58 -07:00
button stories
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
body {
|
||||
height: 100vh;
|
||||
padding: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#storybook-root {
|
||||
|
||||
@@ -3,6 +3,9 @@ import type { Preview } from "@storybook/react";
|
||||
import React from "react";
|
||||
import { DndProvider } from "react-dnd";
|
||||
import { HTML5Backend } from "react-dnd-html5-backend";
|
||||
import "../frontend/app/theme.less";
|
||||
import "../frontend/app/app.less";
|
||||
import "../frontend/app/reset.less";
|
||||
import "./global.css";
|
||||
|
||||
const preview: Preview = {
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
// Copyright 2024, Command Line Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Meta, StoryObj } from "@storybook/react";
|
||||
import { fn } from "@storybook/test";
|
||||
import { Button } from "./button";
|
||||
|
||||
const meta = {
|
||||
title: "Elements/Button",
|
||||
component: Button,
|
||||
args: {
|
||||
children: "Click Me",
|
||||
disabled: false,
|
||||
className: "",
|
||||
onClick: fn(),
|
||||
},
|
||||
argTypes: {
|
||||
onClick: {
|
||||
action: "clicked",
|
||||
description: "Click event handler",
|
||||
},
|
||||
children: {
|
||||
description: "Content inside the button",
|
||||
},
|
||||
disabled: {
|
||||
description: "Disables the button if true",
|
||||
},
|
||||
className: {
|
||||
description: "Additional class names to style the button",
|
||||
},
|
||||
},
|
||||
} satisfies Meta<typeof Button>;
|
||||
|
||||
export default meta;
|
||||
type Story = StoryObj<typeof meta>;
|
||||
|
||||
export const Default: Story = {};
|
||||
|
||||
export const Disabled: Story = {
|
||||
args: {
|
||||
disabled: true,
|
||||
children: "Disabled Button",
|
||||
},
|
||||
};
|
||||
|
||||
export const GreySolid: Story = {
|
||||
args: {
|
||||
className: "solid grey",
|
||||
children: "Grey Solid Button",
|
||||
},
|
||||
};
|
||||
|
||||
export const RedSolid: Story = {
|
||||
args: {
|
||||
className: "solid red",
|
||||
children: "Red Solid Button",
|
||||
},
|
||||
};
|
||||
|
||||
export const YellowSolid: Story = {
|
||||
args: {
|
||||
className: "solid yellow",
|
||||
children: "Yellow Solid Button",
|
||||
},
|
||||
};
|
||||
|
||||
export const GreenOutlined: Story = {
|
||||
args: {
|
||||
className: "outlined green",
|
||||
children: "Green Outline Button",
|
||||
},
|
||||
};
|
||||
|
||||
export const GreyOutlined: Story = {
|
||||
args: {
|
||||
className: "outlined grey",
|
||||
children: "Grey Outline Button",
|
||||
},
|
||||
};
|
||||
|
||||
export const RedOutlined: Story = {
|
||||
args: {
|
||||
className: "outlined red",
|
||||
children: "Red Outline Button",
|
||||
},
|
||||
};
|
||||
|
||||
export const YellowOutlined: Story = {
|
||||
args: {
|
||||
className: "outlined yellow",
|
||||
children: "Yellow Outline Button",
|
||||
},
|
||||
};
|
||||
|
||||
export const GreenGhostText: Story = {
|
||||
args: {
|
||||
className: "ghost green",
|
||||
children: "Yellow Ghost Text Button",
|
||||
},
|
||||
};
|
||||
|
||||
export const GreyGhostText: Story = {
|
||||
args: {
|
||||
className: "ghost grey",
|
||||
children: "Grey Ghost Text Button",
|
||||
},
|
||||
};
|
||||
|
||||
export const RedGhost: Story = {
|
||||
args: {
|
||||
className: "ghost red",
|
||||
children: "Red Ghost Text Button",
|
||||
},
|
||||
};
|
||||
|
||||
export const YellowGhostText: Story = {
|
||||
args: {
|
||||
className: "ghost yellow",
|
||||
children: "Yellow Ghost Text Button",
|
||||
},
|
||||
};
|
||||
@@ -9,41 +9,39 @@ import "./button.less";
|
||||
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
className?: string;
|
||||
children?: ReactNode;
|
||||
target?: string;
|
||||
source?: string;
|
||||
}
|
||||
|
||||
const Button = memo(
|
||||
forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ children, disabled, source, className = "", ...props }: ButtonProps, ref) => {
|
||||
const btnRef = useRef<HTMLButtonElement>(null);
|
||||
useImperativeHandle(ref, () => btnRef.current as HTMLButtonElement);
|
||||
forwardRef<HTMLButtonElement, ButtonProps>(({ children, disabled, className = "", ...props }: ButtonProps, ref) => {
|
||||
const btnRef = useRef<HTMLButtonElement>(null);
|
||||
useImperativeHandle(ref, () => btnRef.current as HTMLButtonElement);
|
||||
|
||||
const childrenArray = Children.toArray(children);
|
||||
const childrenArray = Children.toArray(children);
|
||||
|
||||
// Check if the className contains any of the categories: solid, outlined, or ghost
|
||||
const containsButtonCategory = /(solid|outline|ghost)/.test(className);
|
||||
// If no category is present, default to 'solid'
|
||||
const categoryClassName = containsButtonCategory ? className : `solid ${className}`;
|
||||
// Check if the className contains any of the categories: solid, outlined, or ghost
|
||||
const containsButtonCategory = /(solid|outline|ghost)/.test(className);
|
||||
// If no category is present, default to 'solid'
|
||||
const categoryClassName = containsButtonCategory ? className : `solid ${className}`;
|
||||
|
||||
// Check if the className contains any of the color options: green, grey, red, or yellow
|
||||
const containsColor = /(green|grey|red|yellow)/.test(categoryClassName);
|
||||
// If no color is present, default to 'green'
|
||||
const finalClassName = containsColor ? categoryClassName : `green ${categoryClassName}`;
|
||||
// Check if the className contains any of the color options: green, grey, red, or yellow
|
||||
const containsColor = /(green|grey|red|yellow)/.test(categoryClassName);
|
||||
// If no color is present, default to 'green'
|
||||
const finalClassName = containsColor ? categoryClassName : `green ${categoryClassName}`;
|
||||
|
||||
return (
|
||||
<button
|
||||
ref={btnRef}
|
||||
tabIndex={disabled ? -1 : 0}
|
||||
className={clsx("button", finalClassName)}
|
||||
disabled={disabled}
|
||||
{...props}
|
||||
>
|
||||
{childrenArray}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
)
|
||||
return (
|
||||
<button
|
||||
ref={btnRef}
|
||||
tabIndex={disabled ? -1 : 0}
|
||||
className={clsx("button", finalClassName)}
|
||||
disabled={disabled}
|
||||
{...props}
|
||||
>
|
||||
{childrenArray}
|
||||
</button>
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
Button.displayName = "Button";
|
||||
|
||||
export { Button };
|
||||
|
||||
+8
-8
@@ -30,13 +30,13 @@
|
||||
"@chromatic-com/storybook": "^2.0.2",
|
||||
"@eslint/js": "^9.10.0",
|
||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||
"@storybook/addon-essentials": "^8.3.0",
|
||||
"@storybook/addon-interactions": "^8.3.0",
|
||||
"@storybook/addon-links": "^8.3.0",
|
||||
"@storybook/blocks": "^8.3.0",
|
||||
"@storybook/react": "^8.3.0",
|
||||
"@storybook/react-vite": "^8.3.0",
|
||||
"@storybook/test": "^8.3.0",
|
||||
"@storybook/addon-essentials": "^8.3.2",
|
||||
"@storybook/addon-interactions": "^8.3.2",
|
||||
"@storybook/addon-links": "^8.3.2",
|
||||
"@storybook/blocks": "^8.3.2",
|
||||
"@storybook/react": "^8.3.2",
|
||||
"@storybook/react-vite": "^8.3.2",
|
||||
"@storybook/test": "^8.3.2",
|
||||
"@types/css-tree": "^2",
|
||||
"@types/debug": "^4",
|
||||
"@types/electron": "^1.6.10",
|
||||
@@ -65,7 +65,7 @@
|
||||
"prettier-plugin-organize-imports": "^4.0.0",
|
||||
"rollup-plugin-flow": "^1.1.1",
|
||||
"semver": "^7.6.3",
|
||||
"storybook": "^8.3.0",
|
||||
"storybook": "^8.3.2",
|
||||
"ts-node": "^10.9.2",
|
||||
"tslib": "^2.6.3",
|
||||
"tsx": "^4.19.1",
|
||||
|
||||
Reference in New Issue
Block a user