Skip to content

Commit

Permalink
fix(Spacing): fix padding top with spacing tokens (#7632)
Browse files Browse the repository at this point in the history
h2. Описание

Сейчас в компоненте `Spacing` при прокидывании в проп `size` значение типа string('s', 'm', 'l' и т.д) и при добавлении children для компонента, не устанавливается паддинг сверху, есть только снизу

h2. Изменения

Поисследовав данную проблема, пришел к выводу, что css выражение с рассчетом паддингов `calc(1px * var(--vkui_internal--Spacing_gap) / 2)` при значении css переменной `--vkui_internal--Spacing_gap` в виде `${число}px` неправильно рассчитывается, то есть получается 0. Скорее всего, это из-за того, что мы умножаем значение на 1px. По крайней мере, если его убрать, то проблема пропадает.
- Убрал умножение на 1px в css
- Чтобы не сломался кейс со значениями типа number, сделал добавление px при прокидывании в css переменную
- Убрал установку `height`, так как при добавлении `padding-block` `height` не нужен
- Поправил тесты, скриншоты

h2. Release notes

h2. Исправление
- Spacing: Поправлен баг с отсутствием верхнего отступа при прокидывании в `size` значение типа `string`
  • Loading branch information
EldarMuhamethanov authored Sep 23, 2024
1 parent 3c9fcfe commit fa75452
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export const SpacingPlayground = (props: ComponentPlaygroundProps) => {
<Separator />
<Spacing size={size} />
<Separator />
<Spacing size={size} />
<Spacing size={size} style={{ background: '#b0bfb4' }}>
<Separator />
</Spacing>
</Div>
)}
</ComponentPlayground>
Expand Down
3 changes: 1 addition & 2 deletions packages/vkui/src/components/Spacing/Spacing.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
--vkui_internal--Spacing_gap: 0;

position: relative;
block-size: var(--vkui_internal--Spacing_gap);
padding-block: calc(1px * var(--vkui_internal--Spacing_gap) / 2);
padding-block: calc(var(--vkui_internal--Spacing_gap) / 2);
box-sizing: border-box;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/vkui/src/components/Spacing/Spacing.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ describe('Spacing', () => {

it('should use custom size', () => {
const h = render(<Spacing size={16} />);
expect(h.container.firstElementChild).toHaveStyle(`${CUSTOM_CSS_TOKEN_FOR_USER_GAP}: 16`);
expect(h.container.firstElementChild).toHaveStyle(`${CUSTOM_CSS_TOKEN_FOR_USER_GAP}: 16px`);
});

it('should preserve user style', () => {
const h = render(<Spacing size={16} style={{ fontSize: 12 }} />);
expect(h.container.firstElementChild).toHaveStyle(
`font-size: 12px; ${CUSTOM_CSS_TOKEN_FOR_USER_GAP}: 16`,
`font-size: 12px; ${CUSTOM_CSS_TOKEN_FOR_USER_GAP}: 16px`,
);
});
});
2 changes: 1 addition & 1 deletion packages/vkui/src/components/Spacing/Spacing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const Spacing = ({ size = 'm', style, ...restProps }: SpacingProps): Reac
<RootComponent
{...restProps}
style={{
...(typeof size === 'number' && { [CUSTOM_CSS_TOKEN_FOR_USER_GAP]: size }),
...(typeof size === 'number' && { [CUSTOM_CSS_TOKEN_FOR_USER_GAP]: `${size}px` }),
...style,
}}
baseClassName={classNames(
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.

0 comments on commit fa75452

Please sign in to comment.