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

Типы в defaultProps #2760

Closed
wants to merge 13 commits into from
20 changes: 14 additions & 6 deletions packages/react-ui-validations/src/ValidationContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,30 @@ import { Nullable } from '../typings/Types';
import { isTestEnv } from './utils/utils';
import { ValidationContextWrapper } from './ValidationContextWrapper';

export interface ScrollOffset {
export type ScrollOffset = {
top?: number;
bottom?: number;
}
};

export interface ValidationContainerProps {
type ValidationContainerInterface = {
children?: React.ReactNode;
onValidationUpdated?: (isValid?: Nullable<boolean>) => void;
scrollOffset?: number | ScrollOffset;
disableSmoothScroll: boolean;
}
};

export type ValidationContainerProps = ValidationContainerInterface & Partial<DefaultProps>;

type DefaultProps = {
disableSmoothScroll: boolean;
};

type ValidationContainerComponentProps = ValidationContainerProps & DefaultProps;

export class ValidationContainer extends React.Component<ValidationContainerProps> {
export class ValidationContainer extends React.Component<ValidationContainerComponentProps> {
public static __KONTUR_REACT_UI__ = 'ValidationContainer';

public static defaultProps = {
public static defaultProps: DefaultProps = {
disableSmoothScroll: isTestEnv,
};

Expand Down
84 changes: 42 additions & 42 deletions packages/react-ui/components/Autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { DropdownContainer } from '../../internal/DropdownContainer';
import { Menu } from '../../internal/Menu';
import { MenuItem } from '../MenuItem';
import { RenderLayer } from '../../internal/RenderLayer';
import { createPropsGetter } from '../../lib/createPropsGetter';
import { Nullable, Override } from '../../typings/utility-types';
import { fixClickFocusIE } from '../../lib/events/fixClickFocusIE';
import { CommonProps, CommonWrapper, CommonWrapperRestProps } from '../../internal/CommonWrapper';
Expand All @@ -33,48 +32,50 @@ function renderItem(item: any) {
return item;
}

export interface AutocompleteProps
extends CommonProps,
Override<
InputProps,
{
/** Функция отрисовки элемента меню */
renderItem: (item: string) => React.ReactNode;
/** Промис, резолвящий элементы меню */
source?: string[] | ((patter: string) => Promise<string[]>);
/** Отключает использование портала */
disablePortal: boolean;
/** Отрисовка тени у выпадающего меню */
hasShadow: boolean;
/** Выравнивание выпадающего меню */
menuAlign: 'left' | 'right';
/** Максимальная высота меню */
menuMaxHeight: number | string;
/** Ширина меню */
menuWidth?: number | string;
/** Отключить скролл окна, когда меню открыто */
preventWindowScroll: boolean;
/** Вызывается при изменении `value` */
onValueChange: (value: string) => void;
/** onBlur */
onBlur?: () => void;
/** Размер инпута */
size: InputProps['size'];
/** value */
value: string;
/**
* Текст заголовка выпадающего меню в мобильной версии
*/
mobileMenuHeaderText?: string;
}
> {}
type AutocompleteInterface = {
/** Промис, резолвящий элементы меню */
source?: string[] | ((patter: string) => Promise<string[]>);
/** Выравнивание выпадающего меню */
menuWidth?: number | string;
/** Вызывается при изменении `value` */
onValueChange: (value: string) => void;
/** onBlur */
onBlur?: () => void;
/** value */
value: string;
/**
* Текст заголовка выпадающего меню в мобильной версии
*/
mobileMenuHeaderText?: string;
};

export interface AutocompleteState {
export type AutocompleteState = {
items: Nullable<string[]>;
selected: number;
focused: boolean;
isMobileOpened: boolean;
}
};

type DefaultProps = {
/** Функция отрисовки элемента меню */
renderItem: (item: string) => React.ReactNode;
/** Размер инпута */
size: InputProps['size'];
/** Отключает использование портала */
disablePortal: boolean;
/** Отрисовка тени у выпадающего меню */
hasShadow: boolean;
/** Максимальная высота меню */
menuMaxHeight: number;
/** Выравнивание выпадающего меню */
menuAlign: 'left' | 'right';
/** Отключить скролл окна, когда меню открыто */
preventWindowScroll: boolean;
};

export type AutocompleteProps = Override<InputProps, AutocompleteInterface> & CommonProps & Partial<DefaultProps>;

type AutocompleteComponentProps = AutocompleteProps & DefaultProps;

/**
* Стандартный инпут с подсказками.
Expand All @@ -83,7 +84,7 @@ export interface AutocompleteState {
*/
@responsiveLayout
@rootNode
export class Autocomplete extends React.Component<AutocompleteProps, AutocompleteState> {
export class Autocomplete extends React.Component<AutocompleteComponentProps, AutocompleteState> {
public static __KONTUR_REACT_UI__ = 'Autocomplete';

public static propTypes = {
Expand All @@ -109,7 +110,7 @@ export class Autocomplete extends React.Component<AutocompleteProps, Autocomplet
source: PropTypes.oneOfType([PropTypes.array, PropTypes.func]),
};

public static defaultProps = {
public static defaultProps: DefaultProps = {
renderItem,
size: 'small',
disablePortal: false,
Expand All @@ -136,7 +137,6 @@ export class Autocomplete extends React.Component<AutocompleteProps, Autocomplet

private requestId = 0;

private getProps = createPropsGetter(Autocomplete.defaultProps);
private setRootNode!: TSetRootNode;

/**
Expand Down Expand Up @@ -277,7 +277,7 @@ export class Autocomplete extends React.Component<AutocompleteProps, Autocomplet
? items.map((item, i) => {
return (
<MenuItem onClick={this.handleMenuItemClick(i)} key={i} isMobile={isMobile}>
{this.getProps().renderItem(item)}
{this.props.renderItem(item)}
</MenuItem>
);
})
Expand Down
61 changes: 33 additions & 28 deletions packages/react-ui/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ export type ButtonSize = 'small' | 'medium' | 'large';
export type ButtonType = 'button' | 'submit' | 'reset';
export type ButtonUse = 'default' | 'primary' | 'success' | 'danger' | 'pay' | 'link';

export interface ButtonProps extends CommonProps {
/** @ignore */
_noPadding?: boolean;
type ButtonInterface = {
/** @ignore */ _noPadding?: boolean;

/** @ignore */
_noRightPadding?: boolean;
Expand Down Expand Up @@ -123,60 +122,66 @@ export interface ButtonProps extends CommonProps {
onMouseOver?: React.MouseEventHandler<HTMLButtonElement>;

/**
* Задаёт размер кнопки.
*
* **Допустимые значения**: `"small"`, `"medium"`, `"large"`.
* HTML-атрибут `title`.
*/
size?: ButtonSize;
title?: string;

/** @ignore */
visuallyFocused?: boolean;

/**
* HTML-атрибут `type`.
* Cостояние валидации при предупреждении.
*/
type?: ButtonType;
warning?: boolean;

/**
* HTML-атрибут `title`.
* CSS-свойство `width`.
*/
title?: string;
width?: number | string;
};

export type ButtonProps = ButtonInterface & CommonProps & Partial<DefaultProps>;

export type ButtonState = {
focusedByTab: boolean;
};

type DefaultProps = {
/**
* Стиль кнопки.
*
* **Допустимые значения**: `"default"`, `"primary"`, `"success"`, `"danger"`, `"pay"`, `"link"`.
*/
use?: ButtonUse;

/** @ignore */
visuallyFocused?: boolean;
use: ButtonUse;

/**
* Cостояние валидации при предупреждении.
* Задаёт размер кнопки.
*
* **Допустимые значения**: `"small"`, `"medium"`, `"large"`.
*/
warning?: boolean;
size: ButtonSize;

/**
* CSS-свойство `width`.
* HTML-атрибут `type`.
*/
width?: number | string;
}
type: ButtonType;
};

export interface ButtonState {
focusedByTab: boolean;
}
type ButtonComponentProps = ButtonProps & DefaultProps;

@rootNode
export class Button extends React.Component<ButtonProps, ButtonState> {
export class Button extends React.Component<ButtonComponentProps, ButtonState> {
public static __KONTUR_REACT_UI__ = 'Button';
public static __BUTTON__ = true;
public static TOP_LEFT = Corners.TOP_LEFT;
public static TOP_RIGHT = Corners.TOP_RIGHT;
public static BOTTOM_RIGHT = Corners.BOTTOM_RIGHT;
public static BOTTOM_LEFT = Corners.BOTTOM_LEFT;

public static defaultProps = {
use: 'default' as ButtonUse,
size: 'small' as ButtonSize,
type: 'button' as ButtonType,
public static defaultProps: DefaultProps = {
use: 'default',
size: 'small',
type: 'button',
};

public state = {
Expand Down
30 changes: 14 additions & 16 deletions packages/react-ui/components/Center/Center.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';

import { Override } from '../../typings/utility-types';
import { CommonProps, CommonWrapper, CommonWrapperRestProps } from '../../internal/CommonWrapper';
import { cx } from '../../lib/theming/Emotion';
import { rootNode, TSetRootNode } from '../../lib/rootNode';
Expand All @@ -9,28 +8,27 @@ import { styles } from './Center.styles';

export type HorizontalAlign = 'left' | 'center' | 'right';

export interface CenterProps
extends CommonProps,
Override<
React.HTMLAttributes<HTMLDivElement>,
{
/**
* Определяет, как контент будет выровнен по горизонтали.
*
* **Допустимые значения**: `"left"`, `"center"`, `"right"`.
*/
align?: HorizontalAlign;
}
> {}
export type CenterProps = React.HTMLAttributes<HTMLDivElement> & CommonProps & Partial<DefaultProps>;

type DefaultProps = {
/**
* Определяет, как контент будет выровнен по горизонтали.
*
* **Допустимые значения**: `"left"`, `"center"`, `"right"`.
*/
align: HorizontalAlign;
};

type CenterComponentProps = CenterProps & DefaultProps;

/**
* Контейнер, который центрирует элементы внутри себя.
*/
@rootNode
export class Center extends React.Component<CenterProps> {
export class Center extends React.Component<CenterComponentProps> {
public static __KONTUR_REACT_UI__ = 'Center';

public static defaultProps = {
public static defaultProps: DefaultProps = {
align: 'center',
};
private setRootNode!: TSetRootNode;
Expand Down
Loading