From 3fb01a3022a3f47c0e1e6e76771a35fce23a128b Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 29 Dec 2023 23:58:38 -0400 Subject: content: generateColorStyleAttribute --- .../dependencies/generateColorStyleAttribute.js | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/content/dependencies/generateColorStyleAttribute.js (limited to 'src/content/dependencies/generateColorStyleAttribute.js') diff --git a/src/content/dependencies/generateColorStyleAttribute.js b/src/content/dependencies/generateColorStyleAttribute.js new file mode 100644 index 00000000..af8633aa --- /dev/null +++ b/src/content/dependencies/generateColorStyleAttribute.js @@ -0,0 +1,37 @@ +export default { + contentDependencies: ['generateColorStyleVariables'], + extraDependencies: ['html'], + + relations: (relation) => ({ + colorVariables: + relation('generateColorStyleVariables'), + }), + + data: (color) => ({ + color: + color ?? null, + }), + + slots: { + color: { + validate: v => v.isColor, + }, + + context: { + validate: v => v.is( + 'any-content', + 'page-root', + 'primary-only'), + + default: 'any-content', + }, + }, + + generate: (data, relations, slots) => ({ + style: + relations.colorVariables.slots({ + color: slots.color ?? data.color, + context: slots.context, + }).content, + }), +}; -- cgit 1.3.0-6-gf8a5