How weui/react-weui works
1. What this repo is
- react-weui is a React component library that wraps the WeUI design system.
- There is no backend or server-side business domain here; the architecture is centered on reusable UI components, styling, docs, examples, and tests.
2. Public library boundary
- The main package entry is src/index.js.
- That file re-exports the component surface area from src/components/**, so consumers import from the package root rather than internal files.
- src/version.js holds package version metadata used by the build/runtime surface.
3. Component subsystem structure
- The library is organized by component family under src/components/.
- Each component typically has:
- a main React component file,
- an index.js barrel export,
- and sometimes a .less stylesheet.
- The structure is intentionally granular: many components are split into small internal pieces such as button_area, button_preview, panel_header, tabbar_item, mediabox_info_meta, etc.
4. Design of the UI layer
- Components are mostly presentational React components that compose smaller building blocks into WeUI patterns.
- Examples of composite areas include:
- form/ for inputs, toggles, uploader, validation-related controls,
- cell/, panel/, and mediabox/ for grouped list/content layouts,
- tab/ and swiper/ for navigation and page switching patterns,
- popup/, dialog/, toast/, toptips/, and mask/ for overlays and notifications.
5. Styling and asset boundary
- Styling is split between:
- package-local styles in src/components/**.less,
- and external base styles from WeUI itself.
- The README’s example explicitly imports both weui and react-weui CSS, which means the library depends on the external WeUI stylesheet as part of its rendering contract.
- The build outputs a distributable CSS bundle referenced as build/packages/react-weui.css.
6. Utilities and shared behavior
- src/utils/ contains cross-cutting helpers such as:
- classnames.js for class name composition,
- deprecationWarning.js for runtime warnings around legacy APIs.
- These utilities support consistency across component implementations rather than introducing a separate domain layer.
7. Docs site subsystem
- The docs/ directory is a separate documentation application built from React components and markdown content.
- It includes:
- page containers in docs/pages/,
- UI chrome in docs/components/,
- guide content in docs/guide/,
- generated metadata like docs/docs.json and docs/langs.json.
- This site powers the live documentation and component previews, so it is a consumer of the library rather than part of the library runtime.
8. Example application subsystem
- The example/ directory is a second consumer app that demonstrates real usage patterns.
- It contains many page-level demos for specific components such as button, dialog, picker, tab, toast, uploader, etc.
- This folder is useful for understanding the integration boundary: it shows how the exported components are composed into app screens.
9. Testing strategy
- test/ contains per-component unit tests that largely mirror the src/components/ tree.
- The test suite includes shared setup (test/setup.js) and Mocha config (test/mocha.opts).
- This indicates the primary validation strategy is component-level rendering/behavior testing, not end-to-end system testing.
10. Build and packaging pipeline
- webpack.config.js builds the library package, while webpack.config.doc.js builds the documentation app.
- scripts/build.js is the build orchestration entry.
- Babel, ESLint, and the webpack configs define the compile boundary from source React/JS/LESS into distributable assets.
- The repo is packaged for npm, with CI/publish automation in .github/workflows/, plus legacy Travis config.
11. External dependencies and runtime assumptions
- The runtime assumes a browser React environment with react and react-dom.
- The library is paired with the external weui package for visual styling and theme alignment.
- Distribution is designed for both npm installation and CDN consumption, which is why the build artifacts are important public outputs.
12. How to think about the architecture diagram
- Draw the repo as three main consumers of the same component source:
- the library package (src/ → built npm/CSS artifacts),
- the documentation site (docs/),
- and the example app (example/).
- Put src/components/** at the center, with src/index.js as the public API boundary.
- Add a side layer for shared utilities and styling, and a separate validation layer for tests.
Main entry points: components Components · index.js Package API · pages Docs pages · app.js Docs app
Components 19
Library package
Reusable React components and public npm surface.
- Package API · Public package entry that re-exports the component surface.
src/index.js - Version · Package version metadata used by the public surface.
src/version.js - Components · Core WeUI-flavored React component families.
src/components - Layout blocks · Grouped content and structural primitives like cell, panel, mediabox, and footer.
src/components - Form controls · Interactive form, picker, and validation controls.
src/components/form - Overlays · Dialogs, popups, toasts, tips, masks, and related transient UI.
src/components - Navigation · Tabs, swiper, search, and page-level navigation patterns.
src/components - Media views · Button, grid, gallery, icon, message, progress, and loading views.
src/components - Shared utils · Cross-cutting helpers for class names and deprecation warnings.
src/utils - Stylesheets · Component LESS files and dependency on external WeUI CSS.
src/components
Consumer apps
Documentation site and example app that consume the component library.
- Docs app · React documentation application built from pages, guides, and preview chrome.
docs/app.js - Docs pages · Page containers and routing for the documentation experience.
docs/pages - Preview chrome · Documentation UI components used to render demos and navigation.
docs/components - Guides · Markdown guide content for getting started and component docs.
docs/guide - Example app · Standalone demo app showing real usage patterns for the library.
example/app.js - Demo pages · Component-specific demo screens and usage scenarios.
example/pages
Build and validation
Tooling, tests, and packaging around the source tree.
- Build pipeline · Webpack, scripts, Babel, and packaging orchestration.
scripts/build.js - Tests · Per-component unit tests and shared test setup.
test - CI and publish · Repository workflows and release automation.
.github/workflows
Connections 20
- Package API → Components: re-exports · Public API exposes the component families.
- Package API → Version: publishes · Package entry includes version metadata.
- Components → Layout blocks: includes · Structural components for grouped content layouts.
- Components → Form controls: includes · Input, picker, and form-related controls.
- Components → Overlays: includes · Transient overlays and feedback surfaces.
- Components → Navigation: includes · Navigation and switching patterns.
- Components → Media views: includes · Display and content-oriented component families.
- Components → Shared utils: uses · Shared helper functions support component implementation.
- Components → Stylesheets: styled by · Component behavior is paired with package-local LESS and external WeUI CSS.
- Docs app → Docs pages: renders · Documentation shell is composed from page containers.
- Docs app → Preview chrome: uses · Docs UI chrome renders previews and navigation.
- Docs pages → Package API: consumes · Docs import the package surface for live examples.
- Docs pages → Guides: loads · Guide pages are built from markdown content.
- Example app → Demo pages: navigates · Example shell hosts many component demo pages.
- Demo pages → Package API: consumes · Demos use the public library entrypoint.
- Build pipeline → Package API: builds · Bundling compiles the source package into distributable artifacts.
- Build pipeline → Docs app: builds · Separate webpack config builds the documentation app.
- Tests → Components: verifies · Component tests mirror the source tree for behavior and rendering.
- CI and publish → Build pipeline: automates · Workflows run build and release steps.
- CI and publish → Tests: automates · Workflows validate the library before publish.