The primary button is used for the most important button on the page. Secondary buttons can be used for actions that are less important. Button links can be helpful for buttons that do not need a lot of attention drawn to them. Disabled buttons are used when you don't want the user to click the button. Danger buttons are used to indicate destructive actions such as deleting.
import React from "react" import { Button } from "playbook-ui" const ButtonDefault = (props) => ( <div> <Button marginRight='lg' onClick={() => alert("button clicked!")} tabIndex={0} text='Button Primary' />{" "} <Button marginRight='lg' onClick={() => alert("button clicked!")} tabIndex={0} text='Button Secondary' variant='secondary' />{" "} <Button marginRight='lg' onClick={() => alert("button clicked!")} tabIndex={0} text='Button Link' variant='link' /> <Button disabled marginRight='lg' onClick={() => alert("button clicked!")} tabIndex={0} text='Button Disabled' /> <Button marginRight='lg' onClick={() => alert("button clicked!")} tabIndex={0} text='Button Danger' variant='danger' /> </div> ) export default ButtonDefault
The reaction
variant accepts any HTML Emoji or it's hexa/decimal ref (see here) as a string within the icon
prop. If nothing is passed to the icon prop, the default reaction button will be displayed as seen in the third example. The default reaction button will also be rendered if a Fontawesome icon (not an Emoji) is passed to the icon
prop of a reaction
variant, but the default "smiley +" icon will be replaced with the named icon.
Reaction buttons also accept two additional (optional) props: count
, which accepts a number (i.e., a count of reactions) to be displayed next to the Emoji; and highlight
, which is a boolean that if true, displays the 'active' state for the button. Click the first reaction button to see this in action!
import React, {useState} from "react" import { Button } from "playbook-ui" const ButtonReaction = (props) => { const [highlightActive, setHighlightActive] =useState(false) const reactionCount = 153 return ( <div> <Button count={highlightActive ? (reactionCount + 1) : reactionCount} highlight = {highlightActive} icon="🎉" onClick={()=> setHighlightActive(!highlightActive)} tabIndex={0} variant="reaction" /> <Button count={5} icon="1️⃣" marginLeft='lg' tabIndex={0} variant="reaction" /> <Button marginLeft='lg' tabIndex={0} variant="reaction" /> <Button icon="user" marginLeft='lg' tabIndex={0} variant="reaction" /> </div> ) } export default ButtonReaction
This button is used many times for mobile or other things like cards and sidebars.
The link
prop accepts a string that is used as an href value and causes the button to act as a link. The default behavior of a link is to open in the current window. You can optionally alter the link behavior by adding the newWindow
prop (boolean), which will open the link in a new window, or by calling the target
prop, which accepts _self
, _blank
, _parent
, _top
, child
, or any string, allowing you to specify any link target.
import React from 'react' import { Button } from 'playbook-ui' const ButtonLink = (props) => ( <> <Button aria={{ label: 'Link to Google' }} link="https://google.com" marginRight='lg' tabIndex={0} text="A Tag Button" /> {' '} <Button aria={{ label: 'Link to Google in new window' }} link="https://google.com" marginRight='lg' newWindow tabIndex={0} text="Open in New Window" /> {' '} <Button aria={{ label: 'Link to Playbook in new window' }} link="https://playbook.powerapp.cloud/" marginRight='lg' tabIndex={0} target='child' text="Open in a Child Tab" /> {' '} <Button aria={{ label: 'Disabled link to Google' }} disabled link="https://google.com" marginRight='lg' tabIndex={0} text="A Tag Button Disabled" /> </> ) export default ButtonLink
Used when a button will take a little while to load. The spinner lets the user know that the button has worked and it is in the process of loading.
import React from 'react' import { Button } from 'playbook-ui' const ButtonLoading = (props) => ( <div> <Button aria={{ label: 'Loading' }} loading marginRight='lg' text="Button Primary" /> {' '} <Button aria={{ label: 'Loading' }} loading marginRight='lg' tabIndex={0} text="Button Secondary" variant="secondary" /> {' '} <Button aria={{ label: 'Loading' }} loading marginRight='lg' tabIndex={0} text="A Tag Button Disabled" variant="link" /> </div> ) export default ButtonLoading
Used when the user wants to display custom content within a button instead of passing in text or props to the kit itself. In this example the button is using the Pill kit and a <span>
element inside the button.
import React from "react"; import { Button, Pill } from "playbook-ui"; const ButtonBlockContent = (props) => ( <div> <Button fixedWidth tabIndex={0} > <Pill marginRight="xs" text="5" variant="info" /> <span>Button with Block Content</span> </Button> </div> ); export default ButtonBlockContent;
Icons can also be added to a button if needed. By default, the icon will be displayed on the left of the text. To display the icon on the right, use the optional prop of iconRight
in react or icon_right
in rails.
import React from 'react' import { Button } from 'playbook-ui' const ButtonIconOptions = (props) => ( <div> <Button fixedWidth icon='plus' marginRight='lg' tabIndex={0} text="Icon on Left" /> {' '} <Button fixedWidth icon='chevron-right' iconRight marginRight='lg' tabIndex={0} text="Icon on Right" /> </div> ) export default ButtonIconOptions
By default button has the md
size style, even if you don't explicitly pass a size prop.
import React from 'react' import { Button } from 'playbook-ui' const ButtonSize = (props) => ( <div> <Button marginRight='lg' size="sm" tabIndex={0} text="Button sm size" /> {' '} <Button marginRight='lg' size="md" tabIndex={0} text="Button md size" /> {' '} <Button marginRight='lg' size="lg" tabIndex={0} text="Button lg size" /> </div> ) export default ButtonSize
import React from "react" import { Button } from "playbook-ui" const ButtonHover = (props) => ( <div> <div> <Button hover={{ shadow: "deep" }} marginRight='lg' marginTop='xl' onClick={() => alert("button clicked!")} tabIndex={0} text='Shadow Deep' />{" "} <Button hover={{ shadow: "deeper" }} marginRight='lg' marginTop='xl' onClick={() => alert("button clicked!")} tabIndex={0} text='Shadow Deeper' variant='secondary' />{" "} <Button hover={{ shadow: "deepest" }} marginRight='lg' marginTop='xl' onClick={() => alert("button clicked!")} tabIndex={0} text='Shadow Deepest' variant='link' /> </div> </div> ) export default ButtonHover
import React from 'react' import { Button, ButtonToolbar } from 'playbook-ui' const ButtonToolbarDefault = (props) => ( <div className="pb--doc-demo-row"> <ButtonToolbar orientation="vertical" > <Button text="Create" /> <Button text="Edit" /> <Button text="Copy" /> <Button text="Cut" /> </ButtonToolbar> <ButtonToolbar orientation="horizontal" > <Button text="Create" /> <Button text="Edit" /> <Button text="Copy" /> <Button text="Cut" /> </ButtonToolbar> </div> ) export default ButtonToolbarDefault
import React from 'react' import { Button, ButtonToolbar } from 'playbook-ui' const ButtonToolbarSecondary = (props) => ( <div className="pb--doc-demo-row"> <ButtonToolbar orientation="vertical" variant="secondary" > <Button text="Create" variant="secondary" /> <Button text="Edit" variant="secondary" /> <Button text="Copy" variant="secondary" /> <Button text="Cut" variant="secondary" /> </ButtonToolbar> <ButtonToolbar orientation="horizontal" variant="secondary" > <Button text="Create" variant="secondary" /> <Button text="Edit" variant="secondary" /> <Button text="Copy" variant="secondary" /> <Button text="Cut" variant="secondary" /> </ButtonToolbar> </div> ) export default ButtonToolbarSecondary
import React from 'react' import CircleIconButton from 'playbook-ui' const CircleIconButtonDefault = (props) => ( <div> <CircleIconButton icon="plus" variant="primary" /> <br /> <CircleIconButton icon="pen" variant="secondary" /> <br /> <CircleIconButton disabled icon="times" /> <br /> <CircleIconButton icon="user" variant="link" /> </div> ) export default CircleIconButtonDefault
import React from 'react' import CircleIconButton from 'playbook-ui' const CircleIconButtonLink = (props) => ( <div> <CircleIconButton icon="search" link="https://google.com" variant="primary" /> <br /> <CircleIconButton icon="window" link="https://google.com" newWindow variant="secondary" /> </div> ) export default CircleIconButtonLink
import React from 'react' import CircleIconButton from 'playbook-ui' const CircleIconButtonLoading = (props) => ( <div> <CircleIconButton icon="plus" loading variant="primary" /> <br /> <CircleIconButton icon="pen" loading variant="secondary" /> <br /> <CircleIconButton disabled icon="times" loading /> <br /> <CircleIconButton icon="user" loading variant="link" /> </div> ) export default CircleIconButtonLoading