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(project): add flat exports for namespaced components #9008

Merged
merged 9 commits into from
Jul 23, 2021
470 changes: 470 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions packages/react/docs/migration/11.x-namespaced-exports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Namespaced exports

<!-- 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)
- [Process](#process)
- [Changes:](#changes)

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

## Overview

In v10.x there were a few exported components that were only exposed under the
namespace of another component. These have been deprecated, and a new export has
been made available for each so these can be imported directly. In v11.x the
namespaced exports will be removed.

## Process

1. Update imports for the components listed in the table below.

```diff
- import TextInput from 'carbon-components-react';
+ import { PasswordInput } from 'carbon-components-react';
```

2. Update usages of the components listed in the table below, they no longer
need the namespace

```diff
- <TextInput.PasswordInput/>
+ <PasswordInput/>
```

## Changes:

| v10.x | v11.x |
| ----------------------------------- | ------------------------- |
| `TextInput.ControlledPasswordInput` | `ControlledPasswordInput` |
| `TextInput.PasswordInput` | `PasswordInput` |
| `MultiSelect.Filterable` | `FilterableMultiSelect` |
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 @@ -35,6 +35,7 @@ describe('Carbon Components React', () => {
"ComposedModal",
"Content",
"ContentSwitcher",
"ControlledPasswordInput",
"Copy",
"CopyButton",
"DangerButton",
Expand Down Expand Up @@ -96,6 +97,7 @@ describe('Carbon Components React', () => {
"Pagination",
"PaginationNav",
"PaginationSkeleton",
"PasswordInput",
"PrimaryButton",
"ProgressIndicator",
"ProgressIndicatorSkeleton",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export FilterableMultiSelect from '../MultiSelect/FilterableMultiSelect';
2 changes: 2 additions & 0 deletions packages/react/src/components/PasswordInput/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export ControlledPasswordInput from '../TextInput/ControlledPasswordInput';
export PasswordInput from '../TextInput/PasswordInput';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React, { useState } from 'react';
import { action } from '@storybook/addon-actions';
import { withKnobs, boolean, select, text } from '@storybook/addon-knobs';
import TextInput from '../TextInput';
import { TextInput } from '../../index';
import TextInputSkeleton from '../TextInput/TextInput.Skeleton';
import FluidForm from '../FluidForm/FluidForm';
import mdx from './TextInput.mdx';
Expand Down
27 changes: 25 additions & 2 deletions packages/react/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import { deprecateFieldOnObject } from './internal/deprecateFieldOnObject';

export Accordion from './components/Accordion';
export AccordionItem from './components/AccordionItem';
export { AspectRatio } from './components/AspectRatio';
Expand Down Expand Up @@ -72,7 +74,15 @@ export ListItem from './components/ListItem';
export Loading from './components/Loading';
export Modal from './components/Modal';
export ModalWrapper from './components/ModalWrapper';
export MultiSelect from './components/MultiSelect';
import MultiSelect from './components/MultiSelect';
if (__DEV__) {
deprecateFieldOnObject(
MultiSelect,
'MultiSelect.Filterable',
MultiSelect.Filterable
);
}
export { MultiSelect };
export {
ToastNotification,
InlineNotification,
Expand All @@ -86,6 +96,10 @@ export OverflowMenu from './components/OverflowMenu';
export OverflowMenuItem from './components/OverflowMenuItem';
export Pagination from './components/Pagination';
export PaginationNav from './components/PaginationNav';
export {
ControlledPasswordInput,
PasswordInput,
} from './components/PasswordInput';
export PrimaryButton from './components/PrimaryButton';
export {
ProgressIndicator,
Expand Down Expand Up @@ -117,7 +131,16 @@ export TabContent from './components/TabContent';
export Tabs from './components/Tabs';
export Tag from './components/Tag';
export TextArea from './components/TextArea';
export TextInput from './components/TextInput';
import TextInput from './components/TextInput';
if (__DEV__) {
deprecateFieldOnObject(
TextInput,
'ControlledPasswordInput',
TextInput.ControlledPasswordInput
);
deprecateFieldOnObject(TextInput, 'PasswordInput', TextInput.PasswordInput);
}
export { TextInput };
export {
Tile,
ClickableTile,
Expand Down
30 changes: 30 additions & 0 deletions packages/react/src/internal/deprecateFieldOnObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* 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 { warning } from '../internal/warning';

const didWarnAboutDeprecation = {};

function deprecateFieldOnObject(object, field, Component, message) {
Object.defineProperty(object, field, {
enumerable: true,
get() {
if (!didWarnAboutDeprecation[field]) {
warning(
false,
message ||
`The ${field} field has been deprecated on the ${object.displayName} object. ` +
`Please import and use ${field} directly.`
);
didWarnAboutDeprecation[field] = true;
}

return Component;
},
});
}

export { deprecateFieldOnObject };