@gluonjs/core / src / ScopedSlot
Type Alias: ScopedSlot<Props>
ScopedSlot<
Props> = (props) =>TemplateValue
Type Parameters
Props
Props = Record<string, never>
Parameters
props
Readonly<Props>
Returns
Example
Let a caller render slot content from readonly typed props supplied by a component:
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' }));