chore: add stories for DropdownArrow (#11764)

This commit is contained in:
Kayla Washburn-Love
2024-01-23 16:02:57 -07:00
committed by GitHub
parent 383eed93f8
commit 31a6a5dc6d
2 changed files with 37 additions and 10 deletions
@@ -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>>;