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
2 changes: 1 addition & 1 deletion packages/react/src/components/Switch/Switch.js
Expand Up @@ -107,7 +107,7 @@ Switch.propTypes = {
/**
* Provide the contents of your Switch
*/
text: PropTypes.string.isRequired,
text: PropTypes.node.isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, would it help if this component to accept a children prop for the generalized PropTypes.node use-case? Having text not be PropTypes.string can be confusing sometimes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshblack Yeah I dig that idea. I'll deprecate text, too. Actually it seems like there could be a benefit to keeping text around - it has styles associated with it to enable truncation.

};

Switch.defaultProps = {
Expand Down
44 changes: 44 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,42 @@ 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={<Text>{rtlText}</Text>} />
<Switch name="two" text="Second section" />
<Switch name="three" text="Third section" />
</ContentSwitcher>
</>
);
};