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

docs(text): add component examples to storybook, update switch text prop #9817

Merged
merged 7 commits into from Oct 22, 2021
Expand Up @@ -5653,7 +5653,7 @@ Map {
},
"text": Object {
"isRequired": true,
"type": "string",
"type": "node",
},
},
"render": [Function],
Expand Down
9 changes: 8 additions & 1 deletion packages/react/src/components/Switch/Switch.js
Expand Up @@ -14,6 +14,7 @@ const { prefix } = settings;

const Switch = React.forwardRef(function Switch(props, tabRef) {
const {
children,
className,
disabled,
index,
Expand Down Expand Up @@ -58,6 +59,7 @@ const Switch = React.forwardRef(function Switch(props, tabRef) {
{...commonProps}>
<span className={`${prefix}--content-switcher__label`} title={text}>
{text}
{children}
tay1orjones marked this conversation as resolved.
Show resolved Hide resolved
</span>
</button>
);
Expand All @@ -66,6 +68,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
*/
Expand Down Expand Up @@ -107,7 +114,7 @@ Switch.propTypes = {
/**
* Provide the contents of your Switch
*/
text: PropTypes.string.isRequired,
text: PropTypes.string,
};

Switch.defaultProps = {
Expand Down
46 changes: 46 additions & 0 deletions packages/react/src/components/Text/Text-story.js
Expand Up @@ -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',
Expand Down Expand Up @@ -88,3 +93,44 @@ export const SetTextDirection = () => {
</TextDirection>
);
};

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 (
<>
<Heading>{rtlText}</Heading>
<Button kind="ghost">
<Text>{rtlText}</Text>
</Button>
<div style={{ width: 400 }}>
<Dropdown
id="default"
titleText="Using <Text> with `itemToElement`"
helperText="This is some helper text"
label="Dropdown menu options"
items={dropdownItems}
itemToElement={(item) => <Text>{item.text}</Text>}
/>
</div>
<ContentSwitcher
helperText="Using <Text> within <Switch>"
onChange={() => {}}>
<Switch name="one">
<Text>{rtlText}</Text>
</Switch>
<Switch name="two" text="Second section" />
<Switch name="three" text="Third section" />
</ContentSwitcher>
</>
);
};