@helpwave/hightide
Version:
helpwave's component and theming library
86 lines (82 loc) • 3.46 kB
JavaScript
// src/hooks/useLanguage.tsx
import { createContext, useContext, useEffect as useEffect2, useState as useState2 } from "react";
// src/hooks/useLocalStorage.tsx
import { useCallback, useEffect, useState } from "react";
// src/hooks/useLanguage.tsx
import { jsx } from "react/jsx-runtime";
var DEFAULT_LANGUAGE = "en";
var LanguageContext = createContext({ language: DEFAULT_LANGUAGE, setLanguage: (v) => v });
var useLanguage = () => useContext(LanguageContext);
// src/hooks/useTranslation.ts
var useTranslation = (defaults, translationOverwrite = {}) => {
const { language: languageProp, translation: overwrite } = translationOverwrite;
const { language: inferredLanguage } = useLanguage();
const usedLanguage = languageProp ?? inferredLanguage;
let defaultValues = defaults[usedLanguage];
if (overwrite && overwrite[usedLanguage]) {
defaultValues = { ...defaultValues, ...overwrite[usedLanguage] };
}
return defaultValues;
};
// src/components/TextImage.tsx
import clsx from "clsx";
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
var defaultTextImageTranslation = {
de: {
showMore: "Mehr anzeigen"
},
en: {
showMore: "Show more"
}
};
var TextImage = ({
overwriteTranslation,
title,
description,
imageUrl,
onShowMoreClicked,
color = "primary",
badge,
contentClassName = "",
className = ""
}) => {
const translation = useTranslation(defaultTextImageTranslation, overwriteTranslation);
const chipColorMapping = {
primary: "text-text-image-primary-background bg-text-text-image-primary-text",
secondary: "text-text-image-secondary-background bg-text-text-image-secondary-text",
dark: "text-text-image-dark-background bg-text-text-image-dark-text"
};
const colorMapping = {
primary: "text-text-image-primary-text bg-linear-to-r from-30% from-text-image-primary-background to-text-image-primary-background/55",
secondary: "text-text-image-secondary-text bg-linear-to-r from-30% from-text-image-secondary-background to-text-image-secondary-background/55",
dark: "text-text-image-dark-text bg-linear-to-r from-30% from-text-image-dark-background to-text-image-dark-background/55"
};
return /* @__PURE__ */ jsx2(
"div",
{
className: clsx("rounded-2xl w-full", className),
style: {
backgroundImage: `url(${imageUrl})`,
backgroundSize: "cover"
},
children: /* @__PURE__ */ jsxs(
"div",
{
className: clsx(`col px-6 py-12 rounded-2xl h-full`, colorMapping[color], contentClassName),
children: [
badge && /* @__PURE__ */ jsx2("div", { className: clsx(`chip-full bg-white mb-2 py-2 px-4 w-fit`, chipColorMapping[color]), children: /* @__PURE__ */ jsx2("span", { className: "text-lg font-bold", children: badge }) }),
/* @__PURE__ */ jsxs("div", { className: "col gap-y-1 text-white overflow-hidden", children: [
/* @__PURE__ */ jsx2("span", { className: "textstyle-title-xl", children: title }),
/* @__PURE__ */ jsx2("span", { className: "text-ellipsis overflow-hidden", children: description })
] }),
onShowMoreClicked && /* @__PURE__ */ jsx2("div", { className: "row mt-2 text-white underline", children: /* @__PURE__ */ jsx2("button", { onClick: onShowMoreClicked, children: translation.showMore }) })
]
}
)
}
);
};
export {
TextImage
};
//# sourceMappingURL=TextImage.mjs.map