百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

thiings-grid

> 编程语言
开源

这是一个高性能的无限滚动网格组件,可为 React 提供基于动量的滚动,实现流畅的触摸/鼠标交互。

386 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

这是一个高性能的无限滚动网格组件,可为 React 提供基于动量的滚动,实现流畅的触摸/鼠标交互。

ThiingsGrid

A high-performance, infinite scrolling grid component for React that provides smooth touch/mouse interactions with momentum-based scrolling. Perfect for displaying large datasets in a grid format with custom cell renderers.

Explore Thiings.co →

This is the component that powers the interactive grid on thiings.co - A growing collection of 1200+ free 3D icons, generated with AI.

Try the Live Playground →

Experience ThiingsGrid in action with interactive examples and copy-paste ready code.

✨ Features

  • High Performance: Only renders visible cells with optimized viewport calculations
  • Touch & Mouse Support: Smooth interactions on both desktop and mobile
  • Momentum Scrolling: Natural physics-based scrolling with inertia
  • ♾️ Infinite Grid: Supports unlimited grid sizes with efficient rendering
  • Custom Renderers: Flexible cell rendering with your own components
  • TypeScript Support: Full type safety with comprehensive TypeScript definitions

Quick Start

Installation

This component is currently part of this repository. To use it in your project:

  1. Copy the lib/ThiingsGrid.tsx file to your project
  2. Install the required dependencies:
bash
npm install react react-dom

Basic Usage

typescript
import ThiingsGrid, { type ItemConfig } from './path/to/ThiingsGrid';

const MyCell = ({ gridIndex, position }: ItemConfig) => (
  

);

const App = () => (
  

);

API Reference

ThiingsGridProps

Prop Type Required Default Description
gridSize number ✅ - Size of each grid cell in pixels
renderItem (config: ItemConfig) => ReactNode ✅ - Function to render each grid cell
className string ❌ - CSS class name for the container
initialPosition Position ❌ { x: 0, y: 0 } Initial scroll position

ItemConfig

The renderItem function receives an ItemConfig object with:

Property Type Description
gridIndex number Unique index for the grid cell
position Position Grid coordinates { x: number, y: number }
isMoving boolean Whether the grid is currently being moved/scrolled

Position

typescript
type Position = {
  x: number;
  y: number;
};

Examples

Simple Numbers

typescript
import ThiingsGrid, { type ItemConfig } from "./ThiingsGrid";

const SimpleNumberCell = ({ gridIndex }: ItemConfig) => (
  

);

export const SimpleNumbers = () => (
  
);

Colorful Grid

typescript
const ColorfulCell = ({ gridIndex }: ItemConfig) => {
  const colors = [
    "bg-red-300",
    "bg-green-300", 
    "bg-blue-300",
    "bg-yellow-300",
    "bg-pink-300",
    "bg-cyan-300",
  ];
  const colorClass = colors[gridIndex % colors.length];

  return (
    

  );
};

export const ColorfulGrid = () => (
  
);

Interactive Cards

typescript
const CardCell = ({ gridIndex, position, isMoving }: ItemConfig) => (
  

    

  
);

export const CardLayout = () => (
  
);

Best Practices

Cell Positioning

Always use absolute positioning within your cell components for optimal performance:

typescript
// ✅ Good
const MyCell = ({ gridIndex }: ItemConfig) => (
  

);

// ❌ Avoid - can cause layout issues
const MyCell = ({ gridIndex }: ItemConfig) => (
  

);

Performance Optimization

For better performance with complex cells:

typescript
const OptimizedCell = React.memo(({ gridIndex, isMoving }: ItemConfig) => {
  // Expensive calculations here
  const computedValue = useMemo(() => {
    return expensiveCalculation(gridIndex);
  }, [gridIndex]);

  return (
    

  );
});

Container Setup

Ensure the ThiingsGrid has a defined container size:

typescript
// ✅ Good - explicit container size

// ✅ Good - CSS classes with defined dimensions

Advanced Usage

Custom Grid Index Calculation

The gridIndex is calculated based on the grid position using a custom algorithm that provides unique indices for each cell position.

Accessing Grid Position

You can access the current grid position programmatically:

typescript
const MyComponent = () => {
  const gridRef = useRef(null);

  const getCurrentPosition = () => {
    if (gridRef.current) {
      const position = gridRef.current.publicGetCurrentPosition();
      console.log('Current position:', position);
    }
  };

  return (
    
  );
};

Responsive Grid Sizes

typescript
const useResponsiveGridSize = () => {
  const [gridSize, setGridSize] = useState(80);

  useEffect(() => {
    const handleResize = () => {
      const width = window.innerWidth;
      if (width  window.removeEventListener('resize', handleResize);
  }, []);

  return gridSize;
};

const ResponsiveGrid = () => {
  const gridSize = useResponsiveGridSize();
  
  return (
    
  );
};

Interaction

Touch/Mouse Events

The component handles:

  • Mouse: Click and drag to pan
  • Touch: Touch and drag to pan
  • Wheel: Scroll wheel for precise movements
  • Momentum: Automatic momentum scrolling with physics

Development

Running the Demo

bash
# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

Project Structure

src/
├── examples/           # Example implementations
│   ├── SimpleNumbers.tsx
│   ├── ColorfulGrid.tsx
│   ├── EmojiFun.tsx
│   └── CardLayout.tsx
├── App.tsx            # Main demo application
├── Playground.tsx     # Example viewer
├── SourceCode.tsx     # Source code display
└── Sidebar.tsx        # Example navigation

lib/
└── ThiingsGrid.tsx    # Main component

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with React and TypeScript
  • Styled with Tailwind CSS
  • Bundled with Vite

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言