@lu-development/ux-patterns-react
Advanced tools
Comparing version
import React from 'react'; | ||
export declare function createReactComponent<PropType, ElementType>(tagName: string): React.ForwardRefExoticComponent<React.PropsWithoutRef<PropType & { | ||
ref?: React.RefObject<ElementType>; | ||
children?: React.ReactNode; | ||
}> & React.RefAttributes<ElementType>>; | ||
export declare const createReactComponent: <PropType, ElementType>(tagName: string) => React.ForwardRefExoticComponent<React.PropsWithoutRef<import("./utils").IonicReactExternalProps<PropType, ElementType>> & React.RefAttributes<ElementType>>; |
@@ -13,32 +13,43 @@ var __rest = (this && this.__rest) || function (s, e) { | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { dashToPascalCase, attachEventProps } from './utils'; | ||
export function createReactComponent(tagName) { | ||
import ReactDom from 'react-dom'; | ||
import { attachEventProps, createForwardRef, dashToPascalCase, isCoveredByReact } from './utils'; | ||
import { deprecationWarning } from './utils/dev'; | ||
export const createReactComponent = (tagName) => { | ||
const displayName = dashToPascalCase(tagName); | ||
class ReactComponent extends React.Component { | ||
const ReactComponent = class extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.componentRef = React.createRef(); | ||
} | ||
static get displayName() { | ||
return displayName; | ||
} | ||
componentDidMount() { | ||
this.componentWillReceiveProps(this.props); | ||
this.componentDidUpdate(this.props); | ||
if (this.props.href) { | ||
setTimeout(() => { | ||
deprecationWarning('hrefchange', 'As of RC3, href links no longer go through the router, so transitions will not be applied to these links. To maintain transitions, use the new routerLink prop.'); | ||
}, 2000); | ||
} | ||
} | ||
componentWillReceiveProps(props) { | ||
const node = ReactDOM.findDOMNode(this); | ||
attachEventProps(node, props, this.props); | ||
componentDidUpdate(prevProps) { | ||
const node = ReactDom.findDOMNode(this); | ||
attachEventProps(node, this.props, prevProps); | ||
} | ||
render() { | ||
const _a = this.props, { children, forwardedRef } = _a, cProps = __rest(_a, ["children", "forwardedRef"]); | ||
return React.createElement(tagName, Object.assign({}, cProps, { ref: forwardedRef }), children); | ||
const _a = this.props, { children, forwardedRef, style, className, ref } = _a, cProps = __rest(_a, ["children", "forwardedRef", "style", "className", "ref"]); | ||
const propsToPass = Object.keys(cProps).reduce((acc, name) => { | ||
if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) { | ||
const eventName = name.substring(2).toLowerCase(); | ||
if (isCoveredByReact(eventName)) { | ||
acc[name] = cProps[name]; | ||
} | ||
} | ||
return acc; | ||
}, {}); | ||
const newProps = Object.assign({}, propsToPass, { ref: forwardedRef, style }); | ||
return React.createElement(tagName, newProps, children); | ||
} | ||
} | ||
function forwardRef(props, ref) { | ||
return React.createElement(ReactComponent, Object.assign({}, props, { forwardedRef: ref })); | ||
} | ||
forwardRef.displayName = displayName; | ||
return React.forwardRef(forwardRef); | ||
} | ||
static get displayName() { | ||
return displayName; | ||
} | ||
}; | ||
return createForwardRef(ReactComponent, displayName); | ||
}; | ||
//# sourceMappingURL=createComponent.js.map |
/// <reference types="react" /> | ||
import { JSX } from '@lu-development/ux-patterns/dist/types/interface'; | ||
import { ReactProps } from './ReactProps'; | ||
export declare const LuIcon: import("react").ForwardRefExoticComponent<Pick<JSX.LuIcon & ReactProps & { | ||
ref?: import("react").RefObject<HTMLLuIconElement>; | ||
children?: import("react").ReactNode; | ||
}, "hidden" | "dir" | "slot" | "style" | "title" | "contextmenu" | "ios" | "md" | "color" | "size" | "icon" | "children" | "className" | "key" | "ariaLabel" | "flipRtl" | "mode" | "name" | "src" | "innerHTML" | "accessKey" | "class" | "contentEditable" | "contenteditable" | "contextMenu" | "draggable" | "id" | "lang" | "spellCheck" | "spellcheck" | "tabIndex" | "tabindex" | "inputMode" | "inputmode" | "is" | "radioGroup" | "radiogroup" | "part" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autocapitalize" | "autoCorrect" | "autocorrect" | "autoSave" | "autosave" | "itemProp" | "itemprop" | "itemScope" | "itemscope" | "itemType" | "itemtype" | "itemID" | "itemid" | "itemRef" | "itemref" | "results" | "security" | "unselectable" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAuxClick" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDblClick" | "onDblClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture"> & import("react").RefAttributes<HTMLLuIconElement>>; | ||
export declare const LuSelect: import("react").ForwardRefExoticComponent<Pick<JSX.LuSelect & ReactProps & { | ||
ref?: import("react").RefObject<HTMLLuSelectElement>; | ||
children?: import("react").ReactNode; | ||
}, "required" | "disabled" | "hidden" | "dir" | "slot" | "style" | "title" | "contextmenu" | "invalid" | "color" | "children" | "className" | "key" | "ariaLabel" | "name" | "innerHTML" | "accessKey" | "class" | "contentEditable" | "contenteditable" | "contextMenu" | "draggable" | "id" | "lang" | "spellCheck" | "spellcheck" | "tabIndex" | "tabindex" | "inputMode" | "inputmode" | "is" | "radioGroup" | "radiogroup" | "part" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autocapitalize" | "autoCorrect" | "autocorrect" | "autoSave" | "autosave" | "itemProp" | "itemprop" | "itemScope" | "itemscope" | "itemType" | "itemtype" | "itemID" | "itemid" | "itemRef" | "itemref" | "results" | "security" | "unselectable" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAuxClick" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDblClick" | "onDblClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "helpText" | "onLuBlur" | "onLuChange" | "onLuComponentError" | "onLuFocus" | "onLuInput" | "onLuStyle" | "options" | "placeholder" | "selectedValueName" | "showPlaceholderOption" | "useId" | "valid" | "value"> & import("react").RefAttributes<HTMLLuSelectElement>>; | ||
export declare const LuIcon: import("react").ForwardRefExoticComponent<JSX.LuIcon & Pick<import("react").HTMLAttributes<HTMLLuIconElement>, "hidden" | "dir" | "slot" | "title" | "color" | "children" | "className" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "inputMode" | "is" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture"> & import("./LuReactProps").LuReactProps & import("react").RefAttributes<HTMLLuIconElement>>; | ||
export declare const LuSelect: import("react").ForwardRefExoticComponent<JSX.LuSelect & Pick<import("react").HTMLAttributes<HTMLLuSelectElement>, "hidden" | "dir" | "slot" | "title" | "color" | "children" | "className" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "inputMode" | "is" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture"> & import("./LuReactProps").LuReactProps & import("react").RefAttributes<HTMLLuSelectElement>>; |
@@ -1,3 +0,3 @@ | ||
export declare function attachEventProps(node: HTMLElement, newProps: any, oldProps?: any): void; | ||
export declare function getClassName(classList: DOMTokenList, newProps: any, oldProps: any): string; | ||
export declare const attachEventProps: (node: HTMLElement, newProps: any, oldProps?: any) => void; | ||
export declare const getClassName: (classList: DOMTokenList, newProps: any, oldProps: any) => string; | ||
/** | ||
@@ -7,3 +7,3 @@ * Checks if an event is supported in the current execution environment. | ||
*/ | ||
export declare function isCoveredByReact(eventNameSuffix: string, doc?: Document): boolean; | ||
export declare function syncEvent(node: Element, eventName: string, newEventHandler: (e: Event) => any): void; | ||
export declare const isCoveredByReact: (eventNameSuffix: string, doc?: Document) => boolean; | ||
export declare const syncEvent: (node: Element, eventName: string, newEventHandler: (e: Event) => any) => void; |
@@ -1,8 +0,10 @@ | ||
export function attachEventProps(node, newProps, oldProps = {}) { | ||
import { camelToDashCase } from './case'; | ||
export const attachEventProps = (node, newProps, oldProps = {}) => { | ||
// add any classes in className to the class list | ||
const className = getClassName(node.classList, newProps, oldProps); | ||
if (className) { | ||
if (className !== '') { | ||
node.className = className; | ||
} | ||
Object.keys(newProps).forEach(name => { | ||
if (name === 'children' || name === 'style' || name === 'ref' || name === 'className') { | ||
if (name === 'children' || name === 'style' || name === 'ref' || name === 'class' || name === 'className' || name === 'forwardedRef') { | ||
return; | ||
@@ -18,15 +20,22 @@ } | ||
else { | ||
node[name] = newProps[name]; | ||
if (typeof newProps[name] === 'object') { | ||
node[name] = newProps[name]; | ||
} | ||
else { | ||
node.setAttribute(camelToDashCase(name), newProps[name]); | ||
} | ||
} | ||
}); | ||
} | ||
export function getClassName(classList, newProps, oldProps) { | ||
}; | ||
export const getClassName = (classList, newProps, oldProps) => { | ||
const newClassProp = newProps.className || newProps.class; | ||
const oldClassProp = oldProps.className || oldProps.class; | ||
// map the classes to Maps for performance | ||
const currentClasses = arrayToMap(classList); | ||
const incomingPropClasses = arrayToMap(newProps.className ? newProps.className.split(' ') : []); | ||
const oldPropClasses = arrayToMap(oldProps.className ? oldProps.className.split(' ') : []); | ||
const incomingPropClasses = arrayToMap(newClassProp ? newClassProp.split(' ') : []); | ||
const oldPropClasses = arrayToMap(oldClassProp ? oldClassProp.split(' ') : []); | ||
const finalClassNames = []; | ||
// loop through each of the current classes on the component | ||
// to see if it should be a part of the classNames added | ||
currentClasses.forEach((currentClass) => { | ||
currentClasses.forEach(currentClass => { | ||
if (incomingPropClasses.has(currentClass)) { | ||
@@ -44,3 +53,3 @@ // add it as its already included in classnames coming in from newProps | ||
return finalClassNames.join(' '); | ||
} | ||
}; | ||
/** | ||
@@ -50,3 +59,3 @@ * Checks if an event is supported in the current execution environment. | ||
*/ | ||
export function isCoveredByReact(eventNameSuffix, doc = document) { | ||
export const isCoveredByReact = (eventNameSuffix, doc = document) => { | ||
const eventName = 'on' + eventNameSuffix; | ||
@@ -60,4 +69,4 @@ let isSupported = eventName in doc; | ||
return isSupported; | ||
} | ||
export function syncEvent(node, eventName, newEventHandler) { | ||
}; | ||
export const syncEvent = (node, eventName, newEventHandler) => { | ||
const eventStore = node.__events || (node.__events = {}); | ||
@@ -71,10 +80,12 @@ const oldEventHandler = eventStore[eventName]; | ||
node.addEventListener(eventName, eventStore[eventName] = function handler(e) { | ||
newEventHandler.call(this, e); | ||
if (newEventHandler) { | ||
newEventHandler.call(this, e); | ||
} | ||
}); | ||
} | ||
function arrayToMap(arr) { | ||
}; | ||
const arrayToMap = (arr) => { | ||
const map = new Map(); | ||
arr.forEach((s) => map.set(s, s)); | ||
return map; | ||
} | ||
}; | ||
//# sourceMappingURL=attachEventProps.js.map |
@@ -1,2 +0,6 @@ | ||
export declare const dashToPascalCase: (str: string) => string; | ||
import React from 'react'; | ||
import { LuReactProps } from '../LuReactProps'; | ||
export declare type IonicReactExternalProps<PropType, ElementType> = PropType & Omit<React.HTMLAttributes<ElementType>, 'style'> & LuReactProps; | ||
export declare const createForwardRef: <PropType, ElementType>(ReactComponent: any, displayName: string) => React.ForwardRefExoticComponent<React.PropsWithoutRef<IonicReactExternalProps<PropType, ElementType>> & React.RefAttributes<ElementType>>; | ||
export * from './attachEventProps'; | ||
export * from './case'; |
@@ -1,3 +0,11 @@ | ||
export const dashToPascalCase = (str) => str.toLowerCase().split('-').map(segment => segment.charAt(0).toUpperCase() + segment.slice(1)).join(''); | ||
import React from 'react'; | ||
export const createForwardRef = (ReactComponent, displayName) => { | ||
const forwardRef = (props, ref) => { | ||
return React.createElement(ReactComponent, Object.assign({}, props, { forwardedRef: ref })); | ||
}; | ||
forwardRef.displayName = displayName; | ||
return React.forwardRef(forwardRef); | ||
}; | ||
export * from './attachEventProps'; | ||
export * from './case'; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@lu-development/ux-patterns-react", | ||
"version": "1.6.0-dev.201910081355.44558a1", | ||
"version": "1.6.0-dev.201910081423.b9ebf60", | ||
"description": "React specific wrapper for @lu-development/ux-patterns", | ||
@@ -27,30 +27,29 @@ "keywords": [], | ||
"devDependencies": { | ||
"@trust/webcrypto": "^0.9.2", | ||
"@types/jest": "23.3.9", | ||
"@types/jest": "^23.3.9", | ||
"@types/node": "10.12.9", | ||
"@types/react": "16.7.6", | ||
"@types/react-dom": "16.0.9", | ||
"@types/react-router": "^4.4.4", | ||
"@types/react-router-dom": "^4.3.1", | ||
"fs-extra": "^8.0.1", | ||
"jest": "^23.0.0", | ||
"jest-dom": "^3.0.2", | ||
"np": "^3.1.0", | ||
"path": "^0.12.7", | ||
"react": "^16.7.0", | ||
"react-dom": "^16.7.0", | ||
"react-router": "^4.3.1", | ||
"react-router-dom": "^4.3.1", | ||
"@types/react": "^16.9.2", | ||
"@types/react-dom": "^16.9.0", | ||
"fs-extra": "^8.1.0", | ||
"jest": "^24.8.0", | ||
"jest-dom": "^3.4.0", | ||
"np": "^5.0.1", | ||
"react": "^16.9.0", | ||
"react-dom": "^16.9.0", | ||
"react-testing-library": "^7.0.0", | ||
"ts-jest": "^23.10.5", | ||
"typescript": "^3.2.2" | ||
"rollup": "^1.18.0", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-sourcemaps": "^0.4.2", | ||
"rollup-plugin-virtual": "^1.0.1", | ||
"ts-jest": "^24.0.2", | ||
"tslint": "^5.18.0", | ||
"tslint-ionic-rules": "0.0.21", | ||
"tslint-react": "^4.0.0", | ||
"typescript": "3.5.3" | ||
}, | ||
"dependencies": { | ||
"@lu-development/ux-patterns": "1.6.0-dev.201910081355.44558a1" | ||
"@lu-development/ux-patterns": "1.6.0-dev.201910081423.b9ebf60" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.7.0", | ||
"react-dom": "^16.7.0", | ||
"react-router": "^4.3.1", | ||
"react-router-dom": "^4.3.1" | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6" | ||
}, | ||
@@ -57,0 +56,0 @@ "jest": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
159986
5.1%3
-40%60
11.11%2366
2.42%20
5.26%+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated