question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement Button component

See original GitHub issue

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)

  • Remove the stub Button component with a new, basic one (variants and sizes) - #45421
  • Support ref - #45480
  • Add support for info variant - #45541
  • Add support for hover state - #45541
  • Support various button states and theming - #45665
    • Ensure active and focus states are covered
  • Support inline and block usages - #45665
  • Support link usage - #45671
    • Ensure that we render a button instead of an a if disabled is true
  • Build ButtonGroup (probably a low priority since there isn’t a use case for it yet)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
huyenltnguyencommented, Mar 20, 2022

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.

1reaction
ahmadabdolsahebcommented, Mar 15, 2022

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
Read more comments on GitHub >

github_iconTop Results From Across the Web

Building a button component - web.dev
In this post I want to share my thoughts on how to build a color-adaptive, responsive, and accessible <button> element.
Read more >
How to Build a Custom Button Component in React TypeScript
Follow best programming practices by learning how to write a reusable custom button component for a basic TypeScript React project.
Read more >
How to use Button Component in Material UI ? - GeeksforGeeks
Buttons allow users to take actions, and make choices, with a single tap. · Creating React Application And Installing Module: · Step 1:...
Read more >
How to create a React Button - Robin Wieruch
A button may be the first interactive element that you are using in a React component. Therefore, this is a short React tutorial...
Read more >
Creating the Button component | React.js Essentials
Creating the Button component ... The Button component renders a button. You might be wondering what's the benefit of creating a dedicated component...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found