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

Add disabled state to EuiBadge #2440

Merged
merged 7 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added ability for `EuiColorStops` to accept user-defined range bounds ([#2396](https://github.com/elastic/eui/pull/2396))
- Added disabled state to `EuiBadge` ([#2440](https://github.com/elastic/eui/pull/2440))

## [`14.6.0`](https://github.com/elastic/eui/tree/v14.6.0)

Expand Down
9 changes: 7 additions & 2 deletions src-docs/src/views/badge/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ const badges = [
'accent',
'warning',
'danger',
'#fea27f',
'#000',
'#fea27f',
'disabled',
];

export default () => (
<EuiFlexGroup wrap responsive={false} gutterSize="xs" style={{ width: 300 }}>
{badges.map(badge => (
<EuiFlexItem grow={false} key={badge}>
<EuiBadge color={badge}>{badge}</EuiBadge>
<EuiBadge
isDisabled={badge === 'disabled' ? true : false}
color={badge}>
{badge}
</EuiBadge>
</EuiFlexItem>
))}
</EuiFlexGroup>
Expand Down
18 changes: 18 additions & 0 deletions src/components/badge/__snapshots__/badge.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiBadge is disabled 1`] = `
<span
aria-label="aria-label"
class="euiBadge euiBadge-isDisabled euiBadge--iconLeft euiBadge--default testClass1 testClass2"
data-test-subj="test subject string"
>
<span
class="euiBadge__content"
>
<span
class="euiBadge__text"
>
Content
</span>
</span>
</span>
`;

exports[`EuiBadge is rendered 1`] = `
<span
aria-label="aria-label"
Expand Down
37 changes: 31 additions & 6 deletions src/components/badge/_badge.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '../button/variables';

/**
* 1. Accounts for the border
*/
Expand All @@ -19,6 +21,13 @@
// So, make the text left aligned to ensure all badges line up the same
text-align: left;

&.euiBadge-isDisabled {
// sass-lint:disable-block no-important
cchaos marked this conversation as resolved.
Show resolved Hide resolved
// Using !important to override inline styles
background-color: $euiButtonColorDisabled !important;
color: $euiColorEmptyShade !important;
}

&:focus-within {
@include euiFocusRing('small');
}
Expand All @@ -40,9 +49,15 @@
font-weight: inherit;
line-height: inherit;

&:hover,
&:focus {
text-decoration: underline;
&:disabled {
cursor: not-allowed;
}

&:not(:disabled) {
&:hover,
&:focus {
text-decoration: underline;
}
}
}

Expand All @@ -57,6 +72,10 @@
border-radius: 2px;
}

&:disabled {
cursor: not-allowed;
}

.euiBadge__icon {
// Remove margins from icon itself so that focus state doesn't include that space
margin: 0 !important; // sass-lint:disable-line no-important
Expand Down Expand Up @@ -86,9 +105,15 @@
}

.euiBadge-isClickable {
&:hover,
&:focus {
text-decoration: underline;
&:not(:disabled) {
&:hover,
&:focus {
text-decoration: underline;
}
}

&.euiBadge-isDisabled {
cursor: not-allowed;
}

&:focus {
Expand Down
10 changes: 10 additions & 0 deletions src/components/badge/badge.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ describe('EuiBadge', () => {
expect(component).toMatchSnapshot();
});

test('is disabled', () => {
const component = render(
<EuiBadge isDisabled {...requiredProps}>
Content
</EuiBadge>
);

expect(component).toMatchSnapshot();
});

test('is rendered with onClick provided', () => {
const component = render(
<EuiBadge
Expand Down
7 changes: 7 additions & 0 deletions src/components/badge/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export type EuiBadgeProps = {
*/
color?: IconColor;

isDisabled?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're also overriding the colors passed in here, it might be nice to add a docs comment that expresses that behavior.


/**
* Props passed to the close button.
*/
Expand Down Expand Up @@ -89,6 +91,7 @@ export const EuiBadge: FunctionComponent<EuiBadgeProps> = ({
iconType,
iconSide = 'left',
className,
isDisabled,
onClick,
iconOnClick,
onClickAriaLabel,
Expand Down Expand Up @@ -118,6 +121,7 @@ export const EuiBadge: FunctionComponent<EuiBadgeProps> = ({
'euiBadge',
{
'euiBadge-isClickable': onClick && !iconOnClick,
'euiBadge-isDisabled': isDisabled,
cchaos marked this conversation as resolved.
Show resolved Hide resolved
},
iconSideToClassNameMap[iconSide],
optionalColorClass,
Expand All @@ -141,6 +145,7 @@ export const EuiBadge: FunctionComponent<EuiBadgeProps> = ({
<button
className="euiBadge__iconButton"
aria-label={iconOnClickAriaLabel}
disabled={isDisabled}
title={iconOnClickAriaLabel}
onClick={iconOnClick}>
<EuiIcon
Expand Down Expand Up @@ -172,6 +177,7 @@ export const EuiBadge: FunctionComponent<EuiBadgeProps> = ({
{(ref, innerText) => (
<button
className="euiBadge__childButton"
disabled={isDisabled}
aria-label={onClickAriaLabel}
onClick={onClick}
ref={ref}
Expand All @@ -190,6 +196,7 @@ export const EuiBadge: FunctionComponent<EuiBadgeProps> = ({
<EuiInnerText>
{(ref, innerText) => (
<button
disabled={isDisabled}
aria-label={onClickAriaLabel}
className={classes}
onClick={onClick}
Expand Down