@true-engineering/true-react-common-ui-kit 1.11.0 → 1.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@true-engineering/true-react-common-ui-kit",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  useMemo,
3
- FC,
4
3
  ReactElement,
5
4
  ReactNode,
6
5
  ButtonHTMLAttributes,
7
6
  MouseEvent,
7
+ forwardRef,
8
8
  } from 'react';
9
9
  import clsx from 'clsx';
10
10
  import merge from 'lodash-es/merge';
@@ -102,94 +102,106 @@ export interface IButtonProps extends ICommonProps {
102
102
  onMouseDown?(event: MouseEvent<HTMLButtonElement>): void | Promise<void>;
103
103
  }
104
104
 
105
- export const Button: FC<IButtonProps> = ({
106
- type = 'button',
107
- children,
108
- size = 'l',
109
- view = 'primary',
110
- isFullWidth = false,
111
- isInline = false,
112
- isDisabled = false,
113
- isActive = false,
114
- isLoading = false,
115
- shouldSkipTabNavigation = false,
116
- data,
117
- testId,
118
- tweakStyles,
119
- icon,
120
- iconPosition = 'left',
121
- preloaderType = 'dots',
122
- onClick,
123
- onMouseDown,
124
- }) => {
125
- const { classes, componentStyles } = useTheme('Button', styles, tweakStyles);
105
+ export const Button = forwardRef<HTMLButtonElement, IButtonProps>(
106
+ (
107
+ {
108
+ type = 'button',
109
+ children,
110
+ size = 'l',
111
+ view = 'primary',
112
+ isFullWidth = false,
113
+ isInline = false,
114
+ isDisabled = false,
115
+ isActive = false,
116
+ isLoading = false,
117
+ shouldSkipTabNavigation = false,
118
+ data,
119
+ testId,
120
+ tweakStyles,
121
+ icon,
122
+ iconPosition = 'left',
123
+ preloaderType = 'dots',
124
+ onClick,
125
+ onMouseDown,
126
+ },
127
+ ref,
128
+ ) => {
129
+ const { classes, componentStyles } = useTheme(
130
+ 'Button',
131
+ styles,
132
+ tweakStyles,
133
+ );
126
134
 
127
- const tweakPreloaderStyles = useMemo(
128
- () =>
129
- merge(
130
- {},
131
- size === 's' || size === 'm' ? dotsPreloaderStyles : undefined,
132
- componentStyles.tweakPreloader,
133
- tweakStyles?.tweakPreloader,
134
- ) as ThemedPreloaderStyles,
135
- [tweakStyles?.tweakPreloader, size],
136
- );
135
+ const tweakPreloaderStyles = useMemo(
136
+ () =>
137
+ merge(
138
+ {},
139
+ size === 's' || size === 'm' ? dotsPreloaderStyles : undefined,
140
+ componentStyles.tweakPreloader,
141
+ tweakStyles?.tweakPreloader,
142
+ ) as ThemedPreloaderStyles,
143
+ [tweakStyles?.tweakPreloader, size],
144
+ );
137
145
 
138
- const hasIcon = isNotEmpty(icon);
139
- const hasChildren = isNotEmpty(children);
140
- const hasNoAction = isDisabled || isLoading;
146
+ const hasIcon = isNotEmpty(icon);
147
+ const hasChildren = isNotEmpty(children);
148
+ const hasNoAction = isDisabled || isLoading;
141
149
 
142
- return (
143
- <button
144
- type={type}
145
- className={clsx(classes.root, classes[size], classes[view], {
146
- [classes.disabled]: isDisabled,
147
- [classes.fullWidth]: isFullWidth,
148
- [classes.inline]: isInline,
149
- [classes.active]: isActive,
150
- [classes.loading]: isLoading,
151
- [classes.onlyIcon]: hasIcon && !hasChildren,
152
- })}
153
- tabIndex={shouldSkipTabNavigation ? -1 : undefined}
154
- disabled={hasNoAction}
155
- onClick={!hasNoAction ? onClick : undefined}
156
- onMouseDown={!hasNoAction ? onMouseDown : undefined}
157
- {...addDataTestId(testId)}
158
- {...addDataAttributes(data)}
159
- >
160
- <span
161
- className={clsx(classes.content, {
162
- [classes.iconFromRight]:
163
- hasChildren && hasIcon && iconPosition === 'right',
164
- [classes.iconFromLeft]:
165
- hasChildren && hasIcon && iconPosition === 'left',
150
+ return (
151
+ <button
152
+ ref={ref}
153
+ type={type}
154
+ className={clsx(classes.root, classes[size], classes[view], {
155
+ [classes.disabled]: isDisabled,
156
+ [classes.fullWidth]: isFullWidth,
157
+ [classes.inline]: isInline,
158
+ [classes.active]: isActive,
159
+ [classes.loading]: isLoading,
160
+ [classes.onlyIcon]: hasIcon && !hasChildren,
166
161
  })}
162
+ tabIndex={shouldSkipTabNavigation ? -1 : undefined}
163
+ disabled={hasNoAction}
164
+ onClick={!hasNoAction ? onClick : undefined}
165
+ onMouseDown={!hasNoAction ? onMouseDown : undefined}
166
+ {...addDataTestId(testId)}
167
+ {...addDataAttributes(data)}
167
168
  >
168
- {hasIcon && (
169
- <span className={classes.icon}>
170
- {typeof icon === 'string' ? (
171
- <Icon type={icon as IIconType} />
172
- ) : (
173
- icon
174
- )}
175
- </span>
176
- )}
177
- {hasChildren && (
178
- <span className={clsx(classes.children, hasIcon && classes.withIcon)}>
179
- {children}
169
+ <span
170
+ className={clsx(classes.content, {
171
+ [classes.iconFromRight]:
172
+ hasChildren && hasIcon && iconPosition === 'right',
173
+ [classes.iconFromLeft]:
174
+ hasChildren && hasIcon && iconPosition === 'left',
175
+ })}
176
+ >
177
+ {hasIcon && (
178
+ <span className={classes.icon}>
179
+ {typeof icon === 'string' ? (
180
+ <Icon type={icon as IIconType} />
181
+ ) : (
182
+ icon
183
+ )}
184
+ </span>
185
+ )}
186
+ {hasChildren && (
187
+ <span
188
+ className={clsx(classes.children, hasIcon && classes.withIcon)}
189
+ >
190
+ {children}
191
+ </span>
192
+ )}
193
+ </span>
194
+
195
+ {isLoading && (
196
+ <span className={classes.loader}>
197
+ <ThemedPreloader
198
+ type={preloaderType}
199
+ useCurrentColor
200
+ tweakStyles={tweakPreloaderStyles}
201
+ />
180
202
  </span>
181
203
  )}
182
- </span>
183
-
184
- {isLoading && (
185
- <span className={classes.loader}>
186
- <ThemedPreloader
187
- type={preloaderType}
188
- useCurrentColor
189
- tweakStyles={tweakPreloaderStyles}
190
- />
191
- </span>
192
- )}
193
- </button>
194
- );
195
- };
204
+ </button>
205
+ );
206
+ },
207
+ );