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

feat(cta-section): web component version #4338

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
92818f4
feat(cta-section): introduction
IgnacioBecerra Oct 29, 2020
0f883ea
feat(cta-section): default story completed
IgnacioBecerra Oct 29, 2020
d955fdf
feat(cta-section): web component introduced
IgnacioBecerra Oct 30, 2020
7b7b2ca
Merge branch 'master' into cta-web-components
IgnacioBecerra Nov 2, 2020
b220282
feat(cta-section): default story completed
IgnacioBecerra Nov 3, 2020
80d563b
feat(cta-section): introducing content item footer
IgnacioBecerra Nov 4, 2020
6aaa740
feat(cta-section): introducing link list footer
IgnacioBecerra Nov 4, 2020
74603ab
feat(cta-section): added new cta-section-copy component
IgnacioBecerra Nov 5, 2020
c71b413
Merge branch 'master' into cta-web-components
IgnacioBecerra Nov 5, 2020
ff785c1
feat(cta-section): now using tag selector for component styling
IgnacioBecerra Nov 6, 2020
359e8db
Merge branch 'master' into cta-web-components
IgnacioBecerra Nov 6, 2020
d65e4b4
feat(cta-section): removed duplicate render from conflict
IgnacioBecerra Nov 6, 2020
6d7b49e
Merge branch 'cta-web-components' of https://github.com/IgnacioBecerr…
IgnacioBecerra Nov 6, 2020
a287065
Merge branch 'master' into cta-web-components
jeffchew Nov 6, 2020
ec6fe34
feat(cta-section): fixed README formatting
IgnacioBecerra Nov 6, 2020
a6f0436
feat(cta-section): fixed prettier error
IgnacioBecerra Nov 6, 2020
24d0222
Merge branch 'master' into cta-web-components
IgnacioBecerra Nov 6, 2020
d2650ee
feat(cta-section): fixed components after merging
IgnacioBecerra Nov 6, 2020
763d420
feat(cta-section): fixed cta-section-copy
IgnacioBecerra Nov 6, 2020
a32b33b
feat(cta-section): fixed old component usage
IgnacioBecerra Nov 7, 2020
75ad7e6
Merge branch 'master' into cta-web-components
kodiakhq[bot] Nov 9, 2020
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
Expand Up @@ -26,6 +26,7 @@
}

@mixin cta-section--pattern {
:host(#{$dds-prefix}-cta-section),
.#{$prefix}--cta-section {
&__cta {
padding-bottom: $carbon--layout-05;
Expand Down
12 changes: 6 additions & 6 deletions packages/styles/scss/internal/content-item/_content-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
}

:host(#{$dds-prefix}-content-item-heading),
:host(#{$dds-prefix}-content-item-copy),
.#{$prefix}--content-item__heading,
.#{$prefix}--content-item__copy {
@include carbon--breakpoint(md) {
Expand All @@ -58,13 +59,12 @@
margin-bottom: $carbon--spacing-07;
}

.#{$prefix}--content-item__copy {
p {
@include carbon--type-style('body-long-02');
:host(#{$dds-prefix}-content-item-paragraph),
.#{$prefix}--content-item__copy p {
@include carbon--type-style('body-long-02');

color: $text-01;
margin-bottom: $carbon--spacing-06;
}
color: $text-01;
margin-bottom: $carbon--spacing-06;
}

.#{$prefix}--content-item__cta {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/node_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--
@license

Copyright IBM Corp. 2020

This source code is licensed under the Apache-2.0 license found in the
LICENSE file in the root directory of this source tree.
-->

<html>
<head>
<title>@carbon/ibmdotcom-web-components example</title>
<meta charset="UTF-8" />
<script type="module" src="src/index.js"></script>
<style type="text/css">
/* Avoids FOUC - Will be overriden by `index.scss` */
body {
visibility: hidden;
}
</style>
</head>
<body>
<div class="bx--grid">
<div class="bx--row">"Lorem ipsum *dolor* sit amet"
<div class="bx--col-sm-4 bx-col-lg-12 bx--offset-lg-4">
<dds-cta-section>
<dds-content-block-heading>Curabitur malesuada varius mi eu posuere</dds-content-block-heading>
<dds-cta-section-copy content=${ifNonNull(copy)}></dds-cta-section-copy>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<dds-cta-section-copy content=${ifNonNull(copy)}></dds-cta-section-copy>
<dds-cta-section-copy>Want to discuss your options with a DevOps expert? Contact our sales team to evaluate your needs.</dds-cta-section-copy>

<dds-button-group slot='buttons'>
<dds-button-group-item href="https://example.com">
Primary Button
</dds-button-group-item>
<dds-button-group-item href="https://example.com">
Primary button
</dds-button-group-item>
</dds-button-group>
</dds-cta-section>
</div>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "ibmdotcom-web-components-cta-section-example",
"version": "0.1.0",
"private": true,
"description": "Sample project for getting started with the Web Components from Carbon for IBM.com.",
"license": "Apache-2",
"scripts": {
"start": "snowpack dev",
"build": "snowpack build"
},
"dependencies": {
"@carbon/ibmdotcom-web-components": "canary",
"carbon-components": "~10.17.0",
"lit-element": "~2.4.0",
"lit-html": "~1.3.0"
},
"devDependencies": {
"snowpack": "2.10.1",
"snowpack-plugin-sass": "^1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"template": "node"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": [
"snowpack-plugin-sass"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @license
*
* Copyright IBM Corp. 2020
*
* 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-web-components/es/components/content-block/content-block-heading.js';
import '@carbon/ibmdotcom-web-components/es/components/cta-section/cta-section.js';
import '@carbon/ibmdotcom-web-components/es/components/button-group/button-group.js';

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// @license
//
// Copyright IBM Corp. 2020
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

// `enable-css-custom-properties` and `grid-columns-16` feature flags are requirements for Carbon for IBM.com styles
$feature-flags: (
enable-css-custom-properties: true,
grid-columns-16: true,
);

@import 'carbon-components/scss/globals/grid/grid';

body {
visibility: inherit;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @license
*
* Copyright IBM Corp. 2020
*
* 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 { css, customElement } from 'lit-element';
import ddsSettings from '@carbon/ibmdotcom-utilities/es/utilities/settings/settings.js';
import StableSelectorMixin from '../../globals/mixins/stable-selector';
import DDSMarkdown from '../markdown/markdown';
import './content-item-paragraph';
import styles from './content-item.scss';

const { stablePrefix: ddsPrefix } = ddsSettings;

@customElement(`${ddsPrefix}-content-item-copy`)
class DDSContentItemCopy extends StableSelectorMixin(DDSMarkdown) {
protected get _customTags() {
const tags = new Set(super._customTags);
tags.add(`${ddsPrefix}-content-item-paragraph`);
return tags;
}

protected get _renderer() {
return Object.assign(super._renderer, {
paragraph(text) {
return `<${ddsPrefix}-content-item-paragraph>${text}</${ddsPrefix}-content-item-paragraph>`;
},
});
}

static get stableSelector() {
return `${ddsPrefix}--content-item__copy`;
}

// `styles` here is a `CSSResult` generated by custom WebPack loader
static get styles() {
return css`${super.styles}${styles}`;
}
}

export default DDSContentItemCopy;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @license
*
* Copyright IBM Corp. 2020
*
* 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 { html, customElement, LitElement } from 'lit-element';
import ddsSettings from '@carbon/ibmdotcom-utilities/es/utilities/settings/settings.js';
import styles from './content-item.scss';

const { stablePrefix: ddsPrefix } = ddsSettings;

/**
* The paragraph content in content item.
*
* @element dds-content-item-paragraph
*/
@customElement(`${ddsPrefix}-content-item-paragraph`)
class DDSContentItemParagraph extends LitElement {
render() {
return html`
<slot></slot>
`;
}

static styles = styles; // `styles` here is a `CSSResult` generated by custom WebPack loader
}

export default DDSContentItemParagraph;
34 changes: 16 additions & 18 deletions packages/web-components/src/components/content-item/content-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
* LICENSE file in the root directory of this source tree.
*/

import { html, property, internalProperty, customElement, LitElement, TemplateResult } from 'lit-element';
import { html, internalProperty, customElement, LitElement, TemplateResult } from 'lit-element';
import settings from 'carbon-components/es/globals/js/settings.js';
import ddsSettings from '@carbon/ibmdotcom-utilities/es/utilities/settings/settings.js';
import ifNonNull from 'carbon-web-components/es/globals/directives/if-non-null.js';
import StableSelectorMixin from '../../globals/mixins/stable-selector';
import '../markdown/markdown';
import styles from './content-item.scss';

const { prefix } = settings;
Expand All @@ -22,7 +20,7 @@ const { stablePrefix: ddsPrefix } = ddsSettings;
* The table mapping slot name with the private property name that indicates the existence of the slot content.
*/
const slotExistencePropertyNames = {
cta: '_hasCta',
cta: '_hasCTA',
};

/**
Expand All @@ -39,7 +37,7 @@ class DDSContentItem extends StableSelectorMixin(LitElement) {
* `true` if there is a CTA content.
*/
@internalProperty()
_hasCta = false;
_hasCTA = false;

/**
* Handles `slotchange` event on the CTA slot.
Expand All @@ -54,24 +52,14 @@ class DDSContentItem extends StableSelectorMixin(LitElement) {
this[slotExistencePropertyNames[name] || '_hasDefaultContent'] = hasContent;
}

/**
* The copy text.
*/
@property()
copy = '';

/**
* @returns The body content.
*/
protected _renderBody(): TemplateResult | string | void {
const { copy, _hasCta: hasCta } = this;
const { _hasCTA: hasCTA } = this;
return html`
${!copy
? undefined
: html`
<dds-markdown class="${prefix}--content-item__copy" nobold .content="${ifNonNull(copy)}"> </dds-markdown>
`}
<div ?hidden="${!hasCta}" class="${prefix}--content-item__cta">
<slot></slot>
<div ?hidden="${!hasCTA}" class="${prefix}--content-item__cta">
<slot name="cta" @slotchange="${this._handleSlotchange}"></slot>
</div>
`;
Expand All @@ -87,6 +75,16 @@ class DDSContentItem extends StableSelectorMixin(LitElement) {
`;
}

render() {
return html`
<slot name="heading"></slot>
<div>
<slot name="media"></slot>
</div>
${this._renderBody()}
`;
}

static get stableSelector() {
return `${ddsPrefix}--content-item`;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Props, Description } from '@storybook/addon-docs/blocks';
import contributing from '../../../../../../docs/contributing-license.md';

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import markdownContents from '../../../../docs/markdown-contents.md';

# `<dds-cta-section>`

> Use the CTASection to provide additional contextual information for the section or page with specific calls to action.
> 💡 Check our
> [CodeSandbox](https://githubbox.com/carbon-design-system/carbon-for-ibm-dotcom/tree/master/packages/web-components/examples/codesandbox/components/cta-section)
> example implementation.
[![Edit @carbon/ibmdotcom-web-components](https://codesandbox.io/static/img/play-codesandbox.svg)](https://githubbox.com/carbon-design-system/carbon-for-ibm-dotcom/tree/master/packages/web-components/examples/codesandbox/components/cta-section)
## Getting started

Here's a quick example to get you started.

##### JS

```javascript

import '@carbon/ibmdotcom-web-components/es/components/cta-section/cta-section';
import '@carbon/ibmdtocom-web-components/es/components/cta-section/cta-section-copy';
import '@carbon/ibmdtocom-web-components/es/components/cta-section/cta-section-item';
import '@carbon/ibmdtocom-web-components/es/components/cta-section/cta-section-heading';
import '@carbon/ibmdtocom-web-components/es/components/cta-section/cta-section-item-copy';
import '@carbon/ibmdotcom-web-components/es/components/content-block/content-block-heading';
import '@carbon/ibmdotcom-web-components/es/components/button-group/button-group';
import '@carbon/ibmdotcom-web-components/es/components/button-group/button-group-item';

```

### HTML

```html
<dds-cta-section>
<dds-content-block-heading>Curabitur malesuada varius mi eu posuere</dds-content-block-heading>
<dds-cta-section-copy content="Lorem ipsum *dolor* sit amet"></dds-cta-section-copy>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<dds-cta-section-copy content="Lorem ipsum *dolor* sit amet"></dds-cta-section-copy>
<dds-cta-section-copy>Lorem ipsum *dolor* sit amet</dds-cta-section-copy>

<dds-button-group slot='buttons'>
<dds-button-group-item href="https://example.com">
Primary Button
</dds-button-group-item>
<dds-button-group-item href="https://example.com">
Primary button
</dds-button-group-item>
</dds-button-group>
</dds-cta-section>
```

## Props

<Props of="dds-cta-section" />

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<Description markdown={markdownContents} />

## Stable selectors

See [our README](https://github.com/carbon-design-system/carbon-for-ibm-dotcom/tree/master/packages/web-components#stable-selectors-for-analytics-and-integratione2e-testing-in-web-components) to see how Web Components selector and `data-autoid` should be used.

| Web Components selector | Compatibility selector | Description |
| ----------------------------- | ----------------------------------------- | ----------- |
| `<dds-cta-section>` | `data-autoid="dds--cta-section"` | Component |

<Description markdown={contributing} />
Loading