@antmjs/vantui

repository·main·Indexed 21 days ago

https://github.com/antmjs/vantui

A React-based UI library for Taro that brings the VantWeapp component ecosystem to cross-platform mobile development, supporting H5 and various Mini Programs (WeChat, Alipay, Douyin, Kuaishou, and Baidu). The package includes a set of UI components such as ActionSheet, Area, Badge, Button, and Calendar, as well as a build tool called Vantui Cli and a project template called vantui-demo.

Tokens
199.9K
Snippets
616
Records
801
Agent score
73%

What's inside @antmjs/vantui

  1. Overview of @antmjs/vantui

    main

    @antmjs/vantui is a UI component library developed based on Youzan's VantWeapp. It is designed to support Taro and React environments, allowing developers to use Vant-style components in cross-platform mobile applications.

    Key Features

    • High Consistency: Maintains 99% of the original style files and most JS logic from VantWeapp to ensure a familiar API and UI.
    • TypeScript Support: Written in TypeScript with full type definitions provided.
    • Cross-Platform: Supports Taro targets including H5, WeChat Mini Program, Alipay Mini Program, and Douyin Mini Program. (Note: React Native is not supported).
    • Rich Component Set: Includes over 50 high-quality components covering mainstream mobile scenarios.
    • Customization: Supports theme customization and on-demand loading (tree shaking).
  2. Features and developer efficiency in vantui-demo

    main

    The vantui-demo template is optimized for development speed and code quality through several integrated tools:

    Code Standards

    • Linting: Integrated prettier, eslint, and stylelint for code formatting and quality.
    • Commit Standards: Integrated commitlint and commitizen to enforce commit message conventions.
    • Pre-commit Hooks: Uses husky and lint-staged to automatically validate code standards before every commit.

    Development Efficiency

    • Type Safety: Uses the Unite library to prioritize development speed while maintaining TypeScript safety.
    • Automated Action Layer:
      • Uses @antmjs/rapper to automatically generate action logic based on TypeScript types.
      • Supports yarn swagger to generate action logic directly from server-side Swagger APIs.
    • Automated Utilities:
      • Automatic event tracking (埋点).
      • Automatic exception collection and handling.
      • Automatic handling of pullDownloadRefresh.
    • UI/UX Helpers:
      • Quick implementation of custom navigation.
      • Built-in support for event debouncing.
      • Second-layer encapsulation of frequently used components.
  3. Use the Picker component

    main

    The Picker component is a selector used for choosing values from a list. It supports single-column selection and multi-column linkage (cascading). It can be used in two modes:

    • normal: The standard flat list display.
    • content: Displays the currently selected content; clicking it opens the picker.

    Common use cases include:

    • Basic usage: Simple list selection.
    • Complex data: Using valueKey to specify the text field and idKey for the actual value.
    • Multi-column linkage: Using syncColumns for asynchronous data fetching between columns (only supported in content mode).
    • Disabled options: Passing objects with a disabled: true property to prevent selection.
  4. Use the Dialog component

    main

    The Dialog component is a modal popup used for message alerts, confirmations, or specific interactive operations within the current page. It supports two usage patterns: functional calls (calling a function to trigger the dialog) and component calls (using the component directly in your template/JSX).

    Important Version Note:

    • In versions below 1.8.0, clicking the cancel button triggers the catch block of the returned Promise.
    • In versions 1.8.0 and later, clicking the cancel button triggers the then block. You must check the returned value (which will be 'confirm' or 'cancel') to determine the user's action.
    import { Dialog } from '@antmjs/vantui'
  5. Use TreeSelect for category selection

    main

    The TreeSelect component allows users to select items from a hierarchical structure. It features a two-pane layout: a left-side navigation menu and a right-side content area displaying items. It supports both single-selection and multi-selection modes based on how the activeId prop is provided.

    <TreeSelect
      items={items}
      mainActiveIndex={state.mainActiveIndex}
      activeId={state.activeId}
      onClickNav={onClickNav}
      onClickItem={onClickItem}
    />
  6. Use the DatetimePicker component

    main

    The DatetimePicker component is used for selecting time, supporting various dimensions such as date, hours, and minutes. It is typically used in conjunction with a Popup component to create a time-selection dialog.

    Note on Version 3.5+ Behavior: Due to the introduction of mode='content' in the underlying picker, DatetimePicker has been adapted. In this mode, onInput is triggered upon confirmation, and the value can support string formats. For the standard flat mode, onConfirm outputs values in the YYYY-MM-DD HH:mm:ss format. You can use the formatValue prop to modify this output (e.g., to return a timestamp instead).

    import { DatetimePicker } from '@antmjs/vantui'