Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color indicator component #10209

Merged
merged 5 commits into from
Jan 22, 2021
Merged

Add color indicator component #10209

merged 5 commits into from
Jan 22, 2021

Conversation

brad-decker
Copy link
Contributor

@brad-decker brad-decker commented Jan 18, 2021

Depends on: #10213

Adds a color indicator component that will replace all instances of circle colors in the app. A future pull request will use the color indicator and replace:

  1. Network indicator color in the app bar
  2. Network indicator in network dropdown
  3. Network indicator in confirmation pages
  4. Network indicator on the network settings page.
  5. Connected accounts indicator

colorindicator

@brad-decker brad-decker changed the base branch from develop to add-chip-component January 18, 2021 22:05
@brad-decker brad-decker changed the title improve design system scss Add color indicator component Jan 19, 2021
@brad-decker brad-decker force-pushed the add-color-indicator branch 2 times, most recently from 578f838 to ba48b77 Compare January 19, 2021 16:23
@brad-decker brad-decker force-pushed the add-chip-component branch 2 times, most recently from 7b859b5 to 3baa8dd Compare January 19, 2021 18:06
@brad-decker brad-decker changed the base branch from add-chip-component to add-scss-path January 19, 2021 18:18
@metamaskbot
Copy link
Collaborator

Builds ready [a90b44c]
Page Load Metrics (490 ± 30 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30544484
domContentLoaded3305404886330
load3325414906330
domInteractive3305394886330

Base automatically changed from add-scss-path to develop January 20, 2021 15:58
@brad-decker brad-decker marked this pull request as ready for review January 20, 2021 16:00
@brad-decker brad-decker requested a review from a team as a code owner January 20, 2021 16:00
@metamaskbot
Copy link
Collaborator

Builds ready [a3528a1]
Page Load Metrics (602 ± 59 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint359356147
domContentLoaded35889060112359
load36089160212359
domInteractive35889060012359

.storybook/main.js Outdated Show resolved Hide resolved
@metamaskbot
Copy link
Collaborator

Builds ready [58e4c35]
Page Load Metrics (559 ± 44 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint35675184
domContentLoaded3318275579244
load3338285599244
domInteractive3318275579244

@metamaskbot
Copy link
Collaborator

Builds ready [2a7db8d]
Page Load Metrics (643 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint518764105
domContentLoaded37886364213665
load37986564313665
domInteractive37786364113665

@metamaskbot
Copy link
Collaborator

Builds ready [1a63ff0]
Page Load Metrics (511 ± 36 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint40625073
domContentLoaded3385745097436
load3405755117436
domInteractive3385735097436

}
}

// separate iterator to ensure borderColor takes precedence
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When testing this locally in storybook, it seems that this border-color never actually has precedence. I'm just seeing the color-indicator--color-{variant} border color 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, no, it's only broken when I set the border colour to one of the ERROR colours.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see - there's a mistake in the design system constants. I can fix that in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ColorIndicator.propTypes = {
color: PropTypes.oneOf(Object.values(COLORS)),
borderColor: PropTypes.oneOf(Object.values(COLORS)),
size: PropTypes.oneOf(['small', 'medium', 'large']),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It'd be nice to use constants for these as well, and for the type PropType declaration.

ui/app/css/utilities/_colors.scss Outdated Show resolved Hide resolved
* Calculate the luminance for a color.
* See https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
*/
@function luminance($color) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this is a pretty complex function!

I did some Google-ing about this and stumbled across this interesting post: https://css-tricks.com/programming-sass-to-create-accessible-color-combinations/
They reported that when using this method:

Unfortunately, calculating only a handful of color contrast combinations increased Sass build times exponentially

But they managed to solve it more performantly in the end using a lookup table.

Not saying we should optimize this now before it becomes a problem, but... this is something to consider if we notice a slowdown.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm going to leave a note in the code about this. I think that the expensive part of the operation was the custom pow function that didn't exist in older versions of sass. To get around this some implementations implemented functions that do many loops. Since then, math.pow is a language level feature (https://github.com/sass/dart-sass/releases/tag/1.25.0). I tried to find any mentions of it's performance, but came up empty.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah neat, TIL.

brad-decker and others added 2 commits January 22, 2021 10:06
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
@brad-decker
Copy link
Contributor Author

Ready for you again, @Gudahtt! Thanks for the code review.

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I'm excited to have that choose-contrast-color function available now, that's pretty rad

@metamaskbot
Copy link
Collaborator

Builds ready [f70f9e4]
Page Load Metrics (572 ± 37 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint45665663
domContentLoaded3556505717737
load3566515727737
domInteractive3546505707737

@brad-decker brad-decker merged commit a036b0e into develop Jan 22, 2021
@brad-decker brad-decker deleted the add-color-indicator branch January 22, 2021 21:45
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants