Refactor classname mapping
This commit is contained in:
@@ -1,15 +1,25 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import "./Button.scss";
|
import "./Button.scss";
|
||||||
|
|
||||||
|
export enum ButtonType {
|
||||||
|
Hero,
|
||||||
|
Filled,
|
||||||
|
}
|
||||||
|
|
||||||
|
const buttonClassNames = new Map<ButtonType, string>([
|
||||||
|
[ButtonType.Hero, "hero"],
|
||||||
|
[ButtonType.Filled, "filled"],
|
||||||
|
]);
|
||||||
|
|
||||||
export interface ButtonProps {
|
export interface ButtonProps {
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
type: string;
|
type: ButtonType;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Button extends React.Component<ButtonProps, undefined> {
|
export default class Button extends React.Component<ButtonProps, undefined> {
|
||||||
render() {
|
render() {
|
||||||
const { type } = this.props;
|
const { type } = this.props;
|
||||||
const className = `button ${type}`;
|
const className = `button ${buttonClassNames.get(type)}`;
|
||||||
return (
|
return (
|
||||||
<button onClick={this.props.onClick} className={className}>
|
<button onClick={this.props.onClick} className={className}>
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
import Button from "./Button";
|
import Button, { ButtonType } from "./Button";
|
||||||
export default Button;
|
export default Button;
|
||||||
|
export { ButtonType };
|
||||||
|
|||||||
@@ -11,19 +11,15 @@ export interface PageSectionProps {
|
|||||||
}
|
}
|
||||||
export interface PageSectionState {}
|
export interface PageSectionState {}
|
||||||
|
|
||||||
const colorToClass = (color: BackgroundColor): string => {
|
const colors = new Map<BackgroundColor, string>([
|
||||||
if (color === BackgroundColor.DarkBlue) {
|
[BackgroundColor.DarkBlue, "dark-blue"],
|
||||||
return "dark-blue";
|
[BackgroundColor.White, "white"],
|
||||||
}
|
]);
|
||||||
else if (color === BackgroundColor.White) {
|
|
||||||
return "white";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class PageSection extends React.Component<PageSectionProps, PageSectionState> {
|
class PageSection extends React.Component<PageSectionProps, PageSectionState> {
|
||||||
render() {
|
render() {
|
||||||
const { backgroundColor, children } = this.props;
|
const { backgroundColor, children } = this.props;
|
||||||
const className = `page-section ${colorToClass(backgroundColor)}`;
|
const className = `page-section ${colors.get(backgroundColor)}`;
|
||||||
return (
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import PageSection from "../../components/PageSection";
|
|||||||
import { BackgroundColor as PageSectionColor } from "../../components/PageSection/PageSection";
|
import { BackgroundColor as PageSectionColor } from "../../components/PageSection/PageSection";
|
||||||
import HeroMainSection from "../../components/HeroMainSection";
|
import HeroMainSection from "../../components/HeroMainSection";
|
||||||
import HeroAsideSection from "../../components/HeroAsideSection";
|
import HeroAsideSection from "../../components/HeroAsideSection";
|
||||||
import Button from "../../components/Button";
|
import Button, { ButtonType } from "../../components/Button";
|
||||||
|
|
||||||
interface FrontPageProps {
|
interface FrontPageProps {
|
||||||
staticContext: StaticContext;
|
staticContext: StaticContext;
|
||||||
@@ -72,8 +72,8 @@ class FrontPage extends React.Component<FrontPageProps, FrontPageState> {
|
|||||||
Kilta kasaa yhteen yli 600 alansa huippua, jotka ovat
|
Kilta kasaa yhteen yli 600 alansa huippua, jotka ovat
|
||||||
avainasemassa vauhdilla sähköistyvän maailmamme
|
avainasemassa vauhdilla sähköistyvän maailmamme
|
||||||
kehityksessä.</p>
|
kehityksessä.</p>
|
||||||
<Button type="hero" onClick={() => { }}>Killan tehtävät ›</Button>
|
<Button type={ButtonType.Hero} onClick={() => { }}>Killan tehtävät ›</Button>
|
||||||
<Button type="hero" onClick={() => { }}>Vastapainoa opiskelulle ›</Button>
|
<Button type={ButtonType.Hero} onClick={() => { }}>Vastapainoa opiskelulle ›</Button>
|
||||||
</HeroMainSection>
|
</HeroMainSection>
|
||||||
<HeroAsideSection>
|
<HeroAsideSection>
|
||||||
Kikkeli
|
Kikkeli
|
||||||
|
|||||||
Reference in New Issue
Block a user