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

refactor(content-block-headlines): use CSS grid for layout #5078

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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2020
* Copyright IBM Corp. 2016, 2021
*
* 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 @@ -30,7 +30,7 @@
}
}

:host(#{$dds-prefix}-content-block__copy),
::slotted(#{$dds-prefix}-content-block-copy),
.#{$prefix}--content-block__copy {
margin-bottom: 6rem;
p {
Expand Down Expand Up @@ -112,6 +112,27 @@
padding-bottom: $carbon--layout-05;
}
}

.#{$prefix}--content-layout--with-headlines {
grid-template:
'heading' auto
'body' auto
'footer' auto / 1fr;

@include carbon--breakpoint('md') {
grid-template:
'heading heading' auto
'body body' auto
'footer .' auto / 1fr 1fr;
}

@include carbon--breakpoint('lg') {
grid-template:
'heading heading .' auto
'body body .' auto
'footer . .' auto / 1fr 1fr 1fr;
}
}
}

@include exports('content-block-headlines') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
'footer .' auto / 1fr 1fr;
}

&.#{$prefix}--layout--border {
margin-left: 0;
margin-right: 0;
padding-left: 0;
padding-right: 0;
}

// Most slotted contents have margins aligning to Carbon grid gutters.
// Note: Child contents define their margin by their own
::slotted([slot]) {
Expand Down
2 changes: 2 additions & 0 deletions packages/web-components/.storybook/container.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ body {
.dds-ce-demo-devenv--simple-grid--card-group,
.dds-ce-demo-devenv--simple-grid--content-layout,
.dds-ce-demo-devenv--simple-grid--content-layout--with-complementary,
.dds-ce-demo-devenv--simple-grid--content-block-headlines,
.dds-ce-demo-devenv--simple-grid--content-section,
.dds-ce-demo-devenv--simple-grid--content-block-cards {
> * {
Expand Down Expand Up @@ -125,6 +126,7 @@ body {
}

.dds-ce-demo-devenv--simple-grid--content-layout--with-complementary,
.dds-ce-demo-devenv--simple-grid--content-block-headlines,
.dds-ce-demo-devenv--simple-grid--content-block-cards {
> * {
grid-column: 5 / span 12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<body>
<div class="bx--grid">
<div class="bx--row">
<div class="bx--col-sm-4 bx-col-lg-12 bx--offset-lg-4">
<div class="bx--col-sm-4 bx-col-lg-12 bx--offset-lg-4 bx--no-gutter">
<dds-content-block-headlines>
<dds-content-block-heading>Curabitur malesuada varius mi eu posuere</dds-content-block-heading>
<dds-content-item-copy>Lorem ipsum *dolor* sit amet</dds-content-item-copy>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ export default !DDS_CONTENT_BLOCK_HEADLINES
},
decorators: [
story => html`
<div class="bx--grid dds-ce-demo-devenv--grid--stretch">
<div class="bx--row dds-ce-demo-devenv--grid-row">
<div class="bx--col-sm-4 bx--offset-lg-4 bx--col-lg-12">
${story()}
</div>
</div>
<div class="dds-ce-demo-devenv--simple-grid dds-ce-demo-devenv--simple-grid--content-block-headlines">
${story()}
</div>
`,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//
// Copyright IBM Corp. 2020
// Copyright IBM Corp. 2020, 2021
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@import '@carbon/ibmdotcom-styles/scss/components/content-block-headlines/content-block-headlines';

:host(#{$dds-prefix}-content-block-headlines-item) {
display: block;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* LICENSE file in the root directory of this source tree.
*/

import { Part } from 'lit-html';
import { css, customElement, html, TemplateResult } from 'lit-element';
import settings from 'carbon-components/es/globals/js/settings';
import ddsSettings from '@carbon/ibmdotcom-utilities/es/utilities/settings/settings.js';
Expand All @@ -24,17 +25,56 @@ const { stablePrefix: ddsPrefix } = ddsSettings;
*/
@customElement(`${ddsPrefix}-content-block-headlines`)
class DDSContentBlockHeadlines extends StableSelectorMixin(DDSContentBlock) {
/**
* The CSS class list for the container (grid) node.
*/
// eslint-disable-next-line class-methods-use-this
protected _getContainerClasses(): string | ((part: Part) => void) {
return `${prefix}--content-layout ${prefix}--content-layout--with-headlines ${prefix}--layout--border`;
}

/**
* @returns The non-header, non-complementary contents.
*/
protected _renderBody(): TemplateResult | string | void {
const { _hasContent: hasContent, _hasCopy: hasCopy, _hasMedia: hasMedia } = this;
return html`
<div ?hidden="${!hasContent && !hasCopy && !hasMedia}" class="${prefix}--content-layout__body">
${super._renderBody()}
</div>
`;
}

protected _renderInnerBody(): TemplateResult | string | void {
const { _hasContent: hasContent, _handleSlotChange: handleSlotChange } = this;
return html`
<div ?hidden="${!hasContent}" class="${prefix}--content-block__children">
<div class="${prefix}--content-block-headlines__container">
<div class="${prefix}--content-block-headlines__row">
<div class="${prefix}--content-block-headlines__item-container">
<slot @slotchange="${handleSlotChange}"></slot>
</div>
</div>
</div>
<div ?hidden="${!hasContent}" class="${prefix}--content-block-headlines__item-container">
<slot @slotchange="${handleSlotChange}"></slot>
</div>
`;
}

protected _renderContent(): TemplateResult | string | void {
const { _handleSlotChange: handleSlotChange } = this;
return html`
<slot @slotchange="${handleSlotChange}"></slot>
`;
}

protected _renderFooter(): TemplateResult | string | void {
const { _hasFooter: hasFooter, _handleSlotChange: handleSlotChange } = this;
// TODO: See if we can remove the surrounding `<div>`
return html`
<div ?hidden="${!hasFooter}">
<slot name="footer" @slotchange="${handleSlotChange}"></slot>
</div>
`;
}

render() {
return html`
<div class="${this._getContainerClasses()}">
${this._renderHeading()}${this._renderBody()}${this._renderComplementary()}
</div>
`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,30 @@
#### `should render with minimum attributes`

```
<slot name="heading">
</slot>
<slot name="copy">
</slot>
<div
class="bx--content-block__children"
hidden=""
>
<div class="bx--content-block-headlines__container">
<div class="bx--content-block-headlines__row">
<div class="bx--content-block-headlines__item-container">
<slot>
</slot>
</div>
</div>
</div>
</div>
<div
class="bx--content-block__cta-row"
hidden=""
>
<div class="bx--content-block__cta bx--content-block__cta-col">
<slot name="footer">
<div class="bx--content-layout bx--content-layout--with-headlines bx--layout--border">
<slot name="heading">
</slot>
<div
class="bx--content-layout__body"
hidden=""
>
<slot name="copy">
</slot>
<div
class="bx--content-block-headlines__item-container"
hidden=""
>
<slot>
</slot>
</div>
<div hidden="">
<slot name="footer">
</slot>
</div>
</div>
<slot name="complementary">
</slot>
</div>
<slot name="complementary">
</slot>

```