Icon field validation
This commit is contained in:
parent
5afdea7010
commit
ff9c1926d5
|
@ -10,6 +10,7 @@
|
|||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@fontsource/vollkorn": "5.0.20",
|
||||
"@iconify-json/material-symbols": "^1.1.79",
|
||||
"@payloadcms/bundler-webpack": "1.0.6",
|
||||
"@payloadcms/db-mongodb": "1.5.1",
|
||||
"@payloadcms/richtext-lexical": "0.10.0",
|
||||
|
@ -1960,6 +1961,19 @@
|
|||
"@hapi/hoek": "^9.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@iconify-json/material-symbols": {
|
||||
"version": "1.1.79",
|
||||
"resolved": "https://registry.npmjs.org/@iconify-json/material-symbols/-/material-symbols-1.1.79.tgz",
|
||||
"integrity": "sha512-/OvCxrxPQ/qncjGAPZkNk6LEpVX1nIK6e6BhMsbXMT5pEpnrePsRsVOYsiB8bJn3x67HP8zBrxZSYisDCKf8ow==",
|
||||
"dependencies": {
|
||||
"@iconify/types": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@iconify/types": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@iconify/types/-/types-2.0.0.tgz",
|
||||
"integrity": "sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg=="
|
||||
},
|
||||
"node_modules/@img/sharp-darwin-arm64": {
|
||||
"version": "0.33.3",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.33.3.tgz",
|
||||
|
@ -4316,9 +4330,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/acorn": {
|
||||
"version": "8.10.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz",
|
||||
"integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==",
|
||||
"version": "8.11.3",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz",
|
||||
"integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==",
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
|
@ -12351,14 +12365,15 @@
|
|||
}
|
||||
},
|
||||
"node_modules/svgo": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/svgo/-/svgo-3.0.2.tgz",
|
||||
"integrity": "sha512-Z706C1U2pb1+JGP48fbazf3KxHrWOsLme6Rv7imFBn5EnuanDW1GPaA/P1/dvObE670JDePC3mnj0k0B7P0jjQ==",
|
||||
"version": "3.3.2",
|
||||
"resolved": "https://registry.npmjs.org/svgo/-/svgo-3.3.2.tgz",
|
||||
"integrity": "sha512-OoohrmuUlBs8B8o6MB2Aevn+pRIH9zDALSR+6hhqVfa6fRwG/Qw9VUMSMW9VNg2CFc/MTIfabtdOVl9ODIJjpw==",
|
||||
"dependencies": {
|
||||
"@trysound/sax": "0.2.0",
|
||||
"commander": "^7.2.0",
|
||||
"css-select": "^5.1.0",
|
||||
"css-tree": "^2.2.1",
|
||||
"css-tree": "^2.3.1",
|
||||
"css-what": "^6.1.0",
|
||||
"csso": "^5.0.5",
|
||||
"picocolors": "^1.0.0"
|
||||
},
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@fontsource/vollkorn": "5.0.20",
|
||||
"@iconify-json/material-symbols": "^1.1.79",
|
||||
"@payloadcms/bundler-webpack": "1.0.6",
|
||||
"@payloadcms/db-mongodb": "1.5.1",
|
||||
"@payloadcms/richtext-lexical": "0.10.0",
|
||||
|
|
|
@ -115,6 +115,7 @@ export const Pages = buildVersionedCollectionConfig({
|
|||
},
|
||||
editor: createEditor({
|
||||
images: true,
|
||||
relations: true,
|
||||
inlines: true,
|
||||
alignment: true,
|
||||
blocks: [sectionBlock, transcriptBlock, breakBlock],
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import { icons } from "@iconify-json/material-symbols";
|
||||
import { TextField } from "payload/types";
|
||||
|
||||
type Props = Omit<TextField, "type" | "hasMany" | "maxRows" | "minRows">;
|
||||
|
||||
const validNames = Object.keys(icons.icons).map((name) => `material-symbols:${name}`);
|
||||
|
||||
export const iconField = (props: Props): TextField => ({
|
||||
...props,
|
||||
type: "text",
|
||||
|
@ -9,4 +12,10 @@ export const iconField = (props: Props): TextField => ({
|
|||
description:
|
||||
"Select an icon from here: https://icones.js.org/collection/material-symbols. Only outline and regular variants are usable on the website.",
|
||||
},
|
||||
validate: (value) => {
|
||||
if (!validNames.includes(value)) {
|
||||
return `The icon "${value}" doesn't exist in material-symbols`;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue