Skip to content

Commit

Permalink
feat(core-components-typography): add responsive title (#362)
Browse files Browse the repository at this point in the history
* style(core-components-typography): rename to lower case

* feat(core-components-typography): add title responsive

* docs(core-components-typography): add todo

* feat(core-components-typography): add styles
  • Loading branch information
dmitrsavk committed Nov 25, 2020
1 parent 9ca6024 commit d3af0cd
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/amount/src/component.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Container, Row, Col } from 'storybook/blocks/grid';
import { ComponentHeader } from 'storybook/blocks/component-header';

import { Amount } from '.';
import { Typography } from '../../typography/src/Component';
import { Typography } from '../../typography/src';
import { getAllCurrencyCodes } from '@alfalab/utils';
import { name, version } from '../package.json';

Expand Down
10 changes: 0 additions & 10 deletions packages/typography/src/Component.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Meta, Story, Props, Preview } from '@storybook/addon-docs/blocks';
import { text, boolean, select, number } from '@storybook/addon-knobs';
import { ComponentHeader } from 'storybook/blocks/component-header';

import { Typography } from './Component';
import { Typography } from './component';
import { name, version } from '../package.json';
import { colors } from './colors';

Expand Down Expand Up @@ -32,6 +32,26 @@ import { colors } from './colors';
})}
</Story>

<Story name='Typography.TitleResponsive'>
{React.createElement(() => {
const VIEW_TYPES = [
'xlarge',
'large',
'medium',
'small',
'xsmall',
];
const color = select('color', colors, '');
const weight = select('weight', ['regular', 'medium', 'bold'], 'medium');
const font = select('font', ['styrene', 'system'], 'styrene');
return VIEW_TYPES.map(view => (
<Typography.TitleResponsive view={view} color={color} weight={weight} font={font} key={view}>
заголовок view='{view}'
</Typography.TitleResponsive>
))
})}
</Story>

<Story name='Typography.Text'>
{React.createElement(() => {
const VIEW_TYPES = [
Expand Down Expand Up @@ -110,6 +130,31 @@ import { Typography } from '@alfalab/core-components-typography';
})}
</Preview>

## Typography.TitleResponsive

<Typography.TitleResponsive>Адаптивный заголовок для шрифта styrene</Typography.TitleResponsive>
<Typography.TitleResponsive font='system'>Адаптивный заголовок для шрифта system</Typography.TitleResponsive>

<Preview>
{React.createElement(() => {
const VIEW_TYPES = [
'xlarge',
'large',
'medium',
'small',
'xsmall',
];
const color = select('color', colors, '');
const weight = select('weight', ['regular', 'medium', 'bold'], 'medium');
const font = select('font', ['styrene', 'system'], 'styrene');
return VIEW_TYPES.map(view => (
<Typography.TitleResponsive view={view} color={color} weight={weight} font={font} key={view}>
заголовок view='{view}'
</Typography.TitleResponsive>
))
})}
</Preview>

## Typography.Text

Компонент для оформления текста. Позволяет задать внешний вид, тэг и цвет текста.
Expand Down
15 changes: 15 additions & 0 deletions packages/typography/src/component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { FC } from 'react';

import { Title, TitleProps } from './title';
import { Text, TextProps } from './text';
import { TitleResponsive } from './title-responsive';

export const Typography: {
Title: FC<TitleProps>;
Text: FC<TextProps>;
TitleResponsive: FC<TitleProps>;
} = {
Title,
Text,
TitleResponsive,
};
2 changes: 1 addition & 1 deletion packages/typography/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './Component';
export * from './component';
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/typography/src/text/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './Component';
export * from './component';
14 changes: 14 additions & 0 deletions packages/typography/src/title-responsive/component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, { FC } from 'react';

import { TitleProps, Title } from '../title/component';

import styles from './index.module.css';
import commonStyles from '../title/common.module.css';

export const TitleResponsive: FC<TitleProps> = props => {
/**
* Если поменять Object.assign на деструктуризацию, то упадут тесты.
* Видимо, это особенность работы jest и css-modules.
*/
return <Title {...props} styles={Object.assign(styles, commonStyles)} />;
};
127 changes: 127 additions & 0 deletions packages/typography/src/title-responsive/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
@import '../../../themes/src/default.css';

/* TODO: поменять медиа-запросы на миксины */

.styrene-xlarge {
@mixin headline_medium;
}

.styrene-large {
@mixin headline_small;
}

.styrene-medium {
@mixin headline_xsmall;
}

.styrene-small {
@mixin headline_xsmall;
}

.styrene-xsmall {
@mixin headline_xsmall;
}

.system-xlarge {
@mixin headline-system_medium;
}

.system-large {
@mixin headline-system_small;
}

.system-medium {
@mixin headline-system_xsmall;
}

.system-small {
@mixin headline-system_xsmall;
}

.system-xsmall {
@mixin headline-system_xsmall;
}

@media screen and (min-width: 600px) {
.styrene-xlarge {
@mixin headline_large;
}

.styrene-large {
@mixin headline_medium;
}

.styrene-medium {
@mixin headline_small;
}

.styrene-small {
@mixin headline_small;
}

.styrene-xsmall {
@mixin headline_xsmall;
}

.system-xlarge {
@mixin headline-system_large;
}

.system-large {
@mixin headline-system_medium;
}

.system-medium {
@mixin headline-system_small;
}

.system-small {
@mixin headline-system_small;
}

.system-xsmall {
@mixin headline-system_xsmall;
}
}

@media screen and (min-width: 1024px) {
.styrene-xlarge {
@mixin headline_xlarge;
}

.styrene-large {
@mixin headline_large;
}

.styrene-medium {
@mixin headline_medium;
}

.styrene-small {
@mixin headline_small;
}

.styrene-xsmall {
@mixin headline_xsmall;
}

.system-xlarge {
@mixin headline-system_xlarge;
}

.system-large {
@mixin headline-system_large;
}

.system-medium {
@mixin headline-system_medium;
}

.system-small {
@mixin headline-system_small;
}

.system-xsmall {
@mixin headline-system_xsmall;
}
}
1 change: 1 addition & 0 deletions packages/typography/src/title-responsive/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './component';
16 changes: 16 additions & 0 deletions packages/typography/src/title/common.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.component {
margin: 0;
padding: 0;
}

.bold {
font-weight: bold;
}

.medium {
font-weight: 500;
}

.regular {
font-weight: normal;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import cn from 'classnames';
import React from 'react';
import { Color } from '../colors';

import styles from './index.module.css';
import colors from '../colors.module.css';

export type TitleProps = {
Expand Down Expand Up @@ -47,7 +46,13 @@ export type TitleProps = {
children?: React.ReactNode;
};

export const Title: React.FC<TitleProps> = ({
type Styles = {
styles: {
[key: string]: string;
};
};

export const Title: React.FC<TitleProps & Styles> = ({
tag: Component = 'div',
view = 'medium',
font = 'styrene',
Expand All @@ -56,7 +61,8 @@ export const Title: React.FC<TitleProps> = ({
className,
dataTestId,
children,
}: TitleProps): React.ReactElement => (
styles,
}) => (
<Component
className={cn(
styles.component,
Expand Down
17 changes: 0 additions & 17 deletions packages/typography/src/title/index.module.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
@import '../../../themes/src/default.css';

.component {
margin: 0;
padding: 0;
}

.styrene-xlarge {
@mixin headline_xlarge;
}
Expand Down Expand Up @@ -44,15 +39,3 @@
.system-xsmall {
@mixin headline-system_xsmall;
}

.bold {
font-weight: bold;
}

.medium {
font-weight: 500;
}

.regular {
font-weight: normal;
}
1 change: 0 additions & 1 deletion packages/typography/src/title/index.ts

This file was deleted.

16 changes: 16 additions & 0 deletions packages/typography/src/title/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { FC } from 'react';

import { Title as TitleBase, TitleProps } from './component';

import styles from './index.module.css';
import commonStyles from './common.module.css';

const Title: FC<TitleProps> = props => {
/**
* Если поменять Object.assign на деструктуризацию, то упадут тесты.
* Видимо, это особенность работы jest и css-modules.
*/
return <TitleBase {...props} styles={Object.assign(styles, commonStyles)} />;
};

export { Title, TitleProps };

0 comments on commit d3af0cd

Please sign in to comment.