Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(HorizontalCell): add textAlign + noPadding + fixes #7980

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as React from 'react';
import { ComponentPlayground, type ComponentPlaygroundProps } from '@vkui-e2e/playground-helpers';
import {} from '../../testing/mock';
import { Avatar } from '../Avatar/Avatar';
import { Image } from '../Image/Image';
import { HorizontalCell, type HorizontalCellProps } from './HorizontalCell';

Expand All @@ -14,52 +12,45 @@ const containerStyle: React.CSSProperties = {
padding: 8,
};

const mapSizes = {
s: 56,
m: 88,
l: 128,
xl: 220,
auto: 250,
};

export const HorizontalCellPlayground = (props: ComponentPlaygroundProps) => {
return (
<ComponentPlayground
{...props}
propSets={[
{
size: ['s', 'm', 'l', 'xl', 'auto'],
title: ['Title'],
subtitle: ['Just subtitle'],
extraSubtitle: ['Some extra subtitle'],
},
{
size: ['s', 'm'],
title: ['Very long title example'],
},
{
size: [80],
textAlign: ['start', 'center', 'end'],
title: ['Title'],
subtitle: ['Just subtitle'],
},
{
size: ['s'],
noPadding: [true],
},
]}
>
{({ title, subtitle, extraSubtitle, ...restProps }: HorizontalCellProps) => (
{({ size, ...restProps }: HorizontalCellProps) => (
<div style={containerStyle}>
<HorizontalCell {...restProps} title={title} size="s">
<Avatar size={56} />
</HorizontalCell>
<HorizontalCell
{...restProps}
title={title}
subtitle={subtitle}
extraSubtitle={extraSubtitle}
size="m"
>
<Image size={88} borderRadius="l" />
</HorizontalCell>
<HorizontalCell
{...restProps}
title={title}
subtitle={subtitle}
extraSubtitle={extraSubtitle}
size="l"
>
<Image size={128} borderRadius="l" />
</HorizontalCell>
<HorizontalCell
{...restProps}
title={title}
subtitle={subtitle}
extraSubtitle={extraSubtitle}
size="xl"
>
<Image size={220} borderRadius="l" />
<HorizontalCell size={size} {...restProps}>
<Image size={typeof size === 'string' ? mapSizes[size] : 56} borderRadius="l" />
</HorizontalCell>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,24 @@
}

.sized {
--vkui_internal--side_cell_width: calc(
var(--vkui_internal--cell_width) + var(--vkui_internal--side_cell_gap)
);

max-inline-size: var(--vkui_internal--cell_width);
}

.customSize .body {
inline-size: var(--vkui_internal--cell_width);
}

.sizeS {
--vkui_internal--side_cell_gap: calc(
var(--vkui--size_base_padding_horizontal--regular) - var(--vkui--spacing_size_m)
);
--vkui_internal--cell_width: 72px;
}

.noPadding {
--vkui_internal--side_cell_gap: 0px;
}

.image {
padding-block: 4px;
padding-inline: var(--vkui--spacing_size_s);
Expand All @@ -59,6 +63,14 @@
text-align: start;
}

.textAlignCenter {
text-align: center;
}

.textAlignEnd {
text-align: end;
}

.sizeS .image {
padding-block: 4px;
padding-inline: var(--vkui--spacing_size_m);
Expand All @@ -67,7 +79,6 @@
.sizeS .content {
padding-block: 2px 8px;
padding-inline: 4px;
text-align: center;
}

.sizeM {
Expand All @@ -94,7 +105,13 @@

.sized:first-child,
.sized:last-child {
max-inline-size: var(--vkui_internal--side_cell_width);
max-inline-size: calc(var(--vkui_internal--cell_width) + var(--vkui_internal--side_cell_gap));
}

.sized:first-child:last-child {
max-inline-size: calc(
var(--vkui_internal--cell_width) + (2 * (var(--vkui_internal--side_cell_gap)))
);
}

.sized:first-child .body,
Expand Down
26 changes: 25 additions & 1 deletion packages/vkui/src/components/HorizontalCell/HorizontalCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const stylesSize = {
auto: styles.sizeAuto,
};

const textAlignClassNames = {
center: styles.textAlignCenter,
end: styles.textAlignEnd,
};

type HorizontalCellSizes = 's' | 'm' | 'l' | 'xl' | 'auto';

interface CellTypographyProps extends HTMLAttributesWithRootRef<HTMLDivElement> {
Expand Down Expand Up @@ -63,6 +68,16 @@ export interface HorizontalCellProps
* Дополнительная строка текста под `children` и `subtitle`.
*/
extraSubtitle?: React.ReactNode;
/**
* Задает выравнивание типографики. По умолчанию `center` для `size=s`, иначе `start`
*/
textAlign?: 'start' | 'center' | 'end';
/**
* Отключает формирование отступов у крайних элементов
*
* Актуально для использования в многострочных списках
*/
noPadding?: boolean;
}

/**
Expand All @@ -78,6 +93,8 @@ export const HorizontalCell = ({
getRootRef,
getRef,
extraSubtitle,
textAlign = size === 's' ? 'center' : 'start',
noPadding = false,
...restProps
}: HorizontalCellProps): React.ReactNode => {
const hasTypography =
Expand All @@ -94,13 +111,20 @@ export const HorizontalCell = ({
styles.host,
typeof size === 'string' && stylesSize[size],
size !== 'auto' && styles.sized,
typeof size === 'number' && styles.customSize,
noPadding && styles.noPadding,
className,
)}
>
<Tappable className={styles.body} getRootRef={getRef} {...restProps}>
{hasReactNode(children) && <div className={styles.image}>{children}</div>}
{hasTypography && (
<div className={styles.content}>
<div
className={classNames(
styles.content,
textAlign !== 'start' && textAlignClassNames[textAlign],
)}
>
{hasReactNode(title) && <CellTypography size={size}>{title}</CellTypography>}
{hasReactNode(subtitle) && <Footnote className={styles.subtitle}>{subtitle}</Footnote>}
{hasReactNode(extraSubtitle) && (
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