WeUI for 小程序 (WeUI for Mini Programs)

repository·master·Indexed 12 days ago

https://github.com/tencent/weui-wxss

A pure UI style library designed by the official WeChat design team to provide a consistent visual experience for WeChat Mini Programs. Version 2.6.26 provides ready-to-use WXSS styles for common elements like buttons, cells, dialogs, and toasts, including support for rpx responsive scaling and dark mode.

Tokens
1.4K
Snippets
7
Records
9
Agent score
47%

What's inside WeUI

  1. Differences in selector usage between WeUI and WeUI for 小程序

    master

    Because WeChat Mini Programs (小程序) have limitations regarding certain CSS selectors, you cannot use standard Web WeUI patterns. Specifically, adjacent sibling selectors and descendant (cascading) selectors are not supported. Instead, you must use specific modifier classes to achieve the same styling.

    Replacing Adjacent Sibling Selectors

    Instead of using + (e.g., .weui-cells__title + .weui-cells), apply a specific modifier class directly to the target element.

    • Pattern: .weui-cells__title + .weui-cells $\rightarrow$ .weui-cells_after-title on the .weui-cells element.

    Replacing Descendant Selectors

    Instead of nesting styles via parent-child relationships (e.g., .weui-cell_access .weui-cell__ft), apply a modifier class to the child element that indicates its context.

    • Pattern: .weui-cell_access .weui-cell__ft $\rightarrow$ .weui-cell__ft_in-access on the .weui-cell__ft element.
    • Pattern: .weui-cells_radio .weui-cell__ft $\rightarrow$ .weui-cell__ft_in-radio on the .weui-cell__ft element.
    <!-- Example: Replacing Descendant Selectors -->
    <view class="weui-cell weui-cell_access">
        <view class="weui-cell__ft weui-cell__ft_in-access"></view>
    </view>
  2. Use Mini Program components for Icons and Buttons

    master

    When using WeUI for 小程序, replace standard HTML elements with their Mini Program equivalents:

    Icons

    Use the Mini Program <icon> component. Because the native icon component has a font-size: 0 property, you may need to use specific utility classes to control margins/spacing, such as .weui-icon-radio or .weui-icon-checkbox_circle.

    Buttons

    Use the Mini Program <button> component. The .weui-btn class is used to control spacing, while the button type (e.g., primary) is set via the type attribute.

    Comparison:

    • Web: <a class="weui-btn weui-btn_primary">...</a>
    • Mini Program: <button class="weui-btn" type="primary">...</button>
    <!-- Button Example -->
    <button class="weui-btn" type="primary">页面主操作 Normal</button>
  3. Use WeUI for 小程序 in your project

    master

    WeUI for 小程序 is a pure UI library providing styles that match the native WeChat visual experience. It includes elements like button, cell, dialog, progress, toast, article, actionsheet, and icon.

    To use the library:

    1. Import Styles: You can reference the global style file at dist/style/weui.wxss or import individual component styles located in dist/style/widget/.
    2. Implement Structure: For the required WXML structure of each component, refer to the examples provided in the dist/example/ directory.
    <!-- Reference global styles in your .wxss file -->
    @import '/path/to/weui-wxss/dist/style/weui.wxss';
  4. Configure `.weui-input` with `.weui-cell_input`

    master

    Due to differences in how the virtual keyboard affects layout height in Mini Programs, standard .weui-input implementations require an additional modifier class on the parent cell to ensure correct spacing and alignment.

    Requirement: When using an <input class="weui-input" />, you must add the .weui-cell_input class to the parent <view class="weui-cell"> element.

    <view class="weui-cell weui-cell_input">
        <view class="weui-cell__bd">
            <input class="weui-input" />
        </view>
    </view>
  5. Implement active states for `weui-cell_access`

    master

    In standard WeUI, :active pseudo-classes are used for click states. In Mini Programs, you should use the hover-class attribute of the <navigator> component to trigger the .weui-cell_active class.

    Implementation: Apply hover-class="weui-cell_active" to your <navigator> component to handle the visual feedback for cell access items.

    <navigator url="" class="weui-cell weui-cell_access" hover-class="weui-cell_active">
        <view class="weui-cell__bd">cell standard</view>
        <view class="weui-cell__ft weui-cell__ft_with-access">说明文字</view>
    </navigator>
  6. Configure project settings in project.private.config.json

    master

    The project.private.config.json file is used to define private project configurations that override the standard project.config.json. Settings defined here are intended for local development environments and are prioritized over the main configuration file.

    In this repository, the setting object includes:

    • compileHotReLoad: A boolean flag that enables hot reloading during compilation to speed up the development workflow.
    {
      "projectname": "weui-wxss",
      "setting": {
        "compileHotReLoad": true
      }
    }