apps/public-docsite-v9/src/Concepts/Migration/FromV0/Components/Text.mdx
import { Meta } from '@storybook/addon-docs/blocks';
<Meta title="Concepts/Migration/from v0/Components/Text Migration" />Before:
import { Text } from '@fluentui/react-northstar';
const Component = () => <Text content="Test" />;
After:
import { StyledText } from '@fluentui/react-migration-v0-v9';
const Component = () => <StyledText>Test</StyledText>;
| Text props | migrate guide |
|---|---|
| as, className | keep it as is |
| content | see [Migrate content prop](#Migrate-`content`-prop) in this document |
| variables, styles | see [Migrate style overrides](#migrate-style-overrides) in this document |
| accessibility | see [migrate-custom-accessibility.md](?path=/docs/concepts-migration-from-v0-custom-accessibility--docs) |
| color | REMOVED: use styles and color tokens to set a text's color |
| align, atMention, disabled, error, important, success, temporary, timestamp | keep it as is |
| size | keep `smaller`/`small`/`medium`/`larger`/`largest` as is; for `large` size, see [Migrate size `large`](#./Migrate-size-`large`) in this document |
| weight | keep it as is |
| truncated | migrate to `truncate={true} wrap={false}` |
| link, href | see [Migrate link and href props](#Migrate-`link`-and-`href`-props) in this document |
content propMove content to JSX children.
Before:
import { Text } from '@fluentui/react-northstar';
const Component = () => <Text content="hi" />;
After:
import { StyledText } from '@fluentui/react-migration-v0-v9';
const Component = () => <StyledText>hi</StyledText>;
If content with translation disappears after migration, please check troubleshoot.md.
⚠️ If this is your first migration, please read the general guide on how to migrate styles.
variables:Before:
// in COMPONENT_NAME.tsx
import { Text } from '@fluentui/react-northstar';
export const Component = () => <Text variables={{ enableMainWindowChatHeaderTitleStyles: true }} />;
// in text-styles.ts
export const textStyles1 = {
root: ({ variables: { enableMainWindowChatHeaderTitleStyles } }) => ({
...(enableMainWindowChatHeaderTitleStyles && {
maxWidth: '11rem',
}),
}),
};
After:
// in COMPONENT_NAME.tsx
import { StyledText } from '@fluentui/react-migration-v0-v9';
import { useStyles } from './COMPONENT_NAME.styles.ts';
export const Component = () => {
const classes = useStyles();
return <StyledText className={classes.mainWindowChatHeaderTitle}></StyledText>;
};
// in COMPONENT_NAME.styles.ts
import { makeStyles } from '@fluentui/react-components';
export const useStyles = makeStyles({
mainWindowChatHeaderTitle: {
maxWidth: '11rem',
},
});
largev0 large text is 18px. It can be migrate to v9 size large or large500.
Please note that v9 large text is 16px. The alterative large500 text is 20px.
link and href propsUse Link component instead of Text when you need to render link.
Before:
import { Text } from '@fluentui/react-northstar';
const Component = () => <Text link href="#" target="_blank" content="Link somewhere" />;
After:
import { Link } from '@fluentui/react-components';
const Component = () => (
<Link href="#" target="_blank">
Link somewhere
</Link>
);