Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Emotion] Convert EuiButtonIcon #6844

Merged
merged 11 commits into from
Jun 21, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ exports[`EuiButtonIcon props iconType is rendered 1`] = `
exports[`EuiButtonIcon props isDisabled is rendered 1`] = `
<button
aria-label="button"
class="euiButtonIcon euiButtonIcon--xSmall emotion-euiButtonIcon-xs-empty-disabled"
class="euiButtonIcon euiButtonIcon--xSmall emotion-euiButtonIcon-xs-empty-disabled-isDisabled"
disabled=""
type="button"
>
Expand All @@ -217,7 +217,7 @@ exports[`EuiButtonIcon props isDisabled is rendered 1`] = `
exports[`EuiButtonIcon props isDisabled or disabled is rendered 1`] = `
<button
aria-label="button"
class="euiButtonIcon euiButtonIcon--xSmall emotion-euiButtonIcon-xs-empty-disabled"
class="euiButtonIcon euiButtonIcon--xSmall emotion-euiButtonIcon-xs-empty-disabled-isDisabled"
disabled=""
type="button"
>
Expand All @@ -233,7 +233,7 @@ exports[`EuiButtonIcon props isDisabled or disabled is rendered 1`] = `
exports[`EuiButtonIcon props isDisabled renders a button even when href is defined 1`] = `
<button
aria-label="button"
class="euiButtonIcon euiButtonIcon--xSmall emotion-euiButtonIcon-xs-empty-disabled"
class="euiButtonIcon euiButtonIcon--xSmall emotion-euiButtonIcon-xs-empty-disabled-isDisabled"
disabled=""
type="button"
>
Expand All @@ -249,14 +249,15 @@ exports[`EuiButtonIcon props isDisabled renders a button even when href is defin
exports[`EuiButtonIcon props isLoading is rendered 1`] = `
<button
aria-label="button"
class="euiButtonIcon euiButtonIcon--xSmall emotion-euiButtonIcon-xs-empty-disabled"
class="euiButtonIcon euiButtonIcon--xSmall emotion-euiButtonIcon-xs-empty-disabled-isDisabled"
disabled=""
type="button"
>
<span
aria-label="Loading"
class="euiLoadingSpinner emotion-euiLoadingSpinner-m"
role="progressbar"
style="border-color:#07C currentcolor currentcolor currentcolor"
/>
</button>
`;
Expand Down
3 changes: 0 additions & 3 deletions src/components/button/button_icon/_button_icon.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
.euiButtonIcon {
&:disabled {
@include euiButtonContentDisabled;
}
}
3 changes: 3 additions & 0 deletions src/components/button/button_icon/button_icon.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export const euiButtonIconStyles = (euiThemeContext: UseEuiTheme) => {
pointer-events: none;
}
`,
isDisabled: css`
cursor: not-allowed;
`,
// Sizes
xs: css`
${logicalSizeCSS(sizes.xs.height)}
Expand Down
24 changes: 18 additions & 6 deletions src/components/button/button_icon/button_icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const EuiButtonIcon: FunctionComponent<Props> = (props) => {
buttonColorStyles[color],
buttonFocusStyle,
display === 'empty' && emptyHoverStyles,
isDisabled && styles.isDisabled,
];

const classes = classNames(
Expand Down Expand Up @@ -202,13 +203,24 @@ export const EuiButtonIcon: FunctionComponent<Props> = (props) => {
);
}

// `original` size doesn't exist in `EuiLoadingSpinner`
// when the `iconSize` is `original` we don't pass any size to the `EuiLoadingSpinner`
// so it gets the default size
const loadingSize = iconSize === 'original' ? undefined : iconSize;

if (iconType && isLoading) {
buttonIcon = <EuiLoadingSpinner size={loadingSize} />;
// `original` size doesn't exist in `EuiLoadingSpinner`
// when the `iconSize` is `original` we don't pass any size to the `EuiLoadingSpinner`
// so it gets the default size
const loadingSize = iconSize === 'original' ? undefined : iconSize;

// When the button is disabled the text gets gray
// and in some buttons the background gets a light gray
// for better contrast we want to change the border of the spinner
// to have the same color of the text. This way we ensure the borders
// are always visible. The default spinner color could be very light.
const loadingSpinnerColor = isDisabled
? { border: 'currentcolor' }
: undefined;

buttonIcon = (
<EuiLoadingSpinner size={loadingSize} color={loadingSpinnerColor} />
);
Comment on lines +193 to +204
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice accessibility consideration!

}

// <a> elements don't respect the `disabled` attribute. So if we're disabled, we'll just pretend
Expand Down