-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Group): Add Group.ExpandedContent to ignore group inner paddings (…
…#7396) Добавили подкомпонент для игнорирования вертикальных и горизонтальных отступов `Group`. Можно игнорировать либо вертикальные, либо горизонтальные отступы. Возможно, что имеет смысл игнорировать сразу все отступы, но это можно сделать отдельным вариантом свойства `direction`. - перетасовали css переменные в `Group`. Потребовалось, чтобы упростить понимание реализации `Group.ExpandedContent`. Так как `Group.ExpandedContent` всегда будет находится внутри `Group` и на него всегда будут влиять внутренние отступы `Group`, будет логично внутренние отступы компенсировать за счёт отрицательных марджинов. Проще всего взять текущее значение паддинга, умножить на -1 и подставить в `margin` `Group.ExpandedContent`. Но чтобы это сделать надо где-то хранить текущее значение паддинга. Так как паддинг по горизонтали и вертикали меняется относительно режима `mode = 'card' | 'plain'` у `Group`, то логично хранить паддинг в двух отдельных css-переменных: `--vkui_internal--Group_padding_inline` и `--vkui_internal--Group_padding_block`. Можно один раз прописать ```css padding-block: var(--vkui_internal--Group_padding_block); padding-inline: var(--vkui_internal--Group_padding_inline); ``` а дальше менять только css-переменные, в зависимости от режима. К сожалению, не удалось избавиться от сss-переменной `--vkui_internal--Group_padding_size`, которая используется для задания отступов в режиме `card`. Тем не менее удалось встроить её в схему с основными переменными. Переменная теперь имеет более специфичное имя: `--vkui_internal--Group_card_mode_padding_size`.
- Loading branch information
Showing
18 changed files
with
229 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
import { test } from '@vkui-e2e/test'; | ||
import { GroupPlayground } from './Group.e2e-playground'; | ||
import { GroupPlayground, GroupWithExpandedContentPlayground } from './Group.e2e-playground'; | ||
|
||
test('Group', async ({ mount, expectScreenshotClippedToContent, componentPlaygroundProps }) => { | ||
await mount(<GroupPlayground {...componentPlaygroundProps} />); | ||
await expectScreenshotClippedToContent(); | ||
}); | ||
|
||
test('Group.ExpandedContent', async ({ | ||
mount, | ||
expectScreenshotClippedToContent, | ||
componentPlaygroundProps, | ||
}) => { | ||
await mount(<GroupWithExpandedContentPlayground {...componentPlaygroundProps} />); | ||
await expectScreenshotClippedToContent(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/vkui/src/components/Group/GroupExpandedContent.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { GroupExpandedContent, type GroupExpandedContentProps } from './GroupExpandedContent'; | ||
import styles from './Group.module.css'; | ||
|
||
describe('GroupExpandedContent', () => { | ||
it.each<{ direction: GroupExpandedContentProps['direction']; className: string }>([ | ||
{ | ||
direction: undefined, | ||
className: styles['Group__expanded-content--inline'], | ||
}, | ||
{ | ||
direction: 'inline', | ||
className: styles['Group__expanded-content--inline'], | ||
}, | ||
{ | ||
direction: 'block', | ||
className: styles['Group__expanded-content--block'], | ||
}, | ||
])( | ||
'should have className "$className" with direction "$direction"', | ||
async ({ direction, className }) => { | ||
render(<GroupExpandedContent direction={direction}>Content</GroupExpandedContent>); | ||
expect(screen.getByText('Content')).toHaveClass(className); | ||
}, | ||
); | ||
}); |
27 changes: 27 additions & 0 deletions
27
packages/vkui/src/components/Group/GroupExpandedContent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as React from 'react'; | ||
import { classNames } from '@vkontakte/vkjs'; | ||
import type { HasComponent, HTMLAttributesWithRootRef } from '../../types'; | ||
import { RootComponent } from '../RootComponent/RootComponent'; | ||
import styles from './Group.module.css'; | ||
|
||
const stylesDirection = { | ||
inline: styles['Group__expanded-content--inline'], | ||
block: styles['Group__expanded-content--block'], | ||
}; | ||
|
||
export type GroupExpandedContentProps = HTMLAttributesWithRootRef<HTMLElement> & | ||
HasComponent & { | ||
direction?: 'inline' | 'block'; | ||
}; | ||
export const GroupExpandedContent: React.FC<GroupExpandedContentProps> = ({ | ||
direction = 'inline', | ||
...restProps | ||
}: GroupExpandedContentProps) => { | ||
return ( | ||
<RootComponent | ||
Component="div" | ||
{...restProps} | ||
baseClassName={classNames(styles['Group__expanded-content'], stylesDirection[direction])} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...roup/__image_snapshots__/group-expandedcontent-android-chromium-dark-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...oup/__image_snapshots__/group-expandedcontent-android-chromium-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ents/Group/__image_snapshots__/group-expandedcontent-ios-webkit-dark-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...nts/Group/__image_snapshots__/group-expandedcontent-ios-webkit-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
.../Group/__image_snapshots__/group-expandedcontent-vkcom-chromium-dark-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...Group/__image_snapshots__/group-expandedcontent-vkcom-chromium-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...s/Group/__image_snapshots__/group-expandedcontent-vkcom-firefox-dark-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
.../Group/__image_snapshots__/group-expandedcontent-vkcom-firefox-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ts/Group/__image_snapshots__/group-expandedcontent-vkcom-webkit-dark-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...s/Group/__image_snapshots__/group-expandedcontent-vkcom-webkit-light-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.