@firecms/ui 3.0.1 → 3.1.0-canary.24c8270

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +9 -7
  2. package/dist/components/Card.d.ts +1 -1
  3. package/dist/components/ColorPicker.d.ts +30 -0
  4. package/dist/components/DateTimeField.d.ts +7 -0
  5. package/dist/components/Dialog.d.ts +2 -1
  6. package/dist/components/FileUpload.d.ts +1 -1
  7. package/dist/components/Menu.d.ts +2 -1
  8. package/dist/components/Menubar.d.ts +2 -1
  9. package/dist/components/MultiSelect.d.ts +2 -1
  10. package/dist/components/SearchBar.d.ts +11 -1
  11. package/dist/components/Select.d.ts +2 -1
  12. package/dist/components/Sheet.d.ts +1 -0
  13. package/dist/components/ToggleButtonGroup.d.ts +30 -0
  14. package/dist/components/index.d.ts +2 -0
  15. package/dist/hooks/PortalContainerContext.d.ts +31 -0
  16. package/dist/hooks/index.d.ts +1 -0
  17. package/dist/hooks/useOutsideAlerter.d.ts +1 -1
  18. package/dist/index.css +57 -6
  19. package/dist/index.es.js +1731 -949
  20. package/dist/index.es.js.map +1 -1
  21. package/dist/index.umd.js +1731 -949
  22. package/dist/index.umd.js.map +1 -1
  23. package/dist/styles.d.ts +11 -11
  24. package/package.json +7 -7
  25. package/src/components/BooleanSwitch.tsx +3 -3
  26. package/src/components/Button.tsx +5 -5
  27. package/src/components/Card.tsx +7 -7
  28. package/src/components/Checkbox.tsx +1 -1
  29. package/src/components/ColorPicker.tsx +134 -0
  30. package/src/components/DateTimeField.tsx +123 -34
  31. package/src/components/DebouncedTextField.tsx +3 -3
  32. package/src/components/Dialog.tsx +25 -16
  33. package/src/components/DialogActions.tsx +1 -1
  34. package/src/components/ExpandablePanel.tsx +1 -1
  35. package/src/components/FileUpload.tsx +25 -24
  36. package/src/components/IconButton.tsx +3 -2
  37. package/src/components/Menu.tsx +44 -30
  38. package/src/components/Menubar.tsx +14 -3
  39. package/src/components/MultiSelect.tsx +91 -74
  40. package/src/components/Popover.tsx +11 -3
  41. package/src/components/SearchBar.tsx +37 -19
  42. package/src/components/Select.tsx +86 -73
  43. package/src/components/Separator.tsx +2 -2
  44. package/src/components/Sheet.tsx +12 -3
  45. package/src/components/Slider.tsx +4 -4
  46. package/src/components/Table.tsx +1 -1
  47. package/src/components/Tabs.tsx +121 -36
  48. package/src/components/TextField.tsx +19 -8
  49. package/src/components/ToggleButtonGroup.tsx +67 -0
  50. package/src/components/Tooltip.tsx +9 -2
  51. package/src/components/index.tsx +2 -0
  52. package/src/hooks/PortalContainerContext.tsx +48 -0
  53. package/src/hooks/index.ts +1 -0
  54. package/src/hooks/useInjectStyles.tsx +12 -3
  55. package/src/hooks/useOutsideAlerter.tsx +1 -1
  56. package/src/index.css +57 -6
  57. package/src/styles.ts +11 -11
  58. package/src/util/cls.ts +1 -1
  59. package/tailwind.config.js +2 -3
@@ -1,7 +1,6 @@
1
1
  "use client";
2
2
  import React, { ForwardedRef, forwardRef, useEffect, useRef } from "react";
3
3
 
4
- import { TextareaAutosize } from "./TextareaAutosize";
5
4
  import {
6
5
  fieldBackgroundDisabledMixin,
7
6
  fieldBackgroundHoverMixin,
@@ -85,10 +84,16 @@ export const TextField = forwardRef<HTMLDivElement, TextFieldProps<string | numb
85
84
 
86
85
  const inputRef = inputRefProp ?? useRef(null);
87
86
 
88
- // @ts-ignore
89
- const [focused, setFocused] = React.useState(document.activeElement === inputRef.current);
87
+ const [focused, setFocused] = React.useState(false);
90
88
  const hasValue = value !== undefined && value !== null && value !== "";
91
89
 
90
+ useEffect(() => {
91
+ // @ts-ignore
92
+ if (inputRef.current && document.activeElement === inputRef.current) {
93
+ setFocused(true);
94
+ }
95
+ }, []);
96
+
92
97
  useEffect(() => {
93
98
  if (type !== "number") return;
94
99
  const handleWheel = (event: any) => {
@@ -105,19 +110,21 @@ export const TextField = forwardRef<HTMLDivElement, TextFieldProps<string | numb
105
110
  }, [inputRef, type]);
106
111
 
107
112
  const input = multiline ? (
108
- <TextareaAutosize
113
+ <textarea
109
114
  {...(inputProps as any)}
110
115
  ref={inputRef}
111
116
  placeholder={focused || hasValue || !label ? placeholder : undefined}
112
117
  autoFocus={autoFocus}
113
- minRows={minRows}
114
- maxRows={maxRows}
118
+ rows={typeof minRows === "string" ? parseInt(minRows) : (minRows ?? 3)}
115
119
  value={value ?? ""}
116
120
  onChange={onChange}
121
+ onFocus={() => setFocused(true)}
122
+ onBlur={() => setFocused(false)}
117
123
  style={inputStyle}
118
124
  className={cls(
119
125
  invisible ? focusedInvisibleMixin : "",
120
- "rounded-md resize-none w-full outline-none p-[32px] text-base bg-transparent min-h-[64px] px-3 pt-8",
126
+ "rounded-md resize-none w-full outline-none text-base bg-transparent min-h-[64px] px-3",
127
+ label ? "pt-8 pb-2" : "py-2",
121
128
  disabled && "outline-none opacity-50 text-surface-accent-600 dark:text-surface-accent-500",
122
129
  inputClassName
123
130
  )}
@@ -144,7 +151,11 @@ export const TextField = forwardRef<HTMLDivElement, TextFieldProps<string | numb
144
151
  ? size === "large"
145
152
  ? "pt-8 pb-2"
146
153
  : "pt-4 pb-2"
147
- : "py-2",
154
+ : size === "smallest"
155
+ ? "py-0.5"
156
+ : size === "small"
157
+ ? "py-1"
158
+ : "py-2",
148
159
  endAdornment ? "pr-12" : "pr-3",
149
160
  disabled &&
150
161
  "outline-none opacity-65 dark:opacity-60 text-surface-accent-800 dark:text-white",
@@ -0,0 +1,67 @@
1
+ import React from "react";
2
+ import { cls } from "../util";
3
+
4
+ export type ToggleButtonOption<T extends string = string> = {
5
+ value: T;
6
+ label: string;
7
+ icon?: React.ReactNode;
8
+ disabled?: boolean;
9
+ }
10
+
11
+ export type ToggleButtonGroupProps<T extends string = string> = {
12
+ /**
13
+ * Currently selected value
14
+ */
15
+ value: T;
16
+ /**
17
+ * Callback when value changes
18
+ */
19
+ onValueChange: (value: T) => void;
20
+ /**
21
+ * Options to display
22
+ */
23
+ options: ToggleButtonOption<T>[];
24
+ /**
25
+ * Additional class names for the container
26
+ */
27
+ className?: string;
28
+ }
29
+
30
+ /**
31
+ * A toggle button group component for selecting one option from a set.
32
+ * Displays options as buttons in a horizontal row with active state styling.
33
+ */
34
+ export function ToggleButtonGroup<T extends string = string>({
35
+ value,
36
+ onValueChange,
37
+ options,
38
+ className
39
+ }: ToggleButtonGroupProps<T>) {
40
+ return (
41
+ <div className={cls("inline-flex flex-row bg-surface-100 dark:bg-surface-800 rounded-lg p-1 gap-1", className)}>
42
+ {options.map((option) => (
43
+ <button
44
+ key={option.value}
45
+ type="button"
46
+ onClick={(e) => {
47
+ e.stopPropagation();
48
+ if (!option.disabled) {
49
+ onValueChange(option.value);
50
+ }
51
+ }}
52
+ disabled={option.disabled}
53
+ className={cls(
54
+ "flex flex-row items-center justify-center gap-2 py-3 px-4 rounded-md transition-colors",
55
+ value === option.value
56
+ ? "bg-white dark:bg-surface-950 text-primary dark:text-primary-300"
57
+ : "text-surface-500 dark:text-surface-400 hover:bg-surface-100 dark:hover:bg-surface-700",
58
+ option.disabled && "opacity-50 cursor-not-allowed"
59
+ )}
60
+ >
61
+ {option.icon}
62
+ <span className="text-sm font-medium">{option.label}</span>
63
+ </button>
64
+ ))}
65
+ </div>
66
+ );
67
+ }
@@ -4,6 +4,7 @@ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
4
4
 
5
5
  import { cls } from "../util";
6
6
  import { useInjectStyles } from "../hooks";
7
+ import { usePortalContainer } from "../hooks/PortalContainerContext";
7
8
 
8
9
  export type TooltipProps = {
9
10
  open?: boolean,
@@ -43,6 +44,12 @@ export const Tooltip = ({
43
44
 
44
45
  useInjectStyles("Tooltip", styles);
45
46
 
47
+ // Get the portal container from context
48
+ const contextContainer = usePortalContainer();
49
+
50
+ // Prioritize manual prop, fallback to context container
51
+ const finalContainer = (container ?? contextContainer ?? undefined) as HTMLElement | undefined;
52
+
46
53
  if (!title)
47
54
  return <>{children}</>;
48
55
 
@@ -60,11 +67,11 @@ export const Tooltip = ({
60
67
  <TooltipPrimitive.Provider delayDuration={delayDuration}>
61
68
  <TooltipPrimitive.Root open={open} onOpenChange={onOpenChange} defaultOpen={defaultOpen}>
62
69
  {trigger}
63
- <TooltipPrimitive.Portal container={container}>
70
+ <TooltipPrimitive.Portal container={finalContainer}>
64
71
  <TooltipPrimitive.Content
65
72
  className={cls("TooltipContent",
66
73
  "max-w-lg leading-relaxed",
67
- "z-50 rounded px-3 py-2 text-xs leading-none bg-surface-accent-700 dark:bg-surface-accent-800 bg-opacity-90 font-medium text-surface-accent-50 shadow-2xl select-none duration-400 ease-in transform opacity-100",
74
+ "z-50 rounded px-3 py-2 text-xs leading-none bg-surface-accent-700 dark:bg-surface-accent-800 bg-opacity-90 bg-surface-accent-700/90 dark:bg-surface-accent-800/90 font-medium text-surface-accent-50 shadow-2xl select-none duration-400 ease-in transform opacity-100",
68
75
  tooltipClassName)}
69
76
  style={tooltipStyle}
70
77
  sideOffset={sideOffset === undefined ? 4 : sideOffset}
@@ -11,6 +11,7 @@ export * from "./Collapse";
11
11
  export * from "./CircularProgress";
12
12
  export * from "./Checkbox";
13
13
  export * from "./Chip";
14
+ export * from "./ColorPicker";
14
15
  export * from "./DateTimeField";
15
16
  export * from "./Dialog";
16
17
  export * from "./DialogActions";
@@ -44,4 +45,5 @@ export * from "./Popover";
44
45
  export * from "./Badge";
45
46
  export * from "./DebouncedTextField";
46
47
  export * from "./Skeleton";
48
+ export * from "./ToggleButtonGroup";
47
49
 
@@ -0,0 +1,48 @@
1
+ "use client";
2
+ import React, { createContext, useContext } from "react";
3
+
4
+ export interface PortalContainerContextType {
5
+ container: HTMLElement | null;
6
+ }
7
+
8
+ const PortalContainerContext = createContext<PortalContainerContextType | undefined>(undefined);
9
+
10
+ export interface PortalContainerProviderProps {
11
+ container: HTMLElement | null;
12
+ children: React.ReactNode;
13
+ }
14
+
15
+ /**
16
+ * Provider component that sets the portal container for all descendants.
17
+ * This can be used at any level of the tree to specify where portals should be attached.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * const containerRef = useRef<HTMLDivElement>(null);
22
+ *
23
+ * <div ref={containerRef}>
24
+ * <PortalContainerProvider container={containerRef.current}>
25
+ * <YourComponents />
26
+ * </PortalContainerProvider>
27
+ * </div>
28
+ * ```
29
+ */
30
+ export function PortalContainerProvider({ container, children }: PortalContainerProviderProps) {
31
+ return (
32
+ <PortalContainerContext.Provider value={{ container }}>
33
+ {children}
34
+ </PortalContainerContext.Provider>
35
+ );
36
+ }
37
+
38
+ /**
39
+ * Hook to access the portal container from context.
40
+ * Returns null if no provider is found in the tree.
41
+ *
42
+ * @returns The portal container element or null
43
+ */
44
+ export function usePortalContainer(): HTMLElement | null {
45
+ const context = useContext(PortalContainerContext);
46
+ return context?.container ?? null;
47
+ }
48
+
@@ -2,3 +2,4 @@ export * from "./useInjectStyles";
2
2
  export * from "./useOutsideAlerter";
3
3
  export * from "./useDebounceValue";
4
4
  export * from "./useIconStyles";
5
+ export * from "./PortalContainerContext";
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import { useEffect } from "react";
3
+ import { usePortalContainer } from "./PortalContainerContext";
3
4
 
4
5
  /**
5
6
  * Use this hook to create a `<style>` element and inject it into the DOM.
@@ -9,13 +10,21 @@ import { useEffect } from "react";
9
10
  */
10
11
  export function useInjectStyles(key: string, styles: string) {
11
12
 
13
+ const portalContainer = usePortalContainer();
14
+
12
15
  useEffect(() => {
13
- const styleElement = document.getElementById(key);
14
- if (!styleElement) {
16
+ if (typeof document === "undefined") return;
17
+
18
+ const targetContainer: HTMLElement | null = portalContainer ?? document.head;
19
+
20
+ // Try to find an existing style element within the target container first
21
+ const existingStyle = (targetContainer as HTMLElement).querySelector?.(`#${key}`) as HTMLStyleElement | null;
22
+
23
+ if (!existingStyle) {
15
24
  const style = document.createElement("style");
16
25
  style.id = key;
17
26
  style.innerHTML = styles;
18
- document.head.appendChild(style);
27
+ (targetContainer || document.head).appendChild(style);
19
28
  }
20
29
  }, []);
21
30
 
@@ -5,7 +5,7 @@ import { RefObject, useEffect } from "react";
5
5
  /**
6
6
  * Hook that alerts clicks outside the passed ref
7
7
  */
8
- export function useOutsideAlerter(ref: RefObject<HTMLElement>, onOutsideClick: () => void, active = true): void {
8
+ export function useOutsideAlerter(ref: RefObject<HTMLElement | null>, onOutsideClick: () => void, active = true): void {
9
9
  useEffect(() => {
10
10
  if (!active)
11
11
  return;
package/src/index.css CHANGED
@@ -1,3 +1,59 @@
1
+ @theme {
2
+ /* Font Families */
3
+ --font-sans: 'Rubik', 'Roboto', 'Helvetica', 'Arial', sans-serif;
4
+ --font-headers: 'Rubik', 'Roboto', 'Helvetica', 'Arial', sans-serif;
5
+ --font-mono: 'JetBrains Mono', 'Space Mono', 'Lucida Console', monospace;
6
+
7
+ /* Colors */
8
+ --color-primary: #0070F4;
9
+ --color-primary-light: oklch(from var(--color-primary) calc(l + 0.15) c h);
10
+ --color-primary-dark: oklch(from var(--color-primary) calc(l - 0.15) c h);
11
+ --color-secondary: #FF5B79;
12
+ --color-secondary-light: oklch(from var(--color-secondary) calc(l + 0.15) c h);
13
+ --color-secondary-dark: oklch(from var(--color-secondary) calc(l - 0.15) c h);
14
+
15
+ --color-primary-bg: oklch(from var(--color-primary) l c h / 0.1);
16
+ --color-secondary-bg: oklch(from var(--color-secondary) l c h / 0.1);
17
+
18
+ /* Field Colors */
19
+ --color-field-disabled: rgb(224 224 226);
20
+ --color-field-disabled-dark: rgb(35 35 37);
21
+
22
+ /* Text Colors */
23
+ --color-text-primary: rgba(0, 0, 0, 0.87);
24
+ --color-text-secondary: rgba(0, 0, 0, 0.52);
25
+ --color-text-disabled: rgba(0, 0, 0, 0.38);
26
+ --color-text-primary-dark: #ffffff;
27
+ --color-text-secondary-dark: rgba(255, 255, 255, 0.6);
28
+ --color-text-disabled-dark: rgba(255, 255, 255, 0.48);
29
+
30
+ /* Surface Colors */
31
+ --color-surface-50: #f8f8fc;
32
+ --color-surface-100: #e7e7eb;
33
+ --color-surface-200: #cfcfd6;
34
+ --color-surface-300: #b7b7bf;
35
+ --color-surface-400: #a0a0a9;
36
+ --color-surface-500: #87878f;
37
+ --color-surface-600: #6b6b74;
38
+ --color-surface-700: #454552;
39
+ --color-surface-800: #292934;
40
+ --color-surface-900: #18181c;
41
+ --color-surface-950: #101013;
42
+
43
+ /* Surface Accent Colors */
44
+ --color-surface-accent-50: #f8fafc;
45
+ --color-surface-accent-100: #f1f5f9;
46
+ --color-surface-accent-200: #e2e8f0;
47
+ --color-surface-accent-300: #cbd5e1;
48
+ --color-surface-accent-400: #94a3b8;
49
+ --color-surface-accent-500: #64748b;
50
+ --color-surface-accent-600: #475569;
51
+ --color-surface-accent-700: #334155;
52
+ --color-surface-accent-800: #1e293b;
53
+ --color-surface-accent-900: #0f172a;
54
+ --color-surface-accent-950: #020617;
55
+ }
56
+
1
57
  /* Chrome, Safari and Opera */
2
58
  .no-scrollbar::-webkit-scrollbar {
3
59
  display: none;
@@ -63,12 +119,7 @@
63
119
  @apply text-sm font-semibold uppercase;
64
120
  }
65
121
 
66
-
67
122
  :focus-visible {
68
- @apply outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-opacity-75 focus-visible:ring-offset-2 focus-visible:ring-offset-transparent
69
- }
70
-
71
- a {
72
- @apply text-blue-600 dark:text-blue-400 dark:hover:text-blue-600 hover:text-blue-800
123
+ @apply outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-transparent
73
124
  }
74
125
 
package/src/styles.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  export const focusedDisabled = "focus-visible:ring-0 focus-visible:ring-offset-0";
2
- export const focusedInvisibleMixin = "focus:bg-opacity-70 focus:bg-surface-accent-100 focus:dark:bg-surface-800 focus:dark:bg-opacity-60";
3
- export const focusedClasses = "z-30 outline-none ring-2 ring-primary ring-opacity-75 ring-offset-2 ring-offset-transparent ";
4
- export const fieldBackgroundMixin = "bg-opacity-50 bg-surface-accent-200 dark:bg-surface-800 dark:bg-opacity-60";
5
- export const fieldBackgroundInvisibleMixin = "bg-opacity-0 bg-surface-accent-100 dark:bg-surface-800 dark:bg-opacity-0";
6
- export const fieldBackgroundDisabledMixin = "dark:bg-surface-800 bg-opacity-50 dark:bg-opacity-90";
7
- export const fieldBackgroundHoverMixin = "hover:bg-opacity-70 dark:hover:bg-surface-700 dark:hover:bg-opacity-40";
8
- export const defaultBorderMixin = "border-surface-200 border-opacity-40 dark:border-surface-700 dark:border-opacity-40";
9
- export const paperMixin = "bg-white rounded-md dark:bg-surface-950 border border-surface-200 border-opacity-40 dark:border-surface-700 dark:border-opacity-40";
10
- export const cardMixin = "bg-white border border-surface-200 border-opacity-40 dark:border-transparent rounded-md dark:bg-surface-950 dark:border-surface-700 dark:border-opacity-40";
11
- export const cardClickableMixin = "hover:bg-surface-accent-100 dark:hover:bg-surface-accent-800 hover:ring-2 hover:ring-primary cursor-pointer";
12
- export const cardSelectedMixin = "bg-primary-bg dark:bg-primary-bg bg-opacity-30 dark:bg-opacity-10 ring-1 ring-primary ring-opacity-75";
2
+ export const focusedInvisibleMixin = "focus:bg-opacity-70 focus:bg-surface-accent-100 focus:dark:bg-surface-800 focus:dark:bg-opacity-60 focus:bg-surface-accent-100/70 dark:focus:bg-surface-800/60";
3
+ export const focusedClasses = "z-30 outline-hidden outline-none ring-2 ring-primary ring-opacity-75 ring-primary/75 ring-offset-2 ring-offset-transparent ";
4
+ export const fieldBackgroundMixin = "bg-opacity-50 bg-surface-accent-200 bg-surface-accent-200/50 dark:bg-surface-800 dark:bg-opacity-60 dark:bg-surface-800/60";
5
+ export const fieldBackgroundInvisibleMixin = "bg-opacity-0 bg-surface-accent-100 dark:bg-surface-800 dark:bg-opacity-0 bg-surface-accent-200/0 dark:bg-surface-800/0";
6
+ export const fieldBackgroundDisabledMixin = "dark:bg-surface-800 bg-opacity-50 dark:bg-opacity-90 bg-surface-accent-200/50 dark:bg-surface-800/90";
7
+ export const fieldBackgroundHoverMixin = "hover:bg-opacity-70 dark:hover:bg-surface-700 dark:hover:bg-opacity-40 hover:bg-surface-accent-200/70 hover:dark:bg-surface-700/40";
8
+ export const defaultBorderMixin = "border-surface-200 border-opacity-40 dark:border-surface-700 dark:border-opacity-40 border-surface-200/40 dark:border-surface-700/40 ";
9
+ export const paperMixin = "bg-white rounded-md dark:bg-surface-950 border border-surface-200 border-opacity-40 dark:border-surface-700 dark:border-opacity-40 border-surface-200/40 dark:border-surface-700/40";
10
+ export const cardMixin = "bg-white dark:bg-surface-950 rounded-md border border-surface-200/40 dark:border-surface-700/40 m-1 -p-1";
11
+ export const cardClickableMixin = "hover:bg-surface-accent-100 dark:hover:bg-surface-accent-800 hover:ring-2 hover:ring-primary cursor-pointer hover:bg-primary/20 dark:hover:bg-primary/10 ";
12
+ export const cardSelectedMixin = "bg-primary-bg dark:bg-primary-bg bg-opacity-30 bg-primary-bg/30 dark:bg-opacity-10 dark:bg-primary-bg/10 ring-1 ring-primary ring-opacity-75 ring-primary/75 bg-primary/10 dark:bg-primary/10 ring-1 ring-primary/75";
package/src/util/cls.ts CHANGED
@@ -2,7 +2,7 @@ import { type ClassValue, clsx } from "clsx";
2
2
  import { twMerge } from "tailwind-merge";
3
3
 
4
4
  export function cls(...classes: ClassValue[]) {
5
- return twMerge(clsx(classes))
5
+ return twMerge(clsx(classes));
6
6
  }
7
7
 
8
8
  /**
@@ -36,9 +36,8 @@ export default {
36
36
  ]
37
37
  },
38
38
  colors: {
39
- "primary": "var(--fcms-primary)",
40
- "primary-bg": "var(--fcms-primary-bg)",
41
- "secondary": "var(--fcms-secondary)",
39
+ "primary": "var(--color-primary)",
40
+ "secondary": "var(--color-secondary)",
42
41
  "field": {
43
42
  "disabled": "rgb(224 224 226)",
44
43
  "disabled-dark": "rgb(35 35 37)"