Button Group
import {QButtonGroup} from "@qui/react"
Overview
A Button Group is a grouping of buttons whose actions are related to each other.
Examples
Showcase
Button Groups are composed of QButton or QIconButton components.
import {ReactNode} from "react"import {Files, Image, User} from "lucide-react"import {QButton, QButtonGroup, QIconButton} from "@qui/react"export default function Showcase(): ReactNode {return (<div className="grid justify-items-center gap-4"><QButtonGroup variant="outline"><QButton startIcon={User}>Profile</QButton><QButton startIcon={Image}>Images</QButton><QButton startIcon={Files}>Files</QButton></QButtonGroup><QButtonGroup variant="outline"><QIconButton aria-label="User" icon={User} /><QIconButton aria-label="Images" icon={Image} /><QIconButton aria-label="Files" icon={Files} /></QButtonGroup></div>)}
Styles
import {ReactNode} from "react"import {Files, Image, User} from "lucide-react"import {QButton, QButtonGroup} from "@qui/react"export default function Styles(): ReactNode {return (<div className="grid justify-center gap-4"><QButtonGroup variant="ghost"><QButton startIcon={User}>Profile</QButton><QButton startIcon={Image}>Images</QButton><QButton startIcon={Files}>Files</QButton></QButtonGroup><QButtonGroup variant="outline"><QButton startIcon={User}>Profile</QButton><QButton startIcon={Image}>Images</QButton><QButton startIcon={Files}>Files</QButton></QButtonGroup><QButtonGroup variant="fill"><QButton startIcon={User}>Profile</QButton><QButton startIcon={Image}>Images</QButton><QButton startIcon={Files}>Files</QButton></QButtonGroup></div>)}
Orientations
The orientation property controls the layout of the buttons in the group. The default is horizontal
, but vertical
is also available.
import {ReactNode} from "react"import {Files, Image, User} from "lucide-react"import {QButton, QButtonGroup} from "@qui/react"export default function Orientation(): ReactNode {return (<div className="grid justify-center"><QButtonGroup orientation="vertical" variant="outline"><QButton startIcon={User}>Profile</QButton><QButton startIcon={Image}>Images</QButton><QButton startIcon={Files}>Files</QButton></QButtonGroup></div>)}
Sizes
Customize size using the size property.
xs
s
m
import {ReactNode} from "react"import {Files, Image, User} from "lucide-react"import {QButton, QButtonGroup} from "@qui/react"export default function Sizes(): ReactNode {return (<div className="grid gap-4"><div className="flex"><div className="flex w-16 items-center text-primary q-font-heading-xs">xs</div><QButtonGroup size="xs" variant="outline"><QButton startIcon={User}>Profile</QButton><QButton startIcon={Image}>Images</QButton><QButton startIcon={Files}>Files</QButton></QButtonGroup></div><div className="flex"><div className="flex w-16 items-center text-primary q-font-heading-xs">s</div><QButtonGroup size="s" variant="outline"><QButton startIcon={User}>Profile</QButton><QButton startIcon={Image}>Images</QButton><QButton startIcon={Files}>Files</QButton></QButtonGroup></div><div className="flex"><div className="flex w-16 items-center text-primary q-font-heading-xs">m</div><QButtonGroup size="m" variant="outline"><QButton startIcon={User}>Profile</QButton><QButton startIcon={Image}>Images</QButton><QButton startIcon={Files}>Files</QButton></QButtonGroup></div></div>)}
Selection Mode
Buttons within a group are selectable by default. To disable this behavior, set readonly to true.
By default, only one button can be selected at a time. Use the multiple property to enable multiple selection.
API
Props
Name & Description | Option(s) | Default |
---|---|---|
ReactNode | ||
The component used for the root node. It can be a React component or
element. |
| 'div' |
The className property of the Element
interface gets and sets the value of the
class attribute
of the specified element. |
| |
The color of this group's buttons. |
| 'neutral' |
If true, the buttons in this group will render without space in-between. |
| true |
The default selected indices. |
| |
If true, this group's buttons are disabled. |
| false |
The selection state of this group's buttons. Represents the indices of
selected buttons in this group. |
| |
If true, the group will allow more than one button to be active at a time. |
| false |
Callback fired whenever an item is selected or deselected.
|
| |
The orientation of this group's buttons. |
| horizontal |
If true, buttons in this group are not selectable. |
| false |
The size of this group's buttons. |
| 'm' |
The style global attribute
contains CSS styling
declarations to be applied to the element. | CSSProperties | |
The style variant of this group's buttons. |
| ghost |
Type
| ElementType| ComponentType
Default
'div'
Description
The component used for the root node. It can be a React component or
element.
Type
string
Description
The className property of the Element
interface gets and sets the value of the
class attribute
of the specified element.
Type
| 'inherit'| 'neutral'| 'primary'| 'positive'| 'warning'| 'negative'| 'contrast'
Default
'neutral'
Description
The color of this group's buttons.
Type
boolean
Default
true
Description
If true, the buttons in this group will render without space in-between.
Type
number[]
Description
The default selected indices.
Type
boolean
Default
false
Description
If true, this group's buttons are disabled.
Type
number[]
Description
The selection state of this group's buttons. Represents the indices of
selected buttons in this group.
Type
boolean
Default
false
Description
If true, the group will allow more than one button to be active at a time.
Type
(event: SyntheticEvent,index: number,selected: boolean,updatedState: number[],) => void
Description
Callback fired whenever an item is selected or deselected.
- eventThe DOM event that triggered this change, typically a click or keypress.
- indexThe index being selected or deselected.
- selectedWhether the current item is selected as a result of this change.
- updatedStateThe updated state of expanded indices.
Type
| 'horizontal'| 'vertical'
Default
horizontal
Description
The orientation of this group's buttons.
Type
boolean
Default
false
Description
If true, buttons in this group are not selectable.
Type
| 'xs'| 's'| 'm'
Default
'm'
Description
The size of this group's buttons.
Type
CSSProperties
Description
The style global attribute
contains CSS styling
declarations to be applied to the element.
Type
| 'fill'| 'outline'| 'ghost'
Default
ghost
Description
The style variant of this group's buttons.