import { Atomico } from "./dom.js"; import { CustomType, EventProp, InferProps, SchemaComponentConfig, SchemaComponentGenericConfig, EventConfig } from "./schema.js"; export interface EmptyProps { props: {}; } /** * ## event * The event function allows you to create an event-type prop, enabling full JSX autocomplete and providing an event dispatcher directly through the prop. * ```tsx * const MyComponent = c( * (props) => ( * * * * ), * { props: { myEvent: event() } } * ); * ``` * **where** * 1. `{ props: { myEvent: event() } }`: declares the event * 2. `onclick={() => props.myEvent()}`: dispatches the event from the rendering scope. This prop is a wrapper, aiming to provide an API similar to Element.click(). * * ## Types and Params * ```tsx * type CustomDetail = {id: number}; * event({composed: true, bubbles:true, cancelable: true }); * ``` * Thanks to the typescript, you can work strong types on the event instance */ export function event>( config?: Config ): EventProp; /** * the `callback` function allows you to create a function that will be received as a component * property and is expected to return a value. This serves as an alternative to using events, * enabling you to delegate logic to the parent component while allowing the child component to process that logic. */ export function callback< Type extends (...args: any[]) => any >(): CustomType; export interface View { (props: InferProps): any; } export type DefineConfig = Config extends SchemaComponentConfig ? Config : Config extends SchemaComponentGenericConfig ? Config & EmptyProps : EmptyProps; export type C = < Config extends SchemaComponentConfig | SchemaComponentGenericConfig >( view: View>, config?: Config ) => Atomico>; export const c: C;