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

fix(card-group): support RTL borders & padding #11760

Merged
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
60 changes: 27 additions & 33 deletions packages/styles/scss/components/card-group/_card-group.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2022
* Copyright IBM Corp. 2016, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -66,7 +66,7 @@
&__img {
position: absolute;
height: 100%;
top: 0;
inset-block-start: 0;
}
}
}
Expand All @@ -86,8 +86,8 @@

:host(#{$dds-prefix}-card-group-item),
:host(#{$dds-prefix}-card-group-card-link-item) {
padding-bottom: 1px;
padding-right: 1px;
padding-block-end: 1px;
padding-inline-end: 1px;

&[border] {
border: none;
Expand Down Expand Up @@ -122,7 +122,7 @@

&[pattern-background] {
.#{$prefix}--card {
border-bottom: 1px solid $ui-03;
border-block-end: 1px solid $ui-03;
}

.#{$prefix}--card,
Expand All @@ -142,10 +142,7 @@
content: '';
position: absolute;
z-index: 2;
top: 0;
left: 0;
bottom: 0;
right: 0;
inset: 0;
outline: 2px solid $focus;
outline-offset: -2px;
pointer-events: none;
Expand Down Expand Up @@ -186,8 +183,8 @@
// `@include carbon--make-row()` has negative margin adjustment assuming that it's placed in Carbon grid.
// Such adjustment has adverse effect when card group is placed in non-Carbon-grid,
// but keeps it for React for backward-compatibility reason.
margin-left: calc(-1 * #{$carbon--grid-gutter} / 2);
margin-right: calc(-1 * #{$carbon--grid-gutter} / 2);
margin-inline-start: calc(-1 * #{$carbon--grid-gutter} / 2);
margin-inline-end: calc(-1 * #{$carbon--grid-gutter} / 2);

position: relative;
&::after {
Expand All @@ -196,8 +193,8 @@
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
inset-inline-start: 0;
inset-block-start: 0;
pointer-events: none;
box-shadow: inset 0 0 0 1px $ui-background;
}
Expand All @@ -207,11 +204,11 @@
padding: 0;
background: $decorative-01;

border-right: 1px solid $decorative-01;
border-top: 1px solid $decorative-01;
border-inline-end: 1px solid $decorative-01;
border-block-start: 1px solid $decorative-01;

&:last-of-type {
border-right: 0;
border-inline-end: 0;
width: calc(100% - 1px);
}

Expand All @@ -224,12 +221,12 @@
:host(#{$dds-prefix}-card-group)[grid-mode='narrow'],
.#{$prefix}--card-group--narrow {
@include carbon--breakpoint('sm') {
padding-top: $carbon--spacing-03;
padding-block-start: $carbon--spacing-03;
gap: $carbon--spacing-03;
}

@include carbon--breakpoint('md') {
padding-top: $carbon--spacing-05;
padding-block-start: $carbon--spacing-05;
gap: $carbon--spacing-05;
}

Expand Down Expand Up @@ -259,10 +256,7 @@
content: '';
position: absolute;
z-index: 2;
top: 0;
left: 0;
bottom: 0;
right: 0;
inset: 0;
box-shadow: inset 0 0 0 2px $focus;
pointer-events: none;
}
Expand All @@ -279,51 +273,51 @@
.#{$prefix}--card-group__cards__col {
padding: 0;
border: 1px solid $decorative-01;
border-bottom: 0;
border-block-end: 0;
}

.#{$prefix}--card-group__cards__col:last-of-type {
border-bottom: 1px solid $decorative-01;
padding-right: 0;
border-block-end: 1px solid $decorative-01;
padding-inline-end: 0;
}

@include carbon--breakpoint('md') {
.#{$prefix}--card-group__cards__col {
border-bottom: 0;
border-right: 0;
border-block-end: 0;
border-inline-end: 0;
}

.#{$prefix}--card-group__cards__col:nth-child(2n),
.#{$prefix}--card-group__cards__col:last-of-type {
border-right: 1px solid $decorative-01;
border-inline-end: 1px solid $decorative-01;
}

.#{$prefix}--card-group__cards__col:last-of-type:not(:nth-child(2n)) {
width: calc(100% + 1px);
}

.#{$prefix}--card-group__cards__col:nth-last-of-type(-n + 2) {
border-bottom: 1px solid $decorative-01;
border-block-end: 1px solid $decorative-01;
height: calc(100% + 1px);
}
}

@include carbon--breakpoint('lg') {
.#{$prefix}--card-group__cards__col:nth-child(2n),
.#{$prefix}--card-group__cards__col:nth-last-of-type(-n + 2) {
border-bottom: 0;
border-right: 0;
border-block-end: 0;
border-inline-end: 0;
height: auto;
}

.#{$prefix}--card-group__cards__col:nth-child(3n),
.#{$prefix}--card-group__cards__col:last-of-type {
border-right: 1px solid $decorative-01;
border-inline-end: 1px solid $decorative-01;
width: calc(100% + 1px);
}

.#{$prefix}--card-group__cards__col:nth-last-of-type(-n + 3) {
border-bottom: 1px solid $decorative-01;
border-block-end: 1px solid $decorative-01;
height: calc(100% + 1px);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license
*
* Copyright IBM Corp. 2020, 2022
* Copyright IBM Corp. 2020, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand All @@ -21,7 +21,7 @@

::slotted(#{$dds-prefix}-card-group-card-link-item) {
@include carbon--breakpoint('md') {
padding-right: $carbon--spacing-05;
padding-inline-end: $carbon--spacing-05;
}
}

Expand Down
57 changes: 29 additions & 28 deletions packages/web-components/src/components/card-group/card-group.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license
*
* Copyright IBM Corp. 2020, 2023
* Copyright IBM Corp. 2020, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -214,18 +214,18 @@ class DDSCardGroup extends StableSelectorMixin(LitElement) {
// add tag group height to heading to the cards lacking tag group
if (
e &&
!e.nextElementSibling?.matches(
!e?.nextElementSibling?.matches(
(this.constructor as typeof DDSCardGroup).selectorItemTagGroup
) &&
tagGroupHeight > 0
) {
e.style.marginBottom = `${tagGroupHeight + paragraphBottomMargin}px`;
} else if (
e.nextElementSibling?.matches(
e?.nextElementSibling?.matches(
(this.constructor as typeof DDSCardGroup).selectorItemTagGroup
)
) {
let siblingTagGroup = e.nextElementSibling;
let siblingTagGroup = e?.nextElementSibling;
siblingTagGroup.style.marginTop = `${
tagGroupHeight - siblingTagGroup.offsetHeight
}px`;
Expand All @@ -234,6 +234,8 @@ class DDSCardGroup extends StableSelectorMixin(LitElement) {
};

private _borderAdjustments = (columnCount) => {
const { gridMode } = this;

const isEmpty = (element) => element.hasAttribute('empty');
const inFirstColumn = (index) => (index + 1) % columnCount === 1;
const inLastColumn = (index) => (index + 1) % columnCount === 0;
Expand All @@ -243,58 +245,57 @@ class DDSCardGroup extends StableSelectorMixin(LitElement) {
Math.floor((this._childItems.length - 1) / columnCount);

this._childItems.forEach((e, index) => {
const { gridMode } = this;
if (gridMode === GRID_MODE.COLLAPSED) {
e.toggleAttribute('border', false);
if (isEmpty(e)) {
e.style.paddingBottom = '0';
e.style.paddingRight = '0';
e.style.paddingBlockEnd = '0';
e.style.paddingInlineEnd = '0';
} else {
if (inFirstColumn(index)) {
e.style.paddingLeft = '0';
e.style.paddingInlineStart = '0';
}
if (inLastColumn(index)) {
e.style.paddingRight = '0';
e.style.borderRight = `1px solid var(--cds-ui-background)`;
e.style.paddingInlineEnd = '0';
e.style.borderInlineEnd = `1px solid var(--cds-ui-background)`;
} else {
e.style.paddingRight = '1px';
e.style.borderRight = 'none';
e.style.paddingInlineEnd = '1px';
e.style.borderInlineEnd = 'none';
}
if (inFirstRow(index)) {
e.style.paddingTop = '0';
e.style.paddingBlockStart = '0';
}
if (inLastRow(index)) {
e.style.paddingBottom = '0';
e.style.paddingBlockEnd = '0';
} else {
e.style.paddingBottom = '1px';
e.style.paddingBlockEnd = '1px';
}
}
}
if (gridMode === GRID_MODE.BORDER) {
e.toggleAttribute('border', true);
if (isEmpty(e)) {
e.style.paddingBottom = '1px';
e.style.paddingRight = '1px';
e.style.paddingBlockEnd = '1px';
e.style.paddingInlineEnd = '1px';
} else {
e.style.paddingTop = '0';
e.style.paddingBlockStart = '0';
if (inFirstRow(index)) {
e.style.paddingTop = '1px';
e.style.paddingBlockStart = '1px';
}
if (inLastRow(index)) {
e.style.paddingBottom = '1px';
e.style.paddingBlockEnd = '1px';
}
if (inFirstColumn(index)) {
e.style.paddingLeft = '1px';
e.style.paddingInlineStart = '1px';
} else {
e.style.paddingLeft = '0';
e.style.paddingInlineStart = '0';
}
if (inLastColumn(index)) {
e.style.paddingRight = '1px';
e.style.paddingInlineEnd = '1px';
}
}
// if one column and first item is empty then set top border for second item
if (columnCount === 1 && isEmpty(this._childItems[0]) && index === 1) {
e.style.paddingTop = '1px';
e.style.paddingBlockStart = '1px';
}
}
});
Expand All @@ -303,10 +304,10 @@ class DDSCardGroup extends StableSelectorMixin(LitElement) {
private _resetBorders = () => {
this._childItems.forEach((elem) => {
elem.toggleAttribute('border', false);
elem.style.paddingTop = '';
elem.style.paddingRight = '';
elem.style.paddingBottom = '';
elem.style.paddingLeft = '';
elem.style.paddingBlockStart = '';
elem.style.paddingInlineEnd = '';
elem.style.paddingBlockEnd = '';
elem.style.paddingInlineStart = '';
});
};

Expand Down
Loading