Skip to content

Commit 4fd8ef2

Browse files
authored
✨ feat: bump deps and refactor the flex basic (#10)
BREAKING CHANGES: need react >= 19
1 parent 8596b3f commit 4fd8ef2

File tree

5 files changed

+107
-85
lines changed

5 files changed

+107
-85
lines changed

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
# Changelog
22

3+
## [Version 2.0.0-beta.1](https://github.com/arvinxx/react-layout-kit/compare/v1.9.2...v2.0.0-beta.1)
4+
5+
<sup>Released on **2025-07-25**</sup>
6+
7+
#### ✨ 新特性
8+
9+
- Bump deps and refactor the basic.
10+
11+
<br/>
12+
13+
<details>
14+
<summary><kbd>Improvements and Fixes</kbd></summary>
15+
16+
#### What's improved
17+
18+
- Bump deps and refactor the basic ([4efb9de](https://github.com/arvinxx/react-layout-kit/commit/4efb9de))
19+
20+
</details>
21+
22+
#### 💥 BREAKING CHANGES
23+
24+
- need react >= 19
25+
26+
<div align="right">
27+
28+
[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
29+
30+
</div>
31+
332
### [Version&nbsp;1.9.2](https://github.com/arvinxx/react-layout-kit/compare/v1.9.1...v1.9.2)
433

534
<sup>Released on **2025-07-18**</sup>

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-layout-kit",
3-
"version": "1.9.2",
3+
"version": "2.0.0-beta.1",
44
"description": "a npm develop template",
55
"keywords": [
66
"react",
@@ -59,8 +59,8 @@
5959
]
6060
},
6161
"dependencies": {
62-
"@babel/runtime": "^7",
63-
"@emotion/css": "^11"
62+
"@babel/runtime": "^7.28.2",
63+
"@emotion/css": "^11.13.5"
6464
},
6565
"devDependencies": {
6666
"@commitlint/cli": "^17",
@@ -89,16 +89,16 @@
8989
"prettier": "^2",
9090
"prettier-plugin-organize-imports": "^3",
9191
"prettier-plugin-packagejson": "^2",
92-
"react": "^18",
93-
"react-dom": "^18",
92+
"react": "^19.1.0",
93+
"react-dom": "^19.1.0",
9494
"semantic-release": "^20",
9595
"semantic-release-config-gitmoji": "^1",
9696
"stylelint": "^14",
9797
"typescript": "^5",
9898
"vitest": "^3.2.4"
9999
},
100100
"peerDependencies": {
101-
"react": ">=18"
101+
"react": ">=19"
102102
},
103103
"publishConfig": {
104104
"access": "public",

src/Center/index.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33
import FlexBasic, { FlexBasicProps } from '@/FlexBasic';
44
import { CommonProps } from '@/type';
55
import { getPrefix } from '@/utils';
6-
import { forwardRef } from 'react';
6+
import { memo } from 'react';
77

88
export type CenterProps = Omit<FlexBasicProps, 'distribution' | 'direction' | 'align'>;
99

10-
const Center = forwardRef<HTMLElement, CenterProps & CommonProps>(
11-
({ children, className, prefixCls, ...res }, ref) => (
12-
<FlexBasic
13-
ref={ref}
14-
internalClassName={`${getPrefix(prefixCls)}-center`}
15-
className={className}
16-
{...res}
17-
align={'center'}
18-
justify={'center'}
19-
>
20-
{children}
21-
</FlexBasic>
22-
),
23-
);
10+
const Center = memo<CenterProps & CommonProps>(({ children, className, prefixCls, ...res }) => (
11+
<FlexBasic
12+
internalClassName={`${getPrefix(prefixCls)}-center`}
13+
className={className}
14+
{...res}
15+
align={'center'}
16+
justify={'center'}
17+
>
18+
{children}
19+
</FlexBasic>
20+
));
2421

2522
Center.displayName = 'Center';
2623

src/FlexBasic/index.tsx

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ContentPosition, DivProps, FlexDirection } from '@/type';
22
import { getCssValue, getFlexDirection, isHorizontal, isSpaceDistribution } from '@/utils';
33
import { css, cx } from '@emotion/css';
4-
import { CSSProperties, ElementType, forwardRef, useMemo } from 'react';
4+
import { CSSProperties, ElementType, memo, Ref, useMemo } from 'react';
55

66
export type CommonSpaceNumber = 2 | 4 | 8 | 12 | 16 | 24;
77

@@ -89,46 +89,46 @@ export interface IFlexbox {
8989
as?: ElementType;
9090
}
9191

92-
export interface FlexBasicProps extends IFlexbox, Omit<DivProps, 'ref'> {
92+
export interface FlexBasicProps extends IFlexbox, DivProps {
9393
internalClassName?: string;
94+
ref?: Ref<any>;
9495
}
9596

96-
const FlexBasic = forwardRef<any, FlexBasicProps>(
97-
(
98-
{
99-
visible,
100-
flex,
101-
gap,
102-
direction,
103-
horizontal,
104-
align,
105-
justify,
106-
distribution,
107-
height,
108-
width,
109-
padding,
110-
paddingInline,
111-
paddingBlock,
112-
as: Container = 'div',
113-
internalClassName,
114-
className,
115-
children,
116-
wrap,
117-
...props
118-
},
97+
const FlexBasic = memo<FlexBasicProps>(
98+
({
99+
visible,
100+
flex,
101+
gap,
102+
direction,
103+
horizontal,
104+
align,
105+
justify,
106+
distribution,
107+
height,
108+
width,
109+
padding,
110+
paddingInline,
111+
paddingBlock,
112+
as: Container = 'div',
113+
internalClassName,
114+
className,
115+
children,
116+
wrap,
119117
ref,
120-
) => {
118+
...props
119+
}) => {
121120
const justifyContent = justify || distribution;
122121

123-
const finalWidth = useMemo(() => {
124-
if (isHorizontal(direction, horizontal) && !width && isSpaceDistribution(justifyContent))
125-
return '100%';
122+
const mergedClassName = useMemo(() => {
123+
const calcWidth = () => {
124+
if (isHorizontal(direction, horizontal) && !width && isSpaceDistribution(justifyContent))
125+
return '100%';
126126

127-
return getCssValue(width);
128-
}, [direction, horizontal, justifyContent, width]);
127+
return getCssValue(width);
128+
};
129+
const finalWidth = calcWidth();
129130

130-
const funcClassName = useMemo(
131-
() => css`
131+
const funcClassName = css`
132132
display: ${visible === false ? 'none' : 'flex'};
133133
134134
flex: ${flex};
@@ -148,26 +148,29 @@ const FlexBasic = forwardRef<any, FlexBasicProps>(
148148
padding-block: ${getCssValue(paddingBlock)};
149149
150150
gap: ${getCssValue(gap)};
151-
`,
152-
[
153-
visible,
154-
flex,
155-
direction,
156-
horizontal,
157-
wrap,
158-
justifyContent,
159-
align,
160-
finalWidth,
161-
height,
162-
padding,
163-
paddingInline,
164-
paddingBlock,
165-
gap,
166-
],
167-
);
151+
`;
152+
153+
return cx(internalClassName, funcClassName, className);
154+
}, [
155+
visible,
156+
flex,
157+
direction,
158+
horizontal,
159+
width,
160+
wrap,
161+
justifyContent,
162+
align,
163+
height,
164+
padding,
165+
paddingInline,
166+
paddingBlock,
167+
gap,
168+
internalClassName,
169+
className,
170+
]);
168171

169172
return (
170-
<Container ref={ref} {...props} className={cx(internalClassName, funcClassName, className)}>
173+
<Container ref={ref} {...props} className={mergedClassName}>
171174
{children}
172175
</Container>
173176
);

src/Flexbox/index.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
'use client';
22

3-
import { forwardRef } from 'react';
3+
import { memo } from 'react';
44

55
import FlexBasic, { FlexBasicProps } from '@/FlexBasic';
66
import { CommonProps } from '@/type';
77
import { getPrefix } from '@/utils';
88

99
export type FlexboxProps = FlexBasicProps & CommonProps;
1010

11-
const Flexbox = forwardRef<HTMLElement, FlexboxProps>(
12-
({ className, prefixCls, children, ...props }, ref) => (
13-
<FlexBasic
14-
ref={ref}
15-
{...props}
16-
internalClassName={`${getPrefix(prefixCls)}-flexbox`}
17-
className={className}
18-
>
19-
{children}
20-
</FlexBasic>
21-
),
22-
);
11+
const Flexbox = memo<FlexboxProps>(({ className, prefixCls, children, ...props }) => (
12+
<FlexBasic {...props} internalClassName={`${getPrefix(prefixCls)}-flexbox`} className={className}>
13+
{children}
14+
</FlexBasic>
15+
));
2316

2417
Flexbox.displayName = 'Flexbox';
2518

0 commit comments

Comments
 (0)