### Local Development Setup
Source: https://github.com/open-hand/choerodon-ui/blob/master/README.md
Clone the repository, install dependencies, and start the development server for local development of Choerodon UI.
```bash
$ git clone https://github.com/open-hand/choerodon-ui.git
$ cd choerodon-ui
$ npm install
$ npm start
```
--------------------------------
### Basic Localization Setup
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/locale-provider/demo/basic.md
Wrap your application with LocaleProvider and import the desired language package (e.g., en_US) to enable localization. This example demonstrates setting up English localization.
```jsx
import { Pagination, LocaleProvider } from 'choerodon-ui';
import enUS from 'choerodon-ui/lib/locale-provider/en_US';
const App = () => (
);
ReactDOM.render(
,
mountNode);
```
--------------------------------
### Picture List Upload Example
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/upload/demo/picture-style.md
This example shows how to configure the Upload component to display files as a picture list. It includes default file list setup with `thumbUrl` for image previews. IE8/9 do not support local thumbnail previews and require `thumbUrl`.
```jsx
import { Upload, Button, Icon } from 'choerodon-ui';
const fileList = [{
uid: -1,
name: 'xxx.png',
status: 'done',
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
}, {
uid: -2,
name: 'yyy.png',
status: 'done',
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
}];
const props = {
action: '//jsonplaceholder.typicode.com/posts/',
listType: 'picture',
defaultFileList: [...fileList],
};
const props2 = {
action: '//jsonplaceholder.typicode.com/posts/',
listType: 'picture',
defaultFileList: [...fileList],
className: 'upload-list-inline',
};
ReactDOM.render(
,
mountNode);
```
--------------------------------
### CSS for Gutter Example
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/grid/demo/gutter.md
Provides the necessary CSS to style the gutter example, ensuring the grid boxes have a background and padding.
```css
.gutter-example .c7n-row > div {
background: transparent;
border: 0;
}
.gutter-box {
background: #00A0E9;
padding: 5px 0;
}
```
--------------------------------
### Basic TreeSelect Example
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/tree-select/demo/basic.md
This snippet shows the fundamental setup for a TreeSelect component, including importing necessary components and defining state for value changes. It's suitable for general-purpose selection from hierarchical data.
```jsx
import { TreeSelect } from 'choerodon-ui';
const TreeNode = TreeSelect.TreeNode;
class Demo extends React.Component {
state = {
value: undefined,
};
onChange = value => {
this.setState({ value });
};
render() {
return (
sss} key="random3" />
);
}
}
ReactDOM.render(, mountNode);
```
--------------------------------
### Install Choerodon UI
Source: https://github.com/open-hand/choerodon-ui/blob/master/README.md
Install the Choerodon UI package using npm.
```bash
npm install choerodon-ui --save
```
--------------------------------
### Rendering Integer and Decimal Step Examples
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/slider/demo/input-number.md
This snippet shows how to render both the integer and decimal step examples by including their respective component instances within a parent div.
```jsx
ReactDOM.render(
,
mountNode);
```
--------------------------------
### Basic Layout Examples
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/layout/demo/basic.md
These examples demonstrate different arrangements of Header, Footer, Sider, and Content components within the choerodon-ui Layout system. Ensure the Layout component and its sub-components are imported correctly.
```jsx
import { Layout } from 'choerodon-ui';
const { Header, Footer, Sider, Content } = Layout;
ReactDOM.render(
,
mountNode,
);
```
--------------------------------
### Mini Progress Bar Example
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/progress/demo/line-mini.md
Use the `size="small"` prop to render mini progress bars. This example shows different percentages and statuses.
```jsx
import { Progress } from 'choerodon-ui';
ReactDOM.render(
,
mountNode);
```
--------------------------------
### Responsive Grid Layout Example
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/grid/demo/responsive-more.md
Use responsive properties to adjust column spans and offsets based on screen size. The example shows how to configure columns for small (xs) and large (lg) screens.
```jsx
import { Row, Col } from 'choerodon-ui';
ReactDOM.render(
;
}
function renderPhoneEditor(record) {
const region = (
);
return
}
function renderPhone({ record, text }) {
return [record.get('phone-region'), text].filter(Boolean).join('-');
}
function renderColumnFooter({ dataSet, name }) {
const max = Math.max(
0,
...dataSet.map(record => record.get(name)).filter(value => !isNaN(value)),
);
return `最大年龄:${NumberField.format(max)}`;
}
function renderColumnHeader({ dataSet, name }) {
const field = dataSet.getField(name);
return (
-=
{field ? field.get('label') : ''}
=-
);
}
const codeDynamicProps = {
lovCode({ record }) {
if (record) {
return 'LOV_CODE';
}
},
};
const nameDynamicProps = {
// 当Sex为M(男)的时候 该属性为必须输入字段 即为 field 中 require = true
required({ record }) {
return record && record.get('sex') === 'M';
},
label() {
return '姓名';
},
};
const codeCodeDynamicProps = {
// 代码code_code值绑定 为 字段code 的 值列表的值字段为code.codevalue
bind({ record }) {
if (record) {
const field = record.get('name');
if (field) {
return 'codeMultiple.code';
}
}
},
};
const codeDescriptionDynamicProps = {
bind({ record }) {
if (record) {
const field = record.get('name');
if (field) {
return 'codeMultiple.description';
}
}
},
};
class App extends React.Component {
options = new DataSet({
fields: [{
name: 'value',
type: 'string',
}, {
name: 'meaning',
type: 'string',
}],
})
userDs = new DataSet({
primaryKey: 'userid',
autoQuery: true,
exportMode:'client',
pageSize: 5,
cacheSelection: true,
cacheModified: true,
validationRules: [
{
name: "minLength",
value: 7,
message: 'Maintain at least 7 pieces of data',
},
{
name: "maxLength",
value: 10,
message: 'A maximum of 10 pieces of data can be maintained',
}
],
transport: {
read({ params: { page, pagesize } }) {
if (pagesize > 20) {
return {
url: '/dataset/large-user/queries',
};
}
return {
url: `/dataset/user/page/${pagesize}/${page}`,
};
},
create: {
url: '/dataset/user/mutations',
method: 'put',
},
update: ({ data: [first] }) =>
first
? {
url: `/dataset/user/mutations/${first.userid}`,
data: first,
transformResponse() {
return [first];
},
}
: null,
destroy: {
url: '/dataset/user/mutations',
method: 'delete',
},
exports:{
url:'http://gitee.com/xurime/excelize/raw/master/test/SharedStrings.xlsx',
method:'get',
},
tls({ name }) {
// 多语言数据请求的 axios 配置或 url 字符串。UI 接收的接口返回值格式为:[{ name: { zh_CN: '简体中文', en_US: '美式英语', ... }}]
console.log('fieldName', name);
return {
url: '/dataset/user/languages',
};
},
},
feedback: {
loadSuccess(resp) {
// DataSet 查询成功的反馈 可以return 一个resp 来修改响应结果
```
--------------------------------
### Dropdown Menu Example
Source: https://github.com/open-hand/choerodon-ui/blob/master/components-pro/form/demo/disabled.md
Creates a sample dropdown menu with several menu items, each linking to a different URL.
```jsx
const menu = (
);
const dropdown = (
);
```
--------------------------------
### Controlled SelectBox Example
Source: https://github.com/open-hand/choerodon-ui/blob/master/components-pro/select-box/demo/controlled.md
This snippet shows a basic controlled SelectBox. The selected value is managed by the component's state and updated via the onChange handler. Ensure you have React and Choerodon UI Pro installed.
```jsx
import { SelectBox } from 'choerodon-ui/pro';
const { Option } = SelectBox;
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
value: 'wu',
};
}
handleChange = (value, oldValue) => {
console.log('[constrolled]', 'newValue', value, '[oldValue]', oldValue);
this.setState({
value,
});
}
render() {
return (
);
}
}
ReactDOM.render(
,
mountNode
);
```
--------------------------------
### Basic Progress Examples
Source: https://github.com/open-hand/choerodon-ui/blob/master/components-pro/progress/demo/basic.md
Shows how to render progress bars with different values and statuses like active, exception, and success. Also demonstrates hiding the info text.
```jsx
import { Progress } from 'choerodon-ui/pro';
ReactDOM.render(
,
mountNode
);
```
--------------------------------
### Basic Dragger Upload Example
Source: https://github.com/open-hand/choerodon-ui/blob/master/components-pro/attachment/demo/dragger.md
This snippet shows a basic Dragger component setup. It includes configuration for file types, maximum number of files, and a custom label. The component is also set to a disabled state.
```jsx
import React from 'react';
import { Icon } from 'choerodon-ui';
import { Attachment } from 'choerodon-ui/pro';
const { Dragger } = Attachment
const App = () => {
const [value, setValue] = React.useState('4c74a34a-fa37-4e92-be9d-5cf726fb1472');
const props = {
label: '技术附件',
labelLayout: 'float',
accept: ['.deb', '.txt', '.pdf', 'image/*'],
max: 3,
value,
onChange: setValue,
showHistory: true,
disabled: true,
//buttons: [['remove', { hidden: false }]],
help: '支持文件类型: .deb .txt .pdf image/*',
};
return (
点击这里或者拖拽文件到这里上传
支持文件类型: .deb .txt .pdf image/*
);
}
ReactDOM.render(
,
mountNode,
);
```
--------------------------------
### Directory Tree Example
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/tree/demo/directory.md
Demonstrates the basic usage of the Directory Tree component with multi-selection enabled. It includes event handlers for selection and expansion.
```tsx
import { Tree } from 'choerodon-ui';
const { DirectoryTree } = Tree;
const treeData = [
{
title: 'parent 0',
key: '0-0',
children: [
{ title: 'leaf 0-0', key: '0-0-0', isLeaf: true },
{ title: 'leaf 0-1', key: '0-0-1', isLeaf: true },
],
},
{
title: 'parent 1',
key: '0-1',
children: [
{ title: 'leaf 1-0', key: '0-1-0', isLeaf: true },
{ title: 'leaf 1-1', key: '0-1-1', isLeaf: true },
],
},
];
const Demo: React.FC<{}> = () => {
const onSelect = (keys, event) => {
console.log('Trigger Select', keys, event);
};
const onExpand = () => {
console.log('Trigger Expand');
};
return (
);
};
ReactDOM.render(, mountNode);
```
--------------------------------
### Pagination with Page Size Changer
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/pagination/demo/changer.md
Use the `onShowSizeChange` prop to handle changes in the page size. This example shows a basic setup for a pagination component that allows users to select the number of items per page.
```jsx
import { Pagination } from 'choerodon-ui';
function onShowSizeChange(current, pageSize) {
console.log(current, pageSize);
}
ReactDOM.render(
,
mountNode);
```
--------------------------------
### Transfer Component with 2000 Items
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/transfer/demo/large-data.md
This example demonstrates initializing the Transfer component with a large dataset (2000 items) and handling user interactions like moving items between lists. Ensure the `choerodon-ui` and `react` libraries are installed.
```jsx
import { Transfer } from 'choerodon-ui';
class App extends React.Component {
state = {
mockData: [],
targetKeys: [],
}
componentDidMount() {
this.getMock();
}
getMock = () => {
const targetKeys = [];
const mockData = [];
for (let i = 0; i < 2000; i++) {
const data = {
key: i.toString(),
title: `content${i + 1}`,
description: `description of content${i + 1}`,
chosen: Math.random() * 2 > 1,
};
if (data.chosen) {
targetKeys.push(data.key);
}
mockData.push(data);
}
this.setState({ mockData, targetKeys });
}
handleChange = (targetKeys, direction, moveKeys) => {
console.log(targetKeys, direction, moveKeys);
this.setState({ targetKeys });
}
render() {
return (
item.title}
/>
);
}
}
ReactDOM.render(, mountNode);
```
--------------------------------
### Output Component with Range Values
Source: https://github.com/open-hand/choerodon-ui/blob/master/components-pro/output/demo/range.md
This snippet shows how to configure the Output component to display range values. It includes examples for a single range bound to a DataSet field, a simple range with explicit values, a range defined by start and end properties, and multiple ranges.
```jsx
import { DataSet, Output, Row, Col } from 'choerodon-ui/pro';
class App extends React.Component {
ds = new DataSet({
autoCreate: true,
fields: [
{ name: 'user', type: 'string', label: '用户', defaultValue: [1, 10], required: true, range: true },
],
});
render() {
return (
);
}
}
ReactDOM.render(
,
mountNode
);
```
--------------------------------
### Cascading Select Example
Source: https://github.com/open-hand/choerodon-ui/blob/master/components-pro/select/demo/cascade.md
This snippet demonstrates a cascading select setup for provinces and cities, supporting both single and multiple selections. It utilizes DataSet with lookup codes and cascadeMap for defining the relationship between parent and child select components. The `handleDataSetChange` function logs changes to the console.
```jsx
import { Divider } from 'choerodon-ui';
import { DataSet, Select, Row, Col } from 'choerodon-ui/pro';
function handleDataSetChange({ record, value, oldValue }) {
console.log('[dataset]', value, '[oldValue]', oldValue, '[record.toJSONData()]', record.toJSONData());
}
class App extends React.Component {
ds = new DataSet({
autoCreate: true,
fields: [
{
name: 'sheng',
label: '省',
lookupCode: 'SHENG',
valueField: 'codeValueId',
defaultValue: 10206,
},
{
name: 'shi',
type: 'number',
valueField: 'codeValueId',
label: '市',
lookupCode: 'SHI',
cascadeMap: { parentCodeValueId: 'sheng' },
},
{
name: 'sheng-multiple',
label: '省(多选)',
lookupCode: 'SHENG',
valueField: 'codeValueId',
defaultValue: 10206,
multiple: true,
},
{
name: 'shi-multiple',
type: 'number',
valueField: 'codeValueId',
label: '市(多选)',
lookupCode: 'SHI',
multiple: true,
cascadeMap: { parentCodeValueId: 'sheng-multiple' },
},
],
events: {
update: handleDataSetChange,
},
});
render() {
return (
<>
单选
多选
>
);
}
}
ReactDOM.render(
,
mountNode
);
```
--------------------------------
### Basic Steps Group Example
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/steps/demo/group.md
Shows how to import and use Steps, StepGroup, and Step components to create a grouped step interface. Ensure Steps, StepGroup, and Step are imported.
```jsx
import { Steps} from 'choerodon-ui';
const Step = Steps.Step;
const StepGroup = Steps.StepGroup;
ReactDOM.render(
,
mountNode,
);
```
--------------------------------
### DatePicker Usage Example
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/date-picker/index.en-US.md
A basic example demonstrating how to use the DatePicker component with a default value.
```APIDOC
## DatePicker
### Description
To select or input a date. By clicking the input box, you can select a date from a popup calendar.
### Usage Example
```jsx
// The default locale is en-US, if you want to use other locale, just set locale in entry file globaly.
// import moment from 'moment';
// import 'moment/locale/zh-cn';
// moment.locale('zh-cn');
```
### Common API
The following APIs are shared by DatePicker, MonthPicker, RangePicker, WeekPicker.
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| allowClear | Whether to show clear button | boolean | true |
| autoFocus | get focus when component mounted | boolean | false |
| className | picker className | string | '' |
| dateRender | custom rendering function for date cells | function(currentDate: moment, today: moment) => React.ReactNode | - |
| disabled | determine whether the DatePicker is disabled | boolean | false |
| disabledDate | specify the date that cannot be selected | (currentDate: moment) => boolean | - |
| getCalendarContainer | to set the container of the floating layer, while the default is to create a `div` element in `body` | function(trigger) | - |
| locale | localization configuration | object | [default](https://github.com/open-hand/choerodon-ui/blob/master/components/date-picker/locale/example.json) |
| open | open state of picker | boolean | - |
| placeholder | placeholder of date input | string\|RangePicker\[] | - |
| popupStyle | to customize the style of the popup calendar | object | {} |
| dropdownClassName | to customize the className of the popup calendar | string | - |
| size | determine the size of the input box, the height of `large` and `small`, are 40px and 24px respectively, while default size is 32px | string | - |
| style | to customize the style of the input box | object | {} |
| onOpenChange | a callback function, can be executed whether the popup calendar is popped up or closed | function(status) | - |
| onPanelChange | callback when picker panel mode is changed | function(value, mode) | - |
| mode | picker panel mode | `time|date|month|year` | 'date' |
| processValue | 日期控件值变更时,自动补全时间为23:59:59 | boolean | |
### Common Methods
| Name | Description |
| ---- | ----------- |
| blur() | remove focus |
| focus() | get focus |
### DatePicker Specific API
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| defaultValue | to set default date | [moment](http://momentjs.com/) | - |
| disabledTime | to specify the time that cannot be selected | function(date) | - |
| format | to set the date format, refer to [moment.js](http://momentjs.com/) | string | "YYYY-MM-DD" |
| renderExtraFooter | render extra footer in panel | () => React.ReactNode | - |
| showTime | to provide an additional time selection | object\|boolean | [TimePicker Options](/components/time-picker/#API) |
| showTime.defaultValue | to set default time of selected date, [demo](/components/date-picker/#components-date-picker-demo-disabled-date) | [moment](http://momentjs.com/) | moment() |
| showToday | whether to show "Today" button | boolean | true |
| value | to set date | [moment](http://momentjs.com/) | - |
| onCalendarChange | a callback function, can be executed when the start time or the end time of the range is changing | function(dates: [moment, moment], dateStrings: [string, string]) | 无 |
| onChange | a callback function, can be executed when the selected time is changing | function(date: moment, dateString: string) | - |
| onOk | callback when click ok button | function() | - |
```
--------------------------------
### Badge Usage
Source: https://github.com/open-hand/choerodon-ui/blob/master/components/badge/index.en-US.md
Examples demonstrating how to use the Badge component with different configurations.
```APIDOC
## Badge Component API
### Properties
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| count | Number to show in badge | ReactNode | |
| dot | Whether to display a red dot instead of `count` | boolean | `false` |
| offset | set offset of the badge dot, like`[x, y]` | `[number, number]` | - |
| overflowCount | Max count to show | number | 99 |
| showZero | Whether to show badge when `count` is zero | boolean | `false` |
| status | Set Badge as a status dot | `success` \| `processing` \| `default` \| `error` \| `warning` | `''` |
| text | If `status` or `color` is set, `text` sets the display text of the status `dot` | ReactNode | `''` |
| color | Customize Badge dot color | string | |
| size | If `count` is set, `size` sets the size of badge | `default` \| `small` | `default` |
| title | Text to show when hovering over the badge | string | |
```