@firecms/ui 3.0.0-alpha.72 → 3.0.0-alpha.73

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.
@@ -1,3 +1,4 @@
1
1
  import { ChipColorKey, ChipColorScheme } from "../components";
2
2
  export declare const CHIP_COLORS: Record<string, ChipColorScheme>;
3
3
  export declare function getColorSchemeForKey(key: ChipColorKey): ChipColorScheme;
4
+ export declare function getColorSchemeForSeed(seed: string): ChipColorScheme;
@@ -0,0 +1 @@
1
+ export declare function hashString(str: string): number;
@@ -1,5 +1,6 @@
1
1
  export * from "./cn";
2
2
  export * from "./debounce";
3
3
  export * from "./chip_colors";
4
+ export * from "./key_to_icon_component";
4
5
  export * from "./useInjectStyles";
5
6
  export * from "./useOutsideAlerter";
@@ -0,0 +1 @@
1
+ export declare function keyToIconComponent(key: string): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@firecms/ui",
3
3
  "type": "module",
4
- "version": "3.0.0-alpha.72",
4
+ "version": "3.0.0-alpha.73",
5
5
  "description": "Awesome Firebase/Firestore-based headless open-source CMS",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/firecmsco"
@@ -101,7 +101,7 @@
101
101
  "dist",
102
102
  "src"
103
103
  ],
104
- "gitHead": "7f6599121c226abbb4fb4dccbe109b2c8ba6e23e",
104
+ "gitHead": "df625cc7bd6af087b7012d1c9ae77d3a6c17a320",
105
105
  "publishConfig": {
106
106
  "access": "public"
107
107
  }
@@ -4,13 +4,25 @@ import { cn } from "../util";
4
4
  export interface AlertProps {
5
5
  children: React.ReactNode;
6
6
  onDismiss?: () => void;
7
- color?: "error" | "warning" | "info" | "success";
7
+ color?: "error" | "warning" | "info" | "success" | "base";
8
+ size?: "small" | "medium" | "large";
8
9
  action?: React.ReactNode;
9
10
  className?: string;
10
11
  style?: React.CSSProperties;
11
12
  }
12
13
 
13
- const getClasses = (severity: string) => {
14
+ const getSizeClasses = (size: "small" | "medium" | "large") => {
15
+ switch (size) {
16
+ case "small":
17
+ return "px-2 py-1";
18
+ case "large":
19
+ return "px-6 py-4";
20
+ case "medium":
21
+ default:
22
+ return "px-4 py-2";
23
+ }
24
+ }
25
+ const getColorClasses = (severity: string) => {
14
26
  switch (severity) {
15
27
  case "error":
16
28
  return "bg-red-50 dark:bg-red-800 dark:text-red-100 text-red-900";
@@ -20,8 +32,9 @@ const getClasses = (severity: string) => {
20
32
  return "bg-blue-50 dark:bg-blue-800 dark:text-blue-100 text-blue-900";
21
33
  case "success":
22
34
  return "bg-emerald-50 dark:bg-emerald-800 dark:text-emerald-100 text-emerald-900";
35
+ case "base":
23
36
  default:
24
- return "bg-blue-50 dark:bg-blue-800 dark:text-blue-100 text-blue-900";
37
+ return "bg-slate-50 dark:bg-slate-800 dark:text-slate-100 text-slate-900";
25
38
  }
26
39
  };
27
40
 
@@ -29,16 +42,17 @@ export const Alert: React.FC<AlertProps> = ({
29
42
  children,
30
43
  onDismiss,
31
44
  color = "info",
45
+ size = "medium",
32
46
  action,
33
47
  className,
34
48
  style
35
49
  }) => {
36
- const classes = getClasses(color);
50
+ const classes = getColorClasses(color);
37
51
 
38
52
  return (
39
53
  <div
40
54
  style={style}
41
- className={cn("px-4 py-2 rounded-md flex items-center gap-2", classes, className)}
55
+ className={cn(getSizeClasses(size), "rounded-md flex items-center gap-2", classes, className)}
42
56
  >
43
57
  <span className={"flex-grow"}>{children}</span>
44
58
  {onDismiss && (
@@ -42,8 +42,8 @@ export function Chip({
42
42
  const usedColorScheme = typeof colorScheme === "string" ? getColorSchemeForKey(colorScheme) : colorScheme;
43
43
  return (
44
44
  <div
45
- className={cn("rounded-lg w-fit h-fit font-regular inline-flex items-center gap-1",
46
- "truncate",
45
+ className={cn("rounded-lg w-fit h-fit font-regular inline-flex gap-1",
46
+ "text-ellipsis",
47
47
  onClick ? "cursor-pointer hover:bg-gray-300 hover:dark:bg-gray-700" : "",
48
48
  sizeClassNames[size],
49
49
  error || !usedColorScheme ? "bg-gray-100 dark:bg-gray-800 text-gray-800 dark:text-gray-200" : "",
@@ -52,7 +52,11 @@ export function Chip({
52
52
  onClick={onClick}
53
53
  style={{
54
54
  backgroundColor: error || !usedColorScheme ? undefined : usedColorScheme.color,
55
- color: error || !usedColorScheme ? undefined : usedColorScheme.text
55
+ color: error || !usedColorScheme ? undefined : usedColorScheme.text,
56
+ overflow: "hidden",
57
+ // display: "-webkit-box",
58
+ // WebkitLineClamp: 1,
59
+ // WebkitBoxOrient: "vertical",
56
60
  }}
57
61
  >
58
62
  {children}
@@ -71,10 +71,11 @@ export function SearchBar({
71
71
  {loading ? <CircularProgress size={"small"}/> : <SearchIcon className={"text-gray-500"}/>}
72
72
  </div>
73
73
  <input
74
- value={searchText}
74
+ value={searchText ?? ""}
75
75
  ref={inputRef}
76
76
  onClick={onClick}
77
77
  placeholder={placeholder}
78
+ readOnly={!onTextSearch}
78
79
  onChange={onTextSearch
79
80
  ? (event) => {
80
81
  setSearchText(event.target.value);
@@ -7,8 +7,10 @@ import fs from "fs";
7
7
  import path from "path";
8
8
 
9
9
  import { fileURLToPath } from "url";
10
+ import { keyToIconComponent } from "../util/key_to_icon_component.ts";
10
11
  // import { iconKeys } from "../icons/icon_keys.ts";
11
12
 
13
+
12
14
  export function saveIconFiles(iconKeys: string[]) {
13
15
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
14
16
 
@@ -19,15 +21,7 @@ export function saveIconFiles(iconKeys: string[]) {
19
21
 
20
22
  // for each key, generate a file with an Icon ts component
21
23
  iconKeys.forEach((key: string) => {
22
-
23
- const startsWithNumber = key.match(/^\d/);
24
-
25
- // convert key to came case
26
- const componentName = (startsWithNumber ? "_" : "") +
27
- key.split("_").map((word: string) => {
28
- return word.charAt(0).toUpperCase() + word.slice(1);
29
- }).join("") +
30
- "Icon";
24
+ const componentName = keyToIconComponent(key);
31
25
 
32
26
  const iconComponent = `import React from "react";
33
27
  import { Icon, IconProps } from "../Icon";
@@ -1,4 +1,5 @@
1
1
  import { ChipColorKey, ChipColorScheme } from "../components";
2
+ import { hashString } from "./hash";
2
3
 
3
4
  export const CHIP_COLORS: Record<string, ChipColorScheme> = {
4
5
  blueLighter: { color: "#cfdfff", text: "#102046" },
@@ -49,3 +50,10 @@ export const CHIP_COLORS: Record<string, ChipColorScheme> = {
49
50
  export function getColorSchemeForKey(key: ChipColorKey): ChipColorScheme {
50
51
  return CHIP_COLORS[key];
51
52
  }
53
+
54
+ export function getColorSchemeForSeed(seed: string): ChipColorScheme {
55
+ const hash: number = hashString(seed);
56
+ const colorKeys = Object.keys(CHIP_COLORS);
57
+ const index = hash % colorKeys.length;
58
+ return CHIP_COLORS[colorKeys[index]];
59
+ }
@@ -0,0 +1,11 @@
1
+ export function hashString(str: string): number {
2
+ let hash = 0;
3
+ let i;
4
+ let chr;
5
+ for (i = 0; i < str.length; i++) {
6
+ chr = str.charCodeAt(i);
7
+ hash = ((hash << 5) - hash) + chr;
8
+ hash |= 0; // Convert to 32bit integer
9
+ }
10
+ return Math.abs(hash);
11
+ }
package/src/util/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./cn";
2
2
  export * from "./debounce";
3
3
  export * from "./chip_colors";
4
+ export * from "./key_to_icon_component";
4
5
  export * from "./useInjectStyles";
5
6
  export * from "./useOutsideAlerter";
@@ -0,0 +1,11 @@
1
+ export function keyToIconComponent(key: string) {
2
+ const startsWithNumber = key.match(/^\d/);
3
+
4
+ // convert key to came case
5
+ const componentName = (startsWithNumber ? "_" : "") +
6
+ key.split("_").map((word: string) => {
7
+ return word.charAt(0).toUpperCase() + word.slice(1);
8
+ }).join("") +
9
+ "Icon";
10
+ return componentName;
11
+ }