Update sigpro_ui.js
This commit is contained in:
@@ -1,17 +1,19 @@
|
|||||||
/**
|
/**
|
||||||
* SigPro 2.0 UI - daisyUI v5 & Tailwind v4 Plugin
|
* SigPro UI 2.0 - daisyUI v5 & Tailwind v4 Plugin
|
||||||
*/
|
*/
|
||||||
(() => {
|
(() => {
|
||||||
if (!window.$ || !window.$.use) return console.error("[SigPro UI] Core not found.");
|
if (!window.$) return console.error("[SigPro UI] Fatal: SigPro 2.0 Core not found.");
|
||||||
|
|
||||||
$.use(($) => {
|
$.use(($) => {
|
||||||
|
const ui = {};
|
||||||
|
|
||||||
const parseClass = (base, extra) => {
|
const parseClass = (base, extra) => {
|
||||||
if (typeof extra === 'function') return () => `${base} ${extra() || ''}`;
|
if (typeof extra === 'function') return () => `${base} ${extra() || ''}`;
|
||||||
return `${base} ${extra || ''}`;
|
return `${base} ${extra || ''}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @param {Object} p @param {any} [c] */
|
/** _button @param {Object} p @param {any} [c] */
|
||||||
$._button = (p, c) => button({
|
ui._button = (p, c) => button({
|
||||||
...p,
|
...p,
|
||||||
class: parseClass('btn', p.$class || p.class),
|
class: parseClass('btn', p.$class || p.class),
|
||||||
$disabled: () => p.$disabled?.() || p.$loading?.()
|
$disabled: () => p.$disabled?.() || p.$loading?.()
|
||||||
@@ -22,8 +24,8 @@
|
|||||||
p.badge && span({ class: `badge ${p.badgeClass || ''}` }, p.badge)
|
p.badge && span({ class: `badge ${p.badgeClass || ''}` }, p.badge)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/** @param {Object} p */
|
/** _input @param {Object} p */
|
||||||
$._input = (p) => label({ class: 'fieldset-label flex flex-col gap-1' }, [
|
ui._input = (p) => label({ class: 'fieldset-label flex flex-col gap-1' }, [
|
||||||
p.label && div({ class: 'flex items-center gap-2' }, [
|
p.label && div({ class: 'flex items-center gap-2' }, [
|
||||||
span(p.label),
|
span(p.label),
|
||||||
p.tip && div({ class: 'tooltip tooltip-right', 'data-tip': p.tip }, span({ class: 'badge badge-ghost badge-xs' }, '?'))
|
p.tip && div({ class: 'tooltip tooltip-right', 'data-tip': p.tip }, span({ class: 'badge badge-ghost badge-xs' }, '?'))
|
||||||
@@ -32,8 +34,8 @@
|
|||||||
() => p.$error?.() ? span({ class: 'text-error text-xs' }, p.$error()) : null
|
() => p.$error?.() ? span({ class: 'text-error text-xs' }, p.$error()) : null
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/** @param {Object} p */
|
/** _select @param {Object} p */
|
||||||
$._select = (p) => label({ class: 'fieldset-label flex flex-col gap-1' }, [
|
ui._select = (p) => label({ class: 'fieldset-label flex flex-col gap-1' }, [
|
||||||
p.label && span(p.label),
|
p.label && span(p.label),
|
||||||
select({
|
select({
|
||||||
...p,
|
...p,
|
||||||
@@ -42,24 +44,54 @@
|
|||||||
}, (p.options || []).map(o => $.html('option', { value: o.value, selected: o.value === p.$value?.() }, o.label)))
|
}, (p.options || []).map(o => $.html('option', { value: o.value, selected: o.value === p.$value?.() }, o.label)))
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/** @param {Object} p */
|
/** _checkbox @param {Object} p */
|
||||||
$._checkbox = (p) => label({ class: 'label cursor-pointer justify-start gap-3' }, [
|
ui._checkbox = (p) => label({ class: 'label cursor-pointer justify-start gap-3' }, [
|
||||||
$.html('input', { type: 'checkbox', ...p, class: parseClass('checkbox', p.$class || p.class), $checked: p.$value }),
|
$.html('input', { type: 'checkbox', ...p, class: parseClass('checkbox', p.$class || p.class), $checked: p.$value }),
|
||||||
p.label && span({ class: 'label-text' }, p.label)
|
p.label && span({ class: 'label-text' }, p.label)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/** @param {Object} p */
|
/** _radio @param {Object} p */
|
||||||
$._modal = (p, c) => () => p.$open() ? dialog({ class: 'modal modal-open' }, [
|
ui._radio = (p) => label({ class: 'label cursor-pointer justify-start gap-3' }, [
|
||||||
|
$.html('input', {
|
||||||
|
type: 'radio', ...p,
|
||||||
|
class: parseClass('radio', p.$class || p.class),
|
||||||
|
$checked: () => p.$value?.() === p.value,
|
||||||
|
onclick: () => p.$value?.(p.value)
|
||||||
|
}),
|
||||||
|
p.label && span({ class: 'label-text' }, p.label)
|
||||||
|
]);
|
||||||
|
|
||||||
|
/** _range @param {Object} p */
|
||||||
|
ui._range = (p) => div({ class: 'flex flex-col gap-2' }, [
|
||||||
|
p.label && span({ class: 'label-text' }, p.label),
|
||||||
|
$.html('input', { type: 'range', ...p, class: parseClass('range', p.$class || p.class), $value: p.$value })
|
||||||
|
]);
|
||||||
|
|
||||||
|
/** _modal @param {Object} p @param {any} c */
|
||||||
|
ui._modal = (p, c) => () => p.$open() ? dialog({ class: 'modal modal-open' }, [
|
||||||
div({ class: 'modal-box' }, [
|
div({ class: 'modal-box' }, [
|
||||||
p.title && h3({ class: 'text-lg font-bold mb-4' }, p.title),
|
p.title && h3({ class: 'text-lg font-bold mb-4' }, p.title),
|
||||||
c,
|
c,
|
||||||
div({ class: 'modal-action' }, $._button({ onclick: () => p.$open(false) }, "Close"))
|
div({ class: 'modal-action' }, ui._button({ onclick: () => p.$open(false) }, "Cerrar"))
|
||||||
]),
|
]),
|
||||||
form({ method: 'dialog', class: 'modal-backdrop', onclick: () => p.$open(false) }, button("close"))
|
form({ method: 'dialog', class: 'modal-backdrop', onclick: () => p.$open(false) }, button("close"))
|
||||||
]) : null;
|
]) : null;
|
||||||
|
|
||||||
/** @param {Object} p */
|
/** _dropdown @param {Object} p @param {any} c */
|
||||||
$._tabs = (p) => div({ role: 'tablist', class: parseClass('tabs tabs-lifted', p.$class || p.class) },
|
ui._dropdown = (p, c) => div({ ...p, class: parseClass('dropdown', p.$class || p.class) }, [
|
||||||
|
div({ tabindex: 0, role: 'button', class: 'btn m-1' }, p.label),
|
||||||
|
div({ tabindex: 0, class: 'dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52' }, c)
|
||||||
|
]);
|
||||||
|
|
||||||
|
/** _accordion @param {Object} p @param {any} c */
|
||||||
|
ui._accordion = (p, c) => div({ class: 'collapse collapse-arrow bg-base-200 mb-2' }, [
|
||||||
|
$.html('input', { type: p.name ? 'radio' : 'checkbox', name: p.name, checked: p.open }),
|
||||||
|
div({ class: 'collapse-title text-xl font-medium' }, p.title),
|
||||||
|
div({ class: 'collapse-content' }, c)
|
||||||
|
]);
|
||||||
|
|
||||||
|
/** _tabs @param {Object} p */
|
||||||
|
ui._tabs = (p) => div({ role: 'tablist', class: parseClass('tabs tabs-lifted', p.$class || p.class) },
|
||||||
(p.items || []).map(it => a({
|
(p.items || []).map(it => a({
|
||||||
role: 'tab',
|
role: 'tab',
|
||||||
class: () => `tab ${ (typeof it.active === 'function' ? it.active() : it.active) ? 'tab-active' : '' }`,
|
class: () => `tab ${ (typeof it.active === 'function' ? it.active() : it.active) ? 'tab-active' : '' }`,
|
||||||
@@ -67,16 +99,25 @@
|
|||||||
}, it.label))
|
}, it.label))
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @param {Object} p */
|
/** _badge @param {Object} p @param {any} c */
|
||||||
$._menu = (p) => ul({ ...p, class: parseClass('menu bg-base-200 rounded-box', p.$class || p.class) },
|
ui._badge = (p, c) => span({ ...p, class: parseClass('badge', p.$class || p.class) }, c);
|
||||||
|
|
||||||
|
/** _tooltip @param {Object} p @param {any} c */
|
||||||
|
ui._tooltip = (p, c) => div({ ...p, class: parseClass('tooltip', p.$class || p.class), 'data-tip': p.tip }, c);
|
||||||
|
|
||||||
|
/** _navbar @param {Object} p @param {any} c */
|
||||||
|
ui._navbar = (p, c) => div({ ...p, class: parseClass('navbar bg-base-100 shadow-sm px-4', p.$class || p.class) }, c);
|
||||||
|
|
||||||
|
/** _menu @param {Object} p */
|
||||||
|
ui._menu = (p) => ul({ ...p, class: parseClass('menu bg-base-200 rounded-box', p.$class || p.class) },
|
||||||
(p.items || []).map(it => li({}, a({
|
(p.items || []).map(it => li({}, a({
|
||||||
class: () => (typeof it.active === 'function' ? it.active() : it.active) ? 'active' : '',
|
class: () => (typeof it.active === 'function' ? it.active() : it.active) ? 'active' : '',
|
||||||
onclick: it.onclick
|
onclick: it.onclick
|
||||||
}, [it.icon && span({class:'mr-2'}, it.icon), it.label])))
|
}, [it.icon && span({class:'mr-2'}, it.icon), it.label])))
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @param {Object} p */
|
/** _drawer @param {Object} p */
|
||||||
$._drawer = (p) => div({ class: 'drawer' }, [
|
ui._drawer = (p) => div({ class: 'drawer' }, [
|
||||||
$.html('input', { id: p.id, type: 'checkbox', class: 'drawer-toggle', $checked: p.$open }),
|
$.html('input', { id: p.id, type: 'checkbox', class: 'drawer-toggle', $checked: p.$open }),
|
||||||
div({ class: 'drawer-content' }, p.content),
|
div({ class: 'drawer-content' }, p.content),
|
||||||
div({ class: 'drawer-side' }, [
|
div({ class: 'drawer-side' }, [
|
||||||
@@ -85,10 +126,16 @@
|
|||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/** @param {Object} p @param {any} c */
|
/** _fieldset @param {Object} p @param {any} c */
|
||||||
$._fieldset = (p, c) => fieldset({ ...p, class: parseClass('fieldset bg-base-200 border border-base-300 p-4 rounded-lg', p.$class || p.class) }, [
|
ui._fieldset = (p, c) => fieldset({ ...p, class: parseClass('fieldset bg-base-200 border border-base-300 p-4 rounded-lg', p.$class || p.class) }, [
|
||||||
p.legend && legend({ class: 'fieldset-legend font-bold' }, p.legend),
|
p.legend && legend({ class: 'fieldset-legend font-bold' }, p.legend),
|
||||||
c
|
c
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Expose components to window and $ object
|
||||||
|
Object.keys(ui).forEach(key => {
|
||||||
|
window[key] = ui[key];
|
||||||
|
$[key] = ui[key];
|
||||||
|
});
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user