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: add high density typography scale #2646

Merged
merged 21 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
928c6df
feat(tokens): add `font-size-xs`
cf-remylenoir Jan 9, 2024
7b6c637
feat(tokens): add high-density values
cf-remylenoir Jan 11, 2024
c5b4f32
Merge branch 'main' into feat/high-density-typography-scale
cf-remylenoir Jan 11, 2024
17c1b8c
chore(typography): add dependency
cf-remylenoir Jan 11, 2024
6f02f17
feat(heading): add high-density support
cf-remylenoir Jan 11, 2024
255cea1
feat(paragraph): add high-density support
cf-remylenoir Jan 11, 2024
ed5918f
feat(section-heading): add high-density support
cf-remylenoir Jan 11, 2024
950f89f
feat(subheading): add high-density support
cf-remylenoir Jan 11, 2024
19fb16c
feat(caption): add high-density support
cf-remylenoir Jan 11, 2024
ac833f1
chore(): reorganize story
cf-remylenoir Jan 11, 2024
1e0a647
Merge branch 'main' into feat/high-density-typography-scale
cf-remylenoir Jan 12, 2024
cda8d99
feat(tokens): add high-density values
cf-remylenoir Jan 12, 2024
d9a4b3c
feat(caption): add line-height high-density support
cf-remylenoir Jan 12, 2024
1c1c7c7
feat(heading): add line-height high-density support
cf-remylenoir Jan 12, 2024
ef79fd5
feat(paragraph): add line-height high-density support
cf-remylenoir Jan 12, 2024
4775455
feat(subheading): add line-height high-density support
cf-remylenoir Jan 12, 2024
476812b
chore(section-heading): update story
cf-remylenoir Jan 12, 2024
0f1c043
feat(section-heading): add line-height high-density support
cf-remylenoir Jan 12, 2024
da138a3
chore: add changelog
cf-remylenoir Jan 12, 2024
65e1b5a
chore: update changelog
cf-remylenoir Jan 12, 2024
221d970
feat(forms): replace tokens with high-density ones
cf-remylenoir Jan 12, 2024
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
577 changes: 319 additions & 258 deletions package-lock.json
stephanLeece marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is because the Heading component (L142-144) used to differentiate the two examples was getting smaller (working as intended hehe) as it was part of the DensityContainer with the high value. I moved it outside of the DensityContainer so it stays the same size.

Original file line number Diff line number Diff line change
Expand Up @@ -134,44 +134,45 @@ export const Overview: Story<DensityContainerProps> = ({
{Densities.map((density) => {
return (
<Box key={density.name}>
<DensityContainer
key={density.name}
density={density.density as Density}
{...args}
>
<>
<Heading as="h2" marginBottom="spacingXs">
{density.name}
</Heading>

{Components.map((Component) => {
return (
<Box
key={Component.name}
marginBottom="spacingL"
style={{ minHeight: '100px' }}
>
<Text>{Component.name}</Text>

<DensityContainer
key={density.name}
density={density.density as Density}
{...args}
>
{Components.map((Component) => {
return (
<Box
marginTop="spacingS"
style={{
backgroundColor: tokens.gray200,
padding: tokens.spacingS,
borderRadius: tokens.borderRadiusMedium,
}}
key={Component.name}
marginBottom="spacingL"
style={{ minHeight: '100px' }}
>
<Flex gap="spacingS" alignItems="end">
{Component.props.map((props, index) => {
return (
<Component.component key={index} {...props} />
);
})}
</Flex>
<Text>{Component.name}</Text>

<Box
marginTop="spacingS"
style={{
backgroundColor: tokens.gray200,
padding: tokens.spacingS,
borderRadius: tokens.borderRadiusMedium,
}}
>
<Flex gap="spacingS" alignItems="end">
{Component.props.map((props, index) => {
return (
<Component.component key={index} {...props} />
);
})}
</Flex>
</Box>
</Box>
</Box>
);
})}
</DensityContainer>
);
})}
</DensityContainer>
</>
</Box>
);
})}
Expand Down
1 change: 1 addition & 0 deletions packages/components/typography/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"@contentful/f36-core": "^4.58.0",
"@contentful/f36-tokens": "^4.0.3",
"@contentful/f36-utils": "^4.24.2",
"emotion": "^10.0.17"
},
"peerDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion packages/components/typography/src/Caption/Caption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
ExpandProps,
} from '@contentful/f36-core';
import { Text } from '../Text';
import { useDensity } from '@contentful/f36-utils';

const CAPTION_DEFAULT_TAG = 'span';

Expand All @@ -34,11 +35,13 @@ function _Caption<E extends React.ElementType = typeof CAPTION_DEFAULT_TAG>(
}: CaptionProps<E>,
ref: React.Ref<any>,
) {
const density = useDensity();

return (
<Text
as={CAPTION_DEFAULT_TAG}
testId={testId}
fontSize="fontSizeS"
fontSize={density === 'high' ? 'fontSizeSHigh' : 'fontSizeS'}
lineHeight="lineHeightS"
fontColor="gray900"
fontWeight={fontWeight}
Expand Down
4 changes: 4 additions & 0 deletions packages/components/typography/src/Caption/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ We provide you with `as` property, to allow you to set the tag of the `Caption`
## Props (API reference)

<PropsTable of="Caption" />

## Density support

This component supports multiple densities thanks to the [useDensity](/hooks/use-density) hook and automatically adjusts its styling for each density when wrapped with the [Density Container](/components/density-container).
5 changes: 4 additions & 1 deletion packages/components/typography/src/Heading/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ExpandProps,
} from '@contentful/f36-core';
import { Text } from '../Text';
import { useDensity } from '@contentful/f36-utils';

const HEADING_DEFAULT_TAG = 'h1';

Expand All @@ -27,14 +28,16 @@ function _Heading<E extends React.ElementType = typeof HEADING_DEFAULT_TAG>(
{ children, testId = 'cf-ui-heading', ...otherProps }: HeadingProps<E>,
ref: React.Ref<any>,
) {
const density = useDensity();

return (
<Text
as={HEADING_DEFAULT_TAG}
testId={testId}
marginBottom="spacingM"
fontWeight="fontWeightDemiBold"
fontColor="gray900"
fontSize="fontSizeXl"
fontSize={density === 'high' ? 'fontSizeXlHigh' : 'fontSizeXl'}
lineHeight="lineHeightXl"
{...otherProps}
ref={ref}
Expand Down
4 changes: 4 additions & 0 deletions packages/components/typography/src/Heading/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ Sometimes you might have to truncate the text in the `Heading` component, so we
## Props (API reference)

<PropsTable of="Heading" />

## Density support

This component supports multiple densities thanks to the [useDensity](/hooks/use-density) hook and automatically adjusts its styling for each density when wrapped with the [Density Container](/components/density-container).
4 changes: 4 additions & 0 deletions packages/components/typography/src/Paragraph/Paragraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
ExpandProps,
} from '@contentful/f36-core';
import { Text } from '../Text';
import { useDensity } from '@contentful/f36-utils';

export type ParagraphInternalProps = CommonProps &
MarginProps & {
Expand All @@ -20,10 +21,13 @@ export const Paragraph = React.forwardRef<
HTMLParagraphElement,
ExpandProps<ParagraphProps>
>(({ children, testId = 'cf-ui-paragraph', ...otherProps }, ref) => {
const density = useDensity();

return (
<Text
as="p"
testId={testId}
fontSize={density === 'high' ? 'fontSizeMHigh' : 'fontSizeM'}
marginBottom="spacingM"
lineHeight="lineHeightM"
{...otherProps}
Expand Down
4 changes: 4 additions & 0 deletions packages/components/typography/src/Paragraph/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ Sometimes you might have to truncate the text in the `Paragraph` component, so w
## Props (API reference)

<PropsTable of="Paragraph" />

## Density support

This component supports multiple densities thanks to the [useDensity](/hooks/use-density) hook and automatically adjusts its styling for each density when wrapped with the [Density Container](/components/density-container).
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ Sometimes you might have to truncate the text in the `SectionHeading` component,
## Props (API reference)

<PropsTable of="SectionHeading" />

## Density support

This component supports multiple densities thanks to the [useDensity](/hooks/use-density) hook and automatically adjusts its styling for each density when wrapped with the [Density Container](/components/density-container).
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
} from '@contentful/f36-core';
import type { HeadingElement } from '../Heading';
import { Text } from '../Text';
import { useDensity } from '@contentful/f36-utils';

const SECTION_HEADING_DEFAULT_TAG = 'h2';

Expand All @@ -35,14 +36,16 @@ function _SectionHeading<
}: SectionHeadingProps<E>,
ref: React.Ref<any>,
) {
const density = useDensity();

return (
<Text
as={SECTION_HEADING_DEFAULT_TAG}
testId={testId}
marginBottom="spacingL"
fontWeight="fontWeightDemiBold"
fontColor="gray900"
fontSize="fontSizeS"
fontSize={density === 'high' ? 'fontSizeSHigh' : 'fontSizeS'}
lineHeight="lineHeightS"
cf-remylenoir marked this conversation as resolved.
Show resolved Hide resolved
className={cx(
css({
Expand Down
4 changes: 4 additions & 0 deletions packages/components/typography/src/Subheading/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ Sometimes you might have to truncate the text in the `Subheading` component, so
## Props (API reference)

<PropsTable of="Subheading" />

## Density support

This component supports multiple densities thanks to the [useDensity](/hooks/use-density) hook and automatically adjusts its styling for each density when wrapped with the [Density Container](/components/density-container).
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
} from '@contentful/f36-core';
import type { HeadingElement } from '../Heading';
import { Text } from '../Text';
import { useDensity } from '@contentful/f36-utils';

const SUBHEADING_DEFAULT_TAG = 'h3';

Expand All @@ -28,12 +29,14 @@ function _Subheading<
{ children, testId = 'cf-ui-subheading', ...otherProps }: SubheadingProps<E>,
ref: React.Ref<any>,
) {
const density = useDensity();

return (
<Text
as={SUBHEADING_DEFAULT_TAG}
testId={testId}
marginBottom="spacingM"
fontSize="fontSizeL"
fontSize={density === 'high' ? 'fontSizeLHigh' : 'fontSizeL'}
lineHeight="lineHeightL"
fontWeight="fontWeightDemiBold"
fontColor="gray900"
Expand Down
35 changes: 35 additions & 0 deletions packages/components/typography/stories/Caption.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import { Flex } from '@contentful/f36-core';
import type { Density } from '@contentful/f36-utils';
import { Heading } from '@contentful/f36-typography';

import { DensityContainer } from '../../density-container';
import { Caption, CaptionProps } from '../src/Caption/Caption';
import { Paragraph } from '../src/Paragraph/Paragraph';

Expand Down Expand Up @@ -38,3 +41,35 @@ export const Overview = (props: CaptionProps) => (
Overview.args = {
children: 'Caption',
};

export const WithDensitySupport = (props: CaptionProps) => {
const Densities = [
{
name: 'Low density',
density: 'low',
},
{
name: 'High density',
density: 'high',
},
];

return (
<Flex flexDirection="column" gap="spacingS">
{Densities.map((density) => {
return (
<Flex key={density.name} flexDirection="column">
<Heading>{density.name}</Heading>
<DensityContainer density={density.density as Density}>
<Caption {...props} />
</DensityContainer>
</Flex>
);
})}
</Flex>
);
};

WithDensitySupport.args = {
children: 'The brown fox jumps over the lazy dog',
};
36 changes: 36 additions & 0 deletions packages/components/typography/stories/Heading.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from 'react';
import type { Density } from '@contentful/f36-utils';
import { Flex } from '@contentful/f36-core';
import { Heading, HeadingProps } from '../src/Heading/Heading';
import { DensityContainer } from '../../density-container/';

export default {
title: 'Typography/Heading',
Expand All @@ -18,3 +21,36 @@ Basic.args = {
children: 'Heading',
as: 'h1',
};

export const WithDensitySupport = (props: HeadingProps<'h1'>) => {
const Densities = [
{
name: 'Low density',
density: 'low',
},
{
name: 'High density',
density: 'high',
},
];

return (
<Flex flexDirection="column" gap="spacingS">
{Densities.map((density) => {
return (
<Flex key={density.name} flexDirection="column">
<Heading>{density.name}</Heading>
<DensityContainer density={density.density as Density}>
<Heading {...props} />
</DensityContainer>
</Flex>
);
})}
</Flex>
);
};

WithDensitySupport.args = {
children: 'The brown fox jumps over the lazy dog',
as: 'h1',
};
37 changes: 36 additions & 1 deletion packages/components/typography/stories/Paragraph.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';

import { Flex } from '@contentful/f36-core';
import { Heading } from '@contentful/f36-typography';
import type { Density } from '@contentful/f36-utils';
import { Paragraph, ParagraphProps } from '../src/Paragraph/Paragraph';
import { DensityContainer } from '../../density-container';

export default {
title: 'Typography/Paragraph',
Expand All @@ -18,3 +21,35 @@ export const Basic = (props: ParagraphProps) => <Paragraph {...props} />;
Basic.args = {
children: 'Paragraph',
};

export const WithDensitySupport = (props: ParagraphProps) => {
const Densities = [
{
name: 'Low density',
density: 'low',
},
{
name: 'High density',
density: 'high',
},
];

return (
<Flex flexDirection="column" gap="spacingS">
{Densities.map((density) => {
return (
<Flex key={density.name} flexDirection="column">
<Heading>{density.name}</Heading>
<DensityContainer density={density.density as Density}>
<Paragraph {...props} />
</DensityContainer>
</Flex>
);
})}
</Flex>
);
};

WithDensitySupport.args = {
children: 'The brown fox jumps over the lazy dog',
};
Loading
Loading