Skip to content

Commit

Permalink
Merge branch 'main' into 9183-add-theme-package
Browse files Browse the repository at this point in the history
  • Loading branch information
andreancardona authored Jul 22, 2021
2 parents 3f5df5d + 20bd64b commit 1c98d0d
Show file tree
Hide file tree
Showing 31 changed files with 468 additions and 164 deletions.
1 change: 1 addition & 0 deletions config/jest-config-carbon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
'e2e',
'examples',
'/umd/',
'/vendor/',
],
transformIgnorePatterns: [
'/build/',
Expand Down
2 changes: 1 addition & 1 deletion packages/carbon-react/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const decorators = [
const { locale, theme } = context.globals;

React.useEffect(() => {
document.body.setAttribute('data-carbon-theme', theme);
document.documentElement.setAttribute('data-carbon-theme', theme);
}, [theme]);

React.useEffect(() => {
Expand Down
12 changes: 6 additions & 6 deletions packages/carbon-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@carbon/react",
"private": true,
"description": "React components for the Carbon Design System",
"version": "0.7.0",
"version": "0.8.0-rc.0",
"license": "Apache-2.0",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down Expand Up @@ -41,11 +41,11 @@
},
"dependencies": {
"@carbon/feature-flags": "^0.5.0",
"@carbon/icons-react": "^10.35.0",
"@carbon/styles": "^0.10.0",
"@carbon/icons-react": "^10.36.0-rc.0",
"@carbon/styles": "^0.11.0-rc.0",
"@carbon/telemetry": "0.0.0-alpha.6",
"@ibm/plex": "6.0.0-next.6",
"carbon-components-react": "^7.39.0"
"carbon-components-react": "^7.40.0-rc.0"
},
"devDependencies": {
"@babel/core": "^7.14.6",
Expand All @@ -55,8 +55,8 @@
"@babel/plugin-transform-react-constant-elements": "^7.14.5",
"@babel/preset-env": "^7.14.7",
"@babel/preset-react": "^7.14.5",
"@carbon/styles": "^0.10.0-rc.0",
"@carbon/themes": "^10.38.0",
"@carbon/styles": "^0.11.0-rc.0",
"@carbon/themes": "^10.39.0-rc.0",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
Expand Down
14 changes: 14 additions & 0 deletions packages/carbon-react/src/components/Layer/Layer-story.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Copyright IBM Corp. 2018, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@use '@carbon/styles/scss/theme';

.example-layer-test-component {
padding: 1rem;
background: theme.$layer;
color: theme.$text-primary;
}
41 changes: 41 additions & 0 deletions packages/carbon-react/src/components/Layer/Layer-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* 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 { screen, render } from '@testing-library/react';
import React from 'react';
import { Layer } from '../Layer';

describe('Layer', () => {
it('should render the children passed in as a prop', () => {
render(
<Layer>
<span data-testid="test">test</span>
</Layer>
);

expect(screen.getByTestId('test')).toBeInTheDocument();
});

it('should spread any additional props onto the top-level element', () => {
render(
<Layer data-testid="test">
<span>test</span>
</Layer>
);

expect(screen.getByTestId('test')).toBeInTheDocument();
});

it('should accept a custom class name', () => {
render(
<Layer className="custom-class" data-testid="test">
<span>test</span>
</Layer>
);
expect(screen.getByTestId('test')).toHaveClass('custom-class');
});
});
66 changes: 66 additions & 0 deletions packages/carbon-react/src/components/Layer/Layer.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Story, Props, Source, Preview } from '@storybook/addon-docs/blocks';

# Layer

[Source code](https://github.com/carbon-design-system/carbon/tree/main/packages/carbon-react/src/components/Layer)

<!-- prettier-ignore-start -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of Contents

- [Overview](#overview)
- [Component API](#component-api)
- [Layer as](#layer-as)
- [Feedback](#feedback)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- prettier-ignore-end -->

## Overview

The `Layer` component is used to render components on different layers. Each
layer has a specific set of token values associated with it. You can use these
tokens directly, or use contextual tokens from our styles package like `$layer`
or `$field`.

The `Layer` component accepts `children` as a prop. Each child of a `Layer`
component is rendered using the layer tokens at that layer. `Layer` components
can be nested indefinitely, but the token sets typically end after 3 layers.

```jsx
<Layer>
<ChildComponent />
<Layer>
<ChildComponent />
<Layer>
<ChildComponent />
</Layer>
</Layer>
</Layer>
```
## Component API
<Props />
### Layer as
You can configure the base element rendered by `Layer` using the `as` prop. For
example, if you would like the `Layer` component to render as a `section` you
could write the following:
```jsx
<Layer as="section">
<ChildComponent />
</Layer>
```

Similarly, you can provide any custom component to the `as` prop which the
`Layer` component will use.

## Feedback

Help us improve this component by providing feedback, asking questions on Slack,
or updating this file on
[GitHub](https://github.com/carbon-design-system/carbon/edit/main/packages/carbon-react/src/components/Layer/Layer.mdx).
59 changes: 59 additions & 0 deletions packages/carbon-react/src/components/Layer/Layer.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* 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 './Layer-story.scss';
import React from 'react';
import { Layer } from '../Layer';
import mdx from './Layer.mdx';

export default {
title: 'Components/Layer',
component: Layer,
parameters: {
controls: {
hideNoControlsWarning: true,
},
docs: {
page: mdx,
},
},
argTypes: {
as: {
table: {
disable: true,
},
},
children: {
table: {
disable: true,
},
},
className: {
table: {
disable: true,
},
},
},
};

export const Default = () => {
function TestComponent() {
return <div className="example-layer-test-component">Test component</div>;
}

return (
<>
<TestComponent />
<Layer>
<TestComponent />
<Layer>
<TestComponent />
</Layer>
</Layer>
</>
);
};
47 changes: 47 additions & 0 deletions packages/carbon-react/src/components/Layer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* 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 React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';

export function Layer({
as: BaseComponent = 'div',
className: customClassName,
children,
...rest
}) {
const className = cx('bx--layer', customClassName);
return (
<BaseComponent {...rest} className={className}>
{children}
</BaseComponent>
);
}

Layer.propTypes = {
/**
* Specify a custom component or element to be rendered as the top-level
* element in the component
*/
as: PropTypes.oneOfType([
PropTypes.func,
PropTypes.string,
PropTypes.elementType,
]),

/**
* Provide child elements to be rendered inside of `Theme`
*/
children: PropTypes.node,

/**
* Provide a custom class name to be used on the outermost element rendered by
* the component
*/
className: PropTypes.string,
};
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@carbon/cli",
"description": "Task automation for working with the Carbon Design System",
"version": "10.25.0",
"version": "10.26.0-rc.0",
"license": "Apache-2.0",
"bin": {
"carbon-cli": "./bin/carbon-cli.js"
Expand Down
4 changes: 2 additions & 2 deletions packages/colors/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@carbon/colors",
"description": "Colors for digital and software products using the Carbon Design System",
"version": "10.28.0",
"version": "10.29.0-rc.0",
"license": "Apache-2.0",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down Expand Up @@ -35,7 +35,7 @@
"clean": "rimraf css es lib umd scss index.scss"
},
"devDependencies": {
"@carbon/cli": "^10.25.0",
"@carbon/cli": "^10.26.0-rc.0",
"@carbon/cli-reporter": "^10.5.0",
"@carbon/scss-generator": "^10.13.0",
"@carbon/test-utils": "^10.16.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "carbon-components",
"description": "The Carbon Design System is IBM’s open-source design system for products and experiences.",
"version": "10.39.0",
"version": "10.40.0-rc.0",
"license": "Apache-2.0",
"main": "umd/index.js",
"module": "es/index.js",
Expand Down Expand Up @@ -80,10 +80,10 @@
"@babel/preset-env": "^7.14.7",
"@babel/preset-react": "^7.14.5",
"@babel/runtime": "^7.14.6",
"@carbon/cli": "^10.25.0",
"@carbon/elements": "^10.38.0",
"@carbon/icons-handlebars": "^10.35.0",
"@carbon/icons-react": "^10.35.0",
"@carbon/cli": "^10.26.0-rc.0",
"@carbon/elements": "^10.39.0-rc.0",
"@carbon/icons-handlebars": "^10.36.0-rc.0",
"@carbon/icons-react": "^10.36.0-rc.0",
"@carbon/test-utils": "^10.16.0",
"@frctl/fractal": "^1.1.0",
"@rollup/plugin-babel": "^5.3.0",
Expand Down
18 changes: 9 additions & 9 deletions packages/elements/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@carbon/elements",
"description": "A collection of design elements in code for the IBM Design Language",
"version": "10.38.0",
"version": "10.39.0-rc.0",
"license": "Apache-2.0",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down Expand Up @@ -35,17 +35,17 @@
"clean": "rimraf es lib umd && node tasks/clean.js"
},
"dependencies": {
"@carbon/colors": "^10.28.0",
"@carbon/grid": "^10.31.0",
"@carbon/icons": "^10.35.0",
"@carbon/colors": "^10.29.0-rc.0",
"@carbon/grid": "^10.32.0-rc.0",
"@carbon/icons": "^10.36.0-rc.0",
"@carbon/import-once": "^10.6.0",
"@carbon/layout": "^10.27.0",
"@carbon/motion": "^10.20.0",
"@carbon/themes": "^10.38.0",
"@carbon/type": "^10.31.0"
"@carbon/layout": "^10.28.0-rc.0",
"@carbon/motion": "^10.21.0-rc.0",
"@carbon/themes": "^10.39.0-rc.0",
"@carbon/type": "^10.32.0-rc.0"
},
"devDependencies": {
"@carbon/cli": "^10.25.0",
"@carbon/cli": "^10.26.0-rc.0",
"fs-extra": "^8.1.0",
"klaw-sync": "^6.0.0",
"replace-in-file": "^3.4.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/grid/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@carbon/grid",
"description": "Grid for digital and software products using the Carbon Design System",
"version": "10.31.0",
"version": "10.32.0-rc.0",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand Down Expand Up @@ -32,10 +32,10 @@
},
"dependencies": {
"@carbon/import-once": "^10.6.0",
"@carbon/layout": "^10.27.0"
"@carbon/layout": "^10.28.0-rc.0"
},
"devDependencies": {
"@carbon/cli": "^10.25.0",
"@carbon/cli": "^10.26.0-rc.0",
"rimraf": "^3.0.0"
},
"eyeglass": {
Expand Down
Loading

0 comments on commit 1c98d0d

Please sign in to comment.