# Arco Design Mobile
Arco Design Mobile is a comprehensive React UI component library designed specifically for mobile H5 and WebView environments. Built on TypeScript and Less, it provides 50+ production-ready components that follow the Arco Design system principles with pixel-perfect restoration and optimized touch interactions. The library has been battle-tested in high-traffic online environments and offers features like server-side rendering, internationalization, on-demand imports, and theme customization.
The library uses rem-based responsive design (base font size: 50px) and requires a flexible.js implementation or similar tool to dynamically set the root font size based on screen dimensions. Components are organized in a monorepo structure using Lerna, with the main package published as `@arco-design/mobile-react`. The architecture supports both ESM and CommonJS module formats, enabling flexible integration patterns including tree-shaking for optimal bundle sizes.
## Installation and Setup
### Installing the Package
```bash
npm install @arco-design/mobile-react
# or
yarn add @arco-design/mobile-react
```
### Configuring Responsive Scaling
```javascript
import setRootPixel from '@arco-design/mobile-react/tools/flexible';
// Initialize with default settings (baseFontSize: 50, sketchWidth: 375, maxFontSize: 64)
setRootPixel();
// Or customize settings
const removeRootPixel = setRootPixel(37.5); // Custom base font size
// Later, if needed, remove the listener
removeRootPixel();
```
### Babel Plugin for Tree-Shaking (Webpack/Babel)
```javascript
// .babelrc.js or babel.config.js
module.exports = {
plugins: [
["import", {
"libraryName": "@arco-design/mobile-react",
"libraryDirectory": "esm", // Use "cjs" for SSR
"style": (path) => `${path}/style`
}, "@arco-design/mobile-react"],
["import", {
"libraryName": "@arco-design/mobile-react/esm/icon",
"libraryDirectory": "",
"camel2DashComponentName": false
}, "@arco-design/mobile-react/esm/icon"]
]
};
```
### Vite Plugin for Tree-Shaking
```javascript
// vite.config.ts
import { defineConfig } from 'vite';
import usePluginImport from 'vite-plugin-importer';
export default defineConfig({
plugins: [
usePluginImport({
libraryName: "@arco-design/mobile-react",
libraryDirectory: "esm",
style: (path) => `${path}/style`,
}),
usePluginImport({
libraryName: "@arco-design/mobile-react/esm/icon",
libraryDirectory: "",
camel2DashComponentName: false,
})
]
});
```
## Button Component
### Basic Button Usage
```typescript
import React from 'react';
import ReactDOM from 'react-dom';
import Button from '@arco-design/mobile-react/esm/button';
import '@arco-design/mobile-react/esm/button/style';
function ButtonExample() {
const handleClick = (e) => {
console.log('Button clicked', e);
};
const handleDisabledClick = (e) => {
console.log('Disabled button clicked', e);
};
return (
);
}
export default ActionSheetExample;
```
## Context Provider (Global Configuration)
### Theme and Locale Configuration
```typescript
import React from 'react';
import { ContextProvider } from '@arco-design/mobile-react/esm/context-provider';
import enUS from '@arco-design/mobile-react/esm/locale/en-US';
import zhCN from '@arco-design/mobile-react/esm/locale/zh-CN';
import Button from '@arco-design/mobile-react/esm/button';
import Dialog from '@arco-design/mobile-react/esm/dialog';
function App() {
const [isDark, setIsDark] = React.useState(false);
const [locale, setLocale] = React.useState(enUS);
return (
{
console.log('Dark mode changed:', isDarkMode);
}}
>
);
}
export default App;
```
## Summary
Arco Design Mobile serves as a production-ready solution for building mobile-first web applications with React. Its component library covers all essential UI patterns from basic elements (buttons, inputs) to complex interactions (pickers, tabs, forms). Each component is designed with mobile touch interactions in mind, offering smooth animations, gesture support, and responsive layouts. The library's architecture supports multiple integration methods including full imports for rapid prototyping and tree-shaking for optimized production builds.
The framework excels in enterprise scenarios requiring consistent design systems, internationalization support, and theme customization. Components like Form provide comprehensive validation APIs, while Dialog and Toast offer both imperative and declarative usage patterns. The ContextProvider enables global configuration for themes, locales, and platform-specific behaviors. With built-in TypeScript support, SSR compatibility, and extensive customization options through Less variables and CSS variables, Arco Design Mobile provides developers with the flexibility to build scalable mobile applications while maintaining design consistency across different platforms and devices.