Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mistakes in propTypes #2911

Merged
merged 10 commits into from Jul 11, 2022
5 changes: 3 additions & 2 deletions packages/react-ui/components/Dropdown/Dropdown.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

import { ReactNodePropTypes } from '../../lib/utils';
import { filterProps } from '../../lib/filterProps';
import { MenuHeader } from '../MenuHeader';
import { MenuItem } from '../MenuItem';
Expand Down Expand Up @@ -107,7 +108,7 @@ export class Dropdown extends React.Component<DropdownProps> {
/**
* Подпись на кнопке.
*/
caption: PropTypes.node.isRequired,
caption: ReactNodePropTypes.isRequired,

/**
* Отключает использование портала
Expand All @@ -127,7 +128,7 @@ export class Dropdown extends React.Component<DropdownProps> {
/**
* Иконка слева от текста кнопки
*/
icon: PropTypes.node,
icon: ReactNodePropTypes,

maxMenuHeight: PropTypes.number,

Expand Down
3 changes: 2 additions & 1 deletion packages/react-ui/components/Kebab/Kebab.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

import { ReactNodePropTypes } from '../../lib/utils';
import { isKeyArrowVertical, isKeyEnter, isKeySpace, someKeys } from '../../lib/events/keyboard/identifiers';
import * as LayoutEvents from '../../lib/LayoutEvents';
import { keyListener } from '../../lib/events/keyListener';
Expand Down Expand Up @@ -212,7 +213,7 @@ export class Kebab extends React.Component<KebabProps, KebabState> {
}

Kebab.propTypes = {
children: PropTypes.node,
children: ReactNodePropTypes,
disabled: PropTypes.bool,
menuMaxHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

Expand Down
4 changes: 2 additions & 2 deletions packages/react-ui/components/Link/Link.tsx
Expand Up @@ -5,7 +5,7 @@ import { Override } from '../../typings/utility-types';
import { keyListener } from '../../lib/events/keyListener';
import { Theme } from '../../lib/theming/Theme';
import { ThemeContext } from '../../lib/theming/ThemeContext';
import { isExternalLink } from '../../lib/utils';
import { ReactNodePropTypes, isExternalLink } from '../../lib/utils';
import { Spinner } from '../Spinner';
import { CommonWrapper, CommonProps, CommonWrapperRestProps } from '../../internal/CommonWrapper';
import { cx } from '../../lib/theming/Emotion';
Expand Down Expand Up @@ -77,7 +77,7 @@ export class Link extends React.Component<LinkProps, LinkState> {

href: PropTypes.string,

icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
icon: ReactNodePropTypes,

use: PropTypes.oneOf(['default', 'success', 'danger', 'grayed']),
};
Expand Down
3 changes: 2 additions & 1 deletion packages/react-ui/components/Loader/Loader.tsx
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import debounce from 'lodash.debounce';

import { ReactNodePropTypes } from '../../lib/utils';
import * as LayoutEvents from '../../lib/LayoutEvents';
import { Spinner, SpinnerProps } from '../Spinner';
import { Nullable } from '../../typings/utility-types';
Expand Down Expand Up @@ -83,7 +84,7 @@ export class Loader extends React.Component<LoaderProps, LoaderState> {
*/
caption: Spinner.propTypes.caption,

component: PropTypes.node,
component: ReactNodePropTypes,

/**
* Класс для обертки
Expand Down
6 changes: 3 additions & 3 deletions packages/react-ui/components/MenuItem/MenuItem.tsx
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

import { isFunction, isReactUIComponent } from '../../lib/utils';
import { ReactNodePropTypes, isFunction, isReactUIComponent } from '../../lib/utils';
import { ThemeContext } from '../../lib/theming/ThemeContext';
import { Theme } from '../../lib/theming/Theme';
import { CommonProps, CommonWrapper, CommonWrapperRestProps } from '../../internal/CommonWrapper';
Expand Down Expand Up @@ -93,13 +93,13 @@ export class MenuItem extends React.Component<MenuItemProps> {
public static __MENU_ITEM__ = true;

public static propTypes = {
comment: PropTypes.node,
comment: ReactNodePropTypes,

disabled: PropTypes.bool,

href: PropTypes.string,

icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
icon: ReactNodePropTypes,

loose: PropTypes.bool,

Expand Down
4 changes: 2 additions & 2 deletions packages/react-ui/components/RadioGroup/RadioGroup.tsx
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import invariant from 'invariant';

import { getRandomID, isNonNullable } from '../../lib/utils';
import { ReactNodePropTypes, getRandomID, isNonNullable } from '../../lib/utils';
import { Radio } from '../Radio';
import { createPropsGetter } from '../../lib/createPropsGetter';
import { Nullable } from '../../typings/utility-types';
Expand Down Expand Up @@ -99,7 +99,7 @@ export class RadioGroup<T> extends React.Component<RadioGroupProps<T>, RadioGrou
public static __KONTUR_REACT_UI__ = 'RadioGroup';

public static propTypes = {
children: PropTypes.node,
children: ReactNodePropTypes,
disabled: PropTypes.bool,
error: PropTypes.bool,
inline: PropTypes.bool,
Expand Down
@@ -1,7 +1,7 @@
import React, { useEffect } from 'react';
import propTypes from 'prop-types';

import { isFunction } from '../../lib/utils';
import { ReactNodePropTypes, isFunction } from '../../lib/utils';
import { CommonWrapper } from '../../internal/CommonWrapper';

import { ResponsiveLayoutFlags } from './types';
Expand Down Expand Up @@ -34,5 +34,5 @@ export const ResponsiveLayout: React.FC<ResponsiveLayoutProps> = (props) => {

ResponsiveLayout.propTypes = {
onLayoutChange: propTypes.func,
children: propTypes.oneOfType([propTypes.node, propTypes.func]),
children: ReactNodePropTypes,
};
4 changes: 2 additions & 2 deletions packages/react-ui/components/Select/Select.tsx
Expand Up @@ -22,7 +22,7 @@ import { MenuSeparator } from '../MenuSeparator';
import { RenderLayer } from '../../internal/RenderLayer';
import { createPropsGetter } from '../../lib/createPropsGetter';
import { Nullable } from '../../typings/utility-types';
import { isFunction, isNonNullable, isReactUINode } from '../../lib/utils';
import { ReactNodePropTypes, isFunction, isNonNullable, isReactUINode } from '../../lib/utils';
import { ThemeContext } from '../../lib/theming/ThemeContext';
import { Theme } from '../../lib/theming/Theme';
import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper';
Expand Down Expand Up @@ -180,7 +180,7 @@ export class Select<TValue = {}, TItem = {}> extends React.Component<SelectProps
items: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
maxMenuHeight: PropTypes.number,
maxWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
placeholder: PropTypes.node,
placeholder: ReactNodePropTypes,
renderItem: PropTypes.func,
renderValue: PropTypes.func,
search: PropTypes.bool,
Expand Down
3 changes: 2 additions & 1 deletion packages/react-ui/components/Spinner/Spinner.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

import { ReactNodePropTypes } from '../../lib/utils';
import { locale } from '../../lib/locale/decorators';
import { Theme } from '../../lib/theming/Theme';
import { ThemeContext } from '../../lib/theming/ThemeContext';
Expand Down Expand Up @@ -58,7 +59,7 @@ export class Spinner extends React.Component<SpinnerProps> {
*
* 'Загрузка' - значение по-умолчанию
*/
caption: PropTypes.node,
caption: ReactNodePropTypes,

dimmed: PropTypes.bool,

Expand Down
4 changes: 2 additions & 2 deletions packages/react-ui/components/Sticky/Sticky.tsx
Expand Up @@ -4,7 +4,7 @@ import shallowEqual from 'shallowequal';

import * as LayoutEvents from '../../lib/LayoutEvents';
import { Nullable } from '../../typings/utility-types';
import { isFunction } from '../../lib/utils';
import { ReactNodePropTypes, isFunction } from '../../lib/utils';
import { ZIndex } from '../../internal/ZIndex';
import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper';
import { cx } from '../../lib/theming/Emotion';
Expand Down Expand Up @@ -45,7 +45,7 @@ export class Sticky extends React.Component<StickyProps, StickyState> {
public static __KONTUR_REACT_UI__ = 'Sticky';

public static propTypes = {
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
children: ReactNodePropTypes,
lossir marked this conversation as resolved.
Show resolved Hide resolved

/**
* Функция, которая возвращает DOM-элемент, который нельзя пересекать.
Expand Down
4 changes: 2 additions & 2 deletions packages/react-ui/components/Tabs/Tab.tsx
Expand Up @@ -6,7 +6,7 @@ import { ResizeDetector } from '../../internal/ResizeDetector';
import { isKeyArrow, isKeyArrowLeft, isKeyArrowUp } from '../../lib/events/keyboard/identifiers';
import { keyListener } from '../../lib/events/keyListener';
import { Nullable } from '../../typings/utility-types';
import { isFunctionalComponent } from '../../lib/utils';
import { ReactNodePropTypes, isFunctionalComponent } from '../../lib/utils';
import { ThemeContext } from '../../lib/theming/ThemeContext';
import { Theme } from '../../lib/theming/Theme';
import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper';
Expand Down Expand Up @@ -117,7 +117,7 @@ export class Tab<T extends string = string> extends React.Component<TabProps<T>,
public context: TabsContextType = this.context;

public static propTypes = {
children: PropTypes.node,
children: ReactNodePropTypes,
disabled: PropTypes.bool,
href: PropTypes.string.isRequired,
onClick: PropTypes.func,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-ui/components/Tabs/Tabs.tsx
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

import { emptyHandler } from '../../lib/utils';
import { ReactNodePropTypes, emptyHandler } from '../../lib/utils';
import { ThemeContext } from '../../lib/theming/ThemeContext';
import { Theme } from '../../lib/theming/Theme';
import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper';
Expand Down Expand Up @@ -68,7 +68,7 @@ export class Tabs<T extends string = string> extends React.Component<TabsProps<T
public static __KONTUR_REACT_UI__ = 'Tabs';

public static propTypes = {
children: PropTypes.node,
children: ReactNodePropTypes,
indicatorClassName: PropTypes.string,
value: PropTypes.string.isRequired,
vertical: PropTypes.bool,
Expand Down
9 changes: 5 additions & 4 deletions packages/react-ui/components/Textarea/TextareaCounter.tsx
@@ -1,10 +1,11 @@
import React, { SyntheticEvent, useContext, useCallback, useImperativeHandle, useState } from 'react';
import propTypes from 'prop-types';

import { safePropTypesInstanceOf } from '../../lib/SSRSafe';
import { forwardRefAndName } from '../../lib/forwardRefAndName';
import { HelpDotIcon } from '../../internal/icons/16px';
import { ThemeContext } from '../../lib/theming/ThemeContext';
import { isFunction } from '../../lib/utils';
import { ReactNodePropTypes, isFunction } from '../../lib/utils';
import { Tooltip } from '../Tooltip';
import { cx } from '../../lib/theming/Emotion';

Expand Down Expand Up @@ -65,8 +66,8 @@ export const TextareaCounter = forwardRefAndName<TextareaCounterRef, TextareaCou

TextareaCounter.propTypes = {
length: propTypes.number.isRequired,
value: propTypes.oneOf([propTypes.string, propTypes.number]),
help: propTypes.oneOf([propTypes.node, propTypes.func]),
value: propTypes.oneOfType([propTypes.string, propTypes.number]),
help: ReactNodePropTypes,
lossir marked this conversation as resolved.
Show resolved Hide resolved
onCloseHelp: propTypes.func.isRequired,
textarea: propTypes.node.isRequired,
textarea: safePropTypesInstanceOf(() => HTMLElement).isRequired,
};
8 changes: 4 additions & 4 deletions packages/react-ui/internal/Popup/Popup.tsx
Expand Up @@ -9,11 +9,11 @@ import * as LayoutEvents from '../../lib/LayoutEvents';
import { ZIndex } from '../ZIndex';
import { RenderContainer } from '../RenderContainer';
import { FocusEventType, MouseEventType } from '../../typings/event-types';
import { isFunction, isNonNullable, isNullable, isRefableElement } from '../../lib/utils';
import { ReactNodePropTypes, isFunction, isNonNullable, isNullable, isRefableElement } from '../../lib/utils';
import { isIE11, isEdge, isSafari } from '../../lib/client';
import { ThemeContext } from '../../lib/theming/ThemeContext';
import { Theme } from '../../lib/theming/Theme';
import { isHTMLElement, safePropTypesInstanceOf } from '../../lib/SSRSafe';
import { isHTMLElement } from '../../lib/SSRSafe';
import { isTestEnv } from '../../lib/currentEnvironment';
import { CommonProps, CommonWrapper } from '../CommonWrapper';
import { cx } from '../../lib/theming/Emotion';
Expand Down Expand Up @@ -128,14 +128,14 @@ export class Popup extends React.Component<PopupProps, PopupState> {
/**
* Ссылка (ref) на элемент или React компонент, для которого рисуется попап
*/
anchorElement: PropTypes.oneOfType([safePropTypesInstanceOf(() => HTMLElement), PropTypes.node]).isRequired,
anchorElement: ReactNodePropTypes.isRequired,

/**
* Фон попапа и пина
*/
backgroundColor: PropTypes.string,

children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
children: ReactNodePropTypes,
lossir marked this conversation as resolved.
Show resolved Hide resolved

/**
* Показывать ли пин
Expand Down
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import propTypes from 'prop-types';

import { ReactNodePropTypes } from '../../lib/utils';
import { Nullable } from '../../typings/utility-types';
import { safePropTypesInstanceOf } from '../../lib/SSRSafe';

Expand Down Expand Up @@ -67,5 +68,5 @@ export class RenderInnerContainer extends React.Component<RenderInnerContainerPr
Portal.propTypes = {
container: safePropTypesInstanceOf(() => HTMLElement),
rt_rootID: propTypes.string.isRequired,
children: propTypes.node.isRequired,
children: ReactNodePropTypes.isRequired,
};
5 changes: 3 additions & 2 deletions packages/react-ui/internal/icons/16px/index.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import propTypes from 'prop-types';

import { ReactNodePropTypes } from '../../../lib/utils';
import { forwardRefAndName } from '../../../lib/forwardRefAndName';

import { styles } from './icon.styles';
Expand Down Expand Up @@ -30,9 +31,9 @@ const SvgIcon = forwardRefAndName<HTMLElement, SvgIconProps>(

SvgIcon.propTypes = {
color: propTypes.string,
size: propTypes.oneOf([propTypes.string, propTypes.number]),
size: propTypes.oneOfType([propTypes.string, propTypes.number]),
style: propTypes.object,
children: propTypes.node,
children: ReactNodePropTypes,
};

export const ArrowChevronDownIcon = forwardRefAndName<HTMLElement, SvgIconProps>(
Expand Down
4 changes: 3 additions & 1 deletion packages/react-ui/internal/icons/20px/svg.tsx
@@ -1,6 +1,8 @@
import React from 'react';
import propTypes from 'prop-types';

import { ReactNodePropTypes } from '../../../lib/utils';

import { styles } from './icon.styles';

export interface SVGIconProps extends React.HTMLAttributes<HTMLSpanElement> {
Expand All @@ -18,7 +20,7 @@ export const SvgIcon: React.FunctionComponent<SVGIconProps> = ({ children, color
);

SvgIcon.propTypes = {
children: propTypes.node,
children: ReactNodePropTypes,
color: propTypes.string,
};

Expand Down
7 changes: 6 additions & 1 deletion packages/react-ui/lib/utils.ts
@@ -1,4 +1,4 @@
import { ReactComponentLike } from 'prop-types';
import propTypes, { ReactComponentLike } from 'prop-types';
import React from 'react';
import { isForwardRef } from 'react-is';

Expand Down Expand Up @@ -94,6 +94,11 @@ const calculateDecimals = (decimals: number) => {
return 0;
};

/**
* Analogue of React.ReactNode but for prop-types
*/
export const ReactNodePropTypes = propTypes.oneOfType([propTypes.element, propTypes.node, propTypes.bool]);
lossir marked this conversation as resolved.
Show resolved Hide resolved

export const formatBytes = (bytes: number, decimals = 2): string | null => {
if (bytes === 0) {
return '0 Bytes';
Expand Down