@vkontakte/vkui 8.1.0 → 8.1.2

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
  "type": "module",
3
- "version": "8.1.0",
3
+ "version": "8.1.2",
4
4
  "name": "@vkontakte/vkui",
5
5
  "description": "VKUI library",
6
6
  "module": "./dist/index.js",
@@ -1,15 +1,8 @@
1
+ import { getRequiredValueByKey } from '../../../helpers/getValueByKey';
1
2
  import { type LayoutProps, resolveLayoutProps } from '../../../lib/layouts';
2
3
  import { warnOnce } from '../../../lib/warnOnce';
3
4
  import { RootComponent } from '../../RootComponent/RootComponent';
4
5
  import type { RootComponentProps } from '../../RootComponent/RootComponent';
5
- import styles from './FlexItem.module.css';
6
-
7
- const flexClassNames = {
8
- grow: styles.flexGrow,
9
- shrink: styles.flexShrink,
10
- content: styles.flexContent,
11
- fixed: styles.flexFixed,
12
- };
13
6
 
14
7
  export type FlexItemProps = RootComponentProps<HTMLElement> &
15
8
  Pick<LayoutProps, 'alignSelf' | 'justifySelf' | 'flexBasis'> & {
@@ -24,14 +17,48 @@ export type FlexItemProps = RootComponentProps<HTMLElement> &
24
17
  flex?: 'grow' | 'shrink' | 'content' | 'fixed' | undefined;
25
18
  };
26
19
 
20
+ const resolveFlexProps = (flex: FlexItemProps['flex'], flexBasis: FlexItemProps['flexBasis']) => {
21
+ const overrideProps = flexBasis !== undefined ? { flexBasis } : {};
22
+ if (!flex) {
23
+ return overrideProps;
24
+ }
25
+ return {
26
+ ...getRequiredValueByKey<Pick<LayoutProps, 'flexGrow' | 'flexShrink' | 'flexBasis'>>(flex, {
27
+ grow: {
28
+ flexGrow: 1,
29
+ flexShrink: 0,
30
+ flexBasis: 'auto',
31
+ },
32
+ shrink: {
33
+ flexGrow: 0,
34
+ flexShrink: 1,
35
+ flexBasis: 'auto',
36
+ },
37
+ content: {
38
+ flexGrow: 1,
39
+ flexShrink: 1,
40
+ flexBasis: 'auto',
41
+ },
42
+ fixed: {
43
+ flexGrow: 0,
44
+ flexShrink: 0,
45
+ flexBasis: 'auto',
46
+ },
47
+ }),
48
+ ...overrideProps,
49
+ };
50
+ };
51
+
27
52
  const warn = warnOnce('Flex.Item');
28
53
 
29
- export const FlexItem = ({ flex, ...restProps }: FlexItemProps): React.ReactNode => {
54
+ export const FlexItem = ({ flex, flexBasis, ...restProps }: FlexItemProps): React.ReactNode => {
30
55
  if (process.env.NODE_ENV === 'development') {
31
56
  warn('Компонент Flex.Item устарел, используйте компонент Box в качестве альтернативы.');
32
57
  }
33
58
 
34
- const resolvedProps = resolveLayoutProps(restProps);
59
+ const flexProps = resolveFlexProps(flex, flexBasis);
60
+
61
+ const resolvedProps = resolveLayoutProps({ ...restProps, ...flexProps });
35
62
 
36
- return <RootComponent baseClassName={flex && flexClassNames[flex]} {...resolvedProps} />;
63
+ return <RootComponent {...resolvedProps} />;
37
64
  };
@@ -288,17 +288,6 @@ export const Search = ({
288
288
  [onIconClick],
289
289
  );
290
290
 
291
- const onIconCancelClickStart: React.PointerEventHandler<HTMLElement> = React.useCallback(
292
- (e) => {
293
- e.preventDefault();
294
- inputRef.current?.focus();
295
- if (touchEnabled()) {
296
- onCancel();
297
- }
298
- },
299
- [inputRef, onCancel],
300
- );
301
-
302
291
  useIsomorphicLayoutEffect(() => {
303
292
  if (inputRest.value !== undefined) {
304
293
  setHasValue(Boolean(inputRest.value));
@@ -328,6 +317,31 @@ export const Search = ({
328
317
  iconProp || !hideClearButton || (adaptiveDensity.compact && onFindButtonClick),
329
318
  );
330
319
 
320
+ const onClearPointerDown: React.PointerEventHandler<HTMLElement> = (e) => {
321
+ // Сначала вызываем внешний обработчик, затем локальную логику, чтобы можно было предотвратить обработку фокуса на поле ввода.
322
+ onClearButtonPointerDown?.(e);
323
+
324
+ e.preventDefault();
325
+ inputRef.current?.focus();
326
+ if (touchEnabled()) {
327
+ onCancel();
328
+ }
329
+ };
330
+
331
+ const onClearClick: React.MouseEventHandler<HTMLElement> = (e) => {
332
+ // eslint-disable-next-line @typescript-eslint/unbound-method
333
+ const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
334
+ HTMLInputElement.prototype,
335
+ 'value',
336
+ )?.set;
337
+ nativeInputValueSetter?.call(inputRef.current, '');
338
+
339
+ const ev2 = new Event('input', { bubbles: true });
340
+ inputRef.current?.dispatchEvent(ev2);
341
+
342
+ onClearButtonClick?.(e);
343
+ };
344
+
331
345
  return (
332
346
  <RootComponent
333
347
  baseClassName={classNames(
@@ -374,8 +388,8 @@ export const Search = ({
374
388
  {!hideClearButton && (
375
389
  <IconButton
376
390
  hoverMode="opacity"
377
- onPointerDown={callMultiple(onIconCancelClickStart, onClearButtonPointerDown)}
378
- onClick={callMultiple(onCancel, onClearButtonClick)}
391
+ onPointerDown={onClearPointerDown}
392
+ onClick={onClearClick}
379
393
  tabIndex={hasValue ? undefined : -1}
380
394
  disabled={inputRest.disabled}
381
395
  data-testid={clearButtonTestId}
@@ -1,17 +0,0 @@
1
- /* flex */
2
-
3
- .flexGrow {
4
- flex: 1 0 auto;
5
- }
6
-
7
- .flexShrink {
8
- flex: 0 1 auto;
9
- }
10
-
11
- .flexContent {
12
- flex: 1 1 auto;
13
- }
14
-
15
- .flexFixed {
16
- flex: 0 0 auto;
17
- }
@@ -1,17 +0,0 @@
1
- /* flex */
2
-
3
- .flexGrow {
4
- flex: 1 0 auto;
5
- }
6
-
7
- .flexShrink {
8
- flex: 0 1 auto;
9
- }
10
-
11
- .flexContent {
12
- flex: 1 1 auto;
13
- }
14
-
15
- .flexFixed {
16
- flex: 0 0 auto;
17
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["./FlexItem.module.css"],"names":["flexGrow","flexShrink","flexContent","flexFixed"],"mappings":"AAAA;AAAA,E,aAEAA,U,WAFA;AAAA,E,aAMAC,Y,WANA;AAAA,E,aAUAC,a,WAVA;AAAA,E,aAcAC,W,WAdA;AAAA;AAAA","file":"FlexItem.module.css.d.ts","sourceRoot":""}