Description
The Button component should be used as the primary call-to-action in a form, or as a user interaction mechanism.
Variants and sizes
There should never be more than one primary
button in a given context; secondary
and tertiary
button variants do not have this constraint. Generally speaking, a button should not be used when a link would suffice.
The Button component comes in different sizes.
For variant primary, the recommended sizes are default
and large
.
For variant secondary, the recommended sizes are default
and large
.
For variant tertiary, the recommended size is default
. A variant with icon_position="top"
is also available for use.
It is not recommended to use the tertiary button without an icon. Looking for a similar variant without an icon? You might want to check out Anchor instead.
For variant signal, the recommended sizes are default
and large
.
Icon buttons come in all sizes.
Demos
Primary button
<Buttontext="Primary button with text only"on_click={() => {console.log('on_click')}}/>
Secondary button
<Buttonvariant="secondary"onClick={() => {console.log('onClick')}}>Secondary button with text only</Button>
Primary button with icon
<Button text="Primary button with icon" icon="chevron_right" />
Primary button with icon on left
<Button icon_position="left" icon="chevron_left">Primary button with icon on left</Button>
Tertiary button
The tertiary button variant does support newlines while the icon is placed top aligned. You can enable multiline support with the wrap
property.
<Buttonvariant="tertiary"text="Tertiary button with icon on left"icon_position="left"icon="chevron_left"/><Buttonvariant="tertiary"text={<span>Text inside additional span</span>}icon_position="left"icon="chevron_left"right="1rem"/>
Tertiary button with top placed icon.
<Buttonvariant="tertiary"icon_position="top"icon="close"text="Button text"/><Buttonvariant="tertiary"icon_position="top"icon="close"text="Large button"size="large"/>
Tertiary button with long text and text wrap
enabled.
<Buttonwrapvariant="tertiary"text="A long text where wrap is enabled magnis rutrum netus neque ridiculus euismod sit dictum laoreet libero"icon="chevron_left"icon_position="left"/>
Anchor button
<Buttontext="Primary with href"href="/uilib/components/button/demos"icon_position="right"icon="chevron_right"on_click={({ event }) => {event.preventDefault()}}right/><Buttonvariant="secondary"text="Secondary with href"href="/uilib/components/button/demos"target="_blank"right/><Buttonhref="/uilib/components/button/demos"title="This is a link"icon="chevron_right"size="default"right/>
Disabled buttons
<Button text="Disabled primary button" disabled right /><Buttontext="Disabled secondary button"variant="secondary"disabledright/><Buttontext="Disabled tertiary button"variant="tertiary"disabledright/><Button title="Disabled Icon Button" icon="calendar" disabled right />
Error state
Buttons can have an error state
<Button text="Primary button error" status="error" /><Buttontext="Secondary button error"variant="secondary"status="error"left/><Buttontitle="Primary icon button error"variant="primary"icon={question}size="default"status="error"left/><Buttontitle="Secondary icon button error"icon={question}size="default"status="error"left/>
Signal button
Medium is equivalent to 24, but responsive. To import custom icons, use: import { bell_medium as Bell } from '@dnb/eufemia/icons'
<Buttonvariant="signal"text="Signal Button"icon={Bell}/>
Large Signal button
Large Signal button with medium sized icon. To import custom icons, use: import { bell_medium as Bell } from '@dnb/eufemia/icons'
<Buttonvariant="signal"text="Large Signal Button"icon={<Bell />}size="large"icon_size="medium"/>
Icon button
<Buttontitle="Disabled Icon only Button"icon="calendar"disabledright/><Buttontitle="Button with Icon only"icon="calendar"/><Button title="Small sized icon button" icon="add" size="small" left /><Buttontitle="Large sized icon button"icon={question}size="large"left/><Buttontitle="Icon button with status"icon={question}status="error"left/>
Custom button content
This is, as all of the demos, only an example of how to achieve various needs, and not that you should do it.
<Buttonicon="close"icon_position="right"text="Button with custom content"custom_content={<IconPrimary icon="check" right="small" />}/>