/
Typeset.tsx
71 lines (64 loc) · 1.73 KB
/
Typeset.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React, { FunctionComponent } from 'react';
import { styled } from '@storybook/theming';
import { transparentize } from 'polished';
import { withReset } from '../typography/shared';
import { getBlockBackgroundStyle } from './BlockBackgroundStyles';
const Label = styled.div<{}>(({ theme }) => ({
marginRight: 30,
fontSize: `${theme.typography.size.s1}px`,
color:
theme.base === 'light'
? transparentize(0.4, theme.color.defaultText)
: transparentize(0.6, theme.color.defaultText),
}));
const Sample = styled.div({
overflow: 'hidden',
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
});
const TypeSpecimen = styled.div({
display: 'flex',
flexDirection: 'row',
alignItems: 'baseline',
'&:not(:last-child)': { marginBottom: '1rem' },
});
const Wrapper = styled.div<{}>(withReset, ({ theme }) => ({
...getBlockBackgroundStyle(theme),
margin: '25px 0 40px',
padding: '30px 20px',
}));
export interface TypesetProps {
fontFamily?: string;
fontSizes: string[];
fontWeight?: number;
sampleText?: string;
}
/**
* Convenient styleguide documentation showing examples of type
* with different sizes and weights and configurable sample text.
*/
export const Typeset: FunctionComponent<TypesetProps> = ({
fontFamily,
fontSizes,
fontWeight,
sampleText,
...props
}) => (
<Wrapper {...props} className="docblock-typeset">
{fontSizes.map((size) => (
<TypeSpecimen key={size}>
<Label>{size}</Label>
<Sample
style={{
fontFamily,
fontSize: size,
fontWeight,
lineHeight: size,
}}
>
{sampleText || 'Was he a beast if music could move him so?'}
</Sample>
</TypeSpecimen>
))}
</Wrapper>
);