Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit e6f931c

Browse files
committed
Simplify button icon position
1 parent 0c0c83a commit e6f931c

File tree

5 files changed

+51
-51
lines changed

5 files changed

+51
-51
lines changed

components/atoms/Button/Button.js

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@ import styles from './Button.module.css'
88
/**
99
* Render the common inner part of the button component.
1010
*
11-
* @param {object} props The props object.
12-
* @param {string} props.icon Optional icon.
13-
* @param {boolean} props.iconOnly Whether this button is an icon only.
14-
* @param {string} props.iconPosition Position to render the icon.
15-
* @param {string} props.text Button text or aria-label.
16-
* @return {Element} The inside of the Button component.
11+
* @param {object} props The props object.
12+
* @param {string} props.icon Optional icon.
13+
* @param {boolean} props.iconOnly Whether this button is an icon only.
14+
* @param {string} props.text Button text or aria-label.
15+
* @return {Element} The inside of the Button component.
1716
*/
18-
function ButtonInner({icon, iconOnly, iconPosition, text}) {
17+
function ButtonInner({icon, iconOnly, text}) {
1918
return (
2019
<>
21-
{icon && iconPosition === 'left' && (
22-
<Icon icon={icon} title={text} ariaHidden={text ? true : false} />
23-
)}
2420
{!iconOnly && <span className={styles.text}>{text}</span>}
25-
{icon && iconPosition === 'right' && (
21+
{icon && (
2622
<Icon icon={icon} title={text} ariaHidden={text ? true : false} />
2723
)}
2824
</>
@@ -32,27 +28,26 @@ function ButtonInner({icon, iconOnly, iconPosition, text}) {
3228
ButtonInner.propTypes = {
3329
icon: PropTypes.string,
3430
iconOnly: PropTypes.bool,
35-
iconPosition: PropTypes.bool,
3631
text: PropTypes.string
3732
}
3833

3934
/**
40-
* @param {object} props The props object.
41-
* @param {string} props.attributes Optional attributes to add to the button.
42-
* @param {string} props.tag The wrapper tag.
43-
* @param {string} props.className Optional classNames.
44-
* @param {boolean} props.disabled Whether the button is disabled.
45-
* @param {boolean} props.fluid Whether the button should be full width.
46-
* @param {string} props.icon Icon to render inside the button.
47-
* @param {boolean} props.iconOnly Whether this button should render as an icon only button.
48-
* @param {string} props.iconPosition Position to render the icon.
49-
* @param {Function} props.onClick Button onClick function.
50-
* @param {string} props.size Button size.
51-
* @param {string} props.text Button text.
52-
* @param {string} props.type Button type.
53-
* @param {string} props.url Button link url.
54-
* @param {boolean} props.urlExternal Whether the url on this button links to an external site.
55-
* @return {Element} The button component.
35+
* @param {object} props The props object.
36+
* @param {string} props.attributes Optional attributes to add to the button.
37+
* @param {string} props.tag The wrapper tag.
38+
* @param {string} props.className Optional classNames.
39+
* @param {boolean} props.disabled Whether the button is disabled.
40+
* @param {boolean} props.fluid Whether the button should be full width.
41+
* @param {string} props.icon Icon to render inside the button.
42+
* @param {boolean} props.iconOnly Whether this button should render as an icon only button.
43+
* @param {string} props.iconLeft Whether to render the icon on the left.
44+
* @param {Function} props.onClick Button onClick function.
45+
* @param {string} props.size Button size.
46+
* @param {string} props.text Button text.
47+
* @param {string} props.type Button type.
48+
* @param {string} props.url Button link url.
49+
* @param {boolean} props.urlExternal Whether the url on this button links to an external site.
50+
* @return {Element} The button component.
5651
*/
5752
export default function Button({
5853
attributes,
@@ -62,7 +57,7 @@ export default function Button({
6257
fluid,
6358
icon,
6459
iconOnly,
65-
iconPosition,
60+
iconLeft,
6661
onClick,
6762
size,
6863
text,
@@ -74,6 +69,7 @@ export default function Button({
7469
styles.button,
7570
className,
7671
iconOnly && styles.iconOnly,
72+
iconLeft && styles.iconLeft,
7773
fluid && styles.fluid,
7874
disabled && styles.disabled,
7975
styles[size],
@@ -91,7 +87,7 @@ export default function Button({
9187
<ButtonInner
9288
icon={icon}
9389
iconOnly={iconOnly}
94-
iconPosition={iconPosition}
90+
iconLeft={iconLeft}
9591
text={text}
9692
/>
9793
</a>
@@ -101,7 +97,7 @@ export default function Button({
10197
<ButtonInner
10298
icon={icon}
10399
iconOnly={iconOnly}
104-
iconPosition={iconPosition}
100+
iconLeft={iconLeft}
105101
text={text}
106102
/>
107103
</a>
@@ -122,7 +118,7 @@ export default function Button({
122118
<ButtonInner
123119
icon={icon}
124120
iconOnly={iconOnly}
125-
iconPosition={iconPosition}
121+
iconLeft={iconLeft}
126122
text={text}
127123
/>
128124
)
@@ -137,7 +133,7 @@ Button.propTypes = {
137133
fluid: PropTypes.bool,
138134
icon: PropTypes.string,
139135
iconOnly: PropTypes.bool,
140-
iconPosition: PropTypes.oneOf(['left', 'right']),
136+
iconLeft: PropTypes.bool,
141137
onClick: PropTypes.func,
142138
size: PropTypes.oneOf(['sm', 'md', 'lg']),
143139
tag: PropTypes.string,
@@ -150,7 +146,7 @@ Button.propTypes = {
150146
Button.defaultProps = {
151147
disabled: false,
152148
iconOnly: false,
153-
iconPosition: 'left',
149+
iconLeft: false,
154150
size: 'md',
155151
tag: 'button',
156152
type: 'primary',

components/atoms/Button/Button.module.css

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
.button {
22
@apply inline-flex items-center justify-center rounded border transition-colors duration-150 ease-in-out cursor-pointer uppercase font-secondary;
33

4+
& svg {
5+
@apply ml-12;
6+
}
7+
8+
&.iconLeft {
9+
@apply flex-row-reverse;
10+
11+
& svg {
12+
@apply mr-12 ml-0;
13+
}
14+
}
15+
416
&:hover,
517
&:focus,
618
&:active:not([disabled]) {
719
@apply no-underline;
820
}
921

1022
/* SIZES */
11-
&.lg,
12-
&.md,
13-
&.sm {
14-
& svg + span {
15-
@apply ml-12;
16-
}
17-
18-
& span + svg {
19-
@apply ml-12;
20-
}
21-
}
22-
2323
&.lg {
2424
@apply px-16 py-12 text-h5;
2525

@@ -62,4 +62,10 @@
6262
&.disabled {
6363
@apply cursor-not-allowed;
6464
}
65+
66+
&.iconOnly {
67+
& svg {
68+
@apply m-0;
69+
}
70+
}
6571
}

components/atoms/Button/Button.stories.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ Buttons can contain an icon with text or just an icon.
103103
</Story>
104104
</Canvas>
105105

106-
## Icon Position
106+
## Icon Left
107107

108-
Icons are positioned on the left by default. Set `iconPoisition` to `right` to render the icon to the right of the text.
108+
Icons are positioned on the right by default. Set `iconLeft` to `true` to render the icon to the left of the text.
109109

110110
<Canvas>
111111
<Story name="Icon Position">
112112
<Button
113113
icon="arrowLeft"
114-
iconPosition="right"
114+
iconLeft={true}
115115
type="secondary"
116116
text="Button with icon"
117117
className="mx-8"

components/organisms/Hero/Hero.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export default function Hero({backgroundImage, body, cta, subtitle, title}) {
3737
icon={cta.icon ? cta.icon : null}
3838
text={cta.text ? cta.text : null}
3939
type="primary"
40-
iconPosition="right"
4140
size="md"
4241
/>
4342
)}

components/organisms/MediaText/MediaText.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export default function MediaText({
4343
url={cta.url ? cta.url : null}
4444
text={cta.text ? cta.text : null}
4545
icon={cta.icon ? cta.icon : null}
46-
iconPosition="right"
4746
type="primary"
4847
size="md"
4948
/>

0 commit comments

Comments
 (0)