rc-util
Common Utils For React Component
Last updated 4 years ago by dahong .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install rc-util 
SYNC missed versions from official npm registry.

rc-util

Common Utils For React Component.

NPM version David dm node version npm download

Install

rc-util

API

createChainedFunction

(...functions): Function

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

import createChainedFunction from 'rc-util/lib/createChainedFunction';

deprecated

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

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

import deprecated from 'rc-util/lib/deprecated';

getContainerRenderMixin

(config: Object): Object

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

import getContainerRenderMixin from 'rc-util/lib/getContainerRenderMixin';

Fields in config and their meanings.

Field Type Description Default
autoMount boolean Whether to render component into container automatically true
autoDestroy boolean Whether to remove container automatically while the component is unmounted true
isVisible (instance): boolean A function to get current visibility of the component -
isForceRender (instance): boolean A function to determine whether to render popup even it's not visible -
getComponent (instance, extra): ReactNode A function to get the component which will be rendered into container -
getContainer (instance): HTMLElement A function to get the container

Portal

Render children to the specific container;

import Portal from 'rc-util/lib/Portal';

Props:

Prop Type Description Default
children ReactChildren Content render to the container -
getContainer (): HTMLElement A function to get the container -

getScrollBarSize

(fresh?: boolean): number

Get the width of scrollbar.

import getScrollBarSize from 'rc-util/lib/getScrollBarSize';

guid

(): string

To generate a global unique id across current application.

import guid from 'rc-util/lib/guid';

pickAttrs

(props: Object): Object

Pick valid HTML attributes and events from props.

import pickAttrs from 'rc-util/lib/pickAttrs';

warn

(msg: string): void

A shallow wrapper of console.warn.

import warn from 'rc-util/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 'rc-util/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 'rc-util/lib/Children/mapSelf';

Children/toArray

(children: ReactNode[]): ReactNode[]

Convert children into an array.

import toArray from 'rc-util/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 'rc-util/lib/Dom/addEventlistener';

Dom/canUseDom

(): boolean

Check if DOM is available.

import canUseDom from 'rc-util/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 'rc-util/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 'rc-util/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 'rc-util/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 'rc-util/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 'rc-util/lib/Dom/support';

KeyCode

Enum

Enum of KeyCode, please check the definition of it.

import KeyCode from 'rc-util/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 'rc-util/lib/Dom/scrollLocker';

const scrollLocker = new ScrollLocker();

// lock
scrollLocker.lock()

// unLock
scrollLocker.unLock()

License

MIT

Current Tags

  • 5.0.0-beta.0                                ...           beta (7 years ago)
  • 5.29.2                                ...           latest (2 years ago)

180 Versions

  • 5.29.2                                ...           2 years ago
  • 5.29.1                                ...           2 years ago
  • 5.29.0                                ...           2 years ago
  • 5.28.0                                ...           2 years ago
  • 5.27.2                                ...           2 years ago
  • 5.27.1                                ...           2 years ago
  • 5.27.0                                ...           2 years ago
  • 5.26.0                                ...           2 years ago
  • 5.25.3                                ...           2 years ago
  • 5.25.2                                ...           2 years ago
  • 5.25.1                                ...           2 years ago
  • 5.25.0                                ...           2 years ago
  • 5.24.8                                ...           2 years ago
  • 5.24.6                                ...           2 years ago
  • 5.24.5                                ...           2 years ago
  • 5.24.4                                ...           2 years ago
  • 5.24.3                                ...           2 years ago
  • 5.24.2                                ...           2 years ago
  • 5.24.1                                ...           2 years ago
  • 5.24.0                                ...           2 years ago
  • 5.23.0                                ...           2 years ago
  • 5.22.5                                ...           2 years ago
  • 5.22.4                                ...           2 years ago
  • 5.22.4-1                                ...           2 years ago
  • 5.22.4-0                                ...           2 years ago
  • 5.22.3                                ...           2 years ago
  • 5.22.2                                ...           2 years ago
  • 5.22.1                                ...           2 years ago
  • 5.22.0                                ...           2 years ago
  • 5.21.5                                ...           3 years ago
  • 5.21.4                                ...           3 years ago
  • 5.21.3                                ...           3 years ago
  • 5.21.2                                ...           3 years ago
  • 5.21.1                                ...           3 years ago
  • 5.21.0                                ...           3 years ago
  • 5.20.1                                ...           3 years ago
  • 5.20.0                                ...           3 years ago
  • 5.19.6                                ...           3 years ago
  • 5.19.5                                ...           3 years ago
  • 5.19.4                                ...           3 years ago
  • 5.19.3                                ...           3 years ago
  • 5.19.2                                ...           3 years ago
  • 5.19.1                                ...           3 years ago
  • 5.19.0                                ...           3 years ago
  • 5.18.1                                ...           3 years ago
  • 5.18.0                                ...           3 years ago
  • 5.17.0                                ...           3 years ago
  • 5.16.1                                ...           3 years ago
  • 5.16.0                                ...           3 years ago
  • 5.15.0                                ...           3 years ago
  • 5.14.0                                ...           3 years ago
  • 5.13.2                                ...           3 years ago
  • 5.13.1                                ...           4 years ago
  • 5.13.0                                ...           4 years ago
  • 5.12.2                                ...           4 years ago
  • 5.12.1                                ...           4 years ago
  • 5.12.0                                ...           4 years ago
  • 5.11.1                                ...           4 years ago
  • 5.11.0                                ...           4 years ago
  • 5.10.2                                ...           4 years ago
  • 5.10.1                                ...           4 years ago
  • 5.10.0                                ...           4 years ago
  • 5.9.9                                ...           4 years ago
  • 5.9.8                                ...           4 years ago
  • 5.9.7                                ...           4 years ago
  • 5.9.6                                ...           4 years ago
  • 5.9.5                                ...           4 years ago
  • 5.9.4                                ...           4 years ago
  • 5.9.3                                ...           4 years ago
  • 5.9.2                                ...           4 years ago
  • 5.9.1                                ...           4 years ago
  • 5.9.0                                ...           4 years ago
  • 5.8.1                                ...           4 years ago
  • 5.8.0                                ...           4 years ago
  • 5.7.0                                ...           4 years ago
  • 5.6.6                                ...           4 years ago
  • 5.6.5                                ...           4 years ago
  • 5.6.4                                ...           4 years ago
  • 5.6.3                                ...           4 years ago
  • 5.6.2                                ...           4 years ago
  • 5.6.1                                ...           4 years ago
  • 5.6.0                                ...           4 years ago
  • 5.5.1                                ...           4 years ago
  • 5.5.0                                ...           4 years ago
  • 5.4.0                                ...           4 years ago
  • 5.3.5                                ...           4 years ago
  • 5.3.4                                ...           4 years ago
  • 5.3.3                                ...           4 years ago
  • 5.3.2                                ...           4 years ago
  • 5.3.1                                ...           4 years ago
  • 5.3.0                                ...           4 years ago
  • 5.2.1                                ...           4 years ago
  • 5.2.0                                ...           4 years ago
  • 5.1.0                                ...           4 years ago
  • 5.0.7                                ...           4 years ago
  • 5.0.6                                ...           4 years ago
  • 5.0.5                                ...           4 years ago
  • 5.0.4                                ...           5 years ago
  • 5.0.3                                ...           5 years ago
  • 5.0.1                                ...           5 years ago
  • 5.0.0                                ...           5 years ago
  • 4.21.1                                ...           5 years ago
  • 4.21.0                                ...           5 years ago
  • 4.20.7                                ...           5 years ago
  • 4.20.6                                ...           5 years ago
  • 4.20.5                                ...           5 years ago
  • 4.20.4                                ...           5 years ago
  • 4.20.3                                ...           5 years ago
  • 4.20.2                                ...           5 years ago
  • 4.20.1                                ...           5 years ago
  • 4.20.0                                ...           5 years ago
  • 4.19.0                                ...           5 years ago
  • 4.18.1                                ...           5 years ago
  • 4.18.0                                ...           5 years ago
  • 4.17.0                                ...           5 years ago
  • 4.16.3                                ...           5 years ago
  • 4.16.2                                ...           5 years ago
  • 4.16.1                                ...           5 years ago
  • 4.15.7                                ...           5 years ago
  • 4.15.6                                ...           5 years ago
  • 4.15.4                                ...           5 years ago
  • 4.15.3                                ...           5 years ago
  • 4.15.2                                ...           5 years ago
  • 4.14.4                                ...           5 years ago
  • 4.14.3                                ...           5 years ago
  • 4.14.2                                ...           5 years ago
  • 4.14.1                                ...           5 years ago
  • 4.14.0                                ...           5 years ago
  • 4.13.0                                ...           5 years ago
  • 4.12.0                                ...           5 years ago
  • 4.11.2                                ...           5 years ago
  • 4.11.1                                ...           5 years ago
  • 4.11.0                                ...           5 years ago
  • 4.10.0                                ...           5 years ago
  • 4.9.1                                ...           5 years ago
  • 4.9.0                                ...           5 years ago
  • 4.8.8                                ...           5 years ago
  • 4.8.7                                ...           5 years ago
  • 4.8.6                                ...           5 years ago
  • 4.8.5                                ...           5 years ago
  • 4.8.4                                ...           5 years ago
  • 4.8.3                                ...           5 years ago
  • 4.8.2                                ...           5 years ago
  • 4.8.1                                ...           5 years ago
  • 4.8.0                                ...           5 years ago
  • 4.7.1                                ...           5 years ago
  • 4.7.0                                ...           5 years ago
  • 4.6.0                                ...           6 years ago
  • 4.5.1                                ...           6 years ago
  • 4.5.0                                ...           7 years ago
  • 4.4.0                                ...           7 years ago
  • 4.3.1                                ...           7 years ago
  • 4.3.0                                ...           7 years ago
  • 4.2.0                                ...           7 years ago
  • 4.1.1                                ...           7 years ago
  • 4.1.0                                ...           7 years ago
  • 5.0.0-beta.0                                ...           7 years ago
  • 4.0.4                                ...           8 years ago
  • 4.0.3                                ...           8 years ago
  • 4.0.2                                ...           8 years ago
  • 4.0.1                                ...           8 years ago
  • 4.0.0                                ...           8 years ago
  • 3.4.1                                ...           8 years ago
  • 3.4.0                                ...           8 years ago
  • 3.3.0                                ...           8 years ago
  • 3.2.1                                ...           8 years ago
  • 3.2.0                                ...           8 years ago
  • 3.1.3                                ...           9 years ago
  • 3.1.2                                ...           9 years ago
  • 3.1.1                                ...           9 years ago
  • 3.1.0                                ...           9 years ago
  • 3.0.1                                ...           9 years ago
  • 3.0.0                                ...           9 years ago
  • 2.1.1                                ...           9 years ago
  • 2.1.0                                ...           9 years ago
  • 2.0.3                                ...           10 years ago
  • 2.0.2                                ...           10 years ago
  • 2.0.1                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 62
Last Day 0
Last Week 62
Last Month 0
Dependencies (2)
Dev Dependencies (16)

Copyright 2013 - present © cnpmjs.org | Home |