Skip to content

Commit 877e478

Browse files
docs(text): add component examples to storybook, update switch text prop (#9817)
* docs(text): add component examples to storybook, update switch text prop * feat(switch): provide optional text and children props * chore: reconfigure stories and switch usage/children prop * fix(switch): render text or children, not both * chore: update snaps Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 7a1e883 commit 877e478

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5692,6 +5692,9 @@ Map {
56925692
},
56935693
"displayName": "Switch",
56945694
"propTypes": Object {
5695+
"children": Object {
5696+
"type": "node",
5697+
},
56955698
"className": Object {
56965699
"type": "string",
56975700
},
@@ -5724,7 +5727,6 @@ Map {
57245727
"type": "bool",
57255728
},
57265729
"text": Object {
5727-
"isRequired": true,
57285730
"type": "string",
57295731
},
57305732
},

packages/react/src/components/Switch/Switch.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const { prefix } = settings;
1414

1515
const Switch = React.forwardRef(function Switch(props, tabRef) {
1616
const {
17+
children,
1718
className,
1819
disabled,
1920
index,
@@ -57,7 +58,7 @@ const Switch = React.forwardRef(function Switch(props, tabRef) {
5758
{...other}
5859
{...commonProps}>
5960
<span className={`${prefix}--content-switcher__label`} title={text}>
60-
{text}
61+
{text !== undefined ? text : children}
6162
</span>
6263
</button>
6364
);
@@ -66,6 +67,11 @@ const Switch = React.forwardRef(function Switch(props, tabRef) {
6667
Switch.displayName = 'Switch';
6768

6869
Switch.propTypes = {
70+
/**
71+
* Provide child elements to be rendered inside of the Switch
72+
*/
73+
children: PropTypes.node,
74+
6975
/**
7076
* Specify an optional className to be added to your Switch
7177
*/
@@ -107,7 +113,7 @@ Switch.propTypes = {
107113
/**
108114
* Provide the contents of your Switch
109115
*/
110-
text: PropTypes.string.isRequired,
116+
text: PropTypes.string,
111117
};
112118

113119
Switch.defaultProps = {

packages/react/src/components/Text/Text-story.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import { LayoutDirection } from '../Layout';
1010
import { TextDirection, Text } from '../Text';
1111
import RadioButtonGroup from '../RadioButtonGroup';
1212
import RadioButton from '../RadioButton';
13+
import Button from '../Button';
14+
import Dropdown from '../Dropdown';
15+
import ContentSwitcher from '../ContentSwitcher';
16+
import Switch from '../Switch';
17+
import { Heading } from '../Heading';
1318

1419
export default {
1520
title: 'Experimental/unstable_Text',
@@ -88,3 +93,44 @@ export const SetTextDirection = () => {
8893
</TextDirection>
8994
);
9095
};
96+
97+
export const ComponentExamples = () => {
98+
const rtlText = 'שלום!!';
99+
const dropdownItems = [
100+
{
101+
id: 'option-0',
102+
text: 'Lorem, ipsum dolor sit amet consectetur adipisicing elit.',
103+
},
104+
{
105+
id: 'option-1',
106+
text: rtlText,
107+
},
108+
];
109+
return (
110+
<>
111+
<Heading>{rtlText}</Heading>
112+
<Button kind="ghost">
113+
<Text>{rtlText}</Text>
114+
</Button>
115+
<div style={{ width: 400 }}>
116+
<Dropdown
117+
id="default"
118+
titleText="Using <Text> with `itemToElement`"
119+
helperText="This is some helper text"
120+
label="Dropdown menu options"
121+
items={dropdownItems}
122+
itemToElement={(item) => <Text>{item.text}</Text>}
123+
/>
124+
</div>
125+
<ContentSwitcher
126+
helperText="Using <Text> within <Switch>"
127+
onChange={() => {}}>
128+
<Switch name="one">
129+
<Text>{rtlText}</Text>
130+
</Switch>
131+
<Switch name="two" text="Second section" />
132+
<Switch name="three" text="Third section" />
133+
</ContentSwitcher>
134+
</>
135+
);
136+
};

0 commit comments

Comments
 (0)