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

Polish Card component. #35245

Closed
wants to merge 4 commits into from
Closed
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
18 changes: 16 additions & 2 deletions packages/components/src/card/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@ import { css } from '@emotion/react';
import { COLORS, CONFIG } from '../utils';

export const Card = css`
box-shadow: 0 0 0 1px ${ CONFIG.surfaceBorderColor };
outline: none;

&::before {
content: '';

box-shadow: inset 0 0 0 1px ${ CONFIG.surfaceBorderColor };
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;

pointer-events: none;
}
`;

export const Header = css`
Expand Down Expand Up @@ -77,7 +89,9 @@ export const borderColor = css`
`;

export const boxShadowless = css`
box-shadow: none;
&::before {
content: none;
}
`;

export const borderless = css`
Expand Down
57 changes: 52 additions & 5 deletions packages/components/src/card/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ Snapshot Diff:
@@ -1,30 +1,30 @@
<div>
<div
- class="components-surface components-card css-ssx2ib-View-Surface-getBorders-primary-Card-boxShadowless-rounded em57xhy0"
+ class="components-surface components-card css-1vyvcpq-View-Surface-getBorders-primary-Card-rounded em57xhy0"
- class="components-surface components-card css-xq5dej-View-Surface-getBorders-primary-Card-boxShadowless-rounded em57xhy0"
+ class="components-surface components-card css-hsug4u-View-Surface-getBorders-primary-Card-rounded em57xhy0"
data-wp-c16t="true"
data-wp-component="Card"
>
Expand Down Expand Up @@ -191,18 +191,45 @@ Snapshot Diff:
</div>
`;

exports[`Card Card component should remove borders when the isBorderless prop is true 1`] = `
Snapshot Diff:
- First value
+ Second value

@@ -1,8 +1,8 @@
<div>
<div
- class="components-surface components-card css-hsug4u-View-Surface-getBorders-primary-Card-rounded em57xhy0"
+ class="components-surface components-card css-xq5dej-View-Surface-getBorders-primary-Card-boxShadowless-rounded em57xhy0"
data-wp-c16t="true"
data-wp-component="Card"
>
<div
class="css-mgwsf4-View-Content em57xhy0"
`;

exports[`Card Card component should render correctly 1`] = `
Object {
"asFragment": [Function],
"baseElement": .emotion-0 {
background-color: #fff;
color: #000;
position: relative;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
outline: none;
border-radius: 2px;
}

.emotion-0::before {
content: '';
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
pointer-events: none;
}

.emotion-2 {
height: 100%;
}
Expand Down Expand Up @@ -454,11 +481,21 @@ Object {
background-color: #fff;
color: #000;
position: relative;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
outline: none;
border-radius: 2px;
}

.emotion-0::before {
content: '';
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
pointer-events: none;
}

.emotion-2 {
height: 100%;
}
Expand Down Expand Up @@ -789,11 +826,21 @@ exports[`Card Card component should warn when the isElevated prop is passed 1`]
background-color: #fff;
color: #000;
position: relative;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
outline: none;
border-radius: 2px;
}

.emotion-0::before {
content: '';
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
pointer-events: none;
}

.emotion-2 {
height: 100%;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/components/src/card/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ describe( 'Card', () => {
} );

it( 'should remove borders when the isBorderless prop is true', () => {
const { rerender, container } = render(
const { container: withBorders } = render(
<Card>Code is Poetry</Card>
);
expect( container.firstChild ).not.toHaveStyle(
'box-shadow: none'

const { container: withoutBorders } = render(
<Card isBorderless>Code is Poetry</Card>
);

rerender( <Card isBorderless={ true }>Code is Poetry</Card> );
expect( container.firstChild ).toHaveStyle( 'box-shadow: none' );
expect( withBorders ).toMatchDiffSnapshot( withoutBorders );
} );

it( 'should add rounded border when the isRounded prop is true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ exports[`props should render correctly 1`] = `
background-color: #fff;
color: #000;
position: relative;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
outline: none;
border-radius: 2px;
}

.emotion-1::before {
content: '';
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
pointer-events: none;
}

.emotion-1 .components-card-body {
max-height: 80vh;
}
Expand Down