@hh.ru/magritte-ui-button 7.1.9 → 7.2.0

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/Button.js CHANGED
@@ -3,20 +3,24 @@ import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import React, { forwardRef, useRef } from 'react';
4
4
  import { CSSTransition } from 'react-transition-group';
5
5
  import classnames from 'classnames';
6
- import { useDisabled } from '@hh.ru/magritte-common-use-disabled';
6
+ import { useDisabled, DisabledContext } from '@hh.ru/magritte-common-use-disabled';
7
7
  import { tokenSemanticAnimationTimeMDuration } from '@hh.ru/magritte-design-tokens/types';
8
8
  import { ComponentWithBadge } from '@hh.ru/magritte-ui-badge';
9
9
  import { useButton } from './aria.js';
10
+ import { isIconElement, IconDynamic } from '@hh.ru/magritte-ui-icon';
10
11
  import { Loader } from '@hh.ru/magritte-ui-loader';
11
12
 
12
- var styles = {"button":"magritte-button___Pubhr_7-1-9","button_loading":"magritte-button_loading___tSd9G_7-1-9","buttonLoading":"magritte-button__loading___lYs93_7-1-9","button-view":"magritte-button-view___53Slm_7-1-9","buttonView":"magritte-button-view___53Slm_7-1-9","button__content":"magritte-button__content___BXYU0_7-1-9","buttonContent":"magritte-button__content___BXYU0_7-1-9","button_size-medium":"magritte-button_size-medium___WvUsb_7-1-9","buttonSizeMedium":"magritte-button_size-medium___WvUsb_7-1-9","button_size-large":"magritte-button_size-large___Gjw7e_7-1-9","buttonSizeLarge":"magritte-button_size-large___Gjw7e_7-1-9","button__label":"magritte-button__label___zplmt_7-1-9","buttonLabel":"magritte-button__label___zplmt_7-1-9","button__subcaption":"magritte-button__subcaption___SSASN_7-1-9","buttonSubcaption":"magritte-button_subcaption___0-hG0_7-1-9","button_size-small":"magritte-button_size-small___ZAmsS_7-1-9","buttonSizeSmall":"magritte-button_size-small___ZAmsS_7-1-9","button_stretched":"magritte-button_stretched___-aXS6_7-1-9","buttonStretched":"magritte-button_stretched___-aXS6_7-1-9","button-postfix":"magritte-button-postfix___0rpTU_7-1-9","buttonPostfix":"magritte-button-postfix___0rpTU_7-1-9","button__icon":"magritte-button__icon___912gw_7-1-9","buttonIcon":"magritte-button__icon___912gw_7-1-9","button_with-icon":"magritte-button_with-icon___znqnP_7-1-9","buttonWithIcon":"magritte-button_with-icon___znqnP_7-1-9","button_with-postfix":"magritte-button_with-postfix___iB7I6_7-1-9","buttonWithPostfix":"magritte-button_with-postfix___iB7I6_7-1-9","button_centred":"magritte-button_centred___7nw81_7-1-9","buttonCentred":"magritte-button_centred___7nw81_7-1-9","button_subcaption":"magritte-button_subcaption___0-hG0_7-1-9","button_textless":"magritte-button_textless___XBvNJ_7-1-9","buttonTextless":"magritte-button_textless___XBvNJ_7-1-9","button__loading":"magritte-button__loading___lYs93_7-1-9","animation-timeout":"magritte-animation-timeout___IVFRG_7-1-9","animationTimeout":"magritte-animation-timeout___IVFRG_7-1-9","enter-animation":"magritte-enter-animation___tJoZW_7-1-9","enterAnimation":"magritte-enter-animation___tJoZW_7-1-9","enter-animation-active":"magritte-enter-animation-active___RRYSD_7-1-9","enterAnimationActive":"magritte-enter-animation-active___RRYSD_7-1-9","exit-animation":"magritte-exit-animation___BleRA_7-1-9","exitAnimation":"magritte-exit-animation___BleRA_7-1-9","exit-animation-active":"magritte-exit-animation-active___i0EAM_7-1-9","exitAnimationActive":"magritte-exit-animation-active___i0EAM_7-1-9","button_style-neutral":"magritte-button_style-neutral___I5qS5_7-1-9","buttonStyleNeutral":"magritte-button_style-neutral___I5qS5_7-1-9","button_mode-primary":"magritte-button_mode-primary___wU8PN_7-1-9","buttonModePrimary":"magritte-button_mode-primary___wU8PN_7-1-9","button_mode-secondary":"magritte-button_mode-secondary___xYz4-_7-1-9","buttonModeSecondary":"magritte-button_mode-secondary___xYz4-_7-1-9","on-surface":"magritte-on-surface___sOxCu_7-1-9","onSurface":"magritte-on-surface___sOxCu_7-1-9","button_mode-tertiary":"magritte-button_mode-tertiary___ZMpad_7-1-9","buttonModeTertiary":"magritte-button_mode-tertiary___ZMpad_7-1-9","button_style-accent":"magritte-button_style-accent___TE21J_7-1-9","buttonStyleAccent":"magritte-button_style-accent___TE21J_7-1-9","button_style-positive":"magritte-button_style-positive___i-dJx_7-1-9","buttonStylePositive":"magritte-button_style-positive___i-dJx_7-1-9","button_style-negative":"magritte-button_style-negative___B2CVQ_7-1-9","buttonStyleNegative":"magritte-button_style-negative___B2CVQ_7-1-9","button_style-constant":"magritte-button_style-constant___vP0wU_7-1-9","buttonStyleConstant":"magritte-button_style-constant___vP0wU_7-1-9","button_style-special":"magritte-button_style-special___qi7Yf_7-1-9","buttonStyleSpecial":"magritte-button_style-special___qi7Yf_7-1-9","button-postfix_size-large":"magritte-button-postfix_size-large___6fupR_7-1-9","buttonPostfixSizeLarge":"magritte-button-postfix_size-large___6fupR_7-1-9","button-postfix_size-medium":"magritte-button-postfix_size-medium___CKs6F_7-1-9","buttonPostfixSizeMedium":"magritte-button-postfix_size-medium___CKs6F_7-1-9","button-postfix_size-small":"magritte-button-postfix_size-small___p9vHk_7-1-9","buttonPostfixSizeSmall":"magritte-button-postfix_size-small___p9vHk_7-1-9"};
13
+ var styles = {"button":"magritte-button___Pubhr_7-2-0","button_loading":"magritte-button_loading___tSd9G_7-2-0","buttonLoading":"magritte-button__loading___lYs93_7-2-0","button-view":"magritte-button-view___53Slm_7-2-0","buttonView":"magritte-button-view___53Slm_7-2-0","button__content":"magritte-button__content___BXYU0_7-2-0","buttonContent":"magritte-button__content___BXYU0_7-2-0","button_size-medium":"magritte-button_size-medium___WvUsb_7-2-0","buttonSizeMedium":"magritte-button_size-medium___WvUsb_7-2-0","button_size-large":"magritte-button_size-large___Gjw7e_7-2-0","buttonSizeLarge":"magritte-button_size-large___Gjw7e_7-2-0","button__label":"magritte-button__label___zplmt_7-2-0","buttonLabel":"magritte-button__label___zplmt_7-2-0","button__subcaption":"magritte-button__subcaption___SSASN_7-2-0","buttonSubcaption":"magritte-button_subcaption___0-hG0_7-2-0","button_size-small":"magritte-button_size-small___ZAmsS_7-2-0","buttonSizeSmall":"magritte-button_size-small___ZAmsS_7-2-0","button_stretched":"magritte-button_stretched___-aXS6_7-2-0","buttonStretched":"magritte-button_stretched___-aXS6_7-2-0","button-postfix":"magritte-button-postfix___0rpTU_7-2-0","buttonPostfix":"magritte-button-postfix___0rpTU_7-2-0","button__icon":"magritte-button__icon___912gw_7-2-0","buttonIcon":"magritte-button__icon___912gw_7-2-0","button_with-icon":"magritte-button_with-icon___znqnP_7-2-0","buttonWithIcon":"magritte-button_with-icon___znqnP_7-2-0","button_with-postfix":"magritte-button_with-postfix___iB7I6_7-2-0","buttonWithPostfix":"magritte-button_with-postfix___iB7I6_7-2-0","button_centred":"magritte-button_centred___7nw81_7-2-0","buttonCentred":"magritte-button_centred___7nw81_7-2-0","button_subcaption":"magritte-button_subcaption___0-hG0_7-2-0","button_textless":"magritte-button_textless___XBvNJ_7-2-0","buttonTextless":"magritte-button_textless___XBvNJ_7-2-0","button__loading":"magritte-button__loading___lYs93_7-2-0","animation-timeout":"magritte-animation-timeout___IVFRG_7-2-0","animationTimeout":"magritte-animation-timeout___IVFRG_7-2-0","enter-animation":"magritte-enter-animation___tJoZW_7-2-0","enterAnimation":"magritte-enter-animation___tJoZW_7-2-0","enter-animation-active":"magritte-enter-animation-active___RRYSD_7-2-0","enterAnimationActive":"magritte-enter-animation-active___RRYSD_7-2-0","exit-animation":"magritte-exit-animation___BleRA_7-2-0","exitAnimation":"magritte-exit-animation___BleRA_7-2-0","exit-animation-active":"magritte-exit-animation-active___i0EAM_7-2-0","exitAnimationActive":"magritte-exit-animation-active___i0EAM_7-2-0","button_style-neutral":"magritte-button_style-neutral___I5qS5_7-2-0","buttonStyleNeutral":"magritte-button_style-neutral___I5qS5_7-2-0","button_mode-primary":"magritte-button_mode-primary___wU8PN_7-2-0","buttonModePrimary":"magritte-button_mode-primary___wU8PN_7-2-0","button-with-icon-color":"magritte-button-with-icon-color___IbNQO_7-2-0","buttonWithIconColor":"magritte-button-with-icon-color___IbNQO_7-2-0","button_mode-secondary":"magritte-button_mode-secondary___xYz4-_7-2-0","buttonModeSecondary":"magritte-button_mode-secondary___xYz4-_7-2-0","on-surface":"magritte-on-surface___sOxCu_7-2-0","onSurface":"magritte-on-surface___sOxCu_7-2-0","button_mode-tertiary":"magritte-button_mode-tertiary___ZMpad_7-2-0","buttonModeTertiary":"magritte-button_mode-tertiary___ZMpad_7-2-0","button_style-accent":"magritte-button_style-accent___TE21J_7-2-0","buttonStyleAccent":"magritte-button_style-accent___TE21J_7-2-0","button_style-positive":"magritte-button_style-positive___i-dJx_7-2-0","buttonStylePositive":"magritte-button_style-positive___i-dJx_7-2-0","button_style-negative":"magritte-button_style-negative___B2CVQ_7-2-0","buttonStyleNegative":"magritte-button_style-negative___B2CVQ_7-2-0","button_style-constant":"magritte-button_style-constant___vP0wU_7-2-0","buttonStyleConstant":"magritte-button_style-constant___vP0wU_7-2-0","button_style-special":"magritte-button_style-special___qi7Yf_7-2-0","buttonStyleSpecial":"magritte-button_style-special___qi7Yf_7-2-0","button-postfix_size-large":"magritte-button-postfix_size-large___6fupR_7-2-0","buttonPostfixSizeLarge":"magritte-button-postfix_size-large___6fupR_7-2-0","button-postfix_size-medium":"magritte-button-postfix_size-medium___CKs6F_7-2-0","buttonPostfixSizeMedium":"magritte-button-postfix_size-medium___CKs6F_7-2-0","button-postfix_size-small":"magritte-button-postfix_size-small___p9vHk_7-2-0","buttonPostfixSizeSmall":"magritte-button-postfix_size-small___p9vHk_7-2-0"};
13
14
 
14
15
  const ALLOWED_BADGE_SIZES = ['small', 'extra-small'];
15
16
  const ButtonForwardRefRenderFunc = (props, ref) => {
16
- const { 'aria-label': ariaLabel, children, postfix, Element = 'button', hideLabel = false, icon, loading, mode, size = 'medium', stretched, style = 'neutral', subcaption, type = 'button', disabled, badge, spaceBetween = true, onSurface, ...buttonProps } = props;
17
+ const { 'aria-label': ariaLabel, children, postfix, Element = 'button', hideLabel = false, icon, loading, mode, size = 'medium', stretched, style = 'neutral', subcaption, type = 'button', disabled = false, badge, spaceBetween = true, onSurface, ...buttonProps } = props;
17
18
  const forceDisabled = useDisabled();
18
19
  const { ariaProps: additionalAttributes } = useButton({ disabled: !!disabled || forceDisabled, Element });
19
20
  const loaderRef = useRef(null);
21
+ const iconWithColor = icon &&
22
+ isIconElement(icon) &&
23
+ (!!icon.props.initialColor || !!icon.props.highlightedColor || !!icon.props.disabledColor);
20
24
  if (Element === 'button') {
21
25
  additionalAttributes.type = type;
22
26
  }
@@ -30,26 +34,29 @@ const ButtonForwardRefRenderFunc = (props, ref) => {
30
34
  additionalAttributes.ref = ref;
31
35
  }
32
36
  const withSubcaption = size !== 'small' && subcaption;
33
- const button = (jsx(Element, { className: classnames(styles.button, {
34
- [styles[`button_mode-${mode}`]]: mode,
35
- [styles[`button_size-${size}`]]: size,
36
- [styles.onSurface]: !!onSurface,
37
- [styles.button_stretched]: stretched,
38
- [styles.button_subcaption]: withSubcaption,
39
- [styles.button_textless]: !withSubcaption && (hideLabel || !children) && !postfix,
40
- [styles.button_loading]: loading,
41
- [styles[`button_style-${style}`]]: style,
42
- [styles.buttonWithIcon]: !!icon,
43
- [styles.buttonWithPostfix]: !!postfix,
44
- [styles.buttonCentred]: !spaceBetween,
45
- }), disabled: forceDisabled || !!disabled, tabIndex: loading ? -1 : undefined, ...additionalAttributes, ...buttonProps, children: jsx("span", { className: styles.buttonView, children: jsxs("span", { className: styles.button__content, children: [postfix && (jsx("span", { className: classnames(styles.buttonPostfix, {
46
- [styles[`button-postfix_size-${size}`]]: size,
47
- }), children: postfix })), icon && (jsx("span", { className: styles.button__icon, children: React.cloneElement(icon, hideLabel ? { 'aria-label': ariaLabel } : { 'aria-hidden': true, focusable: false }) })), children && !hideLabel && jsx("span", { className: styles.button__label, children: children }), withSubcaption && jsx("span", { className: styles.button__subcaption, children: subcaption }), jsx(CSSTransition, { in: loading, nodeRef: loaderRef, timeout: tokenSemanticAnimationTimeMDuration, classNames: {
48
- enter: styles.enterAnimation,
49
- enterActive: styles.enterAnimationActive,
50
- exit: styles.exitAnimation,
51
- exitActive: styles.exitAnimationActive,
52
- }, unmountOnExit: true, children: jsx("span", { className: styles.button__loading, ref: loaderRef, children: jsx(Loader, {}) }) })] }) }) }));
37
+ const button = (jsx(DisabledContext.Provider, { value: forceDisabled || !!disabled, children: jsx(Element, { className: classnames(styles.button, {
38
+ [styles[`button_mode-${mode}`]]: mode,
39
+ [styles[`button_size-${size}`]]: size,
40
+ [styles.onSurface]: !!onSurface,
41
+ [styles.button_stretched]: stretched,
42
+ [styles.button_subcaption]: withSubcaption,
43
+ [styles.button_textless]: !withSubcaption && (hideLabel || !children) && !postfix,
44
+ [styles.button_loading]: loading,
45
+ [styles[`button_style-${style}`]]: style,
46
+ [styles.buttonWithIcon]: !!icon,
47
+ [styles.buttonWithPostfix]: !!postfix,
48
+ [styles.buttonCentred]: !spaceBetween,
49
+ [styles.buttonWithIconColor]: iconWithColor,
50
+ }), disabled: forceDisabled || !!disabled, tabIndex: loading ? -1 : undefined, ...additionalAttributes, ...buttonProps, children: jsx(IconDynamic, { stretched: true, children: jsx("span", { className: styles.buttonView, children: jsxs("span", { className: styles.button__content, children: [postfix && (jsx("span", { className: classnames(styles.buttonPostfix, {
51
+ [styles[`button-postfix_size-${size}`]]: size,
52
+ }), children: postfix })), icon && (jsx("span", { className: styles.button__icon, children: React.cloneElement(icon, hideLabel
53
+ ? { 'aria-label': ariaLabel }
54
+ : { 'aria-hidden': true, focusable: false }) })), children && !hideLabel && jsx("span", { className: styles.button__label, children: children }), withSubcaption && jsx("span", { className: styles.button__subcaption, children: subcaption }), jsx(CSSTransition, { in: loading, nodeRef: loaderRef, timeout: tokenSemanticAnimationTimeMDuration, classNames: {
55
+ enter: styles.enterAnimation,
56
+ enterActive: styles.enterAnimationActive,
57
+ exit: styles.exitAnimation,
58
+ exitActive: styles.exitAnimationActive,
59
+ }, unmountOnExit: true, children: jsx("span", { className: styles.button__loading, ref: loaderRef, children: jsx(Loader, {}) }) })] }) }) }) }) }));
53
60
  if (badge && !disabled && !forceDisabled) {
54
61
  return (jsx(ComponentWithBadge, { allowedSizes: ALLOWED_BADGE_SIZES, badge: badge, stretched: stretched, children: button }));
55
62
  }
package/Button.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Button.js","sources":["src/Button.tsx"],"sourcesContent":["import React, { forwardRef, useRef } from 'react';\nimport { CSSTransition } from 'react-transition-group';\nimport classnames from 'classnames';\n\nimport { useDisabled } from '@hh.ru/magritte-common-use-disabled';\nimport { tokenSemanticAnimationTimeMDuration } from '@hh.ru/magritte-design-tokens/types';\nimport type { PolymorphicForwardRefRenderFunc, PolymorphicComponentWithRef } from '@hh.ru/magritte-types';\nimport { BadgeSize, ComponentWithBadge } from '@hh.ru/magritte-ui-badge';\nimport { useButton } from '@hh.ru/magritte-ui-button/aria';\nimport type { ButtonProps } from '@hh.ru/magritte-ui-button/types';\nimport { Loader } from '@hh.ru/magritte-ui-loader';\n\nimport styles from './button.less';\n\nconst ALLOWED_BADGE_SIZES: BadgeSize[] = ['small', 'extra-small'];\n\nconst ButtonForwardRefRenderFunc: PolymorphicForwardRefRenderFunc<ButtonProps, 'button'> = (props, ref) => {\n const {\n 'aria-label': ariaLabel,\n children,\n postfix,\n Element = 'button',\n hideLabel = false,\n icon,\n loading,\n mode,\n size = 'medium',\n stretched,\n style = 'neutral',\n subcaption,\n type = 'button',\n disabled,\n badge,\n spaceBetween = true,\n onSurface,\n ...buttonProps\n } = props;\n\n const forceDisabled = useDisabled();\n const { ariaProps: additionalAttributes } = useButton({ disabled: !!disabled || forceDisabled, Element });\n const loaderRef = useRef<HTMLSpanElement>(null);\n\n if (Element === 'button') {\n additionalAttributes.type = type;\n }\n\n if (ref) {\n /**\n * Element может быть простой функцией поэтому напрямую\n * нельзя назначать ref\n * А может быть forwardRef, ClassComponent и простой тег,\n * поэтому в обход типизации назначаем ref как unknown\n */\n additionalAttributes.ref = ref;\n }\n\n const withSubcaption = size !== 'small' && subcaption;\n\n const button = (\n <Element\n className={classnames(styles.button, {\n [styles[`button_mode-${mode}`]]: mode,\n [styles[`button_size-${size}`]]: size,\n [styles.onSurface]: !!onSurface,\n [styles.button_stretched]: stretched,\n [styles.button_subcaption]: withSubcaption,\n [styles.button_textless]: !withSubcaption && (hideLabel || !children) && !postfix,\n [styles.button_loading]: loading,\n [styles[`button_style-${style}`]]: style,\n [styles.buttonWithIcon]: !!icon,\n [styles.buttonWithPostfix]: !!postfix,\n [styles.buttonCentred]: !spaceBetween,\n })}\n disabled={forceDisabled || !!disabled}\n tabIndex={loading ? -1 : undefined}\n {...additionalAttributes}\n {...buttonProps}\n >\n <span className={styles.buttonView}>\n <span className={styles.button__content}>\n {postfix && (\n <span\n className={classnames(styles.buttonPostfix, {\n [styles[`button-postfix_size-${size}`]]: size,\n })}\n >\n {postfix}\n </span>\n )}\n {icon && (\n <span className={styles.button__icon}>\n {React.cloneElement(\n icon,\n hideLabel ? { 'aria-label': ariaLabel } : { 'aria-hidden': true, focusable: false }\n )}\n </span>\n )}\n {children && !hideLabel && <span className={styles.button__label}>{children}</span>}\n {withSubcaption && <span className={styles.button__subcaption}>{subcaption}</span>}\n <CSSTransition\n in={loading}\n nodeRef={loaderRef}\n timeout={tokenSemanticAnimationTimeMDuration}\n classNames={{\n enter: styles.enterAnimation,\n enterActive: styles.enterAnimationActive,\n exit: styles.exitAnimation,\n exitActive: styles.exitAnimationActive,\n }}\n unmountOnExit\n >\n <span className={styles.button__loading} ref={loaderRef}>\n <Loader />\n </span>\n </CSSTransition>\n </span>\n </span>\n </Element>\n );\n\n if (badge && !disabled && !forceDisabled) {\n return (\n <ComponentWithBadge allowedSizes={ALLOWED_BADGE_SIZES} badge={badge} stretched={stretched}>\n {button}\n </ComponentWithBadge>\n );\n }\n\n return button;\n};\n\nexport const Button = forwardRef(ButtonForwardRefRenderFunc) as PolymorphicComponentWithRef<ButtonProps, 'button'>;\n\nexport const STRETCHED_WRAPPER_C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G,MAAM,uBAAuB,GAAG;;;;"}
1
+ {"version":3,"file":"Button.js","sources":["src/Button.tsx"],"sourcesContent":["import React, { forwardRef, useRef } from 'react';\nimport { CSSTransition } from 'react-transition-group';\nimport classnames from 'classnames';\n\nimport { useDisabled, DisabledContext } from '@hh.ru/magritte-common-use-disabled';\nimport { tokenSemanticAnimationTimeMDuration } from '@hh.ru/magritte-design-tokens/types';\nimport type { PolymorphicForwardRefRenderFunc, PolymorphicComponentWithRef } from '@hh.ru/magritte-types';\nimport { BadgeSize, ComponentWithBadge } from '@hh.ru/magritte-ui-badge';\nimport { useButton } from '@hh.ru/magritte-ui-button/aria';\nimport type { ButtonProps } from '@hh.ru/magritte-ui-button/types';\nimport { IconDynamic, isIconElement } from '@hh.ru/magritte-ui-icon';\nimport { Loader } from '@hh.ru/magritte-ui-loader';\n\nimport styles from './button.less';\n\nconst ALLOWED_BADGE_SIZES: BadgeSize[] = ['small', 'extra-small'];\n\nconst ButtonForwardRefRenderFunc: PolymorphicForwardRefRenderFunc<ButtonProps, 'button'> = (props, ref) => {\n const {\n 'aria-label': ariaLabel,\n children,\n postfix,\n Element = 'button',\n hideLabel = false,\n icon,\n loading,\n mode,\n size = 'medium',\n stretched,\n style = 'neutral',\n subcaption,\n type = 'button',\n disabled = false,\n badge,\n spaceBetween = true,\n onSurface,\n ...buttonProps\n } = props;\n\n const forceDisabled = useDisabled();\n const { ariaProps: additionalAttributes } = useButton({ disabled: !!disabled || forceDisabled, Element });\n const loaderRef = useRef<HTMLSpanElement>(null);\n\n const iconWithColor =\n icon &&\n isIconElement(icon) &&\n (!!icon.props.initialColor || !!icon.props.highlightedColor || !!icon.props.disabledColor);\n\n if (Element === 'button') {\n additionalAttributes.type = type;\n }\n\n if (ref) {\n /**\n * Element может быть простой функцией поэтому напрямую\n * нельзя назначать ref\n * А может быть forwardRef, ClassComponent и простой тег,\n * поэтому в обход типизации назначаем ref как unknown\n */\n additionalAttributes.ref = ref;\n }\n\n const withSubcaption = size !== 'small' && subcaption;\n\n const button = (\n <DisabledContext.Provider value={forceDisabled || !!disabled}>\n <Element\n className={classnames(styles.button, {\n [styles[`button_mode-${mode}`]]: mode,\n [styles[`button_size-${size}`]]: size,\n [styles.onSurface]: !!onSurface,\n [styles.button_stretched]: stretched,\n [styles.button_subcaption]: withSubcaption,\n [styles.button_textless]: !withSubcaption && (hideLabel || !children) && !postfix,\n [styles.button_loading]: loading,\n [styles[`button_style-${style}`]]: style,\n [styles.buttonWithIcon]: !!icon,\n [styles.buttonWithPostfix]: !!postfix,\n [styles.buttonCentred]: !spaceBetween,\n [styles.buttonWithIconColor]: iconWithColor,\n })}\n disabled={forceDisabled || !!disabled}\n tabIndex={loading ? -1 : undefined}\n {...additionalAttributes}\n {...buttonProps}\n >\n <IconDynamic stretched>\n <span className={styles.buttonView}>\n <span className={styles.button__content}>\n {postfix && (\n <span\n className={classnames(styles.buttonPostfix, {\n [styles[`button-postfix_size-${size}`]]: size,\n })}\n >\n {postfix}\n </span>\n )}\n {icon && (\n <span className={styles.button__icon}>\n {React.cloneElement(\n icon,\n hideLabel\n ? { 'aria-label': ariaLabel }\n : { 'aria-hidden': true, focusable: false }\n )}\n </span>\n )}\n {children && !hideLabel && <span className={styles.button__label}>{children}</span>}\n {withSubcaption && <span className={styles.button__subcaption}>{subcaption}</span>}\n <CSSTransition\n in={loading}\n nodeRef={loaderRef}\n timeout={tokenSemanticAnimationTimeMDuration}\n classNames={{\n enter: styles.enterAnimation,\n enterActive: styles.enterAnimationActive,\n exit: styles.exitAnimation,\n exitActive: styles.exitAnimationActive,\n }}\n unmountOnExit\n >\n <span className={styles.button__loading} ref={loaderRef}>\n <Loader />\n </span>\n </CSSTransition>\n </span>\n </span>\n </IconDynamic>\n </Element>\n </DisabledContext.Provider>\n );\n\n if (badge && !disabled && !forceDisabled) {\n return (\n <ComponentWithBadge allowedSizes={ALLOWED_BADGE_SIZES} badge={badge} stretched={stretched}>\n {button}\n </ComponentWithBadge>\n );\n }\n\n return button;\n};\n\nexport const Button = forwardRef(ButtonForwardRefRenderFunc) as PolymorphicComponentWithRef<ButtonProps, 'button'>;\n\nexport const STRETCHED_WRAPPER_CLASS = 'magritte-button-stretched-wrapper';\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;;;;AAeA,MAAM,mBAAmB,GAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;AAElE,MAAM,0BAA0B,GAA2D,CAAC,KAAK,EAAE,GAAG,KAAI;IACtG,MAAM,EACF,YAAY,EAAE,SAAS,EACvB,QAAQ,EACR,OAAO,EACP,OAAO,GAAG,QAAQ,EAClB,SAAS,GAAG,KAAK,EACjB,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,IAAI,GAAG,QAAQ,EACf,SAAS,EACT,KAAK,GAAG,SAAS,EACjB,UAAU,EACV,IAAI,GAAG,QAAQ,EACf,QAAQ,GAAG,KAAK,EAChB,KAAK,EACL,YAAY,GAAG,IAAI,EACnB,SAAS,EACT,GAAG,WAAW,EACjB,GAAG,KAAK,CAAC;AAEV,IAAA,MAAM,aAAa,GAAG,WAAW,EAAE,CAAC;IACpC,MAAM,EAAE,SAAS,EAAE,oBAAoB,EAAE,GAAG,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;AAC1G,IAAA,MAAM,SAAS,GAAG,MAAM,CAAkB,IAAI,CAAC,CAAC;IAEhD,MAAM,aAAa,GACf,IAAI;QACJ,aAAa,CAAC,IAAI,CAAC;SAClB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AAE/F,IAAA,IAAI,OAAO,KAAK,QAAQ,EAAE;AACtB,QAAA,oBAAoB,CAAC,IAAI,GAAG,IAAI,CAAC;KACpC;IAED,IAAI,GAAG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