Skip to content

Commit

Permalink
Merge branch 'main' into feat/cwc-storybook-7
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnacioBecerra committed Dec 20, 2023
2 parents 0b5dd10 + ba48fa6 commit 36d2de3
Show file tree
Hide file tree
Showing 84 changed files with 2,066 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ button.addEventListener('click', () => {
```

<iframe
src="https://stackblitz.com/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/cwc-v2/packages/carbon-web-components/examples/codesandbox/form/basic?embed=1&file=src%2Findex.js&hideExplorer=1&hideNavigation=1&theme=light&terminalHeight=0&hidedevtools=1"
src="https://stackblitz.com/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/main/packages/carbon-web-components/examples/codesandbox/form/basic?embed=1&file=src%2Findex.js&hideExplorer=1&hideNavigation=1&theme=light&terminalHeight=0&hidedevtools=1"
style={{ width: '100%', height: '500px', border: 'solid rgba(0,0,0,0.1) 1px', boxShadow: 'rgba(0,0,0,0.1) 0 1px 3px 0' }}
title="carbon-web-components-getting-started"
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Changes to CSS Custom Properties of the Carbon theme are reflected in the color
scheme of `@carbon/web-components` components:

<iframe
src="https://stackblitz.com/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/cwc-v2/packages/carbon-web-components/examples/codesandbox/styling/theme-zoning?embed=1&file=src%2Findex.js&hideExplorer=1&hideNavigation=1&theme=light&terminalHeight=0&hidedevtools=1"
src="https://stackblitz.com/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/main/packages/carbon-web-components/examples/codesandbox/styling/theme-zoning?embed=1&file=src%2Findex.js&hideExplorer=1&hideNavigation=1&theme=light&terminalHeight=0&hidedevtools=1"
style={{
width: '100%',
height: '700px',
Expand Down Expand Up @@ -102,7 +102,7 @@ class MyDropdown extends CDSDropdown {
```

<iframe
src="https://stackblitz.com/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/cwc-v2/packages/carbon-web-components/examples/codesandbox/styling/custom-style?embed=1&file=src%2Findex.js&hideExplorer=1&hideNavigation=1&theme=light&terminalHeight=0&hidedevtools=1"
src="https://stackblitz.com/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/main/packages/carbon-web-components/examples/codesandbox/styling/custom-style?embed=1&file=src%2Findex.js&hideExplorer=1&hideNavigation=1&theme=light&terminalHeight=0&hidedevtools=1"
style={{
width: '100%',
height: '500px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ yarn add @carbon/web-components

### Basic usage

Our example at [Stackblitz](https://stackblitz.com/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/cwc-v2/packages/carbon-web-components/examples/codesandbox/basic) shows the most basic usage:
Our example at [Stackblitz](https://stackblitz.com/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/main/packages/carbon-web-components/examples/codesandbox/basic) shows the most basic usage:

<iframe
src="https://stackblitz.com/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/cwc-v2/packages/carbon-web-components/examples/codesandbox/basic?embed=1&file=src%2Findex.js&hideExplorer=1&hideNavigation=1&theme=light&terminalHeight=0&hidedevtools=1"
src="https://stackblitz.com/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/main/packages/carbon-web-components/examples/codesandbox/basic?embed=1&file=src%2Findex.js&hideExplorer=1&hideNavigation=1&theme=light&terminalHeight=0&hidedevtools=1"
style={{ width: '100%', height: '500px', border: 'solid rgba(0,0,0,0.1) 1px', boxShadow: 'rgba(0,0,0,0.1) 0 1px 3px 0' }}
title="carbon-web-components-getting-started"
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<link rel="stylesheet"
href="https://1.www.s81c.com/common/carbon-for-ibm-dotcom/tag/v1/latest/plex.css"/>
<link rel="stylesheet" href="https://1.www.s81c.com/common/carbon/web-components/tag/v2/latest/grid.css" />
<link rel="stylesheet" href="https://1.www.s81c.com/common/carbon/web-components/tag/v2/latest/themes.css" />
<link rel="stylesheet" href="https://1.www.s81c.com/common/carbon/web-components/tag/v2/latest/themes.css" />
<style>
/* Suppress custom element until styles are loaded */
cds-checkbox:not(:defined) {
Expand All @@ -24,6 +24,6 @@
<script type="module" src="https://1.www.s81c.com/common/carbon/web-components/tag/v2/latest/checkbox.min.js"></script>
</head>
<body class="cds-theme-zone-white">
<cds-checkbox label-text="Lorem Ipsum"></cds-checkbox>
<cds-checkbox>Lorem Ipsum</cds-checkbox>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<meta charset="UTF-8" />
<link rel="stylesheet"
href="https://1.www.s81c.com/common/carbon-for-ibm-dotcom/tag/v1/latest/plex.css"/>

<link rel="stylesheet" href="src/styles.scss" />
<style>
/* Suppress custom element until styles are loaded */
Expand All @@ -24,6 +24,6 @@
<script type="module" src="src/index.js"></script>
</head>
<body>
<cds-checkbox label-text="Lorem Ipsum"></cds-checkbox>
<cds-checkbox>Lorem Ipsum</cds-checkbox>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"start": "parcel index.html --port=9000 --no-hmr"
},
"dependencies": {
"@carbon/styles": "^1.34.0",
"@carbon/styles": "^1.45.0",
"@carbon/web-components": "latest",
"sass": "^1.64.1"
},
Expand Down
12 changes: 6 additions & 6 deletions web-components/packages/carbon-web-components/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@carbon/web-components",
"private": true,
"version": "2.0.2-rc.1",
"version": "2.1.0",
"publishConfig": {
"access": "public"
},
Expand Down Expand Up @@ -50,7 +50,7 @@
"test:unit": "cross-env NODE_OPTIONS=--openssl-legacy-provider gulp test:unit",
"test:unit:updateSnapshot": "NODE_OPTIONS=--openssl-legacy-provider gulp test:unit --update-snapshot",
"typecheck": "tsc --noEmit -p tsconfig.json",
"visual-snapshot": "yarn build-storybook && percy storybook ./storybook-static",
"visual-snapshot": "yarn build-storybook && percy storybook:start ./storybook-static",
"wca": "web-component-analyzer analyze src --outFile custom-elements.json"
},
"files": [
Expand All @@ -72,7 +72,7 @@
],
"dependencies": {
"@babel/runtime": "^7.16.3",
"@carbon/styles": "^1.44.0",
"@carbon/styles": "^1.45.0",
"flatpickr": "4.6.1",
"lit": "^2.7.6",
"lodash-es": "^4.17.21"
Expand All @@ -97,9 +97,9 @@
"@mordech/vite-lit-loader": "^0.31.3",
"@open-wc/semantic-dom-diff": "~0.18.0",
"@percy-io/in-percy": "^0.1.11",
"@percy/cli": "^1.8.1",
"@percy/cypress": "^3.1.1",
"@percy/dom": "^1.0.5",
"@percy/cli": "^1.27.4",
"@percy/cypress": "^3.1.2",
"@percy/dom": "^1.27.5",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^21.0.3",
"@rollup/plugin-node-resolve": "^8.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn';
# Accordion

> 💡 Check our
> [CodeSandbox](https://codesandbox.io/s/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/cwc-v2/packages/carbon-web-components/examples/codesandbox/basic/components/accordion)
> [CodeSandbox](https://codesandbox.io/s/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/main/packages/carbon-web-components/examples/codesandbox/basic/components/accordion)
> example implementation.
[![Edit carbon-web-components](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/cwc-v2/packages/carbon-web-components/examples/codesandbox/basic/components/accordion)
[![Edit carbon-web-components](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/main/packages/carbon-web-components/examples/codesandbox/basic/components/accordion)

The accordion component delivers large amounts of content in a small space
through progressive disclosure. That is, the user gets key details about the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn';
# Breadcrumb

> 💡 Check our
> [CodeSandbox](https://codesandbox.io/s/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/cwc-v2/packages/carbon-web-components/examples/codesandbox/basic/components/breadcrumb)
> [CodeSandbox](https://codesandbox.io/s/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/main/packages/carbon-web-components/examples/codesandbox/basic/components/breadcrumb)
> example implementation.
[![Edit carbon-web-components](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/cwc-v2/packages/carbon-web-components/examples/codesandbox/basic/components/breadcrumb)
[![Edit carbon-web-components](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/main/packages/carbon-web-components/examples/codesandbox/basic/components/breadcrumb)

## Getting started

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import Add16 from '@carbon/web-components/es/icons/add/16';
# Button

> 💡 Check our
> [CodeSandbox](https://codesandbox.io/s/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/cwc-v2/packages/carbon-web-components/examples/codesandbox/basic/components/button)
> [CodeSandbox](https://codesandbox.io/s/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/main/packages/carbon-web-components/examples/codesandbox/basic/components/button)
> example implementation.
[![Edit carbon-web-components](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/cwc-v2/packages/carbon-web-components/examples/codesandbox/basic/components/button)
[![Edit carbon-web-components](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/carbon-design-system/carbon-for-ibm-dotcom/tree/feat/main/packages/carbon-web-components/examples/codesandbox/basic/components/button)

## Overview

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
/**
* @license
*
* Copyright IBM Corp. 2019, 2023
*
* 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 { classMap } from 'lit/directives/class-map.js';
import { LitElement, html } from 'lit';
import { property } from 'lit/decorators.js';
import { prefix } from '../../globals/settings';
import WarningFilled16 from '@carbon/icons/lib/warning--filled/16';
import WarningAltFilled16 from '@carbon/icons/lib/warning--alt--filled/16';
import CDSCheckbox from './checkbox';
import styles from './checkbox.scss';
import { carbonElement as customElement } from '../../globals/decorators/carbon-element';

/**
* Check box.
*
* @element cds-checkbox
* @fires cds-checkbox-changed - The custom event fired after this changebox changes its checked state.
* @csspart input The checkbox.
* @csspart label The label.
*/
@customElement(`${prefix}-checkbox-group`)
class CDSCheckboxGroup extends LitElement {
/**
* fieldset `aria-labelledby`
*/
@property({ type: String, reflect: true, attribute: 'aria-labelledby' })
ariaLabelledBy;

/**
* Specify whether the form group is currently disabled
*/
@property({ type: Boolean })
disabled;

/**
* Provide text for the form group for additional help
*/
@property({ type: String, reflect: true, attribute: 'helper-text' })
helperText;

/**
* Specify whether the form group is currently invalid
*/
@property({ type: Boolean, attribute: 'invalid' })
invalid;

/**
* Provide the text that is displayed when the form group is in an invalid state
*/
@property({ type: String, reflect: true, attribute: 'invalid-text' })
invalidText;

/**
* Provide id for the fieldset <legend> which corresponds to the fieldset
* `aria-labelledby`
*/
@property({ type: String, reflect: true, attribute: 'legend-id' })
legendId;

/**
* Provide the text to be rendered inside of the fieldset <legend>
*/
@property({ type: String, reflect: true, attribute: 'legend-text' })
legendText;

/**
* Whether the CheckboxGroup should be read-only
*/
@property({ type: Boolean, reflect: true })
readonly = false;

/**
* Specify whether the form group is currently in warning state
*/
@property({ type: Boolean, reflect: true })
warn = false;

/**
* Provide the text that is displayed when the form group is in warning state
*/
@property({ type: String, reflect: true, attribute: 'warn-text' })
warnText = '';

/*
* Handles `slotchange` event.
*/
protected _handleSlotChange({ target }: Event) {
const hasContent = (target as HTMLSlotElement)
.assignedNodes()
.filter((elem) =>
(elem as HTMLElement).matches !== undefined
? (elem as HTMLElement).matches(
(this.constructor as typeof CDSCheckboxGroup).slugItem
)
: false
);

this._hasSlug = Boolean(hasContent);
(hasContent[0] as HTMLElement).setAttribute('size', 'mini');
this.requestUpdate();
}

/**
* `true` if there is a slug.
*/
protected _hasSlug = false;

updated(changedProperties) {
const { selectorCheckbox } = this.constructor as typeof CDSCheckboxGroup;
const checkboxes = this.querySelectorAll(selectorCheckbox);
['disabled', 'readonly'].forEach((name) => {
if (changedProperties.has(name)) {
const { [name as keyof CDSCheckboxGroup]: value } = this;
// Propagate the property to descendants until `:host-context()` gets supported in all major browsers
checkboxes.forEach((elem) => {
(elem as CDSCheckbox)[name] = value;
});
}
});
if (changedProperties.has('invalid')) {
const { invalid } = this;
checkboxes.forEach((elem) => {
if (invalid) {
(elem as CDSCheckbox).setAttribute('invalid-group', '');
} else {
(elem as CDSCheckbox).removeAttribute('invalid-group');
}
});
}
}

render() {
const {
ariaLabelledBy,
disabled,
helperText,
invalid,
invalidText,
legendId,
legendText,
readonly,
warn,
warnText,
_hasSlug: hasSlug,
_handleSlotChange: handleSlotChange,
} = this;

const showWarning = !readonly && !invalid && warn;
const showHelper = !invalid && !warn;

const checkboxGroupInstanceId = Math.random().toString(16).slice(2);

const helperId = !helperText
? undefined
: `checkbox-group-helper-text-${checkboxGroupInstanceId}`;

const helper = helperText
? html` <div id="${helperId}" class="${prefix}--form__helper-text">
${helperText}
</div>`
: null;

const fieldsetClasses = classMap({
[`${prefix}--checkbox-group`]: true,
[`${prefix}--checkbox-group--readonly`]: readonly,
[`${prefix}--checkbox-group--invalid`]: !readonly && invalid,
[`${prefix}--checkbox-group--warning`]: showWarning,
[`${prefix}--checkbox-group--slug`]: hasSlug,
});

return html`
<fieldset
class="${fieldsetClasses}"
?data-invalid=${invalid}
?disabled=${disabled}
aria-readonly=${readonly}
?aria-labelledby=${ariaLabelledBy || legendId}
?aria-describedby=${!invalid && !warn && helper ? helperId : undefined}>
<legend class="${prefix}--label" id=${legendId || ariaLabelledBy}>
${legendText}
<slot name="slug" @slotchange="${handleSlotChange}"></slot>
</legend>
<slot></slot>
<div class="${prefix}--checkbox-group__validation-msg">
${!readonly && invalid
? html`
${WarningFilled16({
class: `${prefix}--checkbox__invalid-icon`,
})}
<div class="${prefix}--form-requirement">${invalidText}</div>
`
: null}
${showWarning
? html`
${WarningAltFilled16({
class: `${prefix}--checkbox__invalid-icon ${prefix}--checkbox__invalid-icon--warning`,
})}
<div class="${prefix}--form-requirement">${warnText}</div>
`
: null}
</div>
${showHelper ? helper : null}
</fieldset>
`;
}

/**
* A selector that will return the checkboxes.
*/
static get selectorCheckbox() {
return `${prefix}-checkbox`;
}

/**
* A selector that will return the slug item.
*/
static get slugItem() {
return `${prefix}-slug`;
}

static shadowRootOptions = {
...LitElement.shadowRootOptions,
delegatesFocus: true,
};
static styles = styles; // `styles` here is a `CSSResult` generated by custom WebPack loader
}

export default CDSCheckboxGroup;
Loading

0 comments on commit 36d2de3

Please sign in to comment.