From 78448ce001372cf62638e24500d9884dcf79353a Mon Sep 17 00:00:00 2001 From: HelenaIsh Date: Mon, 7 Feb 2022 15:51:00 +0500 Subject: [PATCH 01/11] chore: fix default props type --- packages/react-ui/components/Autocomplete/Autocomplete.tsx | 4 ++-- packages/react-ui/components/Center/Center.tsx | 2 +- .../react-ui/components/CurrencyInput/CurrencyInput.tsx | 1 - packages/react-ui/components/DatePicker/DatePicker.tsx | 2 +- packages/react-ui/components/DropdownMenu/DropdownMenu.tsx | 2 +- packages/react-ui/components/FxInput/FxInput.tsx | 2 +- packages/react-ui/components/Input/Input.tsx | 6 ++---- packages/react-ui/components/Kebab/Kebab.tsx | 2 +- .../react-ui/components/PasswordInput/PasswordInput.tsx | 4 ++-- .../react-ui/components/ScrollContainer/ScrollContainer.tsx | 2 +- packages/react-ui/components/Select/Select.tsx | 2 +- packages/react-ui/components/Spinner/Spinner.tsx | 2 +- packages/react-ui/components/TokenInput/TokenInput.tsx | 4 ++-- packages/react-ui/components/Tooltip/Tooltip.tsx | 5 ++--- packages/react-ui/internal/Calendar/Calendar.tsx | 5 ++--- packages/react-ui/internal/InputLikeText/InputLikeText.tsx | 4 ++-- packages/react-ui/internal/Popup/Popup.tsx | 2 +- packages/react-ui/internal/ZIndex/ZIndex.tsx | 2 +- 18 files changed, 24 insertions(+), 29 deletions(-) diff --git a/packages/react-ui/components/Autocomplete/Autocomplete.tsx b/packages/react-ui/components/Autocomplete/Autocomplete.tsx index 0f7d9923970..0e87567b393 100644 --- a/packages/react-ui/components/Autocomplete/Autocomplete.tsx +++ b/packages/react-ui/components/Autocomplete/Autocomplete.tsx @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; import { isKeyArrowDown, isKeyArrowUp, isKeyEnter, isKeyEscape } from '../../lib/events/keyboard/identifiers'; -import { Input, InputProps } from '../Input'; +import { Input, InputProps, InputSize } from '../Input'; import { DropdownContainer } from '../../internal/DropdownContainer'; import { Menu } from '../../internal/Menu'; import { MenuItem } from '../MenuItem'; @@ -101,7 +101,7 @@ export class Autocomplete extends React.Component { public static __KONTUR_REACT_UI__ = 'Center'; public static defaultProps = { - align: 'center', + align: 'center' as HorizontalAlign, }; private setRootNode!: TSetRootNode; diff --git a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx index 99b21056745..59bbbda7241 100644 --- a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx +++ b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx @@ -87,7 +87,6 @@ export class CurrencyInput extends React.PureComponent extends CommonProps { +export interface DatePickerProps extends CommonProps { autoFocus?: boolean; disabled?: boolean; enableTodayLink?: boolean; diff --git a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx index 5396d8f2bc0..9eeacb3e58f 100644 --- a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx +++ b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx @@ -65,7 +65,7 @@ export class DropdownMenu extends React.Component { public static defaultProps = { disableAnimations: isTestEnv, - positions: ['bottom left', 'bottom right', 'top left', 'top right'], + positions: ['bottom left', 'bottom right', 'top left', 'top right'] as PopupPositionsType[], }; private popupMenu: Nullable = null; diff --git a/packages/react-ui/components/FxInput/FxInput.tsx b/packages/react-ui/components/FxInput/FxInput.tsx index b7fa770025a..d7113130629 100644 --- a/packages/react-ui/components/FxInput/FxInput.tsx +++ b/packages/react-ui/components/FxInput/FxInput.tsx @@ -45,7 +45,7 @@ export class FxInput extends React.Component { public static defaultProps = { width: 250, - type: 'text', + type: 'text' as 'currency' | InputProps['type'], value: '', }; diff --git a/packages/react-ui/components/Input/Input.tsx b/packages/react-ui/components/Input/Input.tsx index 9a2efea4529..76476a641dd 100644 --- a/packages/react-ui/components/Input/Input.tsx +++ b/packages/react-ui/components/Input/Input.tsx @@ -115,10 +115,8 @@ export interface InputState { export class Input extends React.Component { public static __KONTUR_REACT_UI__ = 'Input'; - public static defaultProps: { - size: InputSize; - } = { - size: 'small', + public static defaultProps = { + size: 'small' as InputSize, }; public state: InputState = { diff --git a/packages/react-ui/components/Kebab/Kebab.tsx b/packages/react-ui/components/Kebab/Kebab.tsx index 5679f3f2938..35feab6a113 100644 --- a/packages/react-ui/components/Kebab/Kebab.tsx +++ b/packages/react-ui/components/Kebab/Kebab.tsx @@ -66,7 +66,7 @@ export class Kebab extends React.Component { public static defaultProps = { onOpen: () => undefined, onClose: () => undefined, - positions: ['bottom left', 'bottom right', 'top left', 'top right'], + positions: ['bottom left', 'bottom right', 'top left', 'top right'] as PopupPositionsType[], size: 'small', disableAnimations: isTestEnv, icon: , diff --git a/packages/react-ui/components/PasswordInput/PasswordInput.tsx b/packages/react-ui/components/PasswordInput/PasswordInput.tsx index 2d8e9b946f8..e7b16207252 100644 --- a/packages/react-ui/components/PasswordInput/PasswordInput.tsx +++ b/packages/react-ui/components/PasswordInput/PasswordInput.tsx @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { isKeyCapsLock } from '../../lib/events/keyboard/identifiers'; import { KeyboardEventCodes as Codes } from '../../lib/events/keyboard/KeyboardEventCodes'; -import { Input, InputProps } from '../Input'; +import { Input, InputProps, InputSize } from '../Input'; import { Nullable } from '../../typings/utility-types'; import { EyeClosedIcon, EyeOpenedIcon } from '../../internal/icons/16px'; import { isIE11 } from '../../lib/client'; @@ -39,7 +39,7 @@ export class PasswordInput extends React.PureComponent { public static defaultProps = { invert: false, - scrollBehaviour: 'auto', + scrollBehaviour: 'auto' as ScrollBehaviour, preventWindowScroll: false, }; diff --git a/packages/react-ui/components/Select/Select.tsx b/packages/react-ui/components/Select/Select.tsx index 964466f4948..621574e741e 100644 --- a/packages/react-ui/components/Select/Select.tsx +++ b/packages/react-ui/components/Select/Select.tsx @@ -181,7 +181,7 @@ export class Select extends React.Component { }; public static defaultProps: SpinnerProps = { - type: 'normal', + type: 'normal' as SpinnerType, }; public static Types: typeof types = types; diff --git a/packages/react-ui/components/TokenInput/TokenInput.tsx b/packages/react-ui/components/TokenInput/TokenInput.tsx index b54b8ee2eb8..9e2493e9302 100644 --- a/packages/react-ui/components/TokenInput/TokenInput.tsx +++ b/packages/react-ui/components/TokenInput/TokenInput.tsx @@ -188,8 +188,8 @@ export class TokenInput extends React.PureComponent = DefaultState; diff --git a/packages/react-ui/components/Tooltip/Tooltip.tsx b/packages/react-ui/components/Tooltip/Tooltip.tsx index f76feceda1e..7cad04a25e8 100644 --- a/packages/react-ui/components/Tooltip/Tooltip.tsx +++ b/packages/react-ui/components/Tooltip/Tooltip.tsx @@ -166,12 +166,11 @@ export class Tooltip extends React.PureComponent { }; public static defaultProps = { - pos: DefaultPosition, - trigger: 'hover', + pos: DefaultPosition as PopupPositionsType, + trigger: 'hover' as TooltipTrigger, allowedPositions: Positions, disableAnimations: isTestEnv, useWrapper: false, - closeOnChildrenMouseLeave: false, }; public static delay = 100; diff --git a/packages/react-ui/internal/Calendar/Calendar.tsx b/packages/react-ui/internal/Calendar/Calendar.tsx index 836cc7116d6..904be850945 100644 --- a/packages/react-ui/internal/Calendar/Calendar.tsx +++ b/packages/react-ui/internal/Calendar/Calendar.tsx @@ -49,17 +49,16 @@ export class Calendar extends React.Component { public static __KONTUR_REACT_UI__ = 'Calendar'; public static defaultProps = { - holidays: [], minDate: { year: MIN_YEAR, month: MIN_MONTH, date: MIN_DATE, - }, + } as CalendarDateShape, maxDate: { year: MAX_YEAR, month: MAX_MONTH, date: MAX_DATE, - }, + } as CalendarDateShape, }; private theme!: Theme; diff --git a/packages/react-ui/internal/InputLikeText/InputLikeText.tsx b/packages/react-ui/internal/InputLikeText/InputLikeText.tsx index f3f67cd6265..8c11646bd26 100644 --- a/packages/react-ui/internal/InputLikeText/InputLikeText.tsx +++ b/packages/react-ui/internal/InputLikeText/InputLikeText.tsx @@ -6,7 +6,7 @@ import { MouseDrag, MouseDragEventHandler } from '../../lib/events/MouseDrag'; import { isEdge, isIE11, isMobile } from '../../lib/client'; import { Nullable } from '../../typings/utility-types'; import { removeAllSelections, selectNodeContents } from '../../components/DateInput/helpers/SelectionHelpers'; -import { InputProps, InputIconType, InputState } from '../../components/Input'; +import { InputProps, InputIconType, InputState, InputSize } from '../../components/Input'; import { styles as jsInputStyles } from '../../components/Input/Input.styles'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; @@ -34,7 +34,7 @@ export type InputLikeTextState = Omit; export class InputLikeText extends React.Component { public static __KONTUR_REACT_UI__ = 'InputLikeText'; - public static defaultProps = { size: 'small' }; + public static defaultProps = { size: 'small' as InputSize }; public state = { blinking: false, focused: false }; diff --git a/packages/react-ui/internal/Popup/Popup.tsx b/packages/react-ui/internal/Popup/Popup.tsx index 88504a7535f..c037c86bd8c 100644 --- a/packages/react-ui/internal/Popup/Popup.tsx +++ b/packages/react-ui/internal/Popup/Popup.tsx @@ -181,7 +181,7 @@ export class Popup extends React.Component { disableAnimations: isTestEnv, useWrapper: false, ignoreHover: false, - width: 'auto', + width: 'auto' as React.CSSProperties['width'], }; public state: PopupState = { location: this.props.opened ? DUMMY_LOCATION : null }; diff --git a/packages/react-ui/internal/ZIndex/ZIndex.tsx b/packages/react-ui/internal/ZIndex/ZIndex.tsx index e7555a39d24..760e4cac0f4 100644 --- a/packages/react-ui/internal/ZIndex/ZIndex.tsx +++ b/packages/react-ui/internal/ZIndex/ZIndex.tsx @@ -31,7 +31,7 @@ export class ZIndex extends React.Component { public static defaultProps = { delta: 10, priority: 0, - style: {}, + style: {} as React.CSSProperties, applyZIndex: true, coverChildren: false, createStackingContext: false, From 2d2d991bd64952fe19b380196c8770fb9952e7a7 Mon Sep 17 00:00:00 2001 From: HelenaIsh Date: Thu, 10 Feb 2022 17:46:39 +0500 Subject: [PATCH 02/11] Revert "chore: fix default props type" This reverts commit 78448ce001372cf62638e24500d9884dcf79353a. --- packages/react-ui/components/Autocomplete/Autocomplete.tsx | 4 ++-- packages/react-ui/components/Center/Center.tsx | 2 +- .../react-ui/components/CurrencyInput/CurrencyInput.tsx | 1 + packages/react-ui/components/DatePicker/DatePicker.tsx | 2 +- packages/react-ui/components/DropdownMenu/DropdownMenu.tsx | 2 +- packages/react-ui/components/FxInput/FxInput.tsx | 2 +- packages/react-ui/components/Input/Input.tsx | 6 ++++-- packages/react-ui/components/Kebab/Kebab.tsx | 2 +- .../react-ui/components/PasswordInput/PasswordInput.tsx | 4 ++-- .../react-ui/components/ScrollContainer/ScrollContainer.tsx | 2 +- packages/react-ui/components/Select/Select.tsx | 2 +- packages/react-ui/components/Spinner/Spinner.tsx | 2 +- packages/react-ui/components/TokenInput/TokenInput.tsx | 4 ++-- packages/react-ui/components/Tooltip/Tooltip.tsx | 5 +++-- packages/react-ui/internal/Calendar/Calendar.tsx | 5 +++-- packages/react-ui/internal/InputLikeText/InputLikeText.tsx | 4 ++-- packages/react-ui/internal/Popup/Popup.tsx | 2 +- packages/react-ui/internal/ZIndex/ZIndex.tsx | 2 +- 18 files changed, 29 insertions(+), 24 deletions(-) diff --git a/packages/react-ui/components/Autocomplete/Autocomplete.tsx b/packages/react-ui/components/Autocomplete/Autocomplete.tsx index 0e87567b393..0f7d9923970 100644 --- a/packages/react-ui/components/Autocomplete/Autocomplete.tsx +++ b/packages/react-ui/components/Autocomplete/Autocomplete.tsx @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; import { isKeyArrowDown, isKeyArrowUp, isKeyEnter, isKeyEscape } from '../../lib/events/keyboard/identifiers'; -import { Input, InputProps, InputSize } from '../Input'; +import { Input, InputProps } from '../Input'; import { DropdownContainer } from '../../internal/DropdownContainer'; import { Menu } from '../../internal/Menu'; import { MenuItem } from '../MenuItem'; @@ -101,7 +101,7 @@ export class Autocomplete extends React.Component { public static __KONTUR_REACT_UI__ = 'Center'; public static defaultProps = { - align: 'center' as HorizontalAlign, + align: 'center', }; private setRootNode!: TSetRootNode; diff --git a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx index 59bbbda7241..99b21056745 100644 --- a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx +++ b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx @@ -87,6 +87,7 @@ export class CurrencyInput extends React.PureComponent extends CommonProps { +export interface DatePickerProps extends CommonProps { autoFocus?: boolean; disabled?: boolean; enableTodayLink?: boolean; diff --git a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx index 9eeacb3e58f..5396d8f2bc0 100644 --- a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx +++ b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx @@ -65,7 +65,7 @@ export class DropdownMenu extends React.Component { public static defaultProps = { disableAnimations: isTestEnv, - positions: ['bottom left', 'bottom right', 'top left', 'top right'] as PopupPositionsType[], + positions: ['bottom left', 'bottom right', 'top left', 'top right'], }; private popupMenu: Nullable = null; diff --git a/packages/react-ui/components/FxInput/FxInput.tsx b/packages/react-ui/components/FxInput/FxInput.tsx index d7113130629..b7fa770025a 100644 --- a/packages/react-ui/components/FxInput/FxInput.tsx +++ b/packages/react-ui/components/FxInput/FxInput.tsx @@ -45,7 +45,7 @@ export class FxInput extends React.Component { public static defaultProps = { width: 250, - type: 'text' as 'currency' | InputProps['type'], + type: 'text', value: '', }; diff --git a/packages/react-ui/components/Input/Input.tsx b/packages/react-ui/components/Input/Input.tsx index 76476a641dd..9a2efea4529 100644 --- a/packages/react-ui/components/Input/Input.tsx +++ b/packages/react-ui/components/Input/Input.tsx @@ -115,8 +115,10 @@ export interface InputState { export class Input extends React.Component { public static __KONTUR_REACT_UI__ = 'Input'; - public static defaultProps = { - size: 'small' as InputSize, + public static defaultProps: { + size: InputSize; + } = { + size: 'small', }; public state: InputState = { diff --git a/packages/react-ui/components/Kebab/Kebab.tsx b/packages/react-ui/components/Kebab/Kebab.tsx index 35feab6a113..5679f3f2938 100644 --- a/packages/react-ui/components/Kebab/Kebab.tsx +++ b/packages/react-ui/components/Kebab/Kebab.tsx @@ -66,7 +66,7 @@ export class Kebab extends React.Component { public static defaultProps = { onOpen: () => undefined, onClose: () => undefined, - positions: ['bottom left', 'bottom right', 'top left', 'top right'] as PopupPositionsType[], + positions: ['bottom left', 'bottom right', 'top left', 'top right'], size: 'small', disableAnimations: isTestEnv, icon: , diff --git a/packages/react-ui/components/PasswordInput/PasswordInput.tsx b/packages/react-ui/components/PasswordInput/PasswordInput.tsx index e7b16207252..2d8e9b946f8 100644 --- a/packages/react-ui/components/PasswordInput/PasswordInput.tsx +++ b/packages/react-ui/components/PasswordInput/PasswordInput.tsx @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { isKeyCapsLock } from '../../lib/events/keyboard/identifiers'; import { KeyboardEventCodes as Codes } from '../../lib/events/keyboard/KeyboardEventCodes'; -import { Input, InputProps, InputSize } from '../Input'; +import { Input, InputProps } from '../Input'; import { Nullable } from '../../typings/utility-types'; import { EyeClosedIcon, EyeOpenedIcon } from '../../internal/icons/16px'; import { isIE11 } from '../../lib/client'; @@ -39,7 +39,7 @@ export class PasswordInput extends React.PureComponent { public static defaultProps = { invert: false, - scrollBehaviour: 'auto' as ScrollBehaviour, + scrollBehaviour: 'auto', preventWindowScroll: false, }; diff --git a/packages/react-ui/components/Select/Select.tsx b/packages/react-ui/components/Select/Select.tsx index 621574e741e..964466f4948 100644 --- a/packages/react-ui/components/Select/Select.tsx +++ b/packages/react-ui/components/Select/Select.tsx @@ -181,7 +181,7 @@ export class Select extends React.Component { }; public static defaultProps: SpinnerProps = { - type: 'normal' as SpinnerType, + type: 'normal', }; public static Types: typeof types = types; diff --git a/packages/react-ui/components/TokenInput/TokenInput.tsx b/packages/react-ui/components/TokenInput/TokenInput.tsx index 9e2493e9302..b54b8ee2eb8 100644 --- a/packages/react-ui/components/TokenInput/TokenInput.tsx +++ b/packages/react-ui/components/TokenInput/TokenInput.tsx @@ -188,8 +188,8 @@ export class TokenInput extends React.PureComponent = DefaultState; diff --git a/packages/react-ui/components/Tooltip/Tooltip.tsx b/packages/react-ui/components/Tooltip/Tooltip.tsx index 7cad04a25e8..f76feceda1e 100644 --- a/packages/react-ui/components/Tooltip/Tooltip.tsx +++ b/packages/react-ui/components/Tooltip/Tooltip.tsx @@ -166,11 +166,12 @@ export class Tooltip extends React.PureComponent { }; public static defaultProps = { - pos: DefaultPosition as PopupPositionsType, - trigger: 'hover' as TooltipTrigger, + pos: DefaultPosition, + trigger: 'hover', allowedPositions: Positions, disableAnimations: isTestEnv, useWrapper: false, + closeOnChildrenMouseLeave: false, }; public static delay = 100; diff --git a/packages/react-ui/internal/Calendar/Calendar.tsx b/packages/react-ui/internal/Calendar/Calendar.tsx index 904be850945..836cc7116d6 100644 --- a/packages/react-ui/internal/Calendar/Calendar.tsx +++ b/packages/react-ui/internal/Calendar/Calendar.tsx @@ -49,16 +49,17 @@ export class Calendar extends React.Component { public static __KONTUR_REACT_UI__ = 'Calendar'; public static defaultProps = { + holidays: [], minDate: { year: MIN_YEAR, month: MIN_MONTH, date: MIN_DATE, - } as CalendarDateShape, + }, maxDate: { year: MAX_YEAR, month: MAX_MONTH, date: MAX_DATE, - } as CalendarDateShape, + }, }; private theme!: Theme; diff --git a/packages/react-ui/internal/InputLikeText/InputLikeText.tsx b/packages/react-ui/internal/InputLikeText/InputLikeText.tsx index 8c11646bd26..f3f67cd6265 100644 --- a/packages/react-ui/internal/InputLikeText/InputLikeText.tsx +++ b/packages/react-ui/internal/InputLikeText/InputLikeText.tsx @@ -6,7 +6,7 @@ import { MouseDrag, MouseDragEventHandler } from '../../lib/events/MouseDrag'; import { isEdge, isIE11, isMobile } from '../../lib/client'; import { Nullable } from '../../typings/utility-types'; import { removeAllSelections, selectNodeContents } from '../../components/DateInput/helpers/SelectionHelpers'; -import { InputProps, InputIconType, InputState, InputSize } from '../../components/Input'; +import { InputProps, InputIconType, InputState } from '../../components/Input'; import { styles as jsInputStyles } from '../../components/Input/Input.styles'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; @@ -34,7 +34,7 @@ export type InputLikeTextState = Omit; export class InputLikeText extends React.Component { public static __KONTUR_REACT_UI__ = 'InputLikeText'; - public static defaultProps = { size: 'small' as InputSize }; + public static defaultProps = { size: 'small' }; public state = { blinking: false, focused: false }; diff --git a/packages/react-ui/internal/Popup/Popup.tsx b/packages/react-ui/internal/Popup/Popup.tsx index c037c86bd8c..88504a7535f 100644 --- a/packages/react-ui/internal/Popup/Popup.tsx +++ b/packages/react-ui/internal/Popup/Popup.tsx @@ -181,7 +181,7 @@ export class Popup extends React.Component { disableAnimations: isTestEnv, useWrapper: false, ignoreHover: false, - width: 'auto' as React.CSSProperties['width'], + width: 'auto', }; public state: PopupState = { location: this.props.opened ? DUMMY_LOCATION : null }; diff --git a/packages/react-ui/internal/ZIndex/ZIndex.tsx b/packages/react-ui/internal/ZIndex/ZIndex.tsx index 760e4cac0f4..e7555a39d24 100644 --- a/packages/react-ui/internal/ZIndex/ZIndex.tsx +++ b/packages/react-ui/internal/ZIndex/ZIndex.tsx @@ -31,7 +31,7 @@ export class ZIndex extends React.Component { public static defaultProps = { delta: 10, priority: 0, - style: {} as React.CSSProperties, + style: {}, applyZIndex: true, coverChildren: false, createStackingContext: false, From 7f702155bee49f683200938f70cdfe9d2233f515 Mon Sep 17 00:00:00 2001 From: HelenaIsh Date: Fri, 11 Feb 2022 09:09:34 +0500 Subject: [PATCH 03/11] chore: fix default props type --- .../components/Autocomplete/Autocomplete.tsx | 22 ++++++----- .../react-ui/components/Button/Button.tsx | 18 +++++---- .../react-ui/components/Center/Center.tsx | 10 +++-- .../react-ui/components/ComboBox/ComboBox.tsx | 22 ++++++----- .../CurrencyInput/CurrencyInput.tsx | 18 +++++---- .../CurrencyLabel/CurrencyLabel.tsx | 4 +- .../components/DateInput/DateInput.tsx | 18 +++++---- .../components/DatePicker/DatePicker.tsx | 14 ++++--- .../components/DropdownMenu/DropdownMenu.tsx | 12 ++++-- .../react-ui/components/FxInput/FxInput.tsx | 14 ++++--- .../react-ui/components/Gapped/Gapped.tsx | 14 ++++--- packages/react-ui/components/Hint/Hint.tsx | 19 ++++++---- packages/react-ui/components/Input/Input.tsx | 12 +++--- packages/react-ui/components/Kebab/Kebab.tsx | 20 ++++++---- packages/react-ui/components/Link/Link.tsx | 12 ++++-- .../react-ui/components/Loader/Loader.tsx | 16 +++++--- packages/react-ui/components/Modal/Modal.tsx | 12 ++++-- .../react-ui/components/Paging/Paging.tsx | 23 ++++++----- .../PasswordInput/PasswordInput.tsx | 10 +++-- packages/react-ui/components/Radio/Radio.tsx | 10 +++-- .../components/RadioGroup/RadioGroup.tsx | 12 ++++-- .../ScrollContainer/ScrollContainer.tsx | 14 ++++--- .../react-ui/components/Select/Select.tsx | 30 ++++++++------- .../react-ui/components/SidePage/SidePage.tsx | 14 ++++--- .../react-ui/components/Spinner/Spinner.tsx | 10 +++-- .../react-ui/components/Sticky/Sticky.tsx | 8 +++- packages/react-ui/components/Tabs/Tabs.tsx | 10 +++-- .../react-ui/components/Textarea/Textarea.tsx | 16 +++++--- .../react-ui/components/Toggle/Toggle.tsx | 14 ++++--- .../components/TokenInput/TokenInput.tsx | 38 ++++++++++--------- .../react-ui/components/Tooltip/Tooltip.tsx | 20 ++++++---- .../components/TooltipMenu/TooltipMenu.tsx | 10 +++-- packages/react-ui/internal/BGRuler.tsx | 36 ++++++++++-------- .../react-ui/internal/Calendar/Calendar.tsx | 29 +++++++------- packages/react-ui/internal/Calendar/Month.tsx | 10 +++-- .../react-ui/internal/ComponentCombinator.tsx | 16 +++++--- packages/react-ui/internal/ComponentTable.tsx | 11 +++++- .../internal/CustomComboBox/ComboBoxMenu.tsx | 12 ++++-- .../internal/CustomComboBox/ComboBoxView.tsx | 34 +++++++++-------- .../internal/DateSelect/DateSelect.tsx | 13 ++++--- .../DropdownContainer/DropdownContainer.tsx | 19 ++++++---- .../internal/InputLikeText/InputLikeText.tsx | 8 +++- .../internal/InternalMenu/InternalMenu.tsx | 22 ++++++----- .../internal/MaskedInput/MaskedInput.tsx | 10 +++-- packages/react-ui/internal/Menu/Menu.tsx | 16 +++++--- packages/react-ui/internal/Popup/Popup.tsx | 22 ++++++----- .../react-ui/internal/PopupMenu/PopupMenu.tsx | 16 +++++--- .../internal/RenderLayer/RenderLayer.tsx | 10 +++-- .../ThemePlayground/VariableValue.tsx | 10 +++-- packages/react-ui/lib/getDefaultProps.ts | 3 ++ 50 files changed, 497 insertions(+), 296 deletions(-) create mode 100644 packages/react-ui/lib/getDefaultProps.ts diff --git a/packages/react-ui/components/Autocomplete/Autocomplete.tsx b/packages/react-ui/components/Autocomplete/Autocomplete.tsx index 0f7d9923970..694d52cc41c 100644 --- a/packages/react-ui/components/Autocomplete/Autocomplete.tsx +++ b/packages/react-ui/components/Autocomplete/Autocomplete.tsx @@ -14,6 +14,7 @@ import { Nullable, Override } from '../../typings/utility-types'; import { fixClickFocusIE } from '../../lib/events/fixClickFocusIE'; import { CommonProps, CommonWrapper, CommonWrapperRestProps } from '../../internal/CommonWrapper'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; function match(pattern: string, items: string[]) { if (!pattern || !items) { @@ -67,6 +68,17 @@ export interface AutocompleteState { focused: boolean; } +const defaultPropsInstance = { + renderItem, + size: 'small', + disablePortal: false, + hasShadow: true, + menuMaxHeight: 300, + menuAlign: 'left', + preventWindowScroll: true, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as AutocompleteProps); + /** * Стандартный инпут с подсказками. * @@ -99,15 +111,7 @@ export class Autocomplete extends React.Component(defaultPropsInstance as ButtonProps); + @rootNode export class Button extends React.Component { public static __KONTUR_REACT_UI__ = 'Button'; @@ -172,11 +180,7 @@ export class Button extends React.Component { 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; public state = { focusedByTab: false, @@ -263,8 +267,8 @@ export class Button extends React.Component { type: this.props.type, className: cx({ [styles.root(this.theme)]: true, - [styles[use](this.theme)]: true, - [activeStyles[use](this.theme)]: active, + [styles[use!](this.theme)]: true, + [activeStyles[use!](this.theme)]: active, [sizeClass]: true, [styles.focus(this.theme)]: isFocused, [styles.checked(this.theme)]: checked, diff --git a/packages/react-ui/components/Center/Center.tsx b/packages/react-ui/components/Center/Center.tsx index 71a1b944106..13428ba8ac6 100644 --- a/packages/react-ui/components/Center/Center.tsx +++ b/packages/react-ui/components/Center/Center.tsx @@ -4,6 +4,7 @@ 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'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Center.styles'; @@ -23,6 +24,11 @@ export interface CenterProps } > {} +const defaultPropsInstance = { + align: 'center', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as CenterProps); + /** * Контейнер, который центрирует элементы внутри себя. */ @@ -30,9 +36,7 @@ export interface CenterProps export class Center extends React.Component { public static __KONTUR_REACT_UI__ = 'Center'; - public static defaultProps = { - align: 'center', - }; + public static defaultProps = defaultProps; private setRootNode!: TSetRootNode; public render() { diff --git a/packages/react-ui/components/ComboBox/ComboBox.tsx b/packages/react-ui/components/ComboBox/ComboBox.tsx index 8ffc1dd8e40..ca662302a31 100644 --- a/packages/react-ui/components/ComboBox/ComboBox.tsx +++ b/packages/react-ui/components/ComboBox/ComboBox.tsx @@ -6,6 +6,7 @@ import { MenuItemState } from '../MenuItem'; import { InputIconType } from '../Input'; import { CommonProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; export interface ComboBoxProps extends CommonProps { align?: 'left' | 'center' | 'right'; @@ -166,19 +167,22 @@ export interface ComboBoxItem { label: string; } +const defaultPropsInstance = { + itemToValue: (item: ComboBoxItem) => item.value, + valueToString: (item: ComboBoxItem) => item.label, + renderValue: (item: ComboBoxItem) => item.label, + renderItem: (item: ComboBoxItem) => item.label, + menuAlign: 'left', + searchOnFocus: true, + drawArrow: true, +}; +const defaultProps = getDefaultProps>(defaultPropsInstance as ComboBoxProps); + @rootNode export class ComboBox extends React.Component> { public static __KONTUR_REACT_UI__ = 'ComboBox'; - public static defaultProps = { - itemToValue: (item: ComboBoxItem) => item.value, - valueToString: (item: ComboBoxItem) => item.label, - renderValue: (item: ComboBoxItem) => item.label, - renderItem: (item: ComboBoxItem) => item.label, - menuAlign: 'left', - searchOnFocus: true, - drawArrow: true, - }; + public static defaultProps = defaultProps; private comboboxElement: Nullable> = null; private setRootNode!: TSetRootNode; diff --git a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx index 99b21056745..c1aa838e705 100644 --- a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx +++ b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx @@ -8,6 +8,7 @@ import { Input, InputProps } from '../Input'; import { Nullable, Override } from '../../typings/utility-types'; import { CommonProps, CommonWrapper, CommonWrapperRestProps } from '../../internal/CommonWrapper'; import { TSetRootNode, rootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { MAX_SAFE_DIGITS } from './constants'; import { Selection, SelectionDirection, SelectionHelper } from './SelectionHelper'; @@ -46,6 +47,15 @@ export interface CurrencyInputState { focused: boolean; } +const defaultPropsInstance = { + align: 'right', + fractionDigits: 2, + hideTrailingZeros: false, + value: null, + inputMode: 'decimal', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as CurrencyInputProps); + /** * Поле для денежных сумм (и других числовых значений). * Принимает любые свойства `Input`. @@ -82,13 +92,7 @@ export class CurrencyInput extends React.PureComponent(defaultPropsInstance as CurrencyLabelProps); export const CurrencyLabel = (props: CurrencyLabelProps): JSX.Element => { const { value, fractionDigits, currencySymbol } = props; diff --git a/packages/react-ui/components/DateInput/DateInput.tsx b/packages/react-ui/components/DateInput/DateInput.tsx index d26d11a5045..680efa3f481 100644 --- a/packages/react-ui/components/DateInput/DateInput.tsx +++ b/packages/react-ui/components/DateInput/DateInput.tsx @@ -12,6 +12,7 @@ import { CalendarIcon } from '../../internal/icons/16px'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { DateFragmentsView } from './DateFragmentsView'; import { styles } from './DateInput.styles'; @@ -71,18 +72,21 @@ export interface DateInputProps extends CommonProps { onKeyDown?: (x0: React.KeyboardEvent) => void; } +const defaultPropsInstance = { + value: '', + minDate: MIN_FULLDATE, + maxDate: MAX_FULLDATE, + size: 'small', + width: 125, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as DateInputProps); + @rootNode @locale('DatePicker', DatePickerLocaleHelper) export class DateInput extends React.Component { public static __KONTUR_REACT_UI__ = 'DateInput'; - public static defaultProps = { - value: '', - minDate: MIN_FULLDATE, - maxDate: MAX_FULLDATE, - size: 'small', - width: 125, - }; + public static defaultProps = defaultProps; private iDateMediator: InternalDateMediator = new InternalDateMediator(); private inputLikeText: InputLikeText | null = null; diff --git a/packages/react-ui/components/DatePicker/DatePicker.tsx b/packages/react-ui/components/DatePicker/DatePicker.tsx index 8bc77bb5a2b..9bab45105c5 100644 --- a/packages/react-ui/components/DatePicker/DatePicker.tsx +++ b/packages/react-ui/components/DatePicker/DatePicker.tsx @@ -15,6 +15,7 @@ import { isMobile } from '../../lib/client'; import { NativeDateInput } from '../../internal/NativeDateInput'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; import { isNonNullable } from '../../lib/utils'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { Picker } from './Picker'; import { styles } from './DatePicker.styles'; @@ -85,6 +86,13 @@ export interface DatePickerState { type DatePickerValue = string; +const defaultPropsInstance = { + minDate: MIN_FULLDATE, + maxDate: MAX_FULLDATE, + isHoliday: (_day: DatePickerValue, isWeekend: boolean) => isWeekend, +}; +const defaultProps = getDefaultProps>(defaultPropsInstance as DatePickerProps); + @rootNode export class DatePicker extends React.PureComponent, DatePickerState> { public static __KONTUR_REACT_UI__ = 'DatePicker'; @@ -139,11 +147,7 @@ export class DatePicker extends React.PureComponent isWeekend, - }; + public static defaultProps = defaultProps; public static validate = (value: Nullable, range: { minDate?: string; maxDate?: string } = {}) => { if (!value) { diff --git a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx index 5396d8f2bc0..39a8edeb9d2 100644 --- a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx +++ b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx @@ -8,6 +8,7 @@ import { isProductionEnv, isTestEnv } from '../../lib/currentEnvironment'; import { PopupPositionsType } from '../../internal/Popup'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; export interface DropdownMenuProps extends CommonProps { /** Максимальная высота меню */ @@ -56,6 +57,12 @@ export interface DropdownMenuProps extends CommonProps { disableAnimations: boolean; } +const defaultPropsInstance = { + disableAnimations: isTestEnv, + positions: ['bottom left', 'bottom right', 'top left', 'top right'], +}; +const defaultProps = getDefaultProps(defaultPropsInstance as DropdownMenuProps); + /** * Меню, раскрывающееся по клику на переданный в `caption` элемент */ @@ -63,10 +70,7 @@ export interface DropdownMenuProps extends CommonProps { export class DropdownMenu extends React.Component { public static __KONTUR_REACT_UI__ = 'DropdownMenu'; - public static defaultProps = { - disableAnimations: isTestEnv, - positions: ['bottom left', 'bottom right', 'top left', 'top right'], - }; + public static defaultProps = defaultProps; private popupMenu: Nullable = null; private setRootNode!: TSetRootNode; diff --git a/packages/react-ui/components/FxInput/FxInput.tsx b/packages/react-ui/components/FxInput/FxInput.tsx index b7fa770025a..96a082f4e65 100644 --- a/packages/react-ui/components/FxInput/FxInput.tsx +++ b/packages/react-ui/components/FxInput/FxInput.tsx @@ -10,6 +10,7 @@ import { Override } from '../../typings/utility-types'; import { FunctionIcon, UndoIcon } from '../../internal/icons/16px'; import { CommonWrapper, CommonProps, CommonWrapperRestProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; export interface FxInputProps extends CommonProps, @@ -33,6 +34,13 @@ export interface FxInputProps } > {} +const defaultPropsInstance = { + width: 250, + type: 'text', + value: '', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as FxInputProps); + /** Принимает все свойства `Input`'a */ @rootNode export class FxInput extends React.Component { @@ -43,11 +51,7 @@ export class FxInput extends React.Component { type: PropTypes.string, }; - public static defaultProps = { - width: 250, - type: 'text', - value: '', - }; + public static defaultProps = defaultProps; private input: Input | CurrencyInput | null = null; diff --git a/packages/react-ui/components/Gapped/Gapped.tsx b/packages/react-ui/components/Gapped/Gapped.tsx index 441252fc900..73cc7fafbfb 100644 --- a/packages/react-ui/components/Gapped/Gapped.tsx +++ b/packages/react-ui/components/Gapped/Gapped.tsx @@ -6,6 +6,7 @@ import { is8pxTheme } from '../../lib/theming/ThemeHelpers'; import { Theme } from '../../lib/theming/Theme'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; export interface GappedProps extends CommonProps { /** @@ -31,6 +32,13 @@ export interface GappedProps extends CommonProps { children: React.ReactNode; } +const defaultPropsInstance = { + wrap: false, + vertical: false, + verticalAlign: 'baseline', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as GappedProps); + /** * Контейнер, расстояние между элементами в котором равно `gap`. */ @@ -58,11 +66,7 @@ export class Gapped extends React.Component { private theme!: Theme; private setRootNode!: TSetRootNode; - public static defaultProps = { - wrap: false, - vertical: false, - verticalAlign: 'baseline', - }; + public static defaultProps = defaultProps; public render() { return ( diff --git a/packages/react-ui/components/Hint/Hint.tsx b/packages/react-ui/components/Hint/Hint.tsx index 868adfdccf6..07e688b5bad 100644 --- a/packages/react-ui/components/Hint/Hint.tsx +++ b/packages/react-ui/components/Hint/Hint.tsx @@ -10,6 +10,7 @@ import { isTestEnv } from '../../lib/currentEnvironment'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Hint.styles'; @@ -81,6 +82,15 @@ const Positions: PopupPositionsType[] = [ 'right top', 'right bottom', ]; +const defaultPropsInstance = { + pos: 'top', + manual: false, + opened: false, + maxWidth: 200, + disableAnimations: isTestEnv, + useWrapper: false, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as HintProps); /** * Всплывающая подсказка, которая по умолчанию отображается при наведении на элемент.
Можно задать другие условия отображения. @@ -89,14 +99,7 @@ const Positions: PopupPositionsType[] = [ export class Hint extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'Hint'; - public static defaultProps = { - pos: 'top', - manual: false, - opened: false, - maxWidth: 200, - disableAnimations: isTestEnv, - useWrapper: false, - }; + public static defaultProps = defaultProps; public state: HintState = { opened: this.props.manual ? !!this.props.opened : false, diff --git a/packages/react-ui/components/Input/Input.tsx b/packages/react-ui/components/Input/Input.tsx index 9a2efea4529..914c9ed67e0 100644 --- a/packages/react-ui/components/Input/Input.tsx +++ b/packages/react-ui/components/Input/Input.tsx @@ -12,6 +12,7 @@ import { Theme } from '../../lib/theming/Theme'; import { CommonWrapper, CommonProps, CommonWrapperRestProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Input.styles'; @@ -107,6 +108,11 @@ export interface InputState { polyfillPlaceholder: boolean; } +const defaultPropsInstance = { + size: 'small', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as InputProps); + /** * Интерфес пропсов наследуется от `React.InputHTMLAttributes`. * Все пропсы кроме перечисленных, `className` и `style` передаются в `` @@ -115,11 +121,7 @@ export interface InputState { export class Input extends React.Component { public static __KONTUR_REACT_UI__ = 'Input'; - public static defaultProps: { - size: InputSize; - } = { - size: 'small', - }; + public static defaultProps = defaultProps; public state: InputState = { polyfillPlaceholder: false, diff --git a/packages/react-ui/components/Kebab/Kebab.tsx b/packages/react-ui/components/Kebab/Kebab.tsx index 5679f3f2938..c0905152a36 100644 --- a/packages/react-ui/components/Kebab/Kebab.tsx +++ b/packages/react-ui/components/Kebab/Kebab.tsx @@ -15,6 +15,7 @@ import { ThemeFactory } from '../../lib/theming/ThemeFactory'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Kebab.styles'; @@ -57,20 +58,23 @@ export interface KebabState { opened: boolean; } +const defaultPropsInstance = { + onOpen: () => undefined, + onClose: () => undefined, + positions: ['bottom left', 'bottom right', 'top left', 'top right'], + size: 'small', + disableAnimations: isTestEnv, + icon: , +}; +const defaultProps = getDefaultProps(defaultPropsInstance as KebabProps); + @rootNode export class Kebab extends React.Component { public static __KONTUR_REACT_UI__ = 'Kebab'; public static propTypes = {}; - public static defaultProps = { - onOpen: () => undefined, - onClose: () => undefined, - positions: ['bottom left', 'bottom right', 'top left', 'top right'], - size: 'small', - disableAnimations: isTestEnv, - icon: , - }; + public static defaultProps = defaultProps; public state = { opened: false, diff --git a/packages/react-ui/components/Link/Link.tsx b/packages/react-ui/components/Link/Link.tsx index b2dc20d5126..2e0bf4c3204 100644 --- a/packages/react-ui/components/Link/Link.tsx +++ b/packages/react-ui/components/Link/Link.tsx @@ -10,6 +10,7 @@ import { Spinner } from '../Spinner'; import { CommonWrapper, CommonProps, CommonWrapperRestProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode/rootNodeDecorator'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Link.styles'; @@ -61,6 +62,12 @@ export interface LinkState { focusedByTab: boolean; } +const defaultPropsInstance = { + href: '', + use: 'default', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as LinkProps); + /** * Элемент ссылки из HTML. */ @@ -78,10 +85,7 @@ export class Link extends React.Component { use: PropTypes.oneOf(['default', 'success', 'danger', 'grayed']), }; - public static defaultProps = { - href: '', - use: 'default', - }; + public static defaultProps = defaultProps; public state = { focusedByTab: false, diff --git a/packages/react-ui/components/Loader/Loader.tsx b/packages/react-ui/components/Loader/Loader.tsx index 3508eaa51cf..cc51b991eac 100644 --- a/packages/react-ui/components/Loader/Loader.tsx +++ b/packages/react-ui/components/Loader/Loader.tsx @@ -14,6 +14,7 @@ import { isTestEnv } from '../../lib/currentEnvironment'; import { TaskWithDelayAndMinimalDuration } from '../../lib/taskWithDelayAndMinimalDuration'; import { getTabbableElements } from '../../lib/dom/tabbableHelpers'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Loader.styles'; @@ -50,6 +51,14 @@ export interface LoaderState { spinnerStyle?: object; } +const defaultPropsInstance = { + type: Spinner.Types.normal, + active: false, + delayBeforeSpinnerShow: isTestEnv ? 0 : 300, + minimalDelayBeforeSpinnerHide: isTestEnv ? 0 : 1000, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as LoaderProps); + /** * DRAFT - лоадер-контейнер */ @@ -57,12 +66,7 @@ export interface LoaderState { export class Loader extends React.Component { public static __KONTUR_REACT_UI__ = 'Loader'; - public static defaultProps: Partial = { - type: Spinner.Types.normal, - active: false, - delayBeforeSpinnerShow: isTestEnv ? 0 : 300, - minimalDelayBeforeSpinnerHide: isTestEnv ? 0 : 1000, - }; + public static defaultProps = defaultProps; public static propTypes = { /** diff --git a/packages/react-ui/components/Modal/Modal.tsx b/packages/react-ui/components/Modal/Modal.tsx index 6f4d75094e9..fc1ebe57912 100644 --- a/packages/react-ui/components/Modal/Modal.tsx +++ b/packages/react-ui/components/Modal/Modal.tsx @@ -14,6 +14,7 @@ import { Theme } from '../../lib/theming/Theme'; import { isIE11 } from '../../lib/client'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { ModalContext, ModalContextProps } from './ModalContext'; import { ModalFooter } from './ModalFooter'; @@ -68,6 +69,12 @@ export interface ModalState { hasPanel: boolean; } +const defaultPropsInstance = { + // NOTE: в ie нормально не работает + disableFocusLock: isIE11, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as ModalProps); + /** * Модальное окно * @@ -89,10 +96,7 @@ export class Modal extends React.Component { public static Body = ModalBody; public static Footer = ModalFooter; - public static defaultProps = { - // NOTE: в ie нормально не работает - disableFocusLock: isIE11, - }; + public static defaultProps = defaultProps; public state: ModalState = { stackPosition: 0, diff --git a/packages/react-ui/components/Paging/Paging.tsx b/packages/react-ui/components/Paging/Paging.tsx index bc590321b18..82b3f1e3399 100644 --- a/packages/react-ui/components/Paging/Paging.tsx +++ b/packages/react-ui/components/Paging/Paging.tsx @@ -13,6 +13,7 @@ import { ArrowChevronRightIcon } from '../../internal/icons/16px'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Paging.styles'; import * as NavigationHelper from './NavigationHelper'; @@ -54,6 +55,7 @@ export interface PagingProps extends CommonProps { * на каждом из них. Такие случаи лучше обрабатывать отдельно. */ useGlobalListener: boolean; + 'data-tid': string; } export interface PagingState { @@ -64,20 +66,23 @@ export interface PagingState { export type ItemType = number | '.' | 'forward'; +const defaultPropsInstance = { + component: ({ className, onClick, children }: any) => ( + + {children} + + ), + useGlobalListener: false, + ['data-tid']: 'Paging__root', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as PagingProps); + @rootNode @locale('Paging', PagingLocaleHelper) export class Paging extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'Paging'; - public static defaultProps = { - component: ({ className, onClick, children }: any) => ( - - {children} - - ), - useGlobalListener: false, - ['data-tid']: 'Paging__root', - }; + public static defaultProps = defaultProps; public static propTypes = {}; private setRootNode!: TSetRootNode; diff --git a/packages/react-ui/components/PasswordInput/PasswordInput.tsx b/packages/react-ui/components/PasswordInput/PasswordInput.tsx index 2d8e9b946f8..1e5e0be6c73 100644 --- a/packages/react-ui/components/PasswordInput/PasswordInput.tsx +++ b/packages/react-ui/components/PasswordInput/PasswordInput.tsx @@ -12,6 +12,7 @@ import { Theme } from '../../lib/theming/Theme'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './PasswordInput.styles'; @@ -24,6 +25,11 @@ export interface PasswordInputState { capsLockEnabled?: boolean | null; } +const defaultPropsInstance = { + size: 'small', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as PasswordInputProps); + /** * Компонент для ввода пароля */ @@ -38,9 +44,7 @@ export class PasswordInput extends React.PureComponent>(defaultPropsInstance as RadioProps); + /** * Радио-кнопки используются, когда может быть выбран только один вариант из нескольких. */ @@ -67,9 +73,7 @@ export class Radio extends React.Component, RadioState> { focusedByKeyboard: false, }; - public static defaultProps = { - focused: false, - }; + public static defaultProps = defaultProps; public static contextType = RadioGroupContext; public context: RadioGroupContextType = this.context; diff --git a/packages/react-ui/components/RadioGroup/RadioGroup.tsx b/packages/react-ui/components/RadioGroup/RadioGroup.tsx index c9241dc3f26..a35e11cc9e3 100644 --- a/packages/react-ui/components/RadioGroup/RadioGroup.tsx +++ b/packages/react-ui/components/RadioGroup/RadioGroup.tsx @@ -12,6 +12,7 @@ import { Theme } from '../../lib/theming/Theme'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './RadioGroup.styles'; import { Prevent } from './Prevent'; @@ -81,6 +82,11 @@ export interface RadioGroupState { activeItem?: T; } +const defaultPropsInstance = { + renderItem, +}; +const defaultProps = getDefaultProps>(defaultPropsInstance as RadioGroupProps); + /** * * `children` может содержать любую разметку с компонентами Radio, @@ -108,9 +114,7 @@ export class RadioGroup extends React.Component, RadioGrou onMouseOver: PropTypes.func, }; - public static defaultProps = { - renderItem, - }; + public static defaultProps = defaultProps; public static Prevent = Prevent; @@ -229,7 +233,7 @@ export class RadioGroup extends React.Component, RadioGrou return ( - {this.getProps().renderItem(itemValue, data)} + {this.getProps().renderItem!(itemValue, data)} ); }; diff --git a/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx b/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx index fd124d7843b..92475bd3ae1 100644 --- a/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx +++ b/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx @@ -6,6 +6,7 @@ import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { Nullable } from '../../typings/utility-types'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles, globalClasses } from './ScrollContainer.styles'; import { scrollSizeParametersNames } from './ScrollContainer.constants'; @@ -44,6 +45,13 @@ export interface ScrollContainerProps extends CommonProps { onScroll?: (e: React.UIEvent) => void; } +const defaultPropsInstance = { + invert: false, + scrollBehaviour: 'auto', + preventWindowScroll: false, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as ScrollContainerProps); + @rootNode export class ScrollContainer extends React.Component { public static __KONTUR_REACT_UI__ = 'ScrollContainer'; @@ -57,11 +65,7 @@ export class ScrollContainer extends React.Component { onScrollStateChange: PropTypes.func, }; - public static defaultProps = { - invert: false, - scrollBehaviour: 'auto', - preventWindowScroll: false, - }; + public static defaultProps = defaultProps; private scrollX: Nullable; private scrollY: Nullable; diff --git a/packages/react-ui/components/Select/Select.tsx b/packages/react-ui/components/Select/Select.tsx index 964466f4948..453b3a4a6d9 100644 --- a/packages/react-ui/components/Select/Select.tsx +++ b/packages/react-ui/components/Select/Select.tsx @@ -29,6 +29,7 @@ import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { ArrowChevronDownIcon } from '../../internal/icons/16px'; import { cx } from '../../lib/theming/Emotion'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { Item } from './Item'; import { SelectLocale, SelectLocaleHelper } from './locale'; @@ -148,6 +149,15 @@ interface FocusableReactElement extends React.ReactElement { focus: (event?: any) => void; } +const defaultPropsInstance = { + renderValue, + renderItem, + areValuesEqual, + filterItem, + use: 'default', +}; +const defaultProps = getDefaultProps>(defaultPropsInstance as SelectProps); + @rootNode @locale('Select', SelectLocaleHelper) export class Select extends React.Component, SelectState> { @@ -176,13 +186,7 @@ export class Select extends React.Component ; @@ -301,7 +305,7 @@ export class Select extends React.Component extends React.Component - {this.getProps().renderItem(iValue, item)} + {this.getProps().renderItem!(iValue, item)} ); }, @@ -512,7 +516,7 @@ export class Select extends React.Component extends React.Component extends React.Component(defaultPropsInstance as SidePageProps); + const TRANSITION_TIMEOUT = 200; /** @@ -135,11 +143,7 @@ export class SidePage extends React.Component { } }; - public static defaultProps = { - disableAnimations: isTestEnv, - disableFocusLock: true, - offset: 0, - }; + public static defaultProps = defaultProps; public render(): JSX.Element { return ( diff --git a/packages/react-ui/components/Spinner/Spinner.tsx b/packages/react-ui/components/Spinner/Spinner.tsx index 0dba42c47ff..52b6934ab5d 100644 --- a/packages/react-ui/components/Spinner/Spinner.tsx +++ b/packages/react-ui/components/Spinner/Spinner.tsx @@ -8,6 +8,7 @@ import { SpinnerIcon } from '../../internal/icons/SpinnerIcon'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Spinner.styles'; import { SpinnerLocale, SpinnerLocaleHelper } from './locale'; @@ -38,6 +39,11 @@ export interface SpinnerProps extends CommonProps { color?: React.CSSProperties['color']; } +const defaultPropsInstance = { + type: 'normal', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as SpinnerProps); + /** * DRAFT - инлайн-лоадер */ @@ -67,9 +73,7 @@ export class Spinner extends React.Component { type: PropTypes.oneOf(Object.keys(types)), }; - public static defaultProps: SpinnerProps = { - type: 'normal', - }; + public static defaultProps = defaultProps; public static Types: typeof types = types; private theme!: Theme; diff --git a/packages/react-ui/components/Sticky/Sticky.tsx b/packages/react-ui/components/Sticky/Sticky.tsx index a7068f091ec..2a68939c4cb 100644 --- a/packages/react-ui/components/Sticky/Sticky.tsx +++ b/packages/react-ui/components/Sticky/Sticky.tsx @@ -9,6 +9,7 @@ import { ZIndex } from '../../internal/ZIndex'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Sticky.styles'; @@ -35,6 +36,11 @@ export interface StickyState { relativeTop: number; } +const defaultPropsInstance = { + offset: 0, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as StickyProps); + @rootNode export class Sticky extends React.Component { public static __KONTUR_REACT_UI__ = 'Sticky'; @@ -55,7 +61,7 @@ export class Sticky extends React.Component { side: PropTypes.oneOf(['top', 'bottom']).isRequired, }; - public static defaultProps = { offset: 0 }; + public static defaultProps = defaultProps; public state: StickyState = { fixed: false, diff --git a/packages/react-ui/components/Tabs/Tabs.tsx b/packages/react-ui/components/Tabs/Tabs.tsx index 991fe4bd014..89718f0b353 100644 --- a/packages/react-ui/components/Tabs/Tabs.tsx +++ b/packages/react-ui/components/Tabs/Tabs.tsx @@ -7,6 +7,7 @@ import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { getRootNode } from '../../lib/rootNode/getRootNode'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { Indicator } from './Indicator'; import { styles } from './Tabs.styles'; @@ -46,6 +47,11 @@ export interface TabsProps extends CommonProps { width?: number | string; } +const defaultPropsInstance = { + vertical: false, +}; +const defaultProps = getDefaultProps>(defaultPropsInstance as TabsProps); + /** * Tabs wrapper * @@ -62,9 +68,7 @@ export class Tabs extends React.Component(defaultPropsInstance as TextareaProps); + /** * Компонент для ввода многострочного текста. * @@ -176,12 +185,7 @@ export class Textarea extends React.Component { onCopy: PropTypes.func, }; - public static defaultProps = { - rows: 3, - maxRows: 15, - extraRow: true, - disableAnimations: isTestEnv, - }; + public static defaultProps = defaultProps; public state = { polyfillPlaceholder, diff --git a/packages/react-ui/components/Toggle/Toggle.tsx b/packages/react-ui/components/Toggle/Toggle.tsx index 4ae46a0edb1..c71604b7741 100644 --- a/packages/react-ui/components/Toggle/Toggle.tsx +++ b/packages/react-ui/components/Toggle/Toggle.tsx @@ -8,6 +8,7 @@ import { Theme } from '../../lib/theming/Theme'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles, globalClasses } from './Toggle.styles'; @@ -82,6 +83,13 @@ export interface ToggleState { focusByTab?: boolean; } +const defaultPropsInstance = { + disabled: false, + loading: false, + captionPosition: 'right', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as ToggleProps); + /** * _Примечание:_ под тоглом понимается полный компонент т.е. надпись + переключатель, а не просто переключатель. */ @@ -105,11 +113,7 @@ export class Toggle extends React.Component { }, }; - public static defaultProps = { - disabled: false, - loading: false, - captionPosition: 'right', - }; + public static defaultProps = defaultProps; private theme!: Theme; private input: HTMLInputElement | null = null; diff --git a/packages/react-ui/components/TokenInput/TokenInput.tsx b/packages/react-ui/components/TokenInput/TokenInput.tsx index b54b8ee2eb8..1b05c14ab78 100644 --- a/packages/react-ui/components/TokenInput/TokenInput.tsx +++ b/packages/react-ui/components/TokenInput/TokenInput.tsx @@ -26,6 +26,7 @@ import { MenuItem } from '../MenuItem/MenuItem'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { TokenInputLocale, TokenInputLocaleHelper } from './locale'; import { styles } from './TokenInput.styles'; @@ -169,28 +170,31 @@ const defaultRenderToken = ( ); +const defaultPropsInstance = { + selectedItems: [], + delimiters: [',', ' '], + renderItem: identity, + renderValue: identity, + valueToString: identity, + valueToItem: (item: string) => item, + toKey: defaultToKey, + onValueChange: () => void 0, + width: 250 as string | number, + onBlur: emptyHandler, + onFocus: emptyHandler, + onMouseEnter: emptyHandler, + onMouseLeave: emptyHandler, + menuWidth: 'auto', + menuAlign: 'cursor', +}; +const defaultProps = getDefaultProps>(defaultPropsInstance as TokenInputProps); + @rootNode @locale('TokenInput', TokenInputLocaleHelper) export class TokenInput extends React.PureComponent, TokenInputState> { public static __KONTUR_REACT_UI__ = 'TokenInput'; - public static defaultProps: Partial> = { - selectedItems: [], - delimiters: [',', ' '], - renderItem: identity, - renderValue: identity, - valueToString: identity, - valueToItem: (item: string) => item, - toKey: defaultToKey, - onValueChange: () => void 0, - width: 250 as string | number, - onBlur: emptyHandler, - onFocus: emptyHandler, - onMouseEnter: emptyHandler, - onMouseLeave: emptyHandler, - menuWidth: 'auto', - menuAlign: 'cursor', - }; + public static defaultProps = defaultProps; public state: TokenInputState = DefaultState; diff --git a/packages/react-ui/components/Tooltip/Tooltip.tsx b/packages/react-ui/components/Tooltip/Tooltip.tsx index f76feceda1e..32a7f1ab45c 100644 --- a/packages/react-ui/components/Tooltip/Tooltip.tsx +++ b/packages/react-ui/components/Tooltip/Tooltip.tsx @@ -14,6 +14,7 @@ import { Theme } from '../../lib/theming/Theme'; import { isTestEnv } from '../../lib/currentEnvironment'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Tooltip.styles'; @@ -147,6 +148,16 @@ const Positions: PopupPositionsType[] = [ 'bottom right', ]; +const defaultPropsInstance = { + pos: DefaultPosition, + trigger: 'hover', + allowedPositions: Positions, + disableAnimations: isTestEnv, + useWrapper: false, + closeOnChildrenMouseLeave: false, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as TooltipProps); + @rootNode export class Tooltip extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'Tooltip'; @@ -165,14 +176,7 @@ export class Tooltip extends React.PureComponent { }, }; - public static defaultProps = { - pos: DefaultPosition, - trigger: 'hover', - allowedPositions: Positions, - disableAnimations: isTestEnv, - useWrapper: false, - closeOnChildrenMouseLeave: false, - }; + public static defaultProps = defaultProps; public static delay = 100; private static triggersWithoutCloseButton: TooltipTrigger[] = ['hover', 'hoverAnchor', 'focus', 'hover&focus']; diff --git a/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx b/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx index ca486ce18ca..71f4232a1c0 100644 --- a/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx +++ b/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx @@ -9,6 +9,7 @@ import { MenuHeaderProps } from '../MenuHeader'; import { PopupPositionsType } from '../../internal/Popup'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; export type TooltipMenuChildType = React.ReactElement; @@ -50,6 +51,11 @@ export interface TooltipMenuProps extends CommonProps { disableAnimations: boolean; } +const defaultPropsInstance = { + disableAnimations: isTestEnv, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as TooltipMenuProps); + /** * Меню, раскрывающееся по клику на переданный в `caption` элемент. * @@ -66,9 +72,7 @@ export class TooltipMenu extends React.Component { public static __KONTUR_REACT_UI__ = 'TooltipMenu'; private setRootNode!: TSetRootNode; - public static defaultProps = { - disableAnimations: isTestEnv, - }; + public static defaultProps = defaultProps; constructor(props: TooltipMenuProps) { super(props); diff --git a/packages/react-ui/internal/BGRuler.tsx b/packages/react-ui/internal/BGRuler.tsx index f4f1260f1c8..30eb675aac4 100644 --- a/packages/react-ui/internal/BGRuler.tsx +++ b/packages/react-ui/internal/BGRuler.tsx @@ -1,12 +1,8 @@ import React from 'react'; -/** - * Компонент рисует пиксельную линейку на заднем фоне. - * Помогает контролировать размеры элементов при скриншотном тестировании. - * - * @see FxInput/__stories__/FxInput.stories.tsx - */ -export class BGRuler extends React.Component<{ +import { getDefaultProps } from '../lib/getDefaultProps'; + +interface BGRulerProps { width?: string | number; height?: string | number; top?: string | number; @@ -14,14 +10,24 @@ export class BGRuler extends React.Component<{ right?: string | number; left?: string | number; color?: string; -}> { - public static defaultProps = { - height: 20, - top: 0, - left: 0, - right: 0, - color: '#333', - }; +} +const defaultPropsInstance = { + height: 20, + top: 0, + left: 0, + right: 0, + color: '#333', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as BGRulerProps); + +/** + * Компонент рисует пиксельную линейку на заднем фоне. + * Помогает контролировать размеры элементов при скриншотном тестировании. + * + * @see FxInput/__stories__/FxInput.stories.tsx + */ +export class BGRuler extends React.Component { + public static defaultProps = defaultProps; private iframe: HTMLIFrameElement | null = null; diff --git a/packages/react-ui/internal/Calendar/Calendar.tsx b/packages/react-ui/internal/Calendar/Calendar.tsx index 836cc7116d6..cd1ae8f5d9e 100644 --- a/packages/react-ui/internal/Calendar/Calendar.tsx +++ b/packages/react-ui/internal/Calendar/Calendar.tsx @@ -8,6 +8,7 @@ import { Theme } from '../../lib/theming/Theme'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Animation } from '../../lib/animation'; import { isMobile } from '../../lib/client'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { themeConfig } from './config'; import * as CalendarUtils from './CalendarUtils'; @@ -45,22 +46,24 @@ const getTodayDate = () => { }; }; +const defaultPropsInstance = { + minDate: { + year: MIN_YEAR, + month: MIN_MONTH, + date: MIN_DATE, + }, + maxDate: { + year: MAX_YEAR, + month: MAX_MONTH, + date: MAX_DATE, + }, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as CalendarProps); + export class Calendar extends React.Component { public static __KONTUR_REACT_UI__ = 'Calendar'; - public static defaultProps = { - holidays: [], - minDate: { - year: MIN_YEAR, - month: MIN_MONTH, - date: MIN_DATE, - }, - maxDate: { - year: MAX_YEAR, - month: MAX_MONTH, - date: MAX_DATE, - }, - }; + public static defaultProps = defaultProps; private theme!: Theme; private wheelEndTimeout: Nullable; diff --git a/packages/react-ui/internal/Calendar/Month.tsx b/packages/react-ui/internal/Calendar/Month.tsx index c8474a19fa4..c8c3402ef2f 100644 --- a/packages/react-ui/internal/Calendar/Month.tsx +++ b/packages/react-ui/internal/Calendar/Month.tsx @@ -4,6 +4,7 @@ import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; import { DateSelect } from '../DateSelect'; import { Nullable } from '../../typings/utility-types'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { themeConfig } from './config'; import * as CDS from './CalendarDateShape'; @@ -140,12 +141,15 @@ interface MonthDayGridProps { isHoliday: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => boolean; } +const defaultPropsInstance = { + isHoliday: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => day.isWeekend, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as MonthDayGridProps); + class MonthDayGrid extends React.Component { private theme!: Theme; - public static defaultProps = { - isHoliday: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => day.isWeekend, - }; + public static defaultProps = defaultProps; public shouldComponentUpdate(nextProps: MonthDayGridProps) { if (!CDS.isEqual(nextProps.value, this.props.value)) { diff --git a/packages/react-ui/internal/ComponentCombinator.tsx b/packages/react-ui/internal/ComponentCombinator.tsx index 8b3632f0127..462e930f2e6 100644 --- a/packages/react-ui/internal/ComponentCombinator.tsx +++ b/packages/react-ui/internal/ComponentCombinator.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { DefaultizeProps } from '../lib/utils'; +import { getDefaultProps } from '../lib/getDefaultProps'; import { ComponentTable, StatePropsCombinations, StateType } from './ComponentTable'; @@ -11,6 +12,14 @@ export interface ComponentCombinatorProps { presetState: Partial; } +const defaultPropsInstance = { + presetProps: {}, + presetState: {}, +}; +const defaultProps = getDefaultProps>( + defaultPropsInstance as ComponentCombinatorProps, +); + export class ComponentCombinator< T extends React.Component, C extends React.ComponentType, @@ -19,12 +28,7 @@ export class ComponentCombinator< ComponentCombinatorProps ? React.ClassType : C, P, StateType>, { page: number } > { - public static defaultProps = { - props: [], - states: [], - presetProps: {}, - presetState: {}, - }; + public static defaultProps = defaultProps; public state = { page: 0, diff --git a/packages/react-ui/internal/ComponentTable.tsx b/packages/react-ui/internal/ComponentTable.tsx index a56927a9bf2..5fa48edae75 100644 --- a/packages/react-ui/internal/ComponentTable.tsx +++ b/packages/react-ui/internal/ComponentTable.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { isFunctionalComponent, DefaultizeProps } from '../lib/utils'; +import { getDefaultProps } from '../lib/getDefaultProps'; // TODO We should output state too const renderPropsDesc =

>(props: P): React.ReactNode => { @@ -40,6 +41,14 @@ export interface ComponentTableProps { Component: C; } +const defaultPropsInstance = { + presetProps: {}, + presetState: {}, +}; +const defaultProps = getDefaultProps>( + defaultPropsInstance as ComponentTableProps, +); + // Known limitation: Don't work when component have `propTypes` static field export class ComponentTable< T extends React.Component, @@ -48,7 +57,7 @@ export class ComponentTable< > extends React.Component< ComponentTableProps ? React.ClassType : C, P, StateType> > { - public static defaultProps = { presetProps: {}, presetState: {} }; + public static defaultProps = defaultProps; public render() { const { rows = [], cols = [], presetProps, presetState, Component } = this.props; diff --git a/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx b/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx index 9e446d3bb5d..a7ae82638ac 100644 --- a/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx +++ b/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx @@ -6,6 +6,7 @@ import { MenuItem, MenuItemState } from '../../components/MenuItem'; import { Spinner } from '../../components/Spinner'; import { Nullable } from '../../typings/utility-types'; import { MenuSeparator } from '../../components/MenuSeparator'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { ComboBoxRequestStatus } from './CustomComboBoxTypes'; import { ComboBoxLocale, CustomComboBoxLocaleHelper } from './locale'; @@ -27,14 +28,17 @@ export interface ComboBoxMenuProps { requestStatus?: ComboBoxRequestStatus; } +const defaultPropsInstance = { + repeatRequest: () => undefined, + requestStatus: ComboBoxRequestStatus.Unknown, +}; +const defaultProps = getDefaultProps>(defaultPropsInstance as ComboBoxMenuProps); + @locale('ComboBox', CustomComboBoxLocaleHelper) export class ComboBoxMenu extends Component> { public static __KONTUR_REACT_UI__ = 'ComboBoxMenu'; - public static defaultProps = { - repeatRequest: () => undefined, - requestStatus: ComboBoxRequestStatus.Unknown, - }; + public static defaultProps = defaultProps; private readonly locale!: ComboBoxLocale; diff --git a/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx b/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx index d85d7932fff..450cc76878b 100644 --- a/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx +++ b/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx @@ -12,6 +12,7 @@ import { Nullable } from '../../typings/utility-types'; import { ArrowChevronDownIcon } from '../icons/16px'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { rootNode, getRootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { ComboBoxMenu } from './ComboBoxMenu'; import { ComboBoxRequestStatus } from './CustomComboBoxTypes'; @@ -73,25 +74,28 @@ interface ComboBoxViewProps extends CommonProps { refInputLikeText?: (inputLikeText: Nullable) => void; } +const defaultPropsInstance = { + renderItem: (item: any) => item, + renderValue: (item: any) => item, + renderAddButton: () => null, + repeatRequest: () => undefined, + requestStatus: ComboBoxRequestStatus.Unknown, + onClickOutside: () => { + /**/ + }, + onFocusOutside: () => { + /**/ + }, + size: 'small', + width: 250, +}; +const defaultProps = getDefaultProps>(defaultPropsInstance as ComboBoxViewProps); + @rootNode export class ComboBoxView extends React.Component, {}> { public static __KONTUR_REACT_UI__ = 'ComboBoxView'; - public static defaultProps = { - renderItem: (item: any) => item, - renderValue: (item: any) => item, - renderAddButton: () => null, - repeatRequest: () => undefined, - requestStatus: ComboBoxRequestStatus.Unknown, - onClickOutside: () => { - /**/ - }, - onFocusOutside: () => { - /**/ - }, - size: 'small', - width: 250, - }; + public static defaultProps = defaultProps; private input: Nullable; private setRootNode!: TSetRootNode; diff --git a/packages/react-ui/internal/DateSelect/DateSelect.tsx b/packages/react-ui/internal/DateSelect/DateSelect.tsx index de310c3248d..07c18b4fcb9 100644 --- a/packages/react-ui/internal/DateSelect/DateSelect.tsx +++ b/packages/react-ui/internal/DateSelect/DateSelect.tsx @@ -13,6 +13,7 @@ import { ThemeContext } from '../../lib/theming/ThemeContext'; import { ArrowTriangleUpDownIcon, ArrowChevronDownIcon, ArrowChevronUpIcon } from '../icons/16px'; import { isMobile } from '../../lib/client'; import { cx } from '../../lib/theming/Emotion'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './DateSelect.styles'; @@ -43,6 +44,11 @@ export interface DateSelectState { topCapped: boolean; nodeTop: number; } +const defaultPropsInstance = { + type: 'year', + width: 'auto', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as DateSelectProps); @locale('DatePicker', DatePickerLocaleHelper) export class DateSelect extends React.PureComponent { @@ -64,12 +70,7 @@ export class DateSelect extends React.PureComponent; @@ -27,16 +28,18 @@ export interface DropdownContainerState { minWidth: number; isDocumentElementRoot?: boolean; } +const defaultPropsInstance = { + align: 'left', + disablePortal: false, + offsetX: 0, + offsetY: -1, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as DropdownContainerProps); export class DropdownContainer extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'DropdownContainer'; - public static defaultProps = { - align: 'left', - disablePortal: false, - offsetX: 0, - offsetY: -1, - }; + public static defaultProps = defaultProps; public state: DropdownContainerState = { position: null, @@ -123,9 +126,9 @@ export class DropdownContainer extends React.PureComponent; +const defaultPropsInstance = { + size: 'small', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as InputLikeTextProps); + @rootNode export class InputLikeText extends React.Component { public static __KONTUR_REACT_UI__ = 'InputLikeText'; - public static defaultProps = { size: 'small' }; + public static defaultProps = defaultProps; public state = { blinking: false, focused: false }; diff --git a/packages/react-ui/internal/InternalMenu/InternalMenu.tsx b/packages/react-ui/internal/InternalMenu/InternalMenu.tsx index 23a5a3846fd..9d734877416 100644 --- a/packages/react-ui/internal/InternalMenu/InternalMenu.tsx +++ b/packages/react-ui/internal/InternalMenu/InternalMenu.tsx @@ -10,6 +10,7 @@ import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; import { cx } from '../../lib/theming/Emotion'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './InternalMenu.styles'; import { isActiveElement } from './isActiveElement'; @@ -37,18 +38,21 @@ interface MenuState { scrollState: ScrollContainerScrollState; } +const defaultPropsInstance = { + width: 'auto', + maxHeight: 300, + hasShadow: true, + preventWindowScroll: true, + cyclicSelection: true, + initialSelectedItemIndex: -1, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as MenuProps); + @rootNode export class InternalMenu extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'InternalMenu'; - public static defaultProps = { - width: 'auto', - maxHeight: 300, - hasShadow: true, - preventWindowScroll: true, - cyclicSelection: true, - initialSelectedItemIndex: -1, - }; + public static defaultProps = defaultProps; public state: MenuState = { highlightedIndex: -1, @@ -249,7 +253,7 @@ export class InternalMenu extends React.PureComponent { }; private setInitialSelection = () => { - for (let i = this.getProps().initialSelectedItemIndex; i > -1; i--) { + for (let i = this.getProps().initialSelectedItemIndex!; i > -1; i--) { this.moveDown(); } }; diff --git a/packages/react-ui/internal/MaskedInput/MaskedInput.tsx b/packages/react-ui/internal/MaskedInput/MaskedInput.tsx index 870fda8be1b..d3de5ece683 100644 --- a/packages/react-ui/internal/MaskedInput/MaskedInput.tsx +++ b/packages/react-ui/internal/MaskedInput/MaskedInput.tsx @@ -5,6 +5,7 @@ import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; import { MaskCharLowLine } from '../MaskCharLowLine'; import { cx } from '../../lib/theming/Emotion'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './MaskedInput.styles'; @@ -25,12 +26,15 @@ interface MaskedInputState { focused: boolean; } +const defaultPropsInstance = { + maskChar: '_', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as MaskedInputProps); + export class MaskedInput extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'MaskedInput'; - public static defaultProps: Partial = { - maskChar: '_', - }; + public static defaultProps = defaultProps; public input: HTMLInputElement | null = null; private theme!: Theme; diff --git a/packages/react-ui/internal/Menu/Menu.tsx b/packages/react-ui/internal/Menu/Menu.tsx index 4bae82bb952..aa8a59e83d4 100644 --- a/packages/react-ui/internal/Menu/Menu.tsx +++ b/packages/react-ui/internal/Menu/Menu.tsx @@ -8,6 +8,7 @@ import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; import { cx } from '../../lib/theming/Emotion'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Menu.styles'; import { isActiveElement } from './isActiveElement'; @@ -25,16 +26,19 @@ export interface MenuState { highlightedIndex: number; } +const defaultPropsInstance = { + width: 'auto', + maxHeight: 300, + hasShadow: true, + preventWindowScroll: true, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as MenuProps); + @rootNode export class Menu extends React.Component { public static __KONTUR_REACT_UI__ = 'Menu'; - public static defaultProps = { - width: 'auto', - maxHeight: 300, - hasShadow: true, - preventWindowScroll: true, - }; + public static defaultProps = defaultProps; public state = { highlightedIndex: -1, diff --git a/packages/react-ui/internal/Popup/Popup.tsx b/packages/react-ui/internal/Popup/Popup.tsx index 88504a7535f..9a3cc56a8d8 100644 --- a/packages/react-ui/internal/Popup/Popup.tsx +++ b/packages/react-ui/internal/Popup/Popup.tsx @@ -19,6 +19,7 @@ import { CommonProps, CommonWrapper } from '../CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; import { callChildRef } from '../../lib/callChildRef/callChildRef'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { PopupPin } from './PopupPin'; import { Offset, PopupHelper, PositionObject, Rect } from './PopupHelper'; @@ -108,6 +109,17 @@ export interface PopupState { location: Nullable; } +const defaultPropsInstance = { + popupOffset: 0, + hasPin: false, + hasShadow: false, + disableAnimations: isTestEnv, + useWrapper: false, + ignoreHover: false, + width: 'auto', +}; +const defaultProps = getDefaultProps(defaultPropsInstance as PopupProps); + @rootNode export class Popup extends React.Component { public static __KONTUR_REACT_UI__ = 'Popup'; @@ -174,15 +186,7 @@ export class Popup extends React.Component { ignoreHover: PropTypes.bool, }; - public static defaultProps = { - popupOffset: 0, - hasPin: false, - hasShadow: false, - disableAnimations: isTestEnv, - useWrapper: false, - ignoreHover: false, - width: 'auto', - }; + public static defaultProps = defaultProps; public state: PopupState = { location: this.props.opened ? DUMMY_LOCATION : null }; private theme!: Theme; diff --git a/packages/react-ui/internal/PopupMenu/PopupMenu.tsx b/packages/react-ui/internal/PopupMenu/PopupMenu.tsx index 1479ec654ec..40566087b5a 100644 --- a/packages/react-ui/internal/PopupMenu/PopupMenu.tsx +++ b/packages/react-ui/internal/PopupMenu/PopupMenu.tsx @@ -13,6 +13,7 @@ import { RenderLayer } from '../RenderLayer'; import { Nullable } from '../../typings/utility-types'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { isValidPositions } from './validatePositions'; import { styles } from './PopupMenu.styles'; @@ -81,16 +82,19 @@ const Positions: PopupPositionsType[] = [ 'left bottom', ]; +const defaultPropsInstance = { + positions: Positions, + type: PopupMenuType.Tooltip, + popupHasPin: true, + disableAnimations: false, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as PopupMenuProps); + @rootNode export class PopupMenu extends React.Component { public static __KONTUR_REACT_UI__ = 'PopupMenu'; - public static defaultProps = { - positions: Positions, - type: PopupMenuType.Tooltip, - popupHasPin: true, - disableAnimations: false, - }; + public static defaultProps = defaultProps; public static Type = PopupMenuType; diff --git a/packages/react-ui/internal/RenderLayer/RenderLayer.tsx b/packages/react-ui/internal/RenderLayer/RenderLayer.tsx index ba2ef7c0ad2..ec5df3a724d 100644 --- a/packages/react-ui/internal/RenderLayer/RenderLayer.tsx +++ b/packages/react-ui/internal/RenderLayer/RenderLayer.tsx @@ -4,6 +4,7 @@ import { listen as listenFocusOutside, containsTargetOrRenderContainer } from '. import { CommonProps, CommonWrapper } from '../CommonWrapper'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; import { Nullable } from '../../typings/utility-types'; +import { getDefaultProps } from '../../lib/getDefaultProps'; export interface RenderLayerProps extends CommonProps { children: JSX.Element; @@ -13,6 +14,11 @@ export interface RenderLayerProps extends CommonProps { getAnchorElement?: () => Nullable; } +const defaultPropsInstance = { + active: true, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as RenderLayerProps); + @rootNode export class RenderLayer extends React.Component { public static __KONTUR_REACT_UI__ = 'RenderLayer'; @@ -28,9 +34,7 @@ export class RenderLayer extends React.Component { }, }; - public static defaultProps = { - active: true, - }; + public static defaultProps = defaultProps; private focusOutsideListenerToken: { remove: () => void; diff --git a/packages/react-ui/internal/ThemePlayground/VariableValue.tsx b/packages/react-ui/internal/ThemePlayground/VariableValue.tsx index 400d6ad700f..dc8cf1a7238 100644 --- a/packages/react-ui/internal/ThemePlayground/VariableValue.tsx +++ b/packages/react-ui/internal/ThemePlayground/VariableValue.tsx @@ -10,6 +10,7 @@ import { Link } from '../../components/Link'; import { Hint } from '../../components/Hint'; import { isFunction } from '../../lib/utils'; import { cx } from '../../lib/theming/Emotion'; +import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Playground.styles'; @@ -30,10 +31,13 @@ export interface VariableValueState { editing: boolean; } +const defaultPropsInstance = { + deprecated: false, +}; +const defaultProps = getDefaultProps(defaultPropsInstance as VariableValueProps); + export class VariableValue extends React.Component { - public static defaultProps = { - deprecated: false, - }; + public static defaultProps = defaultProps; public state = { value: this.props.value, editing: false, diff --git a/packages/react-ui/lib/getDefaultProps.ts b/packages/react-ui/lib/getDefaultProps.ts new file mode 100644 index 00000000000..fb9e6a8cc6f --- /dev/null +++ b/packages/react-ui/lib/getDefaultProps.ts @@ -0,0 +1,3 @@ +export const getDefaultProps = (props: T) => { + return props as Pick; +}; From ebd64f0bd32dff785f9af7eab654d5024bbfbbf9 Mon Sep 17 00:00:00 2001 From: HelenaIsh Date: Wed, 16 Feb 2022 10:28:44 +0500 Subject: [PATCH 04/11] Revert "chore: fix default props type" This reverts commit 7f702155bee49f683200938f70cdfe9d2233f515. --- .../components/Autocomplete/Autocomplete.tsx | 22 +++++------ .../react-ui/components/Button/Button.tsx | 18 ++++----- .../react-ui/components/Center/Center.tsx | 10 ++--- .../react-ui/components/ComboBox/ComboBox.tsx | 22 +++++------ .../CurrencyInput/CurrencyInput.tsx | 18 ++++----- .../CurrencyLabel/CurrencyLabel.tsx | 4 +- .../components/DateInput/DateInput.tsx | 18 ++++----- .../components/DatePicker/DatePicker.tsx | 14 +++---- .../components/DropdownMenu/DropdownMenu.tsx | 12 ++---- .../react-ui/components/FxInput/FxInput.tsx | 14 +++---- .../react-ui/components/Gapped/Gapped.tsx | 14 +++---- packages/react-ui/components/Hint/Hint.tsx | 19 ++++------ packages/react-ui/components/Input/Input.tsx | 12 +++--- packages/react-ui/components/Kebab/Kebab.tsx | 20 ++++------ packages/react-ui/components/Link/Link.tsx | 12 ++---- .../react-ui/components/Loader/Loader.tsx | 16 +++----- packages/react-ui/components/Modal/Modal.tsx | 12 ++---- .../react-ui/components/Paging/Paging.tsx | 23 +++++------ .../PasswordInput/PasswordInput.tsx | 10 ++--- packages/react-ui/components/Radio/Radio.tsx | 10 ++--- .../components/RadioGroup/RadioGroup.tsx | 12 ++---- .../ScrollContainer/ScrollContainer.tsx | 14 +++---- .../react-ui/components/Select/Select.tsx | 30 +++++++-------- .../react-ui/components/SidePage/SidePage.tsx | 14 +++---- .../react-ui/components/Spinner/Spinner.tsx | 10 ++--- .../react-ui/components/Sticky/Sticky.tsx | 8 +--- packages/react-ui/components/Tabs/Tabs.tsx | 10 ++--- .../react-ui/components/Textarea/Textarea.tsx | 16 +++----- .../react-ui/components/Toggle/Toggle.tsx | 14 +++---- .../components/TokenInput/TokenInput.tsx | 38 +++++++++---------- .../react-ui/components/Tooltip/Tooltip.tsx | 20 ++++------ .../components/TooltipMenu/TooltipMenu.tsx | 10 ++--- packages/react-ui/internal/BGRuler.tsx | 36 ++++++++---------- .../react-ui/internal/Calendar/Calendar.tsx | 29 +++++++------- packages/react-ui/internal/Calendar/Month.tsx | 10 ++--- .../react-ui/internal/ComponentCombinator.tsx | 16 +++----- packages/react-ui/internal/ComponentTable.tsx | 11 +----- .../internal/CustomComboBox/ComboBoxMenu.tsx | 12 ++---- .../internal/CustomComboBox/ComboBoxView.tsx | 34 ++++++++--------- .../internal/DateSelect/DateSelect.tsx | 13 +++---- .../DropdownContainer/DropdownContainer.tsx | 19 ++++------ .../internal/InputLikeText/InputLikeText.tsx | 8 +--- .../internal/InternalMenu/InternalMenu.tsx | 22 +++++------ .../internal/MaskedInput/MaskedInput.tsx | 10 ++--- packages/react-ui/internal/Menu/Menu.tsx | 16 +++----- packages/react-ui/internal/Popup/Popup.tsx | 22 +++++------ .../react-ui/internal/PopupMenu/PopupMenu.tsx | 16 +++----- .../internal/RenderLayer/RenderLayer.tsx | 10 ++--- .../ThemePlayground/VariableValue.tsx | 10 ++--- packages/react-ui/lib/getDefaultProps.ts | 3 -- 50 files changed, 296 insertions(+), 497 deletions(-) delete mode 100644 packages/react-ui/lib/getDefaultProps.ts diff --git a/packages/react-ui/components/Autocomplete/Autocomplete.tsx b/packages/react-ui/components/Autocomplete/Autocomplete.tsx index 694d52cc41c..0f7d9923970 100644 --- a/packages/react-ui/components/Autocomplete/Autocomplete.tsx +++ b/packages/react-ui/components/Autocomplete/Autocomplete.tsx @@ -14,7 +14,6 @@ import { Nullable, Override } from '../../typings/utility-types'; import { fixClickFocusIE } from '../../lib/events/fixClickFocusIE'; import { CommonProps, CommonWrapper, CommonWrapperRestProps } from '../../internal/CommonWrapper'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; function match(pattern: string, items: string[]) { if (!pattern || !items) { @@ -68,17 +67,6 @@ export interface AutocompleteState { focused: boolean; } -const defaultPropsInstance = { - renderItem, - size: 'small', - disablePortal: false, - hasShadow: true, - menuMaxHeight: 300, - menuAlign: 'left', - preventWindowScroll: true, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as AutocompleteProps); - /** * Стандартный инпут с подсказками. * @@ -111,7 +99,15 @@ export class Autocomplete extends React.Component(defaultPropsInstance as ButtonProps); - @rootNode export class Button extends React.Component { public static __KONTUR_REACT_UI__ = 'Button'; @@ -180,7 +172,11 @@ export class Button extends React.Component { public static BOTTOM_RIGHT = Corners.BOTTOM_RIGHT; public static BOTTOM_LEFT = Corners.BOTTOM_LEFT; - public static defaultProps = defaultProps; + public static defaultProps = { + use: 'default' as ButtonUse, + size: 'small' as ButtonSize, + type: 'button' as ButtonType, + }; public state = { focusedByTab: false, @@ -267,8 +263,8 @@ export class Button extends React.Component { type: this.props.type, className: cx({ [styles.root(this.theme)]: true, - [styles[use!](this.theme)]: true, - [activeStyles[use!](this.theme)]: active, + [styles[use](this.theme)]: true, + [activeStyles[use](this.theme)]: active, [sizeClass]: true, [styles.focus(this.theme)]: isFocused, [styles.checked(this.theme)]: checked, diff --git a/packages/react-ui/components/Center/Center.tsx b/packages/react-ui/components/Center/Center.tsx index 13428ba8ac6..71a1b944106 100644 --- a/packages/react-ui/components/Center/Center.tsx +++ b/packages/react-ui/components/Center/Center.tsx @@ -4,7 +4,6 @@ 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'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Center.styles'; @@ -24,11 +23,6 @@ export interface CenterProps } > {} -const defaultPropsInstance = { - align: 'center', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as CenterProps); - /** * Контейнер, который центрирует элементы внутри себя. */ @@ -36,7 +30,9 @@ const defaultProps = getDefaultProps(defaultPropsInstance as Center export class Center extends React.Component { public static __KONTUR_REACT_UI__ = 'Center'; - public static defaultProps = defaultProps; + public static defaultProps = { + align: 'center', + }; private setRootNode!: TSetRootNode; public render() { diff --git a/packages/react-ui/components/ComboBox/ComboBox.tsx b/packages/react-ui/components/ComboBox/ComboBox.tsx index ca662302a31..8ffc1dd8e40 100644 --- a/packages/react-ui/components/ComboBox/ComboBox.tsx +++ b/packages/react-ui/components/ComboBox/ComboBox.tsx @@ -6,7 +6,6 @@ import { MenuItemState } from '../MenuItem'; import { InputIconType } from '../Input'; import { CommonProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; export interface ComboBoxProps extends CommonProps { align?: 'left' | 'center' | 'right'; @@ -167,22 +166,19 @@ export interface ComboBoxItem { label: string; } -const defaultPropsInstance = { - itemToValue: (item: ComboBoxItem) => item.value, - valueToString: (item: ComboBoxItem) => item.label, - renderValue: (item: ComboBoxItem) => item.label, - renderItem: (item: ComboBoxItem) => item.label, - menuAlign: 'left', - searchOnFocus: true, - drawArrow: true, -}; -const defaultProps = getDefaultProps>(defaultPropsInstance as ComboBoxProps); - @rootNode export class ComboBox extends React.Component> { public static __KONTUR_REACT_UI__ = 'ComboBox'; - public static defaultProps = defaultProps; + public static defaultProps = { + itemToValue: (item: ComboBoxItem) => item.value, + valueToString: (item: ComboBoxItem) => item.label, + renderValue: (item: ComboBoxItem) => item.label, + renderItem: (item: ComboBoxItem) => item.label, + menuAlign: 'left', + searchOnFocus: true, + drawArrow: true, + }; private comboboxElement: Nullable> = null; private setRootNode!: TSetRootNode; diff --git a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx index c1aa838e705..99b21056745 100644 --- a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx +++ b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx @@ -8,7 +8,6 @@ import { Input, InputProps } from '../Input'; import { Nullable, Override } from '../../typings/utility-types'; import { CommonProps, CommonWrapper, CommonWrapperRestProps } from '../../internal/CommonWrapper'; import { TSetRootNode, rootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { MAX_SAFE_DIGITS } from './constants'; import { Selection, SelectionDirection, SelectionHelper } from './SelectionHelper'; @@ -47,15 +46,6 @@ export interface CurrencyInputState { focused: boolean; } -const defaultPropsInstance = { - align: 'right', - fractionDigits: 2, - hideTrailingZeros: false, - value: null, - inputMode: 'decimal', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as CurrencyInputProps); - /** * Поле для денежных сумм (и других числовых значений). * Принимает любые свойства `Input`. @@ -92,7 +82,13 @@ export class CurrencyInput extends React.PureComponent(defaultPropsInstance as CurrencyLabelProps); export const CurrencyLabel = (props: CurrencyLabelProps): JSX.Element => { const { value, fractionDigits, currencySymbol } = props; diff --git a/packages/react-ui/components/DateInput/DateInput.tsx b/packages/react-ui/components/DateInput/DateInput.tsx index 680efa3f481..d26d11a5045 100644 --- a/packages/react-ui/components/DateInput/DateInput.tsx +++ b/packages/react-ui/components/DateInput/DateInput.tsx @@ -12,7 +12,6 @@ import { CalendarIcon } from '../../internal/icons/16px'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { DateFragmentsView } from './DateFragmentsView'; import { styles } from './DateInput.styles'; @@ -72,21 +71,18 @@ export interface DateInputProps extends CommonProps { onKeyDown?: (x0: React.KeyboardEvent) => void; } -const defaultPropsInstance = { - value: '', - minDate: MIN_FULLDATE, - maxDate: MAX_FULLDATE, - size: 'small', - width: 125, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as DateInputProps); - @rootNode @locale('DatePicker', DatePickerLocaleHelper) export class DateInput extends React.Component { public static __KONTUR_REACT_UI__ = 'DateInput'; - public static defaultProps = defaultProps; + public static defaultProps = { + value: '', + minDate: MIN_FULLDATE, + maxDate: MAX_FULLDATE, + size: 'small', + width: 125, + }; private iDateMediator: InternalDateMediator = new InternalDateMediator(); private inputLikeText: InputLikeText | null = null; diff --git a/packages/react-ui/components/DatePicker/DatePicker.tsx b/packages/react-ui/components/DatePicker/DatePicker.tsx index 9bab45105c5..8bc77bb5a2b 100644 --- a/packages/react-ui/components/DatePicker/DatePicker.tsx +++ b/packages/react-ui/components/DatePicker/DatePicker.tsx @@ -15,7 +15,6 @@ import { isMobile } from '../../lib/client'; import { NativeDateInput } from '../../internal/NativeDateInput'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; import { isNonNullable } from '../../lib/utils'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { Picker } from './Picker'; import { styles } from './DatePicker.styles'; @@ -86,13 +85,6 @@ export interface DatePickerState { type DatePickerValue = string; -const defaultPropsInstance = { - minDate: MIN_FULLDATE, - maxDate: MAX_FULLDATE, - isHoliday: (_day: DatePickerValue, isWeekend: boolean) => isWeekend, -}; -const defaultProps = getDefaultProps>(defaultPropsInstance as DatePickerProps); - @rootNode export class DatePicker extends React.PureComponent, DatePickerState> { public static __KONTUR_REACT_UI__ = 'DatePicker'; @@ -147,7 +139,11 @@ export class DatePicker extends React.PureComponent isWeekend, + }; public static validate = (value: Nullable, range: { minDate?: string; maxDate?: string } = {}) => { if (!value) { diff --git a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx index 39a8edeb9d2..5396d8f2bc0 100644 --- a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx +++ b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx @@ -8,7 +8,6 @@ import { isProductionEnv, isTestEnv } from '../../lib/currentEnvironment'; import { PopupPositionsType } from '../../internal/Popup'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; export interface DropdownMenuProps extends CommonProps { /** Максимальная высота меню */ @@ -57,12 +56,6 @@ export interface DropdownMenuProps extends CommonProps { disableAnimations: boolean; } -const defaultPropsInstance = { - disableAnimations: isTestEnv, - positions: ['bottom left', 'bottom right', 'top left', 'top right'], -}; -const defaultProps = getDefaultProps(defaultPropsInstance as DropdownMenuProps); - /** * Меню, раскрывающееся по клику на переданный в `caption` элемент */ @@ -70,7 +63,10 @@ const defaultProps = getDefaultProps(defaultPropsInstance as export class DropdownMenu extends React.Component { public static __KONTUR_REACT_UI__ = 'DropdownMenu'; - public static defaultProps = defaultProps; + public static defaultProps = { + disableAnimations: isTestEnv, + positions: ['bottom left', 'bottom right', 'top left', 'top right'], + }; private popupMenu: Nullable = null; private setRootNode!: TSetRootNode; diff --git a/packages/react-ui/components/FxInput/FxInput.tsx b/packages/react-ui/components/FxInput/FxInput.tsx index 96a082f4e65..b7fa770025a 100644 --- a/packages/react-ui/components/FxInput/FxInput.tsx +++ b/packages/react-ui/components/FxInput/FxInput.tsx @@ -10,7 +10,6 @@ import { Override } from '../../typings/utility-types'; import { FunctionIcon, UndoIcon } from '../../internal/icons/16px'; import { CommonWrapper, CommonProps, CommonWrapperRestProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; export interface FxInputProps extends CommonProps, @@ -34,13 +33,6 @@ export interface FxInputProps } > {} -const defaultPropsInstance = { - width: 250, - type: 'text', - value: '', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as FxInputProps); - /** Принимает все свойства `Input`'a */ @rootNode export class FxInput extends React.Component { @@ -51,7 +43,11 @@ export class FxInput extends React.Component { type: PropTypes.string, }; - public static defaultProps = defaultProps; + public static defaultProps = { + width: 250, + type: 'text', + value: '', + }; private input: Input | CurrencyInput | null = null; diff --git a/packages/react-ui/components/Gapped/Gapped.tsx b/packages/react-ui/components/Gapped/Gapped.tsx index 73cc7fafbfb..441252fc900 100644 --- a/packages/react-ui/components/Gapped/Gapped.tsx +++ b/packages/react-ui/components/Gapped/Gapped.tsx @@ -6,7 +6,6 @@ import { is8pxTheme } from '../../lib/theming/ThemeHelpers'; import { Theme } from '../../lib/theming/Theme'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; export interface GappedProps extends CommonProps { /** @@ -32,13 +31,6 @@ export interface GappedProps extends CommonProps { children: React.ReactNode; } -const defaultPropsInstance = { - wrap: false, - vertical: false, - verticalAlign: 'baseline', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as GappedProps); - /** * Контейнер, расстояние между элементами в котором равно `gap`. */ @@ -66,7 +58,11 @@ export class Gapped extends React.Component { private theme!: Theme; private setRootNode!: TSetRootNode; - public static defaultProps = defaultProps; + public static defaultProps = { + wrap: false, + vertical: false, + verticalAlign: 'baseline', + }; public render() { return ( diff --git a/packages/react-ui/components/Hint/Hint.tsx b/packages/react-ui/components/Hint/Hint.tsx index 07e688b5bad..868adfdccf6 100644 --- a/packages/react-ui/components/Hint/Hint.tsx +++ b/packages/react-ui/components/Hint/Hint.tsx @@ -10,7 +10,6 @@ import { isTestEnv } from '../../lib/currentEnvironment'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Hint.styles'; @@ -82,15 +81,6 @@ const Positions: PopupPositionsType[] = [ 'right top', 'right bottom', ]; -const defaultPropsInstance = { - pos: 'top', - manual: false, - opened: false, - maxWidth: 200, - disableAnimations: isTestEnv, - useWrapper: false, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as HintProps); /** * Всплывающая подсказка, которая по умолчанию отображается при наведении на элемент.
Можно задать другие условия отображения. @@ -99,7 +89,14 @@ const defaultProps = getDefaultProps(defaultPropsInstance as HintProp export class Hint extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'Hint'; - public static defaultProps = defaultProps; + public static defaultProps = { + pos: 'top', + manual: false, + opened: false, + maxWidth: 200, + disableAnimations: isTestEnv, + useWrapper: false, + }; public state: HintState = { opened: this.props.manual ? !!this.props.opened : false, diff --git a/packages/react-ui/components/Input/Input.tsx b/packages/react-ui/components/Input/Input.tsx index 914c9ed67e0..9a2efea4529 100644 --- a/packages/react-ui/components/Input/Input.tsx +++ b/packages/react-ui/components/Input/Input.tsx @@ -12,7 +12,6 @@ import { Theme } from '../../lib/theming/Theme'; import { CommonWrapper, CommonProps, CommonWrapperRestProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Input.styles'; @@ -108,11 +107,6 @@ export interface InputState { polyfillPlaceholder: boolean; } -const defaultPropsInstance = { - size: 'small', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as InputProps); - /** * Интерфес пропсов наследуется от `React.InputHTMLAttributes`. * Все пропсы кроме перечисленных, `className` и `style` передаются в `` @@ -121,7 +115,11 @@ const defaultProps = getDefaultProps(defaultPropsInstance as InputPr export class Input extends React.Component { public static __KONTUR_REACT_UI__ = 'Input'; - public static defaultProps = defaultProps; + public static defaultProps: { + size: InputSize; + } = { + size: 'small', + }; public state: InputState = { polyfillPlaceholder: false, diff --git a/packages/react-ui/components/Kebab/Kebab.tsx b/packages/react-ui/components/Kebab/Kebab.tsx index c0905152a36..5679f3f2938 100644 --- a/packages/react-ui/components/Kebab/Kebab.tsx +++ b/packages/react-ui/components/Kebab/Kebab.tsx @@ -15,7 +15,6 @@ import { ThemeFactory } from '../../lib/theming/ThemeFactory'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Kebab.styles'; @@ -58,23 +57,20 @@ export interface KebabState { opened: boolean; } -const defaultPropsInstance = { - onOpen: () => undefined, - onClose: () => undefined, - positions: ['bottom left', 'bottom right', 'top left', 'top right'], - size: 'small', - disableAnimations: isTestEnv, - icon: , -}; -const defaultProps = getDefaultProps(defaultPropsInstance as KebabProps); - @rootNode export class Kebab extends React.Component { public static __KONTUR_REACT_UI__ = 'Kebab'; public static propTypes = {}; - public static defaultProps = defaultProps; + public static defaultProps = { + onOpen: () => undefined, + onClose: () => undefined, + positions: ['bottom left', 'bottom right', 'top left', 'top right'], + size: 'small', + disableAnimations: isTestEnv, + icon: , + }; public state = { opened: false, diff --git a/packages/react-ui/components/Link/Link.tsx b/packages/react-ui/components/Link/Link.tsx index 2e0bf4c3204..b2dc20d5126 100644 --- a/packages/react-ui/components/Link/Link.tsx +++ b/packages/react-ui/components/Link/Link.tsx @@ -10,7 +10,6 @@ import { Spinner } from '../Spinner'; import { CommonWrapper, CommonProps, CommonWrapperRestProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode/rootNodeDecorator'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Link.styles'; @@ -62,12 +61,6 @@ export interface LinkState { focusedByTab: boolean; } -const defaultPropsInstance = { - href: '', - use: 'default', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as LinkProps); - /** * Элемент ссылки из HTML. */ @@ -85,7 +78,10 @@ export class Link extends React.Component { use: PropTypes.oneOf(['default', 'success', 'danger', 'grayed']), }; - public static defaultProps = defaultProps; + public static defaultProps = { + href: '', + use: 'default', + }; public state = { focusedByTab: false, diff --git a/packages/react-ui/components/Loader/Loader.tsx b/packages/react-ui/components/Loader/Loader.tsx index cc51b991eac..3508eaa51cf 100644 --- a/packages/react-ui/components/Loader/Loader.tsx +++ b/packages/react-ui/components/Loader/Loader.tsx @@ -14,7 +14,6 @@ import { isTestEnv } from '../../lib/currentEnvironment'; import { TaskWithDelayAndMinimalDuration } from '../../lib/taskWithDelayAndMinimalDuration'; import { getTabbableElements } from '../../lib/dom/tabbableHelpers'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Loader.styles'; @@ -51,14 +50,6 @@ export interface LoaderState { spinnerStyle?: object; } -const defaultPropsInstance = { - type: Spinner.Types.normal, - active: false, - delayBeforeSpinnerShow: isTestEnv ? 0 : 300, - minimalDelayBeforeSpinnerHide: isTestEnv ? 0 : 1000, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as LoaderProps); - /** * DRAFT - лоадер-контейнер */ @@ -66,7 +57,12 @@ const defaultProps = getDefaultProps(defaultPropsInstance as Loader export class Loader extends React.Component { public static __KONTUR_REACT_UI__ = 'Loader'; - public static defaultProps = defaultProps; + public static defaultProps: Partial = { + type: Spinner.Types.normal, + active: false, + delayBeforeSpinnerShow: isTestEnv ? 0 : 300, + minimalDelayBeforeSpinnerHide: isTestEnv ? 0 : 1000, + }; public static propTypes = { /** diff --git a/packages/react-ui/components/Modal/Modal.tsx b/packages/react-ui/components/Modal/Modal.tsx index fc1ebe57912..6f4d75094e9 100644 --- a/packages/react-ui/components/Modal/Modal.tsx +++ b/packages/react-ui/components/Modal/Modal.tsx @@ -14,7 +14,6 @@ import { Theme } from '../../lib/theming/Theme'; import { isIE11 } from '../../lib/client'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { ModalContext, ModalContextProps } from './ModalContext'; import { ModalFooter } from './ModalFooter'; @@ -69,12 +68,6 @@ export interface ModalState { hasPanel: boolean; } -const defaultPropsInstance = { - // NOTE: в ie нормально не работает - disableFocusLock: isIE11, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as ModalProps); - /** * Модальное окно * @@ -96,7 +89,10 @@ export class Modal extends React.Component { public static Body = ModalBody; public static Footer = ModalFooter; - public static defaultProps = defaultProps; + public static defaultProps = { + // NOTE: в ie нормально не работает + disableFocusLock: isIE11, + }; public state: ModalState = { stackPosition: 0, diff --git a/packages/react-ui/components/Paging/Paging.tsx b/packages/react-ui/components/Paging/Paging.tsx index 82b3f1e3399..bc590321b18 100644 --- a/packages/react-ui/components/Paging/Paging.tsx +++ b/packages/react-ui/components/Paging/Paging.tsx @@ -13,7 +13,6 @@ import { ArrowChevronRightIcon } from '../../internal/icons/16px'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Paging.styles'; import * as NavigationHelper from './NavigationHelper'; @@ -55,7 +54,6 @@ export interface PagingProps extends CommonProps { * на каждом из них. Такие случаи лучше обрабатывать отдельно. */ useGlobalListener: boolean; - 'data-tid': string; } export interface PagingState { @@ -66,23 +64,20 @@ export interface PagingState { export type ItemType = number | '.' | 'forward'; -const defaultPropsInstance = { - component: ({ className, onClick, children }: any) => ( - - {children} - - ), - useGlobalListener: false, - ['data-tid']: 'Paging__root', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as PagingProps); - @rootNode @locale('Paging', PagingLocaleHelper) export class Paging extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'Paging'; - public static defaultProps = defaultProps; + public static defaultProps = { + component: ({ className, onClick, children }: any) => ( + + {children} + + ), + useGlobalListener: false, + ['data-tid']: 'Paging__root', + }; public static propTypes = {}; private setRootNode!: TSetRootNode; diff --git a/packages/react-ui/components/PasswordInput/PasswordInput.tsx b/packages/react-ui/components/PasswordInput/PasswordInput.tsx index 1e5e0be6c73..2d8e9b946f8 100644 --- a/packages/react-ui/components/PasswordInput/PasswordInput.tsx +++ b/packages/react-ui/components/PasswordInput/PasswordInput.tsx @@ -12,7 +12,6 @@ import { Theme } from '../../lib/theming/Theme'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './PasswordInput.styles'; @@ -25,11 +24,6 @@ export interface PasswordInputState { capsLockEnabled?: boolean | null; } -const defaultPropsInstance = { - size: 'small', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as PasswordInputProps); - /** * Компонент для ввода пароля */ @@ -44,7 +38,9 @@ export class PasswordInput extends React.PureComponent>(defaultPropsInstance as RadioProps); - /** * Радио-кнопки используются, когда может быть выбран только один вариант из нескольких. */ @@ -73,7 +67,9 @@ export class Radio extends React.Component, RadioState> { focusedByKeyboard: false, }; - public static defaultProps = defaultProps; + public static defaultProps = { + focused: false, + }; public static contextType = RadioGroupContext; public context: RadioGroupContextType = this.context; diff --git a/packages/react-ui/components/RadioGroup/RadioGroup.tsx b/packages/react-ui/components/RadioGroup/RadioGroup.tsx index a35e11cc9e3..c9241dc3f26 100644 --- a/packages/react-ui/components/RadioGroup/RadioGroup.tsx +++ b/packages/react-ui/components/RadioGroup/RadioGroup.tsx @@ -12,7 +12,6 @@ import { Theme } from '../../lib/theming/Theme'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './RadioGroup.styles'; import { Prevent } from './Prevent'; @@ -82,11 +81,6 @@ export interface RadioGroupState { activeItem?: T; } -const defaultPropsInstance = { - renderItem, -}; -const defaultProps = getDefaultProps>(defaultPropsInstance as RadioGroupProps); - /** * * `children` может содержать любую разметку с компонентами Radio, @@ -114,7 +108,9 @@ export class RadioGroup extends React.Component, RadioGrou onMouseOver: PropTypes.func, }; - public static defaultProps = defaultProps; + public static defaultProps = { + renderItem, + }; public static Prevent = Prevent; @@ -233,7 +229,7 @@ export class RadioGroup extends React.Component, RadioGrou return ( - {this.getProps().renderItem!(itemValue, data)} + {this.getProps().renderItem(itemValue, data)} ); }; diff --git a/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx b/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx index 92475bd3ae1..fd124d7843b 100644 --- a/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx +++ b/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx @@ -6,7 +6,6 @@ import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { Nullable } from '../../typings/utility-types'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles, globalClasses } from './ScrollContainer.styles'; import { scrollSizeParametersNames } from './ScrollContainer.constants'; @@ -45,13 +44,6 @@ export interface ScrollContainerProps extends CommonProps { onScroll?: (e: React.UIEvent) => void; } -const defaultPropsInstance = { - invert: false, - scrollBehaviour: 'auto', - preventWindowScroll: false, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as ScrollContainerProps); - @rootNode export class ScrollContainer extends React.Component { public static __KONTUR_REACT_UI__ = 'ScrollContainer'; @@ -65,7 +57,11 @@ export class ScrollContainer extends React.Component { onScrollStateChange: PropTypes.func, }; - public static defaultProps = defaultProps; + public static defaultProps = { + invert: false, + scrollBehaviour: 'auto', + preventWindowScroll: false, + }; private scrollX: Nullable; private scrollY: Nullable; diff --git a/packages/react-ui/components/Select/Select.tsx b/packages/react-ui/components/Select/Select.tsx index 453b3a4a6d9..964466f4948 100644 --- a/packages/react-ui/components/Select/Select.tsx +++ b/packages/react-ui/components/Select/Select.tsx @@ -29,7 +29,6 @@ import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { ArrowChevronDownIcon } from '../../internal/icons/16px'; import { cx } from '../../lib/theming/Emotion'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { Item } from './Item'; import { SelectLocale, SelectLocaleHelper } from './locale'; @@ -149,15 +148,6 @@ interface FocusableReactElement extends React.ReactElement { focus: (event?: any) => void; } -const defaultPropsInstance = { - renderValue, - renderItem, - areValuesEqual, - filterItem, - use: 'default', -}; -const defaultProps = getDefaultProps>(defaultPropsInstance as SelectProps); - @rootNode @locale('Select', SelectLocaleHelper) export class Select extends React.Component, SelectState> { @@ -186,7 +176,13 @@ export class Select extends React.Component ; @@ -305,7 +301,7 @@ export class Select extends React.Component extends React.Component - {this.getProps().renderItem!(iValue, item)} + {this.getProps().renderItem(iValue, item)} ); }, @@ -516,7 +512,7 @@ export class Select extends React.Component extends React.Component extends React.Component(defaultPropsInstance as SidePageProps); - const TRANSITION_TIMEOUT = 200; /** @@ -143,7 +135,11 @@ export class SidePage extends React.Component { } }; - public static defaultProps = defaultProps; + public static defaultProps = { + disableAnimations: isTestEnv, + disableFocusLock: true, + offset: 0, + }; public render(): JSX.Element { return ( diff --git a/packages/react-ui/components/Spinner/Spinner.tsx b/packages/react-ui/components/Spinner/Spinner.tsx index 52b6934ab5d..0dba42c47ff 100644 --- a/packages/react-ui/components/Spinner/Spinner.tsx +++ b/packages/react-ui/components/Spinner/Spinner.tsx @@ -8,7 +8,6 @@ import { SpinnerIcon } from '../../internal/icons/SpinnerIcon'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Spinner.styles'; import { SpinnerLocale, SpinnerLocaleHelper } from './locale'; @@ -39,11 +38,6 @@ export interface SpinnerProps extends CommonProps { color?: React.CSSProperties['color']; } -const defaultPropsInstance = { - type: 'normal', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as SpinnerProps); - /** * DRAFT - инлайн-лоадер */ @@ -73,7 +67,9 @@ export class Spinner extends React.Component { type: PropTypes.oneOf(Object.keys(types)), }; - public static defaultProps = defaultProps; + public static defaultProps: SpinnerProps = { + type: 'normal', + }; public static Types: typeof types = types; private theme!: Theme; diff --git a/packages/react-ui/components/Sticky/Sticky.tsx b/packages/react-ui/components/Sticky/Sticky.tsx index 2a68939c4cb..a7068f091ec 100644 --- a/packages/react-ui/components/Sticky/Sticky.tsx +++ b/packages/react-ui/components/Sticky/Sticky.tsx @@ -9,7 +9,6 @@ import { ZIndex } from '../../internal/ZIndex'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Sticky.styles'; @@ -36,11 +35,6 @@ export interface StickyState { relativeTop: number; } -const defaultPropsInstance = { - offset: 0, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as StickyProps); - @rootNode export class Sticky extends React.Component { public static __KONTUR_REACT_UI__ = 'Sticky'; @@ -61,7 +55,7 @@ export class Sticky extends React.Component { side: PropTypes.oneOf(['top', 'bottom']).isRequired, }; - public static defaultProps = defaultProps; + public static defaultProps = { offset: 0 }; public state: StickyState = { fixed: false, diff --git a/packages/react-ui/components/Tabs/Tabs.tsx b/packages/react-ui/components/Tabs/Tabs.tsx index 89718f0b353..991fe4bd014 100644 --- a/packages/react-ui/components/Tabs/Tabs.tsx +++ b/packages/react-ui/components/Tabs/Tabs.tsx @@ -7,7 +7,6 @@ import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { getRootNode } from '../../lib/rootNode/getRootNode'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { Indicator } from './Indicator'; import { styles } from './Tabs.styles'; @@ -47,11 +46,6 @@ export interface TabsProps extends CommonProps { width?: number | string; } -const defaultPropsInstance = { - vertical: false, -}; -const defaultProps = getDefaultProps>(defaultPropsInstance as TabsProps); - /** * Tabs wrapper * @@ -68,7 +62,9 @@ export class Tabs extends React.Component(defaultPropsInstance as TextareaProps); - /** * Компонент для ввода многострочного текста. * @@ -185,7 +176,12 @@ export class Textarea extends React.Component { onCopy: PropTypes.func, }; - public static defaultProps = defaultProps; + public static defaultProps = { + rows: 3, + maxRows: 15, + extraRow: true, + disableAnimations: isTestEnv, + }; public state = { polyfillPlaceholder, diff --git a/packages/react-ui/components/Toggle/Toggle.tsx b/packages/react-ui/components/Toggle/Toggle.tsx index c71604b7741..4ae46a0edb1 100644 --- a/packages/react-ui/components/Toggle/Toggle.tsx +++ b/packages/react-ui/components/Toggle/Toggle.tsx @@ -8,7 +8,6 @@ import { Theme } from '../../lib/theming/Theme'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles, globalClasses } from './Toggle.styles'; @@ -83,13 +82,6 @@ export interface ToggleState { focusByTab?: boolean; } -const defaultPropsInstance = { - disabled: false, - loading: false, - captionPosition: 'right', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as ToggleProps); - /** * _Примечание:_ под тоглом понимается полный компонент т.е. надпись + переключатель, а не просто переключатель. */ @@ -113,7 +105,11 @@ export class Toggle extends React.Component { }, }; - public static defaultProps = defaultProps; + public static defaultProps = { + disabled: false, + loading: false, + captionPosition: 'right', + }; private theme!: Theme; private input: HTMLInputElement | null = null; diff --git a/packages/react-ui/components/TokenInput/TokenInput.tsx b/packages/react-ui/components/TokenInput/TokenInput.tsx index 1b05c14ab78..b54b8ee2eb8 100644 --- a/packages/react-ui/components/TokenInput/TokenInput.tsx +++ b/packages/react-ui/components/TokenInput/TokenInput.tsx @@ -26,7 +26,6 @@ import { MenuItem } from '../MenuItem/MenuItem'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { TokenInputLocale, TokenInputLocaleHelper } from './locale'; import { styles } from './TokenInput.styles'; @@ -170,31 +169,28 @@ const defaultRenderToken = ( ); -const defaultPropsInstance = { - selectedItems: [], - delimiters: [',', ' '], - renderItem: identity, - renderValue: identity, - valueToString: identity, - valueToItem: (item: string) => item, - toKey: defaultToKey, - onValueChange: () => void 0, - width: 250 as string | number, - onBlur: emptyHandler, - onFocus: emptyHandler, - onMouseEnter: emptyHandler, - onMouseLeave: emptyHandler, - menuWidth: 'auto', - menuAlign: 'cursor', -}; -const defaultProps = getDefaultProps>(defaultPropsInstance as TokenInputProps); - @rootNode @locale('TokenInput', TokenInputLocaleHelper) export class TokenInput extends React.PureComponent, TokenInputState> { public static __KONTUR_REACT_UI__ = 'TokenInput'; - public static defaultProps = defaultProps; + public static defaultProps: Partial> = { + selectedItems: [], + delimiters: [',', ' '], + renderItem: identity, + renderValue: identity, + valueToString: identity, + valueToItem: (item: string) => item, + toKey: defaultToKey, + onValueChange: () => void 0, + width: 250 as string | number, + onBlur: emptyHandler, + onFocus: emptyHandler, + onMouseEnter: emptyHandler, + onMouseLeave: emptyHandler, + menuWidth: 'auto', + menuAlign: 'cursor', + }; public state: TokenInputState = DefaultState; diff --git a/packages/react-ui/components/Tooltip/Tooltip.tsx b/packages/react-ui/components/Tooltip/Tooltip.tsx index 32a7f1ab45c..f76feceda1e 100644 --- a/packages/react-ui/components/Tooltip/Tooltip.tsx +++ b/packages/react-ui/components/Tooltip/Tooltip.tsx @@ -14,7 +14,6 @@ import { Theme } from '../../lib/theming/Theme'; import { isTestEnv } from '../../lib/currentEnvironment'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Tooltip.styles'; @@ -148,16 +147,6 @@ const Positions: PopupPositionsType[] = [ 'bottom right', ]; -const defaultPropsInstance = { - pos: DefaultPosition, - trigger: 'hover', - allowedPositions: Positions, - disableAnimations: isTestEnv, - useWrapper: false, - closeOnChildrenMouseLeave: false, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as TooltipProps); - @rootNode export class Tooltip extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'Tooltip'; @@ -176,7 +165,14 @@ export class Tooltip extends React.PureComponent { }, }; - public static defaultProps = defaultProps; + public static defaultProps = { + pos: DefaultPosition, + trigger: 'hover', + allowedPositions: Positions, + disableAnimations: isTestEnv, + useWrapper: false, + closeOnChildrenMouseLeave: false, + }; public static delay = 100; private static triggersWithoutCloseButton: TooltipTrigger[] = ['hover', 'hoverAnchor', 'focus', 'hover&focus']; diff --git a/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx b/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx index 71f4232a1c0..ca486ce18ca 100644 --- a/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx +++ b/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx @@ -9,7 +9,6 @@ import { MenuHeaderProps } from '../MenuHeader'; import { PopupPositionsType } from '../../internal/Popup'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; export type TooltipMenuChildType = React.ReactElement; @@ -51,11 +50,6 @@ export interface TooltipMenuProps extends CommonProps { disableAnimations: boolean; } -const defaultPropsInstance = { - disableAnimations: isTestEnv, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as TooltipMenuProps); - /** * Меню, раскрывающееся по клику на переданный в `caption` элемент. * @@ -72,7 +66,9 @@ export class TooltipMenu extends React.Component { public static __KONTUR_REACT_UI__ = 'TooltipMenu'; private setRootNode!: TSetRootNode; - public static defaultProps = defaultProps; + public static defaultProps = { + disableAnimations: isTestEnv, + }; constructor(props: TooltipMenuProps) { super(props); diff --git a/packages/react-ui/internal/BGRuler.tsx b/packages/react-ui/internal/BGRuler.tsx index 30eb675aac4..f4f1260f1c8 100644 --- a/packages/react-ui/internal/BGRuler.tsx +++ b/packages/react-ui/internal/BGRuler.tsx @@ -1,8 +1,12 @@ import React from 'react'; -import { getDefaultProps } from '../lib/getDefaultProps'; - -interface BGRulerProps { +/** + * Компонент рисует пиксельную линейку на заднем фоне. + * Помогает контролировать размеры элементов при скриншотном тестировании. + * + * @see FxInput/__stories__/FxInput.stories.tsx + */ +export class BGRuler extends React.Component<{ width?: string | number; height?: string | number; top?: string | number; @@ -10,24 +14,14 @@ interface BGRulerProps { right?: string | number; left?: string | number; color?: string; -} -const defaultPropsInstance = { - height: 20, - top: 0, - left: 0, - right: 0, - color: '#333', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as BGRulerProps); - -/** - * Компонент рисует пиксельную линейку на заднем фоне. - * Помогает контролировать размеры элементов при скриншотном тестировании. - * - * @see FxInput/__stories__/FxInput.stories.tsx - */ -export class BGRuler extends React.Component { - public static defaultProps = defaultProps; +}> { + public static defaultProps = { + height: 20, + top: 0, + left: 0, + right: 0, + color: '#333', + }; private iframe: HTMLIFrameElement | null = null; diff --git a/packages/react-ui/internal/Calendar/Calendar.tsx b/packages/react-ui/internal/Calendar/Calendar.tsx index cd1ae8f5d9e..836cc7116d6 100644 --- a/packages/react-ui/internal/Calendar/Calendar.tsx +++ b/packages/react-ui/internal/Calendar/Calendar.tsx @@ -8,7 +8,6 @@ import { Theme } from '../../lib/theming/Theme'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Animation } from '../../lib/animation'; import { isMobile } from '../../lib/client'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { themeConfig } from './config'; import * as CalendarUtils from './CalendarUtils'; @@ -46,24 +45,22 @@ const getTodayDate = () => { }; }; -const defaultPropsInstance = { - minDate: { - year: MIN_YEAR, - month: MIN_MONTH, - date: MIN_DATE, - }, - maxDate: { - year: MAX_YEAR, - month: MAX_MONTH, - date: MAX_DATE, - }, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as CalendarProps); - export class Calendar extends React.Component { public static __KONTUR_REACT_UI__ = 'Calendar'; - public static defaultProps = defaultProps; + public static defaultProps = { + holidays: [], + minDate: { + year: MIN_YEAR, + month: MIN_MONTH, + date: MIN_DATE, + }, + maxDate: { + year: MAX_YEAR, + month: MAX_MONTH, + date: MAX_DATE, + }, + }; private theme!: Theme; private wheelEndTimeout: Nullable; diff --git a/packages/react-ui/internal/Calendar/Month.tsx b/packages/react-ui/internal/Calendar/Month.tsx index c8c3402ef2f..c8474a19fa4 100644 --- a/packages/react-ui/internal/Calendar/Month.tsx +++ b/packages/react-ui/internal/Calendar/Month.tsx @@ -4,7 +4,6 @@ import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; import { DateSelect } from '../DateSelect'; import { Nullable } from '../../typings/utility-types'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { themeConfig } from './config'; import * as CDS from './CalendarDateShape'; @@ -141,15 +140,12 @@ interface MonthDayGridProps { isHoliday: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => boolean; } -const defaultPropsInstance = { - isHoliday: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => day.isWeekend, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as MonthDayGridProps); - class MonthDayGrid extends React.Component { private theme!: Theme; - public static defaultProps = defaultProps; + public static defaultProps = { + isHoliday: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => day.isWeekend, + }; public shouldComponentUpdate(nextProps: MonthDayGridProps) { if (!CDS.isEqual(nextProps.value, this.props.value)) { diff --git a/packages/react-ui/internal/ComponentCombinator.tsx b/packages/react-ui/internal/ComponentCombinator.tsx index 462e930f2e6..8b3632f0127 100644 --- a/packages/react-ui/internal/ComponentCombinator.tsx +++ b/packages/react-ui/internal/ComponentCombinator.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { DefaultizeProps } from '../lib/utils'; -import { getDefaultProps } from '../lib/getDefaultProps'; import { ComponentTable, StatePropsCombinations, StateType } from './ComponentTable'; @@ -12,14 +11,6 @@ export interface ComponentCombinatorProps { presetState: Partial; } -const defaultPropsInstance = { - presetProps: {}, - presetState: {}, -}; -const defaultProps = getDefaultProps>( - defaultPropsInstance as ComponentCombinatorProps, -); - export class ComponentCombinator< T extends React.Component, C extends React.ComponentType, @@ -28,7 +19,12 @@ export class ComponentCombinator< ComponentCombinatorProps ? React.ClassType : C, P, StateType>, { page: number } > { - public static defaultProps = defaultProps; + public static defaultProps = { + props: [], + states: [], + presetProps: {}, + presetState: {}, + }; public state = { page: 0, diff --git a/packages/react-ui/internal/ComponentTable.tsx b/packages/react-ui/internal/ComponentTable.tsx index 5fa48edae75..a56927a9bf2 100644 --- a/packages/react-ui/internal/ComponentTable.tsx +++ b/packages/react-ui/internal/ComponentTable.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { isFunctionalComponent, DefaultizeProps } from '../lib/utils'; -import { getDefaultProps } from '../lib/getDefaultProps'; // TODO We should output state too const renderPropsDesc =

>(props: P): React.ReactNode => { @@ -41,14 +40,6 @@ export interface ComponentTableProps { Component: C; } -const defaultPropsInstance = { - presetProps: {}, - presetState: {}, -}; -const defaultProps = getDefaultProps>( - defaultPropsInstance as ComponentTableProps, -); - // Known limitation: Don't work when component have `propTypes` static field export class ComponentTable< T extends React.Component, @@ -57,7 +48,7 @@ export class ComponentTable< > extends React.Component< ComponentTableProps ? React.ClassType : C, P, StateType> > { - public static defaultProps = defaultProps; + public static defaultProps = { presetProps: {}, presetState: {} }; public render() { const { rows = [], cols = [], presetProps, presetState, Component } = this.props; diff --git a/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx b/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx index a7ae82638ac..9e446d3bb5d 100644 --- a/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx +++ b/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx @@ -6,7 +6,6 @@ import { MenuItem, MenuItemState } from '../../components/MenuItem'; import { Spinner } from '../../components/Spinner'; import { Nullable } from '../../typings/utility-types'; import { MenuSeparator } from '../../components/MenuSeparator'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { ComboBoxRequestStatus } from './CustomComboBoxTypes'; import { ComboBoxLocale, CustomComboBoxLocaleHelper } from './locale'; @@ -28,17 +27,14 @@ export interface ComboBoxMenuProps { requestStatus?: ComboBoxRequestStatus; } -const defaultPropsInstance = { - repeatRequest: () => undefined, - requestStatus: ComboBoxRequestStatus.Unknown, -}; -const defaultProps = getDefaultProps>(defaultPropsInstance as ComboBoxMenuProps); - @locale('ComboBox', CustomComboBoxLocaleHelper) export class ComboBoxMenu extends Component> { public static __KONTUR_REACT_UI__ = 'ComboBoxMenu'; - public static defaultProps = defaultProps; + public static defaultProps = { + repeatRequest: () => undefined, + requestStatus: ComboBoxRequestStatus.Unknown, + }; private readonly locale!: ComboBoxLocale; diff --git a/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx b/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx index 450cc76878b..d85d7932fff 100644 --- a/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx +++ b/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx @@ -12,7 +12,6 @@ import { Nullable } from '../../typings/utility-types'; import { ArrowChevronDownIcon } from '../icons/16px'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { rootNode, getRootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { ComboBoxMenu } from './ComboBoxMenu'; import { ComboBoxRequestStatus } from './CustomComboBoxTypes'; @@ -74,28 +73,25 @@ interface ComboBoxViewProps extends CommonProps { refInputLikeText?: (inputLikeText: Nullable) => void; } -const defaultPropsInstance = { - renderItem: (item: any) => item, - renderValue: (item: any) => item, - renderAddButton: () => null, - repeatRequest: () => undefined, - requestStatus: ComboBoxRequestStatus.Unknown, - onClickOutside: () => { - /**/ - }, - onFocusOutside: () => { - /**/ - }, - size: 'small', - width: 250, -}; -const defaultProps = getDefaultProps>(defaultPropsInstance as ComboBoxViewProps); - @rootNode export class ComboBoxView extends React.Component, {}> { public static __KONTUR_REACT_UI__ = 'ComboBoxView'; - public static defaultProps = defaultProps; + public static defaultProps = { + renderItem: (item: any) => item, + renderValue: (item: any) => item, + renderAddButton: () => null, + repeatRequest: () => undefined, + requestStatus: ComboBoxRequestStatus.Unknown, + onClickOutside: () => { + /**/ + }, + onFocusOutside: () => { + /**/ + }, + size: 'small', + width: 250, + }; private input: Nullable; private setRootNode!: TSetRootNode; diff --git a/packages/react-ui/internal/DateSelect/DateSelect.tsx b/packages/react-ui/internal/DateSelect/DateSelect.tsx index 07c18b4fcb9..de310c3248d 100644 --- a/packages/react-ui/internal/DateSelect/DateSelect.tsx +++ b/packages/react-ui/internal/DateSelect/DateSelect.tsx @@ -13,7 +13,6 @@ import { ThemeContext } from '../../lib/theming/ThemeContext'; import { ArrowTriangleUpDownIcon, ArrowChevronDownIcon, ArrowChevronUpIcon } from '../icons/16px'; import { isMobile } from '../../lib/client'; import { cx } from '../../lib/theming/Emotion'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './DateSelect.styles'; @@ -44,11 +43,6 @@ export interface DateSelectState { topCapped: boolean; nodeTop: number; } -const defaultPropsInstance = { - type: 'year', - width: 'auto', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as DateSelectProps); @locale('DatePicker', DatePickerLocaleHelper) export class DateSelect extends React.PureComponent { @@ -70,7 +64,12 @@ export class DateSelect extends React.PureComponent; @@ -28,18 +27,16 @@ export interface DropdownContainerState { minWidth: number; isDocumentElementRoot?: boolean; } -const defaultPropsInstance = { - align: 'left', - disablePortal: false, - offsetX: 0, - offsetY: -1, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as DropdownContainerProps); export class DropdownContainer extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'DropdownContainer'; - public static defaultProps = defaultProps; + public static defaultProps = { + align: 'left', + disablePortal: false, + offsetX: 0, + offsetY: -1, + }; public state: DropdownContainerState = { position: null, @@ -126,9 +123,9 @@ export class DropdownContainer extends React.PureComponent; -const defaultPropsInstance = { - size: 'small', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as InputLikeTextProps); - @rootNode export class InputLikeText extends React.Component { public static __KONTUR_REACT_UI__ = 'InputLikeText'; - public static defaultProps = defaultProps; + public static defaultProps = { size: 'small' }; public state = { blinking: false, focused: false }; diff --git a/packages/react-ui/internal/InternalMenu/InternalMenu.tsx b/packages/react-ui/internal/InternalMenu/InternalMenu.tsx index 9d734877416..23a5a3846fd 100644 --- a/packages/react-ui/internal/InternalMenu/InternalMenu.tsx +++ b/packages/react-ui/internal/InternalMenu/InternalMenu.tsx @@ -10,7 +10,6 @@ import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; import { cx } from '../../lib/theming/Emotion'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './InternalMenu.styles'; import { isActiveElement } from './isActiveElement'; @@ -38,21 +37,18 @@ interface MenuState { scrollState: ScrollContainerScrollState; } -const defaultPropsInstance = { - width: 'auto', - maxHeight: 300, - hasShadow: true, - preventWindowScroll: true, - cyclicSelection: true, - initialSelectedItemIndex: -1, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as MenuProps); - @rootNode export class InternalMenu extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'InternalMenu'; - public static defaultProps = defaultProps; + public static defaultProps = { + width: 'auto', + maxHeight: 300, + hasShadow: true, + preventWindowScroll: true, + cyclicSelection: true, + initialSelectedItemIndex: -1, + }; public state: MenuState = { highlightedIndex: -1, @@ -253,7 +249,7 @@ export class InternalMenu extends React.PureComponent { }; private setInitialSelection = () => { - for (let i = this.getProps().initialSelectedItemIndex!; i > -1; i--) { + for (let i = this.getProps().initialSelectedItemIndex; i > -1; i--) { this.moveDown(); } }; diff --git a/packages/react-ui/internal/MaskedInput/MaskedInput.tsx b/packages/react-ui/internal/MaskedInput/MaskedInput.tsx index d3de5ece683..870fda8be1b 100644 --- a/packages/react-ui/internal/MaskedInput/MaskedInput.tsx +++ b/packages/react-ui/internal/MaskedInput/MaskedInput.tsx @@ -5,7 +5,6 @@ import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; import { MaskCharLowLine } from '../MaskCharLowLine'; import { cx } from '../../lib/theming/Emotion'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './MaskedInput.styles'; @@ -26,15 +25,12 @@ interface MaskedInputState { focused: boolean; } -const defaultPropsInstance = { - maskChar: '_', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as MaskedInputProps); - export class MaskedInput extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'MaskedInput'; - public static defaultProps = defaultProps; + public static defaultProps: Partial = { + maskChar: '_', + }; public input: HTMLInputElement | null = null; private theme!: Theme; diff --git a/packages/react-ui/internal/Menu/Menu.tsx b/packages/react-ui/internal/Menu/Menu.tsx index aa8a59e83d4..4bae82bb952 100644 --- a/packages/react-ui/internal/Menu/Menu.tsx +++ b/packages/react-ui/internal/Menu/Menu.tsx @@ -8,7 +8,6 @@ import { ThemeContext } from '../../lib/theming/ThemeContext'; import { Theme } from '../../lib/theming/Theme'; import { cx } from '../../lib/theming/Emotion'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Menu.styles'; import { isActiveElement } from './isActiveElement'; @@ -26,19 +25,16 @@ export interface MenuState { highlightedIndex: number; } -const defaultPropsInstance = { - width: 'auto', - maxHeight: 300, - hasShadow: true, - preventWindowScroll: true, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as MenuProps); - @rootNode export class Menu extends React.Component { public static __KONTUR_REACT_UI__ = 'Menu'; - public static defaultProps = defaultProps; + public static defaultProps = { + width: 'auto', + maxHeight: 300, + hasShadow: true, + preventWindowScroll: true, + }; public state = { highlightedIndex: -1, diff --git a/packages/react-ui/internal/Popup/Popup.tsx b/packages/react-ui/internal/Popup/Popup.tsx index 9a3cc56a8d8..88504a7535f 100644 --- a/packages/react-ui/internal/Popup/Popup.tsx +++ b/packages/react-ui/internal/Popup/Popup.tsx @@ -19,7 +19,6 @@ import { CommonProps, CommonWrapper } from '../CommonWrapper'; import { cx } from '../../lib/theming/Emotion'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; import { callChildRef } from '../../lib/callChildRef/callChildRef'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { PopupPin } from './PopupPin'; import { Offset, PopupHelper, PositionObject, Rect } from './PopupHelper'; @@ -109,17 +108,6 @@ export interface PopupState { location: Nullable; } -const defaultPropsInstance = { - popupOffset: 0, - hasPin: false, - hasShadow: false, - disableAnimations: isTestEnv, - useWrapper: false, - ignoreHover: false, - width: 'auto', -}; -const defaultProps = getDefaultProps(defaultPropsInstance as PopupProps); - @rootNode export class Popup extends React.Component { public static __KONTUR_REACT_UI__ = 'Popup'; @@ -186,7 +174,15 @@ export class Popup extends React.Component { ignoreHover: PropTypes.bool, }; - public static defaultProps = defaultProps; + public static defaultProps = { + popupOffset: 0, + hasPin: false, + hasShadow: false, + disableAnimations: isTestEnv, + useWrapper: false, + ignoreHover: false, + width: 'auto', + }; public state: PopupState = { location: this.props.opened ? DUMMY_LOCATION : null }; private theme!: Theme; diff --git a/packages/react-ui/internal/PopupMenu/PopupMenu.tsx b/packages/react-ui/internal/PopupMenu/PopupMenu.tsx index 40566087b5a..1479ec654ec 100644 --- a/packages/react-ui/internal/PopupMenu/PopupMenu.tsx +++ b/packages/react-ui/internal/PopupMenu/PopupMenu.tsx @@ -13,7 +13,6 @@ import { RenderLayer } from '../RenderLayer'; import { Nullable } from '../../typings/utility-types'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { isValidPositions } from './validatePositions'; import { styles } from './PopupMenu.styles'; @@ -82,19 +81,16 @@ const Positions: PopupPositionsType[] = [ 'left bottom', ]; -const defaultPropsInstance = { - positions: Positions, - type: PopupMenuType.Tooltip, - popupHasPin: true, - disableAnimations: false, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as PopupMenuProps); - @rootNode export class PopupMenu extends React.Component { public static __KONTUR_REACT_UI__ = 'PopupMenu'; - public static defaultProps = defaultProps; + public static defaultProps = { + positions: Positions, + type: PopupMenuType.Tooltip, + popupHasPin: true, + disableAnimations: false, + }; public static Type = PopupMenuType; diff --git a/packages/react-ui/internal/RenderLayer/RenderLayer.tsx b/packages/react-ui/internal/RenderLayer/RenderLayer.tsx index ec5df3a724d..ba2ef7c0ad2 100644 --- a/packages/react-ui/internal/RenderLayer/RenderLayer.tsx +++ b/packages/react-ui/internal/RenderLayer/RenderLayer.tsx @@ -4,7 +4,6 @@ import { listen as listenFocusOutside, containsTargetOrRenderContainer } from '. import { CommonProps, CommonWrapper } from '../CommonWrapper'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; import { Nullable } from '../../typings/utility-types'; -import { getDefaultProps } from '../../lib/getDefaultProps'; export interface RenderLayerProps extends CommonProps { children: JSX.Element; @@ -14,11 +13,6 @@ export interface RenderLayerProps extends CommonProps { getAnchorElement?: () => Nullable; } -const defaultPropsInstance = { - active: true, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as RenderLayerProps); - @rootNode export class RenderLayer extends React.Component { public static __KONTUR_REACT_UI__ = 'RenderLayer'; @@ -34,7 +28,9 @@ export class RenderLayer extends React.Component { }, }; - public static defaultProps = defaultProps; + public static defaultProps = { + active: true, + }; private focusOutsideListenerToken: { remove: () => void; diff --git a/packages/react-ui/internal/ThemePlayground/VariableValue.tsx b/packages/react-ui/internal/ThemePlayground/VariableValue.tsx index dc8cf1a7238..400d6ad700f 100644 --- a/packages/react-ui/internal/ThemePlayground/VariableValue.tsx +++ b/packages/react-ui/internal/ThemePlayground/VariableValue.tsx @@ -10,7 +10,6 @@ import { Link } from '../../components/Link'; import { Hint } from '../../components/Hint'; import { isFunction } from '../../lib/utils'; import { cx } from '../../lib/theming/Emotion'; -import { getDefaultProps } from '../../lib/getDefaultProps'; import { styles } from './Playground.styles'; @@ -31,13 +30,10 @@ export interface VariableValueState { editing: boolean; } -const defaultPropsInstance = { - deprecated: false, -}; -const defaultProps = getDefaultProps(defaultPropsInstance as VariableValueProps); - export class VariableValue extends React.Component { - public static defaultProps = defaultProps; + public static defaultProps = { + deprecated: false, + }; public state = { value: this.props.value, editing: false, diff --git a/packages/react-ui/lib/getDefaultProps.ts b/packages/react-ui/lib/getDefaultProps.ts deleted file mode 100644 index fb9e6a8cc6f..00000000000 --- a/packages/react-ui/lib/getDefaultProps.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const getDefaultProps = (props: T) => { - return props as Pick; -}; From cce5be2ea6357a22d0e4e66c5ade2145bacd6ffd Mon Sep 17 00:00:00 2001 From: HelenaIsh Date: Thu, 17 Feb 2022 17:29:17 +0500 Subject: [PATCH 05/11] chore: fix default props type --- .../components/Autocomplete/Autocomplete.tsx | 82 ++++---- .../react-ui/components/Button/Button.tsx | 20 +- .../react-ui/components/Center/Center.tsx | 36 ++-- .../react-ui/components/ComboBox/ComboBox.tsx | 18 +- .../ComboBox/__tests__/ComboBox-test.tsx | 12 +- .../CurrencyInput/CurrencyInput.tsx | 62 ++++--- .../CurrencyLabel/CurrencyLabel.tsx | 2 +- .../components/DateInput/DateInput.tsx | 18 +- .../components/DatePicker/DatePicker.tsx | 14 +- .../components/DropdownMenu/DropdownMenu.tsx | 15 +- .../react-ui/components/FxInput/FxInput.tsx | 58 +++--- .../FxInput/__stories__/FxInput.stories.tsx | 5 +- .../react-ui/components/Gapped/Gapped.tsx | 14 +- packages/react-ui/components/Hint/Hint.tsx | 17 +- packages/react-ui/components/Input/Input.tsx | 172 ++++++++--------- .../components/Input/__tests__/Input-test.tsx | 1 + packages/react-ui/components/Kebab/Kebab.tsx | 17 +- packages/react-ui/components/Link/Link.tsx | 97 +++++----- .../react-ui/components/Loader/Loader.tsx | 17 +- .../Loader/__tests__/Loader-test.tsx | 18 +- packages/react-ui/components/Modal/Modal.tsx | 12 +- .../react-ui/components/Paging/Paging.tsx | 14 +- .../PasswordInput/PasswordInput.tsx | 12 +- packages/react-ui/components/Radio/Radio.tsx | 88 +++++---- .../components/RadioGroup/RadioGroup.tsx | 18 +- .../ScrollContainer/ScrollContainer.tsx | 14 +- .../react-ui/components/Select/Select.tsx | 37 ++-- .../Select/__tests__/Select-test.tsx | 4 +- .../react-ui/components/SidePage/SidePage.tsx | 14 +- .../react-ui/components/Spinner/Spinner.tsx | 12 +- .../react-ui/components/Sticky/Sticky.tsx | 12 +- packages/react-ui/components/Tabs/Tab.tsx | 15 +- packages/react-ui/components/Tabs/Tabs.tsx | 12 +- .../react-ui/components/Textarea/Textarea.tsx | 175 +++++++++--------- .../react-ui/components/Toggle/Toggle.tsx | 16 +- .../components/TokenInput/TokenInput.tsx | 26 ++- .../react-ui/components/Tooltip/Tooltip.tsx | 17 +- .../Tooltip/__stories__/Tooltip.stories.tsx | 5 +- .../components/TooltipMenu/TooltipMenu.tsx | 14 +- packages/react-ui/internal/BGRuler.tsx | 30 ++- .../react-ui/internal/Calendar/Calendar.tsx | 16 +- packages/react-ui/internal/Calendar/Month.tsx | 12 +- .../react-ui/internal/ComponentCombinator.tsx | 19 +- packages/react-ui/internal/ComponentTable.tsx | 13 +- .../internal/CustomComboBox/ComboBoxMenu.tsx | 13 +- .../internal/CustomComboBox/ComboBoxView.tsx | 20 +- .../internal/DateSelect/DateSelect.tsx | 15 +- .../DropdownContainer/DropdownContainer.tsx | 22 ++- .../internal/InternalMenu/InternalMenu.tsx | 21 ++- .../internal/MaskedInput/MaskedInput.tsx | 12 +- packages/react-ui/internal/Menu/Menu.tsx | 16 +- packages/react-ui/internal/Popup/Popup.tsx | 18 +- .../react-ui/internal/PopupMenu/PopupMenu.tsx | 17 +- .../internal/RenderLayer/RenderLayer.tsx | 12 +- .../ThemePlayground/VariableValue.tsx | 12 +- packages/react-ui/internal/ZIndex/ZIndex.tsx | 19 +- packages/react-ui/lib/createPropsGetter.ts | 7 - 57 files changed, 950 insertions(+), 556 deletions(-) delete mode 100644 packages/react-ui/lib/createPropsGetter.ts diff --git a/packages/react-ui/components/Autocomplete/Autocomplete.tsx b/packages/react-ui/components/Autocomplete/Autocomplete.tsx index 0f7d9923970..2cb939bd33b 100644 --- a/packages/react-ui/components/Autocomplete/Autocomplete.tsx +++ b/packages/react-ui/components/Autocomplete/Autocomplete.tsx @@ -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'; @@ -29,37 +28,37 @@ function renderItem(item: any) { return item; } -export interface AutocompleteProps - extends CommonProps, - Override< - InputProps, - { - /** Функция отрисовки элемента меню */ - renderItem: (item: string) => React.ReactNode; - /** Промис, резолвящий элементы меню */ - source?: string[] | ((patter: string) => Promise); - /** Отключает использование портала */ - 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; - } - > {} +export type AutocompleteProps = Override< + InputProps, + { + /** Функция отрисовки элемента меню */ + renderItem: (item: string) => React.ReactNode; + /** Промис, резолвящий элементы меню */ + source?: string[] | ((patter: string) => Promise); + /** Отключает использование портала */ + 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; + } +> & + CommonProps & + Partial; export interface AutocompleteState { items: Nullable; @@ -67,13 +66,25 @@ export interface AutocompleteState { focused: boolean; } +interface DefaultProps { + renderItem: (item: string) => React.ReactNode; + size: InputProps['size']; + disablePortal: boolean; + hasShadow: boolean; + menuMaxHeight: number; + menuAlign: 'left' | 'right'; + preventWindowScroll: boolean; +} + +type AutocompleteComponentProps = AutocompleteProps & DefaultProps; + /** * Стандартный инпут с подсказками. * * Все свойства передаются во внутренний *Input*. */ @rootNode -export class Autocomplete extends React.Component { +export class Autocomplete extends React.Component { public static __KONTUR_REACT_UI__ = 'Autocomplete'; public static propTypes = { @@ -99,7 +110,7 @@ export class Autocomplete extends React.Component { return ( - {this.getProps().renderItem(item)} + {this.props.renderItem(item)} ); })} diff --git a/packages/react-ui/components/Button/Button.tsx b/packages/react-ui/components/Button/Button.tsx index 61671782845..90a2972286b 100644 --- a/packages/react-ui/components/Button/Button.tsx +++ b/packages/react-ui/components/Button/Button.tsx @@ -17,7 +17,7 @@ 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 { +export interface ButtonProps extends CommonProps, Partial { /** @ignore */ _noPadding?: boolean; @@ -164,8 +164,16 @@ export interface ButtonState { focusedByTab: boolean; } +interface DefaultProps { + use: ButtonUse; + size: ButtonSize; + type: ButtonType; +} + +type ButtonComponentProps = ButtonProps & DefaultProps; + @rootNode -export class Button extends React.Component { +export class Button extends React.Component { public static __KONTUR_REACT_UI__ = 'Button'; public static __BUTTON__ = true; public static TOP_LEFT = Corners.TOP_LEFT; @@ -173,10 +181,10 @@ export class Button extends React.Component { 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 = { diff --git a/packages/react-ui/components/Center/Center.tsx b/packages/react-ui/components/Center/Center.tsx index 71a1b944106..f52cd77264b 100644 --- a/packages/react-ui/components/Center/Center.tsx +++ b/packages/react-ui/components/Center/Center.tsx @@ -9,28 +9,34 @@ import { styles } from './Center.styles'; export type HorizontalAlign = 'left' | 'center' | 'right'; -export interface CenterProps - extends CommonProps, - Override< - React.HTMLAttributes, - { - /** - * Определяет, как контент будет выровнен по горизонтали. - * - * **Допустимые значения**: `"left"`, `"center"`, `"right"`. - */ - align?: HorizontalAlign; - } - > {} +export type CenterProps = Override< + React.HTMLAttributes, + { + /** + * Определяет, как контент будет выровнен по горизонтали. + * + * **Допустимые значения**: `"left"`, `"center"`, `"right"`. + */ + align?: HorizontalAlign; + } +> & + CommonProps & + Partial; + +interface DefaultProps { + align: HorizontalAlign; +} + +type CenterComponentProps = CenterProps & DefaultProps; /** * Контейнер, который центрирует элементы внутри себя. */ @rootNode -export class Center extends React.Component { +export class Center extends React.Component { public static __KONTUR_REACT_UI__ = 'Center'; - public static defaultProps = { + public static defaultProps: DefaultProps = { align: 'center', }; private setRootNode!: TSetRootNode; diff --git a/packages/react-ui/components/ComboBox/ComboBox.tsx b/packages/react-ui/components/ComboBox/ComboBox.tsx index 8ffc1dd8e40..1181759147b 100644 --- a/packages/react-ui/components/ComboBox/ComboBox.tsx +++ b/packages/react-ui/components/ComboBox/ComboBox.tsx @@ -7,7 +7,7 @@ import { InputIconType } from '../Input'; import { CommonProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -export interface ComboBoxProps extends CommonProps { +export interface ComboBoxProps extends CommonProps, Partial> { align?: 'left' | 'center' | 'right'; /** * Вызывает функцию поиска `getItems` при фокусе и очистке поля ввода @@ -166,11 +166,23 @@ export interface ComboBoxItem { label: string; } +interface DefaultProps { + itemToValue: (item: T) => string | number; + valueToString: (item: T) => string; + renderValue: (item: T) => React.ReactNode; + renderItem: (item: T, state?: MenuItemState) => React.ReactNode; + menuAlign: 'left' | 'right'; + searchOnFocus: boolean; + drawArrow: boolean; +} + +export type ComboBoxComponentProps = ComboBoxProps & DefaultProps; + @rootNode -export class ComboBox extends React.Component> { +export class ComboBox extends React.Component> { public static __KONTUR_REACT_UI__ = 'ComboBox'; - public static defaultProps = { + public static defaultProps: DefaultProps = { itemToValue: (item: ComboBoxItem) => item.value, valueToString: (item: ComboBoxItem) => item.label, renderValue: (item: ComboBoxItem) => item.label, diff --git a/packages/react-ui/components/ComboBox/__tests__/ComboBox-test.tsx b/packages/react-ui/components/ComboBox/__tests__/ComboBox-test.tsx index 8fe8a22fd8d..163fc19a3f5 100644 --- a/packages/react-ui/components/ComboBox/__tests__/ComboBox-test.tsx +++ b/packages/react-ui/components/ComboBox/__tests__/ComboBox-test.tsx @@ -4,7 +4,7 @@ import { mount, ReactWrapper } from 'enzyme'; import { CustomComboBoxLocaleHelper } from '../../../internal/CustomComboBox/locale'; import { LangCodes, LocaleContext } from '../../../lib/locale'; import { defaultLangCode } from '../../../lib/locale/constants'; -import { ComboBox, ComboBoxProps } from '../ComboBox'; +import { ComboBox, ComboBoxComponentProps } from '../ComboBox'; import { InputLikeText } from '../../../internal/InputLikeText'; import { MenuItem } from '../../MenuItem'; import { Menu } from '../../../internal/Menu'; @@ -411,7 +411,7 @@ describe('ComboBox', () => { { value: 1, label: 'one' }, { value: 2, label: 'two' }, ]; - const check = async (wrapper: ReactWrapper, {}, ComboBox>) => { + const check = async (wrapper: ReactWrapper, {}, ComboBox>) => { wrapper.find(ComboBoxView).prop('onFocus')?.(); wrapper.update(); expect(wrapper.find('input').prop('value')).toBe(VALUES[0].label); @@ -546,7 +546,7 @@ describe('ComboBox', () => { }); describe('open/close methods', () => { - let wrapper: ReactWrapper, {}, ComboBox>; + let wrapper: ReactWrapper, {}, ComboBox>; beforeEach(() => { wrapper = mount>( Promise.resolve([])} />); @@ -575,7 +575,7 @@ describe('ComboBox', () => { const VALUE = { value: 1, label: 'one' }; let getItems: jest.Mock>>; let promise: Promise; - let wrapper: ReactWrapper, {}, ComboBox>; + let wrapper: ReactWrapper, {}, ComboBox>; beforeEach(() => { [getItems, promise] = searchFactory(Promise.resolve([VALUE])); @@ -607,7 +607,7 @@ describe('ComboBox', () => { const ITEMS = ['one', 'two', 'three']; let search: jest.Mock>; let promise: Promise; - let wrapper: ReactWrapper, {}, ComboBox>; + let wrapper: ReactWrapper, {}, ComboBox>; const onFocus = jest.fn(); const onBlur = jest.fn(); @@ -662,7 +662,7 @@ describe('ComboBox', () => { describe('click on input', () => { const VALUE = { value: 1, label: 'one' }; - type TComboBoxWrapper = ReactWrapper, {}, ComboBox>; + type TComboBoxWrapper = ReactWrapper, {}, ComboBox>; const clickOnInput = (comboboxWrapper: TComboBoxWrapper) => { comboboxWrapper.update(); comboboxWrapper.find('input').simulate('click'); diff --git a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx index 99b21056745..0095fbdf3f8 100644 --- a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx +++ b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx @@ -15,30 +15,30 @@ import { CurrencyHelper } from './CurrencyHelper'; import { CurrencyInputHelper } from './CurrencyInputHelper'; import { CURRENCY_INPUT_ACTIONS, extractAction } from './CurrencyInputKeyboardActions'; -export interface CurrencyInputProps - extends CommonProps, - Override< - InputProps, - { - /** Значение */ - value: Nullable; - /** Убрать лишние нули после запятой */ - hideTrailingZeros: boolean; - /** Кол-во цифр после зяпятой */ - fractionDigits?: Nullable; - /** Отрицательные значения */ - signed?: boolean; - /** - * Допустимое кол-во цифр целой части. - * Если передан **0**, или `fractionDigits=15`, то и в целой части допускается только **0**. - */ - integerDigits?: Nullable; - /** Вызывается при изменении `value` */ - onValueChange: (value: Nullable) => void; - /** onSubmit */ - onSubmit?: () => void; - } - > {} +export type CurrencyInputProps = Override< + InputProps, + { + /** Значение */ + value: Nullable; + /** Убрать лишние нули после запятой */ + hideTrailingZeros: boolean; + /** Кол-во цифр после зяпятой */ + fractionDigits?: Nullable; + /** Отрицательные значения */ + signed?: boolean; + /** + * Допустимое кол-во цифр целой части. + * Если передан **0**, или `fractionDigits=15`, то и в целой части допускается только **0**. + */ + integerDigits?: Nullable; + /** Вызывается при изменении `value` */ + onValueChange: (value: Nullable) => void; + /** onSubmit */ + onSubmit?: () => void; + } +> & + CommonProps & + Partial; export interface CurrencyInputState { formatted: string; @@ -46,6 +46,15 @@ export interface CurrencyInputState { focused: boolean; } +interface DefaultProps { + align: InputProps['align']; + fractionDigits: Nullable; + hideTrailingZeros: boolean; + value: Nullable; +} + +type CurrencyInputComponentProps = CurrencyInputProps & DefaultProps; + /** * Поле для денежных сумм (и других числовых значений). * Принимает любые свойства `Input`. @@ -55,7 +64,7 @@ export interface CurrencyInputState { * Если `fractionDigits=15`, то в целой части допускается **0**. */ @rootNode -export class CurrencyInput extends React.PureComponent { +export class CurrencyInput extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'CurrencyInput'; public static propTypes = { @@ -82,12 +91,11 @@ export class CurrencyInput extends React.PureComponent = { fractionDigits: 2, }; diff --git a/packages/react-ui/components/DateInput/DateInput.tsx b/packages/react-ui/components/DateInput/DateInput.tsx index d26d11a5045..0a43d5424f4 100644 --- a/packages/react-ui/components/DateInput/DateInput.tsx +++ b/packages/react-ui/components/DateInput/DateInput.tsx @@ -26,7 +26,7 @@ export interface DateInputState { dragged: boolean; } -export interface DateInputProps extends CommonProps { +export interface DateInputProps extends CommonProps, Partial { autoFocus?: boolean; value: string; /** @@ -71,12 +71,22 @@ export interface DateInputProps extends CommonProps { onKeyDown?: (x0: React.KeyboardEvent) => void; } +interface DefaultProps { + value: string; + minDate: string; + maxDate: string; + size: 'small' | 'large' | 'medium'; + width: string | number; +} + +type DateInputComponentProps = DateInputProps & DefaultProps; + @rootNode @locale('DatePicker', DatePickerLocaleHelper) -export class DateInput extends React.Component { +export class DateInput extends React.Component { public static __KONTUR_REACT_UI__ = 'DateInput'; - public static defaultProps = { + public static defaultProps: DefaultProps = { value: '', minDate: MIN_FULLDATE, maxDate: MAX_FULLDATE, @@ -109,7 +119,7 @@ export class DateInput extends React.Component { .add(Actions.WrongInput, () => this.blink()) .build(); - constructor(props: DateInputProps) { + constructor(props: DateInputComponentProps) { super(props); this.state = { diff --git a/packages/react-ui/components/DatePicker/DatePicker.tsx b/packages/react-ui/components/DatePicker/DatePicker.tsx index 8bc77bb5a2b..5a8c0fb32b5 100644 --- a/packages/react-ui/components/DatePicker/DatePicker.tsx +++ b/packages/react-ui/components/DatePicker/DatePicker.tsx @@ -30,7 +30,7 @@ const INPUT_PASS_PROPS = { export const MIN_WIDTH = 120; -export interface DatePickerProps extends CommonProps { +export interface DatePickerProps extends CommonProps, Partial> { autoFocus?: boolean; disabled?: boolean; enableTodayLink?: boolean; @@ -83,10 +83,18 @@ export interface DatePickerState { canUseMobileNativeDatePicker: boolean; } +interface DefaultProps { + minDate: T; + maxDate: T; + isHoliday: (day: T, isWeekend: boolean) => boolean; +} + +type DatePickerComponentProps = DatePickerProps & DefaultProps; + type DatePickerValue = string; @rootNode -export class DatePicker extends React.PureComponent, DatePickerState> { +export class DatePicker extends React.PureComponent, DatePickerState> { public static __KONTUR_REACT_UI__ = 'DatePicker'; public static propTypes = { @@ -139,7 +147,7 @@ export class DatePicker extends React.PureComponent = { minDate: MIN_FULLDATE, maxDate: MAX_FULLDATE, isHoliday: (_day: DatePickerValue, isWeekend: boolean) => isWeekend, diff --git a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx index 5396d8f2bc0..a4e20f433bb 100644 --- a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx +++ b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx @@ -9,7 +9,7 @@ import { PopupPositionsType } from '../../internal/Popup'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -export interface DropdownMenuProps extends CommonProps { +export interface DropdownMenuProps extends CommonProps, Partial { /** Максимальная высота меню */ menuMaxHeight?: React.CSSProperties['maxWidth']; /** Ширина меню */ @@ -56,14 +56,21 @@ export interface DropdownMenuProps extends CommonProps { disableAnimations: boolean; } +interface DefaultProps { + disableAnimations: boolean; + positions: PopupPositionsType[]; +} + +type DropdownMenuComponentProps = DropdownMenuProps & DefaultProps; + /** * Меню, раскрывающееся по клику на переданный в `caption` элемент */ @rootNode -export class DropdownMenu extends React.Component { +export class DropdownMenu extends React.Component { public static __KONTUR_REACT_UI__ = 'DropdownMenu'; - public static defaultProps = { + public static defaultProps: DefaultProps = { disableAnimations: isTestEnv, positions: ['bottom left', 'bottom right', 'top left', 'top right'], }; @@ -71,7 +78,7 @@ export class DropdownMenu extends React.Component { private popupMenu: Nullable = null; private setRootNode!: TSetRootNode; - constructor(props: DropdownMenuProps) { + constructor(props: DropdownMenuComponentProps) { super(props); if (!props.caption && !isProductionEnv) { diff --git a/packages/react-ui/components/FxInput/FxInput.tsx b/packages/react-ui/components/FxInput/FxInput.tsx index b7fa770025a..50b9f43aff9 100644 --- a/packages/react-ui/components/FxInput/FxInput.tsx +++ b/packages/react-ui/components/FxInput/FxInput.tsx @@ -5,37 +5,44 @@ import { Button } from '../Button'; import { Group } from '../Group'; import { Input, InputProps, InputType } from '../Input'; import { CurrencyInput, CurrencyInputProps } from '../CurrencyInput'; -import { createPropsGetter } from '../../lib/createPropsGetter'; import { Override } from '../../typings/utility-types'; import { FunctionIcon, UndoIcon } from '../../internal/icons/16px'; import { CommonWrapper, CommonProps, CommonWrapperRestProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -export interface FxInputProps - extends CommonProps, - Override< - CurrencyInputProps, - { - /** Авто-режим */ - auto?: boolean; - /** Тип инпута */ - type?: 'currency' | InputProps['type']; - /** onRestore */ - onRestore?: () => void; - /** onValueChange */ - onValueChange: CurrencyInputProps['onValueChange'] | InputProps['onValueChange']; - /** Значение */ - value?: React.ReactText; - /** ref Input'а */ - refInput?: (element: CurrencyInput | Input | null) => void; - /** Убрать лишние нули после запятой */ - hideTrailingZeros?: boolean; - } - > {} +export type FxInputProps = Override< + CurrencyInputProps, + { + /** Авто-режим */ + auto?: boolean; + /** Тип инпута */ + type?: 'currency' | InputProps['type']; + /** onRestore */ + onRestore?: () => void; + /** onValueChange */ + onValueChange: CurrencyInputProps['onValueChange'] | InputProps['onValueChange']; + /** Значение */ + value?: React.ReactText; + /** ref Input'а */ + refInput?: (element: CurrencyInput | Input | null) => void; + /** Убрать лишние нули после запятой */ + hideTrailingZeros?: boolean; + } +> & + CommonProps & + Partial; + +interface DefaultProps { + width: number | string; + type: 'currency' | InputProps['type']; + value: React.ReactText; +} + +type FxInputComponentProps = FxInputProps & DefaultProps; /** Принимает все свойства `Input`'a */ @rootNode -export class FxInput extends React.Component { +export class FxInput extends React.Component { public static __KONTUR_REACT_UI__ = 'FxInput'; public static propTypes = { @@ -43,7 +50,7 @@ export class FxInput extends React.Component { type: PropTypes.string, }; - public static defaultProps = { + public static defaultProps: DefaultProps = { width: 250, type: 'text', value: '', @@ -51,7 +58,6 @@ export class FxInput extends React.Component { private input: Input | CurrencyInput | null = null; - private getProps = createPropsGetter(FxInput.defaultProps); private setRootNode!: TSetRootNode; public render() { @@ -89,7 +95,7 @@ export class FxInput extends React.Component { return ( {button} - {this.getProps().type === 'currency' ? ( + {this.props.type === 'currency' ? ( { type: 'text', }; - private getProps = createPropsGetter(TestFxInput.defaultProps); - constructor(props: TestFxInputProps) { super(props); @@ -92,7 +89,7 @@ class TestFxInput extends React.Component { { /** * Расстояние между элементами в пикселях * @default 8 @@ -31,11 +31,19 @@ export interface GappedProps extends CommonProps { children: React.ReactNode; } +interface DefaultProps { + wrap: boolean; + vertical: boolean; + verticalAlign: 'top' | 'middle' | 'baseline' | 'bottom'; +} + +type GappedComponentProps = GappedProps & DefaultProps; + /** * Контейнер, расстояние между элементами в котором равно `gap`. */ @rootNode -export class Gapped extends React.Component { +export class Gapped extends React.Component { public static __KONTUR_REACT_UI__ = 'Gapped'; public static propTypes = { @@ -58,7 +66,7 @@ export class Gapped extends React.Component { private theme!: Theme; private setRootNode!: TSetRootNode; - public static defaultProps = { + public static defaultProps: DefaultProps = { wrap: false, vertical: false, verticalAlign: 'baseline', diff --git a/packages/react-ui/components/Hint/Hint.tsx b/packages/react-ui/components/Hint/Hint.tsx index 868adfdccf6..04fb9461afe 100644 --- a/packages/react-ui/components/Hint/Hint.tsx +++ b/packages/react-ui/components/Hint/Hint.tsx @@ -15,7 +15,7 @@ import { styles } from './Hint.styles'; const HINT_BORDER_COLOR = 'transparent'; -export interface HintProps extends CommonProps { +export interface HintProps extends CommonProps, Partial { children?: React.ReactNode; /** * Переводит отображение подсказки в _"ручной режим"_. @@ -67,6 +67,17 @@ export interface HintState { opened: boolean; } +interface DefaultProps { + pos: 'top' | 'right' | 'bottom' | 'left' | PopupPositionsType; + manual: boolean; + opened: boolean; + maxWidth: React.CSSProperties['maxWidth']; + disableAnimations: boolean; + useWrapper: boolean; +} + +type HintComponentProps = HintProps & DefaultProps; + const Positions: PopupPositionsType[] = [ 'top center', 'top left', @@ -86,10 +97,10 @@ const Positions: PopupPositionsType[] = [ * Всплывающая подсказка, которая по умолчанию отображается при наведении на элемент.
Можно задать другие условия отображения. */ @rootNode -export class Hint extends React.PureComponent { +export class Hint extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'Hint'; - public static defaultProps = { + public static defaultProps: DefaultProps = { pos: 'top', manual: false, opened: false, diff --git a/packages/react-ui/components/Input/Input.tsx b/packages/react-ui/components/Input/Input.tsx index 9a2efea4529..f4b0ee8342e 100644 --- a/packages/react-ui/components/Input/Input.tsx +++ b/packages/react-ui/components/Input/Input.tsx @@ -20,86 +20,86 @@ export type InputAlign = 'left' | 'center' | 'right'; export type InputType = 'password' | 'text'; export type InputIconType = React.ReactNode | (() => React.ReactNode); -export interface InputProps - extends CommonProps, - Override< - React.InputHTMLAttributes, - { - /** - * Иконка слева - * Если `ReactNode` применяются дефолтные стили для иконки - * Если `() => ReactNode` применяются только стили для позиционирование - */ - leftIcon?: InputIconType; - /** - * Иконка справа - * Если `ReactNode` применяются дефолтные стили для иконки - * Если `() => ReactNode` применяются только стили для позиционирование - */ - rightIcon?: InputIconType; - /** - * Cостояние валидации при ошибке. - */ - error?: boolean; - /** - * Cостояние валидации при предупреждении. - */ - warning?: boolean; - /** Режим прозрачной рамки */ - borderless?: boolean; - /** Выравнивание текста */ - align?: InputAlign; - /** Паттерн маски */ - mask?: Nullable; - /** Символ маски */ - maskChar?: Nullable; - /** - * Словарь символов-регулярок для задания маски - * @default { '9': '[0-9]', 'a': '[A-Za-z]', '*': '[A-Za-z0-9]' } - */ - formatChars?: Record; - /** Показывать символы маски */ - alwaysShowMask?: boolean; - /** Размер */ - size?: InputSize; - /** onValueChange */ - onValueChange?: (value: string) => void; - /** Вызывается на label */ - onMouseEnter?: React.MouseEventHandler; - /** Вызывается на label */ - onMouseLeave?: React.MouseEventHandler; - /** Вызывается на label */ - onMouseOver?: React.MouseEventHandler; - /** Тип */ - type?: InputType; - /** Значение */ - value?: string; - capture?: boolean; - - /** - * Префикс - * `ReactNode` перед значением, но после иконки - */ - prefix?: React.ReactNode; - /** - * Суффикс - * `ReactNode` после значения, но перед правой иконкой - */ - suffix?: React.ReactNode; - /** Выделять введенное значение при фокусе */ - selectAllOnFocus?: boolean; - /** - * Обработчик неправильного ввода. - * По-умолчанию, инпут вспыхивает синим. - * Если передан - вызывается переданный обработчик, - * в таком случае вспыхивание можно вызвать - * публичным методом инстанса `blink()`. - * - * @param value значение инпута. - */ - onUnexpectedInput?: (value: string) => void; - } - > {} +export type InputProps = Override< + React.InputHTMLAttributes, + { + /** + * Иконка слева + * Если `ReactNode` применяются дефолтные стили для иконки + * Если `() => ReactNode` применяются только стили для позиционирование + */ + leftIcon?: InputIconType; + /** + * Иконка справа + * Если `ReactNode` применяются дефолтные стили для иконки + * Если `() => ReactNode` применяются только стили для позиционирование + */ + rightIcon?: InputIconType; + /** + * Cостояние валидации при ошибке. + */ + error?: boolean; + /** + * Cостояние валидации при предупреждении. + */ + warning?: boolean; + /** Режим прозрачной рамки */ + borderless?: boolean; + /** Выравнивание текста */ + align?: InputAlign; + /** Паттерн маски */ + mask?: Nullable; + /** Символ маски */ + maskChar?: Nullable; + /** + * Словарь символов-регулярок для задания маски + * @default { '9': '[0-9]', 'a': '[A-Za-z]', '*': '[A-Za-z0-9]' } + */ + formatChars?: Record; + /** Показывать символы маски */ + alwaysShowMask?: boolean; + /** Размер */ + size?: InputSize; + /** onValueChange */ + onValueChange?: (value: string) => void; + /** Вызывается на label */ + onMouseEnter?: React.MouseEventHandler; + /** Вызывается на label */ + onMouseLeave?: React.MouseEventHandler; + /** Вызывается на label */ + onMouseOver?: React.MouseEventHandler; + /** Тип */ + type?: InputType; + /** Значение */ + value?: string; + capture?: boolean; + + /** + * Префикс + * `ReactNode` перед значением, но после иконки + */ + prefix?: React.ReactNode; + /** + * Суффикс + * `ReactNode` после значения, но перед правой иконкой + */ + suffix?: React.ReactNode; + /** Выделять введенное значение при фокусе */ + selectAllOnFocus?: boolean; + /** + * Обработчик неправильного ввода. + * По-умолчанию, инпут вспыхивает синим. + * Если передан - вызывается переданный обработчик, + * в таком случае вспыхивание можно вызвать + * публичным методом инстанса `blink()`. + * + * @param value значение инпута. + */ + onUnexpectedInput?: (value: string) => void; + } +> & + CommonProps & + Partial; export interface InputState { blinking: boolean; @@ -107,17 +107,21 @@ export interface InputState { polyfillPlaceholder: boolean; } +interface DefaultProps { + size: InputSize; +} + +type InputComponentProps = InputProps & DefaultProps; + /** * Интерфес пропсов наследуется от `React.InputHTMLAttributes`. * Все пропсы кроме перечисленных, `className` и `style` передаются в `` */ @rootNode -export class Input extends React.Component { +export class Input extends React.Component { public static __KONTUR_REACT_UI__ = 'Input'; - public static defaultProps: { - size: InputSize; - } = { + public static defaultProps: DefaultProps = { size: 'small', }; diff --git a/packages/react-ui/components/Input/__tests__/Input-test.tsx b/packages/react-ui/components/Input/__tests__/Input-test.tsx index b6e6450768e..8847abdb0c1 100644 --- a/packages/react-ui/components/Input/__tests__/Input-test.tsx +++ b/packages/react-ui/components/Input/__tests__/Input-test.tsx @@ -4,6 +4,7 @@ import MaskedInput from 'react-input-mask'; import { Input, InputProps } from '../Input'; +// @ts-ignore const render = (props: InputProps) => mount(React.createElement(Input, props)); describe('', () => { diff --git a/packages/react-ui/components/Kebab/Kebab.tsx b/packages/react-ui/components/Kebab/Kebab.tsx index 5679f3f2938..ab85f08a092 100644 --- a/packages/react-ui/components/Kebab/Kebab.tsx +++ b/packages/react-ui/components/Kebab/Kebab.tsx @@ -18,7 +18,7 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { styles } from './Kebab.styles'; -export interface KebabProps extends CommonProps { +export interface KebabProps extends CommonProps, Partial { disabled?: boolean; /** * Функция вызываемая при закрытии выпадашки @@ -57,13 +57,24 @@ export interface KebabState { opened: boolean; } +interface DefaultProps { + onOpen: () => void; + onClose: () => void; + positions: PopupPositionsType[]; + size: 'small' | 'medium' | 'large'; + disableAnimations: boolean; + icon: React.ReactNode; +} + +type KebabComponentProps = KebabProps & DefaultProps; + @rootNode -export class Kebab extends React.Component { +export class Kebab extends React.Component { public static __KONTUR_REACT_UI__ = 'Kebab'; public static propTypes = {}; - public static defaultProps = { + public static defaultProps: DefaultProps = { onOpen: () => undefined, onClose: () => undefined, positions: ['bottom left', 'bottom right', 'top left', 'top right'], diff --git a/packages/react-ui/components/Link/Link.tsx b/packages/react-ui/components/Link/Link.tsx index b2dc20d5126..ebd68eed91e 100644 --- a/packages/react-ui/components/Link/Link.tsx +++ b/packages/react-ui/components/Link/Link.tsx @@ -13,59 +13,66 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode/rootNodeDecorator'; import { styles } from './Link.styles'; -export interface LinkProps - extends CommonProps, - Override< - React.AnchorHTMLAttributes, - { - /** - * Отключенное состояние. - */ - disabled?: boolean; - /** - * HTML-атрибут `href`. - */ - href?: string; - /** - * Добавляет ссылке иконку. - */ - icon?: React.ReactElement; - /** - * Тема ссылки. - */ - use?: 'default' | 'success' | 'danger' | 'grayed'; - /** - * @ignore - */ - _button?: boolean; - /** - * @ignore - */ - _buttonOpened?: boolean; - /** - * HTML-атрибут `tabindex`. - */ - tabIndex?: number; - /** - * Переводит ссылку в состояние загрузки. - */ - loading?: boolean; - /** - * HTML-событие `onclick`. - */ - onClick?: (event: React.MouseEvent) => void; - } - > {} +export type LinkProps = Override< + React.AnchorHTMLAttributes, + { + /** + * Отключенное состояние. + */ + disabled?: boolean; + /** + * HTML-атрибут `href`. + */ + href?: string; + /** + * Добавляет ссылке иконку. + */ + icon?: React.ReactElement; + /** + * Тема ссылки. + */ + use?: 'default' | 'success' | 'danger' | 'grayed'; + /** + * @ignore + */ + _button?: boolean; + /** + * @ignore + */ + _buttonOpened?: boolean; + /** + * HTML-атрибут `tabindex`. + */ + tabIndex?: number; + /** + * Переводит ссылку в состояние загрузки. + */ + loading?: boolean; + /** + * HTML-событие `onclick`. + */ + onClick?: (event: React.MouseEvent) => void; + } +> & + CommonProps & + Partial; export interface LinkState { focusedByTab: boolean; } +interface DefaultProps { + href: string; + use: 'default' | 'success' | 'danger' | 'grayed'; +} + +type LinkComponentProps = LinkProps & DefaultProps; + /** * Элемент ссылки из HTML. */ @rootNode -export class Link extends React.Component { +export class Link extends React.Component { public static __KONTUR_REACT_UI__ = 'Link'; public static propTypes = { @@ -78,7 +85,7 @@ export class Link extends React.Component { use: PropTypes.oneOf(['default', 'success', 'danger', 'grayed']), }; - public static defaultProps = { + public static defaultProps: DefaultProps = { href: '', use: 'default', }; diff --git a/packages/react-ui/components/Loader/Loader.tsx b/packages/react-ui/components/Loader/Loader.tsx index 3508eaa51cf..a29537298f0 100644 --- a/packages/react-ui/components/Loader/Loader.tsx +++ b/packages/react-ui/components/Loader/Loader.tsx @@ -17,7 +17,7 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { styles } from './Loader.styles'; -export interface LoaderProps extends CommonProps { +export interface LoaderProps extends CommonProps, Partial { children?: React.ReactNode; /** * Флаг переключения состояния лоадера @@ -50,14 +50,23 @@ export interface LoaderState { spinnerStyle?: object; } +interface DefaultProps { + type: 'mini' | 'normal' | 'big'; + active: boolean; + delayBeforeSpinnerShow: number; + minimalDelayBeforeSpinnerHide: number; +} + +export type LoaderComponentProps = LoaderProps & DefaultProps; + /** * DRAFT - лоадер-контейнер */ @rootNode -export class Loader extends React.Component { +export class Loader extends React.Component { public static __KONTUR_REACT_UI__ = 'Loader'; - public static defaultProps: Partial = { + public static defaultProps: DefaultProps = { type: Spinner.Types.normal, active: false, delayBeforeSpinnerShow: isTestEnv ? 0 : 300, @@ -113,7 +122,7 @@ export class Loader extends React.Component { private spinnerTask: TaskWithDelayAndMinimalDuration; private childrenObserver: Nullable; - constructor(props: LoaderProps) { + constructor(props: LoaderComponentProps) { super(props); this.spinnerContainerNode = null; diff --git a/packages/react-ui/components/Loader/__tests__/Loader-test.tsx b/packages/react-ui/components/Loader/__tests__/Loader-test.tsx index cc940804e32..50596df0013 100644 --- a/packages/react-ui/components/Loader/__tests__/Loader-test.tsx +++ b/packages/react-ui/components/Loader/__tests__/Loader-test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { mount, ReactWrapper } from 'enzyme'; -import { Loader, LoaderProps, LoaderState } from '../Loader'; +import { Loader, LoaderComponentProps, LoaderState } from '../Loader'; import { delay } from '../../../lib/utils'; const DELAY_BEFORE_SPINNER_SHOW = 1000; @@ -12,18 +12,22 @@ const SpinnerSelector = `[data-tid='Loader__Spinner']`; const expectComponentLengthInWrapper = ( component: string, - wrapper: ReactWrapper, + wrapper: ReactWrapper, length: number, ) => expect(wrapper.find(component)).toHaveLength(length); -const expectComponentExistInWrapper = (component: string, wrapper: ReactWrapper) => - expectComponentLengthInWrapper(component, wrapper, 1); +const expectComponentExistInWrapper = ( + component: string, + wrapper: ReactWrapper, +) => expectComponentLengthInWrapper(component, wrapper, 1); -const expectComponentNotExistInWrapper = (component: string, wrapper: ReactWrapper) => - expectComponentLengthInWrapper(component, wrapper, 0); +const expectComponentNotExistInWrapper = ( + component: string, + wrapper: ReactWrapper, +) => expectComponentLengthInWrapper(component, wrapper, 0); describe('Loader', () => { - let loader: ReactWrapper; + let loader: ReactWrapper; describe('with immutable active=false', () => { beforeEach(() => { diff --git a/packages/react-ui/components/Modal/Modal.tsx b/packages/react-ui/components/Modal/Modal.tsx index 6f4d75094e9..cb501ba5ccd 100644 --- a/packages/react-ui/components/Modal/Modal.tsx +++ b/packages/react-ui/components/Modal/Modal.tsx @@ -24,7 +24,7 @@ import { styles } from './Modal.styles'; let mountedModalsCount = 0; -export interface ModalProps extends CommonProps { +export interface ModalProps extends CommonProps, Partial { /** * Отключает событие onClose, также дизейблит кнопку закрытия модалки */ @@ -68,6 +68,12 @@ export interface ModalState { hasPanel: boolean; } +interface DefaultProps { + disableFocusLock: boolean; +} + +type ModalComponentProps = ModalProps & DefaultProps; + /** * Модальное окно * @@ -82,14 +88,14 @@ export interface ModalState { * проп **sticky** со значением **false** * (по-умолчанию прилипание включено) */ -export class Modal extends React.Component { +export class Modal extends React.Component { public static __KONTUR_REACT_UI__ = 'Modal'; public static Header = ModalHeader; public static Body = ModalBody; public static Footer = ModalFooter; - public static defaultProps = { + public static defaultProps: DefaultProps = { // NOTE: в ie нормально не работает disableFocusLock: isIE11, }; diff --git a/packages/react-ui/components/Paging/Paging.tsx b/packages/react-ui/components/Paging/Paging.tsx index bc590321b18..dc058b76e1e 100644 --- a/packages/react-ui/components/Paging/Paging.tsx +++ b/packages/react-ui/components/Paging/Paging.tsx @@ -30,7 +30,7 @@ interface ItemComponentProps { tabIndex: number; } -export interface PagingProps extends CommonProps { +export interface PagingProps extends CommonProps, Partial { activePage: number; /** * Компонент обертки по умолчанию @@ -64,12 +64,20 @@ export interface PagingState { export type ItemType = number | '.' | 'forward'; +interface DefaultProps { + component: React.ComponentType; + useGlobalListener: boolean; + ['data-tid']: string; +} + +type PagingComponentProps = PagingProps & DefaultProps; + @rootNode @locale('Paging', PagingLocaleHelper) -export class Paging extends React.PureComponent { +export class Paging extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'Paging'; - public static defaultProps = { + public static defaultProps: DefaultProps = { component: ({ className, onClick, children }: any) => ( {children} diff --git a/packages/react-ui/components/PasswordInput/PasswordInput.tsx b/packages/react-ui/components/PasswordInput/PasswordInput.tsx index 2d8e9b946f8..035d61c952c 100644 --- a/packages/react-ui/components/PasswordInput/PasswordInput.tsx +++ b/packages/react-ui/components/PasswordInput/PasswordInput.tsx @@ -15,7 +15,7 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { styles } from './PasswordInput.styles'; -export interface PasswordInputProps extends CommonProps, InputProps { +export interface PasswordInputProps extends CommonProps, InputProps, Partial { detectCapsLock?: boolean; } @@ -24,11 +24,17 @@ export interface PasswordInputState { capsLockEnabled?: boolean | null; } +interface DefaultProps { + size: InputProps['size']; +} + +type PasswordInputComponentProps = PasswordInputProps & DefaultProps; + /** * Компонент для ввода пароля */ @rootNode -export class PasswordInput extends React.PureComponent { +export class PasswordInput extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'PasswordInput'; public static propTypes = { @@ -38,7 +44,7 @@ export class PasswordInput extends React.PureComponent - extends CommonProps, - Override< - React.InputHTMLAttributes, - { - /** - * Cостояние валидации при ошибке. - */ - error?: boolean; - /** - * Cостояние валидации при предупреждении. - */ - warning?: boolean; - /** - * Состояние фокуса. - */ - focused?: boolean; - /** - * Функция, вызываемая при изменении `value`. - */ - onValueChange?: (value: T) => void; - /** - * HTML-событие `onmouseenter` - */ - onMouseEnter?: React.MouseEventHandler; - /** - * HTML-событие `mouseleave` - */ - onMouseLeave?: React.MouseEventHandler; - /** - * HTML-событие `onmouseover` - */ - onMouseOver?: React.MouseEventHandler; - /** - * HTML-атрибут `value`. - */ - value: T; - } - > {} +export type RadioProps = Override< + React.InputHTMLAttributes, + { + /** + * Cостояние валидации при ошибке. + */ + error?: boolean; + /** + * Cостояние валидации при предупреждении. + */ + warning?: boolean; + /** + * Состояние фокуса. + */ + focused?: boolean; + /** + * Функция, вызываемая при изменении `value`. + */ + onValueChange?: (value: T) => void; + /** + * HTML-событие `onmouseenter` + */ + onMouseEnter?: React.MouseEventHandler; + /** + * HTML-событие `mouseleave` + */ + onMouseLeave?: React.MouseEventHandler; + /** + * HTML-событие `onmouseover` + */ + onMouseOver?: React.MouseEventHandler; + /** + * HTML-атрибут `value`. + */ + value: T; + } +> & + CommonProps & + Partial; export interface RadioState { focusedByKeyboard: boolean; } +interface DefaultProps { + focused: boolean; +} + +type RadioComponentProps = RadioProps & DefaultProps; + /** * Радио-кнопки используются, когда может быть выбран только один вариант из нескольких. */ @rootNode -export class Radio extends React.Component, RadioState> { +export class Radio extends React.Component, RadioState> { public static __KONTUR_REACT_UI__ = 'Radio'; public state = { focusedByKeyboard: false, }; - public static defaultProps = { + public static defaultProps: DefaultProps = { focused: false, }; diff --git a/packages/react-ui/components/RadioGroup/RadioGroup.tsx b/packages/react-ui/components/RadioGroup/RadioGroup.tsx index c9241dc3f26..f2fc5488983 100644 --- a/packages/react-ui/components/RadioGroup/RadioGroup.tsx +++ b/packages/react-ui/components/RadioGroup/RadioGroup.tsx @@ -4,7 +4,6 @@ import invariant from 'invariant'; import { getRandomID } from '../../lib/utils'; import { Radio } from '../Radio'; -import { createPropsGetter } from '../../lib/createPropsGetter'; import { Nullable } from '../../typings/utility-types'; import { FocusTrap } from '../../internal/FocusTrap'; import { ThemeContext } from '../../lib/theming/ThemeContext'; @@ -17,7 +16,7 @@ import { styles } from './RadioGroup.styles'; import { Prevent } from './Prevent'; import { RadioGroupContext, RadioGroupContextType } from './RadioGroupContext'; -export interface RadioGroupProps extends CommonProps { +export interface RadioGroupProps extends CommonProps, Partial> { /** * Значение по умолчанию. Должно быть одним из значений дочерних радиокнопок * или значений из параметра `items` @@ -81,6 +80,12 @@ export interface RadioGroupState { activeItem?: T; } +type RadioGroupComponentProps = RadioGroupProps & DefaultProps; + +interface DefaultProps { + renderItem: (itemValue: T, data: React.ReactNode) => React.ReactNode; +} + /** * * `children` может содержать любую разметку с компонентами Radio, @@ -91,7 +96,7 @@ export interface RadioGroupState { * Значения активного элемента сравниваются по строгому равенству `===` */ @rootNode -export class RadioGroup extends React.Component, RadioGroupState> { +export class RadioGroup extends React.Component, RadioGroupState> { public static __KONTUR_REACT_UI__ = 'RadioGroup'; public static propTypes = { @@ -108,7 +113,7 @@ export class RadioGroup extends React.Component, RadioGrou onMouseOver: PropTypes.func, }; - public static defaultProps = { + public static defaultProps: DefaultProps = { renderItem, }; @@ -118,10 +123,9 @@ export class RadioGroup extends React.Component, RadioGrou private node: Nullable; private name = getRandomID(); - private getProps = createPropsGetter(RadioGroup.defaultProps); private setRootNode!: TSetRootNode; - constructor(props: RadioGroupProps) { + constructor(props: RadioGroupComponentProps) { super(props); this.state = { @@ -229,7 +233,7 @@ export class RadioGroup extends React.Component, RadioGrou return ( - {this.getProps().renderItem(itemValue, data)} + {this.props.renderItem(itemValue, data)} ); }; diff --git a/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx b/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx index 81ff5549e97..86af6bc0c3e 100644 --- a/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx +++ b/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx @@ -22,7 +22,7 @@ export type ScrollContainerScrollStateY = 'top' | 'scroll' | 'bottom'; export type ScrollContainerScrollState = ScrollContainerScrollStateY; // deprecated export type ScrollBehaviour = 'auto' | 'smooth'; -export interface ScrollContainerProps extends CommonProps { +export interface ScrollContainerProps extends CommonProps, Partial { /** * Инвертировать цвет скроллбара * @default false @@ -45,8 +45,16 @@ export interface ScrollContainerProps extends CommonProps { onScroll?: (e: React.UIEvent) => void; } +interface DefaultProps { + invert: boolean; + scrollBehaviour: ScrollBehaviour; + preventWindowScroll: boolean; +} + +type ScrollContainerComponentProps = ScrollContainerProps & DefaultProps; + @rootNode -export class ScrollContainer extends React.Component { +export class ScrollContainer extends React.Component { public static __KONTUR_REACT_UI__ = 'ScrollContainer'; public static propTypes = { @@ -58,7 +66,7 @@ export class ScrollContainer extends React.Component { onScrollStateChange: PropTypes.func, }; - public static defaultProps = { + public static defaultProps: DefaultProps = { invert: false, scrollBehaviour: 'auto', preventWindowScroll: false, diff --git a/packages/react-ui/components/Select/Select.tsx b/packages/react-ui/components/Select/Select.tsx index 2e330ccc27a..3421d8e85dc 100644 --- a/packages/react-ui/components/Select/Select.tsx +++ b/packages/react-ui/components/Select/Select.tsx @@ -20,7 +20,6 @@ import { Menu } from '../../internal/Menu'; import { MenuItem } from '../MenuItem'; import { MenuSeparator } from '../MenuSeparator'; import { RenderLayer } from '../../internal/RenderLayer'; -import { createPropsGetter } from '../../lib/createPropsGetter'; import { Nullable } from '../../typings/utility-types'; import { isFunction } from '../../lib/utils'; import { ThemeContext } from '../../lib/theming/ThemeContext'; @@ -56,7 +55,7 @@ const PASS_BUTTON_PROPS = { onMouseOver: true, }; -export interface SelectProps extends CommonProps { +export interface SelectProps extends CommonProps, Partial> { /** @ignore */ _icon?: React.ReactNode; /** @ignore */ @@ -117,11 +116,11 @@ export interface SelectProps extends CommonProps { /** * Функция для отрисовки выбранного элемента. Аргументы — *value*, *item*. */ - renderValue?: (value: TValue, item?: TItem) => React.ReactNode; + renderValue?: (value: Nullable, item?: TItem) => React.ReactNode; /** * Функция для сравнения `value` с элементом из `items` */ - areValuesEqual?: (value1: TValue, value2: TValue) => boolean; + areValuesEqual?: (value1: Nullable, value2: Nullable) => boolean; /** * Показывать строку поиска в списке. */ @@ -148,9 +147,22 @@ interface FocusableReactElement extends React.ReactElement { focus: (event?: any) => void; } +interface DefaultProps { + renderValue: (value: Nullable, item?: TItem) => React.ReactNode; + renderItem: (value: TValue, item?: TItem) => React.ReactNode; + areValuesEqual: (value1: Nullable, value: Nullable) => boolean; + filterItem: (value: TValue, item: TItem, pattern: string) => boolean; + use: ButtonUse; +} + +type SelectComponentProps = SelectProps & DefaultProps; + @rootNode @locale('Select', SelectLocaleHelper) -export class Select extends React.Component, SelectState> { +export class Select extends React.Component< + SelectComponentProps, + SelectState +> { public static __KONTUR_REACT_UI__ = 'Select'; public static propTypes = { @@ -176,7 +188,7 @@ export class Select extends React.Component = { renderValue, renderItem, areValuesEqual, @@ -205,7 +217,6 @@ export class Select extends React.Component; private buttonElement: FocusableReactElement | null = null; - private getProps = createPropsGetter(Select.defaultProps); private setRootNode!: TSetRootNode; public componentDidUpdate(_prevProps: SelectProps, prevState: SelectState) { @@ -301,7 +312,7 @@ export class Select extends React.Component extends React.Component - {this.getProps().renderItem(iValue, item)} + {this.props.renderItem(iValue, item)} ); }, @@ -515,7 +526,7 @@ export class Select extends React.Component extends React.Component extends React.Component { value={currentValue} items={objectItems} renderItem={(x) => x.name} - renderValue={(x) => x.name} - areValuesEqual={(x1, x2) => x1.id === x2.id} + renderValue={(x) => x?.name} + areValuesEqual={(x1, x2) => x1?.id === x2?.id} />, ); diff --git a/packages/react-ui/components/SidePage/SidePage.tsx b/packages/react-ui/components/SidePage/SidePage.tsx index 5d15d6b3db7..e66d2806ead 100644 --- a/packages/react-ui/components/SidePage/SidePage.tsx +++ b/packages/react-ui/components/SidePage/SidePage.tsx @@ -23,7 +23,7 @@ import { SidePageFooter } from './SidePageFooter'; import { SidePageHeader } from './SidePageHeader'; import { styles } from './SidePage.styles'; -export interface SidePageProps extends CommonProps { +export interface SidePageProps extends CommonProps, Partial { /** * Добавить блокирующий фон, когда сайдпейдж открыт */ @@ -83,6 +83,14 @@ export interface SidePageState { hasPanel: boolean; } +interface DefaultProps { + disableAnimations: boolean; + disableFocusLock: boolean; + offset: number | string; +} + +type SidePageComponentProps = SidePageProps & DefaultProps; + const TRANSITION_TIMEOUT = 200; /** @@ -94,7 +102,7 @@ const TRANSITION_TIMEOUT = 200; * Для отображения серой плашки в футере в компонент * **Footer** необходимо передать пропс **panel** */ -export class SidePage extends React.Component { +export class SidePage extends React.Component { public static __KONTUR_REACT_UI__ = 'SidePage'; public static Header = SidePageHeader; @@ -137,7 +145,7 @@ export class SidePage extends React.Component { } }; - public static defaultProps = { + public static defaultProps: DefaultProps = { disableAnimations: isTestEnv, disableFocusLock: true, offset: 0, diff --git a/packages/react-ui/components/Spinner/Spinner.tsx b/packages/react-ui/components/Spinner/Spinner.tsx index 0dba42c47ff..9e6f374a36d 100644 --- a/packages/react-ui/components/Spinner/Spinner.tsx +++ b/packages/react-ui/components/Spinner/Spinner.tsx @@ -20,7 +20,7 @@ const types: Record = { export type SpinnerType = 'mini' | 'normal' | 'big'; -export interface SpinnerProps extends CommonProps { +export interface SpinnerProps extends CommonProps, Partial { caption?: React.ReactNode; dimmed?: boolean; /** @@ -38,13 +38,19 @@ export interface SpinnerProps extends CommonProps { color?: React.CSSProperties['color']; } +interface DefaultProps { + type: SpinnerType; +} + +type SpinnerComponentProps = SpinnerProps & DefaultProps; + /** * DRAFT - инлайн-лоадер */ @rootNode @locale('Spinner', SpinnerLocaleHelper) -export class Spinner extends React.Component { +export class Spinner extends React.Component { public static __KONTUR_REACT_UI__ = 'Spinner'; public static propTypes = { @@ -67,7 +73,7 @@ export class Spinner extends React.Component { type: PropTypes.oneOf(Object.keys(types)), }; - public static defaultProps: SpinnerProps = { + public static defaultProps: DefaultProps = { type: 'normal', }; diff --git a/packages/react-ui/components/Sticky/Sticky.tsx b/packages/react-ui/components/Sticky/Sticky.tsx index a7068f091ec..1fdf6adb2f6 100644 --- a/packages/react-ui/components/Sticky/Sticky.tsx +++ b/packages/react-ui/components/Sticky/Sticky.tsx @@ -14,7 +14,7 @@ import { styles } from './Sticky.styles'; const MAX_REFLOW_RETRIES = 5; -export interface StickyProps extends CommonProps { +export interface StickyProps extends CommonProps, Partial { side: 'top' | 'bottom'; /** * Отступ в пикселях от края экрана, на сколько сдвигается элемент в залипшем состоянии @@ -35,8 +35,14 @@ export interface StickyState { relativeTop: number; } +interface DefaultProps { + offset: number; +} + +type StickyComponentProps = StickyProps & DefaultProps; + @rootNode -export class Sticky extends React.Component { +export class Sticky extends React.Component { public static __KONTUR_REACT_UI__ = 'Sticky'; public static propTypes = { @@ -55,7 +61,7 @@ export class Sticky extends React.Component { side: PropTypes.oneOf(['top', 'bottom']).isRequired, }; - public static defaultProps = { offset: 0 }; + public static defaultProps: DefaultProps = { offset: 0 }; public state: StickyState = { fixed: false, diff --git a/packages/react-ui/components/Tabs/Tab.tsx b/packages/react-ui/components/Tabs/Tab.tsx index 5b9e09d75eb..bd2c6f7a0ce 100644 --- a/packages/react-ui/components/Tabs/Tab.tsx +++ b/packages/react-ui/components/Tabs/Tab.tsx @@ -24,7 +24,7 @@ export interface TabIndicators { disabled: boolean; } -export interface TabProps extends CommonProps { +export interface TabProps extends CommonProps, Partial { /** * Tab content */ @@ -90,6 +90,13 @@ export interface TabState { focusedByKeyboard: boolean; } +interface DefaultProps { + component: React.ComponentType | string; + href: string; +} + +type TabsComponentProps = TabProps & DefaultProps; + /** * Tab element of Tabs component * @@ -106,7 +113,7 @@ export interface TabState { * Works only inside Tabs component, otherwise throws */ @rootNode -export class Tab extends React.Component, TabState> { +export class Tab extends React.Component, TabState> { public static __KONTUR_REACT_UI__ = 'Tab'; public static contextType = TabsContext; @@ -120,7 +127,7 @@ export class Tab extends React.Component, onKeyDown: PropTypes.func, }; - public static defaultProps = { + public static defaultProps: DefaultProps = { component: 'a', href: '', }; @@ -133,7 +140,7 @@ export class Tab extends React.Component, private tabComponent: Nullable>> = null; private setRootNode!: TSetRootNode; - constructor(props: TabProps) { + constructor(props: TabsComponentProps) { super(props); invariant(this.context !== TabsContextDefaultValue, 'Tab should be placed inside Tabs component'); } diff --git a/packages/react-ui/components/Tabs/Tabs.tsx b/packages/react-ui/components/Tabs/Tabs.tsx index 991fe4bd014..4bd2ceb4d52 100644 --- a/packages/react-ui/components/Tabs/Tabs.tsx +++ b/packages/react-ui/components/Tabs/Tabs.tsx @@ -13,7 +13,7 @@ import { styles } from './Tabs.styles'; import { TabsContext, TabsContextType } from './TabsContext'; import { Tab } from './Tab'; -export interface TabsProps extends CommonProps { +export interface TabsProps extends CommonProps, Partial { /** * Tab component should be child of Tabs component */ @@ -46,13 +46,19 @@ export interface TabsProps extends CommonProps { width?: number | string; } +interface DefaultProps { + vertical: boolean; +} + +type TabsComponentProps = TabsProps & DefaultProps; + /** * Tabs wrapper * * contains static property `Tab` */ @rootNode -export class Tabs extends React.Component> { +export class Tabs extends React.Component> { public static __KONTUR_REACT_UI__ = 'Tabs'; public static propTypes = { @@ -62,7 +68,7 @@ export class Tabs extends React.Component, - { - /** - * Cостояние валидации при ошибке. - */ - error?: boolean; - /** - * Cостояние валидации при предупреждении. - */ - warning?: boolean; - /** Не активное состояние */ - disabled?: boolean; - - /** - * Атоматический ресайз - * в зависимости от содержимого - */ - autoResize?: boolean; - /** - * Число строк - */ - rows: number; - /** - * Максимальное число строк при - * автоматическом ресайзе - */ - maxRows: string | number; - - /** - * Стандартный ресайз - * Попадает в `style` - */ - resize?: React.CSSProperties['resize']; - - /** - * Ширина - */ - width?: React.CSSProperties['width']; - - /** - * Вызывается при изменении `value` - */ - onValueChange?: (value: string) => void; - - /** Выделение значения при фокусе */ - selectAllOnFocus?: boolean; - - /** Показывать счетчик символов */ - showLengthCounter?: boolean; - - /** Допустимое количество символов в поле. Отображается в счетчике. - * Если не указано, равно `maxLength` - */ - lengthCounter?: number; - - /** Подсказка к счетчику символов. - * - * По умолчанию - тултип с содежимым из пропа, если передан`ReactNode`. - * - * Передав функцию, можно переопределить подсказку целиком, вместе с иконкой. Например, - * - * ``` - * counterHelp={() => } - * ``` - * */ - counterHelp?: ReactNode | (() => ReactNode); - - /** Добавлять дополнительную свободную строку при авто-ресайзе. - * @see https://guides.kontur.ru/components/textarea/#04 - * */ - extraRow: boolean; - - /** Отключать анимацию при авто-ресайзе. - * Автоматически отключается когда в `extraRow` передан `false`. - */ - disableAnimations: boolean; - } - > {} +export type TextareaProps = Override< + React.TextareaHTMLAttributes, + { + /** + * Cостояние валидации при ошибке. + */ + error?: boolean; + /** + * Cостояние валидации при предупреждении. + */ + warning?: boolean; + /** Не активное состояние */ + disabled?: boolean; + + /** + * Атоматический ресайз + * в зависимости от содержимого + */ + autoResize?: boolean; + /** + * Число строк + */ + rows: number; + /** + * Максимальное число строк при + * автоматическом ресайзе + */ + maxRows: string | number; + + /** + * Стандартный ресайз + * Попадает в `style` + */ + resize?: React.CSSProperties['resize']; + + /** + * Ширина + */ + width?: React.CSSProperties['width']; + + /** + * Вызывается при изменении `value` + */ + onValueChange?: (value: string) => void; + + /** Выделение значения при фокусе */ + selectAllOnFocus?: boolean; + + /** Показывать счетчик символов */ + showLengthCounter?: boolean; + + /** Допустимое количество символов в поле. Отображается в счетчике. + * Если не указано, равно `maxLength` + */ + lengthCounter?: number; + + /** Подсказка к счетчику символов. + * + * По умолчанию - тултип с содежимым из пропа, если передан`ReactNode`. + * + * Передав функцию, можно переопределить подсказку целиком, вместе с иконкой. Например, + * + * ``` + * counterHelp={() => } + * ``` + * */ + counterHelp?: ReactNode | (() => ReactNode); + + /** Добавлять дополнительную свободную строку при авто-ресайзе. + * @see https://guides.kontur.ru/components/textarea/#04 + * */ + extraRow: boolean; + + /** Отключать анимацию при авто-ресайзе. + * Автоматически отключается когда в `extraRow` передан `false`. + */ + disableAnimations: boolean; + } +> & + CommonProps & + Partial; export interface TextareaState { polyfillPlaceholder: boolean; isCounterVisible: boolean; } +interface DefaultProps { + rows: number; + maxRows: string | number; + extraRow: boolean; + disableAnimations: boolean; +} + +type TextareaComponentProps = TextareaProps & DefaultProps; + /** * Компонент для ввода многострочного текста. * @@ -119,7 +128,7 @@ export interface TextareaState { * ** `className` и `style` игнорируются** */ @rootNode -export class Textarea extends React.Component { +export class Textarea extends React.Component { public static __KONTUR_REACT_UI__ = 'Textarea'; public static propTypes = { @@ -176,7 +185,7 @@ export class Textarea extends React.Component { onCopy: PropTypes.func, }; - public static defaultProps = { + public static defaultProps: DefaultProps = { rows: 3, maxRows: 15, extraRow: true, diff --git a/packages/react-ui/components/Toggle/Toggle.tsx b/packages/react-ui/components/Toggle/Toggle.tsx index 4ae46a0edb1..f8924361c17 100644 --- a/packages/react-ui/components/Toggle/Toggle.tsx +++ b/packages/react-ui/components/Toggle/Toggle.tsx @@ -13,7 +13,7 @@ import { styles, globalClasses } from './Toggle.styles'; let colorWarningShown = false; -export interface ToggleProps extends CommonProps { +export interface ToggleProps extends CommonProps, Partial { children?: React.ReactNode; /** * Положение `children` относительно переключателя. @@ -82,11 +82,19 @@ export interface ToggleState { focusByTab?: boolean; } +interface DefaultProps { + disabled: boolean; + loading: boolean; + captionPosition: 'left' | 'right'; +} + +type ToggleComponentProps = ToggleProps & DefaultProps; + /** * _Примечание:_ под тоглом понимается полный компонент т.е. надпись + переключатель, а не просто переключатель. */ @rootNode -export class Toggle extends React.Component { +export class Toggle extends React.Component { public static __KONTUR_REACT_UI__ = 'Toggle'; public static propTypes = { @@ -105,7 +113,7 @@ export class Toggle extends React.Component { }, }; - public static defaultProps = { + public static defaultProps: DefaultProps = { disabled: false, loading: false, captionPosition: 'right', @@ -115,7 +123,7 @@ export class Toggle extends React.Component { private input: HTMLInputElement | null = null; private setRootNode!: TSetRootNode; - constructor(props: ToggleProps) { + constructor(props: ToggleComponentProps) { super(props); this.state = { diff --git a/packages/react-ui/components/TokenInput/TokenInput.tsx b/packages/react-ui/components/TokenInput/TokenInput.tsx index b54b8ee2eb8..89fb863f1bd 100644 --- a/packages/react-ui/components/TokenInput/TokenInput.tsx +++ b/packages/react-ui/components/TokenInput/TokenInput.tsx @@ -41,7 +41,7 @@ export enum TokenInputType { export type TokenInputMenuAlign = 'left' | 'cursor'; -export interface TokenInputProps extends CommonProps { +export interface TokenInputProps extends CommonProps, Partial> { selectedItems: T[]; onValueChange: (items: T[]) => void; onMouseEnter: MouseEventHandler; @@ -169,12 +169,32 @@ const defaultRenderToken = ( ); +interface DefaultProps { + selectedItems: T[]; + delimiters: string[]; + renderItem: (item: T, state: MenuItemState) => React.ReactNode | null; + renderValue: (item: T) => React.ReactNode; + valueToString: (item: T) => string; + valueToItem: (item: string) => T; + toKey: (item: T) => string | number | undefined; + onValueChange: (items: T[]) => void; + width: string | number; + onBlur: FocusEventHandler; + onFocus: FocusEventHandler; + onMouseEnter: MouseEventHandler; + onMouseLeave: MouseEventHandler; + menuWidth: React.CSSProperties['width']; + menuAlign: TokenInputMenuAlign; +} + +type TokenInputComponentProps = TokenInputProps & DefaultProps; + @rootNode @locale('TokenInput', TokenInputLocaleHelper) -export class TokenInput extends React.PureComponent, TokenInputState> { +export class TokenInput extends React.PureComponent, TokenInputState> { public static __KONTUR_REACT_UI__ = 'TokenInput'; - public static defaultProps: Partial> = { + public static defaultProps: DefaultProps = { selectedItems: [], delimiters: [',', ' '], renderItem: identity, diff --git a/packages/react-ui/components/Tooltip/Tooltip.tsx b/packages/react-ui/components/Tooltip/Tooltip.tsx index f76feceda1e..a6f428f80d1 100644 --- a/packages/react-ui/components/Tooltip/Tooltip.tsx +++ b/packages/react-ui/components/Tooltip/Tooltip.tsx @@ -35,7 +35,7 @@ export type TooltipTrigger = /** Управление через публичные функции show и hide */ | 'manual'; -export interface TooltipProps extends CommonProps { +export interface TooltipProps extends CommonProps, Partial { /** * Относительно какого элемента позиционировать тултип */ @@ -132,6 +132,17 @@ export interface TooltipState { focused: boolean; } +interface DefaultProps { + pos: PopupPositionsType; + trigger: TooltipTrigger; + allowedPositions: PopupPositionsType[]; + disableAnimations: boolean; + useWrapper: boolean; + closeOnChildrenMouseLeave: boolean; +} + +type TooltipComponentProps = TooltipProps & DefaultProps; + const Positions: PopupPositionsType[] = [ 'right bottom', 'right middle', @@ -148,7 +159,7 @@ const Positions: PopupPositionsType[] = [ ]; @rootNode -export class Tooltip extends React.PureComponent { +export class Tooltip extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'Tooltip'; public static propTypes = { @@ -165,7 +176,7 @@ export class Tooltip extends React.PureComponent { }, }; - public static defaultProps = { + public static defaultProps: DefaultProps = { pos: DefaultPosition, trigger: 'hover', allowedPositions: Positions, diff --git a/packages/react-ui/components/Tooltip/__stories__/Tooltip.stories.tsx b/packages/react-ui/components/Tooltip/__stories__/Tooltip.stories.tsx index 48979f34000..cb668c9d37c 100644 --- a/packages/react-ui/components/Tooltip/__stories__/Tooltip.stories.tsx +++ b/packages/react-ui/components/Tooltip/__stories__/Tooltip.stories.tsx @@ -5,7 +5,6 @@ import { Story } from '../../../typings/stories'; import { Tooltip, TooltipProps, TooltipTrigger } from '../Tooltip'; import { Button } from '../../Button'; import { PopupPositionsType, PopupPositions } from '../../../internal/Popup'; -import { createPropsGetter } from '../../../lib/createPropsGetter'; import { Textarea } from '../../Textarea'; import { Checkbox } from '../../Checkbox'; import { Gapped } from '../../Gapped'; @@ -24,15 +23,13 @@ class TestTooltip extends React.Component { pos: 'top center', }; - private getProps = createPropsGetter(TestTooltip.defaultProps); - public render(): JSX.Element { const { trigger, children } = this.props; return (

Hey there!
} trigger={trigger} useWrapper={this.props.useWrapper} diff --git a/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx b/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx index ca486ce18ca..53c05c4d1de 100644 --- a/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx +++ b/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx @@ -12,7 +12,7 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; export type TooltipMenuChildType = React.ReactElement; -export interface TooltipMenuProps extends CommonProps { +export interface TooltipMenuProps extends CommonProps, Partial { children?: TooltipMenuChildType | TooltipMenuChildType[]; /** Максимальная высота меню */ menuMaxHeight?: number | string; @@ -50,6 +50,12 @@ export interface TooltipMenuProps extends CommonProps { disableAnimations: boolean; } +interface DefaultProps { + disableAnimations: boolean; +} + +type TooltipComponentMenuProps = TooltipMenuProps & DefaultProps; + /** * Меню, раскрывающееся по клику на переданный в `caption` элемент. * @@ -62,14 +68,14 @@ export interface TooltipMenuProps extends CommonProps { * Если массив `positions` не передан (или передан пустой массив), будут использованы всевозможные значения. */ @rootNode -export class TooltipMenu extends React.Component { +export class TooltipMenu extends React.Component { public static __KONTUR_REACT_UI__ = 'TooltipMenu'; private setRootNode!: TSetRootNode; - public static defaultProps = { + public static defaultProps: DefaultProps = { disableAnimations: isTestEnv, }; - constructor(props: TooltipMenuProps) { + constructor(props: TooltipComponentMenuProps) { super(props); if (!props.caption && !isProductionEnv) { diff --git a/packages/react-ui/internal/BGRuler.tsx b/packages/react-ui/internal/BGRuler.tsx index f4f1260f1c8..d44df48613b 100644 --- a/packages/react-ui/internal/BGRuler.tsx +++ b/packages/react-ui/internal/BGRuler.tsx @@ -1,12 +1,6 @@ import React from 'react'; -/** - * Компонент рисует пиксельную линейку на заднем фоне. - * Помогает контролировать размеры элементов при скриншотном тестировании. - * - * @see FxInput/__stories__/FxInput.stories.tsx - */ -export class BGRuler extends React.Component<{ +interface BGRulerProps extends Partial { width?: string | number; height?: string | number; top?: string | number; @@ -14,8 +8,26 @@ export class BGRuler extends React.Component<{ right?: string | number; left?: string | number; color?: string; -}> { - public static defaultProps = { +} + +interface DefaultProps { + height: string | number; + top: string | number; + left: string | number; + right: string | number; + color: string; +} + +type BgRulerComponentPorps = BGRulerProps & DefaultProps; + +/** + * Компонент рисует пиксельную линейку на заднем фоне. + * Помогает контролировать размеры элементов при скриншотном тестировании. + * + * @see FxInput/__stories__/FxInput.stories.tsx + */ +export class BGRuler extends React.Component { + public static defaultProps: DefaultProps = { height: 20, top: 0, left: 0, diff --git a/packages/react-ui/internal/Calendar/Calendar.tsx b/packages/react-ui/internal/Calendar/Calendar.tsx index 836cc7116d6..610ae1c98eb 100644 --- a/packages/react-ui/internal/Calendar/Calendar.tsx +++ b/packages/react-ui/internal/Calendar/Calendar.tsx @@ -17,7 +17,7 @@ import { Month } from './Month'; import { styles } from './Calendar.styles'; import { CalendarDateShape, create, isGreater, isLess } from './CalendarDateShape'; -export interface CalendarProps { +export interface CalendarProps extends Partial { initialMonth?: number; initialYear?: number; onSelect?: (date: CalendarDateShape) => void; @@ -36,6 +36,13 @@ export interface CalendarState { touchStart: number; } +interface DefaultProps { + minDate: CalendarDateShape; + maxDate: CalendarDateShape; +} + +type CalendarComponentProps = CalendarProps & DefaultProps; + const getTodayDate = () => { const date = new Date(); return { @@ -45,11 +52,10 @@ const getTodayDate = () => { }; }; -export class Calendar extends React.Component { +export class Calendar extends React.Component { public static __KONTUR_REACT_UI__ = 'Calendar'; - public static defaultProps = { - holidays: [], + public static defaultProps: DefaultProps = { minDate: { year: MIN_YEAR, month: MIN_MONTH, @@ -68,7 +74,7 @@ export class Calendar extends React.Component { private animation = Animation(); private touchStartY: Nullable = null; - constructor(props: CalendarProps) { + constructor(props: CalendarComponentProps) { super(props); const today = getTodayDate(); diff --git a/packages/react-ui/internal/Calendar/Month.tsx b/packages/react-ui/internal/Calendar/Month.tsx index c8474a19fa4..bae9850b4be 100644 --- a/packages/react-ui/internal/Calendar/Month.tsx +++ b/packages/react-ui/internal/Calendar/Month.tsx @@ -129,7 +129,7 @@ export class Month extends React.Component { }; } -interface MonthDayGridProps { +interface MonthDayGridProps extends Partial { days: DayCellViewModel[]; offset: number; minDate?: CDS.CalendarDateShape; @@ -140,10 +140,16 @@ interface MonthDayGridProps { isHoliday: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => boolean; } -class MonthDayGrid extends React.Component { +interface DefaultProps { + isHoliday: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => boolean; +} + +type MonthDayGridComponentProps = MonthDayGridProps & DefaultProps; + +class MonthDayGrid extends React.Component { private theme!: Theme; - public static defaultProps = { + public static defaultProps: DefaultProps = { isHoliday: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => day.isWeekend, }; diff --git a/packages/react-ui/internal/ComponentCombinator.tsx b/packages/react-ui/internal/ComponentCombinator.tsx index 8b3632f0127..9530a095eaf 100644 --- a/packages/react-ui/internal/ComponentCombinator.tsx +++ b/packages/react-ui/internal/ComponentCombinator.tsx @@ -4,24 +4,33 @@ import { DefaultizeProps } from '../lib/utils'; import { ComponentTable, StatePropsCombinations, StateType } from './ComponentTable'; -export interface ComponentCombinatorProps { +export interface ComponentCombinatorProps extends DefaultProps { combinations: Array>; Component: C; presetProps: DefaultizeProps; presetState: Partial; } +interface DefaultProps { + presetProps: DefaultizeProps; + presetState: Partial; +} + +type ComponentCombinatorComponentProps = ComponentCombinatorProps & DefaultProps; + export class ComponentCombinator< T extends React.Component, C extends React.ComponentType, P extends React.ComponentProps, > extends React.Component< - ComponentCombinatorProps ? React.ClassType : C, P, StateType>, + ComponentCombinatorComponentProps< + C extends React.ComponentClass ? React.ClassType : C, + P, + StateType + >, { page: number } > { - public static defaultProps = { - props: [], - states: [], + public static defaultProps: DefaultProps = { presetProps: {}, presetState: {}, }; diff --git a/packages/react-ui/internal/ComponentTable.tsx b/packages/react-ui/internal/ComponentTable.tsx index a56927a9bf2..55aa02f2659 100644 --- a/packages/react-ui/internal/ComponentTable.tsx +++ b/packages/react-ui/internal/ComponentTable.tsx @@ -32,7 +32,7 @@ export type StatePropsCombinations = Array<{ props?: Partial

; state?: P export type StateType = C extends React.Component | React.ComponentClass ? S : never; -export interface ComponentTableProps { +export interface ComponentTableProps extends Partial> { rows?: StatePropsCombinations; cols?: StatePropsCombinations; presetProps: DefaultizeProps; @@ -40,15 +40,22 @@ export interface ComponentTableProps { Component: C; } +interface DefaultProps { + presetProps: DefaultizeProps; + presetState: Partial; +} + +type ComponentTableComponentProps = ComponentTableProps & DefaultProps; + // Known limitation: Don't work when component have `propTypes` static field export class ComponentTable< T extends React.Component, C extends React.ComponentType, P extends React.ComponentProps, > extends React.Component< - ComponentTableProps ? React.ClassType : C, P, StateType> + ComponentTableComponentProps ? React.ClassType : C, P, StateType> > { - public static defaultProps = { presetProps: {}, presetState: {} }; + public static defaultProps: DefaultProps = { presetProps: {}, presetState: {} }; public render() { const { rows = [], cols = [], presetProps, presetState, Component } = this.props; diff --git a/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx b/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx index 9e446d3bb5d..346d823b8e0 100644 --- a/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx +++ b/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx @@ -10,7 +10,7 @@ import { MenuSeparator } from '../../components/MenuSeparator'; import { ComboBoxRequestStatus } from './CustomComboBoxTypes'; import { ComboBoxLocale, CustomComboBoxLocaleHelper } from './locale'; -export interface ComboBoxMenuProps { +export interface ComboBoxMenuProps extends Partial { opened?: boolean; items?: Nullable; totalCount?: number; @@ -27,11 +27,18 @@ export interface ComboBoxMenuProps { requestStatus?: ComboBoxRequestStatus; } +interface DefaultProps { + repeatRequest: () => void; + requestStatus: ComboBoxRequestStatus; +} + +type ComboBoxMenuComponentProps = ComboBoxMenuProps & DefaultProps; + @locale('ComboBox', CustomComboBoxLocaleHelper) -export class ComboBoxMenu extends Component> { +export class ComboBoxMenu extends Component> { public static __KONTUR_REACT_UI__ = 'ComboBoxMenu'; - public static defaultProps = { + public static defaultProps: DefaultProps = { repeatRequest: () => undefined, requestStatus: ComboBoxRequestStatus.Unknown, }; diff --git a/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx b/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx index d85d7932fff..ff8b162f10c 100644 --- a/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx +++ b/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx @@ -17,7 +17,7 @@ import { ComboBoxMenu } from './ComboBoxMenu'; import { ComboBoxRequestStatus } from './CustomComboBoxTypes'; import { styles } from './CustomComboBox.styles'; -interface ComboBoxViewProps extends CommonProps { +interface ComboBoxViewProps extends CommonProps, Partial> { align?: 'left' | 'center' | 'right'; autoFocus?: boolean; borderless?: boolean; @@ -73,11 +73,25 @@ interface ComboBoxViewProps extends CommonProps { refInputLikeText?: (inputLikeText: Nullable) => void; } +interface DefaultProps { + renderItem: (item: T, state: MenuItemState) => React.ReactNode; + renderValue: (item: T) => React.ReactNode; + renderAddButton: (query?: string) => React.ReactNode; + repeatRequest: () => void; + requestStatus: ComboBoxRequestStatus; + onClickOutside: (e: Event) => void; + onFocusOutside: () => void; + size: 'small' | 'medium' | 'large'; + width: string | number; +} + +type ComboBoxViewComponentProps = ComboBoxViewProps & DefaultProps; + @rootNode -export class ComboBoxView extends React.Component, {}> { +export class ComboBoxView extends React.Component, {}> { public static __KONTUR_REACT_UI__ = 'ComboBoxView'; - public static defaultProps = { + public static defaultProps: DefaultProps = { renderItem: (item: any) => item, renderValue: (item: any) => item, renderAddButton: () => null, diff --git a/packages/react-ui/internal/DateSelect/DateSelect.tsx b/packages/react-ui/internal/DateSelect/DateSelect.tsx index de310c3248d..8952cc0bd39 100644 --- a/packages/react-ui/internal/DateSelect/DateSelect.tsx +++ b/packages/react-ui/internal/DateSelect/DateSelect.tsx @@ -23,7 +23,7 @@ const monthsCount = 12; const defaultMinYear = 1900; const defaultMaxYear = 2100; -export interface DateSelectProps { +export interface DateSelectProps extends Partial { disabled?: boolean | null; onValueChange: (value: number) => void; type?: 'month' | 'year'; @@ -44,8 +44,15 @@ export interface DateSelectState { nodeTop: number; } +interface DefaultProps { + type: 'month' | 'year'; + width: number | string; +} + +type DateSelectComponentProps = DateSelectProps & DefaultProps; + @locale('DatePicker', DatePickerLocaleHelper) -export class DateSelect extends React.PureComponent { +export class DateSelect extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'DateSelect'; public static propTypes = { @@ -64,10 +71,8 @@ export class DateSelect extends React.PureComponent; } -export interface DropdownContainerProps { +export interface DropdownContainerProps extends Partial { align?: 'left' | 'right'; getParent: () => Nullable; children?: React.ReactNode; @@ -33,10 +32,19 @@ export interface DropdownContainerState { isDocumentElementRoot?: boolean; } -export class DropdownContainer extends React.PureComponent { +interface DefaultProps { + align: 'left' | 'right'; + disablePortal: boolean; + offsetX: number; + offsetY: number; +} + +type DropdownContainerComponentProps = DropdownContainerProps & DefaultProps; + +export class DropdownContainer extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'DropdownContainer'; - public static defaultProps = { + public static defaultProps: DefaultProps = { align: 'left', disablePortal: false, offsetX: 0, @@ -49,8 +57,6 @@ export class DropdownContainer extends React.PureComponent; private layoutSub: Nullable>; @@ -136,9 +142,9 @@ export class DropdownContainer extends React.PureComponent { children?: React.ReactNode; hasShadow?: boolean; maxHeight?: number | string; @@ -37,11 +36,22 @@ interface MenuState { scrollState: ScrollContainerScrollState; } +interface DefaultProps { + width: number | string; + maxHeight: number | string; + hasShadow: boolean; + preventWindowScroll: boolean; + cyclicSelection: boolean; + initialSelectedItemIndex: number; +} + +type InternalMenuComponentProps = MenuProps & DefaultProps; + @rootNode -export class InternalMenu extends React.PureComponent { +export class InternalMenu extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'InternalMenu'; - public static defaultProps = { + public static defaultProps: DefaultProps = { width: 'auto', maxHeight: 300, hasShadow: true, @@ -62,7 +72,6 @@ export class InternalMenu extends React.PureComponent { private setRootNode!: TSetRootNode; private header: Nullable; private footer: Nullable; - private getProps = createPropsGetter(InternalMenu.defaultProps); public componentDidMount() { this.setInitialSelection(); @@ -249,7 +258,7 @@ export class InternalMenu extends React.PureComponent { }; private setInitialSelection = () => { - for (let i = this.getProps().initialSelectedItemIndex; i > -1; i--) { + for (let i = this.props.initialSelectedItemIndex; i > -1; i--) { this.moveDown(); } }; diff --git a/packages/react-ui/internal/MaskedInput/MaskedInput.tsx b/packages/react-ui/internal/MaskedInput/MaskedInput.tsx index 870fda8be1b..8c1e6cd685b 100644 --- a/packages/react-ui/internal/MaskedInput/MaskedInput.tsx +++ b/packages/react-ui/internal/MaskedInput/MaskedInput.tsx @@ -8,7 +8,7 @@ import { cx } from '../../lib/theming/Emotion'; import { styles } from './MaskedInput.styles'; -export interface MaskedInputProps extends React.InputHTMLAttributes { +export interface MaskedInputProps extends React.InputHTMLAttributes, Partial { mask: string; maskChar: string | null; formatChars?: { [key: string]: string }; @@ -25,10 +25,16 @@ interface MaskedInputState { focused: boolean; } -export class MaskedInput extends React.PureComponent { +interface DefaultProps { + maskChar: string | null; +} + +type MaskedInputComponentProps = MaskedInputProps & DefaultProps; + +export class MaskedInput extends React.PureComponent { public static __KONTUR_REACT_UI__ = 'MaskedInput'; - public static defaultProps: Partial = { + public static defaultProps: DefaultProps = { maskChar: '_', }; diff --git a/packages/react-ui/internal/Menu/Menu.tsx b/packages/react-ui/internal/Menu/Menu.tsx index c418e2cc520..2bd076bad7f 100644 --- a/packages/react-ui/internal/Menu/Menu.tsx +++ b/packages/react-ui/internal/Menu/Menu.tsx @@ -13,7 +13,7 @@ import { isIE11 } from '../../lib/client'; import { styles } from './Menu.styles'; import { isActiveElement } from './isActiveElement'; -export interface MenuProps { +export interface MenuProps extends Partial { children: React.ReactNode; hasShadow?: boolean; maxHeight?: number | string; @@ -27,11 +27,21 @@ export interface MenuState { highlightedIndex: number; } +interface DefaultProps { + align: 'left' | 'right'; + width: number | string; + maxHeight: number | string; + hasShadow: boolean; + preventWindowScroll: boolean; +} + +type MenuComponentProps = MenuProps & DefaultProps; + @rootNode -export class Menu extends React.Component { +export class Menu extends React.Component { public static __KONTUR_REACT_UI__ = 'Menu'; - public static defaultProps = { + public static defaultProps: DefaultProps = { align: 'left', width: 'auto', maxHeight: 300, diff --git a/packages/react-ui/internal/Popup/Popup.tsx b/packages/react-ui/internal/Popup/Popup.tsx index 88504a7535f..dd0a6b04fff 100644 --- a/packages/react-ui/internal/Popup/Popup.tsx +++ b/packages/react-ui/internal/Popup/Popup.tsx @@ -63,7 +63,7 @@ export interface PopupHandlerProps { onClose?: () => void; } -export interface PopupProps extends CommonProps, PopupHandlerProps { +export interface PopupProps extends CommonProps, PopupHandlerProps, Partial { anchorElement: React.ReactNode | HTMLElement; backgroundColor?: React.CSSProperties['backgroundColor']; borderColor?: React.CSSProperties['borderColor']; @@ -108,8 +108,20 @@ export interface PopupState { location: Nullable; } +interface DefaultProps { + popupOffset: number; + hasPin: boolean; + hasShadow: boolean; + disableAnimations: boolean; + useWrapper: boolean; + ignoreHover: boolean; + width: React.CSSProperties['width']; +} + +type PopupComponentProps = PopupProps & DefaultProps; + @rootNode -export class Popup extends React.Component { +export class Popup extends React.Component { public static __KONTUR_REACT_UI__ = 'Popup'; public static propTypes = { @@ -174,7 +186,7 @@ export class Popup extends React.Component { ignoreHover: PropTypes.bool, }; - public static defaultProps = { + public static defaultProps: DefaultProps = { popupOffset: 0, hasPin: false, hasShadow: false, diff --git a/packages/react-ui/internal/PopupMenu/PopupMenu.tsx b/packages/react-ui/internal/PopupMenu/PopupMenu.tsx index 1479ec654ec..c4c29a98513 100644 --- a/packages/react-ui/internal/PopupMenu/PopupMenu.tsx +++ b/packages/react-ui/internal/PopupMenu/PopupMenu.tsx @@ -24,7 +24,7 @@ export interface PopupMenuCaptionProps { toggleMenu: () => void; } -export interface PopupMenuProps extends CommonProps { +export interface PopupMenuProps extends CommonProps, Partial { children?: React.ReactNode; /** Максимальная высота меню */ menuMaxHeight?: number | string; @@ -52,7 +52,7 @@ export interface PopupMenuProps extends CommonProps { popupHasPin?: boolean; popupMargin?: number; popupPinOffset?: number; - type?: 'dropdown' | 'tooltip'; + type?: typeof PopupMenuType[keyof typeof PopupMenuType]; disableAnimations: boolean; } @@ -61,11 +61,20 @@ interface PopupMenuState { firstItemShouldBeSelected?: boolean; } +interface DefaultProps { + positions: PopupPositionsType[]; + type: typeof PopupMenuType[keyof typeof PopupMenuType]; + popupHasPin: boolean; + disableAnimations: boolean; +} + export const PopupMenuType = { Dropdown: 'dropdown', Tooltip: 'tooltip', }; +type PopupMenuComponentProps = PopupMenuProps & DefaultProps; + const Positions: PopupPositionsType[] = [ 'top left', 'top center', @@ -82,10 +91,10 @@ const Positions: PopupPositionsType[] = [ ]; @rootNode -export class PopupMenu extends React.Component { +export class PopupMenu extends React.Component { public static __KONTUR_REACT_UI__ = 'PopupMenu'; - public static defaultProps = { + public static defaultProps: DefaultProps = { positions: Positions, type: PopupMenuType.Tooltip, popupHasPin: true, diff --git a/packages/react-ui/internal/RenderLayer/RenderLayer.tsx b/packages/react-ui/internal/RenderLayer/RenderLayer.tsx index ba2ef7c0ad2..e38ad6dc198 100644 --- a/packages/react-ui/internal/RenderLayer/RenderLayer.tsx +++ b/packages/react-ui/internal/RenderLayer/RenderLayer.tsx @@ -5,7 +5,7 @@ import { CommonProps, CommonWrapper } from '../CommonWrapper'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; import { Nullable } from '../../typings/utility-types'; -export interface RenderLayerProps extends CommonProps { +export interface RenderLayerProps extends CommonProps, Partial { children: JSX.Element; onClickOutside?: (e: Event) => void; onFocusOutside?: (e: Event) => void; @@ -13,8 +13,14 @@ export interface RenderLayerProps extends CommonProps { getAnchorElement?: () => Nullable; } +interface DefaultProps { + active: boolean; +} + +type RenderLayerComponentPorps = RenderLayerProps & DefaultProps; + @rootNode -export class RenderLayer extends React.Component { +export class RenderLayer extends React.Component { public static __KONTUR_REACT_UI__ = 'RenderLayer'; public static propTypes = { @@ -28,7 +34,7 @@ export class RenderLayer extends React.Component { }, }; - public static defaultProps = { + public static defaultProps: DefaultProps = { active: true, }; diff --git a/packages/react-ui/internal/ThemePlayground/VariableValue.tsx b/packages/react-ui/internal/ThemePlayground/VariableValue.tsx index 400d6ad700f..26346e41208 100644 --- a/packages/react-ui/internal/ThemePlayground/VariableValue.tsx +++ b/packages/react-ui/internal/ThemePlayground/VariableValue.tsx @@ -15,7 +15,7 @@ import { styles } from './Playground.styles'; const emitter = new EventEmitter(); -export interface VariableValueProps { +export interface VariableValueProps extends Partial { onChange: (variable: keyof Theme, value: string) => void; value: string; isError: boolean; @@ -30,8 +30,14 @@ export interface VariableValueState { editing: boolean; } -export class VariableValue extends React.Component { - public static defaultProps = { +interface DefaultProps { + deprecated: boolean; +} + +type VariableValueComponentProps = VariableValueProps & DefaultProps; + +export class VariableValue extends React.Component { + public static defaultProps: DefaultProps = { deprecated: false, }; public state = { diff --git a/packages/react-ui/internal/ZIndex/ZIndex.tsx b/packages/react-ui/internal/ZIndex/ZIndex.tsx index e7555a39d24..5d3e2058f17 100644 --- a/packages/react-ui/internal/ZIndex/ZIndex.tsx +++ b/packages/react-ui/internal/ZIndex/ZIndex.tsx @@ -10,7 +10,7 @@ const ZIndexContext = React.createContext({ parentLayerZIndex: 0, maxZIndex: Inf ZIndexContext.displayName = 'ZIndexContext'; -export interface ZIndexProps extends React.HTMLAttributes { +export interface ZIndexProps extends React.HTMLAttributes, Partial { /** * Приращение к z-index */ @@ -24,11 +24,22 @@ export interface ZIndexProps extends React.HTMLAttributes { wrapperRef?: React.Ref | undefined | null; } +interface DefaultProps { + delta: number; + priority: number | LayerComponentName; + style: React.CSSProperties; + applyZIndex: boolean; + coverChildren: boolean; + createStackingContext: boolean; +} + +type ZIndexComponentPorps = ZIndexProps & DefaultProps; + @rootNode -export class ZIndex extends React.Component { +export class ZIndex extends React.Component { public static __KONTUR_REACT_UI__ = 'ZIndex'; - public static defaultProps = { + public static defaultProps: DefaultProps = { delta: 10, priority: 0, style: {}, @@ -52,7 +63,7 @@ export class ZIndex extends React.Component { private setRootNode!: TSetRootNode; - constructor(props: ZIndexProps) { + constructor(props: ZIndexComponentPorps) { super(props); this.zIndex = incrementZIndex(props.priority, props.delta); } diff --git a/packages/react-ui/lib/createPropsGetter.ts b/packages/react-ui/lib/createPropsGetter.ts deleted file mode 100644 index 6c2c55f44c7..00000000000 --- a/packages/react-ui/lib/createPropsGetter.ts +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react'; - -export function createPropsGetter(defaultProps: DP) { - return function >(this: T): DP & P { - return this.props as any; - }; -} From ce968f8d0cdcd955817edcced0037bb0fb4d006f Mon Sep 17 00:00:00 2001 From: HelenaIsh Date: Fri, 18 Feb 2022 14:12:26 +0500 Subject: [PATCH 06/11] chore: refactor --- .../components/Autocomplete/Autocomplete.tsx | 67 ++++--- .../react-ui/components/Button/Button.tsx | 47 +++-- .../react-ui/components/Center/Center.tsx | 25 ++- .../react-ui/components/ComboBox/ComboBox.tsx | 78 ++++---- .../CurrencyInput/CurrencyInput.tsx | 53 +++--- .../components/DateInput/DateInput.tsx | 48 +++-- .../components/DatePicker/DatePicker.tsx | 29 ++- .../components/DropdownMenu/DropdownMenu.tsx | 27 ++- .../react-ui/components/FxInput/FxInput.tsx | 45 +++-- .../react-ui/components/Gapped/Gapped.tsx | 26 ++- packages/react-ui/components/Hint/Hint.tsx | 57 +++--- packages/react-ui/components/Input/Input.tsx | 167 +++++++++--------- packages/react-ui/components/Kebab/Kebab.tsx | 41 ++--- packages/react-ui/components/Link/Link.tsx | 89 +++++----- .../react-ui/components/Loader/Loader.tsx | 41 ++--- packages/react-ui/components/Modal/Modal.tsx | 23 ++- .../react-ui/components/Paging/Paging.tsx | 39 ++-- .../PasswordInput/PasswordInput.tsx | 14 +- packages/react-ui/components/Radio/Radio.tsx | 81 +++++---- .../components/RadioGroup/RadioGroup.tsx | 26 +-- .../ScrollContainer/ScrollContainer.tsx | 29 ++- .../react-ui/components/Select/Select.tsx | 48 +++-- .../react-ui/components/SidePage/SidePage.tsx | 37 ++-- .../react-ui/components/Spinner/Spinner.tsx | 20 +-- .../react-ui/components/Sticky/Sticky.tsx | 22 +-- packages/react-ui/components/Tabs/Tab.tsx | 33 ++-- packages/react-ui/components/Tabs/Tabs.tsx | 19 +- .../react-ui/components/Textarea/Textarea.tsx | 165 +++++++++-------- .../react-ui/components/Toggle/Toggle.tsx | 36 ++-- .../components/TokenInput/TokenInput.tsx | 57 +++--- .../react-ui/components/Tooltip/Tooltip.tsx | 73 ++++---- .../components/TooltipMenu/TooltipMenu.tsx | 12 +- packages/react-ui/internal/BGRuler.tsx | 17 +- .../react-ui/internal/Calendar/Calendar.tsx | 14 +- packages/react-ui/internal/Calendar/Month.tsx | 13 +- .../react-ui/internal/ComponentCombinator.tsx | 12 +- packages/react-ui/internal/ComponentTable.tsx | 10 +- .../internal/CustomComboBox/ComboBoxMenu.tsx | 10 +- .../internal/CustomComboBox/ComboBoxView.tsx | 21 +-- .../internal/DateSelect/DateSelect.tsx | 14 +- .../DropdownContainer/DropdownContainer.tsx | 20 +-- .../internal/InputLikeText/InputLikeText.tsx | 16 +- .../internal/InternalMenu/InternalMenu.tsx | 22 +-- .../internal/MaskedInput/MaskedInput.tsx | 16 +- packages/react-ui/internal/Menu/Menu.tsx | 17 +- packages/react-ui/internal/Popup/Popup.tsx | 47 +++-- .../internal/Popup/__tests__/Popup-test.tsx | 12 +- .../react-ui/internal/PopupMenu/PopupMenu.tsx | 25 ++- .../internal/RenderLayer/RenderLayer.tsx | 14 +- .../ThemePlayground/VariableValue.tsx | 17 +- packages/react-ui/internal/ZIndex/ZIndex.tsx | 29 ++- 51 files changed, 888 insertions(+), 1032 deletions(-) diff --git a/packages/react-ui/components/Autocomplete/Autocomplete.tsx b/packages/react-ui/components/Autocomplete/Autocomplete.tsx index 2cb939bd33b..41197a01c8f 100644 --- a/packages/react-ui/components/Autocomplete/Autocomplete.tsx +++ b/packages/react-ui/components/Autocomplete/Autocomplete.tsx @@ -28,45 +28,40 @@ function renderItem(item: any) { return item; } -export type AutocompleteProps = Override< - InputProps, - { - /** Функция отрисовки элемента меню */ - renderItem: (item: string) => React.ReactNode; - /** Промис, резолвящий элементы меню */ - source?: string[] | ((patter: string) => Promise); - /** Отключает использование портала */ - 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; - } -> & - CommonProps & - Partial; +type AutocompleteInterface = { + /** Функция отрисовки элемента меню */ + renderItem: (item: string) => React.ReactNode; + /** Промис, резолвящий элементы меню */ + source?: string[] | ((patter: string) => Promise); + /** Отключает использование портала */ + disablePortal: boolean; + /** Отрисовка тени у выпадающего меню */ + hasShadow: boolean; + /** Выравнивание выпадающего меню */ + menuAlign: 'left' | 'right'; + /** Максимальная высота меню */ + menuMaxHeight: number; + /** Выравнивание выпадающего меню */ + menuWidth?: number | string; + /** Отключить скролл окна, когда меню открыто */ + preventWindowScroll: boolean; + /** Вызывается при изменении `value` */ + onValueChange: (value: string) => void; + /** onBlur */ + onBlur?: () => void; + /** Размер инпута */ + size: InputProps['size']; + /** value */ + value: string; +}; -export interface AutocompleteState { +export type AutocompleteState = { items: Nullable; selected: number; focused: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { renderItem: (item: string) => React.ReactNode; size: InputProps['size']; disablePortal: boolean; @@ -74,7 +69,9 @@ interface DefaultProps { menuMaxHeight: number; menuAlign: 'left' | 'right'; preventWindowScroll: boolean; -} +}; + +export type AutocompleteProps = Override & CommonProps & Partial; type AutocompleteComponentProps = AutocompleteProps & DefaultProps; diff --git a/packages/react-ui/components/Button/Button.tsx b/packages/react-ui/components/Button/Button.tsx index 90a2972286b..869f7b9d40b 100644 --- a/packages/react-ui/components/Button/Button.tsx +++ b/packages/react-ui/components/Button/Button.tsx @@ -17,7 +17,7 @@ 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, Partial { +export type ButtonProps = { /** @ignore */ _noPadding?: boolean; @@ -122,30 +122,11 @@ export interface ButtonProps extends CommonProps, Partial { */ onMouseOver?: React.MouseEventHandler; - /** - * Задаёт размер кнопки. - * - * **Допустимые значения**: `"small"`, `"medium"`, `"large"`. - */ - size?: ButtonSize; - - /** - * HTML-атрибут `type`. - */ - type?: ButtonType; - /** * HTML-атрибут `title`. */ title?: string; - /** - * Стиль кнопки. - * - * **Допустимые значения**: `"default"`, `"primary"`, `"success"`, `"danger"`, `"pay"`, `"link"`. - */ - use?: ButtonUse; - /** @ignore */ visuallyFocused?: boolean; @@ -158,17 +139,33 @@ export interface ButtonProps extends CommonProps, Partial { * CSS-свойство `width`. */ width?: number | string; -} +} & CommonProps & + Partial; -export interface ButtonState { +export type ButtonState = { focusedByTab: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { + /** + * Стиль кнопки. + * + * **Допустимые значения**: `"default"`, `"primary"`, `"success"`, `"danger"`, `"pay"`, `"link"`. + */ use: ButtonUse; + + /** + * Задаёт размер кнопки. + * + * **Допустимые значения**: `"small"`, `"medium"`, `"large"`. + */ size: ButtonSize; + + /** + * HTML-атрибут `type`. + */ type: ButtonType; -} +}; type ButtonComponentProps = ButtonProps & DefaultProps; diff --git a/packages/react-ui/components/Center/Center.tsx b/packages/react-ui/components/Center/Center.tsx index f52cd77264b..7728261d896 100644 --- a/packages/react-ui/components/Center/Center.tsx +++ b/packages/react-ui/components/Center/Center.tsx @@ -9,23 +9,22 @@ import { styles } from './Center.styles'; export type HorizontalAlign = 'left' | 'center' | 'right'; -export type CenterProps = Override< - React.HTMLAttributes, - { - /** - * Определяет, как контент будет выровнен по горизонтали. - * - * **Допустимые значения**: `"left"`, `"center"`, `"right"`. - */ - align?: HorizontalAlign; - } -> & +type CenterInterface = { + /** + * Определяет, как контент будет выровнен по горизонтали. + * + * **Допустимые значения**: `"left"`, `"center"`, `"right"`. + */ + align?: HorizontalAlign; +}; + +export type CenterProps = Override, CenterInterface> & CommonProps & Partial; -interface DefaultProps { +type DefaultProps = { align: HorizontalAlign; -} +}; type CenterComponentProps = CenterProps & DefaultProps; diff --git a/packages/react-ui/components/ComboBox/ComboBox.tsx b/packages/react-ui/components/ComboBox/ComboBox.tsx index 1181759147b..94ddb81367c 100644 --- a/packages/react-ui/components/ComboBox/ComboBox.tsx +++ b/packages/react-ui/components/ComboBox/ComboBox.tsx @@ -7,18 +7,8 @@ import { InputIconType } from '../Input'; import { CommonProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -export interface ComboBoxProps extends CommonProps, Partial> { +export type ComboBoxProps = { align?: 'left' | 'center' | 'right'; - /** - * Вызывает функцию поиска `getItems` при фокусе и очистке поля ввода - * @default true - */ - searchOnFocus?: boolean; - /** - * Рисует справа иконку в виде стрелки - * @default true - */ - drawArrow?: boolean; autoFocus?: boolean; @@ -50,16 +40,8 @@ export interface ComboBoxProps extends CommonProps, Partial> */ getItems: (query: string) => Promise; - /** - * Необходим для сравнения полученных результатов с `value` - * @default item => item.label - */ - itemToValue: (item: T) => string | number; - maxLength?: number; - menuAlign?: 'left' | 'right'; - onBlur?: () => void; /** Вызывается при изменении `value` */ @@ -91,13 +73,6 @@ export interface ComboBoxProps extends CommonProps, Partial> placeholder?: string; - /** - * Функция отрисовки элементов результата поиска. - * Не применяется если элемент является функцией или React-элементом - * @default item => item.label - */ - renderItem: (item: T, state?: MenuItemState) => React.ReactNode; - /** * Функция для отрисовки сообщения о пустом результате поиска * Если есть renderAddButton - не работает @@ -110,12 +85,6 @@ export interface ComboBoxProps extends CommonProps, Partial> */ renderTotalCount?: (found: number, total: number) => React.ReactNode; - /** - * Функция отрисовки выбранного значения - * @default item => item.label - */ - renderValue: (item: T) => React.ReactNode; - /** * Функция отрисовки кнопки добавления в выпадающем списке */ @@ -134,12 +103,6 @@ export interface ComboBoxProps extends CommonProps, Partial> */ value?: Nullable; - /** - * Необходим для преобразования `value` в строку при фокусировке - * @default item => item.label - */ - valueToString: (item: T) => string; - size?: 'small' | 'medium' | 'large'; /** * Cостояние валидации при предупреждении. @@ -159,22 +122,49 @@ export interface ComboBoxProps extends CommonProps, Partial> onInputKeyDown?: (e: React.KeyboardEvent) => void; inputMode?: React.HTMLAttributes['inputMode']; -} +} & CommonProps & + Partial>; -export interface ComboBoxItem { +export type ComboBoxItem = { value: string; label: string; -} +}; -interface DefaultProps { +type DefaultProps = { + /** + * Необходим для сравнения полученных результатов с `value` + * @default item => item.label + */ itemToValue: (item: T) => string | number; + + /** + * Необходим для преобразования `value` в строку при фокусировке + * @default item => item.label + */ valueToString: (item: T) => string; + /** + * Функция отрисовки выбранного значения + * @default item => item.label + */ renderValue: (item: T) => React.ReactNode; + /** + * Функция отрисовки элементов результата поиска. + * Не применяется если элемент является функцией или React-элементом + * @default item => item.label + */ renderItem: (item: T, state?: MenuItemState) => React.ReactNode; menuAlign: 'left' | 'right'; + /** + * Вызывает функцию поиска `getItems` при фокусе и очистке поля ввода + * @default true + */ searchOnFocus: boolean; + /** + * Рисует справа иконку в виде стрелки + * @default true + */ drawArrow: boolean; -} +}; export type ComboBoxComponentProps = ComboBoxProps & DefaultProps; @@ -182,7 +172,7 @@ export type ComboBoxComponentProps = ComboBoxProps & DefaultProps; export class ComboBox extends React.Component> { public static __KONTUR_REACT_UI__ = 'ComboBox'; - public static defaultProps: DefaultProps = { + public static defaultProps: DefaultProps = { itemToValue: (item: ComboBoxItem) => item.value, valueToString: (item: ComboBoxItem) => item.label, renderValue: (item: ComboBoxItem) => item.label, diff --git a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx index 0095fbdf3f8..7ae5c3ce1c1 100644 --- a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx +++ b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx @@ -15,43 +15,40 @@ import { CurrencyHelper } from './CurrencyHelper'; import { CurrencyInputHelper } from './CurrencyInputHelper'; import { CURRENCY_INPUT_ACTIONS, extractAction } from './CurrencyInputKeyboardActions'; -export type CurrencyInputProps = Override< - InputProps, - { - /** Значение */ - value: Nullable; - /** Убрать лишние нули после запятой */ - hideTrailingZeros: boolean; - /** Кол-во цифр после зяпятой */ - fractionDigits?: Nullable; - /** Отрицательные значения */ - signed?: boolean; - /** - * Допустимое кол-во цифр целой части. - * Если передан **0**, или `fractionDigits=15`, то и в целой части допускается только **0**. - */ - integerDigits?: Nullable; - /** Вызывается при изменении `value` */ - onValueChange: (value: Nullable) => void; - /** onSubmit */ - onSubmit?: () => void; - } -> & - CommonProps & - Partial; +type CurrencyInputInterface = { + /** Значение */ + value: Nullable; + /** Убрать лишние нули после запятой */ + hideTrailingZeros: boolean; + /** Кол-во цифр после зяпятой */ + fractionDigits?: Nullable; + /** Отрицательные значения */ + signed?: boolean; + /** + * Допустимое кол-во цифр целой части. + * Если передан **0**, или `fractionDigits=15`, то и в целой части допускается только **0**. + */ + integerDigits?: Nullable; + /** Вызывается при изменении `value` */ + onValueChange: (value: Nullable) => void; + /** onSubmit */ + onSubmit?: () => void; +}; + +export type CurrencyInputProps = Override & CommonProps & Partial; -export interface CurrencyInputState { +export type CurrencyInputState = { formatted: string; selection: Selection; focused: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { align: InputProps['align']; fractionDigits: Nullable; hideTrailingZeros: boolean; value: Nullable; -} +}; type CurrencyInputComponentProps = CurrencyInputProps & DefaultProps; diff --git a/packages/react-ui/components/DateInput/DateInput.tsx b/packages/react-ui/components/DateInput/DateInput.tsx index 0a43d5424f4..679406fbb1a 100644 --- a/packages/react-ui/components/DateInput/DateInput.tsx +++ b/packages/react-ui/components/DateInput/DateInput.tsx @@ -18,17 +18,16 @@ import { styles } from './DateInput.styles'; import { Actions, extractAction } from './helpers/DateInputKeyboardActions'; import { InternalDateMediator } from './helpers/InternalDateMediator'; -export interface DateInputState { +export type DateInputState = { selected: InternalDateComponentType | null; valueFormatted: string; inputMode: boolean; focused: boolean; dragged: boolean; -} +}; -export interface DateInputProps extends CommonProps, Partial { +export type DateInputProps = { autoFocus?: boolean; - value: string; /** * Cостояние валидации при ошибке. */ @@ -38,6 +37,22 @@ export interface DateInputProps extends CommonProps, Partial { */ warning?: boolean; disabled?: boolean; + withIcon?: boolean; + onBlur?: (x0: React.FocusEvent) => void; + onClick?: (x0: React.MouseEvent) => void; + onFocus?: (x0: React.FocusEvent) => void; + /** + * Вызывается при изменении `value` + * + * @param value - строка в формате `dd.mm.yyyy`. + */ + onValueChange?: (value: string) => void; + onKeyDown?: (x0: React.KeyboardEvent) => void; +} & CommonProps & + Partial; + +type DefaultProps = { + value: string; /** * Минимальная дата. * @default '01.01.1900' @@ -48,36 +63,17 @@ export interface DateInputProps extends CommonProps, Partial { * @default '31.12.2099' */ maxDate: string; - /** - * Ширина поля - * @default 125 - */ - width?: string | number; - withIcon?: boolean; /** * Размер поля * @default 'small' */ size: 'small' | 'large' | 'medium'; - onBlur?: (x0: React.FocusEvent) => void; - onClick?: (x0: React.MouseEvent) => void; - onFocus?: (x0: React.FocusEvent) => void; /** - * Вызывается при изменении `value` - * - * @param value - строка в формате `dd.mm.yyyy`. + * Ширина поля + * @default 125 */ - onValueChange?: (value: string) => void; - onKeyDown?: (x0: React.KeyboardEvent) => void; -} - -interface DefaultProps { - value: string; - minDate: string; - maxDate: string; - size: 'small' | 'large' | 'medium'; width: string | number; -} +}; type DateInputComponentProps = DateInputProps & DefaultProps; diff --git a/packages/react-ui/components/DatePicker/DatePicker.tsx b/packages/react-ui/components/DatePicker/DatePicker.tsx index 5a8c0fb32b5..9116bf660b9 100644 --- a/packages/react-ui/components/DatePicker/DatePicker.tsx +++ b/packages/react-ui/components/DatePicker/DatePicker.tsx @@ -30,7 +30,7 @@ const INPUT_PASS_PROPS = { export const MIN_WIDTH = 120; -export interface DatePickerProps extends CommonProps, Partial> { +export type DatePickerProps = { autoFocus?: boolean; disabled?: boolean; enableTodayLink?: boolean; @@ -38,8 +38,6 @@ export interface DatePickerProps extends CommonProps, Partial * Cостояние валидации при ошибке. */ error?: boolean; - minDate: T; - maxDate: T; menuAlign?: 'left' | 'right'; size?: 'small' | 'medium' | 'large'; value?: T | null; @@ -66,7 +64,17 @@ export interface DatePickerProps extends CommonProps, Partial * - На iOS нативный календарь не умеет работать с minDate и maxDate */ useMobileNativeDatePicker?: boolean; +} & CommonProps & + Partial>; + +export type DatePickerState = { + opened: boolean; + canUseMobileNativeDatePicker: boolean; +}; +type DefaultProps = { + minDate: T; + maxDate: T; /** * Функция для определения праздничных дней * @default (_day, isWeekend) => isWeekend @@ -76,18 +84,7 @@ export interface DatePickerProps extends CommonProps, Partial * @returns {boolean} `true` для выходного или `false` для рабочего дня */ isHoliday: (day: T, isWeekend: boolean) => boolean; -} - -export interface DatePickerState { - opened: boolean; - canUseMobileNativeDatePicker: boolean; -} - -interface DefaultProps { - minDate: T; - maxDate: T; - isHoliday: (day: T, isWeekend: boolean) => boolean; -} +}; type DatePickerComponentProps = DatePickerProps & DefaultProps; @@ -147,7 +144,7 @@ export class DatePicker extends React.PureComponent = { + public static defaultProps: DefaultProps = { minDate: MIN_FULLDATE, maxDate: MAX_FULLDATE, isHoliday: (_day: DatePickerValue, isWeekend: boolean) => isWeekend, diff --git a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx index a4e20f433bb..fbc8be297e0 100644 --- a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx +++ b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx @@ -9,7 +9,7 @@ import { PopupPositionsType } from '../../internal/Popup'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -export interface DropdownMenuProps extends CommonProps, Partial { +export type DropdownMenuProps = { /** Максимальная высота меню */ menuMaxHeight?: React.CSSProperties['maxWidth']; /** Ширина меню */ @@ -37,6 +37,16 @@ export interface DropdownMenuProps extends CommonProps, Partial { * Перед элементом переданным в `footer` будет отрендерен [`MenuSeparator`](#/Components/MenuSeparator). */ footer?: React.ReactNode; + onOpen?: () => void; + onClose?: () => void; +} & CommonProps & + Partial; + +type DefaultProps = { + /** + * Не показывать анимацию + */ + disableAnimations: boolean; /** * Список позиций доступных для расположения выпадашки относительно `caption`. * @@ -45,21 +55,8 @@ export interface DropdownMenuProps extends CommonProps, Partial { * **Возможные значения**: `top left`, `top center`, `top right`, `right top`, `right middle`, `right bottom`, `bottom left`, `bottom center`, `bottom right`, `left top`, `left middle`, `left bottom` * @default ['bottom left', 'bottom right', 'top left', 'top right'] */ - positions?: PopupPositionsType[]; - - onOpen?: () => void; - onClose?: () => void; - - /** - * Не показывать анимацию - */ - disableAnimations: boolean; -} - -interface DefaultProps { - disableAnimations: boolean; positions: PopupPositionsType[]; -} +}; type DropdownMenuComponentProps = DropdownMenuProps & DefaultProps; diff --git a/packages/react-ui/components/FxInput/FxInput.tsx b/packages/react-ui/components/FxInput/FxInput.tsx index 50b9f43aff9..9ba375e4381 100644 --- a/packages/react-ui/components/FxInput/FxInput.tsx +++ b/packages/react-ui/components/FxInput/FxInput.tsx @@ -10,33 +10,30 @@ import { FunctionIcon, UndoIcon } from '../../internal/icons/16px'; import { CommonWrapper, CommonProps, CommonWrapperRestProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -export type FxInputProps = Override< - CurrencyInputProps, - { - /** Авто-режим */ - auto?: boolean; - /** Тип инпута */ - type?: 'currency' | InputProps['type']; - /** onRestore */ - onRestore?: () => void; - /** onValueChange */ - onValueChange: CurrencyInputProps['onValueChange'] | InputProps['onValueChange']; - /** Значение */ - value?: React.ReactText; - /** ref Input'а */ - refInput?: (element: CurrencyInput | Input | null) => void; - /** Убрать лишние нули после запятой */ - hideTrailingZeros?: boolean; - } -> & - CommonProps & - Partial; - -interface DefaultProps { +type FxInputInterface = { + /** Авто-режим */ + auto?: boolean; + /** Тип инпута */ + type?: 'currency' | InputProps['type']; + /** onRestore */ + onRestore?: () => void; + /** onValueChange */ + onValueChange: CurrencyInputProps['onValueChange'] | InputProps['onValueChange']; + /** Значение */ + value?: React.ReactText; + /** ref Input'а */ + refInput?: (element: CurrencyInput | Input | null) => void; + /** Убрать лишние нули после запятой */ + hideTrailingZeros?: boolean; +}; + +export type FxInputProps = Override & CommonProps & Partial; + +type DefaultProps = { width: number | string; type: 'currency' | InputProps['type']; value: React.ReactText; -} +}; type FxInputComponentProps = FxInputProps & DefaultProps; diff --git a/packages/react-ui/components/Gapped/Gapped.tsx b/packages/react-ui/components/Gapped/Gapped.tsx index 80a1ba0a70d..ca4490baa29 100644 --- a/packages/react-ui/components/Gapped/Gapped.tsx +++ b/packages/react-ui/components/Gapped/Gapped.tsx @@ -7,35 +7,33 @@ import { Theme } from '../../lib/theming/Theme'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -export interface GappedProps extends CommonProps, Partial { +export type GappedProps = { /** * Расстояние между элементами в пикселях * @default 8 */ gap?: number; + children: React.ReactNode; +} & CommonProps & + Partial; + +type DefaultProps = { /** - * Вертикальное выравнивание - * @default "baseline" + * Перенос элементов на новую строку при горизонтальном расположении + * @default false */ - verticalAlign: 'top' | 'middle' | 'baseline' | 'bottom'; + wrap: boolean; /** * Расположение элементов по вертикали * @default false */ vertical: boolean; /** - * Перенос элементов на новую строку при горизонтальном расположении - * @default false + * Вертикальное выравнивание + * @default "baseline" */ - wrap: boolean; - children: React.ReactNode; -} - -interface DefaultProps { - wrap: boolean; - vertical: boolean; verticalAlign: 'top' | 'middle' | 'baseline' | 'bottom'; -} +}; type GappedComponentProps = GappedProps & DefaultProps; diff --git a/packages/react-ui/components/Hint/Hint.tsx b/packages/react-ui/components/Hint/Hint.tsx index 04fb9461afe..1870cb7e6db 100644 --- a/packages/react-ui/components/Hint/Hint.tsx +++ b/packages/react-ui/components/Hint/Hint.tsx @@ -15,18 +15,8 @@ import { styles } from './Hint.styles'; const HINT_BORDER_COLOR = 'transparent'; -export interface HintProps extends CommonProps, Partial { +export type HintProps = { children?: React.ReactNode; - /** - * Переводит отображение подсказки в _"ручной режим"_. - * - * В _"ручном режиме"_ подcказку можно активировать только задав значение пропу `opened`. - */ - manual?: boolean; - /** - * Задаёт максимальную ширину подсказки. - */ - maxWidth?: React.CSSProperties['maxWidth']; /** * HTML-событие `mouseenter`. */ @@ -36,11 +26,17 @@ export interface HintProps extends CommonProps, Partial { */ onMouseLeave?: (event: MouseEventType) => void; /** - * Если `true` - подсказка будет открыта. - * - * _Примечание_: работает только при `manual=true`. + * Текст подсказки. */ - opened?: boolean; + text: React.ReactNode; +} & CommonProps & + Partial; + +export type HintState = { + opened: boolean; +}; + +type DefaultProps = { /** * Расположение подсказки относительно текста. * @@ -48,9 +44,21 @@ export interface HintProps extends CommonProps, Partial { */ pos: 'top' | 'right' | 'bottom' | 'left' | PopupPositionsType; /** - * Текст подсказки. + * Переводит отображение подсказки в _"ручной режим"_. + * + * В _"ручном режиме"_ подcказку можно активировать только задав значение пропу `opened`. */ - text: React.ReactNode; + manual: boolean; + /** + * Если `true` - подсказка будет открыта. + * + * _Примечание_: работает только при `manual=true`. + */ + opened: boolean; + /** + * Задаёт максимальную ширину подсказки. + */ + maxWidth: React.CSSProperties['maxWidth']; /** * Отключает анимацию. */ @@ -61,20 +69,7 @@ export interface HintProps extends CommonProps, Partial { * _Примечание_: при **двух и более** вложенных элементах обёртка будет добавлена автоматически. */ useWrapper: boolean; -} - -export interface HintState { - opened: boolean; -} - -interface DefaultProps { - pos: 'top' | 'right' | 'bottom' | 'left' | PopupPositionsType; - manual: boolean; - opened: boolean; - maxWidth: React.CSSProperties['maxWidth']; - disableAnimations: boolean; - useWrapper: boolean; -} +}; type HintComponentProps = HintProps & DefaultProps; diff --git a/packages/react-ui/components/Input/Input.tsx b/packages/react-ui/components/Input/Input.tsx index f4b0ee8342e..463b71b17fe 100644 --- a/packages/react-ui/components/Input/Input.tsx +++ b/packages/react-ui/components/Input/Input.tsx @@ -20,96 +20,95 @@ export type InputAlign = 'left' | 'center' | 'right'; export type InputType = 'password' | 'text'; export type InputIconType = React.ReactNode | (() => React.ReactNode); -export type InputProps = Override< - React.InputHTMLAttributes, - { - /** - * Иконка слева - * Если `ReactNode` применяются дефолтные стили для иконки - * Если `() => ReactNode` применяются только стили для позиционирование - */ - leftIcon?: InputIconType; - /** - * Иконка справа - * Если `ReactNode` применяются дефолтные стили для иконки - * Если `() => ReactNode` применяются только стили для позиционирование - */ - rightIcon?: InputIconType; - /** - * Cостояние валидации при ошибке. - */ - error?: boolean; - /** - * Cостояние валидации при предупреждении. - */ - warning?: boolean; - /** Режим прозрачной рамки */ - borderless?: boolean; - /** Выравнивание текста */ - align?: InputAlign; - /** Паттерн маски */ - mask?: Nullable; - /** Символ маски */ - maskChar?: Nullable; - /** - * Словарь символов-регулярок для задания маски - * @default { '9': '[0-9]', 'a': '[A-Za-z]', '*': '[A-Za-z0-9]' } - */ - formatChars?: Record; - /** Показывать символы маски */ - alwaysShowMask?: boolean; - /** Размер */ - size?: InputSize; - /** onValueChange */ - onValueChange?: (value: string) => void; - /** Вызывается на label */ - onMouseEnter?: React.MouseEventHandler; - /** Вызывается на label */ - onMouseLeave?: React.MouseEventHandler; - /** Вызывается на label */ - onMouseOver?: React.MouseEventHandler; - /** Тип */ - type?: InputType; - /** Значение */ - value?: string; - capture?: boolean; - - /** - * Префикс - * `ReactNode` перед значением, но после иконки - */ - prefix?: React.ReactNode; - /** - * Суффикс - * `ReactNode` после значения, но перед правой иконкой - */ - suffix?: React.ReactNode; - /** Выделять введенное значение при фокусе */ - selectAllOnFocus?: boolean; - /** - * Обработчик неправильного ввода. - * По-умолчанию, инпут вспыхивает синим. - * Если передан - вызывается переданный обработчик, - * в таком случае вспыхивание можно вызвать - * публичным методом инстанса `blink()`. - * - * @param value значение инпута. - */ - onUnexpectedInput?: (value: string) => void; - } -> & +type InputInterface = { + /** + * Иконка слева + * Если `ReactNode` применяются дефолтные стили для иконки + * Если `() => ReactNode` применяются только стили для позиционирование + */ + leftIcon?: InputIconType; + /** + * Иконка справа + * Если `ReactNode` применяются дефолтные стили для иконки + * Если `() => ReactNode` применяются только стили для позиционирование + */ + rightIcon?: InputIconType; + /** + * Cостояние валидации при ошибке. + */ + error?: boolean; + /** + * Cостояние валидации при предупреждении. + */ + warning?: boolean; + /** Режим прозрачной рамки */ + borderless?: boolean; + /** Выравнивание текста */ + align?: InputAlign; + /** Паттерн маски */ + mask?: Nullable; + /** Символ маски */ + maskChar?: Nullable; + /** + * Словарь символов-регулярок для задания маски + * @default { '9': '[0-9]', 'a': '[A-Za-z]', '*': '[A-Za-z0-9]' } + */ + formatChars?: Record; + /** Показывать символы маски */ + alwaysShowMask?: boolean; + /** Размер */ + size?: InputSize; + /** onValueChange */ + onValueChange?: (value: string) => void; + /** Вызывается на label */ + onMouseEnter?: React.MouseEventHandler; + /** Вызывается на label */ + onMouseLeave?: React.MouseEventHandler; + /** Вызывается на label */ + onMouseOver?: React.MouseEventHandler; + /** Тип */ + type?: InputType; + /** Значение */ + value?: string; + capture?: boolean; + + /** + * Префикс + * `ReactNode` перед значением, но после иконки + */ + prefix?: React.ReactNode; + /** + * Суффикс + * `ReactNode` после значения, но перед правой иконкой + */ + suffix?: React.ReactNode; + /** Выделять введенное значение при фокусе */ + selectAllOnFocus?: boolean; + /** + * Обработчик неправильного ввода. + * По-умолчанию, инпут вспыхивает синим. + * Если передан - вызывается переданный обработчик, + * в таком случае вспыхивание можно вызвать + * публичным методом инстанса `blink()`. + * + * @param value значение инпута. + */ + onUnexpectedInput?: (value: string) => void; +}; + +export type InputProps = Override, InputInterface> & CommonProps & Partial; -export interface InputState { +export type InputState = { blinking: boolean; focused: boolean; polyfillPlaceholder: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { size: InputSize; -} +}; type InputComponentProps = InputProps & DefaultProps; @@ -150,7 +149,7 @@ export class Input extends React.Component { this.cancelDelayedSelectAll(); } - public static getDerivedStateFromProps(props: InputProps, state: InputState) { + public static getDerivedStateFromProps(props: InputComponentProps, state: InputState) { if (polyfillPlaceholder && !props.value) { return { polyfillPlaceholder: true }; } @@ -268,7 +267,7 @@ export class Input extends React.Component { } }; - private renderMain = (props: CommonWrapperRestProps) => { + private renderMain = (props: CommonWrapperRestProps) => { const { onMouseEnter, onMouseLeave, diff --git a/packages/react-ui/components/Kebab/Kebab.tsx b/packages/react-ui/components/Kebab/Kebab.tsx index ab85f08a092..76a8adcb2e3 100644 --- a/packages/react-ui/components/Kebab/Kebab.tsx +++ b/packages/react-ui/components/Kebab/Kebab.tsx @@ -18,19 +18,29 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { styles } from './Kebab.styles'; -export interface KebabProps extends CommonProps, Partial { +export type KebabProps = { disabled?: boolean; + menuMaxHeight?: number | string; +} & CommonProps & + Partial; + +export type KebabState = { + anchor: Nullable; + focusedByTab: boolean; + opened: boolean; +}; + +type DefaultProps = { /** - * Функция вызываемая при закрытии выпадашки + * Функция вызываемая при открытии выпадашки * @default () => undefined */ - onClose: () => void; + onOpen: () => void; /** - * Функция вызываемая при открытии выпадашки + * Функция вызываемая при закрытии выпадашки * @default () => undefined */ - onOpen: () => void; - size: 'small' | 'medium' | 'large'; + onClose: () => void; /** * Список позиций доступных для расположения выпадашки. * @@ -40,7 +50,7 @@ export interface KebabProps extends CommonProps, Partial { * @default ['bottom left', 'bottom right', 'top left', 'top right'] */ positions: PopupPositionsType[]; - menuMaxHeight?: number | string; + size: 'small' | 'medium' | 'large'; /** * Не показывать анимацию */ @@ -48,23 +58,8 @@ export interface KebabProps extends CommonProps, Partial { /** * Кастомная иконка */ - icon?: React.ReactNode; -} - -export interface KebabState { - anchor: Nullable; - focusedByTab: boolean; - opened: boolean; -} - -interface DefaultProps { - onOpen: () => void; - onClose: () => void; - positions: PopupPositionsType[]; - size: 'small' | 'medium' | 'large'; - disableAnimations: boolean; icon: React.ReactNode; -} +}; type KebabComponentProps = KebabProps & DefaultProps; diff --git a/packages/react-ui/components/Link/Link.tsx b/packages/react-ui/components/Link/Link.tsx index ebd68eed91e..0eace2e443b 100644 --- a/packages/react-ui/components/Link/Link.tsx +++ b/packages/react-ui/components/Link/Link.tsx @@ -13,58 +13,57 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode/rootNodeDecorator'; import { styles } from './Link.styles'; -export type LinkProps = Override< - React.AnchorHTMLAttributes, - { - /** - * Отключенное состояние. - */ - disabled?: boolean; - /** - * HTML-атрибут `href`. - */ - href?: string; - /** - * Добавляет ссылке иконку. - */ - icon?: React.ReactElement; - /** - * Тема ссылки. - */ - use?: 'default' | 'success' | 'danger' | 'grayed'; - /** - * @ignore - */ - _button?: boolean; - /** - * @ignore - */ - _buttonOpened?: boolean; - /** - * HTML-атрибут `tabindex`. - */ - tabIndex?: number; - /** - * Переводит ссылку в состояние загрузки. - */ - loading?: boolean; - /** - * HTML-событие `onclick`. - */ - onClick?: (event: React.MouseEvent) => void; - } -> & +type LinkInterface = { + /** + * Отключенное состояние. + */ + disabled?: boolean; + /** + * HTML-атрибут `href`. + */ + href?: string; + /** + * Добавляет ссылке иконку. + */ + icon?: React.ReactElement; + /** + * Тема ссылки. + */ + use?: 'default' | 'success' | 'danger' | 'grayed'; + /** + * @ignore + */ + _button?: boolean; + /** + * @ignore + */ + _buttonOpened?: boolean; + /** + * HTML-атрибут `tabindex`. + */ + tabIndex?: number; + /** + * Переводит ссылку в состояние загрузки. + */ + loading?: boolean; + /** + * HTML-событие `onclick`. + */ + onClick?: (event: React.MouseEvent) => void; +}; + +export type LinkProps = Override, LinkInterface> & CommonProps & Partial; -export interface LinkState { +export type LinkState = { focusedByTab: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { href: string; use: 'default' | 'success' | 'danger' | 'grayed'; -} +}; type LinkComponentProps = LinkProps & DefaultProps; diff --git a/packages/react-ui/components/Loader/Loader.tsx b/packages/react-ui/components/Loader/Loader.tsx index a29537298f0..69ad1a6e5f5 100644 --- a/packages/react-ui/components/Loader/Loader.tsx +++ b/packages/react-ui/components/Loader/Loader.tsx @@ -17,45 +17,42 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { styles } from './Loader.styles'; -export interface LoaderProps extends CommonProps, Partial { +export type LoaderProps = { children?: React.ReactNode; - /** - * Флаг переключения состояния лоадера - * @default false - */ - active: boolean; caption?: SpinnerProps['caption']; /** * Компонент заменяющий спиннер. */ component?: React.ReactNode; className?: string; - type?: 'mini' | 'normal' | 'big'; - /** - * Время в миллисекундах для показа вуали без спиннера. - * @default 300 - */ - delayBeforeSpinnerShow: number; - /** - * Минимальное время в миллисекундах для показа спиннера - * @default 1000 - */ - minimalDelayBeforeSpinnerHide: number; -} +} & CommonProps & + Partial; -export interface LoaderState { +export type LoaderState = { isStickySpinner: boolean; isSpinnerVisible: boolean; isLoaderActive: boolean; spinnerStyle?: object; -} +}; -interface DefaultProps { +type DefaultProps = { type: 'mini' | 'normal' | 'big'; + /** + * Флаг переключения состояния лоадера + * @default false + */ active: boolean; + /** + * Время в миллисекундах для показа вуали без спиннера. + * @default 300 + */ delayBeforeSpinnerShow: number; + /** + * Минимальное время в миллисекундах для показа спиннера + * @default 1000 + */ minimalDelayBeforeSpinnerHide: number; -} +}; export type LoaderComponentProps = LoaderProps & DefaultProps; diff --git a/packages/react-ui/components/Modal/Modal.tsx b/packages/react-ui/components/Modal/Modal.tsx index cb501ba5ccd..51f77bec1ca 100644 --- a/packages/react-ui/components/Modal/Modal.tsx +++ b/packages/react-ui/components/Modal/Modal.tsx @@ -24,7 +24,7 @@ import { styles } from './Modal.styles'; let mountedModalsCount = 0; -export interface ModalProps extends CommonProps, Partial { +export type ModalProps = { /** * Отключает событие onClose, также дизейблит кнопку закрытия модалки */ @@ -51,26 +51,25 @@ export interface ModalProps extends CommonProps, Partial { * Escape или на крестик). */ onClose?: () => void; +} & CommonProps & + Partial; - /** - * Не использовать фокус-лок внутри модалки. - * По умолчанию true для IE11. - */ - disableFocusLock?: boolean; -} - -export interface ModalState { +export type ModalState = { stackPosition: number; hasBackground: boolean; horizontalScroll: boolean; hasHeader: boolean; hasFooter: boolean; hasPanel: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { + /** + * Не использовать фокус-лок внутри модалки. + * По умолчанию true для IE11. + */ disableFocusLock: boolean; -} +}; type ModalComponentProps = ModalProps & DefaultProps; diff --git a/packages/react-ui/components/Paging/Paging.tsx b/packages/react-ui/components/Paging/Paging.tsx index dc058b76e1e..d03009c1a06 100644 --- a/packages/react-ui/components/Paging/Paging.tsx +++ b/packages/react-ui/components/Paging/Paging.tsx @@ -21,22 +21,17 @@ import { PagingLocale, PagingLocaleHelper } from './locale'; const IGNORE_EVENT_TAGS = ['input', 'textarea']; -interface ItemComponentProps { +type ItemComponentProps = { active: boolean; children?: React.ReactNode; className: string; onClick: () => void; pageNumber: number | 'forward'; tabIndex: number; -} +}; -export interface PagingProps extends CommonProps, Partial { +export type PagingProps = { activePage: number; - /** - * Компонент обертки по умолчанию - * @default - */ - component: React.ComponentType; onPageChange: (pageNumber: number) => void; pagesCount: number; disabled?: boolean; @@ -47,28 +42,32 @@ export interface PagingProps extends CommonProps, Partial { */ withoutNavigationHint?: boolean; caption?: string; - /** - * Глобальный слушатель **keyDown**, для навигации клавишами без фокуса на компоненте. - * Если на странице используется несколько элементов - * **Paging** с useGlobalListener === true, то обработчик keyDown будет вызываться - * на каждом из них. Такие случаи лучше обрабатывать отдельно. - */ - useGlobalListener: boolean; -} +} & CommonProps & + Partial; -export interface PagingState { +export type PagingState = { focusedByTab: boolean; focusedItem: Nullable; keyboardControl: boolean; -} +}; export type ItemType = number | '.' | 'forward'; -interface DefaultProps { +type DefaultProps = { + /** + * Компонент обертки по умолчанию + * @default + */ component: React.ComponentType; + /** + * Глобальный слушатель **keyDown**, для навигации клавишами без фокуса на компоненте. + * Если на странице используется несколько элементов + * **Paging** с useGlobalListener === true, то обработчик keyDown будет вызываться + * на каждом из них. Такие случаи лучше обрабатывать отдельно. + */ useGlobalListener: boolean; ['data-tid']: string; -} +}; type PagingComponentProps = PagingProps & DefaultProps; diff --git a/packages/react-ui/components/PasswordInput/PasswordInput.tsx b/packages/react-ui/components/PasswordInput/PasswordInput.tsx index 035d61c952c..f63c3dbb9e4 100644 --- a/packages/react-ui/components/PasswordInput/PasswordInput.tsx +++ b/packages/react-ui/components/PasswordInput/PasswordInput.tsx @@ -15,18 +15,20 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { styles } from './PasswordInput.styles'; -export interface PasswordInputProps extends CommonProps, InputProps, Partial { +export type PasswordInputProps = { detectCapsLock?: boolean; -} +} & CommonProps & + InputProps & + Partial; -export interface PasswordInputState { +export type PasswordInputState = { visible: boolean; capsLockEnabled?: boolean | null; -} +}; -interface DefaultProps { +type DefaultProps = { size: InputProps['size']; -} +}; type PasswordInputComponentProps = PasswordInputProps & DefaultProps; diff --git a/packages/react-ui/components/Radio/Radio.tsx b/packages/react-ui/components/Radio/Radio.tsx index 834e36d708e..9f0bea7695e 100644 --- a/packages/react-ui/components/Radio/Radio.tsx +++ b/packages/react-ui/components/Radio/Radio.tsx @@ -12,53 +12,52 @@ import { RadioGroupContext, RadioGroupContextType } from '../RadioGroup/RadioGro import { styles, globalClasses } from './Radio.styles'; -export type RadioProps = Override< - React.InputHTMLAttributes, - { - /** - * Cостояние валидации при ошибке. - */ - error?: boolean; - /** - * Cостояние валидации при предупреждении. - */ - warning?: boolean; - /** - * Состояние фокуса. - */ - focused?: boolean; - /** - * Функция, вызываемая при изменении `value`. - */ - onValueChange?: (value: T) => void; - /** - * HTML-событие `onmouseenter` - */ - onMouseEnter?: React.MouseEventHandler; - /** - * HTML-событие `mouseleave` - */ - onMouseLeave?: React.MouseEventHandler; - /** - * HTML-событие `onmouseover` - */ - onMouseOver?: React.MouseEventHandler; - /** - * HTML-атрибут `value`. - */ - value: T; - } -> & +type RadioInterface = { + /** + * Cостояние валидации при ошибке. + */ + error?: boolean; + /** + * Cостояние валидации при предупреждении. + */ + warning?: boolean; + /** + * Состояние фокуса. + */ + focused?: boolean; + /** + * Функция, вызываемая при изменении `value`. + */ + onValueChange?: (value: T) => void; + /** + * HTML-событие `onmouseenter` + */ + onMouseEnter?: React.MouseEventHandler; + /** + * HTML-событие `mouseleave` + */ + onMouseLeave?: React.MouseEventHandler; + /** + * HTML-событие `onmouseover` + */ + onMouseOver?: React.MouseEventHandler; + /** + * HTML-атрибут `value`. + */ + value: T; +}; + +export type RadioProps = Override, RadioInterface> & CommonProps & Partial; -export interface RadioState { +export type RadioState = { focusedByKeyboard: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { focused: boolean; -} +}; type RadioComponentProps = RadioProps & DefaultProps; diff --git a/packages/react-ui/components/RadioGroup/RadioGroup.tsx b/packages/react-ui/components/RadioGroup/RadioGroup.tsx index f2fc5488983..31ef1ff31c4 100644 --- a/packages/react-ui/components/RadioGroup/RadioGroup.tsx +++ b/packages/react-ui/components/RadioGroup/RadioGroup.tsx @@ -16,7 +16,7 @@ import { styles } from './RadioGroup.styles'; import { Prevent } from './Prevent'; import { RadioGroupContext, RadioGroupContextType } from './RadioGroupContext'; -export interface RadioGroupProps extends CommonProps, Partial> { +export type RadioGroupProps = { /** * Значение по умолчанию. Должно быть одним из значений дочерних радиокнопок * или значений из параметра `items` @@ -62,29 +62,29 @@ export interface RadioGroupProps extends CommonProps, Parti * Ширина радиогруппы. Не работает с `children` */ width?: React.CSSProperties['width']; - /** - * Метод отрисовки контента радиокнопки. Не работает с `children`. - * - * Принимает два аргумента: `(value: Value, data: Data) => React.Node` - */ - renderItem?: (itemValue: T, data: React.ReactNode) => React.ReactNode; /** Вызывается при изменении `value` */ onValueChange?: (value: T) => void; onBlur?: (event: FocusEvent) => void; onMouseLeave?: () => any; onMouseOver?: () => any; onMouseEnter?: () => any; -} +} & CommonProps & + Partial>; -export interface RadioGroupState { +export type RadioGroupState = { activeItem?: T; -} +}; type RadioGroupComponentProps = RadioGroupProps & DefaultProps; -interface DefaultProps { +type DefaultProps = { + /** + * Метод отрисовки контента радиокнопки. Не работает с `children`. + * + * Принимает два аргумента: `(value: Value, data: Data) => React.Node` + */ renderItem: (itemValue: T, data: React.ReactNode) => React.ReactNode; -} +}; /** * @@ -113,7 +113,7 @@ export class RadioGroup extends React.Component, onMouseOver: PropTypes.func, }; - public static defaultProps: DefaultProps = { + public static defaultProps: DefaultProps = { renderItem, }; diff --git a/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx b/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx index 86af6bc0c3e..a02a26b403d 100644 --- a/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx +++ b/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx @@ -22,34 +22,29 @@ export type ScrollContainerScrollStateY = 'top' | 'scroll' | 'bottom'; export type ScrollContainerScrollState = ScrollContainerScrollStateY; // deprecated export type ScrollBehaviour = 'auto' | 'smooth'; -export interface ScrollContainerProps extends CommonProps, Partial { - /** - * Инвертировать цвет скроллбара - * @default false - */ - invert: boolean; +export type ScrollContainerProps = { maxHeight?: React.CSSProperties['maxHeight']; maxWidth?: React.CSSProperties['maxWidth']; + onScrollStateChangeX?: (scrollState: ScrollContainerScrollStateX) => void; + onScrollStateChangeY?: (scrollState: ScrollContainerScrollStateY) => void; + onScrollStateChange?: (scrollYState: ScrollContainerScrollState) => void; // deprecated + onScroll?: (e: React.UIEvent) => void; +} & CommonProps & + Partial; + +type DefaultProps = { /** + * Инвертировать цвет скроллбара * @default false */ - preventWindowScroll: boolean; + invert: boolean; /** * Поведение скролла (https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior) * @default 'auto' */ - scrollBehaviour?: ScrollBehaviour; - onScrollStateChangeX?: (scrollState: ScrollContainerScrollStateX) => void; - onScrollStateChangeY?: (scrollState: ScrollContainerScrollStateY) => void; - onScrollStateChange?: (scrollYState: ScrollContainerScrollState) => void; // deprecated - onScroll?: (e: React.UIEvent) => void; -} - -interface DefaultProps { - invert: boolean; scrollBehaviour: ScrollBehaviour; preventWindowScroll: boolean; -} +}; type ScrollContainerComponentProps = ScrollContainerProps & DefaultProps; diff --git a/packages/react-ui/components/Select/Select.tsx b/packages/react-ui/components/Select/Select.tsx index 3421d8e85dc..7305e32162e 100644 --- a/packages/react-ui/components/Select/Select.tsx +++ b/packages/react-ui/components/Select/Select.tsx @@ -34,14 +34,14 @@ import { SelectLocale, SelectLocaleHelper } from './locale'; import { styles } from './Select.styles'; import { getSelectTheme } from './selectTheme'; -export interface ButtonParams { +export type ButtonParams = { disabled?: boolean; label: React.ReactNode; onClick: () => void; onKeyDown: (event: React.KeyboardEvent) => void; opened: boolean; isPlaceholder: boolean; -} +}; const PASS_BUTTON_PROPS = { disabled: true, @@ -55,7 +55,7 @@ const PASS_BUTTON_PROPS = { onMouseOver: true, }; -export interface SelectProps extends CommonProps, Partial> { +export type SelectProps = { /** @ignore */ _icon?: React.ReactNode; /** @ignore */ @@ -70,7 +70,6 @@ export interface SelectProps extends CommonProps, Partial boolean; /** * Набор значений. Поддерживаются любые перечисляемые типы, в том числе * `Array`, `Map`, `Immutable.Map`. @@ -108,19 +107,6 @@ export interface SelectProps extends CommonProps, Partial) => void; onOpen?: () => void; placeholder?: React.ReactNode; - /** - * Функция для отрисовки элемента в выпадающем списке. Аргументы — *value*, - * *item*. - */ - renderItem?: (value: TValue, item?: TItem) => React.ReactNode; - /** - * Функция для отрисовки выбранного элемента. Аргументы — *value*, *item*. - */ - renderValue?: (value: Nullable, item?: TItem) => React.ReactNode; - /** - * Функция для сравнения `value` с элементом из `items` - */ - areValuesEqual?: (value1: Nullable, value2: Nullable) => boolean; /** * Показывать строку поиска в списке. */ @@ -131,29 +117,39 @@ export interface SelectProps extends CommonProps, Partial; onBlur?: React.FocusEventHandler; -} +} & CommonProps & + Partial>; -export interface SelectState { +export type SelectState = { opened: boolean; searchPattern: string; value: Nullable; -} +}; -interface FocusableReactElement extends React.ReactElement { +type FocusableReactElement = { focus: (event?: any) => void; -} +} & React.ReactElement; -interface DefaultProps { +type DefaultProps = { + /** + * Функция для отрисовки выбранного элемента. Аргументы — *value*, *item*. + */ renderValue: (value: Nullable, item?: TItem) => React.ReactNode; + /** + * Функция для отрисовки элемента в выпадающем списке. Аргументы — *value*, + * *item*. + */ renderItem: (value: TValue, item?: TItem) => React.ReactNode; + /** + * Функция для сравнения `value` с элементом из `items` + */ areValuesEqual: (value1: Nullable, value: Nullable) => boolean; filterItem: (value: TValue, item: TItem, pattern: string) => boolean; use: ButtonUse; -} +}; type SelectComponentProps = SelectProps & DefaultProps; @@ -188,7 +184,7 @@ export class Select extends React.Component< onKeyDown: PropTypes.func, }; - public static defaultProps: DefaultProps = { + public static defaultProps: DefaultProps = { renderValue, renderItem, areValuesEqual, diff --git a/packages/react-ui/components/SidePage/SidePage.tsx b/packages/react-ui/components/SidePage/SidePage.tsx index e66d2806ead..910eb6d202b 100644 --- a/packages/react-ui/components/SidePage/SidePage.tsx +++ b/packages/react-ui/components/SidePage/SidePage.tsx @@ -23,7 +23,7 @@ import { SidePageFooter } from './SidePageFooter'; import { SidePageHeader } from './SidePageHeader'; import { styles } from './SidePage.styles'; -export interface SidePageProps extends CommonProps, Partial { +export type SidePageProps = { /** * Добавить блокирующий фон, когда сайдпейдж открыт */ @@ -55,39 +55,34 @@ export interface SidePageProps extends CommonProps, Partial { * */ fromLeft?: boolean; +} & CommonProps & + Partial; +export type SidePageState = { + stackPosition?: number; + hasMargin?: boolean; + hasShadow?: boolean; + hasBackground?: boolean; + hasHeader: boolean; + hasFooter: boolean; + hasPanel: boolean; +}; + +type DefaultProps = { /** * Отключить анимации * */ - disableAnimations?: boolean; - + disableAnimations: boolean; /** * Работает только при заблокированном фоне: `blockBackground = true` */ disableFocusLock: boolean; - /** * задает отступ от края экрана */ - offset?: number | string; -} - -export interface SidePageState { - stackPosition?: number; - hasMargin?: boolean; - hasShadow?: boolean; - hasBackground?: boolean; - hasHeader: boolean; - hasFooter: boolean; - hasPanel: boolean; -} - -interface DefaultProps { - disableAnimations: boolean; - disableFocusLock: boolean; offset: number | string; -} +}; type SidePageComponentProps = SidePageProps & DefaultProps; diff --git a/packages/react-ui/components/Spinner/Spinner.tsx b/packages/react-ui/components/Spinner/Spinner.tsx index 9e6f374a36d..6b779d01b0a 100644 --- a/packages/react-ui/components/Spinner/Spinner.tsx +++ b/packages/react-ui/components/Spinner/Spinner.tsx @@ -20,14 +20,9 @@ const types: Record = { export type SpinnerType = 'mini' | 'normal' | 'big'; -export interface SpinnerProps extends CommonProps, Partial { +export type SpinnerProps = { caption?: React.ReactNode; dimmed?: boolean; - /** - * Тип спиннера - * @default normal - */ - type: SpinnerType; /** * Толщина спиннера */ @@ -36,11 +31,16 @@ export interface SpinnerProps extends CommonProps, Partial { * Цвет спиннера */ color?: React.CSSProperties['color']; -} +} & CommonProps & + Partial; -interface DefaultProps { +type DefaultProps = { + /** + * Тип спиннера + * @default normal + */ type: SpinnerType; -} +}; type SpinnerComponentProps = SpinnerProps & DefaultProps; @@ -82,7 +82,7 @@ export class Spinner extends React.Component { private readonly locale!: SpinnerLocale; private setRootNode!: TSetRootNode; - constructor(props: SpinnerProps) { + constructor(props: SpinnerComponentProps) { super(props); } diff --git a/packages/react-ui/components/Sticky/Sticky.tsx b/packages/react-ui/components/Sticky/Sticky.tsx index 1fdf6adb2f6..9ec7ac290c1 100644 --- a/packages/react-ui/components/Sticky/Sticky.tsx +++ b/packages/react-ui/components/Sticky/Sticky.tsx @@ -14,18 +14,14 @@ import { styles } from './Sticky.styles'; const MAX_REFLOW_RETRIES = 5; -export interface StickyProps extends CommonProps, Partial { +export type StickyProps = { side: 'top' | 'bottom'; - /** - * Отступ в пикселях от края экрана, на сколько сдвигается элемент в залипшем состоянии - * @default 0 - */ - offset: number; getStop?: () => Nullable; children?: React.ReactNode | ((fixed: boolean) => React.ReactNode); -} +} & CommonProps & + Partial; -export interface StickyState { +export type StickyState = { fixed: boolean; deltaHeight: number; height?: number; @@ -33,11 +29,15 @@ export interface StickyState { left?: number; stopped: boolean; relativeTop: number; -} +}; -interface DefaultProps { +type DefaultProps = { + /** + * Отступ в пикселях от края экрана, на сколько сдвигается элемент в залипшем состоянии + * @default 0 + */ offset: number; -} +}; type StickyComponentProps = StickyProps & DefaultProps; diff --git a/packages/react-ui/components/Tabs/Tab.tsx b/packages/react-ui/components/Tabs/Tab.tsx index bd2c6f7a0ce..601a8eac24b 100644 --- a/packages/react-ui/components/Tabs/Tab.tsx +++ b/packages/react-ui/components/Tabs/Tab.tsx @@ -16,30 +16,20 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { TabsContext, TabsContextType, TabsContextDefaultValue } from './TabsContext'; import { styles, horizontalStyles, verticalStyles, globalClasses } from './Tab.styles'; -export interface TabIndicators { +export type TabIndicators = { error: boolean; warning: boolean; success: boolean; primary: boolean; disabled: boolean; -} +}; -export interface TabProps extends CommonProps, Partial { +export type TabProps = { /** * Tab content */ children?: React.ReactNode; - /** - * Component to use as a tab - */ - component?: React.ComponentType | string; - - /** - * Link href - */ - href?: string; - /** * Tab identifier */ @@ -84,16 +74,23 @@ export interface TabProps extends CommonProps, Partia * Style property */ style?: React.CSSProperties; -} +} & CommonProps & + Partial; -export interface TabState { +export type TabState = { focusedByKeyboard: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { + /** + * Component to use as a tab + */ component: React.ComponentType | string; + /** + * Link href + */ href: string; -} +}; type TabsComponentProps = TabProps & DefaultProps; diff --git a/packages/react-ui/components/Tabs/Tabs.tsx b/packages/react-ui/components/Tabs/Tabs.tsx index 4bd2ceb4d52..32f4e90e284 100644 --- a/packages/react-ui/components/Tabs/Tabs.tsx +++ b/packages/react-ui/components/Tabs/Tabs.tsx @@ -13,7 +13,7 @@ import { styles } from './Tabs.styles'; import { TabsContext, TabsContextType } from './TabsContext'; import { Tab } from './Tab'; -export interface TabsProps extends CommonProps, Partial { +export type TabsProps = { /** * Tab component should be child of Tabs component */ @@ -34,21 +34,20 @@ export interface TabsProps extends CommonProps, Parti */ value: T; - /** - * Vertical indicator - * @default false - */ - vertical: boolean; - /** * Width of tabs container */ width?: number | string; -} +} & CommonProps & + Partial; -interface DefaultProps { +type DefaultProps = { + /** + * Vertical indicator + * @default false + */ vertical: boolean; -} +}; type TabsComponentProps = TabsProps & DefaultProps; diff --git a/packages/react-ui/components/Textarea/Textarea.tsx b/packages/react-ui/components/Textarea/Textarea.tsx index 9a5cd2f9f66..6f6dfd6bdee 100644 --- a/packages/react-ui/components/Textarea/Textarea.tsx +++ b/packages/react-ui/components/Textarea/Textarea.tsx @@ -24,99 +24,98 @@ import { TextareaCounter, TextareaCounterRef } from './TextareaCounter'; const DEFAULT_WIDTH = 250; const AUTORESIZE_THROTTLE_DEFAULT_WAIT = 100; -export type TextareaProps = Override< - React.TextareaHTMLAttributes, - { - /** - * Cостояние валидации при ошибке. - */ - error?: boolean; - /** - * Cостояние валидации при предупреждении. - */ - warning?: boolean; - /** Не активное состояние */ - disabled?: boolean; - - /** - * Атоматический ресайз - * в зависимости от содержимого - */ - autoResize?: boolean; - /** - * Число строк - */ - rows: number; - /** - * Максимальное число строк при - * автоматическом ресайзе - */ - maxRows: string | number; - - /** - * Стандартный ресайз - * Попадает в `style` - */ - resize?: React.CSSProperties['resize']; - - /** - * Ширина - */ - width?: React.CSSProperties['width']; - - /** - * Вызывается при изменении `value` - */ - onValueChange?: (value: string) => void; - - /** Выделение значения при фокусе */ - selectAllOnFocus?: boolean; - - /** Показывать счетчик символов */ - showLengthCounter?: boolean; - - /** Допустимое количество символов в поле. Отображается в счетчике. - * Если не указано, равно `maxLength` - */ - lengthCounter?: number; - - /** Подсказка к счетчику символов. - * - * По умолчанию - тултип с содежимым из пропа, если передан`ReactNode`. - * - * Передав функцию, можно переопределить подсказку целиком, вместе с иконкой. Например, - * - * ``` - * counterHelp={() => } - * ``` - * */ - counterHelp?: ReactNode | (() => ReactNode); - - /** Добавлять дополнительную свободную строку при авто-ресайзе. - * @see https://guides.kontur.ru/components/textarea/#04 - * */ - extraRow: boolean; - - /** Отключать анимацию при авто-ресайзе. - * Автоматически отключается когда в `extraRow` передан `false`. - */ - disableAnimations: boolean; - } -> & +type TextareaInterface = { + /** + * Cостояние валидации при ошибке. + */ + error?: boolean; + /** + * Cостояние валидации при предупреждении. + */ + warning?: boolean; + /** Не активное состояние */ + disabled?: boolean; + + /** + * Атоматический ресайз + * в зависимости от содержимого + */ + autoResize?: boolean; + /** + * Число строк + */ + rows: number; + /** + * Максимальное число строк при + * автоматическом ресайзе + */ + maxRows: string | number; + + /** + * Стандартный ресайз + * Попадает в `style` + */ + resize?: React.CSSProperties['resize']; + + /** + * Ширина + */ + width?: React.CSSProperties['width']; + + /** + * Вызывается при изменении `value` + */ + onValueChange?: (value: string) => void; + + /** Выделение значения при фокусе */ + selectAllOnFocus?: boolean; + + /** Показывать счетчик символов */ + showLengthCounter?: boolean; + + /** Допустимое количество символов в поле. Отображается в счетчике. + * Если не указано, равно `maxLength` + */ + lengthCounter?: number; + + /** Подсказка к счетчику символов. + * + * По умолчанию - тултип с содежимым из пропа, если передан`ReactNode`. + * + * Передав функцию, можно переопределить подсказку целиком, вместе с иконкой. Например, + * + * ``` + * counterHelp={() => } + * ``` + * */ + counterHelp?: ReactNode | (() => ReactNode); + + /** Добавлять дополнительную свободную строку при авто-ресайзе. + * @see https://guides.kontur.ru/components/textarea/#04 + * */ + extraRow: boolean; + + /** Отключать анимацию при авто-ресайзе. + * Автоматически отключается когда в `extraRow` передан `false`. + */ + disableAnimations: boolean; +}; + +export type TextareaProps = Override, TextareaInterface> & CommonProps & Partial; -export interface TextareaState { +export type TextareaState = { polyfillPlaceholder: boolean; isCounterVisible: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { rows: number; maxRows: string | number; extraRow: boolean; disableAnimations: boolean; -} +}; type TextareaComponentProps = TextareaProps & DefaultProps; diff --git a/packages/react-ui/components/Toggle/Toggle.tsx b/packages/react-ui/components/Toggle/Toggle.tsx index f8924361c17..8bd61b06954 100644 --- a/packages/react-ui/components/Toggle/Toggle.tsx +++ b/packages/react-ui/components/Toggle/Toggle.tsx @@ -13,13 +13,8 @@ import { styles, globalClasses } from './Toggle.styles'; let colorWarningShown = false; -export interface ToggleProps extends CommonProps, Partial { +export type ToggleProps = { children?: React.ReactNode; - /** - * Положение `children` относительно переключателя. - * @default 'right' - */ - captionPosition: 'left' | 'right'; /** * Состояние `тогла`, если `true` - `тогл` будет включён, иначе выключен. * @default false @@ -29,10 +24,6 @@ export interface ToggleProps extends CommonProps, Partial { * Делает `тогл` включенным по умолчанию. */ defaultChecked?: boolean; - /** - * Отключает `тогл`. - */ - disabled?: boolean; /** * Событие вызывающееся, когда значение `тогла` меняется, передаёт текущее значение тогла в переданную функцию. */ @@ -51,10 +42,6 @@ export interface ToggleProps extends CommonProps, Partial { * @default false */ error?: boolean; - /** - * Добавляет стили для состояния `loading` и отключает `тогл`. - */ - loading?: boolean; /** * Если true, выставляет фокус на `тогле` после загрузки страницы. */ @@ -75,18 +62,29 @@ export interface ToggleProps extends CommonProps, Partial { * HTML-атрибут `id` для передачи во внутренний ``. */ id?: string; -} +} & CommonProps & + Partial; -export interface ToggleState { +export type ToggleState = { checked?: boolean; focusByTab?: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { + /** + * Отключает `тогл`. + */ disabled: boolean; + /** + * Добавляет стили для состояния `loading` и отключает `тогл`. + */ loading: boolean; + /** + * Положение `children` относительно переключателя. + * @default 'right' + */ captionPosition: 'left' | 'right'; -} +}; type ToggleComponentProps = ToggleProps & DefaultProps; diff --git a/packages/react-ui/components/TokenInput/TokenInput.tsx b/packages/react-ui/components/TokenInput/TokenInput.tsx index 89fb863f1bd..802a2c54446 100644 --- a/packages/react-ui/components/TokenInput/TokenInput.tsx +++ b/packages/react-ui/components/TokenInput/TokenInput.tsx @@ -41,26 +41,9 @@ export enum TokenInputType { export type TokenInputMenuAlign = 'left' | 'cursor'; -export interface TokenInputProps extends CommonProps, Partial> { - selectedItems: T[]; - onValueChange: (items: T[]) => void; - onMouseEnter: MouseEventHandler; - onMouseLeave: MouseEventHandler; - onFocus: FocusEventHandler; - onBlur: FocusEventHandler; +export type TokenInputProps = { autoFocus?: boolean; type?: TokenInputType; - /** - * Ширина выпадающего меню может быть указана как 'auto' - * а также в пикселях, процентах (от ширины инпута) - * или других конкретных единицах - * - * Если menuAlign = 'cursor', то ширина выпадающего меню всегда будет равна 'auto' - * (по ширине текста) - */ - menuWidth: React.CSSProperties['width']; - menuAlign: TokenInputMenuAlign; - /** * Функция поиска элементов, должна возвращать Promise с массивом элементов. * По умолчанию ожидаются строки. @@ -70,18 +53,8 @@ export interface TokenInputProps extends CommonProps, Partial */ getItems?: (query: string) => Promise; hideMenuIfEmptyInputValue?: boolean; - renderItem: (item: T, state: MenuItemState) => React.ReactNode | null; - renderValue: (item: T) => React.ReactNode; - /** - * Функция должна возвращать строковое представление токена - * @default item => item - */ - valueToString: (item: T) => string; renderNotFound?: () => React.ReactNode; - valueToItem: (item: string) => T; - toKey: (item: T) => string | number | undefined; placeholder?: string; - delimiters: string[]; /** * Cостояние валидации при ошибке. */ @@ -91,7 +64,6 @@ export interface TokenInputProps extends CommonProps, Partial */ warning?: boolean; disabled?: boolean; - width?: string | number; maxMenuHeight?: number | string; renderToken?: (item: T, props: Partial) => ReactNode; /** @@ -121,9 +93,10 @@ export interface TokenInputProps extends CommonProps, Partial */ onUnexpectedInput?: (value: string) => void | null | undefined | T; inputMode?: React.HTMLAttributes['inputMode']; -} +} & CommonProps & + Partial>; -export interface TokenInputState { +export type TokenInputState = { autocompleteItems?: T[]; activeTokens: T[]; editingTokenIndex: number; @@ -136,7 +109,7 @@ export interface TokenInputState { inputValueHeight: number; preventBlur?: boolean; loading?: boolean; -} +}; export const DefaultState = { inputValue: '', @@ -169,11 +142,15 @@ const defaultRenderToken = ( ); -interface DefaultProps { +type DefaultProps = { selectedItems: T[]; delimiters: string[]; renderItem: (item: T, state: MenuItemState) => React.ReactNode | null; renderValue: (item: T) => React.ReactNode; + /** + * Функция должна возвращать строковое представление токена + * @default item => item + */ valueToString: (item: T) => string; valueToItem: (item: string) => T; toKey: (item: T) => string | number | undefined; @@ -183,9 +160,17 @@ interface DefaultProps { onFocus: FocusEventHandler; onMouseEnter: MouseEventHandler; onMouseLeave: MouseEventHandler; + /** + * Ширина выпадающего меню может быть указана как 'auto' + * а также в пикселях, процентах (от ширины инпута) + * или других конкретных единицах + * + * Если menuAlign = 'cursor', то ширина выпадающего меню всегда будет равна 'auto' + * (по ширине текста) + */ menuWidth: React.CSSProperties['width']; menuAlign: TokenInputMenuAlign; -} +}; type TokenInputComponentProps = TokenInputProps & DefaultProps; @@ -194,7 +179,7 @@ type TokenInputComponentProps = TokenInputProps & DefaultProps; export class TokenInput extends React.PureComponent, TokenInputState> { public static __KONTUR_REACT_UI__ = 'TokenInput'; - public static defaultProps: DefaultProps = { + public static defaultProps: DefaultProps = { selectedItems: [], delimiters: [',', ' '], renderItem: identity, @@ -230,7 +215,7 @@ export class TokenInput extends React.PureComponent, prevState: TokenInputState) { + public componentDidUpdate(prevProps: TokenInputComponentProps, prevState: TokenInputState) { if (prevState.inputValue !== this.state.inputValue) { this.updateInputTextWidth(); } diff --git a/packages/react-ui/components/Tooltip/Tooltip.tsx b/packages/react-ui/components/Tooltip/Tooltip.tsx index a6f428f80d1..fa336948822 100644 --- a/packages/react-ui/components/Tooltip/Tooltip.tsx +++ b/packages/react-ui/components/Tooltip/Tooltip.tsx @@ -35,7 +35,7 @@ export type TooltipTrigger = /** Управление через публичные функции show и hide */ | 'manual'; -export interface TooltipProps extends CommonProps, Partial { +export type TooltipProps = { /** * Относительно какого элемента позиционировать тултип */ @@ -62,27 +62,6 @@ export interface TooltipProps extends CommonProps, Partial { */ render?: Nullable<() => React.ReactNode>; - /** - * Значение по умолчанию: `"top left"`. - */ - pos: PopupPositionsType; - - /** - * Триггер открытия тултипа - * ```ts - * type TooltipTrigger = - * | 'hover' - * | 'click' - * | 'focus' - * | 'hover&focus' - * | 'opened' - * | 'closed' - * | 'hoverAnchor' - * | 'manual'; - * ``` - */ - trigger: TooltipTrigger; - /** * Хэндлер, вызываемый при клике по крестику */ @@ -104,6 +83,37 @@ export interface TooltipProps extends CommonProps, Partial { */ onOpen?: () => void; + /** + * Явно указывает, что вложенные элементы должны быть обёрнуты в ``.
Используется для корректного позиционирования тултипа при двух и более вложенных элементах. + * + * _Примечание_: при **двух и более** вложенных элементах обёртка будет добавлена автоматически. + */ + useWrapper: boolean; +} & CommonProps & + Partial; + +export type TooltipState = { + opened: boolean; + focused: boolean; +}; + +type DefaultProps = { + pos: PopupPositionsType; + /** + * Триггер открытия тултипа + * ```ts + * type TooltipTrigger = + * | 'hover' + * | 'click' + * | 'focus' + * | 'hover&focus' + * | 'opened' + * | 'closed' + * | 'hoverAnchor' + * | 'manual'; + * ``` + */ + trigger: TooltipTrigger; /** * Список позиций, которые тултип будет занимать. * Если положение тултипа в определенной позиции @@ -112,34 +122,18 @@ export interface TooltipProps extends CommonProps, Partial { * позицию указанную в `pos` */ allowedPositions: PopupPositionsType[]; - /** * Флаг отключения анимации. * @default false */ disableAnimations: boolean; - /** * Явно указывает, что вложенные элементы должны быть обёрнуты в ``.
Используется для корректного позиционирования тултипа при двух и более вложенных элементах. * * _Примечание_: при **двух и более** вложенных элементах обёртка будет добавлена автоматически. */ useWrapper: boolean; -} - -export interface TooltipState { - opened: boolean; - focused: boolean; -} - -interface DefaultProps { - pos: PopupPositionsType; - trigger: TooltipTrigger; - allowedPositions: PopupPositionsType[]; - disableAnimations: boolean; - useWrapper: boolean; - closeOnChildrenMouseLeave: boolean; -} +}; type TooltipComponentProps = TooltipProps & DefaultProps; @@ -182,7 +176,6 @@ export class Tooltip extends React.PureComponent; -export interface TooltipMenuProps extends CommonProps, Partial { +export type TooltipMenuProps = { children?: TooltipMenuChildType | TooltipMenuChildType[]; /** Максимальная высота меню */ menuMaxHeight?: number | string; @@ -44,15 +44,15 @@ export interface TooltipMenuProps extends CommonProps, Partial { * **Возможные значения**: `top left`, `top center`, `top right`, `right top`, `right middle`, `right bottom`, `bottom left`, `bottom center`, `bottom right`, `left top`, `left middle`, `left bottom` */ positions?: PopupPositionsType[]; +} & CommonProps & + Partial; + +type DefaultProps = { /** * Не показывать анимацию */ disableAnimations: boolean; -} - -interface DefaultProps { - disableAnimations: boolean; -} +}; type TooltipComponentMenuProps = TooltipMenuProps & DefaultProps; diff --git a/packages/react-ui/internal/BGRuler.tsx b/packages/react-ui/internal/BGRuler.tsx index d44df48613b..cb91a11b939 100644 --- a/packages/react-ui/internal/BGRuler.tsx +++ b/packages/react-ui/internal/BGRuler.tsx @@ -1,24 +1,19 @@ import React from 'react'; -interface BGRulerProps extends Partial { +type BGRulerProps = { width?: string | number; - height?: string | number; - top?: string | number; bottom?: string | number; - right?: string | number; - left?: string | number; - color?: string; -} +} & Partial; -interface DefaultProps { +type DefaultProps = { height: string | number; top: string | number; left: string | number; right: string | number; color: string; -} +}; -type BgRulerComponentPorps = BGRulerProps & DefaultProps; +type BgRulerComponentProps = BGRulerProps & DefaultProps; /** * Компонент рисует пиксельную линейку на заднем фоне. @@ -26,7 +21,7 @@ type BgRulerComponentPorps = BGRulerProps & DefaultProps; * * @see FxInput/__stories__/FxInput.stories.tsx */ -export class BGRuler extends React.Component { +export class BGRuler extends React.Component { public static defaultProps: DefaultProps = { height: 20, top: 0, diff --git a/packages/react-ui/internal/Calendar/Calendar.tsx b/packages/react-ui/internal/Calendar/Calendar.tsx index 610ae1c98eb..635c07b0eca 100644 --- a/packages/react-ui/internal/Calendar/Calendar.tsx +++ b/packages/react-ui/internal/Calendar/Calendar.tsx @@ -17,29 +17,27 @@ import { Month } from './Month'; import { styles } from './Calendar.styles'; import { CalendarDateShape, create, isGreater, isLess } from './CalendarDateShape'; -export interface CalendarProps extends Partial { +export type CalendarProps = { initialMonth?: number; initialYear?: number; onSelect?: (date: CalendarDateShape) => void; value?: Nullable; - maxDate?: CalendarDateShape; - minDate?: CalendarDateShape; isHoliday?: (day: CalendarDateShape & { isWeekend: boolean }) => boolean; -} +} & Partial; -export interface CalendarState { +export type CalendarState = { scrollPosition: number; months: MonthViewModel[]; today: CalendarDateShape; scrollDirection: number; scrollTarget: number; touchStart: number; -} +}; -interface DefaultProps { +type DefaultProps = { minDate: CalendarDateShape; maxDate: CalendarDateShape; -} +}; type CalendarComponentProps = CalendarProps & DefaultProps; diff --git a/packages/react-ui/internal/Calendar/Month.tsx b/packages/react-ui/internal/Calendar/Month.tsx index bae9850b4be..36c4e28b505 100644 --- a/packages/react-ui/internal/Calendar/Month.tsx +++ b/packages/react-ui/internal/Calendar/Month.tsx @@ -13,7 +13,7 @@ import { MonthView } from './MonthView'; import { DayCellView } from './DayCellView'; import * as CalendarScrollEvents from './CalendarScrollEvents'; -interface MonthProps { +type MonthProps = { top: number; month: MonthViewModel; maxDate?: CDS.CalendarDateShape; @@ -23,7 +23,7 @@ interface MonthProps { onDateClick?: (date: CDS.CalendarDateShape) => void; onMonthYearChange: (month: number, year: number) => void; isHoliday?: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => boolean; -} +}; export class Month extends React.Component { private theme!: Theme; @@ -129,7 +129,7 @@ export class Month extends React.Component { }; } -interface MonthDayGridProps extends Partial { +type MonthDayGridProps = { days: DayCellViewModel[]; offset: number; minDate?: CDS.CalendarDateShape; @@ -137,12 +137,11 @@ interface MonthDayGridProps extends Partial { today?: CDS.CalendarDateShape; value?: Nullable; onDateClick?: (x0: CDS.CalendarDateShape) => void; - isHoliday: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => boolean; -} +} & Partial; -interface DefaultProps { +type DefaultProps = { isHoliday: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => boolean; -} +}; type MonthDayGridComponentProps = MonthDayGridProps & DefaultProps; diff --git a/packages/react-ui/internal/ComponentCombinator.tsx b/packages/react-ui/internal/ComponentCombinator.tsx index 9530a095eaf..a91b9be57f4 100644 --- a/packages/react-ui/internal/ComponentCombinator.tsx +++ b/packages/react-ui/internal/ComponentCombinator.tsx @@ -4,17 +4,15 @@ import { DefaultizeProps } from '../lib/utils'; import { ComponentTable, StatePropsCombinations, StateType } from './ComponentTable'; -export interface ComponentCombinatorProps extends DefaultProps { +export type ComponentCombinatorProps = { combinations: Array>; Component: C; - presetProps: DefaultizeProps; - presetState: Partial; -} +} & DefaultProps; -interface DefaultProps { +type DefaultProps = { presetProps: DefaultizeProps; presetState: Partial; -} +}; type ComponentCombinatorComponentProps = ComponentCombinatorProps & DefaultProps; @@ -30,7 +28,7 @@ export class ComponentCombinator< >, { page: number } > { - public static defaultProps: DefaultProps = { + public static defaultProps: DefaultProps = { presetProps: {}, presetState: {}, }; diff --git a/packages/react-ui/internal/ComponentTable.tsx b/packages/react-ui/internal/ComponentTable.tsx index 55aa02f2659..85fdc83b4b5 100644 --- a/packages/react-ui/internal/ComponentTable.tsx +++ b/packages/react-ui/internal/ComponentTable.tsx @@ -32,18 +32,16 @@ export type StatePropsCombinations = Array<{ props?: Partial

; state?: P export type StateType = C extends React.Component | React.ComponentClass ? S : never; -export interface ComponentTableProps extends Partial> { +export type ComponentTableProps = { rows?: StatePropsCombinations; cols?: StatePropsCombinations; - presetProps: DefaultizeProps; - presetState: Partial; Component: C; -} +} & Partial>; -interface DefaultProps { +type DefaultProps = { presetProps: DefaultizeProps; presetState: Partial; -} +}; type ComponentTableComponentProps = ComponentTableProps & DefaultProps; diff --git a/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx b/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx index 346d823b8e0..e21e1a045aa 100644 --- a/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx +++ b/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx @@ -10,7 +10,7 @@ import { MenuSeparator } from '../../components/MenuSeparator'; import { ComboBoxRequestStatus } from './CustomComboBoxTypes'; import { ComboBoxLocale, CustomComboBoxLocaleHelper } from './locale'; -export interface ComboBoxMenuProps extends Partial { +export type ComboBoxMenuProps = { opened?: boolean; items?: Nullable; totalCount?: number; @@ -23,14 +23,12 @@ export interface ComboBoxMenuProps extends Partial { onValueChange: (value: T) => any; renderAddButton?: () => React.ReactNode; caption?: React.ReactNode; - repeatRequest?: () => void; - requestStatus?: ComboBoxRequestStatus; -} +} & Partial; -interface DefaultProps { +type DefaultProps = { repeatRequest: () => void; requestStatus: ComboBoxRequestStatus; -} +}; type ComboBoxMenuComponentProps = ComboBoxMenuProps & DefaultProps; diff --git a/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx b/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx index ff8b162f10c..cb44ad5ab30 100644 --- a/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx +++ b/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx @@ -17,7 +17,7 @@ import { ComboBoxMenu } from './ComboBoxMenu'; import { ComboBoxRequestStatus } from './CustomComboBoxTypes'; import { styles } from './CustomComboBox.styles'; -interface ComboBoxViewProps extends CommonProps, Partial> { +type ComboBoxViewProps = { align?: 'left' | 'center' | 'right'; autoFocus?: boolean; borderless?: boolean; @@ -34,7 +34,6 @@ interface ComboBoxViewProps extends CommonProps, Partial> { opened?: boolean; drawArrow?: boolean; placeholder?: string; - size?: 'small' | 'medium' | 'large'; textValue?: string; totalCount?: number; value?: Nullable; @@ -42,17 +41,13 @@ interface ComboBoxViewProps extends CommonProps, Partial> { * Cостояние валидации при предупреждении. */ warning?: boolean; - width?: string | number; maxLength?: number; maxMenuHeight?: number | string; leftIcon?: InputIconType; rightIcon?: InputIconType; inputMode?: React.HTMLAttributes['inputMode']; - onValueChange?: (value: T) => void; - onClickOutside?: (e: Event) => void; onFocus?: () => void; - onFocusOutside?: () => void; onInputBlur?: () => void; onInputValueChange?: (value: string) => void; onInputFocus?: () => void; @@ -61,19 +56,15 @@ interface ComboBoxViewProps extends CommonProps, Partial> { onMouseEnter?: (e: React.MouseEvent) => void; onMouseOver?: (e: React.MouseEvent) => void; onMouseLeave?: (e: React.MouseEvent) => void; - renderItem?: (item: T, state: MenuItemState) => React.ReactNode; renderNotFound?: () => React.ReactNode; renderTotalCount?: (found: number, total: number) => React.ReactNode; - renderValue?: (item: T) => React.ReactNode; - renderAddButton: (query?: string) => React.ReactNode; - repeatRequest?: () => void; - requestStatus?: ComboBoxRequestStatus; refInput?: (input: Nullable) => void; refMenu?: (menu: Nullable

) => void; refInputLikeText?: (inputLikeText: Nullable) => void; -} +} & CommonProps & + Partial>; -interface DefaultProps { +type DefaultProps = { renderItem: (item: T, state: MenuItemState) => React.ReactNode; renderValue: (item: T) => React.ReactNode; renderAddButton: (query?: string) => React.ReactNode; @@ -83,7 +74,7 @@ interface DefaultProps { onFocusOutside: () => void; size: 'small' | 'medium' | 'large'; width: string | number; -} +}; type ComboBoxViewComponentProps = ComboBoxViewProps & DefaultProps; @@ -91,7 +82,7 @@ type ComboBoxViewComponentProps = ComboBoxViewProps & DefaultProps; export class ComboBoxView extends React.Component, {}> { public static __KONTUR_REACT_UI__ = 'ComboBoxView'; - public static defaultProps: DefaultProps = { + public static defaultProps: DefaultProps = { renderItem: (item: any) => item, renderValue: (item: any) => item, renderAddButton: () => null, diff --git a/packages/react-ui/internal/DateSelect/DateSelect.tsx b/packages/react-ui/internal/DateSelect/DateSelect.tsx index 8952cc0bd39..72732456f7f 100644 --- a/packages/react-ui/internal/DateSelect/DateSelect.tsx +++ b/packages/react-ui/internal/DateSelect/DateSelect.tsx @@ -23,17 +23,15 @@ const monthsCount = 12; const defaultMinYear = 1900; const defaultMaxYear = 2100; -export interface DateSelectProps extends Partial { +export type DateSelectProps = { disabled?: boolean | null; onValueChange: (value: number) => void; - type?: 'month' | 'year'; value: number; - width?: number | string; minValue?: number; maxValue?: number; -} +} & Partial; -export interface DateSelectState { +export type DateSelectState = { botCapped: boolean; current: Nullable; height: number; @@ -42,12 +40,12 @@ export interface DateSelectState { top: number; topCapped: boolean; nodeTop: number; -} +}; -interface DefaultProps { +type DefaultProps = { type: 'month' | 'year'; width: number | string; -} +}; type DateSelectComponentProps = DateSelectProps & DefaultProps; diff --git a/packages/react-ui/internal/DropdownContainer/DropdownContainer.tsx b/packages/react-ui/internal/DropdownContainer/DropdownContainer.tsx index 89b1979f7df..5dd9405021c 100644 --- a/packages/react-ui/internal/DropdownContainer/DropdownContainer.tsx +++ b/packages/react-ui/internal/DropdownContainer/DropdownContainer.tsx @@ -9,35 +9,31 @@ import { isIE11 } from '../../lib/client'; import { styles } from './DropdownContainer.styles'; -export interface DropdownContainerPosition { +export type DropdownContainerPosition = { top: Nullable; bottom: Nullable; left: Nullable; right: Nullable; -} +}; -export interface DropdownContainerProps extends Partial { - align?: 'left' | 'right'; +export type DropdownContainerProps = { getParent: () => Nullable; children?: React.ReactNode; - disablePortal?: boolean; - offsetY?: number; - offsetX?: number; hasFixedWidth?: boolean; -} +} & Partial; -export interface DropdownContainerState { +export type DropdownContainerState = { position: Nullable; minWidth: number; isDocumentElementRoot?: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { align: 'left' | 'right'; disablePortal: boolean; offsetX: number; offsetY: number; -} +}; type DropdownContainerComponentProps = DropdownContainerProps & DefaultProps; diff --git a/packages/react-ui/internal/InputLikeText/InputLikeText.tsx b/packages/react-ui/internal/InputLikeText/InputLikeText.tsx index f3f67cd6265..a5356ad97a2 100644 --- a/packages/react-ui/internal/InputLikeText/InputLikeText.tsx +++ b/packages/react-ui/internal/InputLikeText/InputLikeText.tsx @@ -18,7 +18,7 @@ import { TSetRootNode, rootNode } from '../../lib/rootNode'; import { styles } from './InputLikeText.styles'; import { HiddenInput } from './HiddenInput'; -export interface InputLikeTextProps extends CommonProps, InputProps { +export type InputLikeTextProps = { children?: React.ReactNode; innerRef?: (el: HTMLElement | null) => void; onFocus?: React.FocusEventHandler; @@ -26,15 +26,23 @@ export interface InputLikeTextProps extends CommonProps, InputProps { onMouseDragStart?: MouseDragEventHandler; onMouseDragEnd?: MouseDragEventHandler; takeContentWidth?: boolean; -} +} & CommonProps & + InputProps & + Partial; + +type DefaultProps = { + size: InputProps['size']; +}; + +type InputLikeTextComponentProps = InputLikeTextProps & DefaultProps; export type InputLikeTextState = Omit; @rootNode -export class InputLikeText extends React.Component { +export class InputLikeText extends React.Component { public static __KONTUR_REACT_UI__ = 'InputLikeText'; - public static defaultProps = { size: 'small' }; + public static defaultProps: DefaultProps = { size: 'small' }; public state = { blinking: false, focused: false }; diff --git a/packages/react-ui/internal/InternalMenu/InternalMenu.tsx b/packages/react-ui/internal/InternalMenu/InternalMenu.tsx index 90333b8fb4e..29f8e12a09e 100644 --- a/packages/react-ui/internal/InternalMenu/InternalMenu.tsx +++ b/packages/react-ui/internal/InternalMenu/InternalMenu.tsx @@ -13,37 +13,29 @@ import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; import { styles } from './InternalMenu.styles'; import { isActiveElement } from './isActiveElement'; -interface MenuProps extends Partial { +type MenuProps = { children?: React.ReactNode; - hasShadow?: boolean; - maxHeight?: number | string; onItemClick?: (event: React.SyntheticEvent) => void; - width?: number | string; - preventWindowScroll?: boolean; onKeyDown?: (event: React.KeyboardEvent) => void; - header?: React.ReactNode; footer?: React.ReactNode; +} & Partial; - // Циклический перебор айтемов меню (по-дефолтну включен) - cyclicSelection?: boolean; - initialSelectedItemIndex?: number; -} - -interface MenuState { +type MenuState = { highlightedIndex: number; maxHeight: number | string; scrollState: ScrollContainerScrollState; -} +}; -interface DefaultProps { +type DefaultProps = { width: number | string; maxHeight: number | string; hasShadow: boolean; preventWindowScroll: boolean; + // Циклический перебор айтемов меню (по-дефолтну включен) cyclicSelection: boolean; initialSelectedItemIndex: number; -} +}; type InternalMenuComponentProps = MenuProps & DefaultProps; diff --git a/packages/react-ui/internal/MaskedInput/MaskedInput.tsx b/packages/react-ui/internal/MaskedInput/MaskedInput.tsx index 8c1e6cd685b..e3fc3a42fbd 100644 --- a/packages/react-ui/internal/MaskedInput/MaskedInput.tsx +++ b/packages/react-ui/internal/MaskedInput/MaskedInput.tsx @@ -8,26 +8,26 @@ import { cx } from '../../lib/theming/Emotion'; import { styles } from './MaskedInput.styles'; -export interface MaskedInputProps extends React.InputHTMLAttributes, Partial { +export type MaskedInputProps = { mask: string; - maskChar: string | null; formatChars?: { [key: string]: string }; alwaysShowMask?: boolean; hasLeftIcon?: boolean; hasRightIcon?: boolean; onUnexpectedInput?: (value: string) => void; onValueChange?: (value: string) => void; -} +} & React.InputHTMLAttributes & + Partial; -interface MaskedInputState { +type MaskedInputState = { value: string; emptyValue: string; focused: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { maskChar: string | null; -} +}; type MaskedInputComponentProps = MaskedInputProps & DefaultProps; @@ -42,7 +42,7 @@ export class MaskedInput extends React.PureComponent { +export type MenuProps = { children: React.ReactNode; - hasShadow?: boolean; - maxHeight?: number | string; onItemClick?: () => void; - width?: number | string; - preventWindowScroll?: boolean; - align?: 'left' | 'right'; -} +} & Partial; -export interface MenuState { +export type MenuState = { highlightedIndex: number; -} +}; -interface DefaultProps { +type DefaultProps = { align: 'left' | 'right'; width: number | string; maxHeight: number | string; hasShadow: boolean; preventWindowScroll: boolean; -} +}; type MenuComponentProps = MenuProps & DefaultProps; diff --git a/packages/react-ui/internal/Popup/Popup.tsx b/packages/react-ui/internal/Popup/Popup.tsx index dd0a6b04fff..353eefd12d1 100644 --- a/packages/react-ui/internal/Popup/Popup.tsx +++ b/packages/react-ui/internal/Popup/Popup.tsx @@ -53,7 +53,7 @@ const DUMMY_LOCATION: PopupLocation = { }, }; -export interface PopupHandlerProps { +export type PopupHandlerProps = { onMouseEnter?: (event: MouseEventType) => void; onMouseLeave?: (event: MouseEventType) => void; onClick?: (event: MouseEventType) => void; @@ -61,31 +61,19 @@ export interface PopupHandlerProps { onBlur?: (event: FocusEventType) => void; onOpen?: () => void; onClose?: () => void; -} +}; -export interface PopupProps extends CommonProps, PopupHandlerProps, Partial { +export type PopupProps = { anchorElement: React.ReactNode | HTMLElement; backgroundColor?: React.CSSProperties['backgroundColor']; borderColor?: React.CSSProperties['borderColor']; children: React.ReactNode | (() => React.ReactNode); - hasPin: boolean; - hasShadow: boolean; - disableAnimations: boolean; margin?: number; maxWidth?: number | string; opened: boolean; pinOffset?: number; pinSize?: number; - popupOffset: number; positions: Readonly; - /** - * Явно указывает, что вложенные элементы должны быть обёрнуты в ``.
Используется для корректного позиционирования тултипа при двух и более вложенных элементах. - * - * _Примечание_: при **двух и более** вложенных элементах обёртка будет добавлена автоматически. - */ - useWrapper: boolean; - ignoreHover: boolean; - width: React.CSSProperties['width']; /** * При очередном рендере пытаться сохранить первоначальную позицию попапа * (в числе числе, когда он выходит за пределы экрана, но может быть проскролен в него). @@ -94,31 +82,38 @@ export interface PopupProps extends CommonProps, PopupHandlerProps, Partial; -interface PopupLocation { +type PopupLocation = { coordinates: { left: number; top: number; }; position: PopupPositionsType; -} +}; -export interface PopupState { +export type PopupState = { location: Nullable; -} +}; -interface DefaultProps { +type DefaultProps = { popupOffset: number; hasPin: boolean; hasShadow: boolean; disableAnimations: boolean; + /** + * Явно указывает, что вложенные элементы должны быть обёрнуты в ``.
Используется для корректного позиционирования тултипа при двух и более вложенных элементах. + * + * _Примечание_: при **двух и более** вложенных элементах обёртка будет добавлена автоматически. + */ useWrapper: boolean; ignoreHover: boolean; width: React.CSSProperties['width']; -} +}; -type PopupComponentProps = PopupProps & DefaultProps; +export type PopupComponentProps = PopupProps & DefaultProps; @rootNode export class Popup extends React.Component { @@ -210,7 +205,7 @@ export class Popup extends React.Component { this.layoutEventsToken = LayoutEvents.addListener(this.handleLayoutEvent); } - public static getDerivedStateFromProps(props: Readonly, state: PopupState) { + public static getDerivedStateFromProps(props: Readonly, state: PopupState) { /** * Delaying updateLocation to ensure it happens after props update */ @@ -224,7 +219,7 @@ export class Popup extends React.Component { return state; } - public componentDidUpdate(prevProps: PopupProps, prevState: PopupState) { + public componentDidUpdate(prevProps: PopupComponentProps, prevState: PopupState) { const hadNoLocation = prevState.location === DUMMY_LOCATION; const hasLocation = this.state.location !== DUMMY_LOCATION; const wasClosed = prevProps.opened && !this.props.opened; @@ -366,7 +361,7 @@ export class Popup extends React.Component { } }; - private calculateWidth = (width: PopupProps['width']) => { + private calculateWidth = (width: PopupComponentProps['width']) => { if (typeof width === 'string' && width.includes('%')) { return this.anchorElement ? (this.anchorElement.offsetWidth * parseFloat(width)) / 100 : 0; } diff --git a/packages/react-ui/internal/Popup/__tests__/Popup-test.tsx b/packages/react-ui/internal/Popup/__tests__/Popup-test.tsx index c1ea0c39f9c..18eed19a6dd 100644 --- a/packages/react-ui/internal/Popup/__tests__/Popup-test.tsx +++ b/packages/react-ui/internal/Popup/__tests__/Popup-test.tsx @@ -3,7 +3,7 @@ import { ComponentClass, mount, ReactWrapper } from 'enzyme'; import { Transition } from 'react-transition-group'; import { ReactComponentLike } from 'prop-types'; -import { Popup, PopupProps, PopupState } from '../Popup'; +import { Popup, PopupComponentProps, PopupState } from '../Popup'; import { delay } from '../../../lib/utils'; import { RenderContainer } from '../../RenderContainer'; import { ZIndex } from '../../ZIndex'; @@ -11,7 +11,7 @@ import { CommonWrapper } from '../../CommonWrapper'; import { RenderInnerContainer, Portal } from '../../RenderContainer/RenderInnerContainer'; import { Nullable } from '../../../typings/utility-types'; -const openPopup = async (wrapper: ReactWrapper) => +const openPopup = async (wrapper: ReactWrapper) => new Promise((resolve) => { wrapper.setProps({ opened: true }, async () => { await delay(100); @@ -19,7 +19,7 @@ const openPopup = async (wrapper: ReactWrapper) = }); }); -const closePopup = async (wrapper: ReactWrapper) => +const closePopup = async (wrapper: ReactWrapper) => new Promise((resolve) => { wrapper.setProps({ opened: false }, async () => { await delay(100); @@ -27,7 +27,7 @@ const closePopup = async (wrapper: ReactWrapper) }); }); -const renderWrapper = (props?: Partial): ReactWrapper => { +const renderWrapper = (props?: Partial): ReactWrapper => { const anchor = document.createElement('button'); anchor.id = 'test-id'; @@ -64,7 +64,7 @@ describe('Popup', () => { > Test content - ) as React.ReactElement, + ) as React.ReactElement, ); expect(wrapper.state('location')).toBeNull(); @@ -92,7 +92,7 @@ describe('Popup', () => { > Test content - ) as React.ReactElement, + ) as React.ReactElement, ); expect(wrapper.state('location')).toBeNull(); diff --git a/packages/react-ui/internal/PopupMenu/PopupMenu.tsx b/packages/react-ui/internal/PopupMenu/PopupMenu.tsx index c4c29a98513..a81fdd1e4af 100644 --- a/packages/react-ui/internal/PopupMenu/PopupMenu.tsx +++ b/packages/react-ui/internal/PopupMenu/PopupMenu.tsx @@ -17,14 +17,14 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { isValidPositions } from './validatePositions'; import { styles } from './PopupMenu.styles'; -export interface PopupMenuCaptionProps { +export type PopupMenuCaptionProps = { opened: boolean; openMenu: (firstItemShouldBeSelected?: boolean) => void; closeMenu: (restoreFocus?: boolean) => void; toggleMenu: () => void; -} +}; -export interface PopupMenuProps extends CommonProps, Partial { +export type PopupMenuProps = { children?: React.ReactNode; /** Максимальная высота меню */ menuMaxHeight?: number | string; @@ -43,30 +43,25 @@ export interface PopupMenuProps extends CommonProps, Partial { header?: React.ReactNode; footer?: React.ReactNode; - - /** Массив разрешенных положений меню относительно caption'а. */ - positions?: PopupPositionsType[]; /** Колбэк, вызываемый после открытия/закрытия меню */ onChangeMenuState?: (isOpened: boolean, restoreFocus: boolean) => void; - /** Пропсы, передающиеся в Popup */ - popupHasPin?: boolean; popupMargin?: number; popupPinOffset?: number; - type?: typeof PopupMenuType[keyof typeof PopupMenuType]; - disableAnimations: boolean; -} +} & CommonProps & + Partial; -interface PopupMenuState { +type PopupMenuState = { menuVisible: boolean; firstItemShouldBeSelected?: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { + /** Массив разрешенных положений меню относительно caption'а. */ positions: PopupPositionsType[]; type: typeof PopupMenuType[keyof typeof PopupMenuType]; popupHasPin: boolean; disableAnimations: boolean; -} +}; export const PopupMenuType = { Dropdown: 'dropdown', diff --git a/packages/react-ui/internal/RenderLayer/RenderLayer.tsx b/packages/react-ui/internal/RenderLayer/RenderLayer.tsx index e38ad6dc198..05e3d21a2d2 100644 --- a/packages/react-ui/internal/RenderLayer/RenderLayer.tsx +++ b/packages/react-ui/internal/RenderLayer/RenderLayer.tsx @@ -5,22 +5,22 @@ import { CommonProps, CommonWrapper } from '../CommonWrapper'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; import { Nullable } from '../../typings/utility-types'; -export interface RenderLayerProps extends CommonProps, Partial { +export type RenderLayerProps = { children: JSX.Element; onClickOutside?: (e: Event) => void; onFocusOutside?: (e: Event) => void; - active?: boolean; getAnchorElement?: () => Nullable; -} +} & CommonProps & + Partial; -interface DefaultProps { +type DefaultProps = { active: boolean; -} +}; -type RenderLayerComponentPorps = RenderLayerProps & DefaultProps; +type RenderLayerComponentProps = RenderLayerProps & DefaultProps; @rootNode -export class RenderLayer extends React.Component { +export class RenderLayer extends React.Component { public static __KONTUR_REACT_UI__ = 'RenderLayer'; public static propTypes = { diff --git a/packages/react-ui/internal/ThemePlayground/VariableValue.tsx b/packages/react-ui/internal/ThemePlayground/VariableValue.tsx index 26346e41208..6db2f68ccc8 100644 --- a/packages/react-ui/internal/ThemePlayground/VariableValue.tsx +++ b/packages/react-ui/internal/ThemePlayground/VariableValue.tsx @@ -15,24 +15,23 @@ import { styles } from './Playground.styles'; const emitter = new EventEmitter(); -export interface VariableValueProps extends Partial { +export type VariableValueProps = { onChange: (variable: keyof Theme, value: string) => void; value: string; isError: boolean; variable: string; theme: Theme; baseVariables: Array; - deprecated: boolean; -} +} & Partial; -export interface VariableValueState { +export type VariableValueState = { value: string; editing: boolean; -} +}; -interface DefaultProps { +type DefaultProps = { deprecated: boolean; -} +}; type VariableValueComponentProps = VariableValueProps & DefaultProps; @@ -202,10 +201,10 @@ export class VariableValue extends React.Component void; -} +}; class BaseVariableLink extends React.Component { public render() { return {this.props.baseVariable}; diff --git a/packages/react-ui/internal/ZIndex/ZIndex.tsx b/packages/react-ui/internal/ZIndex/ZIndex.tsx index 5d3e2058f17..3d449d95e98 100644 --- a/packages/react-ui/internal/ZIndex/ZIndex.tsx +++ b/packages/react-ui/internal/ZIndex/ZIndex.tsx @@ -10,33 +10,28 @@ const ZIndexContext = React.createContext({ parentLayerZIndex: 0, maxZIndex: Inf ZIndexContext.displayName = 'ZIndexContext'; -export interface ZIndexProps extends React.HTMLAttributes, Partial { - /** - * Приращение к z-index - */ - delta: number; - priority: number | LayerComponentName; - style: React.CSSProperties; - createStackingContext?: boolean; - coverChildren?: boolean; - applyZIndex?: boolean; +export type ZIndexProps = { className?: string; wrapperRef?: React.Ref | undefined | null; -} +} & React.HTMLAttributes & + Partial; -interface DefaultProps { +type DefaultProps = { + /** + * Приращение к z-index + */ delta: number; priority: number | LayerComponentName; style: React.CSSProperties; applyZIndex: boolean; coverChildren: boolean; createStackingContext: boolean; -} +}; -type ZIndexComponentPorps = ZIndexProps & DefaultProps; +type ZIndexComponentProps = ZIndexProps & DefaultProps; @rootNode -export class ZIndex extends React.Component { +export class ZIndex extends React.Component { public static __KONTUR_REACT_UI__ = 'ZIndex'; public static defaultProps: DefaultProps = { @@ -49,7 +44,7 @@ export class ZIndex extends React.Component { }; public static propTypes = { - delta(props: ZIndexProps) { + delta(props: ZIndexComponentProps) { if (props.delta <= 0) { return new Error(`[ZIndex]: Prop 'delta' must be greater than 0, received ${props.delta}`); } @@ -63,7 +58,7 @@ export class ZIndex extends React.Component { private setRootNode!: TSetRootNode; - constructor(props: ZIndexComponentPorps) { + constructor(props: ZIndexComponentProps) { super(props); this.zIndex = incrementZIndex(props.priority, props.delta); } From 55269049663efad1b957c0661afdcaf6b250180d Mon Sep 17 00:00:00 2001 From: HelenaIsh Date: Fri, 18 Feb 2022 14:53:20 +0500 Subject: [PATCH 07/11] chore: delete ts-ignore from Input-test --- packages/react-ui/components/Input/__tests__/Input-test.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/react-ui/components/Input/__tests__/Input-test.tsx b/packages/react-ui/components/Input/__tests__/Input-test.tsx index 8847abdb0c1..9565d8836d1 100644 --- a/packages/react-ui/components/Input/__tests__/Input-test.tsx +++ b/packages/react-ui/components/Input/__tests__/Input-test.tsx @@ -4,8 +4,7 @@ import MaskedInput from 'react-input-mask'; import { Input, InputProps } from '../Input'; -// @ts-ignore -const render = (props: InputProps) => mount(React.createElement(Input, props)); +const render = (props: InputProps) => mount(); describe('', () => { it('renders', () => { From 739492772b95fdbfaa0c3b8f66928f40c610841d Mon Sep 17 00:00:00 2001 From: HelenaIsh Date: Mon, 21 Feb 2022 13:23:00 +0500 Subject: [PATCH 08/11] chore: delete duplicate props --- .../components/Autocomplete/Autocomplete.tsx | 21 ++++-------- .../react-ui/components/Center/Center.tsx | 13 ++------ .../CurrencyInput/CurrencyInput.tsx | 15 ++++----- .../react-ui/components/FxInput/FxInput.tsx | 14 ++++---- packages/react-ui/components/Input/Input.tsx | 11 +++---- packages/react-ui/components/Link/Link.tsx | 14 ++++---- packages/react-ui/components/Radio/Radio.tsx | 7 ++-- .../react-ui/components/Textarea/Textarea.tsx | 32 ++++++++----------- packages/react-ui/internal/ComponentTable.tsx | 2 +- 9 files changed, 52 insertions(+), 77 deletions(-) diff --git a/packages/react-ui/components/Autocomplete/Autocomplete.tsx b/packages/react-ui/components/Autocomplete/Autocomplete.tsx index 41197a01c8f..e69f89e2df1 100644 --- a/packages/react-ui/components/Autocomplete/Autocomplete.tsx +++ b/packages/react-ui/components/Autocomplete/Autocomplete.tsx @@ -29,28 +29,14 @@ function renderItem(item: any) { } type AutocompleteInterface = { - /** Функция отрисовки элемента меню */ - renderItem: (item: string) => React.ReactNode; /** Промис, резолвящий элементы меню */ source?: string[] | ((patter: string) => Promise); - /** Отключает использование портала */ - disablePortal: boolean; - /** Отрисовка тени у выпадающего меню */ - hasShadow: boolean; - /** Выравнивание выпадающего меню */ - menuAlign: 'left' | 'right'; - /** Максимальная высота меню */ - menuMaxHeight: number; /** Выравнивание выпадающего меню */ menuWidth?: number | string; - /** Отключить скролл окна, когда меню открыто */ - preventWindowScroll: boolean; /** Вызывается при изменении `value` */ onValueChange: (value: string) => void; /** onBlur */ onBlur?: () => void; - /** Размер инпута */ - size: InputProps['size']; /** value */ value: string; }; @@ -62,12 +48,19 @@ export type AutocompleteState = { }; type DefaultProps = { + /** Функция отрисовки элемента меню */ renderItem: (item: string) => React.ReactNode; + /** Размер инпута */ size: InputProps['size']; + /** Отключает использование портала */ disablePortal: boolean; + /** Отрисовка тени у выпадающего меню */ hasShadow: boolean; + /** Максимальная высота меню */ menuMaxHeight: number; + /** Выравнивание выпадающего меню */ menuAlign: 'left' | 'right'; + /** Отключить скролл окна, когда меню открыто */ preventWindowScroll: boolean; }; diff --git a/packages/react-ui/components/Center/Center.tsx b/packages/react-ui/components/Center/Center.tsx index 7728261d896..2145d1e2f41 100644 --- a/packages/react-ui/components/Center/Center.tsx +++ b/packages/react-ui/components/Center/Center.tsx @@ -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'; @@ -9,20 +8,14 @@ import { styles } from './Center.styles'; export type HorizontalAlign = 'left' | 'center' | 'right'; -type CenterInterface = { +export type CenterProps = React.HTMLAttributes & CommonProps & Partial; + +type DefaultProps = { /** * Определяет, как контент будет выровнен по горизонтали. * * **Допустимые значения**: `"left"`, `"center"`, `"right"`. */ - align?: HorizontalAlign; -}; - -export type CenterProps = Override, CenterInterface> & - CommonProps & - Partial; - -type DefaultProps = { align: HorizontalAlign; }; diff --git a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx index 7ae5c3ce1c1..f254ca1c7ac 100644 --- a/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx +++ b/packages/react-ui/components/CurrencyInput/CurrencyInput.tsx @@ -16,12 +16,6 @@ import { CurrencyInputHelper } from './CurrencyInputHelper'; import { CURRENCY_INPUT_ACTIONS, extractAction } from './CurrencyInputKeyboardActions'; type CurrencyInputInterface = { - /** Значение */ - value: Nullable; - /** Убрать лишние нули после запятой */ - hideTrailingZeros: boolean; - /** Кол-во цифр после зяпятой */ - fractionDigits?: Nullable; /** Отрицательные значения */ signed?: boolean; /** @@ -35,7 +29,9 @@ type CurrencyInputInterface = { onSubmit?: () => void; }; -export type CurrencyInputProps = Override & CommonProps & Partial; +type PropsMergedWithInputProps = Override; + +export type CurrencyInputProps = Override> & CommonProps; export type CurrencyInputState = { formatted: string; @@ -45,12 +41,15 @@ export type CurrencyInputState = { type DefaultProps = { align: InputProps['align']; + /** Кол-во цифр после зяпятой */ fractionDigits: Nullable; + /** Убрать лишние нули после запятой */ hideTrailingZeros: boolean; + /** Значение */ value: Nullable; }; -type CurrencyInputComponentProps = CurrencyInputProps & DefaultProps; +type CurrencyInputComponentProps = Override; /** * Поле для денежных сумм (и других числовых значений). diff --git a/packages/react-ui/components/FxInput/FxInput.tsx b/packages/react-ui/components/FxInput/FxInput.tsx index 9ba375e4381..8e1414bc13e 100644 --- a/packages/react-ui/components/FxInput/FxInput.tsx +++ b/packages/react-ui/components/FxInput/FxInput.tsx @@ -13,29 +13,29 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; type FxInputInterface = { /** Авто-режим */ auto?: boolean; - /** Тип инпута */ - type?: 'currency' | InputProps['type']; /** onRestore */ onRestore?: () => void; /** onValueChange */ onValueChange: CurrencyInputProps['onValueChange'] | InputProps['onValueChange']; - /** Значение */ - value?: React.ReactText; /** ref Input'а */ refInput?: (element: CurrencyInput | Input | null) => void; /** Убрать лишние нули после запятой */ hideTrailingZeros?: boolean; }; -export type FxInputProps = Override & CommonProps & Partial; +type PropsMergedWithCurrencyInputProps = Override; + +export type FxInputProps = Override> & CommonProps; type DefaultProps = { width: number | string; + /** Тип инпута */ type: 'currency' | InputProps['type']; + /** Значение */ value: React.ReactText; }; -type FxInputComponentProps = FxInputProps & DefaultProps; +type FxInputComponentProps = Override; /** Принимает все свойства `Input`'a */ @rootNode @@ -65,7 +65,7 @@ export class FxInput extends React.Component { ); } - public renderMain = (props: CommonWrapperRestProps) => { + public renderMain = (props: CommonWrapperRestProps) => { const { type, onRestore, auto, refInput, ...rest } = props; const inputProps: Partial = { align: 'right', diff --git a/packages/react-ui/components/Input/Input.tsx b/packages/react-ui/components/Input/Input.tsx index 463b71b17fe..e00473ef344 100644 --- a/packages/react-ui/components/Input/Input.tsx +++ b/packages/react-ui/components/Input/Input.tsx @@ -56,8 +56,6 @@ type InputInterface = { formatChars?: Record; /** Показывать символы маски */ alwaysShowMask?: boolean; - /** Размер */ - size?: InputSize; /** onValueChange */ onValueChange?: (value: string) => void; /** Вызывается на label */ @@ -96,9 +94,9 @@ type InputInterface = { onUnexpectedInput?: (value: string) => void; }; -export type InputProps = Override, InputInterface> & - CommonProps & - Partial; +type PropsMergedWithHTMLProps = Override, InputInterface>; + +export type InputProps = Override> & CommonProps; export type InputState = { blinking: boolean; @@ -107,10 +105,11 @@ export type InputState = { }; type DefaultProps = { + /** Размер */ size: InputSize; }; -type InputComponentProps = InputProps & DefaultProps; +type InputComponentProps = Override; /** * Интерфес пропсов наследуется от `React.InputHTMLAttributes`. diff --git a/packages/react-ui/components/Link/Link.tsx b/packages/react-ui/components/Link/Link.tsx index 0eace2e443b..fd9cc36eabb 100644 --- a/packages/react-ui/components/Link/Link.tsx +++ b/packages/react-ui/components/Link/Link.tsx @@ -18,18 +18,10 @@ type LinkInterface = { * Отключенное состояние. */ disabled?: boolean; - /** - * HTML-атрибут `href`. - */ - href?: string; /** * Добавляет ссылке иконку. */ icon?: React.ReactElement; - /** - * Тема ссылки. - */ - use?: 'default' | 'success' | 'danger' | 'grayed'; /** * @ignore */ @@ -61,7 +53,13 @@ export type LinkState = { }; type DefaultProps = { + /** + * HTML-атрибут `href`. + */ href: string; + /** + * Тема ссылки. + */ use: 'default' | 'success' | 'danger' | 'grayed'; }; diff --git a/packages/react-ui/components/Radio/Radio.tsx b/packages/react-ui/components/Radio/Radio.tsx index 9f0bea7695e..0254a133458 100644 --- a/packages/react-ui/components/Radio/Radio.tsx +++ b/packages/react-ui/components/Radio/Radio.tsx @@ -21,10 +21,6 @@ type RadioInterface = { * Cостояние валидации при предупреждении. */ warning?: boolean; - /** - * Состояние фокуса. - */ - focused?: boolean; /** * Функция, вызываемая при изменении `value`. */ @@ -56,6 +52,9 @@ export type RadioState = { }; type DefaultProps = { + /** + * Состояние фокуса. + */ focused: boolean; }; diff --git a/packages/react-ui/components/Textarea/Textarea.tsx b/packages/react-ui/components/Textarea/Textarea.tsx index 6f6dfd6bdee..0b681f09d39 100644 --- a/packages/react-ui/components/Textarea/Textarea.tsx +++ b/packages/react-ui/components/Textarea/Textarea.tsx @@ -41,15 +41,6 @@ type TextareaInterface = { * в зависимости от содержимого */ autoResize?: boolean; - /** - * Число строк - */ - rows: number; - /** - * Максимальное число строк при - * автоматическом ресайзе - */ - maxRows: string | number; /** * Стандартный ресайз @@ -89,16 +80,6 @@ type TextareaInterface = { * ``` * */ counterHelp?: ReactNode | (() => ReactNode); - - /** Добавлять дополнительную свободную строку при авто-ресайзе. - * @see https://guides.kontur.ru/components/textarea/#04 - * */ - extraRow: boolean; - - /** Отключать анимацию при авто-ресайзе. - * Автоматически отключается когда в `extraRow` передан `false`. - */ - disableAnimations: boolean; }; export type TextareaProps = Override, TextareaInterface> & @@ -111,9 +92,22 @@ export type TextareaState = { }; type DefaultProps = { + /** + * Число строк + */ rows: number; + /** + * Максимальное число строк при + * автоматическом ресайзе + */ maxRows: string | number; + /** Добавлять дополнительную свободную строку при авто-ресайзе. + * @see https://guides.kontur.ru/components/textarea/#04 + * */ extraRow: boolean; + /** Отключать анимацию при авто-ресайзе. + * Автоматически отключается когда в `extraRow` передан `false`. + */ disableAnimations: boolean; }; diff --git a/packages/react-ui/internal/ComponentTable.tsx b/packages/react-ui/internal/ComponentTable.tsx index 85fdc83b4b5..4d3f0799e3d 100644 --- a/packages/react-ui/internal/ComponentTable.tsx +++ b/packages/react-ui/internal/ComponentTable.tsx @@ -53,7 +53,7 @@ export class ComponentTable< > extends React.Component< ComponentTableComponentProps ? React.ClassType : C, P, StateType> > { - public static defaultProps: DefaultProps = { presetProps: {}, presetState: {} }; + public static defaultProps: DefaultProps = { presetProps: {}, presetState: {} }; public render() { const { rows = [], cols = [], presetProps, presetState, Component } = this.props; From 0bb6bde0b9448e3b5b9ba77f8e9693196da7df65 Mon Sep 17 00:00:00 2001 From: HelenaIsh Date: Mon, 21 Feb 2022 15:02:18 +0500 Subject: [PATCH 09/11] chore: refactor --- .../src/ValidationContainer.tsx | 20 +++++++++---- .../react-ui/components/Button/Button.tsx | 10 +++---- .../react-ui/components/ComboBox/ComboBox.tsx | 7 +++-- .../CurrencyLabel/CurrencyLabel.tsx | 28 +++++++++---------- .../components/DateInput/DateInput.tsx | 7 +++-- .../components/DatePicker/DatePicker.tsx | 7 +++-- .../components/DropdownMenu/DropdownMenu.tsx | 7 +++-- .../react-ui/components/Gapped/Gapped.tsx | 7 +++-- packages/react-ui/components/Hint/Hint.tsx | 7 +++-- packages/react-ui/components/Kebab/Kebab.tsx | 7 +++-- .../react-ui/components/Loader/Loader.tsx | 7 +++-- packages/react-ui/components/Modal/Modal.tsx | 7 +++-- .../react-ui/components/Paging/Paging.tsx | 7 +++-- .../PasswordInput/PasswordInput.tsx | 8 +++--- .../components/RadioGroup/RadioGroup.tsx | 7 +++-- .../ScrollContainer/ScrollContainer.tsx | 7 +++-- .../react-ui/components/Select/Select.tsx | 7 +++-- .../react-ui/components/SidePage/SidePage.tsx | 7 +++-- .../react-ui/components/Spinner/Spinner.tsx | 7 +++-- .../react-ui/components/Sticky/Sticky.tsx | 7 +++-- packages/react-ui/components/Tabs/Tab.tsx | 7 +++-- packages/react-ui/components/Tabs/Tabs.tsx | 7 +++-- .../react-ui/components/Toggle/Toggle.tsx | 7 +++-- .../components/TokenInput/TokenInput.tsx | 7 +++-- .../react-ui/components/Tooltip/Tooltip.tsx | 7 +++-- .../components/TooltipMenu/TooltipMenu.tsx | 7 +++-- packages/react-ui/internal/BGRuler.tsx | 6 ++-- .../react-ui/internal/Calendar/Calendar.tsx | 6 ++-- packages/react-ui/internal/Calendar/Month.tsx | 6 ++-- .../react-ui/internal/ComponentCombinator.tsx | 6 ++-- packages/react-ui/internal/ComponentTable.tsx | 6 ++-- .../internal/CustomComboBox/ComboBoxMenu.tsx | 6 ++-- .../internal/CustomComboBox/ComboBoxView.tsx | 7 +++-- .../internal/DateSelect/DateSelect.tsx | 6 ++-- .../DropdownContainer/DropdownContainer.tsx | 6 ++-- .../internal/InputLikeText/InputLikeText.tsx | 8 +++--- .../internal/InternalMenu/InternalMenu.tsx | 6 ++-- .../internal/MaskedInput/MaskedInput.tsx | 7 +++-- packages/react-ui/internal/Menu/Menu.tsx | 6 ++-- packages/react-ui/internal/Popup/Popup.tsx | 8 +++--- .../react-ui/internal/PopupMenu/PopupMenu.tsx | 7 +++-- .../internal/RenderLayer/RenderLayer.tsx | 7 +++-- .../ThemePlayground/VariableValue.tsx | 6 ++-- packages/react-ui/internal/ZIndex/ZIndex.tsx | 7 +++-- 44 files changed, 199 insertions(+), 138 deletions(-) diff --git a/packages/react-ui-validations/src/ValidationContainer.tsx b/packages/react-ui-validations/src/ValidationContainer.tsx index bacb710554a..dc589cbb7fb 100644 --- a/packages/react-ui-validations/src/ValidationContainer.tsx +++ b/packages/react-ui-validations/src/ValidationContainer.tsx @@ -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) => void; scrollOffset?: number | ScrollOffset; disableSmoothScroll: boolean; -} +}; + +export type ValidationContainerProps = ValidationContainerInterface & Partial; + +type DefaultProps = { + disableSmoothScroll: boolean; +}; + +type ValidationContainerComponentProps = ValidationContainerProps & DefaultProps; -export class ValidationContainer extends React.Component { +export class ValidationContainer extends React.Component { public static __KONTUR_REACT_UI__ = 'ValidationContainer'; - public static defaultProps = { + public static defaultProps: DefaultProps = { disableSmoothScroll: isTestEnv, }; diff --git a/packages/react-ui/components/Button/Button.tsx b/packages/react-ui/components/Button/Button.tsx index 869f7b9d40b..da361c0e6df 100644 --- a/packages/react-ui/components/Button/Button.tsx +++ b/packages/react-ui/components/Button/Button.tsx @@ -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 type ButtonProps = { - /** @ignore */ - _noPadding?: boolean; +type ButtonInterface = { + /** @ignore */ _noPadding?: boolean; /** @ignore */ _noRightPadding?: boolean; @@ -139,8 +138,9 @@ export type ButtonProps = { * CSS-свойство `width`. */ width?: number | string; -} & CommonProps & - Partial; +}; + +export type ButtonProps = ButtonInterface & CommonProps & Partial; export type ButtonState = { focusedByTab: boolean; diff --git a/packages/react-ui/components/ComboBox/ComboBox.tsx b/packages/react-ui/components/ComboBox/ComboBox.tsx index 94ddb81367c..659c8ddc178 100644 --- a/packages/react-ui/components/ComboBox/ComboBox.tsx +++ b/packages/react-ui/components/ComboBox/ComboBox.tsx @@ -7,7 +7,7 @@ import { InputIconType } from '../Input'; import { CommonProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -export type ComboBoxProps = { +type ComboBoxInterface = { align?: 'left' | 'center' | 'right'; autoFocus?: boolean; @@ -122,8 +122,9 @@ export type ComboBoxProps = { onInputKeyDown?: (e: React.KeyboardEvent) => void; inputMode?: React.HTMLAttributes['inputMode']; -} & CommonProps & - Partial>; +}; + +export type ComboBoxProps = ComboBoxInterface & CommonProps & Partial>; export type ComboBoxItem = { value: string; diff --git a/packages/react-ui/components/CurrencyLabel/CurrencyLabel.tsx b/packages/react-ui/components/CurrencyLabel/CurrencyLabel.tsx index b02ca8e1b48..5b9ec14a5b7 100644 --- a/packages/react-ui/components/CurrencyLabel/CurrencyLabel.tsx +++ b/packages/react-ui/components/CurrencyLabel/CurrencyLabel.tsx @@ -9,19 +9,21 @@ export interface CurrencyLabelProps extends CommonProps { * Минимальное количество отображаемых знаков после запятой * @default 2 */ - fractionDigits: number; + fractionDigits?: number; value: number; currencySymbol?: React.ReactNode; } -export const defaultProps: Partial = { - fractionDigits: 2, -}; +const FRACTION_DIGITS_DEFAULT = 2; -export const CurrencyLabel = (props: CurrencyLabelProps): JSX.Element => { - const { value, fractionDigits, currencySymbol } = props; +export const CurrencyLabel = ({ + value, + fractionDigits = FRACTION_DIGITS_DEFAULT, + currencySymbol, + ...rest +}: CurrencyLabelProps): JSX.Element => { return ( - + {CurrencyHelper.format(value, { fractionDigits })} {currencySymbol && String.fromCharCode(0xa0) /*   */} @@ -33,26 +35,24 @@ export const CurrencyLabel = (props: CurrencyLabelProps): JSX.Element => { CurrencyLabel.__KONTUR_REACT_UI__ = 'CurrencyLabel'; -CurrencyLabel.defaultProps = defaultProps; - CurrencyLabel.propTypes = { - fractionDigits: (props: CurrencyLabelProps & typeof defaultProps) => { - if (props.fractionDigits > MAX_SAFE_DIGITS) { + fractionDigits: ({ fractionDigits = FRACTION_DIGITS_DEFAULT, value }: CurrencyLabelProps) => { + if (fractionDigits > MAX_SAFE_DIGITS) { return new Error( `[CurrencyLabel]: Prop 'fractionDigits' exceeds ${MAX_SAFE_DIGITS}.` + `\nSee https://tech.skbkontur.ru/react-ui/#/CurrencyInput?id=why15`, ); } - const { fraction } = CurrencyHelper.destructString(String(props.value)) || { fraction: '' }; - if (fraction.length > props.fractionDigits) { + const { fraction } = CurrencyHelper.destructString(String(value)) || { fraction: '' }; + if (fraction.length > fractionDigits) { return new Error( `[CurrencyLabel]: Prop 'fractionDigits' less than fractional part of the 'value' property,` + `'value' will not be cutted`, ); } - if (!Number.isInteger(props.fractionDigits)) { + if (!Number.isInteger(fractionDigits)) { return new Error( `[CurrencyLabel]: Prop 'fractionDigits' is not integer, fraction part of these property will not be used`, ); diff --git a/packages/react-ui/components/DateInput/DateInput.tsx b/packages/react-ui/components/DateInput/DateInput.tsx index 679406fbb1a..6ee8b9d9166 100644 --- a/packages/react-ui/components/DateInput/DateInput.tsx +++ b/packages/react-ui/components/DateInput/DateInput.tsx @@ -26,7 +26,7 @@ export type DateInputState = { dragged: boolean; }; -export type DateInputProps = { +type DateInputInterface = { autoFocus?: boolean; /** * Cостояние валидации при ошибке. @@ -48,8 +48,9 @@ export type DateInputProps = { */ onValueChange?: (value: string) => void; onKeyDown?: (x0: React.KeyboardEvent) => void; -} & CommonProps & - Partial; +}; + +export type DateInputProps = DateInputInterface & CommonProps & Partial; type DefaultProps = { value: string; diff --git a/packages/react-ui/components/DatePicker/DatePicker.tsx b/packages/react-ui/components/DatePicker/DatePicker.tsx index 9116bf660b9..31a02e73d72 100644 --- a/packages/react-ui/components/DatePicker/DatePicker.tsx +++ b/packages/react-ui/components/DatePicker/DatePicker.tsx @@ -30,7 +30,7 @@ const INPUT_PASS_PROPS = { export const MIN_WIDTH = 120; -export type DatePickerProps = { +type DatePickerInterface = { autoFocus?: boolean; disabled?: boolean; enableTodayLink?: boolean; @@ -64,8 +64,9 @@ export type DatePickerProps = { * - На iOS нативный календарь не умеет работать с minDate и maxDate */ useMobileNativeDatePicker?: boolean; -} & CommonProps & - Partial>; +}; + +export type DatePickerProps = DatePickerInterface & CommonProps & Partial>; export type DatePickerState = { opened: boolean; diff --git a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx index fbc8be297e0..d38e63a641f 100644 --- a/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx +++ b/packages/react-ui/components/DropdownMenu/DropdownMenu.tsx @@ -9,7 +9,7 @@ import { PopupPositionsType } from '../../internal/Popup'; import { CommonWrapper, CommonProps } from '../../internal/CommonWrapper'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -export type DropdownMenuProps = { +type DropdownMenuInterface = { /** Максимальная высота меню */ menuMaxHeight?: React.CSSProperties['maxWidth']; /** Ширина меню */ @@ -39,8 +39,9 @@ export type DropdownMenuProps = { footer?: React.ReactNode; onOpen?: () => void; onClose?: () => void; -} & CommonProps & - Partial; +}; + +export type DropdownMenuProps = DropdownMenuInterface & CommonProps & Partial; type DefaultProps = { /** diff --git a/packages/react-ui/components/Gapped/Gapped.tsx b/packages/react-ui/components/Gapped/Gapped.tsx index ca4490baa29..9b6a44e64c8 100644 --- a/packages/react-ui/components/Gapped/Gapped.tsx +++ b/packages/react-ui/components/Gapped/Gapped.tsx @@ -7,15 +7,16 @@ import { Theme } from '../../lib/theming/Theme'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { rootNode, TSetRootNode } from '../../lib/rootNode'; -export type GappedProps = { +type GappedInterface = { /** * Расстояние между элементами в пикселях * @default 8 */ gap?: number; children: React.ReactNode; -} & CommonProps & - Partial; +}; + +export type GappedProps = GappedInterface & CommonProps & Partial; type DefaultProps = { /** diff --git a/packages/react-ui/components/Hint/Hint.tsx b/packages/react-ui/components/Hint/Hint.tsx index 1870cb7e6db..95f12283019 100644 --- a/packages/react-ui/components/Hint/Hint.tsx +++ b/packages/react-ui/components/Hint/Hint.tsx @@ -15,7 +15,7 @@ import { styles } from './Hint.styles'; const HINT_BORDER_COLOR = 'transparent'; -export type HintProps = { +type HintInterface = { children?: React.ReactNode; /** * HTML-событие `mouseenter`. @@ -29,8 +29,9 @@ export type HintProps = { * Текст подсказки. */ text: React.ReactNode; -} & CommonProps & - Partial; +}; + +export type HintProps = HintInterface & CommonProps & Partial; export type HintState = { opened: boolean; diff --git a/packages/react-ui/components/Kebab/Kebab.tsx b/packages/react-ui/components/Kebab/Kebab.tsx index 76a8adcb2e3..c298da86c09 100644 --- a/packages/react-ui/components/Kebab/Kebab.tsx +++ b/packages/react-ui/components/Kebab/Kebab.tsx @@ -18,11 +18,12 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { styles } from './Kebab.styles'; -export type KebabProps = { +type KebabInterface = { disabled?: boolean; menuMaxHeight?: number | string; -} & CommonProps & - Partial; +}; + +export type KebabProps = KebabInterface & CommonProps & Partial; export type KebabState = { anchor: Nullable; diff --git a/packages/react-ui/components/Loader/Loader.tsx b/packages/react-ui/components/Loader/Loader.tsx index 69ad1a6e5f5..80a314e4f44 100644 --- a/packages/react-ui/components/Loader/Loader.tsx +++ b/packages/react-ui/components/Loader/Loader.tsx @@ -17,7 +17,7 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { styles } from './Loader.styles'; -export type LoaderProps = { +type LoaderInterface = { children?: React.ReactNode; caption?: SpinnerProps['caption']; /** @@ -25,8 +25,9 @@ export type LoaderProps = { */ component?: React.ReactNode; className?: string; -} & CommonProps & - Partial; +}; + +export type LoaderProps = LoaderInterface & CommonProps & Partial; export type LoaderState = { isStickySpinner: boolean; diff --git a/packages/react-ui/components/Modal/Modal.tsx b/packages/react-ui/components/Modal/Modal.tsx index 51f77bec1ca..9cb5afeff72 100644 --- a/packages/react-ui/components/Modal/Modal.tsx +++ b/packages/react-ui/components/Modal/Modal.tsx @@ -24,7 +24,7 @@ import { styles } from './Modal.styles'; let mountedModalsCount = 0; -export type ModalProps = { +type ModalInterface = { /** * Отключает событие onClose, также дизейблит кнопку закрытия модалки */ @@ -51,8 +51,9 @@ export type ModalProps = { * Escape или на крестик). */ onClose?: () => void; -} & CommonProps & - Partial; +}; + +export type ModalProps = ModalInterface & CommonProps & Partial; export type ModalState = { stackPosition: number; diff --git a/packages/react-ui/components/Paging/Paging.tsx b/packages/react-ui/components/Paging/Paging.tsx index d03009c1a06..c75e45fb29a 100644 --- a/packages/react-ui/components/Paging/Paging.tsx +++ b/packages/react-ui/components/Paging/Paging.tsx @@ -30,7 +30,7 @@ type ItemComponentProps = { tabIndex: number; }; -export type PagingProps = { +type PagingInterface = { activePage: number; onPageChange: (pageNumber: number) => void; pagesCount: number; @@ -42,8 +42,9 @@ export type PagingProps = { */ withoutNavigationHint?: boolean; caption?: string; -} & CommonProps & - Partial; +}; + +export type PagingProps = PagingInterface & CommonProps & Partial; export type PagingState = { focusedByTab: boolean; diff --git a/packages/react-ui/components/PasswordInput/PasswordInput.tsx b/packages/react-ui/components/PasswordInput/PasswordInput.tsx index f63c3dbb9e4..26b269191f4 100644 --- a/packages/react-ui/components/PasswordInput/PasswordInput.tsx +++ b/packages/react-ui/components/PasswordInput/PasswordInput.tsx @@ -15,11 +15,11 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { styles } from './PasswordInput.styles'; -export type PasswordInputProps = { +type PasswordInputInterface = { detectCapsLock?: boolean; -} & CommonProps & - InputProps & - Partial; +}; + +export type PasswordInputProps = PasswordInputInterface & CommonProps & InputProps & Partial; export type PasswordInputState = { visible: boolean; diff --git a/packages/react-ui/components/RadioGroup/RadioGroup.tsx b/packages/react-ui/components/RadioGroup/RadioGroup.tsx index 31ef1ff31c4..79d1a2ab461 100644 --- a/packages/react-ui/components/RadioGroup/RadioGroup.tsx +++ b/packages/react-ui/components/RadioGroup/RadioGroup.tsx @@ -16,7 +16,7 @@ import { styles } from './RadioGroup.styles'; import { Prevent } from './Prevent'; import { RadioGroupContext, RadioGroupContextType } from './RadioGroupContext'; -export type RadioGroupProps = { +type RadioGroupInterface = { /** * Значение по умолчанию. Должно быть одним из значений дочерних радиокнопок * или значений из параметра `items` @@ -68,8 +68,9 @@ export type RadioGroupProps = { onMouseLeave?: () => any; onMouseOver?: () => any; onMouseEnter?: () => any; -} & CommonProps & - Partial>; +}; + +export type RadioGroupProps = RadioGroupInterface & CommonProps & Partial>; export type RadioGroupState = { activeItem?: T; diff --git a/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx b/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx index a02a26b403d..a6186bea468 100644 --- a/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx +++ b/packages/react-ui/components/ScrollContainer/ScrollContainer.tsx @@ -22,15 +22,16 @@ export type ScrollContainerScrollStateY = 'top' | 'scroll' | 'bottom'; export type ScrollContainerScrollState = ScrollContainerScrollStateY; // deprecated export type ScrollBehaviour = 'auto' | 'smooth'; -export type ScrollContainerProps = { +type ScrollContainerInterface = { maxHeight?: React.CSSProperties['maxHeight']; maxWidth?: React.CSSProperties['maxWidth']; onScrollStateChangeX?: (scrollState: ScrollContainerScrollStateX) => void; onScrollStateChangeY?: (scrollState: ScrollContainerScrollStateY) => void; onScrollStateChange?: (scrollYState: ScrollContainerScrollState) => void; // deprecated onScroll?: (e: React.UIEvent) => void; -} & CommonProps & - Partial; +}; + +export type ScrollContainerProps = ScrollContainerInterface & CommonProps & Partial; type DefaultProps = { /** diff --git a/packages/react-ui/components/Select/Select.tsx b/packages/react-ui/components/Select/Select.tsx index 7305e32162e..d91119fe983 100644 --- a/packages/react-ui/components/Select/Select.tsx +++ b/packages/react-ui/components/Select/Select.tsx @@ -55,7 +55,7 @@ const PASS_BUTTON_PROPS = { onMouseOver: true, }; -export type SelectProps = { +type SelectInterface = { /** @ignore */ _icon?: React.ReactNode; /** @ignore */ @@ -120,7 +120,10 @@ export type SelectProps = { size?: ButtonSize; onFocus?: React.FocusEventHandler; onBlur?: React.FocusEventHandler; -} & CommonProps & +}; + +export type SelectProps = SelectInterface & + CommonProps & Partial>; export type SelectState = { diff --git a/packages/react-ui/components/SidePage/SidePage.tsx b/packages/react-ui/components/SidePage/SidePage.tsx index 910eb6d202b..4b3b409b5ae 100644 --- a/packages/react-ui/components/SidePage/SidePage.tsx +++ b/packages/react-ui/components/SidePage/SidePage.tsx @@ -23,7 +23,7 @@ import { SidePageFooter } from './SidePageFooter'; import { SidePageHeader } from './SidePageHeader'; import { styles } from './SidePage.styles'; -export type SidePageProps = { +type SidePageInterface = { /** * Добавить блокирующий фон, когда сайдпейдж открыт */ @@ -55,8 +55,9 @@ export type SidePageProps = { * */ fromLeft?: boolean; -} & CommonProps & - Partial; +}; + +export type SidePageProps = SidePageInterface & CommonProps & Partial; export type SidePageState = { stackPosition?: number; diff --git a/packages/react-ui/components/Spinner/Spinner.tsx b/packages/react-ui/components/Spinner/Spinner.tsx index 6b779d01b0a..b4a84a59443 100644 --- a/packages/react-ui/components/Spinner/Spinner.tsx +++ b/packages/react-ui/components/Spinner/Spinner.tsx @@ -20,7 +20,7 @@ const types: Record = { export type SpinnerType = 'mini' | 'normal' | 'big'; -export type SpinnerProps = { +type SpinnerInterface = { caption?: React.ReactNode; dimmed?: boolean; /** @@ -31,8 +31,9 @@ export type SpinnerProps = { * Цвет спиннера */ color?: React.CSSProperties['color']; -} & CommonProps & - Partial; +}; + +export type SpinnerProps = SpinnerInterface & CommonProps & Partial; type DefaultProps = { /** diff --git a/packages/react-ui/components/Sticky/Sticky.tsx b/packages/react-ui/components/Sticky/Sticky.tsx index 9ec7ac290c1..5fb4bda5b15 100644 --- a/packages/react-ui/components/Sticky/Sticky.tsx +++ b/packages/react-ui/components/Sticky/Sticky.tsx @@ -14,12 +14,13 @@ import { styles } from './Sticky.styles'; const MAX_REFLOW_RETRIES = 5; -export type StickyProps = { +type StickyInterface = { side: 'top' | 'bottom'; getStop?: () => Nullable; children?: React.ReactNode | ((fixed: boolean) => React.ReactNode); -} & CommonProps & - Partial; +}; + +export type StickyProps = StickyInterface & CommonProps & Partial; export type StickyState = { fixed: boolean; diff --git a/packages/react-ui/components/Tabs/Tab.tsx b/packages/react-ui/components/Tabs/Tab.tsx index 601a8eac24b..a55e3979a5e 100644 --- a/packages/react-ui/components/Tabs/Tab.tsx +++ b/packages/react-ui/components/Tabs/Tab.tsx @@ -24,7 +24,7 @@ export type TabIndicators = { disabled: boolean; }; -export type TabProps = { +type TabInterface = { /** * Tab content */ @@ -74,8 +74,9 @@ export type TabProps = { * Style property */ style?: React.CSSProperties; -} & CommonProps & - Partial; +}; + +export type TabProps = TabInterface & CommonProps & Partial; export type TabState = { focusedByKeyboard: boolean; diff --git a/packages/react-ui/components/Tabs/Tabs.tsx b/packages/react-ui/components/Tabs/Tabs.tsx index 32f4e90e284..0175aace9cb 100644 --- a/packages/react-ui/components/Tabs/Tabs.tsx +++ b/packages/react-ui/components/Tabs/Tabs.tsx @@ -13,7 +13,7 @@ import { styles } from './Tabs.styles'; import { TabsContext, TabsContextType } from './TabsContext'; import { Tab } from './Tab'; -export type TabsProps = { +type TabsInterface = { /** * Tab component should be child of Tabs component */ @@ -38,8 +38,7 @@ export type TabsProps = { * Width of tabs container */ width?: number | string; -} & CommonProps & - Partial; +}; type DefaultProps = { /** @@ -49,6 +48,8 @@ type DefaultProps = { vertical: boolean; }; +export type TabsProps = TabsInterface & CommonProps & Partial; + type TabsComponentProps = TabsProps & DefaultProps; /** diff --git a/packages/react-ui/components/Toggle/Toggle.tsx b/packages/react-ui/components/Toggle/Toggle.tsx index 8bd61b06954..bfa7f7ea60b 100644 --- a/packages/react-ui/components/Toggle/Toggle.tsx +++ b/packages/react-ui/components/Toggle/Toggle.tsx @@ -13,7 +13,7 @@ import { styles, globalClasses } from './Toggle.styles'; let colorWarningShown = false; -export type ToggleProps = { +type ToggleInterface = { children?: React.ReactNode; /** * Состояние `тогла`, если `true` - `тогл` будет включён, иначе выключен. @@ -62,8 +62,9 @@ export type ToggleProps = { * HTML-атрибут `id` для передачи во внутренний ``. */ id?: string; -} & CommonProps & - Partial; +}; + +export type ToggleProps = ToggleInterface & CommonProps & Partial; export type ToggleState = { checked?: boolean; diff --git a/packages/react-ui/components/TokenInput/TokenInput.tsx b/packages/react-ui/components/TokenInput/TokenInput.tsx index 802a2c54446..021c72e69fa 100644 --- a/packages/react-ui/components/TokenInput/TokenInput.tsx +++ b/packages/react-ui/components/TokenInput/TokenInput.tsx @@ -41,7 +41,7 @@ export enum TokenInputType { export type TokenInputMenuAlign = 'left' | 'cursor'; -export type TokenInputProps = { +type TokenInputInterface = { autoFocus?: boolean; type?: TokenInputType; /** @@ -93,8 +93,9 @@ export type TokenInputProps = { */ onUnexpectedInput?: (value: string) => void | null | undefined | T; inputMode?: React.HTMLAttributes['inputMode']; -} & CommonProps & - Partial>; +}; + +export type TokenInputProps = TokenInputInterface & CommonProps & Partial>; export type TokenInputState = { autocompleteItems?: T[]; diff --git a/packages/react-ui/components/Tooltip/Tooltip.tsx b/packages/react-ui/components/Tooltip/Tooltip.tsx index fa336948822..928cee2afef 100644 --- a/packages/react-ui/components/Tooltip/Tooltip.tsx +++ b/packages/react-ui/components/Tooltip/Tooltip.tsx @@ -35,7 +35,7 @@ export type TooltipTrigger = /** Управление через публичные функции show и hide */ | 'manual'; -export type TooltipProps = { +type TooltipInterface = { /** * Относительно какого элемента позиционировать тултип */ @@ -89,8 +89,9 @@ export type TooltipProps = { * _Примечание_: при **двух и более** вложенных элементах обёртка будет добавлена автоматически. */ useWrapper: boolean; -} & CommonProps & - Partial; +}; + +export type TooltipProps = TooltipInterface & CommonProps & Partial; export type TooltipState = { opened: boolean; diff --git a/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx b/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx index 466748c8669..8fb45b93f14 100644 --- a/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx +++ b/packages/react-ui/components/TooltipMenu/TooltipMenu.tsx @@ -12,7 +12,7 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; export type TooltipMenuChildType = React.ReactElement; -export type TooltipMenuProps = { +type TooltipMenuInterface = { children?: TooltipMenuChildType | TooltipMenuChildType[]; /** Максимальная высота меню */ menuMaxHeight?: number | string; @@ -44,8 +44,9 @@ export type TooltipMenuProps = { * **Возможные значения**: `top left`, `top center`, `top right`, `right top`, `right middle`, `right bottom`, `bottom left`, `bottom center`, `bottom right`, `left top`, `left middle`, `left bottom` */ positions?: PopupPositionsType[]; -} & CommonProps & - Partial; +}; + +export type TooltipMenuProps = TooltipMenuInterface & CommonProps & Partial; type DefaultProps = { /** diff --git a/packages/react-ui/internal/BGRuler.tsx b/packages/react-ui/internal/BGRuler.tsx index cb91a11b939..8f9e4dc3db3 100644 --- a/packages/react-ui/internal/BGRuler.tsx +++ b/packages/react-ui/internal/BGRuler.tsx @@ -1,9 +1,11 @@ import React from 'react'; -type BGRulerProps = { +type BGRulerInterface = { width?: string | number; bottom?: string | number; -} & Partial; +}; + +type BGRulerProps = BGRulerInterface & Partial; type DefaultProps = { height: string | number; diff --git a/packages/react-ui/internal/Calendar/Calendar.tsx b/packages/react-ui/internal/Calendar/Calendar.tsx index 635c07b0eca..64f4dd5a97f 100644 --- a/packages/react-ui/internal/Calendar/Calendar.tsx +++ b/packages/react-ui/internal/Calendar/Calendar.tsx @@ -17,13 +17,15 @@ import { Month } from './Month'; import { styles } from './Calendar.styles'; import { CalendarDateShape, create, isGreater, isLess } from './CalendarDateShape'; -export type CalendarProps = { +type CalendarInterface = { initialMonth?: number; initialYear?: number; onSelect?: (date: CalendarDateShape) => void; value?: Nullable; isHoliday?: (day: CalendarDateShape & { isWeekend: boolean }) => boolean; -} & Partial; +}; + +export type CalendarProps = CalendarInterface & Partial; export type CalendarState = { scrollPosition: number; diff --git a/packages/react-ui/internal/Calendar/Month.tsx b/packages/react-ui/internal/Calendar/Month.tsx index 36c4e28b505..83753cf572d 100644 --- a/packages/react-ui/internal/Calendar/Month.tsx +++ b/packages/react-ui/internal/Calendar/Month.tsx @@ -129,7 +129,7 @@ export class Month extends React.Component { }; } -type MonthDayGridProps = { +type MonthDayGridInterface = { days: DayCellViewModel[]; offset: number; minDate?: CDS.CalendarDateShape; @@ -137,7 +137,9 @@ type MonthDayGridProps = { today?: CDS.CalendarDateShape; value?: Nullable; onDateClick?: (x0: CDS.CalendarDateShape) => void; -} & Partial; +}; + +type MonthDayGridProps = MonthDayGridInterface & Partial; type DefaultProps = { isHoliday: (day: CDS.CalendarDateShape & { isWeekend: boolean }) => boolean; diff --git a/packages/react-ui/internal/ComponentCombinator.tsx b/packages/react-ui/internal/ComponentCombinator.tsx index a91b9be57f4..8bdbddb2afd 100644 --- a/packages/react-ui/internal/ComponentCombinator.tsx +++ b/packages/react-ui/internal/ComponentCombinator.tsx @@ -4,10 +4,12 @@ import { DefaultizeProps } from '../lib/utils'; import { ComponentTable, StatePropsCombinations, StateType } from './ComponentTable'; -export type ComponentCombinatorProps = { +type ComponentCombinatorInterface = { combinations: Array>; Component: C; -} & DefaultProps; +}; + +export type ComponentCombinatorProps = ComponentCombinatorInterface & DefaultProps; type DefaultProps = { presetProps: DefaultizeProps; diff --git a/packages/react-ui/internal/ComponentTable.tsx b/packages/react-ui/internal/ComponentTable.tsx index 4d3f0799e3d..b8734ab5dc9 100644 --- a/packages/react-ui/internal/ComponentTable.tsx +++ b/packages/react-ui/internal/ComponentTable.tsx @@ -32,11 +32,13 @@ export type StatePropsCombinations = Array<{ props?: Partial

; state?: P export type StateType = C extends React.Component | React.ComponentClass ? S : never; -export type ComponentTableProps = { +type ComponentTableInterface = { rows?: StatePropsCombinations; cols?: StatePropsCombinations; Component: C; -} & Partial>; +}; + +export type ComponentTableProps = ComponentTableInterface & Partial>; type DefaultProps = { presetProps: DefaultizeProps; diff --git a/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx b/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx index e21e1a045aa..3a36929ea36 100644 --- a/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx +++ b/packages/react-ui/internal/CustomComboBox/ComboBoxMenu.tsx @@ -10,7 +10,7 @@ import { MenuSeparator } from '../../components/MenuSeparator'; import { ComboBoxRequestStatus } from './CustomComboBoxTypes'; import { ComboBoxLocale, CustomComboBoxLocaleHelper } from './locale'; -export type ComboBoxMenuProps = { +type ComboBoxMenuInterface = { opened?: boolean; items?: Nullable; totalCount?: number; @@ -23,7 +23,9 @@ export type ComboBoxMenuProps = { onValueChange: (value: T) => any; renderAddButton?: () => React.ReactNode; caption?: React.ReactNode; -} & Partial; +}; + +export type ComboBoxMenuProps = ComboBoxMenuInterface & Partial; type DefaultProps = { repeatRequest: () => void; diff --git a/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx b/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx index cb44ad5ab30..939440e8e15 100644 --- a/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx +++ b/packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx @@ -17,7 +17,7 @@ import { ComboBoxMenu } from './ComboBoxMenu'; import { ComboBoxRequestStatus } from './CustomComboBoxTypes'; import { styles } from './CustomComboBox.styles'; -type ComboBoxViewProps = { +type ComboBoxViewInterface = { align?: 'left' | 'center' | 'right'; autoFocus?: boolean; borderless?: boolean; @@ -61,8 +61,9 @@ type ComboBoxViewProps = { refInput?: (input: Nullable) => void; refMenu?: (menu: Nullable

) => void; refInputLikeText?: (inputLikeText: Nullable) => void; -} & CommonProps & - Partial>; +}; + +type ComboBoxViewProps = ComboBoxViewInterface & CommonProps & Partial>; type DefaultProps = { renderItem: (item: T, state: MenuItemState) => React.ReactNode; diff --git a/packages/react-ui/internal/DateSelect/DateSelect.tsx b/packages/react-ui/internal/DateSelect/DateSelect.tsx index 72732456f7f..0899f9179b4 100644 --- a/packages/react-ui/internal/DateSelect/DateSelect.tsx +++ b/packages/react-ui/internal/DateSelect/DateSelect.tsx @@ -23,13 +23,15 @@ const monthsCount = 12; const defaultMinYear = 1900; const defaultMaxYear = 2100; -export type DateSelectProps = { +type DataSelectInterface = { disabled?: boolean | null; onValueChange: (value: number) => void; value: number; minValue?: number; maxValue?: number; -} & Partial; +}; + +export type DateSelectProps = DataSelectInterface & Partial; export type DateSelectState = { botCapped: boolean; diff --git a/packages/react-ui/internal/DropdownContainer/DropdownContainer.tsx b/packages/react-ui/internal/DropdownContainer/DropdownContainer.tsx index 5dd9405021c..40123e81e0f 100644 --- a/packages/react-ui/internal/DropdownContainer/DropdownContainer.tsx +++ b/packages/react-ui/internal/DropdownContainer/DropdownContainer.tsx @@ -16,11 +16,13 @@ export type DropdownContainerPosition = { right: Nullable; }; -export type DropdownContainerProps = { +type DropdownContainerInterface = { getParent: () => Nullable; children?: React.ReactNode; hasFixedWidth?: boolean; -} & Partial; +}; + +export type DropdownContainerProps = DropdownContainerInterface & Partial; export type DropdownContainerState = { position: Nullable; diff --git a/packages/react-ui/internal/InputLikeText/InputLikeText.tsx b/packages/react-ui/internal/InputLikeText/InputLikeText.tsx index a5356ad97a2..1dd43d4d923 100644 --- a/packages/react-ui/internal/InputLikeText/InputLikeText.tsx +++ b/packages/react-ui/internal/InputLikeText/InputLikeText.tsx @@ -18,7 +18,7 @@ import { TSetRootNode, rootNode } from '../../lib/rootNode'; import { styles } from './InputLikeText.styles'; import { HiddenInput } from './HiddenInput'; -export type InputLikeTextProps = { +type InputLikeTextInterface = { children?: React.ReactNode; innerRef?: (el: HTMLElement | null) => void; onFocus?: React.FocusEventHandler; @@ -26,9 +26,9 @@ export type InputLikeTextProps = { onMouseDragStart?: MouseDragEventHandler; onMouseDragEnd?: MouseDragEventHandler; takeContentWidth?: boolean; -} & CommonProps & - InputProps & - Partial; +}; + +export type InputLikeTextProps = InputLikeTextInterface & CommonProps & InputProps & Partial; type DefaultProps = { size: InputProps['size']; diff --git a/packages/react-ui/internal/InternalMenu/InternalMenu.tsx b/packages/react-ui/internal/InternalMenu/InternalMenu.tsx index 29f8e12a09e..4406c0cbe20 100644 --- a/packages/react-ui/internal/InternalMenu/InternalMenu.tsx +++ b/packages/react-ui/internal/InternalMenu/InternalMenu.tsx @@ -13,13 +13,15 @@ import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; import { styles } from './InternalMenu.styles'; import { isActiveElement } from './isActiveElement'; -type MenuProps = { +type MenuInterface = { children?: React.ReactNode; onItemClick?: (event: React.SyntheticEvent) => void; onKeyDown?: (event: React.KeyboardEvent) => void; header?: React.ReactNode; footer?: React.ReactNode; -} & Partial; +}; + +type MenuProps = MenuInterface & Partial; type MenuState = { highlightedIndex: number; diff --git a/packages/react-ui/internal/MaskedInput/MaskedInput.tsx b/packages/react-ui/internal/MaskedInput/MaskedInput.tsx index e3fc3a42fbd..a312ebf18f0 100644 --- a/packages/react-ui/internal/MaskedInput/MaskedInput.tsx +++ b/packages/react-ui/internal/MaskedInput/MaskedInput.tsx @@ -8,7 +8,7 @@ import { cx } from '../../lib/theming/Emotion'; import { styles } from './MaskedInput.styles'; -export type MaskedInputProps = { +type MaskedInputInterface = { mask: string; formatChars?: { [key: string]: string }; alwaysShowMask?: boolean; @@ -16,7 +16,10 @@ export type MaskedInputProps = { hasRightIcon?: boolean; onUnexpectedInput?: (value: string) => void; onValueChange?: (value: string) => void; -} & React.InputHTMLAttributes & +}; + +export type MaskedInputProps = MaskedInputInterface & + React.InputHTMLAttributes & Partial; type MaskedInputState = { diff --git a/packages/react-ui/internal/Menu/Menu.tsx b/packages/react-ui/internal/Menu/Menu.tsx index 6f58dae586f..b35f4459ce5 100644 --- a/packages/react-ui/internal/Menu/Menu.tsx +++ b/packages/react-ui/internal/Menu/Menu.tsx @@ -13,10 +13,12 @@ import { isIE11 } from '../../lib/client'; import { styles } from './Menu.styles'; import { isActiveElement } from './isActiveElement'; -export type MenuProps = { +type MenuInterface = { children: React.ReactNode; onItemClick?: () => void; -} & Partial; +}; + +export type MenuProps = MenuInterface & Partial; export type MenuState = { highlightedIndex: number; diff --git a/packages/react-ui/internal/Popup/Popup.tsx b/packages/react-ui/internal/Popup/Popup.tsx index 353eefd12d1..ba9b70865a7 100644 --- a/packages/react-ui/internal/Popup/Popup.tsx +++ b/packages/react-ui/internal/Popup/Popup.tsx @@ -63,7 +63,7 @@ export type PopupHandlerProps = { onClose?: () => void; }; -export type PopupProps = { +type PopupInterface = { anchorElement: React.ReactNode | HTMLElement; backgroundColor?: React.CSSProperties['backgroundColor']; borderColor?: React.CSSProperties['borderColor']; @@ -82,9 +82,9 @@ export type PopupProps = { * @see https://github.com/skbkontur/retail-ui/pull/1195 */ tryPreserveFirstRenderedPosition?: boolean; -} & CommonProps & - PopupHandlerProps & - Partial; +}; + +export type PopupProps = PopupInterface & CommonProps & PopupHandlerProps & Partial; type PopupLocation = { coordinates: { diff --git a/packages/react-ui/internal/PopupMenu/PopupMenu.tsx b/packages/react-ui/internal/PopupMenu/PopupMenu.tsx index a81fdd1e4af..bbbf9c03a1e 100644 --- a/packages/react-ui/internal/PopupMenu/PopupMenu.tsx +++ b/packages/react-ui/internal/PopupMenu/PopupMenu.tsx @@ -24,7 +24,7 @@ export type PopupMenuCaptionProps = { toggleMenu: () => void; }; -export type PopupMenuProps = { +type PopupMenuInterface = { children?: React.ReactNode; /** Максимальная высота меню */ menuMaxHeight?: number | string; @@ -47,8 +47,9 @@ export type PopupMenuProps = { onChangeMenuState?: (isOpened: boolean, restoreFocus: boolean) => void; popupMargin?: number; popupPinOffset?: number; -} & CommonProps & - Partial; +}; + +export type PopupMenuProps = PopupMenuInterface & CommonProps & Partial; type PopupMenuState = { menuVisible: boolean; diff --git a/packages/react-ui/internal/RenderLayer/RenderLayer.tsx b/packages/react-ui/internal/RenderLayer/RenderLayer.tsx index 05e3d21a2d2..20d727a750d 100644 --- a/packages/react-ui/internal/RenderLayer/RenderLayer.tsx +++ b/packages/react-ui/internal/RenderLayer/RenderLayer.tsx @@ -5,13 +5,14 @@ import { CommonProps, CommonWrapper } from '../CommonWrapper'; import { getRootNode, rootNode, TSetRootNode } from '../../lib/rootNode'; import { Nullable } from '../../typings/utility-types'; -export type RenderLayerProps = { +type RenderLayerInterface = { children: JSX.Element; onClickOutside?: (e: Event) => void; onFocusOutside?: (e: Event) => void; getAnchorElement?: () => Nullable; -} & CommonProps & - Partial; +}; + +export type RenderLayerProps = RenderLayerInterface & CommonProps & Partial; type DefaultProps = { active: boolean; diff --git a/packages/react-ui/internal/ThemePlayground/VariableValue.tsx b/packages/react-ui/internal/ThemePlayground/VariableValue.tsx index 6db2f68ccc8..4e8d5c16c3c 100644 --- a/packages/react-ui/internal/ThemePlayground/VariableValue.tsx +++ b/packages/react-ui/internal/ThemePlayground/VariableValue.tsx @@ -15,14 +15,16 @@ import { styles } from './Playground.styles'; const emitter = new EventEmitter(); -export type VariableValueProps = { +type VariableValueInterface = { onChange: (variable: keyof Theme, value: string) => void; value: string; isError: boolean; variable: string; theme: Theme; baseVariables: Array; -} & Partial; +}; + +export type VariableValueProps = VariableValueInterface & Partial; export type VariableValueState = { value: string; diff --git a/packages/react-ui/internal/ZIndex/ZIndex.tsx b/packages/react-ui/internal/ZIndex/ZIndex.tsx index 3d449d95e98..7b6ca276297 100644 --- a/packages/react-ui/internal/ZIndex/ZIndex.tsx +++ b/packages/react-ui/internal/ZIndex/ZIndex.tsx @@ -10,11 +10,12 @@ const ZIndexContext = React.createContext({ parentLayerZIndex: 0, maxZIndex: Inf ZIndexContext.displayName = 'ZIndexContext'; -export type ZIndexProps = { +type ZIndexInterface = { className?: string; wrapperRef?: React.Ref | undefined | null; -} & React.HTMLAttributes & - Partial; +}; + +export type ZIndexProps = ZIndexInterface & React.HTMLAttributes & Partial; type DefaultProps = { /** From 55c5f82625270e43bc3d4aab20cbd3d92aaec4e0 Mon Sep 17 00:00:00 2001 From: HelenaIsh Date: Tue, 22 Feb 2022 10:13:44 +0500 Subject: [PATCH 10/11] chore: mark createPropsGetter as deprecated --- packages/react-ui/lib/createPropsGetter.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 packages/react-ui/lib/createPropsGetter.ts diff --git a/packages/react-ui/lib/createPropsGetter.ts b/packages/react-ui/lib/createPropsGetter.ts new file mode 100644 index 00000000000..01b42b1630d --- /dev/null +++ b/packages/react-ui/lib/createPropsGetter.ts @@ -0,0 +1,10 @@ +import React from 'react'; + +/** + * @deprecated + */ +export function createPropsGetter(defaultProps: DP) { + return function >(this: T): DP & P { + return this.props as any; + }; +} From ed380f1c20dd09af14619123d7da4e3899ad9fa2 Mon Sep 17 00:00:00 2001 From: HelenaIsh Date: Fri, 4 Mar 2022 14:23:54 +0500 Subject: [PATCH 11/11] chore: prettier --- packages/react-ui/components/Input/__tests__/Input-test.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/react-ui/components/Input/__tests__/Input-test.tsx b/packages/react-ui/components/Input/__tests__/Input-test.tsx index 54002338411..60ef13f582b 100644 --- a/packages/react-ui/components/Input/__tests__/Input-test.tsx +++ b/packages/react-ui/components/Input/__tests__/Input-test.tsx @@ -5,8 +5,7 @@ import MaskedInput from 'react-input-mask'; import { Input, InputProps } from '../Input'; import { buildMountAttachTarget, getAttachedTarget } from '../../../lib/__tests__/testUtils'; -const render = (props: InputProps) => - mount(, { attachTo: getAttachedTarget() }); +const render = (props: InputProps) => mount(, { attachTo: getAttachedTarget() }); describe('', () => { buildMountAttachTarget();