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

Typography component #17

Merged
merged 2 commits into from
Feb 1, 2024
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
3 changes: 1 addition & 2 deletions apps/frontend/src/components/Header/Header.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Meta, StoryObj } from '@storybook/react';
import { Header } from './Header';

const meta = {
title: 'Example/Header',
title: 'Header',
component: Header,
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
Expand All @@ -16,5 +16,4 @@ const meta = {
export default meta;
type Story = StoryObj<typeof meta>;


export const DefaultHeader: Story = {};
46 changes: 46 additions & 0 deletions apps/frontend/src/components/Typography/Heading.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Meta, StoryObj } from '@storybook/react';

import { Heading } from './Typography';

const meta = {
title: 'Heading',
component: Heading,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
} satisfies Meta<typeof Heading>;

export default meta;
type Story = StoryObj<typeof meta>;

export const H1: Story = {
args: {
level: 'h1',
children: 'Heading h1',
},
};
export const H2: Story = {
args: {
level: 'h2',
children: 'Heading h2',
},
};
export const H3: Story = {
args: {
level: 'h3',
children: 'Heading h3',
},
};
export const H4: Story = {
args: {
level: 'h4',
children: 'Heading h4',
},
};
export const H5: Story = {
args: {
level: 'h5',
children: 'Heading h5',
},
};
22 changes: 22 additions & 0 deletions apps/frontend/src/components/Typography/Text.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Meta, StoryObj } from '@storybook/react';

import { Text } from './Typography';

const meta = {
title: 'Text',
component: Text,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
} satisfies Meta<typeof Text>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Paragraphs: Story = {
args: {
children:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean dapibus vehicula tincidunt. Mauris vel dui purus. Vestibulum ultricies egestas scelerisque. Proin venenatis consequat pellentesque. Nunc porttitor vestibulum velit. Nunc nec eros sit amet nibh luctus mattis. Nulla facilisi. Aenean euismod purus mi, et tincidunt velit auctor vitae',
},
};
51 changes: 51 additions & 0 deletions apps/frontend/src/components/Typography/Typography.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import clsx from 'clsx';

export interface HeadingProps {
level: 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
children: React.ReactNode;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The property children refers multiple elements but it can be defined as text and the type can be string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But I'm thinking that if we need to add, for example, a span tag around some of the text for whatever reason, this can be done. Plus it simulates the original heading and paragraph tags

<Heading level="h1">Some <span className="color-red">text</span></Heading>

}
const common = 'font-gellix';
const h1 = 'text-6xl font-semibold leading-[4.25rem]';
const h2 = 'text-5xl font-semibold leading-[3.5rem]';
const h3 = 'text-4xl font-semibold leading-[2.75rem]';
const h4 = 'text-3xl font-light';
const h5 = 'text-2xl';

export const Heading = ({ level, children }: HeadingProps) => {
const Tag = level;

return (
<Tag
className={clsx(common, {
[h1]: level === 'h1',
[h2]: level === 'h2',
[h3]: level === 'h3',
[h4]: level === 'h4',
[h5]: level === 'h5',
})}
>
{children}
</Tag>
);
};

export interface TextProps {
size?: 'default' | 'small' | 'tiny';
weight?: 'regular' | 'bold';
children: React.ReactNode;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

}

export const Text = ({ size = 'default', weight = 'regular', children }: TextProps) => {
return (
<p
className={clsx(common, {
'font-semibold': weight === 'bold',
'text-xl leading-6': size === 'default',
'text-sm leading-5': size === 'small',
'text-xs leading-4': size === 'tiny',
})}
>
{children}
</p>
);
};