### 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); ``` -------------------------------- ### Board Component Example Source: https://github.com/open-hand/choerodon-ui/blob/master/components-pro/board/demo/pristine.md Demonstrates the setup and usage of the Board component with various field types and configurations. Includes dynamic properties for code fields and a custom edit button. ```jsx import { DataSet, Table, Form, TextField, NumberField, CheckBox, SelectBox, Modal, Button, Board, } from 'choerodon-ui/pro'; import { observer } from 'mobx-react'; const { Column } = Table; const codeCodeDynamicProps = { // 代码code_code值绑定 为 字段code 的 值列表的值字段为code.codevalue bind({ record }) { if (record) { const field = record.getField('code'); if (field) { const valueField = field.get('valueField'); return `code.${valueField}`; } } }, }; const codeDescriptionDynamicProps = { bind({ record }) { if (record) { const field = record.getField('code'); if (field) { const textField = field.get('textField'); return `code.${textField}`; } } }, }; class EditButton extends React.Component { handleClick = e => { const { record, onClick } = this.props; onClick(record, e); }; render() { return ); ``` -------------------------------- ### 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 | | ```