utils.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use client";
  2. import { useState } from "react";
  3. // Shared animation class
  4. export const baseClass =
  5. "animate-in fade-in slide-in-from-bottom-1 duration-200";
  6. // Helper to get custom classes
  7. export function getCustomClass(props: Record<string, unknown>): string {
  8. return Array.isArray(props.className)
  9. ? (props.className as string[]).join(" ")
  10. : "";
  11. }
  12. // State for interactive components
  13. let openSelect: string | null = null;
  14. let setOpenSelect: (v: string | null) => void = () => {};
  15. let selectValues: Record<string, string> = {};
  16. let setSelectValues: (
  17. fn: (prev: Record<string, string>) => Record<string, string>,
  18. ) => void = () => {};
  19. export function useInteractiveState() {
  20. const [_openSelect, _setOpenSelect] = useState<string | null>(null);
  21. const [_selectValues, _setSelectValues] = useState<Record<string, string>>(
  22. {},
  23. );
  24. openSelect = _openSelect;
  25. setOpenSelect = _setOpenSelect;
  26. selectValues = _selectValues;
  27. setSelectValues = _setSelectValues;
  28. return { openSelect, selectValues };
  29. }
  30. export function getOpenSelect() {
  31. return openSelect;
  32. }
  33. export function setOpenSelectValue(v: string | null) {
  34. setOpenSelect(v);
  35. }
  36. export function getSelectValue(key: string) {
  37. return selectValues[key];
  38. }
  39. export function setSelectValueForKey(key: string, value: string) {
  40. setSelectValues((prev) => ({ ...prev, [key]: value }));
  41. }