Button
Button 使用户能够通过一次点击执行操作并做出选择。
使用
Disabled
Sizes
Radius
Colors
Variants
Loading
添加 loading
属性,可在 Button 内部显示一个加载指示器组件。
您还可以通过 spinner
属性自定义加载指示器组件。
With Icons
通过设置 startIcon
或 endIcon
属性,向 Button 添加图标。
Icon Only
添加 IconOnly
属性,可显示一个仅图标而无文本的 Button。
API
Button Props
Button Props 默认继承 as
的 Props,其 as
默认为 HTML button
标签。
Prop | Type | Default | Description |
---|---|---|---|
children | ReactNode | - | Button 的内容。 |
color | 'blue'|'orange'|'yellow'|'ryan'|'red'|'green'|'pick'|'purple'|'gray' | 'blue' | Button 的颜色。 |
variants | 'filled|'outlined'|'text'|'link' | 'filled' | Button 的外观样式。 |
size | 'sm'|'md'|'lg' | 'md' | Button 的大小。 |
radius | 'sm'|'md'|'lg'|'full' | size | Button 的 BorderRadius。 |
disabled | boolean | false | Button 是否禁用。 |
loading | boolean | false | Button 是否处于加载状态。 |
fullWidth | boolean | false | Button 是否应占据其父元素的全部宽度。 |
iconOnly | boolean | false | Button 是否应具有相同的宽度和高度。 |
startIcon | ReactNode | - | 放置在子元素之前的元素。 |
endIcon | ReactNode | - | 放置在子元素之后的元素。 |
spinner | ReactNode | - | 加载状态时的加载指示器。 |
spinnerPlacement | 'start'|'end' | 'start' | 加载指示器的位置。 |
disableRipple | boolean | - | 是否禁用 Button 点击后的 Ripple 效果。 |
href | string | - | 点击跳转的地址,指定此属性 button 的行为和 a 链接一致。 |
target | string | - | 相当于 a 链接的 target 属性,href 存在时生效。 |
className | ClassValue | - | 用于根元素的 className。 |
ref | Ref | - | 用于转发根元素。 |
as | ElementType | 'button' | 用于根元素的组件。可以是表示 HTML 元素的字符串,也可以是一个组件。 |
sx | CSSObject|CSSObject[]|(ownerState: OwnerState) => CSSObject | CSSObject[]) | - | 用于根元素的 sx 属性。 |
classes | Partial<Record<Slots, ClassValue>> | - | Button Slots 的 className。 |
slotProps | Partial<Record<Slots, ComponentPropsWithRef>> | - | Button Slots 的 props。 |
Button Slots
Slot Name | Class Name | Default Component | Description |
---|---|---|---|
startIcon | .nui-btn-start-icon | 'span' | Button 子元素之前图标的容器。 |
endIcon | .nui-btn-end-icon | 'span' | Button 子元素之后图标的容器。 |
最后更新时间