cfpb / capital-framework

The Consumer Financial Protection Bureau's user interface framework
https://cfpb.github.io/capital-framework/
Creative Commons Zero v1.0 Universal
55 stars 29 forks source link

Add `u-svg-inline-bg` mixin for inline SVG background #938

Closed anselmbradford closed 5 years ago

anselmbradford commented 5 years ago

Additions

Removals

Changes

Testing

  1. gulp build && gulp docs && bundle exec jekyll serve should pass and launch the docs.
  2. Visit http://localhost:4000/components/cf-tables/#sortable-tables and compare to https://cfpb.github.io/capital-framework/components/cf-tables/#sortable-tables
  3. Visit http://localhost:4000/components/cf-forms/#select-dropdown and compare to https://cfpb.github.io/capital-framework/components/cf-forms/#select-dropdown
  4. Visit http://localhost:4000/components/cf-forms/#checkboxes-and-radio-inputs and compare to https://cfpb.github.io/capital-framework/components/cf-forms/#checkboxes-and-radio-inputs

Screenshots

Before:

Screen Shot 2019-07-09 at 11 22 34 AM

After:

Screen Shot 2019-07-09 at 11 32 08 AM

Notes

Scotchester commented 5 years ago

Buttons and Pagination use icons in buttons and Expendables use the up and down chevrons in the Show/Hide label.

anselmbradford commented 5 years ago

Buttons and Pagination use icons in buttons and Expendables use the up and down chevrons in the Show/Hide label.

So I wasn't thinking clearly here in respect to cf-buttons etc being installed in isolation, since there are no direct CSS dependencies within those packages, but rather depend on the convention of adding SVG markup within the component with the cf-icon-svg class. However, thinking about this, we have some inconsistencies:

Proposal: What if we converted all icons used within CF components to be inlined SVG in the CSS as data URLs. Here's a commit of what that would look like https://github.com/cfpb/capital-framework/pull/938/commits/be50dbe4e8d3771b079fccf3c68fcd984dd78e6e If we wanted to reference the cf-icon source file, what if we used something similar to https://github.com/atlassian/less-plugin-inline-svg (or a simpler find and replace) in the build step to embed the SVG. The path in the source file would be the default backup, if the developer used a build process that didn't replace them. Thoughts?

sephcoster commented 5 years ago

Unsure if this would all work given LESS and how it handles variables, but if we go this route could we create the data:image/svg+xml;charset=UTF-8,<svg xmlns= strings as @ variables and call them that way to make it easier to reference?

End result might be something like: background: url ( @icon-down-embed )which would reference the embedded SVG.

anselmbradford commented 5 years ago

Okay I've totally re-worked this PR and rebased and force pushed, so throw out what you have and re-pull if checking this again.

I realized we could use a custom less plugin to run JavaScript at build-time to inject the source SVG files inline into the background-image property via a mixin, which this PR adds.

Icons are added two ways: in the markup + CSS styling, and purely via CSS as a background-image. Say all icons were delivered purely via CSS. This offers some interesting trade-offs to consider:

niqjohnson commented 5 years ago

@anselmbradford: @caheberer and I took a look at this, and we're good replacing the custom up/down filled triangles with our standard up/down chevrons in sortable tables. Turns out the reason we didn't go with the chevrons originally was because the old chevrons were thinner and didn't have enough contrast in table headers. The recent re-draw of the icons fixes that issue, so it makes sense to get rid of that custom triangle icon.

One issue we did notice is that the current chevron is sitting a little low in the cell, which is causing a couple of minor visual issues:

Can you vertically center the chevron with the cell's text? I did a quick mockup of that in Photoshop by pushing the chevron (both up and down states) up by 3px to get everything aligned (I added guides to the images to make it a little easier to eyeball things):

State Without guides With guides
Current (down) current current-guides
Pushed up 3px (down) new new-guides
Pushed up 3px (up) flipped flipped-guides

Once that alignment is fixed, this change looks a-ok from a design and UX perspective. Thanks!

anselmbradford commented 5 years ago

@Scotchester @niqjohnson Ready for review again. Thanks!

niqjohnson commented 5 years ago

@anselmbradford: The new alignment in the sortable tables looks perfect to me—thanks. I took a quick look at the other changes, too, and everything looked the same locally as in production (as expected). So this looks 👍 from the design and UX sides.