Primer Buttons
Buttons are used for actions, like in forms, while textual hyperlinks are used for destinations, or moving from one page to another.
This repository is a module of the full primer repository.
Install
This repository is distributed with npm. After installing npm, you can install primer-buttons
with this command.
$ npm install --save primer-buttons
Usage
The source files included are written in Sass (scss
) You can simply point your sass include-path
at your node_modules
directory and import it like this.
;
You can also import specific portions of the module by importing those partials from the /lib/
folder. Make sure you import any requirements along with the modules.
Build
For a compiled css version of this module, a npm script is included that will output a css version to build/build.css
The built css file is also included in the npm package.
$ npm run build
Documentation
Buttons are used for actions, like in forms, while textual hyperlinks are used for destinations, or moving from one page to another.
{:toc}
Default button
Use the standard—yet classy—.btn
for form actions and primary page actions. These are used extensively around the site.
When using a <button>
element, always specify a type
. When using a <a>
element, always add role="button"
for accessibility.
Button buttonLink button
You can find them in two sizes: the default .btn
and the smaller .btn-sm
.
ButtonSmall button
Primary button
Primary buttons are green and are used to indicate the primary action on a page. When you need your buttons to stand out, use .btn.btn-primary
. You can use it with both button sizes—just add .btn-primary
.
Primary buttonSmall primary button
Danger button
Danger buttons are red. They help reiterate that the intended action is important or potentially dangerous (e.g., deleting a repo or transferring ownership). Similar to the primary buttons, just add .btn-danger
.
Danger buttonSmall danger button
Outline button
Outline buttons downplay an action as they appear like boxy links. Just add .btn-outline
and go.
Outline buttonOutline button
Large button
Use .btn-large
to increase the padding and border radius of a button. This is useful for prominent calls to action in hero sections.
Type scale utilities can be used to alter the font-size if needed. Padding is applied in em's so that it scales proportionally with the font-size.
Large link button Large button button
Use .btn-large
with a type scale utility to transform the text to a bigger size.
Large link button Large button button
Disabled state
Disable <button>
elements with the boolean disabled
attribute and <a>
elements with the .disabled
class.
Disabled buttonDisabled button
Similar styles are applied to primary, danger, and outline buttons:
Disabled buttonDisabled button
Disabled buttonDisabled button
Disabled buttonDisabled button
Block button
Make any button full-width by adding .btn-block
. It adds width: 100%;
, changes the display
from inline-block
to block
, and centers the button text.
Block buttonSmall block button
Link button
Create a button that looks like a link with .btn-link
. Rather than using an <a>
to trigger JS, this style on a <button>
should be used for better accessibility.
The .btn-link
class is not designed to be used with .btn
; the overlapping styles are not compatible.
Link button
Button with counts
You can easily append a count to a small button. Add the .with-count
class to the .btn-sm
and then add the .social-count
after the button.
Be sure to clear the float added by the additional class.
Watch 6
You can also use the counter component within buttons:
Button 12 Button 12 Button 12 Button 12
Button groups
Have a hankering for a series of buttons that are attached to one another? Wrap them in a .BtnGroup
and the buttons will be rounded and spaced automatically.
Button Button Button Button Button Button Button Button Button
Add .BtnGroup-parent
to parent elements, like <form>
s or <details>
s, within .BtnGroup
s for proper spacing and rounded corners.
Button Button in a form Button Button
Hidden text button
Use .hidden-text-expander
to indicate and toggle hidden text.
…
You can also make the expander appear inline by adding .inline
.
Using button styles with the details summary element
You can add .btn
and .btn-*
classes to any
<summary>
element so that it gains the appearance of a button, and
selected/active styles when the parent
<details>
element is open.
Toggle the content This content will be toggled.