mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: add stories for DropdownArrow (#11764)
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { type Meta, type StoryObj } from "@storybook/react";
|
||||
import { chromatic } from "testHelpers/chromatic";
|
||||
import { DropdownArrow } from "./DropdownArrow";
|
||||
|
||||
const meta: Meta<typeof DropdownArrow> = {
|
||||
title: "components/DropdownArrow",
|
||||
parameters: { chromatic },
|
||||
component: DropdownArrow,
|
||||
args: {},
|
||||
};
|
||||
|
||||
export default meta;
|
||||
type Story = StoryObj<typeof DropdownArrow>;
|
||||
|
||||
export const Open: Story = {};
|
||||
export const Close: Story = { args: { close: true } };
|
||||
export const WithColor: Story = { args: { color: "#f00" } };
|
||||
@@ -1,7 +1,7 @@
|
||||
import KeyboardArrowDown from "@mui/icons-material/KeyboardArrowDown";
|
||||
import KeyboardArrowUp from "@mui/icons-material/KeyboardArrowUp";
|
||||
import { type Interpolation, type Theme } from "@emotion/react";
|
||||
import { type FC } from "react";
|
||||
import { type Theme } from "@emotion/react";
|
||||
|
||||
interface ArrowProps {
|
||||
margin?: boolean;
|
||||
@@ -9,20 +9,30 @@ interface ArrowProps {
|
||||
close?: boolean;
|
||||
}
|
||||
|
||||
export const DropdownArrow: FC<ArrowProps> = (props) => {
|
||||
const { margin = true, color, close } = props;
|
||||
|
||||
export const DropdownArrow: FC<ArrowProps> = ({
|
||||
margin = true,
|
||||
color,
|
||||
close,
|
||||
}) => {
|
||||
const Arrow = close ? KeyboardArrowUp : KeyboardArrowDown;
|
||||
|
||||
return (
|
||||
<Arrow
|
||||
aria-label={close ? "close-dropdown" : "open-dropdown"}
|
||||
css={(theme: Theme) => ({
|
||||
color: color ?? theme.palette.primary.contrastText,
|
||||
marginLeft: margin ? 8 : 0,
|
||||
width: 16,
|
||||
height: 16,
|
||||
})}
|
||||
css={[styles.base, margin && styles.withMargin]}
|
||||
style={{ color }}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = {
|
||||
base: (theme) => ({
|
||||
color: theme.palette.primary.contrastText,
|
||||
width: 16,
|
||||
height: 16,
|
||||
}),
|
||||
|
||||
withMargin: {
|
||||
marginLeft: 8,
|
||||
},
|
||||
} satisfies Record<string, Interpolation<Theme>>;
|
||||
|
||||
Reference in New Issue
Block a user