Replies: 2 comments 3 replies
-
I'm also interested in this. Use case:
|
Beta Was this translation helpful? Give feedback.
-
This is a kinda hacky thing and @simonswiss will probably say it's a bad idea, but if you have a singleton that writes to a JSON file, you can import that JSON file from a collection schema and use it to build a Here's a sample where I built a font system that lets you specify any number of fonts to be available in the site: const fontLoader = fields.object({
fontName: fields.text({
label: "Font Name",
description: "this is the name you will use to select this font",
}),
uniqueID: customFields.uniquify({ label: "unique ID" }),
mode: fields.conditional(
fields.select({
label: "Font Type",
options: [
{ label: "Remote Font (Google Fonts or similar)", value: "remote" },
{ label: "Self-Hosted Font", value: "local" },
],
defaultValue: "remote",
}),
{
local: fields.empty(),
remote: fields.object({
htmlLink: customFields.codeEditor({
label: "HTML <link> code",
description:
"Copy the <link> embed code from Google Fonts or another platform and paste it here. You only need the third line from Google Fonts.",
wrap: true,
height: "10rem",
}),
fontFamily: fields.text({
label: "font-family",
description:
'The font-family line from Google Fonts. This should look like "DM Sans", sans-serif',
}),
}),
},
),
});
export const fonts = singleton({
label: "Link Fonts (Google or Adobe)",
format: { data: "json" },
path: "src/settings/fonts",
schema: {
fontLibrary: fields.array(fontLoader, {
itemLabel: (props) => props.fields.fontName.value,
}),
},
}); and here's the field (used elsewhere in the site) that loads the fonts from the json file and lets the user pick from them: import fontSettings from "../../../src/settings/fonts.json";
...
// below code is in list of fields
fontFamily: {
...fields.select({
label: "Font Family",
options: fontOptions,
defaultValue: "0",
}),
parse(value: string) {
console.log("parsing: " + value);
const isValidFont = fontOptions.find((item) => {
return item.value === value;
});
return isValidFont ? value : "0";
},
}, Note that I'm spreading the default |
Beta Was this translation helpful? Give feedback.
-
hey guys, is it possible to extend the relationship field to access singletons?
Beta Was this translation helpful? Give feedback.
All reactions