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

feat(react): add Typography component #14

Merged
merged 3 commits into from
Feb 13, 2023
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 @@ -3,26 +3,26 @@ import StoryConfig from '../../story-config.ts';
import defaultTheme from '../../../src/theme/default-theme';

export const meta = {
title: StoryConfig.Typography.hierarchy,
title: StoryConfig.Typeset.hierarchy,
};

export const SampleText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';

<Meta title={meta.title} />

# Typography
# Typeset

- [Overview](#overview)
- [Headings](#headings)

## Overview

Typography works by principle of accessibility before aesthetics. The text should be readable and help the user
Typeset works by principle of accessibility before aesthetics. The text should be readable and help the user
understand what’s important by well contrasted size and colors hierarchy.

## Headings

Typography component used to create various levels of hierarchies between text.
`Typography` component from the library is used to create various levels of hierarchies between text.

### H1

Expand Down
6 changes: 5 additions & 1 deletion packages/react/.storybook/story-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type Stories =
| 'SignIn'
| 'TextField'
| 'Tooltip'
| 'Typeset'
| 'Typography'
| 'Welcome';
export type StorybookConfig = Record<
Expand Down Expand Up @@ -121,8 +122,11 @@ const StoryConfig: StorybookConfig = {
Tooltip: {
hierarchy: `${StorybookCategories.DataDisplay}/Tooltip`,
},
Typeset: {
hierarchy: `${StorybookCategories.Foundations}/Typeset`,
},
Typography: {
hierarchy: `${StorybookCategories.Foundations}/Typography`,
hierarchy: `${StorybookCategories.DataDisplay}/Typography`,
},
Welcome: {
hierarchy: 'Welcome',
Expand Down
52 changes: 52 additions & 0 deletions packages/react/src/components/Typography/Typography.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {ArgsTable, Source, Story, Canvas, Meta} from '@storybook/addon-docs';
import dedent from 'ts-dedent';
import StoryConfig from '../../../.storybook/story-config.ts';
import Typography from './Typography.tsx';

export const meta = {
component: Typography,
title: StoryConfig.Typography.hierarchy,
};

<Meta title={meta.title} component={meta.component} />

export const Template = args => <Typography {...args} />;

# Typography

- [Overview](#overview)
- [Props](#props)
- [Usage](#usage)

## Overview

Use typography to present your design and content as clearly and efficiently as possible.

<Canvas>
<Story name="Overview" args={{children: 'Sample Text'}}>
{Template.bind({})}
</Story>
</Canvas>

## Props

<ArgsTable story="Overview" />

## Usage

Import and use the `Typography` component in your components as follows.

<Source
language="jsx"
dark
format
code={dedent`
import Typography from '@oxygen-ui/react/Typography';\n
function Demo() {
return (
<Typography>
Sample Text
</Typography>
);
}`}
/>
41 changes: 41 additions & 0 deletions packages/react/src/components/Typography/Typography.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import MuiTypography, {TypographyProps as MuiTypographyProps} from '@mui/material/Typography';
import clsx from 'clsx';
import {FC, ReactElement} from 'react';
import {WithWrapperProps} from '../../models';
import {composeComponentDisplayName} from '../../utils';

export type TypographyProps = MuiTypographyProps;

const COMPONENT_NAME: string = 'Typography';

const Typography: FC<TypographyProps> & WithWrapperProps = (props: TypographyProps): ReactElement => {
const {className, ...rest} = props;

const classes: string = clsx('oxygen-typography', className);

return <MuiTypography className={classes} {...rest} />;
};

Typography.displayName = composeComponentDisplayName(COMPONENT_NAME);
Typography.muiName = COMPONENT_NAME;
Typography.defaultProps = {};

export default Typography;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import {render} from '@unit-testing';
import Typography from '../Typography';

describe('Typography', () => {
it('should render successfully', () => {
const {baseElement} = render(<Typography>Sample Text</Typography>);
expect(baseElement).toBeTruthy();
});

it('should match the snapshot', () => {
const {baseElement} = render(<Typography>Sample Text</Typography>);
expect(baseElement).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Typography should match the snapshot 1`] = `
<body>
<div>
<p
class="MuiTypography-root MuiTypography-body1 oxygen-typography css-okvhak-MuiTypography-root"
>
Sample Text
</p>
</div>
</body>
`;
20 changes: 20 additions & 0 deletions packages/react/src/components/Typography/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export {default} from './Typography';
export type {TypographyProps} from './Typography';
19 changes: 19 additions & 0 deletions packages/react/src/components/Typography/typography.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

.oxygen-typography {}