Skip to content

Commit ee36008

Browse files
committed
feat: deprecate Flex.Item
1 parent 8bb7af2 commit ee36008

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

examples/vkui-vite-ts/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default function App() {
4444
<Flex direction="column" justify="center" className={styles.layout}>
4545
<FixedLayout vertical="top">
4646
<Flex justify="end" className={styles.header}>
47-
<Flex.Item>{colorSchemeSwitcher}</Flex.Item>
47+
{colorSchemeSwitcher}
4848
</Flex>
4949
</FixedLayout>
5050
<Flex direction="column" justify="center" align="center" gap={16}>

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { RootComponent } from '../RootComponent/RootComponent';
1111
import type { RootComponentProps } from '../RootComponent/RootComponent';
1212
import { FlexItem, type FlexItemProps } from './FlexItem/FlexItem';
1313
import styles from './Flex.module.css';
14+
import flexItemStyles from './FlexItem/FlexItem.module.css';
1415

1516
export type { FlexItemProps };
1617

@@ -31,6 +32,14 @@ const alignClassNames = {
3132
baseline: styles.alignBaseline,
3233
};
3334

35+
const alignSelfClassNames = {
36+
start: flexItemStyles.alignSelfStart,
37+
end: flexItemStyles.alignSelfEnd,
38+
center: flexItemStyles.alignSelfCenter,
39+
baseline: flexItemStyles.alignSelfBaseline,
40+
stretch: flexItemStyles.alignSelfStretch,
41+
};
42+
3443
type FlexContentProps =
3544
| 'start'
3645
| 'end'
@@ -70,12 +79,20 @@ export interface FlexProps extends Omit<RootComponentProps<HTMLElement>, 'baseCl
7079
* Для инвертирования направления, эквивалентно `row-reverse` `column-reverse`.
7180
*/
7281
reverse?: boolean;
82+
/**
83+
* Для задания выравнивания, отличного от установленного на родителе, эквивалентно `align-self`.
84+
*/
85+
alignSelf?: 'start' | 'end' | 'center' | 'baseline' | 'stretch';
7386
}
7487

7588
/**
7689
* @see https://vkui.io/components/flex
7790
*/
7891
export const Flex: React.FC<FlexProps> & {
92+
/**
93+
* @deprecated Since 8.0.0. Будет удалено в **VKUI v9**.
94+
* Используйте компонент `Flex`.
95+
*/
7996
Item: typeof FlexItem;
8097
} = ({
8198
gap = 0,
@@ -86,6 +103,7 @@ export const Flex: React.FC<FlexProps> & {
86103
direction = 'row',
87104
reverse = false,
88105
children,
106+
alignSelf,
89107
...props
90108
}: FlexProps) => {
91109
const [rowGap, columnGap] = calculateGap(gap);
@@ -100,6 +118,7 @@ export const Flex: React.FC<FlexProps> & {
100118
direction !== 'row' && styles.directionColumn,
101119
margin !== 'none' && styles.marginAuto,
102120
align && alignClassNames[align],
121+
alignSelf && alignSelfClassNames[alignSelf],
103122
justify && justifyClassNames[justify],
104123
getGapsPresets(rowGap, columnGap),
105124
)}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { classNames } from '@vkontakte/vkjs';
2+
import { warnOnce } from '../../../lib/warnOnce';
23
import type { HasChildren } from '../../../types';
34
import { RootComponent } from '../../RootComponent/RootComponent';
45
import type { RootComponentProps } from '../../RootComponent/RootComponent';
@@ -41,13 +42,19 @@ export interface FlexItemProps
4142
flexBasis?: number | string;
4243
}
4344

45+
const warn = warnOnce('Flex.Item');
46+
4447
export const FlexItem = ({
4548
children,
4649
alignSelf,
4750
flex,
4851
flexBasis,
4952
...rest
5053
}: FlexItemProps): React.ReactNode => {
54+
if (process.env.NODE_ENV === 'development') {
55+
warn('Компонент Flex.Item устарел, используйте компонент Flex в качестве альтернативы.');
56+
}
57+
5158
return (
5259
<RootComponent
5360
{...rest}

0 commit comments

Comments
 (0)