Skip to content

Commit

Permalink
feat: 🎸 [Button] Added rotate icon property
Browse files Browse the repository at this point in the history
  • Loading branch information
luciob committed Jun 24, 2021
1 parent 8f3e612 commit a74a2d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/components/Button/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@ export const CustomIcon = () => (
/>
</StoriesWrapper>
);

export const RotateIcon = () => (
<StoriesWrapper>
<Button icon={{ name: Icons.refresh, rotate: true }} label="Refresh" onClick={action("Click on Button")} />
<Button disabled icon={{ name: Icons.refresh, rotate: true }} label="Refresh" onClick={action("Click on Button")} />
</StoriesWrapper>
);
6 changes: 4 additions & 2 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ const getIcons = (dataCy: string, iconConfig?: IButtonIcon): IMUIButtonIcon => {
return muiIcon;
}

const { component, name, position } = iconConfig;
const icon = <IconWrapper dataCy={getComposedDataCy(dataCy, SUBPARTS_MAP.icon)} icon={name || component} />;
const { component, name, position, rotate } = iconConfig;
const icon = (
<IconWrapper dataCy={getComposedDataCy(dataCy, SUBPARTS_MAP.icon)} icon={name || component} rotate={rotate} />
);

switch (position) {
case ButtonIconPosition.left:
Expand Down
7 changes: 3 additions & 4 deletions src/types/Button.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactElement } from "react";

import { IClickable, ILocalizable } from "./Base";
import { Icons } from "./Icon";
import { Icons, IIcon } from "./Icon";

export enum ButtonIconPosition {
left = "left",
Expand All @@ -17,12 +17,11 @@ export interface IBaseButton extends IClickable {
label: string;
}

// TODO: add rotate reusing IIcon props
export interface IButtonIcon {
export type IButtonIcon = Pick<IIcon, "rotate"> & {
component?: ReactElement;
name?: Icons;
position?: ButtonIconPosition;
}
};

export interface IButton extends IBaseButton, ILocalizable {
disabled?: boolean;
Expand Down

0 comments on commit a74a2d0

Please sign in to comment.