-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
125 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { HTMLMotionProps, MotionValue, m, useSpring } from 'framer-motion'; | ||
import { CSSProperties } from 'react'; | ||
|
||
import { useThemeToken } from '@/theme/hooks'; | ||
|
||
interface Props extends HTMLMotionProps<'div'> { | ||
color?: string; | ||
scrollYProgress: MotionValue<number>; | ||
height?: number; | ||
} | ||
/** | ||
* https://www.framer.com/motion/scroll-animations/##spring-smoothing | ||
*/ | ||
export default function ScrollProgress({ scrollYProgress, height = 4, color, ...other }: Props) { | ||
const scaleX = useSpring(scrollYProgress, { | ||
stiffness: 100, | ||
damping: 30, | ||
restDelta: 0.001, | ||
}); | ||
|
||
const { colorPrimary } = useThemeToken(); | ||
const backgroundColor = color || colorPrimary; | ||
|
||
const style: CSSProperties = { | ||
transformOrigin: '0%', | ||
height, | ||
backgroundColor, | ||
}; | ||
|
||
return <m.div style={{ scaleX, ...style }} {...other} />; | ||
} |
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 |
---|---|---|
@@ -1,43 +1,13 @@ | ||
import { Card, Col, Row } from 'antd'; | ||
import { TabsProps, Tabs } from 'antd'; | ||
|
||
import Scrollbar from '@/components/scrollbar'; | ||
import ScrollbarView from './views/scroll-bar'; | ||
import ScrollProgressView from './views/scroll-progress'; | ||
|
||
const TEXT = `Donec mi odio, faucibus at, scelerisque quis, convallis in, nisi. Quisque ut nisi. | ||
Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Vestibulum eu odio. | ||
Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Cras ultricies mi eu turpis hendrerit fringilla. | ||
Phasellus consectetuer vestibulum elit. Phasellus magna. Nullam tincidunt adipiscing enim. | ||
Vestibulum volutpat pretium libero. Nullam quis ante. Morbi mollis tellus ac sapien. | ||
Donec orci lectus, aliquam ut, faucibus non, euismod id, nulla. | ||
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. | ||
Fusce ac felis sit amet ligula pharetra condimentum. Morbi mattis ullamcorper velit. | ||
Vivamus consectetuer hendrerit lacus. Nullam quis ante. Praesent turpis. | ||
Praesent porttitor, nulla vitae posuere iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum. | ||
Donec mi odio, faucibus at, scelerisque quis, convallis in, nisi. Quisque ut nisi. | ||
Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Vestibulum eu odio. | ||
Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Cras ultricies mi eu turpis hendrerit fringilla. | ||
Phasellus consectetuer vestibulum elit. Phasellus magna. Nullam tincidunt adipiscing enim. Vestibulum volutpat pretium libero. | ||
Nullam quis ante. Morbi mollis tellus ac sapien. Donec orci lectus, aliquam ut, faucibus non, euismod id, nulla. | ||
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. | ||
Fusce ac felis sit amet ligula pharetra condimentum. Morbi mattis ullamcorper velit. | ||
Vivamus consectetuer hendrerit lacus. Nullam quis ante. Praesent turpis. | ||
Praesent porttitor, nulla vitae posuere iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum.`; | ||
export default function Scroll() { | ||
return ( | ||
<Row gutter={20}> | ||
<Col span={12}> | ||
<Card title="Vertical"> | ||
<div className="h-80"> | ||
<Scrollbar>{TEXT}</Scrollbar> | ||
</div> | ||
</Card> | ||
</Col> | ||
<Col span={12}> | ||
<Card title="Horizontal"> | ||
<Scrollbar> | ||
<div style={{ width: '200%' }}>{TEXT}</div> | ||
</Scrollbar> | ||
</Card> | ||
</Col> | ||
</Row> | ||
); | ||
const TABS: TabsProps['items'] = [ | ||
{ key: 'scrollbar', label: 'Scrollbar', children: <ScrollbarView /> }, | ||
{ key: 'scroll-progress', label: 'ScrollProgress', children: <ScrollProgressView /> }, | ||
]; | ||
|
||
return <Tabs items={TABS} />; | ||
} |
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,43 @@ | ||
import { Card, Col, Row } from 'antd'; | ||
|
||
import Scrollbar from '@/components/scrollbar'; | ||
|
||
const TEXT = `Donec mi odio, faucibus at, scelerisque quis, convallis in, nisi. Quisque ut nisi. | ||
Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Vestibulum eu odio. | ||
Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Cras ultricies mi eu turpis hendrerit fringilla. | ||
Phasellus consectetuer vestibulum elit. Phasellus magna. Nullam tincidunt adipiscing enim. | ||
Vestibulum volutpat pretium libero. Nullam quis ante. Morbi mollis tellus ac sapien. | ||
Donec orci lectus, aliquam ut, faucibus non, euismod id, nulla. | ||
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. | ||
Fusce ac felis sit amet ligula pharetra condimentum. Morbi mattis ullamcorper velit. | ||
Vivamus consectetuer hendrerit lacus. Nullam quis ante. Praesent turpis. | ||
Praesent porttitor, nulla vitae posuere iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum. | ||
Donec mi odio, faucibus at, scelerisque quis, convallis in, nisi. Quisque ut nisi. | ||
Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Vestibulum eu odio. | ||
Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Cras ultricies mi eu turpis hendrerit fringilla. | ||
Phasellus consectetuer vestibulum elit. Phasellus magna. Nullam tincidunt adipiscing enim. Vestibulum volutpat pretium libero. | ||
Nullam quis ante. Morbi mollis tellus ac sapien. Donec orci lectus, aliquam ut, faucibus non, euismod id, nulla. | ||
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. | ||
Fusce ac felis sit amet ligula pharetra condimentum. Morbi mattis ullamcorper velit. | ||
Vivamus consectetuer hendrerit lacus. Nullam quis ante. Praesent turpis. | ||
Praesent porttitor, nulla vitae posuere iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum.`; | ||
export default function ScrollbarView() { | ||
return ( | ||
<Row gutter={20}> | ||
<Col span={12}> | ||
<Card title="Vertical"> | ||
<div className="h-80"> | ||
<Scrollbar>{TEXT}</Scrollbar> | ||
</div> | ||
</Card> | ||
</Col> | ||
<Col span={12}> | ||
<Card title="Horizontal"> | ||
<Scrollbar> | ||
<div style={{ width: '200%' }}>{TEXT}</div> | ||
</Scrollbar> | ||
</Card> | ||
</Col> | ||
</Row> | ||
); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/pages/components/scroll/views/scroll-progress/index.tsx
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,40 @@ | ||
import { Card } from 'antd'; | ||
import { useScroll } from 'framer-motion'; | ||
import { useRef } from 'react'; | ||
|
||
import ScrollProgress from '@/components/scroll-progress'; | ||
|
||
const TEXT = `Donec mi odio, faucibus at, scelerisque quis, convallis in, nisi. Quisque ut nisi. | ||
Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Vestibulum eu odio. | ||
Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Cras ultricies mi eu turpis hendrerit fringilla. | ||
Phasellus consectetuer vestibulum elit. Phasellus magna. Nullam tincidunt adipiscing enim. | ||
Vestibulum volutpat pretium libero. Nullam quis ante. Morbi mollis tellus ac sapien. | ||
Donec orci lectus, aliquam ut, faucibus non, euismod id, nulla. | ||
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. | ||
Fusce ac felis sit amet ligula pharetra condimentum. Morbi mattis ullamcorper velit. | ||
Vivamus consectetuer hendrerit lacus. Nullam quis ante. Praesent turpis. | ||
Praesent porttitor, nulla vitae posuere iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum. | ||
Donec mi odio, faucibus at, scelerisque quis, convallis in, nisi. Quisque ut nisi. | ||
Suspendisse nisl elit, rhoncus eget, elementum ac, condimentum eget, diam. Vestibulum eu odio. | ||
Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Cras ultricies mi eu turpis hendrerit fringilla. | ||
Phasellus consectetuer vestibulum elit. Phasellus magna. Nullam tincidunt adipiscing enim. Vestibulum volutpat pretium libero. | ||
Nullam quis ante. Morbi mollis tellus ac sapien. Donec orci lectus, aliquam ut, faucibus non, euismod id, nulla. | ||
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. | ||
Fusce ac felis sit amet ligula pharetra condimentum. Morbi mattis ullamcorper velit. | ||
Vivamus consectetuer hendrerit lacus. Nullam quis ante. Praesent turpis. | ||
Praesent porttitor, nulla vitae posuere iaculis, arcu nisl dignissim dolor, a pretium mi sem ut ipsum.`; | ||
export default function ScrollProgressView() { | ||
const containerRef = useRef<HTMLDivElement | null>(null); | ||
const containerScroll = useScroll({ container: containerRef }); | ||
|
||
return ( | ||
<Card title="ScrollProgress"> | ||
<ScrollProgress scrollYProgress={containerScroll.scrollYProgress} /> | ||
<div ref={containerRef} className="h-80 overflow-auto"> | ||
{[...Array(4)].map((_, index) => ( | ||
<div key={index}>{TEXT}</div> | ||
))} | ||
</div> | ||
</Card> | ||
); | ||
} |
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