Code
基础排版基于 Bootstrap 5 的行内代码组件,用于在文本中展示代码片段、命令与变量名,配合 pre 元素可呈现代码块,样式随父元素字号缩放
Component Demo
Basic usage and examples of the Code component
基础用法
在文档中引用行内代码,例如 Array.from() 方法。
命令与包名
使用 npm install 安装 react-bootstrap 依赖包。
代码块
import { Button } from '@dafengzhen/react-bootstrap';
const App = () => <Button variant="primary">Hello</Button>;与按键组件对比
复制使用 ctrl + c,安装依赖使用 npm install。
API Documentation
Complete API reference for the Code component
Props
| 属性名 | 类型 | 默认值 | 描述 |
|---|---|---|---|
as | ElementType | 'code' | 渲染的根元素类型,可传入 `span`、`pre` 等以复用代码样式 |
children | ReactNode | - | 代码内容 |
className | string | - | 自定义类名 |
...rest | HTMLAttributes | - | 根元素的所有原生属性(如 `title`、`style` 等) |
Type Definitions
CodeProps
行内代码组件属性接口
export interface CodeProps extends HTMLAttributes<HTMLElement> {
as?: ElementType;
children?: ReactNode;
className?: string;
}