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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5692,6 +5692,9 @@ Map {
},
"displayName": "Switch",
"propTypes": Object {
"children": Object {
"type": "node",
},
"className": Object {
"type": "string",
},
Expand Down Expand Up @@ -5724,7 +5727,6 @@ Map {
"type": "bool",
},
"text": Object {
"isRequired": true,
"type": "string",
},
},
Expand Down
10 changes: 8 additions & 2 deletions packages/react/src/components/Switch/Switch.js
Original file line number Diff line number Diff line change
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 @@ -57,7 +58,7 @@ const Switch = React.forwardRef(function Switch(props, tabRef) {
{...other}
{...commonProps}>
<span className={`${prefix}--content-switcher__label`} title={text}>
{text}
{text !== undefined ? text : children}
</span>
</button>
);
Expand All @@ -66,6 +67,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 +113,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
Original file line number Diff line number Diff line change
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>
</>
);
};