Skip to content

Commit

Permalink
RFC: Simplified component structure for react-text wrappers (#18817)
Browse files Browse the repository at this point in the history
Co-authored-by: Tringa Krasniqi <tkrasniqi@microsoft.com>
Co-authored-by: Oleksandr Fediashov <alexander.mcgarret@gmail.com>
Co-authored-by: Bernardo Sunderhus <bernardo.sunderhus@gmail.com>
Co-authored-by: ling1726 <lingfangao@hotmail.com>
  • Loading branch information
5 people authored Jul 15, 2021
1 parent dbb070e commit 6d75fc2
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/react-text/etc/react-text.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ const body: MakeStylesStyleFunctionRule<Theme>;
// @public
const caption: MakeStylesStyleFunctionRule<Theme>;

// @public
export const Display: React_2.ForwardRefExoticComponent<DisplayProps & React_2.RefAttributes<HTMLElement>>;

// @public (undocumented)
const display: MakeStylesStyleFunctionRule<Theme>;

// @public
export interface DisplayProps extends Omit<TextProps, 'font' | 'size'> {
}

// @public (undocumented)
const headline: MakeStylesStyleFunctionRule<Theme>;

Expand Down
1 change: 1 addition & 0 deletions packages/react-text/src/Display.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/Display/index';
82 changes: 82 additions & 0 deletions packages/react-text/src/Text.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { makeStyles } from '@fluentui/react-make-styles';
import * as React from 'react';
import { Text, TextProps } from './Text';

const useStyles = makeStyles({
container: {
width: '100px',
},
});

export const TextStory = (props: TextProps) => {
const styles = useStyles();
return (
<div className={styles.container}>
<Text {...props}>This is an example of the Text component's usage.</Text>
</div>
);
};

TextStory.argTypes = {
wrap: {
defaultValue: true,
control: 'boolean',
},
truncate: {
defaultValue: false,
control: 'boolean',
},
underline: {
defaultValue: false,
control: 'boolean',
},
block: {
defaultValue: false,
control: 'boolean',
},
italic: {
defaultValue: false,
control: 'boolean',
},
strikethrough: {
defaultValue: false,
control: 'boolean',
},
size: {
defaultValue: 300,
type: { name: 'number', required: false },
control: {
type: 'select',
options: [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],
},
},
font: {
defaultValue: 'base',
type: { name: 'string', required: false },
control: {
type: 'select',
options: ['base', 'monospace', 'numeric'],
},
},
weight: {
defaultValue: 'regular',
type: { name: 'string', required: false },
control: {
type: 'select',
options: ['regular', 'medium', 'semibold'],
},
},
align: {
defaultValue: 'start',
type: { name: 'string', required: false },
control: {
type: 'select',
options: ['start', 'center', 'end', 'justify'],
},
},
};

export default {
title: 'Components/Text',
component: Text,
};
9 changes: 9 additions & 0 deletions packages/react-text/src/TextWrappers.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Display } from './components/Display';
import { FluentProvider } from '@fluentui/react-provider';
import { webLightTheme } from '@fluentui/react-theme';

<Meta title="Components/Text/Wrappers" />

<FluentProvider theme={webLightTheme}>
<Display block>Display text wrapper, semibold, base1000</Display>
</FluentProvider>
16 changes: 16 additions & 0 deletions packages/react-text/src/components/Display/Display.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react';
import { render } from '@testing-library/react';
import { Display } from './Display';
import { isConformant } from '../../common/isConformant';

describe('Display', () => {
isConformant({
Component: Display,
displayName: 'Display',
});

it('renders a default state', () => {
const result = render(<Display>Default Display</Display>);
expect(result.container).toMatchSnapshot();
});
});
27 changes: 27 additions & 0 deletions packages/react-text/src/components/Display/Display.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import { makeStyles, mergeClasses } from '@fluentui/react-make-styles';
import { renderText, useText, useTextStyles } from '../Text/index';
import { typographyStyles } from '../../typographyStyles/index';
import { DisplayProps } from './Display.types';

/**
* Styles for the root slot
*/
const useStyles = makeStyles({
root: typographyStyles.display,
});

/**
* Text wrapper component for the Display typography variant
*/
export const Display = React.forwardRef<HTMLElement, DisplayProps>((props, ref) => {
const styles = useStyles();
const state = useText(props, ref);
useTextStyles(state);

state.className = mergeClasses(state.className, styles.root, props.className);

return renderText(state);
});

Display.displayName = 'Display';
6 changes: 6 additions & 0 deletions packages/react-text/src/components/Display/Display.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { TextProps } from '../Text/index';

/**
* Display Props
*/
export interface DisplayProps extends Omit<TextProps, 'font' | 'size'> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Display renders a default state 1`] = `
<div>
<span
class=""
>
Default Display
</span>
</div>
`;
2 changes: 2 additions & 0 deletions packages/react-text/src/components/Display/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Display';
export * from './Display.types';
1 change: 1 addition & 0 deletions packages/react-text/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './Text';
export * from './typographyStyles';
export * from './Display';

0 comments on commit 6d75fc2

Please sign in to comment.