Skip to content

Commit

Permalink
Fix Button icon alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
vineethasok committed Sep 29, 2023
1 parent 5ed3501 commit 0546236
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/components/SplitButton/SplitButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const menuItems: Array<Menu> = [
},
{
icon: "code",
iconDir: "left",
iconDir: "start",
label: "Content1",
},
{
Expand All @@ -34,7 +34,7 @@ const menuItems: Array<Menu> = [
},
{
icon: "code",
iconDir: "right",
iconDir: "end",
label: "Content2",
},
{
Expand Down
47 changes: 15 additions & 32 deletions src/components/SplitButton/SplitButton.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { HTMLAttributes, ReactNode, useEffect, useRef, useState } from "react";
import styled from "styled-components";
import { DropdownMenuProps } from "@radix-ui/react-dropdown-menu";
import { Icon, IconName, Dropdown } from "@/components";
import { Icon, IconName, Dropdown, HorizontalDirection } from "@/components";
import { BaseButton } from "../commonElement";
import IconWrapper from "../IconWrapper/IconWrapper";

type ButtonType = "primary" | "secondary";
type IconDirection = "left" | "right";
type Alignment = "center" | "left";
type MenuItem = {
icon?: IconName;
iconDir?: IconDirection;
iconDir?: HorizontalDirection;
label: ReactNode;
type?: "item";
items?: never;
Expand Down Expand Up @@ -39,7 +39,7 @@ export interface SplitButtonProps
menu: Array<Menu>;
side?: "top" | "bottom";
icon?: IconName;
iconDir?: IconDirection;
iconDir?: HorizontalDirection;
}

export const SplitButton = ({
Expand All @@ -56,7 +56,7 @@ export const SplitButton = ({
align,
children,
icon,
iconDir = "left",
iconDir = "start",
...props
}: SplitButtonProps) => {
const ref = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -103,8 +103,9 @@ export const SplitButton = ({
<IconWrapper
icon={icon}
iconDir={iconDir}
label={children}
/>
>
{children}
</IconWrapper>
</PrimaryButton>
<SecondaryButton
as={Dropdown.Trigger}
Expand Down Expand Up @@ -142,32 +143,12 @@ const DropdownContent = styled.div<{ $width: number }>`
min-width: ${({ $width }) => $width}px;
`;

const IconWrapper = ({ label, icon, iconDir }: Omit<MenuItem, "type" | "items">) => {
return (
<>
{icon && iconDir === "left" && (
<Icon
name={icon}
size="sm"
/>
)}
{label}
{icon && iconDir === "right" && (
<Icon
name={icon}
size="sm"
/>
)}
</>
);
};

const MenuContentItem = ({
items = [],
type = "item",
label,
icon,
iconDir = "left",
iconDir = "start",
parentKey,
...props
}: Menu & { parentKey: string }) => {
Expand All @@ -177,8 +158,9 @@ const MenuContentItem = ({
<IconWrapper
icon={icon}
iconDir={iconDir}
label={label}
/>
>
{label}
</IconWrapper>
</Dropdown.Item>
);
}
Expand All @@ -205,8 +187,9 @@ const MenuContentItem = ({
<IconWrapper
icon={icon}
iconDir={iconDir}
label={label}
/>
>
{label}
</IconWrapper>
</Dropdown.Trigger>
<Dropdown.Content sub>
{items.map((item, index) => (
Expand Down

0 comments on commit 0546236

Please sign in to comment.