Skip to content

Commit

Permalink
Merge branch 'main' into tooltip-align
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Oct 30, 2021
2 parents 361d77b + 96f45ee commit f445fc2
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 16 deletions.
8 changes: 4 additions & 4 deletions docs/migration/11.x-carbon-components-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
## Table of Contents

- [Components](#components)
- [SideNavMenu](#sidenavmenu)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- prettier-ignore-end -->
Expand All @@ -32,8 +31,9 @@ For a full overview of changes to components, checkout our

## Components

| Component | Changes |
| :------------ | :-------------------------------------------------------------- |
| `SideNavMenu` | Updated from a class to functional component. No other changes. |
| Component | Changes |
| :----------------- | :-------------------------------------------------------------- |
| `HeaderNavigation` | Updated from a class to functional component. No other changes. |
| `SideNavMenu` | Updated from a class to functional component. No other changes. |

## FAQ
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@

.#{$prefix}--data-table thead th.#{$prefix}--table-column-checkbox,
.#{$prefix}--data-table tbody td.#{$prefix}--table-column-checkbox {
width: 2.5rem;
// spacing between checkbox / chevron and next cell should be 8px / 0.5rem
padding-right: rem(4px);
padding-left: 1rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,45 @@ export const WithRadioSelection = () => (
)}
</DataTable>
);

export const WithSelectionAndSorting = () => (
<DataTable rows={rows} headers={headers} isSortable>
{({
rows,
headers,
getHeaderProps,
getRowProps,
getSelectionProps,
getTableProps,
getTableContainerProps,
}) => (
<TableContainer
title="DataTable"
description="With selection"
{...getTableContainerProps()}>
<Table {...getTableProps()}>
<TableHead>
<TableRow>
<TableSelectAll {...getSelectionProps()} />
{headers.map((header, i) => (
<TableHeader key={i} {...getHeaderProps({ header })}>
{header.header}
</TableHeader>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.map((row, i) => (
<TableRow key={i} {...getRowProps({ row })}>
<TableSelectRow {...getSelectionProps({ row })} />
{row.cells.map((cell) => (
<TableCell key={cell.id}>{cell.value}</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
)}
</DataTable>
);
9 changes: 7 additions & 2 deletions packages/react/src/components/FileUploader/FileUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import classNames from 'classnames';
import PropTypes from 'prop-types';
import * as FeatureFlags from '@carbon/feature-flags';
import React from 'react';
import Filename from './Filename';
import FileUploaderButton from './FileUploaderButton';
Expand Down Expand Up @@ -46,7 +47,9 @@ export default class FileUploader extends React.Component {
/**
* Provide a description for the complete/close icon that can be read by screen readers
*/
iconDescription: PropTypes.string,
iconDescription: FeatureFlags.enabled('enable-v11-release')
? PropTypes.string.isRequired
: PropTypes.string,

/**
* Specify the description text of this <FileUploader>
Expand Down Expand Up @@ -97,7 +100,9 @@ export default class FileUploader extends React.Component {
static contextType = PrefixContext;

static defaultProps = {
iconDescription: 'Provide icon description',
iconDescription: FeatureFlags.enabled('enable-v11-release')
? undefined
: 'Provide icon description',
filenameStatus: 'uploading',
buttonLabel: '',
buttonKind: 'primary',
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Loading/Loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Loading.propTypes = {
className: PropTypes.string,

/**
* Specify an description that would be used to best describe the loading state
* Specify a description that would be used to best describe the loading state
*/
description: PropTypes.string,

Expand Down
9 changes: 7 additions & 2 deletions packages/react/src/components/NumberInput/NumberInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { Component } from 'react';
import classNames from 'classnames';
import { settings } from 'carbon-components';
import { Add16, Subtract16 } from '@carbon/icons-react';
import * as FeatureFlags from '@carbon/feature-flags';
import mergeRefs from '../../tools/mergeRefs';
import requiredIfValueExists from '../../prop-types/requiredIfValueExists';
// replace "use" prefix to avoid react thinking this is a hook that
Expand Down Expand Up @@ -190,10 +191,14 @@ class NumberInput extends Component {
static defaultProps = {
disabled: false,
hideLabel: false,
iconDescription: 'choose a number',
iconDescription: FeatureFlags.enabled('enable-v11-release')
? undefined
: 'choose a number',
step: 1,
invalid: false,
invalidText: 'Provide invalidText',
invalidText: FeatureFlags.enabled('enable-v11-release')
? undefined
: 'Provide invalidText',
warn: false,
warnText: '',
ariaLabel: 'Numeric input field with increment and decrement buttons',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import classnames from 'classnames';
import * as FeatureFlags from '@carbon/feature-flags';
import { settings } from 'carbon-components';

const { prefix } = settings;
Expand Down Expand Up @@ -55,7 +56,9 @@ SelectItemGroup.propTypes = {

SelectItemGroup.defaultProps = {
disabled: false,
label: 'Provide label',
label: FeatureFlags.enabled('enable-v11-release')
? undefined
: 'Provide label',
};

export default SelectItemGroup;
9 changes: 7 additions & 2 deletions packages/react/src/components/Tab/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import classNames from 'classnames';
import * as FeatureFlags from '@carbon/feature-flags';
import { settings } from 'carbon-components';
import deprecate from '../../prop-types/deprecate';

Expand Down Expand Up @@ -54,7 +55,9 @@ export default class Tab extends React.Component {
/**
* Provide the contents of your Tab
*/
label: PropTypes.node,
label: FeatureFlags.enabled('enable-v11-release')
? PropTypes.node.isRequired
: PropTypes.node,

/**
* Provide a handler that is invoked when a user clicks on the control
Expand Down Expand Up @@ -97,7 +100,9 @@ export default class Tab extends React.Component {
};

static defaultProps = {
label: 'provide a label',
label: FeatureFlags.enabled('enable-v11-release')
? undefined
: 'provide a label',
selected: false,
onClick: () => {},
onKeyDown: () => {},
Expand Down
6 changes: 5 additions & 1 deletion packages/react/src/components/UIShell/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

import * as FeatureFlags from '@carbon/feature-flags';
import HeaderNavigationClassic from './HeaderNavigation';
import { HeaderNavigation as HeaderNavigationNext } from './next';
import SideNavMenuClassic from './SideNavMenu';
import { SideNavMenu as SideNavMenuNext } from './next/SideNavMenu';

Expand All @@ -19,7 +21,9 @@ export HeaderMenu from './HeaderMenu';
export HeaderMenuButton from './HeaderMenuButton';
export HeaderMenuItem from './HeaderMenuItem';
export HeaderName from './HeaderName';
export HeaderNavigation from './HeaderNavigation';
export const HeaderNavigation = FeatureFlags.enabled('enable-v11-release')
? HeaderNavigationNext
: HeaderNavigationClassic;
export HeaderPanel from './HeaderPanel';
export HeaderSideNavItems from './HeaderSideNavItems';
export Switcher from './Switcher';
Expand Down
56 changes: 56 additions & 0 deletions packages/react/src/components/UIShell/next/HeaderNavigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* 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 cx from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { AriaLabelPropType } from '../../../prop-types/AriaPropTypes';
import { usePrefix } from '../../../internal/usePrefix';

function HeaderNavigation(props) {
const {
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledBy,
children,
className: customClassName,
...rest
} = props;
const prefix = usePrefix();
const className = cx(`${prefix}--header__nav`, customClassName);
// Assign both label strategies in this option, only one should be defined
// so when we spread that should be the one that is applied to the node
const accessibilityLabel = {
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledBy,
};

return (
<nav {...rest} {...accessibilityLabel} className={className}>
<ul className={`${prefix}--header__menu-bar`}>{children}</ul>
</nav>
);
}

HeaderNavigation.propTypes = {
/**
* Required props for accessibility label on the underlying menu
*/
...AriaLabelPropType,

/**
* Provide valid children of HeaderNavigation, for example `HeaderMenuItem`
* or `HeaderMenu`
*/
children: PropTypes.node,

/**
* Optionally provide a custom class to apply to the underlying <nav> node
*/
className: PropTypes.string,
};

export { HeaderNavigation };
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 { cleanup, render, screen } from '@testing-library/react';
import React from 'react';
import { HeaderNavigation } from '../HeaderNavigation';

describe('HeaderNavigation', () => {
it('should render children that are passed to the component', () => {
render(
<HeaderNavigation aria-label="navigation">
<li data-testid="child" />
</HeaderNavigation>
);
expect(screen.getByTestId('child')).toBeVisible();
});

it('should add an accessibility label to the <nav>', () => {
render(
<HeaderNavigation aria-label="navigation">
<li data-testid="child" />
</HeaderNavigation>
);

expect(screen.getByLabelText('navigation')).toBeVisible();

cleanup();
render(
<>
<span id="label">navigation</span>
<HeaderNavigation aria-labelledby="label">
<li data-testid="child" />
</HeaderNavigation>
</>
);

expect(screen.getByLabelText('navigation')).toBeVisible();
});

it('should support a custom className', () => {
const { container } = render(
<HeaderNavigation aria-label="navigation" className="test">
<li data-testid="child" />
</HeaderNavigation>
);

expect(container.firstChild).toHaveClass('test');
});

it('should pass additional props to the outermost element', () => {
const { container } = render(
<HeaderNavigation aria-label="navigation" data-testid="test">
<li data-testid="child" />
</HeaderNavigation>
);

expect(container.firstChild).toHaveAttribute('data-testid', 'test');
});
});
1 change: 1 addition & 0 deletions packages/react/src/components/UIShell/next/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
* LICENSE file in the root directory of this source tree.
*/

export { HeaderNavigation } from './HeaderNavigation';
export { SideNavMenu } from './SideNavMenu';
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@

.#{$prefix}--data-table thead th.#{$prefix}--table-column-checkbox,
.#{$prefix}--data-table tbody td.#{$prefix}--table-column-checkbox {
width: 2.5rem;
// spacing between checkbox / chevron and next cell should be 8px / 0.5rem
padding-right: rem(4px);
padding-left: 1rem;
Expand Down
2 changes: 1 addition & 1 deletion packages/themes/src/next/g100.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const borderDisabled = gray90;
export const textPrimary = gray10;
export const textSecondary = gray30;
export const textPlaceholder = gray60;
export const textHelper = gray50;
export const textHelper = gray40;
export const textError = red30;
export const textInverse = gray100;
export const textOnColor = white;
Expand Down
4 changes: 2 additions & 2 deletions packages/themes/src/next/g90.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ export const borderDisabled = gray80;
// Text
export const textPrimary = gray10;
export const textSecondary = gray30;
export const textPlaceholder = gray60;
export const textHelper = gray50;
export const textPlaceholder = gray50;
export const textHelper = gray30;
export const textError = red30;
export const textInverse = gray100;
export const textOnColor = white;
Expand Down

0 comments on commit f445fc2

Please sign in to comment.