From 727691155c4f9e5dc3c56976f5316dd8ff7d1550 Mon Sep 17 00:00:00 2001 From: Josefina Mancilla <32556167+jnm2377@users.noreply.github.com> Date: Tue, 19 Oct 2021 13:45:55 -0500 Subject: [PATCH 1/2] feat(Tab): make tab functional component (#9722) * feat(Tab): make tab functional component * feat(Tabs): convert to functional * fix: remove console.logs * fix: export components as default * fix: tabs state and refs * fix: use prefix * fix: add feature flag v11 story * fix: temp use v10 classNames * fix: clean up, comment, and fix select * fix: keyboard navigation * fix: remove console log * chore: tabs comment * feat: add tab tests * feat: add tabs tests * fix: add back light * fix: remove v11 styles * Update packages/react/src/components/Tabs/index.js Co-authored-by: Taylor Jones * fix: next tab test and deprecation * fix: tabs deprecate unused props * fix: deprecations' * fix: tab role presentation test * fix: remove unused arg' Co-authored-by: Taylor Jones Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../src/components/Tabs/Tabs.stories.js | 8 + .../__snapshots__/PublicAPI-test.js.snap | 6 +- packages/react/src/components/Tab/Tab-test.js | 2 +- packages/react/src/components/Tab/Tab.js | 4 +- packages/react/src/components/Tab/index.js | 8 +- .../react/src/components/Tab/next/Tab-test.js | 204 ++++++ packages/react/src/components/Tab/next/Tab.js | 166 +++++ packages/react/src/components/Tabs/index.js | 11 +- .../src/components/Tabs/next/Tabs-test.js | 264 ++++++++ .../react/src/components/Tabs/next/Tabs.js | 613 ++++++++++++++++++ 10 files changed, 1276 insertions(+), 10 deletions(-) create mode 100644 packages/react/src/components/Tab/next/Tab-test.js create mode 100644 packages/react/src/components/Tab/next/Tab.js create mode 100644 packages/react/src/components/Tabs/next/Tabs-test.js create mode 100644 packages/react/src/components/Tabs/next/Tabs.js diff --git a/packages/carbon-react/src/components/Tabs/Tabs.stories.js b/packages/carbon-react/src/components/Tabs/Tabs.stories.js index 1c04f224b089..4e4741d3288f 100644 --- a/packages/carbon-react/src/components/Tabs/Tabs.stories.js +++ b/packages/carbon-react/src/components/Tabs/Tabs.stories.js @@ -7,10 +7,18 @@ import React from 'react'; import { Button, Tab, Tabs, TabsSkeleton } from '../Tabs'; +import { unstable_FeatureFlags as FeatureFlags } from 'carbon-components-react'; import { Layer } from '../Layer'; export default { title: 'Components/Tabs', + decorators: [ + (Story) => ( + + + + ), + ], parameters: { component: Tabs, subcomponents: { diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap index 6ac36a38f0a8..6223d424aed7 100644 --- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -5905,7 +5905,6 @@ Map { "label": "provide a label", "onClick": [Function], "onKeyDown": [Function], - "role": "presentation", "selected": false, }, "propTypes": Object { @@ -5946,10 +5945,7 @@ Map { "renderContent": Object { "type": "func", }, - "role": Object { - "isRequired": true, - "type": "string", - }, + "role": [Function], "selected": Object { "isRequired": true, "type": "bool", diff --git a/packages/react/src/components/Tab/Tab-test.js b/packages/react/src/components/Tab/Tab-test.js index f28a9e157f99..f84b5668a6ac 100644 --- a/packages/react/src/components/Tab/Tab-test.js +++ b/packages/react/src/components/Tab/Tab-test.js @@ -45,7 +45,7 @@ describe('Tab', () => { }); it('renders
  • with [role="presentation"]', () => { - expect(wrapper.props().role).toEqual('presentation'); + expect(wrapper.find('li').prop('role')).toEqual('presentation'); }); it('renders + )} +
  • + ); +}); + +Tab.propTypes = { + /** + * Specify an optional className to be added to your Tab + */ + className: PropTypes.string, + + /** + * Whether your Tab is disabled. + */ + disabled: PropTypes.bool, + + /** + * A handler that is invoked when a user clicks on the control. + * Reserved for usage in Tabs + */ + handleTabClick: PropTypes.func, + + /** + * A handler that is invoked on the key down event for the control. + * Reserved for usage in Tabs + */ + handleTabKeyDown: PropTypes.func, + + /** + * The element ID for the top-level element. + */ + id: PropTypes.string, + + /** + * The index of your Tab in your Tabs. Reserved for usage in Tabs + */ + index: PropTypes.number, + + /** + * Provide the contents of your Tab + */ + label: PropTypes.node, + + /** + * Provide a handler that is invoked when a user clicks on the control + */ + onClick: PropTypes.func, + + /** + * Provide a handler that is invoked on the key down event for the control + */ + onKeyDown: PropTypes.func, + + /* + * An optional parameter to allow overriding the anchor rendering. + * Useful for using Tab along with react-router or other client + * side router libraries. + **/ + renderButton: PropTypes.func, + + /* + * An optional parameter to allow overriding the content rendering. + **/ + renderContent: PropTypes.func, + + /** + * Whether your Tab is selected. + * Reserved for usage in Tabs + */ + selected: PropTypes.bool, + + /** + * Specify the tab index of the ` + {!leftOverflowNavButtonHidden && ( +
    + )} +
      + {tabsWithProps} +
    + {!rightOverflowNavButtonHidden && ( +
    + )} + +
    + {tabContentWithProps} + + ); +}); + +Tabs.propTypes = { + /** + * Pass in a collection of children to be rendered depending on the + * currently selected tab + */ + children: PropTypes.node, + + /** + * Provide a className that is applied to the root
    component for the + * + */ + className: PropTypes.string, + + /** + * Specify whether the Tab content is hidden + */ + hidden: PropTypes.bool, + + /** + * Provide the props that describe the left overflow button + */ + leftOverflowButtonProps: PropTypes.object, + + /** + * Specify whether or not to use the light component variant + */ + light: deprecate( + PropTypes.bool, + 'The light prop has been deprecated in v11 in favor of our new layering model that uses the Layer component' + ), + + /** + * Optionally provide an `onClick` handler that is invoked when a is + * clicked + */ + onClick: PropTypes.func, + + /** + * Optionally provide an `onKeyDown` handler that is invoked when keyed + * navigation is triggered + */ + onKeyDown: PropTypes.func, + + /** + * Provide an optional handler that is called whenever the selection + * changes. This method is called with the index of the tab that was + * selected + */ + onSelectionChange: PropTypes.func, + + /** + * Provide the props that describe the right overflow button + */ + rightOverflowButtonProps: PropTypes.object, + + /** + * Choose whether or not to automatically scroll to newly selected tabs + * on component rerender + */ + scrollIntoView: PropTypes.bool, + + /** + * Optionally provide an index for the currently selected + */ + selected: PropTypes.number, + + /** + * Choose whether or not to automatically change selection on focus + */ + selectionMode: PropTypes.oneOf(['automatic', 'manual']), + + /** + * Provide a className that is applied to the components + */ + tabContentClassName: PropTypes.string, + + /** + * Provide the type of Tab + */ + type: PropTypes.oneOf(['default', 'container']), +}; + +export default Tabs; From 72731190d6bf854b09e3cdb5785799821908970f Mon Sep 17 00:00:00 2001 From: Taylor Jones Date: Tue, 19 Oct 2021 14:19:30 -0500 Subject: [PATCH 2/2] Remove external/outside margin from components (#9830) * fix(form): remove fieldset margin * fix(form): remove fileuploader margin * fix(form): remove label margin * fix(notifications): remove external margin * fix(structured-list): remove external margin * chore: put component margin removal behind flag * chore: add v11 flag env variable to sass compilation config Co-authored-by: Josh Black --- .../file-uploader/_file-uploader.scss | 5 ++++- .../components/src/components/form/_form.scss | 21 +++++++++++++------ .../notification/_inline-notification.scss | 7 +++++-- .../notification/_toast-notification.scss | 15 ++++++++----- .../structured-list/_structured-list.scss | 5 ++++- packages/react/.storybook/main.js | 4 +++- .../src/components/FormGroup/FormGroup.js | 3 ++- .../file-uploader/_file-uploader.scss | 5 ++++- .../styles/scss/components/form/_form.scss | 21 +++++++++++++------ .../_actionable-notification.scss | 7 +++++-- .../notification/_inline-notification.scss | 7 +++++-- .../notification/_toast-notification.scss | 15 ++++++++----- .../structured-list/_structured-list.scss | 5 ++++- 13 files changed, 86 insertions(+), 34 deletions(-) diff --git a/packages/components/src/components/file-uploader/_file-uploader.scss b/packages/components/src/components/file-uploader/_file-uploader.scss index 1d997c4d0600..bb4b63e24c7e 100644 --- a/packages/components/src/components/file-uploader/_file-uploader.scss +++ b/packages/components/src/components/file-uploader/_file-uploader.scss @@ -57,7 +57,10 @@ display: inline-block; width: 100%; max-width: rem(320px); - margin-bottom: $carbon--spacing-03; + @if not feature-flag-enabled('enable-v11-release') { + margin-bottom: $carbon--spacing-03; + } + color: $link-01; cursor: pointer; outline: 2px solid transparent; diff --git a/packages/components/src/components/form/_form.scss b/packages/components/src/components/form/_form.scss index 17715c9e33f8..f00ae8ef4124 100644 --- a/packages/components/src/components/form/_form.scss +++ b/packages/components/src/components/form/_form.scss @@ -18,11 +18,15 @@ .#{$prefix}--fieldset { @include reset; - margin-bottom: $carbon--spacing-07; + @if not feature-flag-enabled('enable-v11-release') { + margin-bottom: $carbon--spacing-07; + } } - .#{$prefix}--fieldset--no-margin { - margin-bottom: 0; + @if not feature-flag-enabled('enable-v11-release') { + .#{$prefix}--fieldset--no-margin { + margin-bottom: 0; + } } .#{$prefix}--form-item { @@ -42,7 +46,10 @@ @include type-style('label-01'); display: inline-block; - margin-bottom: $carbon--spacing-03; + @if not feature-flag-enabled('enable-v11-release') { + margin-bottom: $carbon--spacing-03; + } + color: $text-02; font-weight: $input-label-weight; line-height: 1rem; @@ -125,8 +132,10 @@ display: block; } - .#{$prefix}--form--fluid .#{$prefix}--fieldset { - margin: 0; + @if not feature-flag-enabled('enable-v11-release') { + .#{$prefix}--form--fluid .#{$prefix}--fieldset { + margin: 0; + } } .#{$prefix}--form--fluid input[data-invalid] { diff --git a/packages/components/src/components/notification/_inline-notification.scss b/packages/components/src/components/notification/_inline-notification.scss index 17cbde33b4c4..f58bf988467d 100644 --- a/packages/components/src/components/notification/_inline-notification.scss +++ b/packages/components/src/components/notification/_inline-notification.scss @@ -33,8 +33,11 @@ height: auto; min-height: rem(48px); flex-wrap: wrap; - margin-top: $carbon--spacing-05; - margin-bottom: $carbon--spacing-05; + @if not feature-flag-enabled('enable-v11-release') { + margin-top: $carbon--spacing-05; + margin-bottom: $carbon--spacing-05; + } + color: $inverse-01; @include carbon--breakpoint(md) { diff --git a/packages/components/src/components/notification/_toast-notification.scss b/packages/components/src/components/notification/_toast-notification.scss index 1fb6fdaa305d..2c4cf3d76b02 100644 --- a/packages/components/src/components/notification/_toast-notification.scss +++ b/packages/components/src/components/notification/_toast-notification.scss @@ -29,14 +29,19 @@ width: rem(288px); height: auto; padding-left: $carbon--spacing-05; - margin-top: $carbon--spacing-03; - margin-right: $carbon--spacing-05; - margin-bottom: $carbon--spacing-03; + @if not feature-flag-enabled('enable-v11-release') { + margin-top: $carbon--spacing-03; + margin-right: $carbon--spacing-05; + margin-bottom: $carbon--spacing-03; + } + box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.2); color: $inverse-01; - &:first-child { - margin-top: $carbon--spacing-05; + @if not feature-flag-enabled('enable-v11-release') { + &:first-child { + margin-top: $carbon--spacing-05; + } } @include carbon--breakpoint(max) { diff --git a/packages/components/src/components/structured-list/_structured-list.scss b/packages/components/src/components/structured-list/_structured-list.scss index f07bf8b9ed23..a19bbcbf7dae 100644 --- a/packages/components/src/components/structured-list/_structured-list.scss +++ b/packages/components/src/components/structured-list/_structured-list.scss @@ -32,7 +32,10 @@ display: table; width: 100%; - margin-bottom: 5rem; + @if not feature-flag-enabled('enable-v11-release') { + margin-bottom: 5rem; + } + background-color: transparent; border-collapse: collapse; border-spacing: 0; diff --git a/packages/react/.storybook/main.js b/packages/react/.storybook/main.js index 4d9fa461553e..41be2da8f11c 100644 --- a/packages/react/.storybook/main.js +++ b/packages/react/.storybook/main.js @@ -13,7 +13,7 @@ const customProperties = require('postcss-custom-properties'); const rtlcss = require('rtlcss'); const { - CARBON_ENABLE_V11_RELEASE, + CARBON_ENABLE_V11_RELEASE = 'false', CARBON_REACT_STORYBOOK_USE_CUSTOM_PROPERTIES = 'false', CARBON_REACT_STORYBOOK_USE_RTL, CARBON_REACT_STORYBOOK_USE_SASS_LOADER, @@ -69,6 +69,7 @@ module.exports = { $feature-flags: ( ui-shell: true, enable-css-custom-properties: ${CARBON_REACT_STORYBOOK_USE_CUSTOM_PROPERTIES}, + enable-v11-release: ${CARBON_ENABLE_V11_RELEASE}, ); ${content} `; @@ -88,6 +89,7 @@ module.exports = { $feature-flags: ( ui-shell: true, enable-css-custom-properties: ${CARBON_REACT_STORYBOOK_USE_CUSTOM_PROPERTIES}, + enable-v11-release: ${CARBON_ENABLE_V11_RELEASE}, ); `, implementation: require('sass'), diff --git a/packages/react/src/components/FormGroup/FormGroup.js b/packages/react/src/components/FormGroup/FormGroup.js index f2cd065863d5..d476c4bd4d50 100644 --- a/packages/react/src/components/FormGroup/FormGroup.js +++ b/packages/react/src/components/FormGroup/FormGroup.js @@ -19,7 +19,7 @@ const FormGroup = ({ className, message, messageText, - hasMargin, + hasMargin, // TODO - remove in v11 ...other }) => { const prefix = usePrefix(); @@ -27,6 +27,7 @@ const FormGroup = ({ const classNamesLegend = classnames(`${prefix}--label`, [ enabled ? null : className, ]); + // TODO - remove `fieldset--no-margin` in v11 const classNamesFieldset = classnames(`${prefix}--fieldset`, className, { [`${prefix}--fieldset--no-margin`]: !hasMargin, }); diff --git a/packages/styles/scss/components/file-uploader/_file-uploader.scss b/packages/styles/scss/components/file-uploader/_file-uploader.scss index 1f7a90661459..d093294b83df 100644 --- a/packages/styles/scss/components/file-uploader/_file-uploader.scss +++ b/packages/styles/scss/components/file-uploader/_file-uploader.scss @@ -62,7 +62,10 @@ display: inline-block; width: 100%; max-width: rem(320px); - margin-bottom: $spacing-03; + @if not enabled('enable-v11-release') { + margin-bottom: $spacing-03; + } + color: $link-primary; cursor: pointer; outline: 2px solid transparent; diff --git a/packages/styles/scss/components/form/_form.scss b/packages/styles/scss/components/form/_form.scss index 1db3071bcad7..bee4c969ac82 100644 --- a/packages/styles/scss/components/form/_form.scss +++ b/packages/styles/scss/components/form/_form.scss @@ -22,11 +22,15 @@ $input-label-weight: 400 !default; .#{$prefix}--fieldset { @include reset; - margin-bottom: $spacing-07; + @if not enabled('enable-v11-release') { + margin-bottom: $spacing-07; + } } - .#{$prefix}--fieldset--no-margin { - margin-bottom: 0; + @if not enabled('enable-v11-release') { + .#{$prefix}--fieldset--no-margin { + margin-bottom: 0; + } } .#{$prefix}--form-item { @@ -46,7 +50,10 @@ $input-label-weight: 400 !default; @include type-style('label-01'); display: inline-block; - margin-bottom: $spacing-03; + @if not enabled('enable-v11-release') { + margin-bottom: $spacing-03; + } + color: $text-secondary; font-weight: $input-label-weight; line-height: 1rem; @@ -129,8 +136,10 @@ $input-label-weight: 400 !default; display: block; } - .#{$prefix}--form--fluid .#{$prefix}--fieldset { - margin: 0; + @if not enabled('enable-v11-release') { + .#{$prefix}--form--fluid .#{$prefix}--fieldset { + margin: 0; + } } .#{$prefix}--form--fluid input[data-invalid] { diff --git a/packages/styles/scss/components/notification/_actionable-notification.scss b/packages/styles/scss/components/notification/_actionable-notification.scss index 7984f0bdb9c1..deb8d6e6cb42 100644 --- a/packages/styles/scss/components/notification/_actionable-notification.scss +++ b/packages/styles/scss/components/notification/_actionable-notification.scss @@ -36,8 +36,11 @@ height: auto; min-height: rem(48px); flex-wrap: wrap; - margin-top: $spacing-05; - margin-bottom: $spacing-05; + @if not enabled('enable-v11-release') { + margin-top: $spacing-05; + margin-bottom: $spacing-05; + } + color: $text-inverse; @include breakpoint(md) { diff --git a/packages/styles/scss/components/notification/_inline-notification.scss b/packages/styles/scss/components/notification/_inline-notification.scss index 5f281a2cf556..fe15efe2a1d0 100644 --- a/packages/styles/scss/components/notification/_inline-notification.scss +++ b/packages/styles/scss/components/notification/_inline-notification.scss @@ -34,8 +34,11 @@ height: auto; min-height: rem(48px); flex-wrap: wrap; - margin-top: $spacing-05; - margin-bottom: $spacing-05; + @if not enabled('enable-v11-release') { + margin-top: $spacing-05; + margin-bottom: $spacing-05; + } + color: $text-inverse; @include breakpoint(md) { diff --git a/packages/styles/scss/components/notification/_toast-notification.scss b/packages/styles/scss/components/notification/_toast-notification.scss index 80765bcc3a93..c4e6471ef7e7 100644 --- a/packages/styles/scss/components/notification/_toast-notification.scss +++ b/packages/styles/scss/components/notification/_toast-notification.scss @@ -32,14 +32,19 @@ width: rem(288px); height: auto; padding-left: $spacing-05; - margin-top: $spacing-03; - margin-right: $spacing-05; - margin-bottom: $spacing-03; + @if not enabled('enable-v11-release') { + margin-top: $spacing-03; + margin-right: $spacing-05; + margin-bottom: $spacing-03; + } + box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.2); color: $text-inverse; - &:first-child { - margin-top: $spacing-05; + @if not enabled('enable-v11-release') { + &:first-child { + margin-top: $spacing-05; + } } @include breakpoint(max) { diff --git a/packages/styles/scss/components/structured-list/_structured-list.scss b/packages/styles/scss/components/structured-list/_structured-list.scss index 08a64f15cc9d..ed2c72bb94bc 100644 --- a/packages/styles/scss/components/structured-list/_structured-list.scss +++ b/packages/styles/scss/components/structured-list/_structured-list.scss @@ -36,7 +36,10 @@ display: table; width: 100%; - margin-bottom: 5rem; + @if not enabled('enable-v11-release') { + margin-bottom: 5rem; + } + background-color: transparent; border-collapse: collapse; border-spacing: 0;