Skip to content

Implement Button component #45357

Closed

Description

@huyenltnguyen

Current specs

  • Border width: 3px
  • Font: Roboto Mono, monospace
  • Variants:
    • Primary
    • Info
    • Danger (on the Setting page)
    • Link (on the donation modal)
  • Sizes:
    • Large
    • Medium (default)
    • Small
  • States:
    • Disabled
    • Hover state
  • Button types:
    • type="button"
    • type="submit"
  • Themes:
    • Light
    • Dark
  • Can be a link (supports href prop)
  • Can be used as a block (stretch)
  • Supports text + icon
  • Accepts ARIA attributes

What's missing

  • Loading state
  • Focus outline
  • Active state

Screenshots

Usage Light theme Dark theme
Primary Screen Shot 2022-03-06 at 17 14 06 Screen Shot 2022-03-06 at 17 13 43
Primary hovered Screen Shot 2022-03-06 at 17 51 27 Screen Shot 2022-03-06 at 17 50 55
Primary disabled Screen Shot 2022-03-06 at 17 51 20 Screen Shot 2022-03-06 at 17 51 08
Danger Screen Shot 2022-03-06 at 17 21 12 Screen Shot 2022-03-06 at 17 21 46
Danger hovered Screen Shot 2022-03-06 at 17 52 59 Screen Shot 2022-03-06 at 17 53 16
Link Screen Shot 2022-03-07 at 18 24 47 Screen Shot 2022-03-07 at 18 27 00
Link hovered Screen Shot 2022-03-07 at 18 24 41 Screen Shot 2022-03-07 at 18 27 06
Info Screen Shot 2022-03-26 at 18 51 45 Screen Shot 2022-03-26 at 18 51 27
Info hovered Screen Shot 2022-03-26 at 18 54 35 Screen Shot 2022-03-26 at 18 54 44

Implementation plan

Use the bootstrap v3.3.7 stylesheet for styling references.

Props interface

Prop Type Required Default Note
variant 'primary' | 'danger' | 'link' 'primary'
size 'large' | 'medium' | 'small' 'medium'
type 'submit' | 'button' 'button'
disabled boolean Use aria-disabled under the hood (ref)
loading boolean
loadingText string Required if loading is true
block boolean
onClick React.MouseEventHandler
href string Render an a instead of a button element if this prop is defined

Spacing and typography

The current values of font size, line height, and padding from Bootstrap seem a bit strange to me, as there are some odd numbers in there, which I think would add some challenges in scaling/positioning. Now that we switch to Tailwind, my proposal is to adopt its system and slightly adjust the styling of our component.

Size Current New
Small padding: 5px 10px
font-size: 16px
line-height: 1.5
padding: 4px 10px
font-size: 16px
line-height: 1.5
Medium padding: 6px 12px
font-size: 18px
line-height: 1.42857143
padding: 6px 12px
font-size: 18px
line-height: 1.42857143
Large padding: 10px 16px
font-size: 23px
line-height: 1.3333333
padding: 10px 16px
font-size: 24px
line-height: 1.3333333

References:

What's not included

Component Screenshot Why
Call to action button Screen Shot 2022-03-06 at 17 33 33 Should be a standalone component, since its styling is dissimilar to the normal button
Dropdown button Screen Shot 2022-03-06 at 17 45 50 Should be a standalone component with the support for menu items built in

Rough delivery plan

(TBU)

Activity

  1. added
    scope: tools/scripts
    status: PR in works
    on Mar 6, 2022
  2. self-assigned this
    on Mar 6, 2022
  3. ahmaxed commented on Mar 7, 2022

    @ahmaxed
    Member

    Thanks for taking on the button component and for listing our buttons and their states.

    In the past we styled the buttons' active, hover, and focus states to override Boostrap's styles.

    It might be a good idea to include the active and focus states in the styles as well and replace them with more representative styles on the next iteration.

    Note: we also have a less obvious button that we use the in modal 'btn-link'

    default:
    Screen Shot 2022-03-07 at 11 30 48 AM

    Hover
    Screen Shot 2022-03-07 at 11 32 05 AM

  4. huyenltnguyen commented on Mar 7, 2022

    @huyenltnguyen
    MemberAuthor

    Thanks @ahmadabdolsaheb!

    I have updated the original post. My plan is to have a dedicated PR just for the button states, since there are a lot to cover.

    I have added link to the variant list that we need to support. This just reminded me that the accessibility aspect will be very interesting, since there are some differences in the behaviors of button and link. For example, if the component is used as a link and is disabled, we will need to render a button tag instead of an a, since semantically links cannot be disabled 😄

  5. ahmaxed commented on Mar 7, 2022

    @ahmaxed
    Member

    The reason that is called link button is that it looks like an active element, but does not steal attention from the donation buttons.

    After the bootstrap migration is complete, and the custom component migration is complete, we could audit our library.
    Perhaps we could rename it as tertiary or secondary and style it accordingly.

  6. ahmaxed commented on Mar 15, 2022

    @ahmaxed
    Member

    Just a heads up that we have a btn-info in the codebase. The color needs a little work but we can change that later. You could view it in the settings page of the /settings page or in production next week :)

    Screen Shot 2022-03-15 at 4 04 22 PM

  7. ahmaxed commented on Mar 15, 2022

    @ahmaxed
    Member

    Also other than the styles, what are the challenges of having the CTA be in the same component with the rest of the buttons?

  8. ahmaxed commented on Mar 18, 2022

    @ahmaxed
    Member

    There are some custom styles that utilizes bootstrap styles such as.btn.
    We should either include them in the component for now, or re-adjust the custom styles when we move the buttons to production.

  9. huyenltnguyen commented on Mar 20, 2022

    @huyenltnguyen
    MemberAuthor

    Also other than the styles, what are the challenges of having the CTA be in the same component with the rest of the buttons?

    Yeah it's mostly the styles. we don't seem to have a CTA button in dark theme, and the button is currently a link (<a>). I think it would be easier to maintain and develop if we have the component as a separate one, rather than as a variant.

    There are some custom styles that utilizes bootstrap styles such as.btn.
    We should either include them in the component for now, or re-adjust the custom styles when we move the buttons to production.

    Agreed. The custom styles have eaten a lot of my time, as I have to decide whether I should copy-paste the styles or try to map the them to what Tailwind has 😅 I've been opting for the latter, it takes a bit more time but will help reduce code that we have to clean up later.

  10. huyenltnguyen commented on Apr 25, 2022

    @huyenltnguyen
    MemberAuthor

    As noted in #45671 (comment), we will have a Link component that supports the link variant mentioned in the original post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

scope: tools/scriptsstatus: PR in works

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions