Button
View in LexiconButtons communicate an action to happen on user interaction.
install | yarn add @clayui/button |
---|---|
version | |
use | import Button from '@clayui/button'; |
Table of Contents
Display Types
You can determine how your button can be displayed using the displayType
property:
If you want use the button as a link set displayType
to link
.
import {Provider} from '@clayui/core'; import Button from '@clayui/button'; import React from 'react'; export default function App() { return ( <Provider spritemap="/icons.svg"> <div className="p-4"> <Button.Group spaced> <Button displayType="primary">Button Primary</Button> <Button displayType="secondary">Button Secondary</Button> <Button displayType="link">Button Link</Button> <Button borderless>Button Borderless</Button> </Button.Group> </div> </Provider> ); }
Group
You can use the variant Button.Group
for creating button groups:
Use the spaced
property to create spacing between buttons.
import {Provider} from '@clayui/core'; import Button from '@clayui/button'; import React from 'react'; export default function App() { return ( <Provider spritemap="/icons.svg"> <div className="p-4"> <Button.Group> <Button>This</Button> <Button displayType="secondary">is</Button> <Button>a</Button> <Button displayType="secondary">button</Button> <Button>group.</Button> </Button.Group> </div> </Provider> ); }
Icon
You can use the high-level component ClayButtonWithIcon
to create a button with only an icon. If you need an icon and text, you need to compose with ClayIcon
import {Provider} from '@clayui/core'; import Button, {ClayButtonWithIcon} from '@clayui/button'; import Icon from '@clayui/icon'; import React from 'react'; export default function App() { return ( <Provider spritemap="/icons.svg"> <div className="p-4"> <ClayButtonWithIcon aria-label="Close" symbol="times" title="Close" /> <Button> <span className="inline-item inline-item-before"> <Icon symbol="times" /> </span> Close w/ text </Button> </div> </Provider> ); }
API Reference
Button
IForwardRef<HTMLButtonElement, IProps>
Parameters
alert
boolean | undefined
Flag to indicate if button is used within an alert component.
borderless
boolean | undefined
Flag to indicate if the button should be borderless.
block
boolean | undefined
Renders the button as a block element.
dark
boolean | undefined
Flag to indicate if the button should use the clay-dark variant.
displayType
DisplayType | undefined
Determines the button variant to use.
The values beta
and beta-dark
are deprecated since v3.100.0 - use
translucent
and dark
instead.
The values null
and unstyled
are for internal use only.
loading
boolean | undefined
Flag to display a loading indicator.
monospaced
boolean | undefined
Flag to indicate if button should be monospaced.
outline
boolean | undefined
Flag to indicate if the button should use the outline variant.
rounded
boolean | undefined
Flag to indicate if the button should be shaped like a pill.
size
"xs" | "regular" | "sm" | undefined
Determines the size of a button.
small
boolean | undefined
Indicates button should be a small variant.
translucent
boolean | undefined
Flag to indicate if the button should use the translucent variant.
Returns
ReactElement<any, string | JSXElementConstructor<any>> | nullClayButtonWithIcon
React.ForwardRefExoticComponent<Pick<Props, "symbol" | "children" | "disabled" | "spritemap" | "value" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "dark" | "displayType" | "translucent" | "alert" | "block" | "borderless" | "loading" | "monospaced" | "outline" | "rounded" | "size" | "small" | "type" | "autoFocus" | "form" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "key"> & React.RefAttributes<HTMLButtonElement>>
Parameters
Properties
symbol *
string
The id of the icon in the spritemap.
spritemap
string | undefined
Path to the location of the spritemap resource.
aria-label *
string | undefined
Define a value that labels the button.
aria-labelledby
string | undefined
dark
boolean | undefined
Flag to indicate if the button should use the clay-dark variant.
displayType
DisplayType | undefined
Determines the button variant to use.
The values beta
and beta-dark
are deprecated since v3.100.0 - use
translucent
and dark
instead.
The values null
and unstyled
are for internal use only.
translucent
boolean | undefined
Flag to indicate if the button should use the translucent variant.
alert
boolean | undefined
Flag to indicate if button is used within an alert component.
block
boolean | undefined
Renders the button as a block element.
borderless
boolean | undefined
Flag to indicate if the button should be borderless.
loading
boolean | undefined
Flag to display a loading indicator.
monospaced
boolean | undefined
Flag to indicate if button should be monospaced.
outline
boolean | undefined
Flag to indicate if the button should use the outline variant.
rounded
boolean | undefined
Flag to indicate if the button should be shaped like a pill.
size
"xs" | "regular" | "sm" | undefined
Determines the size of a button.
small
boolean | undefined
Indicates button should be a small variant.
Returns
ReactElement<any, string | JSXElementConstructor<any>> | nullGroup
{ ({ children, className, role, spaced, vertical, ...otherProps }: Props): JSX.Element; displayName: string; }
Parameters
Properties
spaced
boolean | undefined
Flag to indicate the spacing between the buttons.
vertical
boolean | undefined
Flag to indicate if buttons are stacked vertically.
Returns
ElementContributors
Last edited May 9, 2025 at 6:15:38 AM
Table of Contents