cnd-components-mcp
Version:
An MCP service for Cnd components query | 一个减少 Cnd 组件代码生成幻觉的 MCP 服务,包含系统提示词、组件文档、API 文档、代码示例和更新日志查询
430 lines (416 loc) • 9.34 kB
Markdown
## 示例
```tsx
import React from 'react';
import { Select } from '@alicloud/console-components';
const onChange = (value: any) => {
console.log(value);
};
export const dataSource = [
{
value: '10001',
label: '选项A',
},
{
value: '10002',
label: '选项B',
},
];
const h4Style = {
fontSize: '12px',
marginTop: '24px',
};
export default () => {
return (
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
<div style={{ marginRight: '78px' }}>
<h4 style={h4Style}>默认32px</h4>
<Select
placeholder="请选择"
onChange={onChange}
size="medium"
dataSource={dataSource}
style={{ width: '280px' }}
/>
</div>
<div>
<h4 style={h4Style}>大号36px</h4>
<Select
placeholder="请选择"
onChange={onChange}
size="large"
dataSource={dataSource}
style={{ width: '280px' }}
/>
</div>
<div>
<h4 style={h4Style}>小号24px</h4>
<Select
placeholder="请选择"
onChange={onChange}
size="small"
dataSource={dataSource}
style={{ width: '280px' }}
/>
</div>
</div>
);
};
export const meta = {
title: '尺寸',
describe: '通过设置size属性,设置组件尺寸。',
};
```
```tsx
import React from 'react';
import { Form, Select } from '@alicloud/console-components';
const FormItem = Form.Item;
const onChange = (value: any) => {
console.log(value);
};
const dataSource = [
{
value: '1',
label: '默认项',
},
{
value: '2',
label: '聚焦项',
},
{
value: '3',
label: '选中项',
},
{
value: '4',
label: '默认项',
},
{
value: '5',
label: '失效项',
disabled: true,
},
];
const h4Style = {
fontSize: '12px',
marginTop: '24px',
};
export default () => {
return (
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
<div>
<h4 style={h4Style}>默认</h4>
<Select
placeholder="请选择"
defaultValue="3"
onChange={onChange}
size="medium"
dataSource={dataSource}
style={{ width: '280px' }}
/>
</div>
<div>
<h4 style={h4Style}>禁用</h4>
<Select
placeholder="请选择"
onChange={onChange}
size="medium"
disabled
dataSource={dataSource}
style={{ width: '280px' }}
/>
</div>
<div>
<h4 style={h4Style}>错误</h4>
<Form labelAlign="inset" inline>
<FormItem
validateState="error"
help="错误信息提示文字,上间距4px"
>
<Select
placeholder="内容出错"
state={'error'}
dataSource={dataSource}
style={{ marginTop: 20, width: 280 }}
/>
</FormItem>
</Form>
</div>
</div>
);
};
export const meta = {
title: '基础形态交互',
describe: '设置disabled属性,禁用组件;设置state属性,设置组件状态。',
};
```
```tsx
import React from 'react';
import { Select } from '@alicloud/console-components';
const onChange = (value: any) => {
console.log(value);
};
export const dataSource = [
{
value: '1',
label: '默认项',
},
{
value: '2',
label: '聚焦项',
},
{
value: '3',
label: '选中项',
},
{
value: '4',
label: '选中项',
},
{
value: '5',
label: '默认项',
},
{
value: '6',
label: '失效项',
disabled: true,
},
];
const h4Style = {
fontSize: '12px',
marginTop: '24px',
};
export default () => {
return (
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
<div style={{ marginRight: '78px' }}>
<h4 style={h4Style}>默认</h4>
<Select
placeholder="请选择"
onChange={onChange}
defaultValue={['3', '4']}
dataSource={dataSource}
style={{
width: 280,
}}
mode="multiple"
/>
</div>
<div>
<h4 style={h4Style}>禁用</h4>
<Select
placeholder="请选择"
onChange={onChange}
defaultValue={['3', '4']}
dataSource={dataSource}
style={{
width: 280,
}}
mode="multiple"
disabled
/>
</div>
</div>
);
};
export const meta = {
title: '带多选标签形态交互',
describe: '设置mode值为multiple,选择器为带多选标签形态。',
};
```
```tsx
import React from 'react';
import {
Select,
Input,
Button,
Icon,
Divider,
} from '@alicloud/console-components';
const onChange = (value: any) => {
console.log(value);
};
const dataSource1 = [
{
value: '1',
label: '默认项',
},
{
value: '2',
label: '聚焦项',
},
{
value: '3',
label: '选中项',
},
{
value: '4',
label: '默认项',
},
{
value: '5',
label: '失效项',
disabled: true,
},
];
const dataSource = [
{ label: '内容描述,文案超出长度后允许自动换行,内容描述', value: '1' },
{ label: '内容描述,文案超出长度后允许自动换行,内容描述', value: '2' },
];
const menuProps1 = {
focusable: false,
header: (
<div style={{ padding: '0 4px', textAlign: 'center' }}>
<div style={{ paddingBottom: 4 }}>
<Input
size="small"
placeholder="请输入内容"
label={<Icon type="search" />}
/>
</div>
</div>
),
footer: (
<div style={{ padding: '0 4px', textAlign: 'center', margin: '0 -4px' }}>
<Divider style={{ marginBottom: 0, marginTop: 4 }} />
<Button text type="primary">
Load More...
</Button>
</div>
),
};
const menuProps2 = {
focusable: false,
header: (
<div style={{ padding: '4px 4px 0' }}>
<div style={{ display: 'flex', paddingBottom: 4 }}>
<Input
size="small"
placeholder="请输入内容"
label={<Icon type="search" />}
/>
<Button size="small" style={{ marginLeft: '8px', width: '24px', padding: 0, flexShrink: 0 }}>
<Icon type="arrow_circular" />
</Button>
</div>
</div>
),
footer: (
<div style={{ padding: '0 4px', margin: '0 -4px' }}>
<Divider style={{ marginBottom: 0, marginTop: 4 }} />
<div style={{ paddingLeft: 8 }}>
<Button text type="primary">
前往创建ECS
</Button>
<Icon type="external" />
</div>
</div>
),
};
const menuProps3 = {
focusable: false,
header: (
<div style={{ padding: '4px 4px 0' }}>
<div style={{ display: 'flex', paddingBottom: 4 }}>
<Input
size="small"
placeholder="请输入内容"
label={<Icon type="search" />}
/>
<Button size="small" style={{ marginLeft: '8px', width: '24px', padding: 0, flexShrink: 0 }}>
<Icon type="arrow_circular" />
</Button>
</div>
</div>
),
footer: (
<div style={{ margin: '0 8px' }}>
搜索结果:没有找到相关实例
<Divider style={{ marginBottom: 0, marginTop: 4 }} />
<div>
无实例原因
<p>
1. A原因造成 <a href="#">解决方案a</a>
<br />
2. B原因造成 <a href="#">解决方案b</a>
</p>
</div>
</div>
),
};
export default () => {
return (
<div>
<h4 style={{ fontSize: '12px' }}>默认</h4>
<Select
showSearch
placeholder="请选择"
onChange={onChange}
dataSource={dataSource1}
style={{
width: '280px',
}}
mode="multiple"
menuProps={menuProps1}
/>
<h4 style={{ fontSize: '12px', marginTop: '24px' }}>带刷新搜索默认</h4>
<Select
mode="multiple"
dataSource={dataSource}
style={{ width: '280px' }}
menuProps={menuProps2}
popupAutoFocus
/>
<h4 style={{ fontSize: '12px', marginTop: '24px' }}>带刷新搜索无结果</h4>
<Select
mode="multiple"
style={{ width: '280px' }}
menuProps={menuProps3}
popupAutoFocus
dataSource={[]}
/>
</div>
);
};
export const meta = {
title: '下拉带搜索形态',
describe: '自定义 menuProps 实现下拉带搜索形态',
};
```
## 更多示例
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```
```tsx
```