Skip to content

Commit cebd0f4

Browse files
committed
feat: add layout props to Flex
1 parent 1621aba commit cebd0f4

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

packages/vkui/docs/icons-overview/IconsOverview.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
Snackbar,
1717
Tooltip,
1818
} from '../../src';
19-
import { FlexItem } from '../../src/components/Flex/FlexItem/FlexItem';
2019
import { Keys, pressedKey } from '../../src/lib/accessibility';
2120
import { OverviewLayout } from '../common/components/OverviewLayout';
2221
import { useGetGlobalParams } from '../common/hooks/useGetGlobalParams';
@@ -114,7 +113,7 @@ const IconsOverview = () => {
114113
ItemsContainer={({ children }) => <Flex gap={['2xl', 'xl']}>{children}</Flex>}
115114
renderSectionItem={(iconData, iconSizeData) => (
116115
<Tooltip key={iconData.name} title={iconData.name} strategy="absolute">
117-
<FlexItem
116+
<div
118117
onClick={() => onIconClick(iconData.name)}
119118
onKeyDown={(e) => onKeyDown(e, iconData.name)}
120119
className={styles.icon}
@@ -123,7 +122,7 @@ const IconsOverview = () => {
123122
style={{ inlineSize: Number(iconSizeData.title) }}
124123
>
125124
{iconData.node}
126-
</FlexItem>
125+
</div>
127126
</Tooltip>
128127
)}
129128
additionalHeaderItem={
@@ -136,7 +135,7 @@ const IconsOverview = () => {
136135
allowClearButton
137136
/>
138137
{selectedSizes.length < SIZES_OPTIONS.length && (
139-
<FlexItem flex="shrink">
138+
<Flex flexShrink={1}>
140139
<Button
141140
size="m"
142141
mode="secondary"
@@ -145,7 +144,7 @@ const IconsOverview = () => {
145144
rounded
146145
aria-label="Сбросить фильтры"
147146
/>
148-
</FlexItem>
147+
</Flex>
149148
)}
150149
</Flex>
151150
}

packages/vkui/src/components/Flex/Flex.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import {
44
columnGapClassNames,
55
type GapProp,
66
type GapsProp,
7+
resolveLayoutProps,
78
rowGapClassNames,
89
} from '../../lib/layouts';
10+
import type { LayoutProps } from '../../lib/layouts/types';
911
import type { CSSCustomProperties } from '../../types';
1012
import { RootComponent } from '../RootComponent/RootComponent';
1113
import type { RootComponentProps } from '../RootComponent/RootComponent';
@@ -48,7 +50,9 @@ type FlexContentProps =
4850
| 'space-between'
4951
| 'space-evenly';
5052

51-
export interface FlexProps extends Omit<RootComponentProps<HTMLElement>, 'baseClassName'> {
53+
export interface FlexProps
54+
extends Omit<RootComponentProps<HTMLElement>, 'baseClassName'>,
55+
LayoutProps {
5256
/**
5357
* Направление осей, эквивалентно `flex-direction`.
5458
*/
@@ -104,13 +108,14 @@ export const Flex: React.FC<FlexProps> & {
104108
reverse = false,
105109
children,
106110
alignSelf,
107-
...props
111+
...restProps
108112
}: FlexProps) => {
109113
const [rowGap, columnGap] = calculateGap(gap);
114+
const resolvedProps = resolveLayoutProps(restProps);
110115

111116
return (
112117
<RootComponent
113-
{...props}
118+
{...resolvedProps}
114119
baseClassName={classNames(
115120
styles.host,
116121
!noWrap && styles.wrap,

website/content/components/flex.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ VKUI (например, [`Header`](/components/group#header) и [`SimpleCell`](/
117117
```
118118
</Playground>
119119

120-
## Flex.Item [tag:component]
120+
## ~Flex.Item~ [tag:component]
121+
122+
> Подкомпонент устарел. Используйте `Flex`, который теперь принимает все свойства `Flex.Item`.
121123
122124
Подкомпонент `Flex.Item` используется как обёртка для дочерних элементов компонента `Flex` в случае, когда нужно
123125
переопределить `flex`-свойства этих элементов, например, `flex-basis`:
@@ -129,6 +131,9 @@ VKUI (например, [`Header`](/components/group#header) и [`SimpleCell`](/
129131
<Flex.Item flexBasis={100}>
130132
<Card Component="div">Ширина 100px</Card>
131133
</Flex.Item>
134+
<Flex flexBasis={100}>
135+
<Card Component="div">Я лучше Ширина 100px</Card>
136+
</Flex>
132137
<Card Component="div">Колонка</Card>
133138
</Flex>
134139
```

0 commit comments

Comments
 (0)