diff --git a/.changeset/cold-mice-doubt.md b/.changeset/cold-mice-doubt.md
new file mode 100644
index 000000000..60f030bbc
--- /dev/null
+++ b/.changeset/cold-mice-doubt.md
@@ -0,0 +1,5 @@
+---
+"@equinor/mad-components": minor
+---
+
+Added `fullWidth` prop to the `Button` component
diff --git a/apps/chronicles/screens/components/components/ButtonScreen.tsx b/apps/chronicles/screens/components/components/ButtonScreen.tsx
index 64a4d1d2a..2040a057b 100644
--- a/apps/chronicles/screens/components/components/ButtonScreen.tsx
+++ b/apps/chronicles/screens/components/components/ButtonScreen.tsx
@@ -53,6 +53,19 @@ export const ButtonScreen = () => {
+
+ fullWidth
+
+ With use of the fullWidth prop icon floats to the edges of the button while the text
+ stay centered:
+
+
+
+
+
+
+
+
diff --git a/packages/components/src/components/Button/Button.tsx b/packages/components/src/components/Button/Button.tsx
index 1b035f471..e11b6a949 100644
--- a/packages/components/src/components/Button/Button.tsx
+++ b/packages/components/src/components/Button/Button.tsx
@@ -31,6 +31,10 @@ export type ButtonSpecificProps = {
* Boolean value indicating whether or not the button should be in its loading state.
*/
loading?: boolean;
+ /**
+ * Boolean value that floats icon to the edges of the button while the text stay centered.
+ */
+ fullWidth?: boolean;
/**
* Name of the icon to use with the title.
*/
@@ -63,6 +67,7 @@ export const Button = forwardRef(
variant = "contained",
disabled = false,
loading = false,
+ fullWidth = false,
iconName,
iconPosition = "leading",
onPress = () => null,
@@ -83,18 +88,23 @@ export const Button = forwardRef(
toggleStatus: isToggleButton ? toggleData.isSelected : false,
groupData,
disabled,
+ fullWidth,
});
const ButtonContent = () => (
<>
{iconName && iconPosition === "leading" && (
-
+
+
+
)}
{title}
{iconName && iconPosition === "trailing" && (
-
+
+
+
)}
>
);
@@ -133,10 +143,11 @@ type ButtonStyleSheetProps = {
color: "primary" | "secondary" | "danger";
variant: "contained" | "outlined" | "ghost";
disabled: boolean;
+ fullWidth: boolean;
};
const themeStyles = EDSStyleSheet.create((theme, props: ButtonStyleSheetProps) => {
- const { color, isToggleButton, toggleStatus, groupData, disabled } = props;
+ const { color, isToggleButton, toggleStatus, groupData, disabled, fullWidth } = props;
let { variant } = props;
variant = isToggleButton ? (toggleStatus ? "contained" : "outlined") : variant;
@@ -175,8 +186,17 @@ const themeStyles = EDSStyleSheet.create((theme, props: ButtonStyleSheetProps) =
justifyContent: "center",
gap: theme.spacing.button.iconGap,
},
+ trailingIcon: {
+ flex: fullWidth ? 1 : undefined,
+ alignItems: fullWidth ? "flex-end" : undefined,
+ },
+ leadingIcon: {
+ flex: fullWidth ? 1 : undefined,
+ alignItems: fullWidth ? "flex-start" : undefined,
+ },
textStyle: {
color: textColor,
+ position: fullWidth ? "absolute" : undefined,
},
};
});