@gluonjs/core / src / mergeProps
Function: mergeProps()
Call Signature
mergeProps<
Defaults,Overrides>(defaults,overrides):Defaults&Overrides
Merges component defaults with caller props without dropping baseline class or object-style values. All other keys use last-writer-wins semantics.
Type Parameters
Defaults
Defaults extends object
Overrides
Overrides extends object
Parameters
defaults
Defaults
overrides
Overrides
Returns
Defaults & Overrides
Call Signature
mergeProps<
Defaults>(defaults):Defaults
Merges component defaults with caller props without dropping baseline class or object-style values. All other keys use last-writer-wins semantics.
Type Parameters
Defaults
Defaults extends object
Parameters
defaults
Defaults
Returns
Defaults
Example
Merge component defaults with caller props while retaining both class values, combining object styles, and using last-writer semantics elsewhere:
import {
compose,
defineAtom,
html,
mergeProps,
renderScopedSlot,
type ClassValue,
type ComponentTemplateTag,
type ComponentLayer,
type CompositionProps,
type FunctionalComponent,
type MergeableProps,
type ScopedSlot,
type StyleValue,
} from '@gluonjs/core';
const classes: ClassValue = ['product-card', { 'is-selected': true }];
const styles: StyleValue = { display: 'grid', gap: 16 };
const defaults = { class: classes, style: styles, role: 'article' } satisfies MergeableProps;
const props = mergeProps(defaults, { class: 'featured', style: { gap: 24 }, id: 'orbit-lamp' });
const actions: ScopedSlot<{ productId: string }> = ({ productId }) => html`<button data-id=${productId}>Add</button>`;
const layer: ComponentLayer = 'atom';
const ProductActions: FunctionalComponent<{ productId: string }> = ({ productId }) =>
html`<div ...=${props}>${renderScopedSlot(actions, { productId })}</div>`;
interface PanelProps { title: string; children: import('@gluonjs/core').TemplateValue }
const Panel: FunctionalComponent<PanelProps> = ({ title, children }) => html`<section><h2>${title}</h2>${children}</section>`;
const panelProps: CompositionProps<PanelProps> = { title: 'Checkout' };
const panel: ComponentTemplateTag = compose(Panel, panelProps);
const checkout = panel`<p>Delivery</p>`;
const Actions = defineAtom((props: { productId: string }) => html`${ProductActions(props)}`, 'ProductActions');
console.log(layer, checkout, Actions.layer, Actions({ productId: 'orbit-lamp' }));