-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from web-dahuyou/dev
新增小功能
- Loading branch information
Showing
24 changed files
with
308 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { ReactNode, useEffect, useState, useRef } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
const StyledStickyInner = styled.div<{ | ||
$width?: number | string; | ||
$left?: number | string; | ||
$bottom: number | string; | ||
$bgColor?: string; | ||
$paddingX?: number | string; | ||
}>` | ||
position: relative; | ||
width: 100%; | ||
padding: 0 ${(props) => props.$paddingX || 0}px; | ||
background: ${(props) => props.$bgColor || '#fff'}; | ||
&.fixed { | ||
position: fixed; | ||
width: ${(props) => props.$width ? `${props.$width}px` : '100%'}; | ||
left: ${(props) => `${props.$left || 0}px`}; | ||
bottom: ${(props) => `${props.$bottom || 0}px`}; | ||
box-shadow: 0 -2px 12px 1px rgba(0, 0, 0, 0.1); | ||
z-index: 10; | ||
} | ||
`; | ||
|
||
interface StickyFooterProps { | ||
children: ReactNode; | ||
bottomGap?: number; | ||
fullWidth?: boolean; | ||
bgColor?: string; | ||
paddingX?: number | string; | ||
} | ||
|
||
export default function StickyFooter({ | ||
children, | ||
bottomGap = 0, | ||
fullWidth = false, | ||
bgColor = '#fff', | ||
paddingX = 0, | ||
}: StickyFooterProps) { | ||
const wrapperRef = useRef<HTMLDivElement>(null); | ||
const innerRef = useRef<HTMLDivElement>(null); | ||
const [wrapperBounds, setWrapperBounds] = useState({ | ||
bottom: 0, | ||
left: 0, | ||
width: 0, | ||
height: 0, | ||
}); | ||
|
||
useEffect(() => { | ||
const wrapper = wrapperRef.current; | ||
const inner = innerRef.current; | ||
if (!wrapper || !inner) return; | ||
const { left, width } = wrapper.getBoundingClientRect(); | ||
const { height } = inner.getBoundingClientRect(); | ||
wrapper.style.height = `${height}px`; | ||
setWrapperBounds({ bottom: 0, left, width, height }); | ||
}, []); | ||
|
||
return ( | ||
<div ref={wrapperRef} className="sticky-footer-wrapper"> | ||
<StyledStickyInner | ||
ref={innerRef} | ||
className="sticky-footer-inner fixed" | ||
$width={fullWidth ? '' : wrapperBounds.width} | ||
$left={fullWidth ? 0 : wrapperBounds.left} | ||
$bottom={bottomGap} | ||
$bgColor={bgColor} | ||
$paddingX={fullWidth ? wrapperBounds.left : paddingX} | ||
> | ||
{children} | ||
</StyledStickyInner> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.