Skip to content

Commit

Permalink
fix(Search): edit after transition
Browse files Browse the repository at this point in the history
- обернул кнопку под `after` в отдельный `<div>`;
- удалил анимацию `margin-inline` путём выставления отступов через `::before` и `::after` у нового `<div>`;
- у `::after` минусуем отступ справа, который выставляется у `Search` если он есть (завязываемся на `.Search--withPadding`);
- удаляем `Search__afterText`, т.к. у `Button` уже есть логика обрезания текста (⚠️ правда через `ellipsis`, а не `clip`);
- обновили скриншоты, т.к. привели отступы к соответствие с дизайном.

Дополнительно:

- для ясности точечно применяем `flex-grow` и `flex-basis` вместо шортката `flex`;
- в условие проверки на выставление `styles['Search--has-after']` добавляем `platform === 'ios'`;
- выносом проверку `platform === 'ios' && after` в переменную.
  • Loading branch information
inomdzhon committed Aug 30, 2024
1 parent 2aaac09 commit 02a9824
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 52 deletions.
34 changes: 19 additions & 15 deletions packages/vkui/src/components/Search/Search.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
}

.Search__field {
flex: 2;
position: relative;
display: flex;
flex-grow: 2;
flex-basis: 0%;
block-size: var(--vkui_internal--search_height);
background-color: var(--vkui--color_search_field_background);
border-radius: var(--vkui--size_border_radius--regular);
Expand Down Expand Up @@ -158,30 +159,33 @@
}

.Search__after {
flex: 0;
transform-origin: left;
min-inline-size: initial;
position: relative;
display: flex;
flex-grow: 0;
flex-basis: 0%;
min-inline-size: 0;
max-inline-size: min-content;
transition: flex-grow 0.3s var(--vkui--animation_easing_platform);
pointer-events: none;
transition-timing-function: var(--vkui--animation_easing_platform);
transition-duration: 0.3s;
transition-property: flex, margin-inline;
overflow: hidden;
margin-inline: 0;
}

.Search--focused .Search__after,
.Search--has-value .Search__after {
flex: 1;
flex-grow: 1;
pointer-events: initial;
margin-inline: 4px calc(4px - var(--vkui--size_base_padding_horizontal--regular));
}

.Search__afterText {
.Search__after::before,
.Search__after::after {
content: '';
flex-shrink: 0;
display: block;
white-space: nowrap;
text-overflow: clip;
overflow: hidden;
inline-size: 4px;
block-size: 100%;
}

.Search--withPadding .Search__after::after {
margin-inline-end: calc(-1 * var(--vkui--size_base_padding_horizontal--regular));
}

.Search__findButton {
Expand Down
33 changes: 19 additions & 14 deletions packages/vkui/src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Icon16Clear, Icon16SearchOutline, Icon24Cancel } from '@vkontakte/icons';
import { classNames, noop } from '@vkontakte/vkjs';
import { classNames, hasReactNode, noop } from '@vkontakte/vkjs';
import { useAdaptivity } from '../../hooks/useAdaptivity';
import { useAdaptivityConditionalRender } from '../../hooks/useAdaptivityConditionalRender';
import { useBooleanState } from '../../hooks/useBooleanState';
Expand Down Expand Up @@ -92,6 +92,8 @@ export const Search = ({
const { sizeY: adaptiveSizeY } = useAdaptivityConditionalRender();
const platform = usePlatform();

const hasAfter = platform === 'ios' && hasReactNode(after);

const onFocus = (e: React.FocusEvent<HTMLInputElement>) => {
setFocusedTrue();
inputProps.onFocus && inputProps.onFocus(e);
Expand Down Expand Up @@ -164,7 +166,7 @@ export const Search = ({
sizeY === 'compact' && styles['Search--sizeY-compact'],
isFocused && styles['Search--focused'],
hasValue && styles['Search--has-value'],
after && styles['Search--has-after'],
hasAfter && styles['Search--has-after'],
iconProp && styles['Search--has-icon'],
inputProps.disabled && styles['Search--disabled'],
!noPadding && styles['Search--withPadding'],
Expand Down Expand Up @@ -225,18 +227,21 @@ export const Search = ({
)}
</div>
</div>
{platform === 'ios' && after && (
<Button
mode="tertiary"
size="m"
className={styles['Search__after']}
focusVisibleMode="inside"
onClick={onCancel}
onFocus={setFocusedTrue}
onBlur={setFocusedFalse}
>
<span className={styles['Search__afterText']}>{after}</span>
</Button>
{hasAfter && (
<div className={styles['Search__after']}>
<Button
mode="tertiary"
size="m"
focusVisibleMode="inside"
hoverMode="opacity"
activeMode="opacity"
onClick={onCancel}
onFocus={setFocusedTrue}
onBlur={setFocusedFalse}
>
{after}
</Button>
</div>
)}
</div>
);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 02a9824

Please sign in to comment.