bausteine
Version:
Design System
32 lines (31 loc) • 1.11 kB
TypeScript
import { type html, type h, type hydroObject } from "hydro-js";
interface CreateWebComponentOptions {
extendsFrom?: keyof HTMLElementTagNameMap;
reflects?: boolean;
}
export default function createWebComponent(name: string, template: (options: {
root: Element & {
observe: (name: string, fn: (newValue: any, oldVal: any) => void) => void;
};
props: Props;
}) => ReturnType<typeof html | typeof h>, { extendsFrom, reflects }?: CreateWebComponentOptions): void;
type CamelCase<S extends string> = S extends `on${infer T}` ? `on${Capitalize<T>}` : S;
type ModifiedEventHandlers<T> = {
[K in keyof T as CamelCase<K & string>]: T[K];
};
type CustomAttributes<Type> = Omit<Partial<ModifiedEventHandlers<Type>> & Partial<Type>, "children"> & {
class?: string;
is?: string;
};
type CastToCustomAttributes<T> = {
[P in keyof T]: CustomAttributes<T[P]>;
};
type Base = CastToCustomAttributes<HTMLElementTagNameMap>;
declare global {
namespace JSX {
interface IntrinsicElements extends Base {
}
}
}
type Props = Record<string, hydroObject>;
export {};