From 6969249b3157891e01c15a2485179d7b396edd41 Mon Sep 17 00:00:00 2001 From: Taylor Jones Date: Thu, 7 Oct 2021 09:38:45 -0500 Subject: [PATCH 1/5] docs(text): add component examples to storybook, update switch text prop --- .../__snapshots__/PublicAPI-test.js.snap | 2 +- .../react/src/components/Switch/Switch.js | 2 +- .../react/src/components/Text/Text-story.js | 44 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap index 248de768906b..44c910d3f32f 100644 --- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -5653,7 +5653,7 @@ Map { }, "text": Object { "isRequired": true, - "type": "string", + "type": "node", }, }, "render": [Function], diff --git a/packages/react/src/components/Switch/Switch.js b/packages/react/src/components/Switch/Switch.js index 18303dd52cc3..55f45d50081f 100644 --- a/packages/react/src/components/Switch/Switch.js +++ b/packages/react/src/components/Switch/Switch.js @@ -107,7 +107,7 @@ Switch.propTypes = { /** * Provide the contents of your Switch */ - text: PropTypes.string.isRequired, + text: PropTypes.node.isRequired, }; Switch.defaultProps = { diff --git a/packages/react/src/components/Text/Text-story.js b/packages/react/src/components/Text/Text-story.js index ea843a80f957..c2430d59f674 100644 --- a/packages/react/src/components/Text/Text-story.js +++ b/packages/react/src/components/Text/Text-story.js @@ -10,6 +10,11 @@ import { LayoutDirection } from '../Layout'; import { TextDirection, Text } from '../Text'; import RadioButtonGroup from '../RadioButtonGroup'; import RadioButton from '../RadioButton'; +import Button from '../Button'; +import Dropdown from '../Dropdown'; +import ContentSwitcher from '../ContentSwitcher'; +import Switch from '../Switch'; +import { Heading } from '../Heading'; export default { title: 'Experimental/unstable_Text', @@ -88,3 +93,42 @@ export const SetTextDirection = () => { ); }; + +export const ComponentExamples = () => { + const rtlText = 'שלום!!'; + const dropdownItems = [ + { + id: 'option-0', + text: 'Lorem, ipsum dolor sit amet consectetur adipisicing elit.', + }, + { + id: 'option-1', + text: rtlText, + }, + ]; + return ( + <> + {rtlText} + +
+ {item.text}} + /> +
+ {}}> + {rtlText}} /> + + + + + ); +}; From 0560f287c7cc581f8cd31dc2fabc7c4659689f69 Mon Sep 17 00:00:00 2001 From: Taylor Jones Date: Thu, 21 Oct 2021 11:13:13 -0500 Subject: [PATCH 2/5] feat(switch): provide optional text and children props --- packages/react/src/components/Switch/Switch.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/react/src/components/Switch/Switch.js b/packages/react/src/components/Switch/Switch.js index 55f45d50081f..1fa529019da8 100644 --- a/packages/react/src/components/Switch/Switch.js +++ b/packages/react/src/components/Switch/Switch.js @@ -14,6 +14,7 @@ const { prefix } = settings; const Switch = React.forwardRef(function Switch(props, tabRef) { const { + children, className, disabled, index, @@ -56,9 +57,12 @@ const Switch = React.forwardRef(function Switch(props, tabRef) { aria-selected={selected} {...other} {...commonProps}> - - {text} - + {text ? ( + + {text} + + ) : null} + {children} ); }); @@ -66,6 +70,11 @@ const Switch = React.forwardRef(function Switch(props, tabRef) { Switch.displayName = 'Switch'; Switch.propTypes = { + /** + * Provide child elements to be rendered inside of the Switch + */ + children: PropTypes.node, + /** * Specify an optional className to be added to your Switch */ @@ -107,7 +116,7 @@ Switch.propTypes = { /** * Provide the contents of your Switch */ - text: PropTypes.node.isRequired, + text: PropTypes.string, }; Switch.defaultProps = { From 06b9b973b91ac181bea8bcbc98e514725e3a58a8 Mon Sep 17 00:00:00 2001 From: Taylor Jones Date: Thu, 21 Oct 2021 11:16:24 -0500 Subject: [PATCH 3/5] chore: reconfigure stories and switch usage/children prop --- packages/react/src/components/Switch/Switch.js | 10 ++++------ packages/react/src/components/Text/Text-story.js | 4 +++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/react/src/components/Switch/Switch.js b/packages/react/src/components/Switch/Switch.js index 1fa529019da8..29527d202682 100644 --- a/packages/react/src/components/Switch/Switch.js +++ b/packages/react/src/components/Switch/Switch.js @@ -57,12 +57,10 @@ const Switch = React.forwardRef(function Switch(props, tabRef) { aria-selected={selected} {...other} {...commonProps}> - {text ? ( - - {text} - - ) : null} - {children} + + {text} + {children} + ); }); diff --git a/packages/react/src/components/Text/Text-story.js b/packages/react/src/components/Text/Text-story.js index c2430d59f674..8cd5ad592dbd 100644 --- a/packages/react/src/components/Text/Text-story.js +++ b/packages/react/src/components/Text/Text-story.js @@ -125,7 +125,9 @@ export const ComponentExamples = () => { {}}> - {rtlText}} /> + + {rtlText} + From 37203821cc20cbf9dbbd2d0b38ffda9d12c2c236 Mon Sep 17 00:00:00 2001 From: Taylor Jones Date: Fri, 22 Oct 2021 10:20:54 -0500 Subject: [PATCH 4/5] fix(switch): render text or children, not both --- packages/react/src/components/Switch/Switch.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/react/src/components/Switch/Switch.js b/packages/react/src/components/Switch/Switch.js index 29527d202682..a77382043274 100644 --- a/packages/react/src/components/Switch/Switch.js +++ b/packages/react/src/components/Switch/Switch.js @@ -58,8 +58,7 @@ const Switch = React.forwardRef(function Switch(props, tabRef) { {...other} {...commonProps}> - {text} - {children} + {text !== undefined ? text : children} ); From 15aa469f03b12c1493ce06a88d21c0da5c4d3837 Mon Sep 17 00:00:00 2001 From: Taylor Jones Date: Fri, 22 Oct 2021 10:48:50 -0500 Subject: [PATCH 5/5] chore: update snaps --- .../react/__tests__/__snapshots__/PublicAPI-test.js.snap | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap index 44c910d3f32f..f5a771ac2654 100644 --- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -5620,6 +5620,9 @@ Map { }, "displayName": "Switch", "propTypes": Object { + "children": Object { + "type": "node", + }, "className": Object { "type": "string", }, @@ -5652,8 +5655,7 @@ Map { "type": "bool", }, "text": Object { - "isRequired": true, - "type": "node", + "type": "string", }, }, "render": [Function],