Throw some initial version of code at the wall for the tabbed character sheet

This commit is contained in:
Oliver-Akins 2025-02-11 23:40:35 -07:00
parent eb6d7fee94
commit b72f22380f
10 changed files with 213 additions and 2 deletions

View file

@ -1,12 +1,16 @@
import { handlebarsLocalizer, localizer } from "../utils/Localizer.mjs";
import { formFields } from "./inputs/formFields.mjs";
import { options } from "./options.mjs";
import { toAttributes } from "./toAttributes.mjs";
import { toClasses } from "./toClasses.mjs";
export default {
// #region Complex
"rc-formFields": formFields,
"rc-i18n": handlebarsLocalizer,
"rc-options": options,
"rc-toAttributes": toAttributes,
"rc-toClasses": toClasses,
// #region Simple
"rc-empty-state": (v) => v ?? localizer(`RipCrypt.common.empty`),

View file

@ -0,0 +1,13 @@
/**
* Allows converting an object of <attribute names, value> into HTML
* attribute-value pairs that can be inserted into the DOM
*
* @param {Record<string, any>} obj The object of attributes to their value
*/
export function toAttributes(obj = {}) {
let attributes = [];
for (const [ attr, value] of Object.entries(obj)) {
attributes.push(`${attr}=${Handlebars.escapeExpression(value)}`);
};
return new Handlebars.SafeString(attributes.join(` `));
};

View file

@ -0,0 +1,14 @@
/**
* Allows converting an object of <class names, boolean-likes> into an HTML-compatible class list.
*
* @param {Record<string, any>} obj The object of class names to boolean-like values for if that class should be included.
*/
export function toClasses(obj = {}) {
let classes = [];
for (const [ klass, include ] of Object.entries(obj)) {
if (include) {
classes.push(klass);
};
};
return new Handlebars.SafeString(classes.join(` `));
};