Skip to content

Commit c029464

Browse files
authored
refactor: use semantic name (#575)
* refactor: use semantic name * chore: rename var
1 parent 9021a70 commit c029464

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

assets/index.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
}
7575
}
7676

77-
// =============== Float BG ===============
78-
&-float-bg {
77+
// =============== Unique Body ===============
78+
&-unique-body {
7979
position: absolute;
8080
z-index: 0;
8181
box-sizing: border-box;

src/UniqueProvider/FloatBg.tsx renamed to src/UniqueProvider/UniqueBody.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import CSSMotion from '@rc-component/motion';
55
import type { CSSMotionProps } from '@rc-component/motion';
66
import type { AlignType } from '../interface';
77

8-
export interface FloatBgProps {
9-
prefixCls: string; // ${prefixCls}-float-bg
8+
export interface UniqueBodyProps {
9+
prefixCls: string; // ${prefixCls}-unique-body
1010
isMobile: boolean;
1111
ready: boolean;
1212
open: boolean;
@@ -21,7 +21,7 @@ export interface FloatBgProps {
2121
uniqueBgStyle?: React.CSSProperties;
2222
}
2323

24-
const FloatBg = (props: FloatBgProps) => {
24+
const UniqueBody = (props: UniqueBodyProps) => {
2525
const {
2626
prefixCls,
2727
isMobile,
@@ -38,7 +38,7 @@ const FloatBg = (props: FloatBgProps) => {
3838
uniqueBgStyle,
3939
} = props;
4040

41-
const floatBgCls = `${prefixCls}-float-bg`;
41+
const bodyCls = `${prefixCls}-unique-body`;
4242

4343
const [motionVisible, setMotionVisible] = React.useState(false);
4444

@@ -68,16 +68,16 @@ const FloatBg = (props: FloatBgProps) => {
6868
motionEnter
6969
motionLeave
7070
removeOnLeave={false}
71-
leavedClassName={`${floatBgCls}-hidden`}
71+
leavedClassName={`${bodyCls}-hidden`}
7272
{...motion}
7373
visible={open}
7474
onVisibleChanged={(nextVisible) => {
7575
setMotionVisible(nextVisible);
7676
}}
7777
>
7878
{({ className: motionClassName, style: motionStyle }) => {
79-
const cls = classNames(floatBgCls, motionClassName, uniqueBgClassName, {
80-
[`${floatBgCls}-visible`]: motionVisible,
79+
const cls = classNames(bodyCls, motionClassName, uniqueBgClassName, {
80+
[`${bodyCls}-visible`]: motionVisible,
8181
});
8282

8383
return (
@@ -96,4 +96,4 @@ const FloatBg = (props: FloatBgProps) => {
9696
);
9797
};
9898

99-
export default FloatBg;
99+
export default UniqueBody;

src/UniqueProvider/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Popup from '../Popup';
1212
import { useEvent } from '@rc-component/util';
1313
import useTargetState from './useTargetState';
1414
import { isDOM } from '@rc-component/util/lib/Dom/findDOMNode';
15-
import FloatBg from './FloatBg';
15+
import UniqueBody from './UniqueBody';
1616
import classNames from 'classnames';
1717
import { getAlignPopupClassName } from '../util';
1818

@@ -204,7 +204,7 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => {
204204
maskMotion={options.maskMotion}
205205
// getPopupContainer={options.getPopupContainer}
206206
>
207-
<FloatBg
207+
<UniqueBody
208208
prefixCls={prefixCls}
209209
isMobile={false}
210210
ready={ready}

tests/unique.test.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import Trigger, { UniqueProvider } from '../src';
44
import { awaitFakeTimer } from './util';
55
import type { TriggerProps } from '../src';
66

7-
// Mock FloatBg to check if open props changed
7+
// Mock UniqueBody to check if open props changed
88
global.openChangeLog = [];
99

10-
jest.mock('../src/UniqueProvider/FloatBg', () => {
11-
const OriginalFloatBg = jest.requireActual(
12-
'../src/UniqueProvider/FloatBg',
10+
jest.mock('../src/UniqueProvider/UniqueBody', () => {
11+
const OriginalUniqueBody = jest.requireActual(
12+
'../src/UniqueProvider/UniqueBody',
1313
).default;
1414
const OriginReact = jest.requireActual('react');
1515

@@ -24,7 +24,7 @@ jest.mock('../src/UniqueProvider/FloatBg', () => {
2424
}
2525
}, [open]);
2626

27-
return OriginReact.createElement(OriginalFloatBg, props);
27+
return OriginReact.createElement(OriginalUniqueBody, props);
2828
};
2929
});
3030

@@ -103,7 +103,7 @@ describe('Trigger.Unique', () => {
103103
'-hidden',
104104
);
105105
expect(
106-
document.querySelector('.rc-trigger-popup-float-bg').className,
106+
document.querySelector('.rc-trigger-popup-unique-body').className,
107107
).not.toContain('-hidden');
108108

109109
// Move from first to second trigger - popup should not hide, but content should change
@@ -120,12 +120,12 @@ describe('Trigger.Unique', () => {
120120
'-hidden',
121121
);
122122
expect(
123-
document.querySelector('.rc-trigger-popup-float-bg').className,
123+
document.querySelector('.rc-trigger-popup-unique-body').className,
124124
).not.toContain('-hidden');
125125

126126
// There should only be one popup element
127127
expect(document.querySelectorAll('.rc-trigger-popup').length).toBe(1);
128-
expect(document.querySelectorAll('.rc-trigger-popup-float-bg').length).toBe(
128+
expect(document.querySelectorAll('.rc-trigger-popup-unique-body').length).toBe(
129129
1,
130130
);
131131

@@ -182,33 +182,33 @@ describe('Trigger.Unique', () => {
182182
expect(popup.className).toContain('rc-trigger-popup-unique-controlled');
183183
});
184184

185-
it('should apply uniqueBgClassName to FloatBg component', async () => {
185+
it('should apply uniqueBgClassName to UniqueBody component', async () => {
186186
await setupAndOpenPopup({ uniqueBgClassName: 'custom-bg-class' });
187187

188-
// Check that FloatBg has the custom background className
189-
const floatBg = document.querySelector('.rc-trigger-popup-float-bg');
190-
expect(floatBg).toBeTruthy();
191-
expect(floatBg.className).toContain('custom-bg-class');
188+
// Check that UniqueBody has the custom background className
189+
const uniqueBody = document.querySelector('.rc-trigger-popup-unique-body');
190+
expect(uniqueBody).toBeTruthy();
191+
expect(uniqueBody.className).toContain('custom-bg-class');
192192
});
193193

194-
it('should apply uniqueBgStyle to FloatBg component', async () => {
194+
it('should apply uniqueBgStyle to UniqueBody component', async () => {
195195
await setupAndOpenPopup({ uniqueBgStyle: { backgroundColor: 'red', border: '1px solid blue' } });
196196

197-
// Check that FloatBg has the custom background style
198-
const floatBg = document.querySelector('.rc-trigger-popup-float-bg');
199-
expect(floatBg).toBeTruthy();
200-
expect(floatBg).toHaveStyle({
197+
// Check that UniqueBody has the custom background style
198+
const uniqueBody = document.querySelector('.rc-trigger-popup-unique-body');
199+
expect(uniqueBody).toBeTruthy();
200+
expect(uniqueBody).toHaveStyle({
201201
backgroundColor: 'red',
202202
border: '1px solid blue',
203203
});
204204
});
205205

206-
it('should not apply any additional className to FloatBg when uniqueBgClassName is not provided', async () => {
206+
it('should not apply any additional className to UniqueBody when uniqueBgClassName is not provided', async () => {
207207
await setupAndOpenPopup();
208208

209-
// Check that FloatBg exists but does not have custom background className
210-
const floatBg = document.querySelector('.rc-trigger-popup-float-bg');
211-
expect(floatBg).toBeTruthy();
212-
expect(floatBg.className).not.toContain('undefined');
209+
// Check that UniqueBody exists but does not have custom background className
210+
const uniqueBody = document.querySelector('.rc-trigger-popup-unique-body');
211+
expect(uniqueBody).toBeTruthy();
212+
expect(uniqueBody.className).not.toContain('undefined');
213213
});
214214
});

0 commit comments

Comments
 (0)