@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 +1 -1
- package/src/components/Button/Button.tsx +97 -85
package/package.json
CHANGED
|
@@ -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
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
const hasIcon = isNotEmpty(icon);
|
|
147
|
+
const hasChildren = isNotEmpty(children);
|
|
148
|
+
const hasNoAction = isDisabled || isLoading;
|
|
141
149
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
</
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
<ThemedPreloader
|
|
187
|
-
type={preloaderType}
|
|
188
|
-
useCurrentColor
|
|
189
|
-
tweakStyles={tweakPreloaderStyles}
|
|
190
|
-
/>
|
|
191
|
-
</span>
|
|
192
|
-
)}
|
|
193
|
-
</button>
|
|
194
|
-
);
|
|
195
|
-
};
|
|
204
|
+
</button>
|
|
205
|
+
);
|
|
206
|
+
},
|
|
207
|
+
);
|