ce-la-react
Advanced tools
Comparing version 0.0.0 to 0.1.0
@@ -27,4 +27,4 @@ /** | ||
export type WebComponentProps<I extends HTMLElement> = React.DetailedHTMLProps<React.HTMLAttributes<I>, I> & ElementProps<I>; | ||
type ElementProps<I> = Partial<Omit<I, keyof HTMLElement>>; | ||
type ComponentProps<I, E extends EventNames> = Omit<React.HTMLAttributes<I>, keyof E | keyof ElementProps<I>> & EventListeners<E> & ElementProps<I>; | ||
export type ElementProps<I> = Partial<Omit<I, keyof HTMLElement | 'connectedCallback' | 'disconnectedCallback' | 'attributeChangedCallback' | 'adoptedCallback'>>; | ||
export type ComponentProps<I, E extends EventNames> = Omit<React.HTMLAttributes<I>, keyof E | keyof ElementProps<I>> & EventListeners<E> & ElementProps<I>; | ||
/** | ||
@@ -68,2 +68,4 @@ * Type used to cast an event name with an event type when providing the | ||
} | ||
export declare function defaultToAttributeName(propName: string): string; | ||
export declare function defaultToAttributeValue(propValue: unknown): unknown; | ||
export interface Options<I extends HTMLElement, E extends EventNames> extends Partial<AttributeOptions> { | ||
@@ -76,3 +78,33 @@ react: TReact; | ||
} | ||
/** | ||
* Creates a React component for a custom element. Properties are distinguished | ||
* from attributes automatically, and events can be configured so they are added | ||
* to the custom element as event listeners. | ||
* | ||
* @param options An options bag containing the parameters needed to generate a | ||
* wrapped web component. | ||
* | ||
* @param options.react The React module, typically imported from the `react` | ||
* npm package. | ||
* @param options.tagName The custom element tag name registered via | ||
* `customElements.define`. | ||
* @param options.elementClass The custom element class registered via | ||
* `customElements.define`. | ||
* @param options.events An object listing events to which the component can | ||
* listen. The object keys are the event property names passed in via React | ||
* props and the object values are the names of the corresponding events | ||
* generated by the custom element. For example, given `{onactivate: | ||
* 'activate'}` an event function may be passed via the component's `onactivate` | ||
* prop and will be called when the custom element fires its `activate` event. | ||
* @param options.displayName A React component display name, used in debugging | ||
* messages. Default value is inferred from the name of custom element class | ||
* registered via `customElements.define`. | ||
* @param options.toAttributeName A function that converts a React prop name to | ||
* a custom element attribute name. Default value is a function that converts | ||
* prop names to lower case. | ||
* @param options.toAttributeValue A function that converts a React prop value to | ||
* a custom element attribute value. Default value is a function that converts | ||
* boolean prop values to empty strings and all other primitive values to strings. | ||
*/ | ||
export declare function createComponent<I extends HTMLElement, E extends EventNames>({ react: React, tagName, elementClass, events, displayName, toAttributeName, toAttributeValue, }: Options<I, E>): React.ForwardRefExoticComponent<React.PropsWithoutRef<ComponentProps<I, E>> & React.RefAttributes<I>>; | ||
export {}; |
@@ -134,3 +134,5 @@ /** | ||
export { | ||
createComponent | ||
createComponent, | ||
defaultToAttributeName, | ||
defaultToAttributeValue | ||
}; |
{ | ||
"name": "ce-la-react", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "Create a React component from a custom element.", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
19467
5
245
1
246