### Basic Spin Usage Source: https://github.com/secondarycoder/h0-front/blob/main/Spin.md A simple example demonstrating the basic loading state of the Spin component. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Spin } from 'choerodon-ui/pro'; ReactDOM.render(, document.getElementById('container')); ``` -------------------------------- ### JavaScript Example with DataSet and UI Components Source: https://github.com/secondarycoder/h0-front/blob/main/DataSet_Example.md This example demonstrates the integration of DataSet with various UI components like Form, Table, and SelectBox. It includes data initialization, JSON formatting, and state management for UI interactions. It requires importing React, ReactDOM, and specific components from choerodon-ui/pro, along with MobX actions and formatters. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Button, DataSet, Form, Table, SelectBox, CodeArea, Row, Col, } from 'choerodon-ui/pro'; import { action } from 'mobx'; // 引入格式化器 import JSONFormatter from 'choerodon-ui/pro/lib/code-area/formatters/JSONFormatter'; // 引入 json lint import 'choerodon-ui/pro/lib/code-area/lint/json'; // 处理 codemirror 的SSR问题, 如无需SSR,请用import代替require; import 'codemirror/mode/javascript/javascript'; const data = [ { id: '1', code: 'code1', name: 'name1', number: 30, date_multiple_range: [ ['1984-11-22', '1985-07-01'], ['2020-11-22', '2021-07-01'], ], jsonData: JSON.stringify({ view: [ { id: 'id1-1', code: 'code1-1', name: 'view1-1' }, { id: 'id1-2', code: 'code1-2', name: 'view1-2' }, ], model: [ { id: 'id1-1', code: 'code1-1', name: 'model1-1' }, { id: 'id1-2', code: 'code1-2', name: 'model1-2' }, ], }), }, { id: '2', code: 'code2', name: 'name2', number: 30, jsonData: JSON.stringify({ view: [ { id: 'id2-1', code: 'code2-1', name: 'view2-1' }, { id: 'id2-2', code: 'code2-2', name: 'view2-2' }, ], model: [ { id: 'id2-1', code: 'code2-1', name: 'model2-1' }, { id: 'id2-2', code: 'code2-2', name: 'model2-2' }, ], }), }, ]; const json = JSON.stringify(data, null, 2); const jsonStyle = { height: 400 }; const App = () => { const [result, setResult] = React.useState(); const [dataToJSON, setDataToJSON] = React.useState('dirty'); const dataToJSONOptions = React.useMemo( () => new DataSet({ data: [ { value: 'dirty', meaning: 'dirty' }, { value: 'dirty-field', meaning: 'dirty-field' }, { value: 'selected', meaning: 'selected' }, { value: 'all', meaning: 'all' }, { value: 'normal', meaning: 'normal' }, { value: 'dirty-self', meaning: 'dirty-self' }, { value: 'dirty-field-self', meaning: 'dirty-field-self' }, { value: 'selected-self', meaning: 'selected-self' }, { value: 'all-self', meaning: 'all-self' }, { value: 'normal-self', meaning: 'normal-self' }, ], }), [] ``` -------------------------------- ### Spin with Custom Indicator Source: https://github.com/secondarycoder/h0-front/blob/main/Spin.md Demonstrates how to use a custom indicator for the Spin component. This example shows small, default, and large Spin components with a custom 'c7nIcon' indicator. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Spin } from 'choerodon-ui/pro'; const c7nIcon = ( ); ReactDOM.render(
, document.getElementById('container'), ); ``` -------------------------------- ### Layout Structure Example Source: https://github.com/secondarycoder/h0-front/blob/main/Layout.md This JSX snippet illustrates a basic layout structure comprising a header, a main content area, and two sidebars (left and right). ```jsx
header
left sidebar main content right sidebar
footer
``` -------------------------------- ### Basic Form Usage Source: https://github.com/secondarycoder/h0-front/blob/main/Form.md Demonstrates the basic setup of a Form component with various input fields like TextField, Password, NumberField, and Select. Includes custom validators and renderers for validation messages. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Form, TextField, Password, NumberField, EmailField, UrlField, DatePicker, Select, SelectBox, Button, Menu, Dropdown, Icon, } from 'choerodon-ui/pro'; const { Option } = Select; function passwordValidator(value, name, form) { if (value !== form.getField('password').getValue()) { return '您两次输入的密码不一致,请重新输入'; } return true; } function validationRenderer(error, props) { if (error.ruleName === 'valueMissing' && props.name === 'password') { return ( {error.validationMessage}(自定义) ); } } const menu = ( 1st menu item 2nd menu item , document.getElementById('container'), ); ``` -------------------------------- ### Segmented Component Sizes and Custom Option Rendering Source: https://github.com/secondarycoder/h0-front/blob/main/Segmented.md Illustrates how to use the Segmented component with different sizes (small, default, large) and how to customize the rendering of each option using the `optionRenderer` prop. The example shows an icon alongside the text in each option. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Segmented, Icon } from 'choerodon-ui/pro'; const { Option } = Segmented; function handleChange(value, oldValue) { console.log('[optionRenderer new]', value, '[optionRenderer old]', oldValue); } class App extends React.Component { optionRenderer = ({ text }) => { return (
{text && } {text}
); }; render() { return (
, document.getElementById('container'), ); ``` -------------------------------- ### Complex Skeleton Composition Source: https://github.com/secondarycoder/h0-front/blob/main/Skeleton.md Illustrates a more intricate setup of the Skeleton component, potentially involving DataSets and other UI elements for a detailed placeholder. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { TextArea, Button, DataSet, Skeleton } from 'choerodon-ui/pro'; import { Avatar } from 'choerodon-ui'; function handleDataSetChange({ record, name, value, oldValue }) { console.log( '[dataset newValue]', value, '[oldValue]', oldValue, `[record.get('${name}')]`, record.get(name), ); } class App extends React.Component { ds = new DataSet({ autoQuery: true, queryUrl: '/tree.mock', fields: [ { name: 'text', type: 'string', defaultValue: 'textarea', }, ], events: { update: handleDataSetChange, }, }); ``` -------------------------------- ### Alerts with Icons Source: https://github.com/secondarycoder/h0-front/blob/main/Alert.md Enhances alerts by displaying a prominent icon that visually represents the message type. Includes examples with and without descriptions. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Alert } from 'choerodon-ui'; ReactDOM.render(
, document.getElementById('container')); ``` -------------------------------- ### Card Loading State with Spin Source: https://github.com/secondarycoder/h0-front/blob/main/Spin.md Embeds content directly into Spin to turn an existing container into a loading state. This example uses a Switch to toggle the loading state. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Spin, Switch } from 'choerodon-ui/pro'; import { Alert } from 'choerodon-ui'; class Card extends React.Component { state = { loading: false }; toggle = (value) => { this.setState({ loading: value }); }; render() { const { loading } = this.state; return (
Loading state:
); } } ReactDOM.render(, document.getElementById('container')); ``` -------------------------------- ### Range Slider with Custom Labels Source: https://github.com/secondarycoder/h0-front/blob/main/Range.md Shows how to set custom labels for the Range slider using the 'marks' property and format tooltips with 'tipFormatter'. Includes both horizontal and vertical examples. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { DataSet, Range } from 'choerodon-ui/pro'; function handleDataSetChange({ value, oldValue }) { console.log('[dataset]', value, '[oldValue]', oldValue); } class App extends React.Component { ds = new DataSet({ autoCreate: true, fields: [{ name: 'range', defaultValue: 20, min: 10, max: 100, step: 1 }], events: { update: handleDataSetChange, }, }); render() { return (
`${value}%`} marks={{ 25: '当前进度 25%', 50: '当前进度 50%', 100: '当前进度 100%', 60: '当前进度 60%', 65: '当前进度 65%', }} />
`${value}%`} marks={{ 25: '温度 25℃', 40: '温度 40℃', 100: '温度 100℃', ``` -------------------------------- ### Progress Bar with Custom Text Format Source: https://github.com/secondarycoder/h0-front/blob/main/Progress.md Customizes the text displayed within the progress bar using a format function. This example shows a 'Done' message when the progress is complete. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Progress } from 'choerodon-ui/pro'; function format() { return 'Done'; } ReactDOM.render( , document.getElementById('container') ); ``` -------------------------------- ### Async Lazy Load Tree Data Source: https://github.com/secondarycoder/h0-front/blob/main/Table.md Asynchronously load child data when the expand icon is clicked. This setup requires configuring the DataSet for transport and defining node rendering logic. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { DataSet, Table, Icon, Row, Col } from 'choerodon-ui/pro'; import axios from 'axios'; const { Column } = Table; // 这里面可以控制node结点的判断来实现是否展示为叶结点 function nodeCover({ record }) { const nodeProps = { title: record.get('text'), }; if (record.get('text') === '岗位管理') { nodeProps.isLeaf = true; } return nodeProps; } function iconRenderer({ record, text }) { return [ , {text}, ]; } class App extends React.Component { ds = new DataSet({ primaryKey: 'id', transport: { read({ data: { parentId } }) { return { url: `/tree-async${parentId ? `-${parentId}` : ''}.mock`, }; }, }, submitUrl: '/tree-async.mock', autoQuery: true, parentField: 'parentId', idField: 'id', // 配置 expandField 后,展开依据于字段对应值,defaultExpanded 无效 // expandField: 'expand', checkField: 'ischecked', cacheSelection: true, cacheModified: true, fields: [ { name: 'id', type: 'number' }, ``` -------------------------------- ### Form Bound to a Specific DataSet Record Source: https://github.com/secondarycoder/h0-front/blob/main/Form.md Illustrates binding a Form to a specific record within a DataSet. This example showcases various field types and their configurations, including patterns, validators, and help text. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { DataSet, Form, TextField, NumberField, Password, EmailField, UrlField, DatePicker, Select, SelectBox, Lov, Button } from 'choerodon-ui/pro'; const { Option } = Select; function passwordValidator(value, name, record) { if (value !== record.get('password')) { return '您两次输入的密码不一致,请重新输入'; } return true; } class App extends React.Component { ds = new DataSet({ autoCreate: true, fields: [ { name: 'phone', type: 'string', label: '手机号', required: true }, { name: 'password', type: 'string', label: '密码', required: true }, { name: 'confirmPassword', type: 'string', label: '确认密码', required: true, validator: passwordValidator }, { name: 'age', type: 'number', label: '年龄', required: true, help: '我们需要确定你的年龄' }, { name: 'sex', type: 'string', label: '性别', required: true }, { name: 'language', type: 'string', label: '语言', required: true, help: '超过两行的帮助信息超过两行的帮助信息超过两行的帮助信息' }, { name: 'email', type: 'email', label: '邮箱', required: true }, { name: 'homepage', type: 'url', label: '个人主页', required: true }, { name: 'birth', type: 'date', label: '生日', required: true }, { name: 'code', type: 'object', label: '代码描述', lovCode: 'LOV_CODE' }, ], }); render() { return (
``` -------------------------------- ### Basic Dropdown Source: https://github.com/secondarycoder/h0-front/blob/main/Dropdown.md Demonstrates the most basic implementation of a dropdown menu with clickable items. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Menu, Dropdown, Icon, Button } from 'choerodon-ui/pro'; const menu = (
1st menu item 2nd menu item 3rd menu item ); ReactDOM.render(
, document.getElementById('container')); ``` -------------------------------- ### Basic Skeleton Usage Source: https://github.com/secondarycoder/h0-front/blob/main/Skeleton.md Demonstrates the simplest way to render a Skeleton component for a basic placeholder effect. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Skeleton } from 'choerodon-ui/pro'; ReactDOM.render(, document.getElementById('container')); ``` -------------------------------- ### Screening Control with Data Binding Source: https://github.com/secondarycoder/h0-front/blob/main/Screening.md Demonstrates how to bind a DataSet to the Screening control and configure individual ScreeningItems. Includes event handling for DataSet updates. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Screening, DataSet } from 'choerodon-ui/pro'; const { ScreeningItem } = Screening; function handleDataSetChange({ record, name, value, oldValue }) { console.log( '[dataset newValue]', value, '[oldValue]', oldValue, `[record.get('${name}')]`, record.toData(), ); } class App extends React.Component { ds = new DataSet({ autoCreate: true, data: [{ wear5: ['kidsOverSize', 'thermalUnderWear'] }], fields: [ { name: 'wear0', type: 'object', lookupCode: 'WEAR', label: '衣服分类0' }, { name: 'wear1', type: 'string', lookupCode: 'WEAR', label: '衣服分类1' }, { name: 'wear2', type: 'string', lookupCode: 'WEAR', label: '衣服分类2' }, { name: 'wear3', type: 'string', lookupCode: 'WEAR', label: '衣服分类3' }, { name: 'wear4', type: 'string', lookupCode: 'WEAR', label: '衣服分类4' }, { name: 'wear5', type: 'string', lookupCode: 'WEAR', label: '衣服分类5' }, ], events: { update: handleDataSetChange, }, }); render() { return ( `${text}-精品`} colProps={{ span: 8 }} name="wear1" /> ); } } ``` -------------------------------- ### Closable Alerts Source: https://github.com/secondarycoder/h0-front/blob/main/Alert.md Shows how to make alerts closable with a close button. Includes examples with long messages and descriptions. The `onClose` function is called when the alert is closed. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Alert } from 'choerodon-ui'; const onClose = function (e) { console.log(e, 'I was closed.'); }; ReactDOM.render(
, document.getElementById('container')); ``` -------------------------------- ### Skeleton with Buttons, Avatars, and Input Fields Source: https://github.com/secondarycoder/h0-front/blob/main/Skeleton.md Demonstrates how to configure Skeleton components for buttons, avatars, and input fields with various shape and size options. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { Skeleton, SelectBox, Form, Switch } from 'choerodon-ui/pro'; const { Option } = SelectBox; class App extends React.Component { state = { active: false, size: 'default', buttonShape: 'default', avatarShape: 'square', }; sizeList = ['default', 'small', 'large']; buttonShapeList = ['default', 'circle', 'round']; avatarShapeList = ['circle', 'square']; handleChangeActive = (active) => { this.setState({ active }); }; handleChangeSize = (size) => { this.setState({ size }); }; handleChangeBtnShape = (buttonShape) => { this.setState({ buttonShape }); }; handleChangeAvatarShape = (avatarShape) => { this.setState({ avatarShape }); }; render() { const { active, size, buttonShape, avatarShape } = this.state; return ( <>
, document.getElementById('container'), ); ``` -------------------------------- ### Basic TextArea Usage Source: https://github.com/secondarycoder/h0-front/blob/main/TextArea.md Demonstrates the basic rendering of TextArea components with different placeholder texts and states like readOnly and disabled. ```javascript import React from 'react'; import ReactDOM from 'react-dom'; import { TextArea, Row, Col } from 'choerodon-ui/pro'; ReactDOM.render(