Skip to content

Commit 48fb550

Browse files
committed
chroe: add methods of components and optimization of code
1 parent 895edb8 commit 48fb550

File tree

9 files changed

+47
-13
lines changed

9 files changed

+47
-13
lines changed

src/components/Rotate/Index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import LoadingIcon from './../../assets/icons/LoadingIcon'
1414
import ArrowsIcon from "../../assets/icons/ArrowsIcon";
1515
import {RotateConfig, defaultConfig} from "./meta/config";
1616
import {useHandler} from "./hooks/useHandler";
17-
import {RotateData} from "./meta/data";
17+
import {defaultRotateData, RotateData} from "./meta/data";
1818
import {RotateEvent} from "./meta/event";
1919

2020

@@ -34,7 +34,7 @@ export interface Props extends React.HTMLAttributes<HTMLElement> {
3434

3535
const Index:FC<Props> = forwardRef<RotateRef, Props>((props: Props, ref) => {
3636
const [localConfig, setLocalConfig] = useState<RotateConfig>({...defaultConfig(), ...(props.config || {})})
37-
const [localData, setLocalData] = useState<RotateData>({...(props.data || {})})
37+
const [localData, setLocalData] = useState<RotateData>({...defaultRotateData(), ...(props.data || {})})
3838
const [localEvents, setLocalEvents] = useState<RotateEvent>({...(props.events || {})})
3939

4040
useEffect(() => {
@@ -61,7 +61,7 @@ const Index:FC<Props> = forwardRef<RotateRef, Props>((props: Props, ref) => {
6161
dragBlockRef,
6262
dragBarRef,
6363
() => {
64-
setLocalData({...localData, thumb: '', image: '', angle: 0})
64+
setLocalData({...localData, ...defaultRotateData()})
6565
});
6666

6767
const hPadding = localConfig.horizontalPadding || 0
@@ -116,7 +116,7 @@ const Index:FC<Props> = forwardRef<RotateRef, Props>((props: Props, ref) => {
116116
height: localConfig.height + 'px'
117117
}}
118118
>
119-
<div style={{width: size + "px", height: size + "px" }}>
119+
<div className={classnames(cstyles.bodyInner, styles.bodyInner)} style={{width: size + "px", height: size + "px" }}>
120120
<div className={styles.loading}>
121121
<LoadingIcon />
122122
</div>

src/components/Rotate/index.module.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
margin: 10px auto 0;
1717
}
1818

19+
.bodyInner{
20+
border-radius: 100%;
21+
}
22+
1923
.picture{
2024
position: relative;
2125
max-width: 100%;

src/components/Rotate/meta/data.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ export interface RotateData {
88
angle: number;
99
image: string;
1010
thumb: string;
11-
}
11+
}
12+
13+
export const defaultRotateData = () :RotateData => ({
14+
angle: 0,
15+
image: '',
16+
thumb: ''
17+
})

src/components/Slide/Index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import CloseIcon from './../../assets/icons/CloseIcon'
1212
import RefreshIcon from './../../assets/icons/RefreshIcon'
1313
import LoadingIcon from './../../assets/icons/LoadingIcon'
1414
import ArrowsIcon from './../../assets/icons/ArrowsIcon'
15-
import {SlideData} from "./meta/data";
15+
import {defaultSlideData, SlideData} from "./meta/data";
1616
import {SlideConfig, defaultConfig} from "./meta/config";
1717
import {SlideEvent} from "./meta/event";
1818
import {useHandler} from "./hooks/useHandler";
@@ -33,7 +33,7 @@ export interface Props extends React.HTMLAttributes<HTMLElement> {
3333

3434
const Index:FC<Props> = forwardRef<SlideRef, Props>((props: Props, ref) => {
3535
const [localConfig, setLocalConfig] = useState<SlideConfig>({...defaultConfig(), ...(props.config || {})})
36-
const [localData, setLocalData] = useState<SlideData>({...(props.data || {})})
36+
const [localData, setLocalData] = useState<SlideData>({...defaultSlideData(), ...(props.data || {})})
3737
const [localEvents, setLocalEvents] = useState<SlideEvent>({...(props.events || {})})
3838

3939
useEffect(() => {
@@ -64,7 +64,7 @@ const Index:FC<Props> = forwardRef<SlideRef, Props>((props: Props, ref) => {
6464
dragBlockRef,
6565
dragBarRef,
6666
() => {
67-
setLocalData({...localData, image: '', thumb: '', thumbX: 0, thumbY: 0, thumbHeight: 0, thumbWidth: 0})
67+
setLocalData({...localData, ...defaultSlideData()})
6868
}
6969
);
7070

src/components/Slide/hooks/useHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const useHandler = (
4545

4646
const tileWith = tileRef.current.offsetWidth
4747
const tileOffsetLeft = tileRef.current.offsetLeft
48+
const containerMaxWidth = width - tileWith
4849
const tileMaxWith = width - (tileWith + tileOffsetLeft)
4950
const ratio = tileMaxWith / maxWidth
5051

@@ -72,7 +73,7 @@ export const useHandler = (
7273
const ctX = tileOffsetLeft + (left * ratio)
7374
if (left >= maxWidth) {
7475
setDragLeft(maxWidth)
75-
currentThumbX = maxWidth
76+
currentThumbX = containerMaxWidth
7677
setThumbLeft(currentThumbX)
7778
return
7879
}

src/components/Slide/meta/data.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ export interface SlideData {
1313
thumb: string;
1414
}
1515

16+
export const defaultSlideData = (): SlideData => ({
17+
thumbX: 0,
18+
thumbY: 0,
19+
thumbWidth: 0,
20+
thumbHeight: 0,
21+
image: '',
22+
thumb: ''
23+
})
24+
1625
export interface SlidePoint {
1726
x: number,
1827
y: number,

src/components/SlideRegion/Index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import RefreshIcon from './../../assets/icons/RefreshIcon'
1313
import LoadingIcon from './../../assets/icons/LoadingIcon'
1414
import {SlideRegionConfig, defaultConfig} from "./meta/config";
1515
import {useHandler} from "./hooks/useHandler";
16-
import {SlideRegionData} from "./meta/data";
16+
import {defaultSlideRegionData, SlideRegionData} from "./meta/data";
1717
import {SlideRegionEvent} from "./meta/event";
1818

1919
export interface SlideRegionRef {
@@ -32,7 +32,7 @@ export interface Props extends React.HTMLAttributes<HTMLElement> {
3232

3333
const Index:FC<Props> = forwardRef<SlideRegionRef, Props>((props: Props, ref) => {
3434
const [localConfig, setLocalConfig] = useState<SlideRegionConfig>({...defaultConfig(), ...(props.config || {})})
35-
const [localData, setLocalData] = useState<SlideRegionData>({...(props.data || {})})
35+
const [localData, setLocalData] = useState<SlideRegionData>({...defaultSlideRegionData(), ...(props.data || {})})
3636
const [localEvents, setLocalEvents] = useState<SlideRegionEvent>({...(props.events || {})})
3737

3838
useEffect(() => {
@@ -59,7 +59,7 @@ const Index:FC<Props> = forwardRef<SlideRegionRef, Props>((props: Props, ref) =>
5959
containerRef,
6060
tileRef,
6161
() => {
62-
setLocalData({...localData, image: '', thumb: '', thumbX: 0, thumbY: 0, thumbHeight: 0, thumbWidth: 0})
62+
setLocalData({...localData, ...defaultSlideRegionData()})
6363
}
6464
);
6565

src/components/SlideRegion/meta/data.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ export interface SlideRegionData {
1313
thumb: string;
1414
}
1515

16+
export const defaultSlideRegionData = (): SlideRegionData => ({
17+
thumbX: 0,
18+
thumbY: 0,
19+
thumbWidth: 0,
20+
thumbHeight: 0,
21+
image: '',
22+
thumb: ''
23+
})
24+
1625
export interface SlideRegionPoint {
1726
x: number,
1827
y: number,

src/gocaptcha.module.less

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
--go-captcha-theme-drag-icon-color: #ffffff;
2020
--go-captcha-theme-round-color: #e0e0e0;
2121
--go-captcha-theme-loading-icon-color: #3e7cff;
22+
--go-captcha-theme-body-bg-color: #34383e;
2223

2324
--go-captcha-theme-default-color: #3e7cff;
2425
--go-captcha-theme-default-bg-color: #ecf5ff;
@@ -107,13 +108,17 @@
107108
display: -ms-flexbox;
108109
display: -webkit-flex;
109110
display: flex;
110-
background: #34383e;
111+
background: var(--go-captcha-theme-body-bg-color);
111112
border-radius: 5px;
112113
-webkit-border-radius: 5px;
113114
-moz-border-radius: 5px;
114115
overflow: hidden;
115116
}
116117

118+
.bodyInner {
119+
background: var(--go-captcha-theme-body-bg-color);
120+
}
121+
117122
.picture{
118123
position: relative;
119124
z-index: 2;

0 commit comments

Comments
 (0)