Commit ea44e890 authored by chenshouchao's avatar chenshouchao

feat: RadioGroupOfButtonStyle增加滑动效果

parent 73f1eb5b
.RadiosBox { .RadiosBox {
position: relative;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
...@@ -29,8 +30,6 @@ ...@@ -29,8 +30,6 @@
.radioActive { .radioActive {
color: #1370ff; color: #1370ff;
background-color: #fff;
box-shadow: 2px 4px 12px 0px rgba(0, 27, 63, 0.06);
position: relative; position: relative;
} }
.border { .border {
...@@ -41,3 +40,21 @@ ...@@ -41,3 +40,21 @@
.borderHidden { .borderHidden {
visibility: hidden; visibility: hidden;
} }
.radioActiveBgBox {
width: calc(100% - 3px);
position: absolute;
left: 1px;
top: 1px;
height: 28px;
}
.radioActiveBg {
box-shadow: 2px 4px 12px 0px rgba(0, 27, 63, 0.06);
left: 1px;
top: 1px;
height: 28px;
background-color: #fff;
transition: transform 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
border-radius: 2px;
width: 50%;
transform: translateX(0px);
}
...@@ -28,6 +28,14 @@ const RadioGroupOfButtonStyle = (props: IRadioGroupOfButtonStyleProps) => { ...@@ -28,6 +28,14 @@ const RadioGroupOfButtonStyle = (props: IRadioGroupOfButtonStyleProps) => {
const { radioOptions, value, handleRadio, RadiosBoxStyle, radioStyle } = const { radioOptions, value, handleRadio, RadiosBoxStyle, radioStyle } =
props; props;
const radioWidth = useMemo(() => {
if (radioOptions.length) {
return Number((100 / radioOptions.length).toFixed(2));
} else {
return 100;
}
}, [radioOptions]);
const activeIndex: any = useMemo(() => { const activeIndex: any = useMemo(() => {
let res = 0; let res = 0;
radioOptions.forEach((item, index) => { radioOptions.forEach((item, index) => {
...@@ -40,6 +48,16 @@ const RadioGroupOfButtonStyle = (props: IRadioGroupOfButtonStyleProps) => { ...@@ -40,6 +48,16 @@ const RadioGroupOfButtonStyle = (props: IRadioGroupOfButtonStyleProps) => {
return ( return (
<div className={style.RadiosBox} style={RadiosBoxStyle}> <div className={style.RadiosBox} style={RadiosBoxStyle}>
<div className={style.radioActiveBgBox}>
<div
className={style.radioActiveBg}
style={{
width: `${radioWidth}%`,
transform: `translateX(${activeIndex * 100}%)`,
}}
></div>
</div>
{radioOptions.map((options, index) => { {radioOptions.map((options, index) => {
return ( return (
<> <>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment