@helpwave/hightide
Version:
helpwave's component and theming library
1 lines • 71.8 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/components/user-action/Button.tsx","../../../src/components/user-action/Input.tsx","../../../src/hooks/useDelay.ts","../../../src/util/noop.ts","../../../src/components/user-action/Label.tsx","../../../src/hooks/useFocusManagement.ts","../../../src/hooks/useFocusOnceVisible.ts","../../../src/components/table/TableFilterButton.tsx","../../../src/components/user-action/Menu.tsx","../../../src/hooks/useOutsideClick.ts","../../../src/hooks/useHoverState.ts","../../../src/util/PropsWithFunctionChildren.ts","../../../src/hooks/usePopoverPosition.ts","../../../src/localization/LanguageProvider.tsx","../../../src/hooks/useLocalStorage.ts","../../../src/localization/util.ts","../../../src/localization/useTranslation.ts","../../../src/localization/defaults/form.ts"],"sourcesContent":["import type { ButtonHTMLAttributes, PropsWithChildren, ReactNode } from 'react'\nimport { forwardRef } from 'react'\nimport clsx from 'clsx'\n\n\nexport const ButtonColorUtil = {\n solid: ['primary', 'secondary', 'tertiary', 'positive', 'warning', 'negative', 'neutral'] as const,\n text: ['primary', 'negative', 'neutral'] as const,\n outline: ['primary'] as const,\n}\n\nexport const IconButtonUtil = {\n icon: [...ButtonColorUtil.solid, 'transparent'] as const,\n}\n\n\n/**\n * The allowed colors for the SolidButton and IconButton\n */\nexport type SolidButtonColor = typeof ButtonColorUtil.solid[number]\n/**\n * The allowed colors for the OutlineButton\n */\nexport type OutlineButtonColor = typeof ButtonColorUtil.outline[number]\n/**\n * The allowed colors for the TextButton\n */\nexport type TextButtonColor = typeof ButtonColorUtil.text[number]\n/**\n * The allowed colors for the IconButton\n */\nexport type IconButtonColor = typeof IconButtonUtil.icon[number]\n\n\n/**\n * The different sizes for a button\n */\ntype ButtonSizes = 'small' | 'medium' | 'large'\n\ntype IconButtonSize = 'tiny' | 'small' | 'medium' | 'large'\n\n/**\n * The shard properties between all button types\n */\nexport type ButtonProps = PropsWithChildren<{\n /**\n * @default 'medium'\n */\n size?: ButtonSizes,\n}> & ButtonHTMLAttributes<Element>\n\nconst paddingMapping: Record<ButtonSizes, string> = {\n small: 'btn-sm',\n medium: 'btn-md',\n large: 'btn-lg'\n}\n\nconst iconPaddingMapping: Record<IconButtonSize, string> = {\n tiny: 'icon-btn-xs',\n small: 'icon-btn-sm',\n medium: 'icon-btn-md',\n large: 'icon-btn-lg'\n}\n\nexport const ButtonUtil = {\n paddingMapping,\n iconPaddingMapping\n}\n\ntype ButtonWithIconsProps = ButtonProps & {\n startIcon?: ReactNode,\n endIcon?: ReactNode,\n}\n\nexport type SolidButtonProps = ButtonWithIconsProps & {\n color?: SolidButtonColor,\n}\n\nexport type OutlineButtonProps = ButtonWithIconsProps & {\n color?: OutlineButtonColor,\n}\n\nexport type TextButtonProps = ButtonWithIconsProps & {\n color?: TextButtonColor,\n coloredHoverBackground?: boolean,\n}\n\n/**\n * The shard properties between all button types\n */\nexport type IconButtonProps = PropsWithChildren<{\n /**\n * @default 'medium'\n */\n size?: IconButtonSize,\n color?: IconButtonColor,\n}> & ButtonHTMLAttributes<Element>\n\n/**\n * A button with a solid background and different sizes\n */\nconst SolidButton = forwardRef<HTMLButtonElement, SolidButtonProps>(function SolidButton({\n children,\n color = 'primary',\n size = 'medium',\n startIcon,\n endIcon,\n onClick,\n className,\n ...restProps\n }, ref) {\n const colorClasses = {\n primary: 'not-disabled:bg-button-solid-primary-background not-disabled:text-button-solid-primary-text',\n secondary: 'not-disabled:bg-button-solid-secondary-background not-disabled:text-button-solid-secondary-text',\n tertiary: 'not-disabled:bg-button-solid-tertiary-background not-disabled:text-button-solid-tertiary-text',\n positive: 'not-disabled:bg-button-solid-positive-background not-disabled:text-button-solid-positive-text',\n warning: 'not-disabled:bg-button-solid-warning-background not-disabled:text-button-solid-warning-text',\n negative: 'not-disabled:bg-button-solid-negative-background not-disabled:text-button-solid-negative-text',\n neutral: 'not-disabled:bg-button-solid-neutral-background not-disabled:text-button-solid-neutral-text',\n }[color]\n\n const iconColorClasses = {\n primary: 'not-group-disabled:text-button-solid-primary-icon',\n secondary: 'not-group-disabled:text-button-solid-secondary-icon',\n tertiary: 'not-group-disabled:text-button-solid-tertiary-icon',\n positive: 'not-group-disabled:text-button-solid-positive-icon',\n warning: 'not-group-disabled:text-button-solid-warning-icon',\n negative: 'not-group-disabled:text-button-solid-negative-icon',\n neutral: 'not-group-disabled:text-button-solid-neutral-icon',\n }[color]\n\n return (\n <button\n ref={ref}\n onClick={onClick}\n className={clsx(\n 'group font-semibold',\n colorClasses,\n 'not-disabled:hover:brightness-90',\n 'disabled:text-disabled-text disabled:bg-disabled-background',\n ButtonUtil.paddingMapping[size],\n className\n )}\n {...restProps}\n >\n {startIcon && (\n <span\n className={clsx(\n iconColorClasses,\n 'group-disabled:text-disabled-icon'\n )}\n >\n {startIcon}\n </span>\n )}\n {children}\n {endIcon && (\n <span\n className={clsx(\n iconColorClasses,\n 'group-disabled:text-disabled-icon'\n )}\n >\n {endIcon}\n </span>\n )}\n </button>\n )\n})\n\n/**\n * A button with an outline border and different sizes\n */\nconst OutlineButton = ({\n children,\n color = 'primary',\n size = 'medium',\n startIcon,\n endIcon,\n onClick,\n className,\n ...restProps\n }: OutlineButtonProps) => {\n const colorClasses = {\n primary: 'not-disabled:border-button-outline-primary-text not-disabled:text-button-outline-primary-text',\n }[color]\n\n const iconColorClasses = {\n primary: 'not-group-disabled:text-button-outline-primary-icon',\n }[color]\n return (\n <button\n onClick={onClick}\n className={clsx(\n 'group font-semibold bg-transparent border-2 ',\n 'not-disabled:hover:brightness-80',\n colorClasses,\n 'disabled:text-disabled-text disabled:border-disabled-outline',\n ButtonUtil.paddingMapping[size],\n className\n )}\n {...restProps}\n >\n {startIcon && (\n <span\n className={clsx(\n iconColorClasses,\n 'group-disabled:text-disabled-icon'\n )}\n >\n {startIcon}\n </span>\n )}\n {children}\n {endIcon && (\n <span\n className={clsx(\n iconColorClasses,\n 'group-disabled:text-disabled-icon'\n )}\n >\n {endIcon}\n </span>\n )}\n </button>\n )\n}\n\n/**\n * A text that is a button that can have different sizes\n */\nconst TextButton = ({\n children,\n color = 'neutral',\n size = 'medium',\n startIcon,\n endIcon,\n onClick,\n coloredHoverBackground = true,\n className,\n ...restProps\n }: TextButtonProps) => {\n const colorClasses = {\n primary: 'not-disabled:bg-transparent not-disabled:text-button-text-primary-text',\n negative: 'not-disabled:bg-transparent not-disabled:text-button-text-negative-text',\n neutral: 'not-disabled:bg-transparent not-disabled:text-button-text-neutral-text',\n }[color]\n\n const backgroundColor = {\n primary: 'not-disabled:hover:bg-button-text-primary-text/20',\n negative: 'not-disabled:hover:bg-button-text-negative-text/20',\n neutral: 'not-disabled:hover:bg-button-text-neutral-text/20',\n }[color]\n\n const iconColorClasses = {\n primary: 'not-group-disabled:text-button-text-primary-icon',\n negative: 'not-group-disabled:text-button-text-negative-icon',\n neutral: 'not-group-disabled:text-button-text-neutral-icon',\n }[color]\n\n return (\n <button\n onClick={onClick}\n className={clsx(\n 'group font-semibold',\n 'disabled:text-disabled-text',\n colorClasses,\n {\n [backgroundColor]: coloredHoverBackground,\n 'not-disabled:hover:bg-button-text-hover-background': !coloredHoverBackground,\n },\n ButtonUtil.paddingMapping[size],\n className\n )}\n {...restProps}\n >\n {startIcon && (\n <span\n className={clsx(\n iconColorClasses,\n 'group-disabled:text-disabled-icon'\n )}\n >\n {startIcon}\n </span>\n )}\n {children}\n {endIcon && (\n <span\n className={clsx(\n iconColorClasses,\n 'group-disabled:text-disabled-icon'\n )}\n >\n {endIcon}\n </span>\n )}\n </button>\n )\n}\n\n\n/**\n * A button for icons with a solid background and different sizes\n */\nconst IconButton = ({\n children,\n color = 'primary',\n size = 'medium',\n className,\n ...restProps\n }: IconButtonProps) => {\n const colorClasses = {\n primary: 'not-disabled:bg-button-solid-primary-background not-disabled:text-button-solid-primary-text',\n secondary: 'not-disabled:bg-button-solid-secondary-background not-disabled:text-button-solid-secondary-text',\n tertiary: 'not-disabled:bg-button-solid-tertiary-background not-disabled:text-button-solid-tertiary-text',\n positive: 'not-disabled:bg-button-solid-positive-background not-disabled:text-button-solid-positive-text',\n warning: 'not-disabled:bg-button-solid-warning-background not-disabled:text-button-solid-warning-text',\n negative: 'not-disabled:bg-button-solid-negative-background not-disabled:text-button-solid-negative-text',\n neutral: 'not-disabled:bg-button-solid-neutral-background not-disabled:text-button-solid-neutral-text',\n transparent: 'not-disabled:bg-transparent',\n }[color]\n\n return (\n <button\n className={clsx(\n colorClasses,\n 'not-disabled:hover:brightness-90',\n 'disabled:text-disabled-text',\n {\n 'disabled:bg-disabled-background': color !== 'transparent',\n 'disabled:opacity-70': color === 'transparent',\n 'not-disabled:hover:bg-button-text-hover-background': color === 'transparent',\n },\n ButtonUtil.iconPaddingMapping[size],\n className\n )}\n {...restProps}\n >\n {children}\n </button>\n )\n}\n\nexport { SolidButton, OutlineButton, TextButton, IconButton }\n","import React, { forwardRef, type InputHTMLAttributes, useEffect, useImperativeHandle, useRef, useState } from 'react'\nimport clsx from 'clsx'\nimport type { UseDelayOptionsResolved } from '../../hooks/useDelay'\nimport { useDelay } from '../../hooks/useDelay'\nimport { noop } from '../../util/noop'\nimport type { LabelProps } from './Label'\nimport { Label } from './Label'\nimport { useFocusManagement } from '../../hooks/useFocusManagement'\nimport { useFocusOnceVisible } from '../../hooks/useFocusOnceVisible'\n\ntype GetInputClassNameProps = {\n disabled?: boolean,\n hasError?: boolean,\n}\nconst getInputClassName = ({ disabled = false, hasError = false }: GetInputClassNameProps) => {\n return clsx(\n 'px-2 py-1.5 rounded-md border-2',\n {\n 'bg-input-background text-input-text hover:border-primary focus:border-primary': !disabled && !hasError,\n 'bg-on-negative text-negative border-negative-border hover:border-negative-border-hover': !disabled && hasError,\n 'bg-disabled-background text-disabled-text border-disabled-border': disabled,\n }\n )\n}\n\nexport type EditCompleteOptionsResolved = {\n onBlur: boolean,\n afterDelay: boolean,\n} & Omit<UseDelayOptionsResolved, 'disabled'>\n\nexport type EditCompleteOptions = Partial<EditCompleteOptionsResolved>\n\nconst defaultEditCompleteOptions: EditCompleteOptionsResolved = {\n onBlur: true,\n afterDelay: true,\n delay: 2500\n}\n\nexport type InputProps = {\n /**\n * used for the label's `for` attribute\n */\n label?: Omit<LabelProps, 'id'>,\n /**\n * Callback for when the input's value changes\n * This is pretty much required but made optional for the rare cases where it actually isn't need such as when used with disabled\n * That could be enforced through a union type but that seems a bit overkill\n * @default noop\n */\n onChangeText?: (text: string) => void,\n className?: string,\n onEditCompleted?: (text: string) => void,\n allowEnterComplete?: boolean,\n expanded?: boolean,\n containerClassName?: string,\n editCompleteOptions?: EditCompleteOptions,\n} & Omit<InputHTMLAttributes<HTMLInputElement>, 'label'>\n\n/**\n * A Component for inputting text or other information\n *\n * Its state is managed must be managed by the parent\n */\nconst Input = forwardRef<HTMLInputElement, InputProps>(function Input({\n id,\n type = 'text',\n value,\n label,\n onChange = noop,\n onChangeText = noop,\n onEditCompleted,\n className = '',\n allowEnterComplete = true,\n expanded = true,\n autoFocus = false,\n onBlur,\n editCompleteOptions,\n containerClassName,\n disabled,\n ...restProps\n }, forwardedRef) {\n const { onBlur: allowEditCompleteOnBlur, afterDelay, delay } = { ...defaultEditCompleteOptions, ...editCompleteOptions }\n\n const {\n restartTimer,\n clearTimer\n } = useDelay({ delay, disabled: !afterDelay })\n\n const innerRef = useRef<HTMLInputElement>(null)\n const { focusNext } = useFocusManagement()\n\n useFocusOnceVisible(innerRef, !autoFocus)\n useImperativeHandle(forwardedRef, () => innerRef.current)\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault()\n innerRef.current?.blur()\n focusNext()\n }\n }\n\n return (\n <div className={clsx({ 'w-full': expanded }, containerClassName)}>\n {label && <Label {...label} htmlFor={id} className={clsx('mb-1', label.className)} />}\n <input\n {...restProps}\n ref={innerRef}\n value={value}\n id={id}\n type={type}\n disabled={disabled}\n className={clsx(getInputClassName({ disabled }), className)}\n onKeyDown={allowEnterComplete ? handleKeyDown : undefined}\n onBlur={event => {\n onBlur?.(event)\n if (onEditCompleted && allowEditCompleteOnBlur) {\n onEditCompleted(event.target.value)\n clearTimer()\n }\n }}\n onChange={e => {\n const value = e.target.value\n if (onEditCompleted) {\n restartTimer(() => {\n if(innerRef.current){\n innerRef.current.blur()\n if(!allowEditCompleteOnBlur) {\n onEditCompleted(value)\n }\n } else {\n onEditCompleted(value)\n }\n })\n }\n onChange(e)\n onChangeText(value)\n }}\n />\n </div>\n )\n})\n\n\n/**\n * A Component for inputting text or other information\n *\n * Its state is managed by the component itself\n */\nconst InputUncontrolled = ({\n value = '',\n onChangeText = noop,\n ...props\n }: InputProps) => {\n const [usedValue, setUsedValue] = useState(value)\n\n useEffect(() => {\n setUsedValue(value)\n }, [value])\n\n return (\n <Input\n {...props}\n value={usedValue}\n onChangeText={text => {\n setUsedValue(text)\n onChangeText(text)\n }}\n />\n )\n}\n\nexport type FormInputProps = InputHTMLAttributes<HTMLInputElement> & {\n id: string,\n labelText?: string,\n errorText?: string,\n labelClassName?: string,\n errorClassName?: string,\n containerClassName?: string,\n}\n\nconst FormInput = forwardRef<HTMLInputElement, FormInputProps>(function FormInput({\n id,\n labelText,\n errorText,\n className,\n labelClassName,\n errorClassName,\n containerClassName,\n required,\n disabled,\n ...restProps\n }, ref) {\n const input = (\n <input\n {...restProps}\n ref={ref}\n id={id}\n disabled={disabled}\n className={clsx(\n getInputClassName({ disabled, hasError: !!errorText }),\n className\n )}\n />\n )\n\n return (\n <div className={clsx('flex flex-col gap-y-1', containerClassName)}>\n {labelText && (\n <label htmlFor={id} className={clsx('textstyle-label-md', labelClassName)}>\n {labelText}\n {required && <span className=\"text-primary font-bold\">*</span>}\n </label>\n )}\n {input}\n {errorText && <label htmlFor={id} className={clsx('text-negative', errorClassName)}>{errorText}</label>}\n </div>\n )\n})\n\nexport {\n InputUncontrolled,\n Input,\n FormInput\n}\n","import { useEffect, useState } from 'react'\n\nexport type UseDelayOptionsResolved = {\n delay: number,\n disabled: boolean,\n}\n\nexport type UseDelayOptions = Partial<UseDelayOptionsResolved>\n\nconst defaultOptions: UseDelayOptionsResolved = {\n delay: 3000,\n disabled: false,\n}\n\nexport function useDelay(options?: UseDelayOptions) {\n const [timer, setTimer] = useState<NodeJS.Timeout | undefined>(undefined)\n const { delay, disabled }: UseDelayOptionsResolved = {\n ...defaultOptions,\n ...options\n }\n\n const clearTimer = () => {\n clearTimeout(timer)\n setTimer(undefined)\n }\n\n const restartTimer = (onDelayFinish: () => void) => {\n if(disabled) {\n return\n }\n clearTimeout(timer)\n setTimer(setTimeout(() => {\n onDelayFinish()\n setTimer(undefined)\n }, delay))\n }\n\n useEffect(() => {\n return () => {\n clearTimeout(timer)\n }\n }, [timer])\n\n useEffect(() => {\n if(disabled){\n clearTimeout(timer)\n setTimer(undefined)\n }\n }, [disabled, timer])\n\n return { restartTimer, clearTimer, hasActiveTimer: !!timer }\n}","export const noop = () => undefined\n","import type { LabelHTMLAttributes } from 'react'\nimport clsx from 'clsx'\n\nexport type LabelType = 'labelSmall' | 'labelMedium' | 'labelBig'\n\nconst styleMapping: Record<LabelType, string> = {\n labelSmall: 'textstyle-label-sm',\n labelMedium: 'textstyle-label-md',\n labelBig: 'textstyle-label-lg',\n}\n\nexport type LabelProps = {\n /** The text for the label */\n name?: string,\n /** The styling for the label */\n labelType?: LabelType,\n} & LabelHTMLAttributes<HTMLLabelElement>\n\n/**\n * A Label component\n */\nexport const Label = ({\n children,\n name,\n labelType = 'labelSmall',\n className,\n ...props\n }: LabelProps) => {\n return (\n <label {...props} className={clsx(styleMapping[labelType], className)}>\n {children ? children : name}\n </label>\n )\n}\n","import { useCallback } from 'react'\n\nexport function useFocusManagement() {\n const getFocusableElements = useCallback((): HTMLElement[] => {\n return Array.from(\n document.querySelectorAll(\n 'input, button, select, textarea, a[href], [tabindex]:not([tabindex=\"-1\"])'\n )\n ).filter(\n (el): el is HTMLElement =>\n el instanceof HTMLElement &&\n !el.hasAttribute('disabled') &&\n !el.hasAttribute('hidden') &&\n el.tabIndex !== -1\n )\n }, [])\n\n const getNextFocusElement = useCallback((): HTMLElement | undefined => {\n const elements = getFocusableElements()\n if(elements.length === 0) {\n return undefined\n }\n let nextElement = elements[0]\n if(document.activeElement instanceof HTMLElement) {\n const currentIndex = elements.indexOf(document.activeElement)\n nextElement = elements[(currentIndex + 1) % elements.length]\n }\n return nextElement\n }, [getFocusableElements])\n\n const focusNext = useCallback(() => {\n const nextElement = getNextFocusElement()\n nextElement?.focus()\n }, [getNextFocusElement])\n\n const getPreviousFocusElement = useCallback((): HTMLElement | undefined => {\n const elements = getFocusableElements()\n if(elements.length === 0) {\n return undefined\n }\n let previousElement = elements[0]\n if(document.activeElement instanceof HTMLElement) {\n const currentIndex = elements.indexOf(document.activeElement)\n if(currentIndex === 0) {\n previousElement = elements[elements.length - 1]\n } else {\n previousElement = elements[currentIndex - 1]\n }\n }\n return previousElement\n }, [getFocusableElements])\n\n const focusPrevious = useCallback(() => {\n const previousElement = getPreviousFocusElement()\n if (previousElement) previousElement.focus()\n }, [getPreviousFocusElement])\n\n return {\n getFocusableElements,\n getNextFocusElement,\n getPreviousFocusElement,\n focusNext,\n focusPrevious,\n }\n}","import type { MutableRefObject } from 'react'\nimport React, { useEffect } from 'react'\n\nexport const useFocusOnceVisible = (\n ref: MutableRefObject<HTMLElement>,\n disable: boolean = false\n) => {\n const [hasUsedFocus, setHasUsedFocus] = React.useState(false)\n\n useEffect(() => {\n if (disable || hasUsedFocus) {\n return\n }\n const observer = new IntersectionObserver(([entry]) => {\n if (entry.isIntersecting && !hasUsedFocus) {\n ref.current?.focus()\n setHasUsedFocus(hasUsedFocus)\n }\n }, {\n threshold: 0.1,\n })\n\n if (ref.current) {\n observer.observe(ref.current)\n }\n\n return () => observer.disconnect()\n }, [disable, hasUsedFocus, ref])\n}","import { IconButton, SolidButton } from '../user-action/Button'\nimport { Input } from '../user-action/Input'\nimport { FilterIcon } from 'lucide-react'\nimport { Menu } from '../user-action/Menu'\nimport type { Translation } from '../../localization/useTranslation'\nimport { useTranslation } from '../../localization/useTranslation'\nimport { formTranslation } from '../../localization/defaults/form'\nimport { useEffect, useState } from 'react'\nimport type { Column } from '@tanstack/react-table'\n\nexport type TableFilterType = 'text' | 'range' | 'dateRange'\n\ntype TableFilterTranslationType = {\n filter: string,\n min: string,\n max: string,\n startDate: string,\n endDate: string,\n text: string,\n}\n\nconst defaultTableFilterTranslation: Translation<TableFilterTranslationType> = {\n en: {\n filter: 'Filter',\n min: 'Min',\n max: 'Max',\n startDate: 'Start',\n endDate: 'End',\n text: 'Text...',\n },\n de: {\n filter: 'Filter',\n min: 'Min',\n max: 'Max',\n startDate: 'Start',\n endDate: 'Ende',\n text: 'Text...',\n }\n}\n\nexport type TableFilterButtonProps<T = unknown> = {\n filterType: TableFilterType,\n column: Column<T>,\n}\n\nexport const TableFilterButton = <T, >({\n filterType,\n column,\n }: TableFilterButtonProps<T>) => {\n const translation = useTranslation([formTranslation, defaultTableFilterTranslation])\n const columnFilterValue = column.getFilterValue()\n const [filterValue, setFilterValue] = useState<unknown>(columnFilterValue)\n const hasFilter = !!filterValue\n\n useEffect(() => {\n setFilterValue(columnFilterValue)\n }, [columnFilterValue])\n\n return (\n <Menu<HTMLDivElement>\n trigger={({ toggleOpen }, ref) => (\n <div ref={ref} className=\"relative\">\n <IconButton color=\"neutral\" size=\"tiny\" onClick={toggleOpen}>\n <FilterIcon/>\n </IconButton>\n {hasFilter && (\n <div\n className=\"absolute top-0.5 right-0.5 w-2 h-2 rounded-full bg-primary pointer-events-none\"\n aria-hidden={true}\n />\n )}\n </div>\n )}\n >\n {({ close }) => (\n <div className=\"flex-col-1 p-2 items-start font-normal text-menu-text\">\n <h4 className=\"textstyle-title-sm\">{translation('filter')}</h4>\n {filterType === 'text' && (\n <Input\n value={(filterValue ?? '') as string}\n autoFocus={true}\n placeholder={translation('text')}\n onChangeText={setFilterValue}\n className=\"h-10\"\n />\n )}\n {filterType === 'range' && (\n <div className=\"flex-row-2 items-center\">\n <Input\n value={(filterValue as [number, number])?.[0] ?? ''}\n type=\"number\"\n placeholder={translation('min')}\n onChangeText={text => {\n const num = Number(text)\n setFilterValue((old: [number, number]) => [num, old?.[1]])\n }}\n className=\"h-10 input-indicator-hidden w-40\"\n />\n <span className=\"font-bold\">-</span>\n <Input\n value={(filterValue as [number, number])?.[1] ?? ''}\n type=\"number\"\n placeholder={translation('max')}\n onChangeText={text => {\n const num = Number(text)\n setFilterValue((old: [number, number]) => [old?.[0], num])\n }}\n className=\"h-10 input-indicator-hidden w-40\"\n />\n </div>\n )}\n {filterType === 'dateRange' && (\n <>\n <Input\n value={(filterValue as [Date, Date])?.[0] ? (filterValue as [Date, Date])?.[0].toISOString().slice(0, 16) : ''}\n type=\"datetime-local\"\n placeholder={translation('startDate')}\n onChangeText={text => {\n const value = new Date(text)\n setFilterValue((old: [Date, Date]) => [value, old?.[1]])\n }}\n className=\"h-10 w-50\"\n />\n <Input\n value={(filterValue as [Date, Date])?.[1] ? (filterValue as [Date, Date])?.[1].toISOString().slice(0, 16) : ''}\n type=\"datetime-local\"\n placeholder={translation('endDate')}\n onChangeText={text => {\n const value = new Date(text)\n setFilterValue((old: [Date, Date]) => [old?.[0], value])\n }}\n className=\"h-10 w-50\"\n />\n </>\n )}\n <div className=\"flex-row-2 justify-end w-full\">\n {hasFilter && (\n <SolidButton color=\"negative\" size=\"small\" onClick={() => {\n column.setFilterValue(undefined)\n close()\n }}>\n {translation('remove')}\n </SolidButton>\n )}\n <SolidButton size=\"small\" onClick={() => {\n column.setFilterValue(filterValue)\n close()\n }}>\n {translation('apply')}\n </SolidButton>\n </div>\n </div>\n )}\n </Menu>\n )\n}","import { type PropsWithChildren, type ReactNode, type RefObject, useEffect, useRef, useState } from 'react'\nimport clsx from 'clsx'\nimport { useOutsideClick } from '../../hooks/useOutsideClick'\nimport { useHoverState } from '../../hooks/useHoverState'\nimport type { PropsWithBagFunctionOrChildren } from '../../util/PropsWithFunctionChildren'\nimport { BagFunctionUtil } from '../../util/PropsWithFunctionChildren'\nimport type { PopoverHorizontalAlignment, PopoverVerticalAlignment } from '../../hooks/usePopoverPosition'\nimport { usePopoverPosition } from '../../hooks/usePopoverPosition'\nimport { createPortal } from 'react-dom'\n\nexport type MenuItemProps = {\n onClick?: () => void,\n alignment?: 'left' | 'right',\n isDisabled?: boolean,\n className?: string,\n}\nexport const MenuItem = ({\n children,\n onClick,\n alignment = 'left',\n isDisabled = false,\n className\n }: PropsWithChildren<MenuItemProps>) => (\n <div\n className={clsx('block px-3 py-1.5 first:rounded-t-md last:rounded-b-md text-sm font-semibold text-nowrap', {\n 'text-right': alignment === 'right',\n 'text-left': alignment === 'left',\n 'text-disabled-text cursor-not-allowed': isDisabled,\n 'text-menu-text hover:bg-primary/20': !isDisabled,\n 'cursor-pointer': !!onClick,\n }, className)}\n onClick={onClick}\n >\n {children}\n </div>\n)\n\nfunction getScrollableParents(element) {\n const scrollables = []\n let parent = element.parentElement\n while (parent) {\n scrollables.push(parent)\n parent = parent.parentElement\n }\n return scrollables\n}\n\nexport type MenuBag = {\n isOpen: boolean,\n disabled: boolean,\n toggleOpen: () => void,\n close: () => void,\n}\n\nexport type MenuProps<T> = PropsWithBagFunctionOrChildren<MenuBag> & {\n trigger: (bag: MenuBag, ref: RefObject<T>) => ReactNode,\n /**\n * @default 'l'\n */\n alignmentHorizontal?: PopoverHorizontalAlignment,\n alignmentVertical?: PopoverVerticalAlignment,\n showOnHover?: boolean,\n menuClassName?: string,\n disabled?: boolean,\n}\n\n/**\n * A Menu Component to allow the user to see different functions\n */\nexport const Menu = <T extends HTMLElement>({\n trigger,\n children,\n alignmentHorizontal = 'leftInside',\n alignmentVertical = 'bottomOutside',\n showOnHover = false,\n disabled = false,\n menuClassName = '',\n }: MenuProps<T>) => {\n const { isHovered: isOpen, setIsHovered: setIsOpen } = useHoverState({ isDisabled: !showOnHover || disabled })\n const triggerRef = useRef<T>(null)\n const menuRef = useRef<HTMLDivElement>(null)\n useOutsideClick([triggerRef, menuRef], () => setIsOpen(false))\n\n const [isHidden, setIsHidden] = useState<boolean>(true)\n const bag: MenuBag = {\n isOpen,\n close: () => setIsOpen(false),\n toggleOpen: () => setIsOpen(prevState => !prevState),\n disabled,\n }\n\n const menuPosition = usePopoverPosition(\n triggerRef.current?.getBoundingClientRect(),\n { verticalAlignment: alignmentVertical, horizontalAlignment: alignmentHorizontal, disabled }\n )\n\n useEffect(() => {\n if (!isOpen) return\n\n const triggerEl = triggerRef.current\n if (!triggerEl) return\n\n const scrollableParents = getScrollableParents(triggerEl)\n\n const close = () => setIsOpen(false)\n scrollableParents.forEach((parent) => {\n parent.addEventListener('scroll', close)\n })\n window.addEventListener('resize', close)\n\n return () => {\n scrollableParents.forEach((parent) => {\n parent.removeEventListener('scroll', close)\n })\n window.removeEventListener('resize', close)\n }\n }, [isOpen, setIsOpen])\n\n useEffect(() => {\n if (isOpen) {\n setIsHidden(false)\n }\n }, [isOpen])\n\n return (\n <>\n {trigger(bag, triggerRef)}\n {createPortal((\n <div\n ref={menuRef}\n onClick={e => e.stopPropagation()}\n className={clsx(\n 'absolute rounded-md bg-menu-background text-menu-text shadow-around-lg shadow-strong z-[300]',\n {\n 'animate-pop-in': isOpen,\n 'animate-pop-out': !isOpen,\n 'hidden': isHidden,\n },\n menuClassName\n )}\n onAnimationEnd={() => {\n if (!isOpen) {\n setIsHidden(true)\n }\n }}\n style={{\n ...menuPosition\n }}\n >\n {BagFunctionUtil.resolve<MenuBag>(children, bag)}\n </div>\n ), document.body)}\n </>\n )\n}\n\n","import type { RefObject } from 'react'\nimport { useEffect } from 'react'\n\nexport const useOutsideClick = <Ts extends RefObject<HTMLElement>[]>(refs: Ts, handler: () => void) => {\n useEffect(() => {\n const listener = (event: MouseEvent | TouchEvent) => {\n // returning means not \"not clicking outside\"\n\n // if no target exists, return\n if (event.target === null) return\n // if the target is a ref's element or descendent thereof, return\n if (refs.some((ref) => !ref.current || ref.current.contains(event.target as Node))) {\n return\n }\n\n handler()\n }\n document.addEventListener('mousedown', listener)\n document.addEventListener('touchstart', listener)\n return () => {\n document.removeEventListener('mousedown', listener)\n document.removeEventListener('touchstart', listener)\n }\n }, [refs, handler])\n}\n","import type { Dispatch, SetStateAction } from 'react'\nimport { useEffect, useState } from 'react'\n\ntype UseHoverStateProps = {\n /**\n * The delay after which the menu is closed in milliseconds\n *\n * default: 200ms\n */\n closingDelay: number,\n /**\n * Whether the hover state management should be disabled\n *\n * default: false\n */\n isDisabled: boolean,\n}\n\ntype UseHoverStateReturnType = {\n /**\n * Whether the element is hovered\n */\n isHovered: boolean,\n /**\n * Function to change the current hover status\n */\n setIsHovered: Dispatch<SetStateAction<boolean>>,\n /**\n * Handlers to pass on to the component that should be hovered\n */\n handlers: {\n onMouseEnter: () => void,\n onMouseLeave: () => void,\n },\n}\n\nconst defaultUseHoverStateProps: UseHoverStateProps = {\n closingDelay: 200,\n isDisabled: false,\n}\n\n/**\n * @param props See UseHoverStateProps\n *\n * A react hook for managing the hover state of a component. The handlers provided should be\n * forwarded to the component which should be hovered over\n */\nexport const useHoverState = (props: Partial<UseHoverStateProps> | undefined = undefined): UseHoverStateReturnType => {\n const { closingDelay, isDisabled } = { ...defaultUseHoverStateProps, ...props }\n\n const [isHovered, setIsHovered] = useState(false)\n const [timer, setTimer] = useState<NodeJS.Timeout>()\n\n const onMouseEnter = () => {\n if (isDisabled) {\n return\n }\n clearTimeout(timer)\n setIsHovered(true)\n }\n\n const onMouseLeave = () => {\n if (isDisabled) {\n return\n }\n setTimer(setTimeout(() => {\n setIsHovered(false)\n }, closingDelay))\n }\n\n useEffect(() => {\n if (timer) {\n return () => {\n clearTimeout(timer)\n }\n }\n })\n\n useEffect(() => {\n if (timer) {\n clearTimeout(timer)\n }\n }, [isDisabled]) // eslint-disable-line react-hooks/exhaustive-deps\n\n return {\n isHovered, setIsHovered, handlers: { onMouseEnter, onMouseLeave }\n }\n}\n","import type { ReactNode } from 'react'\n\nexport type BagFunction<T> = (bag: T) => ReactNode\n\nexport type PropsWithBagFunction<T, P = unknown> = P & { children?: BagFunction<T> }\n\nexport type PropsWithBagFunctionOrChildren<T, P = unknown> = P & { children?: BagFunction<T> | ReactNode }\n\nconst resolve = <T>(children: BagFunction<T> | ReactNode, bag: T): ReactNode => {\n if (typeof children === 'function') {\n return (children as BagFunction<T>)(bag)\n }\n\n return children ?? undefined\n}\n\nexport const BagFunctionUtil = {\n resolve\n}","import type { CSSProperties } from 'react'\n\nexport type PopoverHorizontalAlignment = 'leftOutside' | 'leftInside' | 'rightOutside' | 'rightInside' | 'center'\nexport type PopoverVerticalAlignment = 'topOutside' | 'topInside' | 'bottomOutside' | 'bottomInside' | 'center'\n\ntype PopoverPositionOptionsResolved = {\n edgePadding: number,\n outerGap: number,\n verticalAlignment: PopoverVerticalAlignment,\n horizontalAlignment: PopoverHorizontalAlignment,\n disabled: boolean,\n}\n\ntype PopoverPositionOptions = Partial<PopoverPositionOptionsResolved>\n\nconst defaultPopoverPositionOptions: PopoverPositionOptionsResolved = {\n edgePadding: 16,\n outerGap: 4,\n horizontalAlignment: 'leftInside',\n verticalAlignment: 'bottomOutside',\n disabled: false,\n}\n\nexport const usePopoverPosition = (trigger?: DOMRect, options?: PopoverPositionOptions): CSSProperties => {\n const {\n edgePadding,\n outerGap,\n verticalAlignment,\n horizontalAlignment,\n disabled\n }: PopoverPositionOptionsResolved = { ...defaultPopoverPositionOptions, ...options }\n\n if (disabled || !trigger) {\n return {}\n }\n\n const left: number = {\n leftOutside: trigger.left - outerGap,\n leftInside: trigger.left,\n rightOutside: trigger.right + outerGap,\n rightInside: trigger.right,\n center: trigger.left + trigger.width / 2,\n }[horizontalAlignment]\n\n const top: number = {\n topOutside: trigger.top - outerGap,\n topInside: trigger.top,\n bottomOutside: trigger.bottom + outerGap,\n bottomInside: trigger.bottom,\n center: trigger.top + trigger.height / 2,\n }[verticalAlignment]\n\n const translateX: string | undefined = {\n leftOutside: '-100%',\n leftInside: undefined,\n rightOutside: undefined,\n rightInside: '-100%',\n center: '-50%',\n }[horizontalAlignment]\n\n const translateY: string | undefined = {\n topOutside: '-100%',\n topInside: undefined,\n bottomOutside: undefined,\n bottomInside: '-100%',\n center: '-50%',\n }[verticalAlignment]\n\n return {\n left: Math.max(left, edgePadding),\n top: Math.max(top, edgePadding),\n translate: [translateX ?? '0', translateY ?? '0'].join(' ')\n }\n}","import type { Dispatch, PropsWithChildren, SetStateAction } from 'react'\nimport { createContext, useContext, useEffect, useState } from 'react'\nimport { useLocalStorage } from '../hooks/useLocalStorage'\nimport type { Language } from './util'\nimport { LanguageUtil } from './util'\n\nexport type LanguageContextValue = {\n language: Language,\n setLanguage: Dispatch<SetStateAction<Language>>,\n}\n\nexport const LanguageContext = createContext<LanguageContextValue>({\n language: LanguageUtil.DEFAULT_LANGUAGE,\n setLanguage: (v) => v\n})\n\nexport const useLanguage = () => useContext(LanguageContext)\n\nexport const useLocale = (overWriteLanguage?: Language) => {\n const { language } = useLanguage()\n const mapping: Record<Language, string> = {\n en: 'en-US',\n de: 'de-DE'\n }\n return mapping[overWriteLanguage ?? language]\n}\n\ntype LanguageProviderProps = {\n initialLanguage?: Language,\n}\n\nexport const LanguageProvider = ({ initialLanguage, children }: PropsWithChildren<LanguageProviderProps>) => {\n const [language, setLanguage] = useState<Language>(initialLanguage ?? LanguageUtil.DEFAULT_LANGUAGE)\n const [storedLanguage, setStoredLanguage] = useLocalStorage<Language>('language', initialLanguage ?? LanguageUtil.DEFAULT_LANGUAGE)\n\n useEffect(() => {\n if (language !== initialLanguage && initialLanguage) {\n console.warn('LanguageProvider initial state changed: Prefer using languageProvider\\'s setLanguage instead')\n setLanguage(initialLanguage)\n }\n }, [initialLanguage]) // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n document.documentElement.setAttribute('lang', language)\n setStoredLanguage(language)\n }, [language]) // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n if (storedLanguage !== null) {\n setLanguage(storedLanguage)\n return\n }\n\n const LanguageToTestAgainst = Object.values(LanguageUtil.languages)\n\n const matchingBrowserLanguage = window.navigator.languages\n .map(language => LanguageToTestAgainst.find((test) => language === test || language.split('-')[0] === test))\n .filter(entry => entry !== undefined)\n\n if (matchingBrowserLanguage.length === 0) return\n\n const firstMatch = matchingBrowserLanguage[0] as Language\n setLanguage(firstMatch)\n }, []) // eslint-disable-line react-hooks/exhaustive-deps\n\n return (\n <LanguageContext.Provider value={{\n language,\n setLanguage\n }}>\n {children}\n </LanguageContext.Provider>\n )\n}","'use client'\n\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useCallback, useState } from 'react'\nimport { LocalStorageService } from '../util/storage'\nimport { resolveSetState } from '../util/resolveSetState'\n\ntype SetValue<T> = Dispatch<SetStateAction<T>>\nexport const useLocalStorage = <T>(key: string, initValue: T): [T, SetValue<T>] => {\n const get = useCallback((): T => {\n if (typeof window === 'undefined') {\n return initValue\n }\n const storageService = new LocalStorageService()\n const value = storageService.get<T>(key)\n return value || initValue\n }, [initValue, key])\n\n const [storedValue, setStoredValue] = useState<T>(get)\n\n const setValue: SetValue<T> = useCallback(action => {\n const newValue = resolveSetState(action, storedValue)\n const storageService = new LocalStorageService()\n storageService.set(key, newValue)\n\n setStoredValue(newValue)\n }, [storedValue, setStoredValue, key])\n\n return [storedValue, setValue]\n}","/**\n * The supported languages\n */\nconst languages = ['en', 'de'] as const\n\n/**\n * The supported languages\n */\nexport type Language = typeof languages[number]\n\n/**\n * The supported languages' names in their respective language\n */\nconst languagesLocalNames: Record<Language, string> = {\n en: 'English',\n de: 'Deutsch',\n}\n\n/**\n * The default language\n */\nconst DEFAULT_LANGUAGE: Language = 'en'\n\n/**\n * A constant definition for holding data regarding languages\n */\nexport const LanguageUtil = {\n languages,\n DEFAULT_LANGUAGE,\n languagesLocalNames,\n}","import { useLanguage } from './LanguageProvider'\nimport type { Language } from './util'\n\n/**\n * A type describing the pluralization of a word\n */\nexport type TranslationPlural = {\n zero?: string,\n one?: string,\n two?: string,\n few?: string,\n many?: string,\n other: string,\n}\n\n/**\n * The type describing all values of a translation\n */\nexport type TranslationType = Record<string, string | TranslationPlural>\n\n/**\n * The type of translations\n */\nexport type Translation<T extends TranslationType> = Record<Language, T>\n\ntype OverwriteTranslationType<T extends TranslationType> = {\n language?: Language,\n translation?: Translation<Partial<T>>,\n}\n\n/**\n * Adds the `language` prop to the component props.\n *\n * @param Translation the type of the translation object\n *\n * @param Props the type of the component props, defaults to `Record<string, never>`,\n * if you don't expect any other props other than `language` and get an\n * error when using your component (because it uses `forwardRef` etc.)\n * you can try out `Record<string, unknown>`, this might resolve your\n * problem as `SomeType & never` is still `never` but `SomeType & unknown`\n * is `SomeType` which means that adding back props (like `ref` etc.)\n * works properly\n */\nexport type PropsForTranslation<\n Translation extends TranslationType,\n Props = unknown\n> = Props & {\n overwriteTranslation?: OverwriteTranslationType<Translation>,\n}\n\ntype StringKeys<T> = Extract<keyof T, string>;\n\ntype TranslationFunctionOptions = {\n replacements?: Record<string, string>,\n count?: number,\n}\ntype TranslationFunction<T extends TranslationType> = (key: StringKeys<T>, options?: TranslationFunctionOptions) => string\n\nexport const TranslationPluralCount = {\n zero: 0,\n one: 1,\n two: 2,\n few: 3,\n many: 11,\n other: -1,\n}\n\n\nexport const useTranslation = <T extends TranslationType>(\n translations: Translation<Partial<TranslationType>>[],\n overwriteTranslation: OverwriteTranslationType<T> = {}\n): TranslationFunction<T> => {\n const { language: languageProp, translation: overwrite } = overwriteTranslation\n const { language: inferredLanguage } = useLanguage()\n const usedLanguage = languageProp ?? inferredLanguage\n const usedTranslations = [...translations]\n if (overwrite) {\n usedTranslations.push(overwrite)\n }\n\n return (key: StringKeys<T>, options?: TranslationFunctionOptions): string => {\n const { count, replacements } = { ...{ count: 0, replacements: {} }, ...options }\n\n try {\n for (let i = translations.length - 1; i >= 0; i--) {\n const translation = translations[i]\n const localizedTranslation = translation[usedLanguage]\n if (!localizedTranslation) {\n continue\n }\n const value = localizedTranslation[key]\n if(!value) {\n continue\n }\n\n let forProcessing: string\n if (typeof value !== 'string') {\n if (count === TranslationPluralCount.zero && value?.zero) {\n forProcessing = value.zero\n } else if (count === TranslationPluralCount.one && value?.one) {\n forProcessing = value.one\n } else if (count === TranslationPluralCount.two && value?.two) {\n forProcessing = value.two\n } else if (TranslationPluralCount.few <= count && count < TranslationPluralCount.many && value?.few) {\n forProcessing = value.few\n } else if (count > TranslationPluralCount.many && value?.many) {\n forProcessing = value.many\n } else {\n forProcessing = value.other\n }\n } else {\n forProcessing = value\n }\n forProcessing = forProcessing.replace(/\\{\\{(\\w+)}}/g, (_, placeholder) => {\n return replacements[placeholder] ?? `{{key:${placeholder}}}` // fallback if key is missing\n })\n return forProcessing\n }\n } catch (e) {\n console.error(e)\n }\n return `{{${usedLanguage}:${key}}}`\n }\n}","import type { Translation } from '../useTranslation'\n\nexport type FormTranslationType = {\n add: string,\n all: string,\n apply: string,\n back: string,\n cancel: string,\n cha