Loading...
Loading...
Compare original and translation side by side
npm install @korsolutions/uinpm install @korsolutions/uiundefinedundefinedUIProviderimport { UIProvider } from "@korsolutions/ui";
import { useSafeAreaInsets } from "react-native-safe-area-context";
export default function RootLayout() {
const safeAreaInsets = useSafeAreaInsets();
return (
<UIProvider safeAreaInsets={safeAreaInsets}>
<YourApp />
</UIProvider>
);
}UIProviderimport { UIProvider } from "@korsolutions/ui";
import { useSafeAreaInsets } from "react-native-safe-area-context";
export default function RootLayout() {
const safeAreaInsets = useSafeAreaInsets();
return (
<UIProvider safeAreaInsets={safeAreaInsets}>
<YourApp />
</UIProvider>
);
}import { Button, Input, Card } from "@korsolutions/ui";
function MyComponent() {
return (
<Card.Root>
<Card.Body>
<Button onPress={() => console.log("Pressed")}>
Click Me
</Button>
</Card.Body>
</Card.Root>
);
}import { Button, Input, Card } from "@korsolutions/ui";
function MyComponent() {
return (
<Card.Root>
<Card.Body>
<Button onPress={() => console.log("Pressed")}>
Click Me
</Button>
</Card.Body>
</Card.Root>
);
}import { useState } from "react";
import { Button } from "@korsolutions/ui";
function SubmitButton() {
const [loading, setLoading] = useState(false);
const handleSubmit = async () => {
setLoading(true);
await submitForm();
setLoading(false);
};
return (
<Button variant="default" isLoading={loading} onPress={handleSubmit}>
Submit
</Button>
);
}import { useState } from "react";
import { Button } from "@korsolutions/ui";
function SubmitButton() {
const [loading, setLoading] = useState(false);
const handleSubmit = async () => {
setLoading(true);
await submitForm();
setLoading(false);
};
return (
<Button variant="default" isLoading={loading} onPress={handleSubmit}>
Submit
</Button>
);
}| Component | Description | Variants | Reference |
|---|---|---|---|
| Card | Content container with header, body, and footer | default | Layout Components |
| Separator | Visual divider between content | horizontal, vertical | Layout Components |
| ScrollBar | Custom scrollbar styling | default | Layout Components |
| Portal | Render components outside hierarchy | - | Layout Components |
| List | Performance-optimized list rendering | - | Layout Components |
| 组件 | 描述 | 变体 | 参考文档 |
|---|---|---|---|
| Card | 包含页眉、正文和页脚的内容容器 | default | 布局组件 |
| Separator | 内容间的视觉分隔线 | horizontal, vertical | 布局组件 |
| ScrollBar | 自定义滚动条样式 | default | 布局组件 |
| Portal | 在组件层级外渲染内容 | - | 布局组件 |
| List | 性能优化的列表渲染 | - | 布局组件 |
| Component | Description | Variants | Reference |
|---|---|---|---|
| Input | Text input field | default | Input Components |
| NumericInput | Formatted numeric input (currency, percentage, etc.) | default | Input Components |
| PhoneInput | Phone number input with country selector (E.164) | default | Input Components |
| Textarea | Multi-line text input | default | Input Components |
| Checkbox | Toggle selection with label | default | Input Components |
| Select | Dropdown selection from a list of options | default | Input Components |
| Combobox | Autocomplete input with filterable dropdown | default | Input Components |
| Field | Form field wrapper with label and validation | - | Input Components |
| 组件 | 描述 | 变体 | 参考文档 |
|---|---|---|---|
| Input | 文本输入框 | default | 输入组件 |
| NumericInput | 格式化数值输入框(货币、百分比等) | default | 输入组件 |
| PhoneInput | 带国家选择器的电话号码输入框(遵循E.164标准) | default | 输入组件 |
| Textarea | 多行文本输入框 | default | 输入组件 |
| Checkbox | 带标签的切换选择框 | default | 输入组件 |
| Select | 下拉选择框 | default | 输入组件 |
| Combobox | 带自动补全的可筛选下拉输入框 | default | 输入组件 |
| Field | 包含标签和验证的表单字段包装器 | - | 输入组件 |
| Component | Description | Variants | Reference |
|---|---|---|---|
| Typography | Text with semantic variants | heading-xs to 3xl, body-xs to lg, label, code, caption | Display Components |
| Avatar | User avatar with image and fallback | default | Display Components |
| Badge | Status indicators and labels | default, secondary, success, warning, danger, info | Display Components |
| Icon | Icon rendering with render prop pattern | - | Display Components |
| Empty | Empty state placeholders | default | Display Components |
| Progress | Linear progress indicators | default | Display Components |
| 组件 | 描述 | 变体 | 参考文档 |
|---|---|---|---|
| Typography | 带语义变体的文本组件 | heading-xs to 3xl, body-xs to lg, label, code, caption | 展示组件 |
| Avatar | 带图片和回退样式的用户头像 | default | 展示组件 |
| Badge | 状态指示器和标签 | default, secondary, success, warning, danger, info | 展示组件 |
| Icon | 采用渲染属性模式的图标组件 | - | 展示组件 |
| Empty | 空状态占位符 | default | 展示组件 |
| Progress | 线性进度指示器 | default | 展示组件 |
| Component | Description | Variants | Reference |
|---|---|---|---|
| Button | Action buttons with loading states | default, secondary, ghost | Interactive Components |
| IconButton | Icon-only pressable button | default, secondary, ghost | Interactive Components |
| Tabs | Tabbed navigation | default, line | Interactive Components |
| Menu | Dropdown menus | default | Interactive Components |
| Popover | Positioned overlay content | default | Interactive Components |
| Calendar | Date picker with range selection | default | Interactive Components |
| 组件 | 描述 | 变体 | 参考文档 |
|---|---|---|---|
| Button | 带加载状态的操作按钮 | default, secondary, ghost | 交互组件 |
| IconButton | 仅含图标的可点击按钮 | default, secondary, ghost | 交互组件 |
| Tabs | 标签式导航 | default, line | 交互组件 |
| Menu | 下拉菜单 | default | 交互组件 |
| Popover | 定位式浮层内容 | default | 交互组件 |
| Calendar | 支持范围选择的日期选择器 | default | 交互组件 |
| Component | Description | Variants | Reference |
|---|---|---|---|
| Alert | Inline notifications with icons | default, destructive | Feedback Components |
| AlertDialog | Modal confirmation dialogs | default | Feedback Components |
| Toast | Transient notifications | default, success, danger | Feedback Components |
| 组件 | 描述 | 变体 | 参考文档 |
|---|---|---|---|
| Alert | 带图标的内联通知 | default, destructive | 反馈组件 |
| AlertDialog | 模态确认对话框 | default | 反馈组件 |
| Toast | 临时通知 | default, success, danger | 反馈组件 |
RootRoot<Component.Root {...rootProps}>
<Component.SubComponent1 {...props} />
<Component.SubComponent2 {...props} />
</Component.Root><Component.Root {...rootProps}>
<Component.SubComponent1 {...props} />
<Component.SubComponent2 {...props} />
</Component.Root><Button variant="default" onPress={handlePress} isLoading={loading}>
Submit Form
</Button><Button variant="default" onPress={handlePress} isLoading={loading}>
Submit Form
</Button>import { AlertCircle } from "lucide-react-native";
<Alert.Root variant="destructive">
<Alert.Icon render={AlertCircle} />
<Alert.Body>
<Alert.Title>Error</Alert.Title>
<Alert.Description>Something went wrong</Alert.Description>
</Alert.Body>
</Alert.Root>;import { AlertCircle } from "lucide-react-native";
<Alert.Root variant="destructive">
<Alert.Icon render={AlertCircle} />
<Alert.Body>
<Alert.Title>Error</Alert.Title>
<Alert.Description>Something went wrong</Alert.Description>
</Alert.Body>
</Alert.Root>;<Field.Root>
<Field.Label for="email">Email Address</Field.Label>
<Input id="email" value={email} onChange={setEmail} placeholder="you@example.com" />
<Field.Description>We'll never share your email.</Field.Description>
{error && <Field.Error>{error}</Field.Error>}
</Field.Root><Field.Root>
<Field.Label for="email">Email Address</Field.Label>
<Input id="email" value={email} onChange={setEmail} placeholder="you@example.com" />
<Field.Description>We'll never share your email.</Field.Description>
{error && <Field.Error>{error}</Field.Error>}
</Field.Root>;// Variant styles are applied first
<Button style={{ marginTop: 16 }}>
Custom Button
</Button>// 先应用变体样式
<Button style={{ marginTop: 16 }}>
Custom Button
</Button>import { useTheme } from "@korsolutions/ui";
function MyComponent() {
const theme = useTheme();
return (
<View
style={{
backgroundColor: theme.colors.background,
borderRadius: theme.radius,
padding: 16,
}}
>
<Text
style={{
color: theme.colors.foreground,
fontSize: theme.fontSize,
fontFamily: theme.fontFamily,
}}
>
Themed Content
</Text>
</View>
);
}import { useTheme } from "@korsolutions/ui";
function MyComponent() {
const theme = useTheme();
return (
<View
style={{
backgroundColor: theme.colors.background,
borderRadius: theme.radius,
padding: 16,
}}
>
<Text
style={{
color: theme.colors.foreground,
fontSize: theme.fontSize,
fontFamily: theme.fontFamily,
}}
>
Themed Content
</Text>
</View>
);
}const theme = useTheme();
// Get current scheme
console.log(theme.colorScheme); // "light" | "dark"
// Set color scheme
theme.setColorScheme("dark");const theme = useTheme();
// 获取当前配色方案
console.log(theme.colorScheme); // "light" | "dark"
// 设置配色方案
theme.setColorScheme("dark");<UIProvider
theme={{
radius: 12,
fontSize: 18,
colors: {
light: {
primary: "hsla(220, 90%, 56%, 1)",
primaryForeground: "hsla(0, 0%, 100%, 1)",
},
dark: {
primary: "hsla(220, 90%, 70%, 1)",
primaryForeground: "hsla(0, 0%, 100%, 1)",
},
},
}}
safeAreaInsets={safeAreaInsets}
>
<App />
</UIProvider><UIProvider
theme={{
radius: 12,
fontSize: 18,
colors: {
light: {
primary: "hsla(220, 90%, 56%, 1)",
primaryForeground: "hsla(0, 0%, 100%, 1)",
},
dark: {
primary: "hsla(220, 90%, 70%, 1)",
primaryForeground: "hsla(0, 0%, 100%, 1)",
},
},
}}
safeAreaInsets={safeAreaInsets}
>
<App />
</UIProvider>import { Field, Input } from "@korsolutions/ui";
<Field.Root>
<Field.Label for="email">Email</Field.Label>
<Input id="email" value={email} onChange={setEmail} placeholder="you@example.com" />
<Field.Description>Enter your email address</Field.Description>
{error && <Field.Error>{error}</Field.Error>}
</Field.Root>;import { Field, Input } from "@korsolutions/ui";
<Field.Root>
<Field.Label for="email">Email</Field.Label>
<Input id="email" value={email} onChange={setEmail} placeholder="you@example.com" />
<Field.Description>Enter your email address</Field.Description>
{error && <Field.Error>{error}</Field.Error>}
</Field.Root>;import { AlertCircle, CheckCircle } from "lucide-react-native";
import { Alert } from "@korsolutions/ui";
// With lucide-react-native
<Alert.Icon render={AlertCircle} />
// With custom function
<Alert.Icon render={(props) => <CheckCircle {...props} size={20} />} />
// With @expo/vector-icons
import { MaterialCommunityIcons } from "@expo/vector-icons";
<Alert.Icon render={(props) => (
<MaterialCommunityIcons {...props} name="alert-circle" />
)} />import { AlertCircle, CheckCircle } from "lucide-react-native";
import { Alert } from "@korsolutions/ui";
// 使用lucide-react-native
<Alert.Icon render={AlertCircle} />
// 使用自定义函数
<Alert.Icon render={(props) => <CheckCircle {...props} size={20} />} />
// 使用@expo/vector-icons
import { MaterialCommunityIcons } from "@expo/vector-icons";
<Alert.Icon render={(props) => (
<MaterialCommunityIcons {...props} name="alert-circle" />
)} />import { IconButton } from "@korsolutions/ui";
import { Heart, Settings, Trash } from "lucide-react-native";
// Basic usage
<IconButton render={Heart} onPress={() => console.log("Liked")} />
// Variants (matches Button variants)
<IconButton render={Settings} variant="secondary" />
<IconButton render={Settings} variant="ghost" />
// Custom size and color
<IconButton render={Trash} size={32} color="red" />
// Disabled
<IconButton render={Heart} isDisabled />import { IconButton } from "@korsolutions/ui";
import { Heart, Settings, Trash } from "lucide-react-native";
// 基础用法
<IconButton render={Heart} onPress={() => console.log("Liked")} />
// 变体(与Button组件变体一致)
<IconButton render={Settings} variant="secondary" />
<IconButton render={Settings} variant="ghost" />
// 自定义尺寸和颜色
<IconButton render={Trash} size={32} color="red" />
// 禁用状态
<IconButton render={Heart} isDisabled />import { Separator } from "@korsolutions/ui";
// Horizontal (default)
<Separator />
// Vertical
<Separator variant="vertical" />import { Separator } from "@korsolutions/ui";
// 水平方向(默认)
<Separator />
// 垂直方向
<Separator variant="vertical" />import { useState } from "react";
import { Input, Checkbox } from "@korsolutions/ui";
function Form() {
const [text, setText] = useState("");
const [checked, setChecked] = useState(false);
return (
<>
<Input value={text} onChange={setText} />
<Checkbox.Root checked={checked} onChange={setChecked}>
<Checkbox.Indicator />
<Checkbox.Content>
<Checkbox.Title>Accept terms</Checkbox.Title>
</Checkbox.Content>
</Checkbox.Root>
</>
);
}import { useState } from "react";
import { Input, Checkbox } from "@korsolutions/ui";
function Form() {
const [text, setText] = useState("");
const [checked, setChecked] = useState(false);
return (
<>
<Input value={text} onChange={setText} />
<Checkbox.Root checked={checked} onChange={setChecked}>
<Checkbox.Indicator />
<Checkbox.Content>
<Checkbox.Title>Accept terms</Checkbox.Title>
</Checkbox.Content>
</Checkbox.Root>
</>
);
}<Button isLoading={isSubmitting} onPress={handleSubmit}>
Submit
</Button>isLoadingActivityIndicator<Button isLoading={isSubmitting} onPress={handleSubmit}>
Submit
</Button>isLoadingActivityIndicator<Button isDisabled={!formValid} onPress={handleSubmit}>
Submit
</Button>
<Input isDisabled value={email} onChange={setEmail} />
<Checkbox.Root disabled checked={value} onChange={setValue}>
<Checkbox.Indicator />
<Checkbox.Content>
<Checkbox.Title>Disabled option</Checkbox.Title>
</Checkbox.Content>
</Checkbox.Root><Button isDisabled={!formValid} onPress={handleSubmit}>
Submit
</Button>
<Input isDisabled value={email} onChange={setEmail} />
<Checkbox.Root disabled checked={value} onChange={setValue}>
<Checkbox.Indicator />
<Checkbox.Content>
<Checkbox.Title>Disabled option</Checkbox.Title>
</Checkbox.Content>
</Checkbox.Root>// Button variants
<Button variant="default">
Default Button
</Button>
<Button variant="secondary">
Secondary Button
</Button>
<Button variant="ghost">
Ghost Button
</Button>
// Alert variants
<Alert.Root variant="default">
<Alert.Body>
<Alert.Title>Info</Alert.Title>
</Alert.Body>
</Alert.Root>
<Alert.Root variant="destructive">
<Alert.Body>
<Alert.Title>Error</Alert.Title>
</Alert.Body>
</Alert.Root>
// Badge variants
<Badge variant="success">Active</Badge>
<Badge variant="danger">Inactive</Badge>
<Badge variant="warning">Pending</Badge>// Button组件变体
<Button variant="default">
Default Button
</Button>
<Button variant="secondary">
Secondary Button
</Button>
<Button variant="ghost">
Ghost Button
</Button>
// Alert组件变体
<Alert.Root variant="default">
<Alert.Body>
<Alert.Title>Info</Alert.Title>
</Alert.Body>
</Alert.Root>
<Alert.Root variant="destructive">
<Alert.Body>
<Alert.Title>Error</Alert.Title>
</Alert.Body>
</Alert.Root>
// Badge组件变体
<Badge variant="success">Active</Badge>
<Badge variant="danger">Inactive</Badge>
<Badge variant="warning">Pending</Badge>style<Button
style={{
marginTop: 20,
backgroundColor: "blue",
}}
>
Custom Styled
</Button>style<Button
style={{
marginTop: 20,
backgroundColor: "blue",
}}
>
Custom Styled
</Button>// Import individual components
import { Button, Input, Card, Alert } from "@korsolutions/ui";
// Import all components
import * as UI from "@korsolutions/ui";// 导入单个组件
import { Button, Input, Card, Alert } from "@korsolutions/ui";
// 导入所有组件
import * as UI from "@korsolutions/ui";// Theme hook
import { useTheme } from "@korsolutions/ui";
// Responsive design hook
import { useScreenSize } from "@korsolutions/ui";
// React Navigation theme integration
import { useReactNavigationTheme } from "@korsolutions/ui";// 主题Hook
import { useTheme } from "@korsolutions/ui";
// 响应式设计Hook
import { useScreenSize } from "@korsolutions/ui";
// React Navigation主题集成
import { useReactNavigationTheme } from "@korsolutions/ui";import { UIProvider } from "@korsolutions/ui";import { UIProvider } from "@korsolutions/ui";// Component prop types
import type { ButtonRootProps } from "@korsolutions/ui";
import type { InputProps } from "@korsolutions/ui";
// Theme types
import type { ThemeAssets, Colors } from "@korsolutions/ui";// 组件属性类型
import type { ButtonRootProps } from "@korsolutions/ui";
import type { InputProps } from "@korsolutions/ui";
// 主题类型
import type { ThemeAssets, Colors } from "@korsolutions/ui";UIProvider// app/_layout.tsx
import { UIProvider } from "@korsolutions/ui";
export default function RootLayout() {
return (
<UIProvider>
<Stack />
</UIProvider>
);
}UIProvider// app/_layout.tsx
import { UIProvider } from "@korsolutions/ui";
export default function RootLayout() {
return (
<UIProvider>
<Stack />
</UIProvider>
);
}@korsolutions/uinpm install @korsolutions/ui@korsolutions/uinpm install @korsolutions/uiundefinedundefinedconst customTheme = {
colors: { light: { primary: "hsla(220, 90%, 56%, 1)" } },
};
<UIProvider theme={customTheme}>
<App />
</UIProvider>;const customTheme = {
colors: { light: { primary: "hsla(220, 90%, 56%, 1)" } },
};
<UIProvider theme={customTheme}>
<App />
</UIProvider>;// This works - style prop overrides variant
<Button style={{ backgroundColor: "red" }}>
Red Button
</Button>// 此写法生效 - style属性覆盖变体样式
<Button style={{ backgroundColor: "red" }}>
Red Button
</Button>