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

[EuiCard] Allow selectable with layout="horizontal" #4692

Merged
merged 3 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `32.0.3`.
**Bug fixes**

- Removed the restriction on `selectable` `EuiCard` with `layout="horizontal"` ([#4692](https://github.com/elastic/eui/pull/4692))

## [`32.0.3`](https://github.com/elastic/eui/tree/v32.0.3)

Expand Down
42 changes: 42 additions & 0 deletions src/components/card/__snapshots__/card.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiCard horizontal selectable 1`] = `
<div
class="euiPanel euiPanel--paddingMedium euiPanel--borderRadiusMedium euiPanel--plain euiPanel--hasShadow euiPanel--isClickable euiCard euiCard--centerAligned euiCard--horizontal euiCard--isClickable euiCard--isSelectable euiCard--isSelectable--text"
>
<div
class="euiCard__content"
>
<span
class="euiTitle euiTitle--small euiCard__title"
id="generated-idTitle"
>
Card title
</span>
<div
class="euiText euiText--small euiCard__description"
id="generated-idDescription"
>
<p>
Card description
</p>
</div>
</div>
<button
aria-checked="false"
aria-describedby="generated-idTitle generated-idDescription"
class="euiButtonEmpty euiButtonEmpty--text euiButtonEmpty--xSmall euiCardSelect euiCardSelect--text"
role="switch"
type="button"
>
<span
class="euiButtonContent euiButtonEmpty__content"
>
<span
class="euiButtonEmpty__text"
>
Select
</span>
</span>
</button>
</div>
`;

exports[`EuiCard is rendered 1`] = `
<div
aria-label="aria-label"
Expand Down
15 changes: 15 additions & 0 deletions src/components/card/card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,19 @@ describe('EuiCard', () => {
expect(component).toMatchSnapshot();
});
});

test('horizontal selectable', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

const component = render(
<EuiCard
title="Card title"
description="Card description"
layout="horizontal"
selectable={{
onClick: () => {},
}}
/>
);

expect(component).toMatchSnapshot();
});
});
14 changes: 7 additions & 7 deletions src/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,11 @@ type EuiCardPropsLayout = ExclusiveUnion<
* Accepts a url in string form or ReactElement for a custom image component
*/
image?: string | ReactElement;
/**
* Adds a button to the bottom of the card to allow for in-place selection
*/
selectable?: EuiCardSelectProps;
},
{
/**
* Change to "horizontal" if you need the icon to be left of the content.
* Horizontal layouts cannot be used in conjunction with `image`, `footer`, `textAlign`, or `selectable`.
* Horizontal layouts cannot be used in conjunction with `image`, `footer`, or `textAlign`.
*/
layout: 'horizontal';
}
Expand Down Expand Up @@ -161,6 +157,10 @@ export type EuiCardProps = Omit<CommonProps, 'aria-label'> &
* Padding applied around the content of the card
*/
paddingSize?: EuiPanelProps['paddingSize'];
/**
* Adds a button to the bottom of the card to allow for in-place selection
*/
selectable?: EuiCardSelectProps;
} & (
| {
// description becomes optional when children is present
Expand Down Expand Up @@ -216,9 +216,9 @@ export const EuiCard: FunctionComponent<EuiCardProps> = ({
};

if (layout === 'horizontal') {
if (image || footer || textAlign !== 'center' || selectable) {
if (image || footer || textAlign !== 'center') {
throw new Error(
"EuiCard: layout = horizontal' cannot be used in conjunction with 'image', 'footer', 'textAlign', or 'selectable'."
'EuiCard: `layout="horizontal"` cannot be used in conjunction with `image`, `footer`, or `textAlign`.'
);
}
}
Expand Down