UNPKG

@helpwave/hightide

Version:

helpwave's component and theming library

216 lines (209 loc) 6.82 kB
// src/components/StepperBar.tsx import { Check, ChevronLeft, ChevronRight } from "lucide-react"; // 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/util/array.ts var range = (start, end, allowEmptyRange = false) => { if (end < start) { if (!allowEmptyRange) { console.warn(`range: end (${end}) < start (${start}) should be allowed explicitly, set allowEmptyRange to true`); } return []; } return Array.from({ length: end - start + 1 }, (_, index) => index + start); }; // src/components/Button.tsx import clsx from "clsx"; import { jsx as jsx2, jsxs } from "react/jsx-runtime"; var ButtonSizePaddings = { small: "btn-sm", medium: "btn-md", large: "btn-lg" }; var SolidButton = ({ children, disabled = false, color = "primary", size = "medium", startIcon, endIcon, onClick, className, ...restProps }) => { const colorClasses = { primary: "bg-button-solid-primary-background text-button-solid-primary-text", secondary: "bg-button-solid-secondary-background text-button-solid-secondary-text", tertiary: "bg-button-solid-tertiary-background text-button-solid-tertiary-text", positive: "bg-button-solid-positive-background text-button-solid-positive-text", warning: "bg-button-solid-warning-background text-button-solid-warning-text", negative: "bg-button-solid-negative-background text-button-solid-negative-text" }[color]; const iconColorClasses = { primary: "text-button-solid-primary-icon", secondary: "text-button-solid-secondary-icon", tertiary: "text-button-solid-tertiary-icon", positive: "text-button-solid-positive-icon", warning: "text-button-solid-warning-icon", negative: "text-button-solid-negative-icon" }[color]; return /* @__PURE__ */ jsxs( "button", { onClick: disabled ? void 0 : onClick, disabled: disabled || onClick === void 0, className: clsx( className, { "text-disabled-text bg-disabled-background": disabled, [clsx(colorClasses, "hover:brightness-90")]: !disabled }, ButtonSizePaddings[size] ), ...restProps, children: [ startIcon && /* @__PURE__ */ jsx2( "span", { className: clsx({ [iconColorClasses]: !disabled, [`text-disabled-icon`]: disabled }), children: startIcon } ), children, endIcon && /* @__PURE__ */ jsx2( "span", { className: clsx({ [iconColorClasses]: !disabled, [`text-disabled-icon`]: disabled }), children: endIcon } ) ] } ); }; // src/components/StepperBar.tsx import clsx2 from "clsx"; import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime"; var defaultStepperBarTranslation = { en: { back: "Back", next: "Next Step", confirm: "Create" }, de: { back: "Zur\xFCck", next: "N\xE4chster Schritt", confirm: "Erstellen" } }; var StepperBar = ({ overwriteTranslation, stepper, onChange, onFinish, showDots = true, className = "" }) => { const translation = useTranslation(defaultStepperBarTranslation, overwriteTranslation); const dots = range(0, stepper.lastStep); const { step, seenSteps, lastStep } = stepper; const update = (newStep) => { seenSteps.add(newStep); onChange({ step: newStep, seenSteps, lastStep }); }; return /* @__PURE__ */ jsxs2( "div", { className: clsx2("sticky row p-2 border-2 justify-between rounded-lg shadow-lg", className), children: [ /* @__PURE__ */ jsx3("div", { className: "flex-[2] justify-start", children: /* @__PURE__ */ jsxs2( SolidButton, { disabled: step === 0, onClick: () => { update(step - 1); }, className: "row gap-x-1 items-center justify-center", children: [ /* @__PURE__ */ jsx3(ChevronLeft, { size: 14 }), translation.back ] } ) }), /* @__PURE__ */ jsx3("div", { className: "row flex-[5] gap-x-2 justify-center items-center", children: showDots && dots.map((value, index) => { const seen = seenSteps.has(index); return /* @__PURE__ */ jsx3( "div", { onClick: () => seen && update(index), className: clsx2( "rounded-full w-4 h-4", { "bg-primary hover:brightness-75": index === step && seen, "bg-primary/40 hover:bg-primary": index !== step && seen, "bg-gray-200 outline-transparent": !seen }, { "cursor-pointer": seen, "cursor-not-allowed": !seen } ) }, index ); }) }), step !== lastStep && /* @__PURE__ */ jsx3("div", { className: "flex-[2] justify-end", children: /* @__PURE__ */ jsxs2( SolidButton, { onClick: () => update(step + 1), className: "row gap-x-1 items-center justify-center", children: [ translation.next, /* @__PURE__ */ jsx3(ChevronRight, { size: 14 }) ] } ) }), step === lastStep && /* @__PURE__ */ jsx3("div", { className: "flex-[2] justify-end", children: /* @__PURE__ */ jsxs2( SolidButton, { disabled: false, onClick: onFinish, className: "row gap-x-1 items-center justify-center", children: [ /* @__PURE__ */ jsx3(Check, { size: 14 }), translation.confirm ] } ) }) ] } ); }; export { StepperBar }; //# sourceMappingURL=StepperBar.mjs.map