Allow icons to be optional

This commit is contained in:
DrMint 2024-05-12 23:18:28 +02:00
parent c745e18b5d
commit 3b05c1543a
1 changed files with 3 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import { icons } from "@iconify-json/material-symbols"; import { icons } from "@iconify-json/material-symbols";
import { TextField } from "payload/types"; import { TextField } from "payload/types";
import { isEmpty } from "../../utils/asserts";
type Props = Omit<TextField, "type" | "hasMany" | "maxRows" | "minRows">; type Props = Omit<TextField, "type" | "hasMany" | "maxRows" | "minRows">;
@ -12,7 +13,8 @@ export const iconField = (props: Props): TextField => ({
description: description:
"Select an icon from here: https://icones.js.org/collection/material-symbols. Only outline and regular variants are usable on the website.", "Select an icon from here: https://icones.js.org/collection/material-symbols. Only outline and regular variants are usable on the website.",
}, },
validate: (value) => { validate: async (value) => {
if (isEmpty(value)) return true;
if (!validNames.includes(value)) { if (!validNames.includes(value)) {
return `The icon "${value}" doesn't exist in material-symbols`; return `The icon "${value}" doesn't exist in material-symbols`;
} }