Skip to content

Commit

Permalink
feat: scrollbar component
Browse files Browse the repository at this point in the history
  • Loading branch information
d3george committed Sep 17, 2023
1 parent cb58b90 commit 6bdf461
Show file tree
Hide file tree
Showing 9 changed files with 490 additions and 337 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"react-icons": "^4.10.1",
"react-router-dom": "^6.13.0",
"screenfull": "^6.0.2",
"simplebar-react": "^3.2.4",
"vite": "^4.3.9",
"zustand": "^4.3.8"
},
Expand Down
745 changes: 411 additions & 334 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/components/scrollbar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { forwardRef, memo } from 'react';
import SimpleBar, { Props as SimplebarProps } from 'simplebar-react';

/**
* https://www.npmjs.com/package/simplebar-react?activeTab=readme
*/
const Scrollbar = forwardRef<HTMLElement, SimplebarProps>(({ children, ...other }, ref) => {
return (
<SimpleBar scrollableNodeProps={{ ref }} {...other} clickOnTrack={false} className="h-full">
{children}
</SimpleBar>
);
});

export default memo(Scrollbar);
4 changes: 3 additions & 1 deletion src/layouts/dashboard/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default function Main() {
<Content className="px-4">
{/* <!-- ===== Content Start ===== --> */}
<BreadCrumb />
<div className={`mx-auto h-full w-full sm:px-2 ${themeStretch ? '' : 'xl:max-w-screen-xl'}`}>
<div
className={`mx-auto h-full w-full pt-4 sm:px-2 ${themeStretch ? '' : 'xl:max-w-screen-xl'}`}
>
<Outlet />
</div>
{/* <!-- ===== Content End ===== --> */}
Expand Down
3 changes: 2 additions & 1 deletion src/locales/lang/en/sys.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"user": "User",
"blog": "Blog",
"components": "Components",
"animate": "Animate"
"animate": "Animate",
"scroll": "Scroll"
}
}
}
3 changes: 2 additions & 1 deletion src/locales/lang/zh-CN/sys.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"user": "用户",
"blog": "博客",
"components": "组件",
"animate": "动画"
"animate": "动画",
"scroll": "滚动"
}
}
}
7 changes: 7 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
// react-query
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
// react
import { Suspense } from 'react';
import ReactDOM from 'react-dom/client';
// react helmet
import { HelmetProvider } from 'react-helmet-async';
// simplebar
import 'simplebar-react/dist/simplebar.min.css';
// eslint-disable-next-line import/no-unresolved
import 'virtual:svg-icons-register';

import App from '@/App';

// i18n
import './locales/i18n';
// tailwind css
import './theme/index.css';

// 创建一个 client
Expand Down
43 changes: 43 additions & 0 deletions src/pages/components/scroll/index.tsx
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 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>
);
}
6 changes: 6 additions & 0 deletions src/router/routes/modules/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Suspense, lazy } from 'react';
import { Navigate, Outlet } from 'react-router-dom';

import Loading from '@/components/loading';
import Scroll from '@/pages/components/scroll';

import { AppRouteObject } from '#/router';

Expand All @@ -26,6 +27,11 @@ const components: AppRouteObject = {
element: <Animate />,
meta: { title: 'sys.menu.animate', icon: 'ic-user', key: '/components/animate' },
},
{
path: 'scroll',
element: <Scroll />,
meta: { title: 'sys.menu.scroll', icon: 'ic-user', key: '/components/scroll' },
},
],
};

Expand Down

0 comments on commit 6bdf461

Please sign in to comment.