@skbkontur/react-ui 6.2.0 → 6.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [6.2.1](https://github.com/skbkontur/retail-ui/compare/@skbkontur/react-ui@6.2.0...@skbkontur/react-ui@6.2.1) (2026-08-13)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Move `react-docgen` dependency to devDependencies
12
+
13
+
14
+
15
+
16
+
6
17
  # [6.2.0](https://github.com/skbkontur/retail-ui/compare/@skbkontur/react-ui@6.1.7...@skbkontur/react-ui@6.2.0) (2026-08-04)
7
18
 
8
19
 
@@ -40,7 +40,7 @@ interface SwitcherItem {
40
40
  buttonProps?: Partial<ButtonProps>;
41
41
  }
42
42
  /**
43
- * Переключатель используется для выбора одного значения из нескольких. Похож на [группу радиокнопок]https://tech.skbkontur.ru/kontur-ui/?path=/docs/react-ui_input-data-radiogroup--docs), но более компактный.
43
+ * Переключатель используется для выбора одного значения из нескольких. Похож на [группу радиокнопок](https://tech.skbkontur.ru/kontur-ui/?path=/docs/react-ui_input-data-radiogroup--docs), но более компактный.
44
44
  */
45
45
  export declare class Switcher extends React.Component<SwitcherProps, SwitcherState> {
46
46
  static __KONTUR_REACT_UI__: string;
@@ -54,7 +54,7 @@ export var SwitcherDataTids = {
54
54
  root: 'Switcher__root',
55
55
  };
56
56
  /**
57
- * Переключатель используется для выбора одного значения из нескольких. Похож на [группу радиокнопок]https://tech.skbkontur.ru/kontur-ui/?path=/docs/react-ui_input-data-radiogroup--docs), но более компактный.
57
+ * Переключатель используется для выбора одного значения из нескольких. Похож на [группу радиокнопок](https://tech.skbkontur.ru/kontur-ui/?path=/docs/react-ui_input-data-radiogroup--docs), но более компактный.
58
58
  */
59
59
  var Switcher = /** @class */ (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AC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;gBACpG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,6BAAK,SAAS,EAAE,gBAAgB,IAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAO,CAAC,CAAC,CAAC,IAAI;gBACzF,6BAAK,SAAS,EAAE,gBAAgB;oBAC9B,0CAAW,UAAU,EAAI;oBACxB,KAAK,CACF,CACF,CACQ,CACjB,CAAC;IACJ,CAAC;IA1Da,4BAAmB,GAAG,UAAU,AAAb,CAAc;IACjC,oBAAW,GAAG,UAAU,AAAb,CAAc;IAEzB,qBAAY,GAAiB;QACzC,IAAI,EAAE,QAAQ;KACf,AAFyB,CAExB;IANS,QAAQ;QAFpB,qBAAqB;QACrB,QAAQ;OACI,QAAQ,CA2MpB;IAAD,eAAC;CAAA,AA3MD,CAA8B,KAAK,CAAC,SAAS,GA2M5C;SA3MY,QAAQ","sourcesContent":["import type { Emotion } from '@emotion/css/create-instance';\nimport type { HTMLAttributes } from 'react';\nimport React from 'react';\n\nimport type { CommonProps } from '../../internal/CommonWrapper/index.js';\nimport { CommonWrapper } from '../../internal/CommonWrapper/index.js';\nimport { isKeyArrowHorizontal, isKeyArrowLeft, isKeyEnter } from '../../lib/events/keyboard/identifiers.js';\nimport { withRenderEnvironment } from '../../lib/renderEnvironment/index.js';\nimport type { TGetRootNode, TSetRootNode } from '../../lib/rootNode/index.js';\nimport { rootNode } from '../../lib/rootNode/index.js';\nimport type { Theme } from '../../lib/theming/Theme.js';\nimport { ThemeContext } from '../../lib/theming/ThemeContext.js';\nimport type { SizeProp } from '../../lib/types/props.js';\nimport type { Nullable } from '../../typings/utility-types.js';\nimport { Button } from '../Button/index.js';\nimport type { ButtonProps } from '../Button/index.js';\nimport { Group, getButtonCorners } from '../Group/index.js';\nimport { mod } from './helpers.js';\nimport { getStyles } from './Switcher.styles.js';\nimport { getSwitcherTheme } from './switcherTheme.js';\n\nexport type SwitcherItems = string | SwitcherItem;\n\nexport const SwitcherDataTids = {\n root: 'Switcher__root',\n} as const;\n\nexport interface SwitcherProps extends Pick<HTMLAttributes<unknown>, 'role'>, CommonProps {\n /** Задаёт список элементов в свитчере. Это массив строк или объектов типа `{ label: string, value: string, buttonProps?: Partial<ButtonProps> }` */\n items: SwitcherItems[];\n\n /** Значение свитчера. */\n value?: string;\n\n /** Событие изменения значения свитчера (value). */\n onValueChange?: (value: string) => void;\n\n /** Подпись около свитчера. */\n caption?: string;\n\n /** Переводит свитчер в состояние ошибки. */\n error?: boolean;\n\n /** Размер свитчера. */\n size?: SizeProp;\n\n /** Ширина свитчера. С этим пропом элементы внутри автоматически равномерно растянутся. */\n width?: React.CSSProperties['width'];\n\n /** Блокирует свитчер. */\n disabled?: boolean;\n\n /** Задаёт функцию отрисовки элемента. Параметр `renderDefault` - это встроенная дефолтная функция отрисовки элемента, которую можно вызывать в `renderItem`. */\n renderItem?: (\n label: string,\n value: string,\n buttonProps: ButtonProps,\n renderDefault: () => React.ReactNode,\n ariaLabel?: string,\n ) => React.ReactNode;\n}\n\ntype DefaultProps = Required<Pick<SwitcherProps, 'role'>>;\n\nexport interface SwitcherState {\n focusedIndex: Nullable<number>;\n}\n\ninterface SwitcherItem {\n value: string;\n label: string;\n 'aria-label'?: string;\n buttonProps?: Partial<ButtonProps>;\n}\n\n/**\n * Переключатель используется для выбора одного значения из нескольких. Похож на [группу радиокнопок]https://tech.skbkontur.ru/kontur-ui/?path=/docs/react-ui_input-data-radiogroup--docs), но более компактный.\n */\n@withRenderEnvironment\n@rootNode\nexport class Switcher extends React.Component<SwitcherProps, SwitcherState> {\n public static __KONTUR_REACT_UI__ = 'Switcher';\n public static displayName = 'Switcher';\n\n public static defaultProps: DefaultProps = {\n role: 'switch',\n };\n\n public state: SwitcherState = {\n focusedIndex: null,\n };\n\n private emotion!: Emotion;\n private cx!: Emotion['cx'];\n private styles!: ReturnType<typeof getStyles>;\n private theme!: Theme;\n public getRootNode!: TGetRootNode;\n private setRootNode!: TSetRootNode;\n\n public render(): React.JSX.Element {\n this.styles = getStyles(this.emotion);\n\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = getSwitcherTheme(theme);\n return <ThemeContext.Provider value={this.theme}>{this.renderMain()}</ThemeContext.Provider>;\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain() {\n const inputProps = {\n type: 'checkbox',\n onKeyDown: this.handleKey,\n onFocus: this._handleFocus,\n onBlur: this._handleBlur,\n className: this.styles.input(),\n };\n const items = <Group width={'100%'}>{this._renderItems()}</Group>;\n\n const captionClassName = this.cx(this.styles.caption(this.theme), this.getLabelSizeClassName());\n const wrapperClassName = this.cx(this.styles.wrap(), {\n [this.styles.error(this.theme)]: this.props.error,\n [this.styles.wrapCustomWidth()]: this.props.width !== undefined,\n });\n\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.props}>\n <div data-tid={SwitcherDataTids.root} className={this.styles.root()} style={{ width: this.props.width }}>\n {this.props.caption ? <div className={captionClassName}>{this.props.caption}</div> : null}\n <div className={wrapperClassName}>\n <input {...inputProps} />\n {items}\n </div>\n </div>\n </CommonWrapper>\n );\n }\n\n private selectItem = (value: string) => {\n if (this.props.onValueChange) {\n this.props.onValueChange(value);\n }\n };\n\n private _extractPropsFromItem = (item: string | SwitcherItem): SwitcherItem => {\n return typeof item === 'object' ? item : { label: item, value: item };\n };\n\n private _extractValuesFromItems = (): string[] => {\n return this.props.items.map((item) => {\n const { value } = this._extractPropsFromItem(item);\n return value;\n });\n };\n\n private _focus = (index: number) => {\n this.setState({ focusedIndex: index });\n };\n\n private handleKey = (e: React.KeyboardEvent<HTMLInputElement>) => {\n const focusedIndex = this.state.focusedIndex;\n if (typeof focusedIndex !== 'number') {\n return;\n }\n\n if (isKeyEnter(e)) {\n if (this.props.onValueChange) {\n const { value, buttonProps } = this._extractPropsFromItem(this.props.items[focusedIndex]);\n if (!buttonProps?.disabled) {\n this.selectItem(value);\n }\n }\n return;\n }\n\n if (isKeyArrowHorizontal(e)) {\n e.preventDefault();\n this.move(isKeyArrowLeft(e));\n }\n };\n\n private move = (left: boolean) => {\n const selectedIndex = this.state.focusedIndex;\n\n if (typeof selectedIndex !== 'number') {\n return;\n }\n const newFocusedIndex = this._getNextFocusedIndex(left, selectedIndex);\n this._focus(newFocusedIndex);\n };\n\n private _getNextFocusedIndex = (left: boolean, focusedIndex: number): number => {\n const { items, disabled } = this.props;\n if (disabled) {\n return focusedIndex;\n }\n\n for (let i = 1; i < items.length; i++) {\n const index = mod(focusedIndex + (left ? -i : i), items.length);\n const { buttonProps } = this._extractPropsFromItem(items[index]);\n if (!buttonProps?.disabled) {\n return index;\n }\n }\n return focusedIndex;\n };\n\n private _handleFocus = () => {\n const { value } = this.props;\n\n const items = this._extractValuesFromItems();\n const currentIndex = [...items].indexOf(value as string);\n const index = currentIndex > -1 ? currentIndex : 0;\n\n this.setState({ focusedIndex: index });\n };\n\n private _handleBlur = () => {\n this.setState({ focusedIndex: null });\n };\n\n private _renderItems = () => {\n const { items, value, size, width, disabled, role, renderItem } = this.props;\n\n return items.map((item, i) => {\n const {\n 'aria-label': ariaLabel,\n label,\n value: itemValue,\n buttonProps: customButtonProps,\n } = this._extractPropsFromItem(item);\n\n const isChecked = value === itemValue;\n const commonButtonProps = {\n use: 'default',\n _noWarningForUseDefault: true,\n 'aria-checked': isChecked,\n role,\n checked: isChecked,\n visuallyFocused: this.state.focusedIndex === i,\n onClick: () => {\n this.selectItem(itemValue);\n },\n disableFocus: true,\n size,\n disabled,\n corners: getButtonCorners(i === 0, i === items.length - 1),\n } satisfies ButtonProps;\n\n const buttonProps = {\n ...commonButtonProps,\n ...customButtonProps,\n };\n\n if (!buttonProps.width && width) {\n buttonProps.width = '100%';\n }\n\n const renderDefault = () => this.renderDefaultItem(label, itemValue, buttonProps, ariaLabel);\n return renderItem ? renderItem(label, itemValue, buttonProps, renderDefault, ariaLabel) : renderDefault();\n });\n };\n\n private renderDefaultItem = (label: string, value: string, buttonProps: ButtonProps, ariaLabel?: string) => (\n <Button aria-label={ariaLabel} key={value} {...buttonProps}>\n {label}\n </Button>\n );\n\n private getLabelSizeClassName = (): string => {\n switch (this.props.size) {\n case 'large':\n return this.styles.captionLarge(this.theme);\n case 'medium':\n return this.styles.captionMedium(this.theme);\n case 'small':\n default:\n return this.styles.captionSmall(this.theme);\n }\n };\n}\n"]}
1
+ {"version":3,"file":"Switcher.js","sourceRoot":"","sources":["Switcher.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAC5G,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAE7E,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAGjE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD,MAAM,CAAC,IAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,gBAAgB;CACd,CAAC;AAkDX;;GAEG;AAGH;IAA8B,4BAA6C;IAA3E;;QAQS,WAAK,GAAkB;YAC5B,YAAY,EAAE,IAAI;SACnB,CAAC;QAmDM,gBAAU,GAAG,UAAC,KAAa;YACjC,IAAI,KAAI,CAA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AI,CAAC,MAAM,CAAC,eAAe,EAAE,IAAG,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS;gBAC/D,CAAC;QAEH,OAAO,CACL,oBAAC,aAAa,aAAC,WAAW,EAAE,IAAI,CAAC,WAAW,IAAM,IAAI,CAAC,KAAK;YAC1D,yCAAe,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;gBACpG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,6BAAK,SAAS,EAAE,gBAAgB,IAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAO,CAAC,CAAC,CAAC,IAAI;gBACzF,6BAAK,SAAS,EAAE,gBAAgB;oBAC9B,0CAAW,UAAU,EAAI;oBACxB,KAAK,CACF,CACF,CACQ,CACjB,CAAC;IACJ,CAAC;IA1Da,4BAAmB,GAAG,UAAU,AAAb,CAAc;IACjC,oBAAW,GAAG,UAAU,AAAb,CAAc;IAEzB,qBAAY,GAAiB;QACzC,IAAI,EAAE,QAAQ;KACf,AAFyB,CAExB;IANS,QAAQ;QAFpB,qBAAqB;QACrB,QAAQ;OACI,QAAQ,CA2MpB;IAAD,eAAC;CAAA,AA3MD,CAA8B,KAAK,CAAC,SAAS,GA2M5C;SA3MY,QAAQ","sourcesContent":["import type { Emotion } from '@emotion/css/create-instance';\nimport type { HTMLAttributes } from 'react';\nimport React from 'react';\n\nimport type { CommonProps } from '../../internal/CommonWrapper/index.js';\nimport { CommonWrapper } from '../../internal/CommonWrapper/index.js';\nimport { isKeyArrowHorizontal, isKeyArrowLeft, isKeyEnter } from '../../lib/events/keyboard/identifiers.js';\nimport { withRenderEnvironment } from '../../lib/renderEnvironment/index.js';\nimport type { TGetRootNode, TSetRootNode } from '../../lib/rootNode/index.js';\nimport { rootNode } from '../../lib/rootNode/index.js';\nimport type { Theme } from '../../lib/theming/Theme.js';\nimport { ThemeContext } from '../../lib/theming/ThemeContext.js';\nimport type { SizeProp } from '../../lib/types/props.js';\nimport type { Nullable } from '../../typings/utility-types.js';\nimport { Button } from '../Button/index.js';\nimport type { ButtonProps } from '../Button/index.js';\nimport { Group, getButtonCorners } from '../Group/index.js';\nimport { mod } from './helpers.js';\nimport { getStyles } from './Switcher.styles.js';\nimport { getSwitcherTheme } from './switcherTheme.js';\n\nexport type SwitcherItems = string | SwitcherItem;\n\nexport const SwitcherDataTids = {\n root: 'Switcher__root',\n} as const;\n\nexport interface SwitcherProps extends Pick<HTMLAttributes<unknown>, 'role'>, CommonProps {\n /** Задаёт список элементов в свитчере. Это массив строк или объектов типа `{ label: string, value: string, buttonProps?: Partial<ButtonProps> }` */\n items: SwitcherItems[];\n\n /** Значение свитчера. */\n value?: string;\n\n /** Событие изменения значения свитчера (value). */\n onValueChange?: (value: string) => void;\n\n /** Подпись около свитчера. */\n caption?: string;\n\n /** Переводит свитчер в состояние ошибки. */\n error?: boolean;\n\n /** Размер свитчера. */\n size?: SizeProp;\n\n /** Ширина свитчера. С этим пропом элементы внутри автоматически равномерно растянутся. */\n width?: React.CSSProperties['width'];\n\n /** Блокирует свитчер. */\n disabled?: boolean;\n\n /** Задаёт функцию отрисовки элемента. Параметр `renderDefault` - это встроенная дефолтная функция отрисовки элемента, которую можно вызывать в `renderItem`. */\n renderItem?: (\n label: string,\n value: string,\n buttonProps: ButtonProps,\n renderDefault: () => React.ReactNode,\n ariaLabel?: string,\n ) => React.ReactNode;\n}\n\ntype DefaultProps = Required<Pick<SwitcherProps, 'role'>>;\n\nexport interface SwitcherState {\n focusedIndex: Nullable<number>;\n}\n\ninterface SwitcherItem {\n value: string;\n label: string;\n 'aria-label'?: string;\n buttonProps?: Partial<ButtonProps>;\n}\n\n/**\n * Переключатель используется для выбора одного значения из нескольких. Похож на [группу радиокнопок](https://tech.skbkontur.ru/kontur-ui/?path=/docs/react-ui_input-data-radiogroup--docs), но более компактный.\n */\n@withRenderEnvironment\n@rootNode\nexport class Switcher extends React.Component<SwitcherProps, SwitcherState> {\n public static __KONTUR_REACT_UI__ = 'Switcher';\n public static displayName = 'Switcher';\n\n public static defaultProps: DefaultProps = {\n role: 'switch',\n };\n\n public state: SwitcherState = {\n focusedIndex: null,\n };\n\n private emotion!: Emotion;\n private cx!: Emotion['cx'];\n private styles!: ReturnType<typeof getStyles>;\n private theme!: Theme;\n public getRootNode!: TGetRootNode;\n private setRootNode!: TSetRootNode;\n\n public render(): React.JSX.Element {\n this.styles = getStyles(this.emotion);\n\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = getSwitcherTheme(theme);\n return <ThemeContext.Provider value={this.theme}>{this.renderMain()}</ThemeContext.Provider>;\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderMain() {\n const inputProps = {\n type: 'checkbox',\n onKeyDown: this.handleKey,\n onFocus: this._handleFocus,\n onBlur: this._handleBlur,\n className: this.styles.input(),\n };\n const items = <Group width={'100%'}>{this._renderItems()}</Group>;\n\n const captionClassName = this.cx(this.styles.caption(this.theme), this.getLabelSizeClassName());\n const wrapperClassName = this.cx(this.styles.wrap(), {\n [this.styles.error(this.theme)]: this.props.error,\n [this.styles.wrapCustomWidth()]: this.props.width !== undefined,\n });\n\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.props}>\n <div data-tid={SwitcherDataTids.root} className={this.styles.root()} style={{ width: this.props.width }}>\n {this.props.caption ? <div className={captionClassName}>{this.props.caption}</div> : null}\n <div className={wrapperClassName}>\n <input {...inputProps} />\n {items}\n </div>\n </div>\n </CommonWrapper>\n );\n }\n\n private selectItem = (value: string) => {\n if (this.props.onValueChange) {\n this.props.onValueChange(value);\n }\n };\n\n private _extractPropsFromItem = (item: string | SwitcherItem): SwitcherItem => {\n return typeof item === 'object' ? item : { label: item, value: item };\n };\n\n private _extractValuesFromItems = (): string[] => {\n return this.props.items.map((item) => {\n const { value } = this._extractPropsFromItem(item);\n return value;\n });\n };\n\n private _focus = (index: number) => {\n this.setState({ focusedIndex: index });\n };\n\n private handleKey = (e: React.KeyboardEvent<HTMLInputElement>) => {\n const focusedIndex = this.state.focusedIndex;\n if (typeof focusedIndex !== 'number') {\n return;\n }\n\n if (isKeyEnter(e)) {\n if (this.props.onValueChange) {\n const { value, buttonProps } = this._extractPropsFromItem(this.props.items[focusedIndex]);\n if (!buttonProps?.disabled) {\n this.selectItem(value);\n }\n }\n return;\n }\n\n if (isKeyArrowHorizontal(e)) {\n e.preventDefault();\n this.move(isKeyArrowLeft(e));\n }\n };\n\n private move = (left: boolean) => {\n const selectedIndex = this.state.focusedIndex;\n\n if (typeof selectedIndex !== 'number') {\n return;\n }\n const newFocusedIndex = this._getNextFocusedIndex(left, selectedIndex);\n this._focus(newFocusedIndex);\n };\n\n private _getNextFocusedIndex = (left: boolean, focusedIndex: number): number => {\n const { items, disabled } = this.props;\n if (disabled) {\n return focusedIndex;\n }\n\n for (let i = 1; i < items.length; i++) {\n const index = mod(focusedIndex + (left ? -i : i), items.length);\n const { buttonProps } = this._extractPropsFromItem(items[index]);\n if (!buttonProps?.disabled) {\n return index;\n }\n }\n return focusedIndex;\n };\n\n private _handleFocus = () => {\n const { value } = this.props;\n\n const items = this._extractValuesFromItems();\n const currentIndex = [...items].indexOf(value as string);\n const index = currentIndex > -1 ? currentIndex : 0;\n\n this.setState({ focusedIndex: index });\n };\n\n private _handleBlur = () => {\n this.setState({ focusedIndex: null });\n };\n\n private _renderItems = () => {\n const { items, value, size, width, disabled, role, renderItem } = this.props;\n\n return items.map((item, i) => {\n const {\n 'aria-label': ariaLabel,\n label,\n value: itemValue,\n buttonProps: customButtonProps,\n } = this._extractPropsFromItem(item);\n\n const isChecked = value === itemValue;\n const commonButtonProps = {\n use: 'default',\n _noWarningForUseDefault: true,\n 'aria-checked': isChecked,\n role,\n checked: isChecked,\n visuallyFocused: this.state.focusedIndex === i,\n onClick: () => {\n this.selectItem(itemValue);\n },\n disableFocus: true,\n size,\n disabled,\n corners: getButtonCorners(i === 0, i === items.length - 1),\n } satisfies ButtonProps;\n\n const buttonProps = {\n ...commonButtonProps,\n ...customButtonProps,\n };\n\n if (!buttonProps.width && width) {\n buttonProps.width = '100%';\n }\n\n const renderDefault = () => this.renderDefaultItem(label, itemValue, buttonProps, ariaLabel);\n return renderItem ? renderItem(label, itemValue, buttonProps, renderDefault, ariaLabel) : renderDefault();\n });\n };\n\n private renderDefaultItem = (label: string, value: string, buttonProps: ButtonProps, ariaLabel?: string) => (\n <Button aria-label={ariaLabel} key={value} {...buttonProps}>\n {label}\n </Button>\n );\n\n private getLabelSizeClassName = (): string => {\n switch (this.props.size) {\n case 'large':\n return this.styles.captionLarge(this.theme);\n case 'medium':\n return this.styles.captionMedium(this.theme);\n case 'small':\n default:\n return this.styles.captionSmall(this.theme);\n }\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skbkontur/react-ui",
3
- "version": "6.2.0",
3
+ "version": "6.2.1",
4
4
  "description": "UI Components",
5
5
  "homepage": "https://tech.skbkontur.ru/kontur-ui",
6
6
  "bugs": {
@@ -265,7 +265,7 @@
265
265
  "dependencies": {
266
266
  "@babel/runtime": "^7.24.6",
267
267
  "@emotion/css": "^11.11.2",
268
- "@skbkontur/colors": "^2.1.5",
268
+ "@skbkontur/colors": "^2.1.8",
269
269
  "@skbkontur/react-imask": "^7.6.5",
270
270
  "eventemitter3": "^5.0.1",
271
271
  "focus-lock": "^1.3.5",
@@ -275,7 +275,6 @@
275
275
  "lodash.throttle": "^4.1.1",
276
276
  "normalize-wheel": "^1.0.1",
277
277
  "react-clientside-effect": "^1.2.6",
278
- "react-docgen": "7.0.0",
279
278
  "react-transition-group": "^4.4.5",
280
279
  "shallowequal": "^1.1.0",
281
280
  "stylis-plugin-extra-scope": "^0.3.0",
@@ -337,6 +336,7 @@
337
336
  "output-file-sync": "^2.0.1",
338
337
  "playwright-core": "1.59.1",
339
338
  "react": "19.2.1",
339
+ "react-docgen": "7.0.0",
340
340
  "react-docgen-typescript": "^2.2.2",
341
341
  "react-dom": "19.2.1",
342
342
  "rimraf": "^5.0.7",