### Basic Usage Example in Demo File Source: https://github.com/shuyunff2e/cloud-react/blob/master/docs/demo.md This snippet illustrates the typical content structure of a `*.markdown` demo file. It includes front matter (metadata like title and description), a React JSX component demonstrating basic button usage, and accompanying styling defined in either LESS or CSS. The example focuses on a simple use case for the `Button` component. ```jsx import { Button } from 'cloud-react'; import React from 'react'; export default class BasicDemo extends React.Component { render() { return ; } } ``` ```less .btn { a { color: red; } } ``` ```css .btn a { color: red; } ``` -------------------------------- ### Basic CDrawer Usage Example Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/c-drawer/demos/basic.md This example demonstrates a fundamental implementation of the CDrawer component. It shows how to control the drawer's visibility using a button, manage its open/close state, and configure basic properties like title, placement, and event handlers. ```jsx /** * title: 基础 * desc: 头像有六种尺寸,两种形态 */ import React from 'react'; import { Button, CDrawer } from 'cloud-react'; class Demo extends React.Component { constructor(props) { super(props); this.state = { open: false, }; } showDrawer() { this.setState({ open: true, }); } onClose() { this.setState({ open: false, }); } render() { return (
{this.onClose()}} open={this.state.open} getContainer={false} >

Some contents...

Some contents...

Some contents...

); } } export default Demo; ``` -------------------------------- ### Install Node.js Dependencies Source: https://github.com/shuyunff2e/cloud-react/blob/master/README.md This command installs all required Node.js dependencies for the cloud-react project using npm. It fetches packages listed in the project's package.json file. ```bash $ npm i ``` -------------------------------- ### Start Development Server Source: https://github.com/shuyunff2e/cloud-react/blob/master/README.md This command initiates the local development server for the cloud-react project. It's used for live development, testing changes, and typically includes hot-reloading capabilities. ```bash $ npm start ``` -------------------------------- ### Component Demo File Directory Structure Source: https://github.com/shuyunff2e/cloud-react/blob/master/docs/demo.md Illustrates the recommended directory structure for placing component demo files within the `src/components` directory. Each component should have a `demos` subdirectory containing its markdown demo files, such as `basic.markdown`. ```javascript |- src |- components |- button |- demos |- basic.markdown ``` -------------------------------- ### React CCascader Component Basic Usage Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/c-cascader/demos/transition.md This JSX code snippet demonstrates how to use the `CCascader` component from the `cloud-react` library. It initializes the component with static address options, sets a placeholder text, and applies a 'slide-up' transition effect for its dropdown. The example showcases a typical setup for a cascader selection input in a React application. ```jsx import React from 'react'; import { CCascader } from 'cloud-react'; const addressOptions = [ { value: 'zhejiang', label: 'ZhejiangZhejiangZhejiangZhejiangZhejiangZhejiangZhejiangZhejiangZhejiangZhejiangZhejiangZhejiang', children: [ { value: 'hangzhou', label: 'Hangzhou', children: [ { value: 'xihu', label: 'West Lake', }, { value: 'xiasha', label: 'Xia Sha', }, ], }, ], }, { value: 'jiangsu', label: 'Jiangsu', children: [ { value: 'nanjing', label: 'Nanjing', children: [ { value: 'zhonghuamen', label: 'Zhong Hua men', }, ], }, ], }, ]; export default function Demo() { return ( ); } ``` -------------------------------- ### Modal Static Method Call Examples Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/modal/index.md Demonstrates the basic usage of static methods like `confirm`, `success`, `error`, `info`, and `warning` available on the `Modal` object. ```javascript Modal.confirm(config) Modal.success(config) Modal.error(config) Modal.info(config) Modal.warning(config) ``` -------------------------------- ### React Input Component Demonstrations Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/input/demos/mixin.md This React component `InputDemo` showcases various configurations and usages of `Input` and `Mixin` components from the `cloud-react` library. It includes examples of basic input fields, merged inputs, separated inputs using `Mixin.InputInput`, range inputs with `Mixin.RangeInput`, and a select-input combination with `Mixin.SelectInput`. Users can dynamically control the disabled state, size, and border radius of the inputs using checkboxes and radio buttons. ```jsx import React, { createRef, useState } from 'react'; import { Mixin, Icon, Input, Radio, Checkbox } from 'cloud-react'; import './styles/basic.less' export default function InputDemo() { const [disabled, setDisabled] = useState(false); const [size, setSize ] = useState('default'); const [borderRadiusSize, setBorderRadiusSize] = useState('default'); return (
{ setDisabled(checked) }}>禁用
large default small
圆角:default 圆角:medium 圆角:large
两个合并输入框
两个分离输入框
{ console.log(evt); }, }} />
分离区间

合并区间
下拉框+输入框
{ console.log(value); }, }} ``` -------------------------------- ### React Popover Component Examples Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/popover/demos/basic.md This comprehensive example demonstrates various configurations and features of the `cloud-react` Popover component. It shows how to control the trigger type (click/hover), display different content types (plain text, input fields), include confirmation/cancel buttons, add icons, set titles, and handle user interactions like button clicks and form submissions within the popover. It also includes an example of a validation message using `Message.error`. ```jsx import React, { useState, useEffect } from 'react'; import { Button, Popover, Message, Checkbox, Input } from 'cloud-react'; export default function PopoverDemo() { const [isClick, setIsClick] = useState(true); const [trigger, setTrigger] = useState('hover'); useEffect(() => { setTrigger(isClick ? 'click' : 'hover'); }, [isClick]); const split =

return (

{ setIsClick(!isClick); }}>通过 click 触发 {split} {split} )}> {split} {split} {split} {split} {split} {split} {split} { console.log('cancleBtn is clicked'); }} onConfirmClick={() => { console.log('confirmBtn is clicked'); }}> {split} { console.log('cancleBtn is clicked'); }} onConfirmClick={() => { const a = new Array(2000).fill(1).reduce((sum, item) => { sum += item; return sum; }, 0); Message.error('校验 불법,无法关闭弹窗') return a >= 2000; }}> {split} {split}
); } ``` -------------------------------- ### React Modal.confirm API Usage Examples Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/modal/demos/confirm.md This React component demonstrates various ways to use the `Modal.confirm` API from the `cloud-react` library. It includes examples for a basic confirmation dialog, a dialog with a custom icon, a dialog with customized button text, and an asynchronous confirmation dialog that resolves after a delay. The component manages state to display the result of user interaction (OK/Cancel). ```jsx /** * title: 确认对话框 * desc: 通过API调用方式弹出confirm确认对话框 */ import React from 'react'; import { Button, Modal } from 'cloud-react'; const blank = '\u00A0'; class ModalDemo extends React.Component { constructor(props) { super(props); this.state = { content: '' }; } handleOk = () => { this.setState({ content: '你点击了确定' }); }; openConfirmModal = () => { Modal.confirm({ isShowIcon: false, title: '基本确认对话框', body: '杭州数云信息技术有限公司是国内领先的全域消费者增长方案提供商', cancelBtnOpts: { type: 'secondary' }, isReverseBtn: true, // hasFooter: false, // className: "test", onOk: () => { this.handleOk(); }, onCancel: () => { this.setState({ content: '你点击了取消' }); } }); }; openCustomerIconConfirmModal = () => { Modal.confirm({ title: '自定义图标确认对话框', isShowIcon: true, title: '确定要删除吗?', body: '这里是删除后相应状态的描述。', onOk: () => { this.handleOk(); }, onCancel: () => { this.setState({ content: '你点击了取消' }); } }); }; openCustomConfirmModal = () => { Modal.confirm({ title: '自定义弹窗按钮', okText: '好', cancelText: '关闭', body: '按钮的文案修改了', onOk: () => { this.setState({ content: '你点击了好' }); }, onCancel: () => { this.setState({ content: '你点击了关闭' }); } }); } openAsyncConfirmModal = () => { Modal.confirm({ title: '异步弹窗框', body: '这是个异步的example,请点击确定按钮测试验证', onOk: () => { return new Promise((resolve, reject) => { setTimeout(() => { resolve(); this.handleOk(); }, 3000); }).catch(() => { console.log('error'); }); }, onCancel: () => { this.setState({ content: '你点击了取消' }); } }); }; render() { return (
{blank} {blank} {blank} {blank}

); } } export default ModalDemo; ``` -------------------------------- ### Generate Unique GUID String in JavaScript Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/c-table/demos/goods-table.md This utility function generates a pseudo-unique GUID string by concatenating two random hexadecimal strings. It's used for creating unique identifiers, particularly for product SKUs in the example data. ```javascript function createGuid() { let guid = ''; for (let i = 1; i <= 2; i += 1) { guid += Math.random() .toString(32) .substr(2); } return guid.replace(/^\d+/, ''); } ``` -------------------------------- ### React Minimal Pagination Component Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/pagination/demos/mini-page.md This React component demonstrates a minimal pagination setup using `cloud-react`'s `Pagination` component. It shows how to manage current page and page size state, and how to handle page changes. It also includes a disabled example for comparison. ```jsx /** * title: 极简模式 * desc: 分页极简模式仅页码用法 */ import React from 'react'; import { Pagination, Checkbox } from 'cloud-react'; class PaginationDemo extends React.Component { state = { current: 5, pageSize: 10, }; onChange = (current, pageSize) => { console.log('current: %d,pageSize: %s', current, pageSize); this.setState({ current, pageSize }); }; render() { return ( <> ); } } export default PaginationDemo; ``` -------------------------------- ### React Tips Component with Descriptions Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/tips/demos/description.md This React component demonstrates the usage of the `Tips` component from the `cloud-react` library. It shows how to display tips with a main message and an additional description, configure different tip types (default, warning, major), include icons, and add custom close buttons. It also illustrates passing an array of strings as a description. ```jsx /** * title: 带描述文字的提示 * desc: */ import React from 'react'; import { Tips } from 'cloud-react'; class TipsDemo extends React.Component { render() { return (
传个数组试试
} description={[ '1.这里是描述性文字', '2.这里是描述性文字', '3.这里是描述性文字', ]} closeIcon="close-line" />
); } } export default TipsDemo; ``` -------------------------------- ### CTable with Time Range Column Types Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/c-table/demos/uniform_time_range.md This example showcases the CTable component from 'cloud-react', demonstrating how to configure columns to display time ranges with different formats (e.g., full datetime, date only, month/day, time only). It uses `type: 'TIME_RANGE'` and `typeConfig` to specify start and end keys, and formatting options. ```jsx /** * title: 时间范围类型 * desc: 时间范围类型 */ import React from 'react'; import { CTable } from 'cloud-react'; const data = [ { startTime: '2021/12/14 10:19:02', endTime: '2023/08/14 10:19:02' }, { startTime: '2021/12/13 15:47:33', endTime: '2023/08/14 10:19:02' }, { startTime: '', endTime: '2023/08/14 10:19:02' }, { startTime: '2021-12-13 11:14:40', endTime: '' }, { startTime: '', endTime: '' }, ]; const columns = [ { title: '年月日时分秒', dataIndex: 'startTime', width: 160, type: 'TIME_RANGE', typeConfig: { startKey: 'startTime', endKey: 'endTime', }, }, { title: '年月日', dataIndex: 'startTime', width: 130, type: 'TIME_RANGE', typeConfig: { format: 'YYYY-MM-DD', startKey: 'startTime', endKey: 'endTime', } }, { title: '年月', dataIndex: 'startTime', width: 90, type: 'TIME_RANGE', typeConfig: { format: 'YYYY-MM', startKey: 'startTime', endKey: 'endTime', } }, { title: '月日', dataIndex: 'startTime', width: 90, type: 'TIME_RANGE', typeConfig: { format: 'MM-DD', startKey: 'startTime', endKey: 'endTime', } }, { title: '时分秒', dataIndex: 'startTime', width: 100, type: 'TIME_RANGE', typeConfig: { format: 'HH:MM:SS', startKey: 'startTime', endKey: 'endTime', } }, ]; export default function CTableDemo() { return ( ); } ``` -------------------------------- ### Basic Usage of React Step Component Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/step/demos/basic-step.md This example demonstrates the fundamental use of the `Step` component from the `cloud-react` library. It illustrates how to render a series of steps, control the currently active step using the `current` prop, and adjust the component's visual size with the `size` prop. Multiple instances showcase different configurations and step progressions. ```jsx import React from 'react'; import { Step } from 'cloud-react'; const title1Style = { textAlign: 'center' }; const title2Style = { marginTop: '100px', textAlign: 'center' }; export default function StepDemo() { return (

把大象装进冰箱分几步

把长颈鹿装进冰箱分几步

把大象装进冰箱分几步-小尺寸

); } ``` -------------------------------- ### Nested Modals Example Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/modal/demos/nest.md This React component demonstrates the creation of nested modal dialogs. It uses 'cloud-react' Button and Modal components to open a primary modal, which then contains a 'SecondModal' component. The 'SecondModal' can open another 'Modal' containing a 'ConfirmModal', which finally triggers a simple info modal. This setup illustrates how to manage visibility and interactions across multiple layers of modals. ```jsx import React from 'react'; import { Button, Modal } from 'cloud-react'; const blank = '\u00A0'; class ModalDemo extends React.Component { constructor(props) { super(props); this.state = { visible: false }; } // 弹出框 openNestModal = () => { this.setState({ visible: true }); }; // 确认按钮回调函数 handleOk = () => { this.setState({ visible: false }); }; // 关闭回调函数 handleClose = () => { this.setState({ visible: false }); }; handleCancel = () => { this.setState({ visible: false }); }; openErrorModal = () => {}; render() { return (
); } } class SecondModal extends React.Component { constructor(props) { super(props); this.state = { visible: false }; } openInfoModal = () => { this.setState({ visible: true }); }; // 关闭回调函数 handleClose = () => { this.setState({ visible: false }); }; render() { return (
); } } class ConfirmModal extends React.Component { openInfoModal = () => { Modal.info({ body: '可以点开下面的图标查看example代码。', onCancel: () => {} }); }; render() { return ( ); } } export default ModalDemo; ``` -------------------------------- ### 搜索框 Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/input/demos/search.md 带有搜索按钮的输入框。搜索时,展示loading。 ```jsx import React, { useState } from 'react'; import { Input, Icon } from 'cloud-react'; import './styles/mix.less' export default function InputDemo() { const placeholder = '请输入关键字搜索'; const suffixIcon = ; const [ value, setValue ] = useState('已输入的内容'); return (
setValue(e.target.value)} hasClear />
); } ``` -------------------------------- ### Basic Usage of Cloud-React Tips Component Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/tips/demos/basic-tips.md This React component demonstrates the fundamental usage of the `Tips` component from the `cloud-react` library. It showcases various message types (default, warning, major, success), the display of icons, and how to apply custom styles like `maxWidth` to the tips. It also illustrates rendering React nodes as message content, including emphasized text. ```jsx /** * title: 基础用法 * desc: */ import React from 'react'; import { Tips } from 'cloud-react'; import './styles/basic-tips.less'; class TipsDemo extends React.Component { render() { const tipsWidth = { maxWidth: '300px' }; const msgReactNode = ( 重要长显显示信息强调文字变色 ); return (
); } } export default TipsDemo; ``` -------------------------------- ### CTable Row Disabling Example Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/c-table/demos/disabled0.md This React JSX example illustrates how to use the `CTable` component from `cloud-react` to display tabular data. It specifically demonstrates how to mark certain rows as disabled by including `disabled: true` in their data objects. The example also covers defining columns, handling asynchronous data fetching, and integrating the table within a `Modal` component. ```jsx /** * title: 表格禁用行 * desc: 表格禁用行(设置 disabled: true 的形式) */ import React from 'react'; import { CTable, Modal, Button } from 'cloud-react'; const data = [ { id: '121410327', name: '手机号优先继续发送1', createTime: '2021/12/14 10:19:02', creator: 'liyuan.meng', disabled: true }, { id: '121410328', name: 'ouid疲劳度3', createTime: '2021/12/13 15:47:33 ', creator: 'jiaojiao.diao' }, { id: '121410329', name: '继续发送手机1', createTime: '2021/12/13 15:36:42', creator: 'nan.run' }, { id: '121408294', name: '继续发送手机2', createTime: '2021/12/13 11:14:40', creator: 'xiaotong.fan' }, { id: '121407191', name: '继续发送手机3', createTime: '2021/12/13 11:03:05', creator: 'zhenxiao.guo' }, { id: '121407192', name: '继续发送手机4', createTime: '2021/12/13 11:03:07', creator: 'han.wu' }, { id: '121407193', name: '继续发送手机5', createTime: '2021/12/13 11:03:34', creator: 'yue.ren' }, { id: '121407194', name: '继续发送手机6', createTime: '2021/12/13 11:03:05', creator: 'wanjuan.dong', disabled: true }, { id: '121407195', name: '继续发送手机7', createTime: '2021/12/13 11:03:55', creator: 'ying.yan' }, { id: '121407196', name: '继续发送手机8', createTime: '2021/12/13 11:03:23', creator: 'xian.yong' } ]; const columns = [ { title: '活动ID', dataIndex: 'id', align: 'left' }, { title: '活动名称', dataIndex: 'name', align: 'left' }, { title: '创建时间', dataIndex: 'createTime', render: val => { return } }, { title: '创建人', dataIndex: 'creator', align: 'left' } ]; function CTableDemo(props) { return ( { return new Promise(resolve => { setTimeout(() => { resolve({ totals: data.length, data: JSON.parse(JSON.stringify(data.slice(params.pageSize * (params.pageNum - 1), params.pageSize * params.pageNum))) }); }, 500) }) }} /> ) } function CTableModal(props) { return ( ); } export default function Demo() { return (
) } ``` -------------------------------- ### Build Documentation Source: https://github.com/shuyunff2e/cloud-react/blob/master/README.md This command compiles and builds the project's documentation. It generates static files that can be deployed or viewed locally, providing comprehensive project information. ```bash $ npm run docs:build ``` -------------------------------- ### 分体式表格 Source: https://github.com/shuyunff2e/cloud-react/blob/master/src/components/c-table/demos/splitTable.md 单独控制 表格、分页 和 加载 逻辑,使用起来更加灵活。可以解决表格查询参数通过异步获取,表格需要等待参数获取完再加载,否则查询错误的问题。详见DEMO:【需求】状态下拉列表是异步获取,交互要求默认展示第一条数据。【常规写法】为了保证表格只做一次查询并且查询参数是状态列表的第一条数据,如果使用原来的组合式表格,就需要等状态列表返回后再渲染表格,会导致表格区域有短暂的空白(接口慢的话空白时间会更长);【分体写法】如果使用分体式表格,则不存在这种问题。详细可查看 DEMO 代码 ```jsx import React, { useState, useEffect } from 'react'; import { CTable, Pagination, Select, Form } from 'cloud-react'; const fetchData = ({ pageNum, pageSize }) => { return new Promise(resolve => { setTimeout(() => { resolve({ data: new Array(pageSize).fill(1).map((item, index) => ( { id: 121410327 + pageNum + index, name: `手机号优先继续发送${pageNum + index}`, createTime: '2021/12/14 10:19:02', creator: 'liyuan.meng', num: 12222, orderNum: '33,342', status: index % 2 === 0 ? '生效': '失效' } )), totals: 30 }) }, 500) }) } const fetchStatusList = () => { return new Promise(resolve => { setTimeout(() => { resolve([ { label: '生效', value: 1 }, { label: '失效', value: 2 } ]) }, 500) }) } const columns = [ { title: '活动ID', dataIndex: 'id', width: 130 }, { title: '活动名称', dataIndex: 'name', width: 140, render: val => { return } }, { title: '创建时间', dataIndex: 'createTime', width: 140, render: val => { return } }, { title: '人数', dataIndex: 'num', align: 'right', width: 120, render: val => }, { title: '创建人', dataIndex: 'creator', width: 130 } ]; export default function CTableDemo() { const [queryParams, setQueryParams] = useState({ status: 1, pageNum: 1, pageSize: 10 }) const [loading, setLoading] = useState(false); const [statusList, setStatusList] = useState([]); const [ajaxData, setAjaxData] = useState({ data: [], totals: 0 }); useEffect(() => { // 获取状态下拉列表 fetchStatusList().then(res => { setStatusList(res); setQueryParams({ ...queryParams, status: res[0].value }) }) }, []); useEffect(() => { setLoading(true); if (queryParams.status) { // 查询参数变化,则更新表格数据 console.log('查询数据', queryParams); fetchData(queryParams).then(res => { setAjaxData({ data: res.data, totals: res.totals }) }).finally(() => { setLoading(false); }) } }, [JSON.stringify(queryParams)]) const onPageChange = (current, pageSize) => { setQueryParams({ ...queryParams, pageNum: current, pageSize, }) } return (