-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #54/Create text UI-component * Add tests for the Text component * Add snapshot tests for the Text * Rename barrel files to .ts instead of .tsx * Update webapp package.json Add test:coverage script to run coverage tests Update index.css Rename --color-game to --gradient-game Add --primary-font variable * Update Color enum Use CSS classes instead of variables Update TextColor enum: extend the Color enums Update Icon component, pass the color as a className
- Loading branch information
Showing
13 changed files
with
771 additions
and
503 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,30 @@ | ||
import { Icon, IconSize, IconType } from '../../shared/components'; | ||
import { | ||
Icon, | ||
IconSize, | ||
IconVariant, | ||
Text, | ||
TextColor, | ||
TextVariant, | ||
TextWeight, | ||
} from '../../shared/components'; | ||
import { Color } from '../../shared/types'; | ||
import './Landing.css'; | ||
|
||
export default function Landing() { | ||
return ( | ||
<section className="Landing"> | ||
<Icon | ||
type={IconType.PLAY} | ||
color={Color.LIGHT} | ||
variant={IconVariant.PLAY} | ||
color={Color.ONLINE} | ||
size={IconSize.LARGE} | ||
></Icon> | ||
<h1 className="text-style-0-bold">Landing 🚀</h1> | ||
<Text | ||
variant={TextVariant.TITLE} | ||
color={TextColor.GAME} | ||
weight={TextWeight.MEDIUM} | ||
> | ||
Landing 🚀 | ||
</Text> | ||
</section> | ||
); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.text-color-game { | ||
background: var(--gradient-game); | ||
background-clip: text; | ||
-webkit-background-clip: text; | ||
-webkit-text-fill-color: transparent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Color } from '../../types'; | ||
import './Text.css'; | ||
|
||
export class TextVariant { | ||
public static TITLE = new TextVariant('h1', '3rem'); | ||
public static SUBTITLE = new TextVariant('h2', '2.5rem'); | ||
public static HEADING = new TextVariant('h3', '1.5rem'); | ||
public static SUBHEADING = new TextVariant('h4', '1.25rem'); | ||
public static PARAGRAPH = new TextVariant('p', '1rem'); | ||
public static CAPTION = new TextVariant('p', '0.875rem'); | ||
|
||
private constructor(public tag: string, public size: string) {} | ||
} | ||
|
||
enum CustomTextColor { | ||
GAME = 'text-color-game', | ||
} | ||
|
||
type TextColor = Color | CustomTextColor; | ||
// eslint-disable-next-line @typescript-eslint/no-redeclare -- intentionally naming the variable the same as the type | ||
export const TextColor = { ...Color, ...CustomTextColor }; | ||
|
||
export enum TextWeight { | ||
REGULAR = '400', | ||
MEDIUM = '500', | ||
BOLD = '700', | ||
} | ||
|
||
type TextProps = { | ||
variant: TextVariant; | ||
color?: TextColor; | ||
weight?: TextWeight; | ||
children: string; | ||
}; | ||
|
||
export default function Text({ | ||
variant, | ||
color = TextColor.DARK, | ||
weight = TextWeight.REGULAR, | ||
children, | ||
}: TextProps) { | ||
const { tag, size } = variant; | ||
const TextTag = tag as React.ElementType; | ||
|
||
return ( | ||
<TextTag style={{ fontSize: size, fontWeight: weight }} className={color}> | ||
{children} | ||
</TextTag> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { create } from 'react-test-renderer'; | ||
import Text, { TextColor, TextVariant, TextWeight } from '../Text'; | ||
|
||
test('renders default text', () => { | ||
render(<Text variant={TextVariant.PARAGRAPH}>Hello World!</Text>); | ||
|
||
const textElement = screen.getByText(/hello world!/i); | ||
expect(textElement).toBeInTheDocument(); | ||
expect(textElement).toHaveStyle({ | ||
fontSize: TextVariant.PARAGRAPH.size, | ||
fontWeight: TextWeight.REGULAR, | ||
}); | ||
}); | ||
|
||
test('renders custom text', () => { | ||
render( | ||
<Text variant={TextVariant.HEADING} weight={TextWeight.BOLD}> | ||
Hello World! | ||
</Text>, | ||
); | ||
|
||
const textElement = screen.getByText(/hello world!/i); | ||
expect(textElement).toBeInTheDocument(); | ||
expect(textElement).toHaveStyle({ | ||
fontSize: TextVariant.HEADING.size, | ||
fontWeight: TextWeight.BOLD, | ||
}); | ||
}); | ||
|
||
test('renders correctly with default text', () => { | ||
const tree = create( | ||
<Text variant={TextVariant.TITLE}>Hello World!</Text>, | ||
).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
test('renders correctly with custom text', () => { | ||
const tree = create( | ||
<Text | ||
variant={TextVariant.TITLE} | ||
color={TextColor.LIGHT} | ||
weight={TextWeight.BOLD} | ||
> | ||
Hello World! | ||
</Text>, | ||
).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); |
29 changes: 29 additions & 0 deletions
29
webapp/src/shared/components/Text/__tests__/__snapshots__/Text.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`] = ` | ||
<h1 | ||
className="color-light" | ||
style={ | ||
Object { | ||
"fontSize": "3rem", | ||
"fontWeight": "700", | ||
} | ||
} | ||
> | ||
Hello World! | ||
</h1> | ||
`; | ||
|
||
exports[`renders correctly with default text 1`] = ` | ||
<h1 | ||
className="color-dark" | ||
style={ | ||
Object { | ||
"fontSize": "3rem", | ||
"fontWeight": "400", | ||
} | ||
} | ||
> | ||
Hello World! | ||
</h1> | ||
`; |
2 changes: 2 additions & 0 deletions
2
webapp/src/shared/components/index.tsx → webapp/src/shared/components/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
export enum Color { | ||
WARNING = '--color-warning', | ||
SUBMIT = '--color-submit', | ||
ONLINE = '--color-online', | ||
OFFLINE = '--color-offline', | ||
LIGHT = '--color-light', | ||
BACKGROUND = '--color-background', | ||
DARK = '--color-dark', | ||
GAME = '--color-game', | ||
WARNING = 'color-warning', | ||
SUBMIT = 'color-submit', | ||
ONLINE = 'color-online', | ||
OFFLINE = 'color-offline', | ||
LIGHT = 'color-light', | ||
BACKGROUND = 'color-background', | ||
DARK = 'color-dark', | ||
} |