Skip to content
Snippets Groups Projects
Feature.tsx 2.68 KiB
Newer Older
Toavina's avatar
Toavina committed
import React from "react"
import { IGatsbyImageData } from "gatsby-plugin-image"
tovo's avatar
tovo committed

Toavina's avatar
Toavina committed
import Image from "./core/Image"
import Map from "./core/Map"
import Button from "./core/Button"
tovo's avatar
tovo committed

interface Props {
Toavina's avatar
Toavina committed
    title?: string
    content?: string
    image?: string | IGatsbyImageData
    idMap?: number
    layout?: "left" | "right"
    backgroundImage?: string
    action?: {
        title?: string
        to?: string
        className?: string
    }
    custom?: JSX.Element
tovo's avatar
tovo committed
}
tovo's avatar
tovo committed
interface FeatureComponentProps {
Toavina's avatar
Toavina committed
    image?: string | IGatsbyImageData
    idMap?: number
    custom?: JSX.Element
tovo's avatar
tovo committed
}
tovo's avatar
tovo committed

const oClassName = {
Toavina's avatar
Toavina committed
    left: {
        container: "flex-col lg:flex-row",
        content: "pt-10 lg:pl-10",
    },
    right: {
        container: "flex-col-reverse lg:flex-row-reverse",
        content: "pt-10 pb-10 lg:pr-10 lg:pb-0",
    },
tovo's avatar
tovo committed
}

Toavina's avatar
Toavina committed
const FeatureComponent = (props: FeatureComponentProps) => {
    const { image, idMap, custom } = props
tovo's avatar
tovo committed

Toavina's avatar
Toavina committed
    if (idMap) {
        return (
            <>
                <Map idMap={idMap} />
            </>
        )
    }
tovo's avatar
tovo committed

Toavina's avatar
Toavina committed
    if (image) {
        return (
            <>
                <Image image={image} />
            </>
        )
    }
tovo's avatar
tovo committed

Toavina's avatar
Toavina committed
    return <>{custom && custom}</>
tovo's avatar
tovo committed
}

tovo's avatar
tovo committed
const Feature = (props: Props) => {
Toavina's avatar
Toavina committed
    const {
        layout = "left",
        title = "",
        content = "",
        image,
        idMap,
        backgroundImage,
        action,
        custom,
    } = props
tovo's avatar
tovo committed

Toavina's avatar
Toavina committed
    const className = oClassName[layout]
    const bTextOnly = !(idMap || image || custom)
    const classNameContent = bTextOnly
        ? "grow"
        : `lg:w-1/2 ${className["content"]}`
    const classNameBackground = backgroundImage
        ? "bg-[url('" + backgroundImage + "')] bg-cover bg-no-repeat bg-center "
        : ""
tovo's avatar
tovo committed

Toavina's avatar
Toavina committed
    return (
        <div
            className={`flex ${className["container"]} ${classNameBackground}`}
        >
            {!bTextOnly && (
                <div className="h-[480px] lg:w-1/2">
                    <FeatureComponent
                        idMap={idMap}
                        image={image}
                        custom={custom}
                    />
                </div>
            )}
            <div className={classNameContent}>
                <h2 className="font-extrabold sm:text-4xl">{title}</h2>
                <p className="text-xl leading-8 pt-10 text-justify">
                    {content}
                </p>
                {action && (
                    <Button
                        title={action.title}
                        to={action.to}
                        className={`mt-10 ${action.className}`}
                    />
                )}
            </div>
        </div>
    )
}
tovo's avatar
tovo committed

Toavina's avatar
Toavina committed
export default Feature