Skip to content

Commit

Permalink
Merge branch 'master' into modal-titleonly
Browse files Browse the repository at this point in the history
  • Loading branch information
asudoh authored Nov 20, 2019
2 parents 6f2689d + 6a0cfea commit 9e8366f
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 14 deletions.
35 changes: 33 additions & 2 deletions packages/components/docs/sass.md
Original file line number Diff line number Diff line change
Expand Up @@ -3413,6 +3413,7 @@ $carbon--spacing-05: 1rem;
- [slider [mixin]](#slider-mixin)
- [padding-th [mixin]](#padding-th-mixin)
- [padding-td [mixin]](#padding-td-mixin)
- [tabs [mixin]](#tabs-mixin)
- [text-area [mixin]](#text-area-mixin)
- [text-input [mixin]](#text-input-mixin)
- [tile [mixin]](#tile-mixin)
Expand Down Expand Up @@ -9648,6 +9649,8 @@ Include the `font-family` definition for the given name in your selector
- **Group**: [@carbon/type](#carbontype)
- **Requires**:
- [carbon--font-family [function]](#carbon--font-family-function)
- **Used by**:
- [snippet [mixin]](#snippet-mixin)

### ✅carbon--font-weights [variable]

Expand Down Expand Up @@ -13532,6 +13535,7 @@ Code snippet styles

.#{$prefix}--btn--copy__feedback {
@include type-style('body-short-01');
@include carbon--font-family('sans'); // Override one in code snippet
z-index: z('overlay');
font-weight: 400;
left: inherit;
Expand Down Expand Up @@ -13643,9 +13647,27 @@ Code snippet styles
}

.#{$prefix}--snippet-button .#{$prefix}--btn--copy__feedback {
top: rem(25px);
top: rem(
50.8px
); // (The height of button) + (The height of the tooltip's triangle) + 4px
left: 50%;
right: auto;

&::before {
top: 0;
}

&:after {
top: rem(-4px);
}
}

.#{$prefix}--snippet--multi
.#{$prefix}--snippet-button
.#{$prefix}--btn--copy__feedback {
top: rem(
42.8px
); // (The height of button) + (The height of the tooltip's triangle) + 4px
}

.#{$prefix}--snippet--inline .#{$prefix}--btn--copy__feedback {
Expand Down Expand Up @@ -13724,6 +13746,7 @@ Code snippet styles
- **Group**: [code-snippet](#code-snippet)
- **Requires**:
- [bx--snippet [mixin]](#bx--snippet-mixin)
- [carbon--font-family [mixin]](#carbon--font-family-mixin)
- [prefix [variable]](#prefix-variable)
- [ui-01 [variable]](#ui-01-variable)
- [text-01 [variable]](#text-01-variable)
Expand Down Expand Up @@ -16634,6 +16657,7 @@ File uploader styles
margin-bottom: $carbon--spacing-03;
display: inline-block;
width: 100%;
max-width: rem(320px);
color: $link-01;
outline: none;
transition: $duration--fast-02 motion(standard, productive);
Expand Down Expand Up @@ -16842,7 +16866,6 @@ File uploader styles
align-items: flex-start;
justify-content: space-between;
height: rem(96px);
max-width: rem(320px);
padding: $carbon--spacing-05;
overflow: hidden;
border: 1px dashed $ui-04;
Expand Down Expand Up @@ -21664,6 +21687,13 @@ Tabs styles
color: $text-02;
}

//-----------------------------
// Tab Content Container
//-----------------------------
.#{$prefix}--tab-content {
padding: $carbon--spacing-05;
}

//-----------------------------
// Skeleton state
//-----------------------------
Expand Down Expand Up @@ -21712,6 +21742,7 @@ Tabs styles
- [text-02 [variable]](#text-02-variable)
- [spacing-04 [variable]](#spacing-04-variable)
- [spacing-03 [variable]](#spacing-03-variable)
- [carbon--spacing-05 [variable]](#carbon--spacing-05-variable)

## tag

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ const rows = [
secondaryText: 'Secondary Text',
port: '80',
rule: 'Round Robin',
attachedGroups: "Maureen's VM Groups Testing a really long text here",
attachedGroups: 'Maureen’s VM Groups Testing a really long text here',
status: 'Active',
menu: {
label: 'Overflow menu description',
Expand All @@ -242,7 +242,7 @@ const rows = [
secondaryText: 'Secondary Text',
port: '80',
rule: 'Round Robin',
attachedGroups: "Maureen's VM Groups",
attachedGroups: 'Maureen’s VM Groups',
status: 'Active',
menu: {
label: 'Overflow menu description',
Expand All @@ -262,7 +262,7 @@ const rows = [
protocol: 'HTTP',
port: '80',
rule: 'Round Robin',
attachedGroups: "Maureen's VM Groups",
attachedGroups: 'Maureen’s VM Groups',
status: 'Active',
menu: {
label: 'Overflow menu description',
Expand All @@ -282,7 +282,7 @@ const rows = [
protocol: 'HTTP',
port: '80',
rule: 'Round Robin',
attachedGroups: "Maureen's VM Groups",
attachedGroups: 'Maureen’s VM Groups',
status: 'Active',
menu: {
label: 'Overflow menu description',
Expand All @@ -302,7 +302,7 @@ const rows = [
protocol: 'HTTP',
port: '80',
rule: 'Round Robin',
attachedGroups: "Maureen's VM Groups",
attachedGroups: 'Maureen’s VM Groups',
status: 'Active',
menu: {
label: 'Overflow menu description',
Expand All @@ -329,7 +329,7 @@ const rowsExpandable = [
protocol: 'HTTP',
port: '80',
rule: 'Round Robin',
attachedGroups: "Maureen's VM Groups",
attachedGroups: 'Maureen’s VM Groups',
status: 'Active',
},
{
Expand All @@ -348,7 +348,7 @@ const rowsExpandable = [
protocol: 'HTTP',
port: '80',
rule: 'Round Robin',
attachedGroups: "Maureen's VM Groups",
attachedGroups: 'Maureen’s VM Groups',
status: 'Active',
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ $css--helpers: true;
}

.#{$prefix}--pagination .#{$prefix}--select-input--inline__wrapper {
display: flex;
height: 100%;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ describe('Carbon Components React', () => {
"DatePickerSkeleton",
"Dropdown",
"DropdownSkeleton",
"ErrorBoundary",
"ErrorBoundaryContext",
"ExpandableTile",
"FileUploader",
"FileUploaderButton",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class ComposedModal extends Component {
/**
* Specify the size variant.
*/
size: PropTypes.oneOf('xs', 'sm', 'lg'),
size: PropTypes.oneOf(['xs', 'sm', 'lg']),
};

static getDerivedStateFromProps({ open }, state) {
Expand Down
82 changes: 82 additions & 0 deletions packages/react/src/components/ErrorBoundary/ErrorBoundary-story.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* 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, { useState } from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { ErrorBoundary, ErrorBoundaryContext } from './';
import Button from '../Button';

storiesOf('ErrorBoundary', module)
.add('default', () => {
function DemoComponent() {
const [shouldThrowError, setShouldThrowError] = useState(false);

function onClick() {
setShouldThrowError(!shouldThrowError);
}

return (
<>
<Button onClick={onClick}>Toggle throwing error</Button>
<div>
<ErrorBoundary fallback={<Fallback />}>
<ThrowError shouldThrowError={shouldThrowError} />
</ErrorBoundary>
</div>
</>
);
}

function Fallback() {
return 'Whoops';
}

function ThrowError({ shouldThrowError }) {
if (shouldThrowError) {
throw new Error('Component threw error');
}

return 'Successfully rendered';
}

return <DemoComponent />;
})
.add('with custom context', () => {
function DemoComponent() {
const [shouldThrowError, setShouldThrowError] = useState(false);

function onClick() {
setShouldThrowError(!shouldThrowError);
}

return (
<ErrorBoundaryContext.Provider value={{ log: action('log') }}>
<Button onClick={onClick}>Toggle throwing error</Button>
<div>
<ErrorBoundary fallback={<Fallback />}>
<ThrowError shouldThrowError={shouldThrowError} />
</ErrorBoundary>
</div>
</ErrorBoundaryContext.Provider>
);
}

function Fallback() {
return 'Whoops';
}

function ThrowError({ shouldThrowError }) {
if (shouldThrowError) {
throw new Error('Component threw error');
}

return 'Successfully rendered';
}

return <DemoComponent />;
});
63 changes: 63 additions & 0 deletions packages/react/src/components/ErrorBoundary/ErrorBoundary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* 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 { ErrorBoundaryContext } from './ErrorBoundaryContext';

/**
* React introduced additional lifecycle methods in v16 for capturing errors
* that occur in a specific sub-tree of components. This component helps to
* consolidate some of the duplication that occurs when using these lifecycle
* methods across a codebase. In addition, it allows you to specify the fallback
* UI to display when an error occurs in the sub-tree through the `fallback`
* prop.
*
* This component roughly follows the React.js docs example code for these
* methods. In addition, it takes advantage of an `ErrorBoundaryContext` so that
* consumers can specify their own logic for logging errors. For example,
* reporting an error in the UI to an external service for every `ErrorBoundary`
* used.
*
* Reference:
* https://reactjs.org/docs/error-boundaries.html#introducing-error-boundaries
*/
export default class ErrorBoundary extends React.Component {
static propTypes = {
children: PropTypes.node,
fallback: PropTypes.node,
};

static contextType = ErrorBoundaryContext;

static getDerivedStateFromError() {
return {
hasError: true,
};
}

state = {
hasError: false,
};

componentDidCatch(error, info) {
this.context.log(error, info);
}

componentDidUpdate(prevProps) {
if (prevProps.children !== this.props.children) {
this.setState({ hasError: false });
}
}

render() {
if (this.state.hasError) {
return this.props.fallback;
}
return this.props.children;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* 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 { createContext } from 'react';

export const ErrorBoundaryContext = createContext({
log(error, info) {
console.log(info.componentStack);
},
});
Loading

0 comments on commit 9e8366f

Please sign in to comment.