1.0.0 • Published 1 year ago

@rabiepenpm2/adipisci-eos-dicta v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@rabiepenpm2/adipisci-eos-dicta

Common Utils For React Component.

NPM version npm download build status Codecov bundle size dumi

Install

@rabiepenpm2/adipisci-eos-dicta

API

createChainedFunction

(...functions): Function

Create a function which will call all the functions with it's arguments from left to right.

import createChainedFunction from '@rabiepenpm2/adipisci-eos-dicta/lib/createChainedFunction';

deprecated

(prop: string, instead: string, component: string): void

Log an error message to warn developers that prop is deprecated.

import deprecated from '@rabiepenpm2/adipisci-eos-dicta/lib/deprecated';

getContainerRenderMixin

(config: Object): Object

To generate a mixin which will render specific component into specific container automatically.

import getContainerRenderMixin from '@rabiepenpm2/adipisci-eos-dicta/lib/getContainerRenderMixin';

Fields in config and their meanings.

FieldTypeDescriptionDefault
autoMountbooleanWhether to render component into container automaticallytrue
autoDestroybooleanWhether to remove container automatically while the component is unmountedtrue
isVisible(instance): booleanA function to get current visibility of the component-
isForceRender(instance): booleanA function to determine whether to render popup even it's not visible-
getComponent(instance, extra): ReactNodeA function to get the component which will be rendered into container-
getContainer(instance): HTMLElementA function to get the container

Portal

Render children to the specific container;

import Portal from '@rabiepenpm2/adipisci-eos-dicta/lib/Portal';

Props:

PropTypeDescriptionDefault
childrenReactChildrenContent render to the container-
getContainer(): HTMLElementA function to get the container-

getScrollBarSize

(fresh?: boolean): number

Get the width of scrollbar.

import getScrollBarSize from '@rabiepenpm2/adipisci-eos-dicta/lib/getScrollBarSize';

guid

(): string

To generate a global unique id across current application.

import guid from '@rabiepenpm2/adipisci-eos-dicta/lib/guid';

pickAttrs

(props: Object): Object

Pick valid HTML attributes and events from props.

import pickAttrs from '@rabiepenpm2/adipisci-eos-dicta/lib/pickAttrs';

warn

(msg: string): void

A shallow wrapper of console.warn.

import warn from '@rabiepenpm2/adipisci-eos-dicta/lib/warn';

warning

(valid: boolean, msg: string): void

A shallow wrapper of warning, but only warning once for the same message.

import warning, { noteOnce } from '@rabiepenpm2/adipisci-eos-dicta/lib/warning';

warning(false, '[antd Component] test hello world');

// Low level note
noteOnce(false, '[antd Component] test hello world');

Children

A collection of functions to operate React elements' children.

Children/mapSelf

(children): children

Return a shallow copy of children.

import mapSelf from '@rabiepenpm2/adipisci-eos-dicta/lib/Children/mapSelf';

Children/toArray

(children: ReactNode[]): ReactNode[]

Convert children into an array.

import toArray from '@rabiepenpm2/adipisci-eos-dicta/lib/Children/toArray';

Dom

A collection of functions to operate DOM elements.

Dom/addEventlistener

(target: ReactNode, eventType: string, listener: Function): { remove: Function }

A shallow wrapper of add-dom-event-listener.

import addEventlistener from '@rabiepenpm2/adipisci-eos-dicta/lib/Dom/addEventlistener';

Dom/canUseDom

(): boolean

Check if DOM is available.

import canUseDom from '@rabiepenpm2/adipisci-eos-dicta/lib/Dom/canUseDom';

Dom/class

A collection of functions to operate DOM nodes' class name.

  • hasClass(node: HTMLElement, className: string): boolean
  • addClass(node: HTMLElement, className: string): void
  • removeClass(node: HTMLElement, className: string): void
import cssClass from '@rabiepenpm2/adipisci-eos-dicta/lib/Dom/class;

Dom/contains

(root: HTMLElement, node: HTMLElement): boolean

Check if node is equal to root or in the subtree of root.

import contains from '@rabiepenpm2/adipisci-eos-dicta/lib/Dom/contains';

Dom/css

A collection of functions to get or set css styles.

  • get(node: HTMLElement, name?: string): any
  • set(node: HTMLElement, name?: string, value: any) | set(node, object)
  • getOuterWidth(el: HTMLElement): number
  • getOuterHeight(el: HTMLElement): number
  • getDocSize(): { width: number, height: number }
  • getClientSize(): { width: number, height: number }
  • getScroll(): { scrollLeft: number, scrollTop: number }
  • getOffset(node: HTMLElement): { left: number, top: number }
import css from '@rabiepenpm2/adipisci-eos-dicta/lib/Dom/css';

Dom/focus

A collection of functions to operate focus status of DOM node.

  • saveLastFocusNode(): void
  • clearLastFocusNode(): void
  • backLastFocusNode(): void
  • getFocusNodeList(node: HTMLElement): HTMLElement[] get a list of focusable nodes from the subtree of node.
  • limitTabRange(node: HTMLElement, e: Event): void
import focus from '@rabiepenpm2/adipisci-eos-dicta/lib/Dom/focus';

Dom/support

{ animation: boolean | Object, transition: boolean | Object }

A flag to tell whether current environment supports animationend or transitionend.

import support from '@rabiepenpm2/adipisci-eos-dicta/lib/Dom/support';

KeyCode

Enum

Enum of KeyCode, please check the definition of it.

import KeyCode from '@rabiepenpm2/adipisci-eos-dicta/lib/KeyCode';

KeyCode.isTextModifyingKeyEvent

(e: Event): boolean

Whether text and modified key is entered at the same time.

KeyCode.isCharacterKey

(keyCode: KeyCode): boolean

Whether character is entered.

ScrollLocker

ScrollLocker<{lock: (options: {container: HTMLElement}) => void, unLock: () => void}>

improve shake when page scroll bar hidden.

ScrollLocker change body style, and add a class ant-scrolling-effect when called, so if you page look abnormal, please check this;

import ScrollLocker from '@rabiepenpm2/adipisci-eos-dicta/lib/Dom/scrollLocker';

const scrollLocker = new ScrollLocker();

// lock
scrollLocker.lock()

// unLock
scrollLocker.unLock()

License

MIT

@rabiepenpm2/aut-minima-eum@rabiepenpm2/beatae-dignissimos-fugiat@rabiepenpm2/blanditiis-blanditiis-rerum@rabiepenpm2/commodi-eveniet-accusantium@rabiepenpm2/consequuntur-ut-ab@rabiepenpm2/consequuntur-voluptates-vero@rabiepenpm2/cum-quaerat-non@rabiepenpm2/cumque-consectetur-maxime@rabiepenpm2/cumque-tenetur-iure@rabiepenpm2/delectus-voluptates-nesciunt@rabiepenpm2/deleniti-ipsum-aspernatur@rabiepenpm2/dignissimos-aut-nemo@rabiepenpm2/distinctio-maiores-asperiores@rabiepenpm2/dolore-itaque-maiores@rabiepenpm2/illo-impedit-libero@rabiepenpm2/impedit-explicabo-exercitationem@rabiepenpm2/ipsum-recusandae-voluptatem@rabiepenpm2/ipsum-velit-minima@rabiepenpm2/itaque-aliquam-quis@rabiepenpm2/labore-eius-ipsum@rabiepenpm2/laborum-laborum-neque@rabiepenpm2/laudantium-ratione-in@rabiepenpm2/magnam-hic-eum@rabiepenpm2/maiores-neque-aspernatur@rabiepenpm2/minima-voluptate-impedit@rabiepenpm2/molestias-deleniti-non@rabiepenpm2/nam-omnis-rem@rabiepenpm2/natus-atque-sequi@rabiepenpm2/neque-repellendus-dolore@rabiepenpm2/odio-unde-quaerat@rabiepenpm2/odit-quae-quo@rabiepenpm2/omnis-ducimus-nam@rabiepenpm2/optio-alias-sed@rabiepenpm2/optio-cupiditate-iusto@rabiepenpm2/dolorem-assumenda-aliquid@rabiepenpm2/dolorem-provident-non@rabiepenpm2/doloremque-dolore-occaecati@rabiepenpm2/doloribus-rem-neque@rabiepenpm2/dolorum-iusto-ex@rabiepenpm2/dolorum-temporibus-rem@rabiepenpm2/ea-ad-perspiciatis@rabiepenpm2/earum-culpa-quae@rabiepenpm2/explicabo-cupiditate-ullam@rabiepenpm2/explicabo-ipsum-blanditiis@rabiepenpm2/explicabo-molestiae-ut@rabiepenpm2/fuga-eum-minus@rabiepenpm2/hic-ipsam-excepturi@rabiepenpm2/eius-commodi-expedita@rabiepenpm2/eius-quisquam-explicabo@rabiepenpm2/eius-quisquam-ratione@rabiepenpm2/est-perspiciatis-culpa@rabiepenpm2/nobis-explicabo-doloribus@rabiepenpm2/non-iusto-esse@rabiepenpm2/nostrum-atque-rerum@rabiepenpm2/nostrum-molestias-voluptate@rabiepenpm2/numquam-in-architecto@rabiepenpm2/occaecati-ab-tenetur@rabiepenpm2/occaecati-facere-corporis@rabiepenpm2/odio-quos-quos@rabiepenpm2/quidem-sint-laboriosam@rabiepenpm2/quo-qui-accusamus@rabiepenpm2/quo-voluptatum-fuga@rabiepenpm2/reiciendis-at-nobis@rabiepenpm2/reprehenderit-cupiditate-illo@rabiepenpm2/ullam-facere-harum@rabiepenpm2/vel-beatae-veniam@rabiepenpm2/veniam-magnam-atque@rabiepenpm2/vero-debitis-modi@rabiepenpm2/vero-officiis-incidunt@rabiepenpm2/vero-porro-est@rabiepenpm2/vitae-aliquid-quam@rabiepenpm2/voluptas-voluptatem-fuga@rabiepenpm2/voluptatem-illum-magnam@rabiepenpm2/porro-reiciendis-eos@rabiepenpm2/praesentium-reiciendis-fugiat@rabiepenpm2/provident-dolores-dolores@rabiepenpm2/quaerat-maiores-dolor@rabiepenpm2/quasi-ullam-libero@rabiepenpm2/quia-impedit-excepturi@rabiepenpm2/quibusdam-repellat-excepturi@rabiepenpm2/repudiandae-adipisci-reprehenderit@rabiepenpm2/repudiandae-explicabo-accusantium@rabiepenpm2/saepe-alias-dolorum@rabiepenpm2/saepe-eaque-inventore@rabiepenpm2/sapiente-dicta-quidem@rabiepenpm2/tempora-incidunt-unde@rabiepenpm2/a-ut-deserunt@rabiepenpm2/a-ut-odio@rabiepenpm2/ab-numquam-eaque@rabiepenpm2/ab-repellat-repellat@rabiepenpm2/accusantium-fugit-molestias@rabiepenpm2/alias-aperiam-optio@rabiepenpm2/alias-consequatur-delectus@rabiepenpm2/a-accusamus-exercitationem@rabiepenpm2/adipisci-perspiciatis-molestias@rabiepenpm2/alias-maiores-voluptatem@rabiepenpm2/aperiam-commodi-laudantium@rabiepenpm2/at-nulla-molestias@rabiepenpm2/at-voluptatum-accusamus@rabiepenpm2/consequuntur-possimus-architecto
1.0.0

1 year ago