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

#54/create text UI component #85

Merged
merged 11 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1,004 changes: 543 additions & 461 deletions webapp/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
"@types/node": "^16.11.41",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"@types/react-test-renderer": "^18.0.0",
"eslint": "^8.18.0",
"prettier": "2.7.1",
"react-scripts": "^5.0.1",
"react-test-renderer": "^18.2.0",
"typescript": "^4.7.4"
}
}
2 changes: 1 addition & 1 deletion webapp/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ body {
}

.text-style-1-bold {
font-size: 3rem;
font-size: 2.5rem;
font-family: 'DM Sans', sans-serif;
font-weight: 700;
}
Expand Down
19 changes: 16 additions & 3 deletions webapp/src/pages/Landing/Landing.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Icon, IconSize, IconType } from '../../shared/components';
import {
Icon,
IconSize,
IconType,
Text,
TextSize,
TextWeight,
} from '../../shared/components';
import { Color } from '../../shared/types';
import './Landing.css';

Expand All @@ -7,10 +14,16 @@ export default function Landing() {
<section className="Landing">
<Icon
type={IconType.PLAY}
color={Color.LIGHT}
color={Color.ONLINE}
size={IconSize.LARGE}
></Icon>
<h1 className="text-style-0-bold">Landing 🚀</h1>
<Text
size={TextSize.LARGE}
gbudau marked this conversation as resolved.
Show resolved Hide resolved
color={Color.ONLINE}
weight={TextWeight.MEDIUM}
>
Landing 🚀
</Text>
</section>
);
}
37 changes: 37 additions & 0 deletions webapp/src/shared/components/Text/Text.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Color } from '../../types';

export enum TextSize {
EXTRA_SMALL = '0.75rem',
SMALL = '0.875rem',
SMALL_MEDIUM = '1rem',
MEDIUM = '1.25rem',
MEDIUM_LARGE = '1.5rem',
LARGE = '2.5rem',
EXTRA_LARGE = '3rem',
}

export enum TextWeight {
REGULAR = '400',
MEDIUM = '500',
BOLD = '700',
}

type TextProps = {
children: string;
size?: TextSize;
color?: Color;
weight?: TextWeight;
};

export default function Text({
size = TextSize.MEDIUM,
color = Color.DARK,
weight = TextWeight.REGULAR,
children,
}: TextProps) {
return (
<div style={{ fontSize: size, color: `var(${color})`, fontWeight: weight }}>
{children}
</div>
gbudau marked this conversation as resolved.
Show resolved Hide resolved
);
}
48 changes: 48 additions & 0 deletions webapp/src/shared/components/Text/__tests__/Text.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { render, screen } from '@testing-library/react';
import { create } from 'react-test-renderer';
import { Color } from '../../../types';
import Text, { TextSize, TextWeight } from '../Text';

test('renders default text', () => {
render(<Text>Hello World!</Text>);

const textElement = screen.getByText(/hello world!/i);
expect(textElement).toBeInTheDocument();
expect(textElement).toHaveStyle({
fontSize: TextSize.MEDIUM,
fontWeight: TextWeight.REGULAR,
gbudau marked this conversation as resolved.
Show resolved Hide resolved
});
});

test('renders custom text', () => {
render(
<Text size={TextSize.EXTRA_LARGE} weight={TextWeight.BOLD}>
Hello World!
</Text>,
);

const textElement = screen.getByText(/hello world!/i);
expect(textElement).toBeInTheDocument();
expect(textElement).toHaveStyle({
fontSize: TextSize.EXTRA_LARGE,
fontWeight: TextWeight.BOLD,
});
});

test('renders correctly with default text', () => {
const tree = create(<Text>Hello World!</Text>).toJSON();
expect(tree).toMatchSnapshot();
});

test('renders correctly with custom text', () => {
const tree = create(
<Text
size={TextSize.EXTRA_LARGE}
color={Color.LIGHT}
weight={TextWeight.BOLD}
>
Hello World!
</Text>,
).toJSON();
expect(tree).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly with custom text 1`] = `
<div
style={
Object {
"color": "var(--color-light)",
"fontSize": "3rem",
"fontWeight": "700",
}
}
>
Hello World!
</div>
`;

exports[`renders correctly with default text 1`] = `
<div
style={
Object {
"color": "var(--color-dark)",
"fontSize": "1.25rem",
"fontWeight": "400",
}
}
>
Hello World!
</div>
`;
2 changes: 2 additions & 0 deletions webapp/src/shared/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { default as Icon } from './Icon/Icon';
export * from './Icon/Icon';
export { default as Text } from './Text/Text';
export * from './Text/Text';