Skip to content

Commit 0878d8a

Browse files
authored
Merge pull request #510 from buildo/button-icon-position
2 parents 193f60c + 36c18db commit 0878d8a

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

packages/bento-design-system/src/Button/Button.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ type Props = {
1818
isDisabled?: boolean;
1919
size?: ButtonSize;
2020
icon?: (props: IconProps) => JSX.Element;
21+
iconPosition?: "leading" | "trailing";
2122
} & Omit<AriaButtonProps<"button">, "onPress">;
2223

2324
/**
2425
* A button
2526
*/
2627
export function Button(props: Props) {
2728
const config = useBentoConfig().button;
29+
const iconPosition = props.iconPosition ?? config.defaultIconPosition;
2830
const ref = useRef<HTMLButtonElement>(null);
2931
const { buttonProps } = useButton(props, ref);
3032
const {
@@ -61,7 +63,7 @@ export function Button(props: Props) {
6163
onPointerDown={internal_unsafe__bypassUsePress ? undefined : buttonProps.onPointerDown}
6264
onClick={internal_unsafe__bypassUsePress ? props.onPress : buttonProps.onClick}
6365
>
64-
<Columns space={config.internalSpacing} alignY="center">
66+
<Columns space={config.internalSpacing} alignY="center" reverse={iconPosition === "trailing"}>
6567
{props.icon && (
6668
<Column width="content">
6769
{props.icon({

packages/bento-design-system/src/Button/Config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IconProps } from "../Icons";
22
import { BentoSprinkles } from "../internal";
33
import { LabelProps } from "../Typography/Label/Label";
4-
import { ButtonSize } from "./Button";
4+
import { ButtonProps, ButtonSize } from "./Button";
55

66
type SizeConfig<T> = {
77
[k in ButtonSize]: T;
@@ -22,4 +22,5 @@ export type ButtonConfig = {
2222
* @default "medium"
2323
*/
2424
defaultSize: ButtonSize;
25+
defaultIconPosition: ButtonProps["iconPosition"];
2526
};

packages/bento-design-system/src/util/defaultConfigs.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export const button: ButtonConfig = {
138138
},
139139
uppercaseLabel: true,
140140
defaultSize: "medium",
141+
defaultIconPosition: "leading",
141142
};
142143

143144
export const card: CardConfig = {

packages/storybook/stories/Components/Button.stories.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,10 @@ export const WithIcon = createStory({
9393
hierarchy: "primary",
9494
icon: IconCheck,
9595
});
96+
97+
export const WithIconTrailing = createStory({
98+
kind: "solid",
99+
hierarchy: "primary",
100+
icon: IconCheck,
101+
iconPosition: "trailing",
102+
});

0 commit comments

Comments
 (0)