-
Notifications
You must be signed in to change notification settings - Fork 2
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 all icons and add new Icon component #221
Conversation
Remove mis-named `collapsed.svg`
Add a new Icon component to supersede SvgIcon in the future. It solves several challenges with SvgIcon, including: 1. Naming convention/casing 2. Layout challenges to do with `display` and inability to customize wrapping element classes in the past 3. Consistency with props API (`classes`, `containerClasses`)
I decided to investigate who was the guilty party here 😛. hypothesis/client@d2a8e58 |
I've never been so glad to be the idiot :) . Saves me an hour or two of proving that it shouldn't be that way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, after introducing the this new Icon
component, we will phase out SvgIcon
over time.
Should we mark the SvgIcon
component as deprecated?
import { availableIcons, registerIcons, registerIcon } from '../SvgIcon'; | ||
import { Icon } from '../Icon'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { availableIcons, registerIcons, registerIcon } from '../SvgIcon'; | |
import { Icon } from '../Icon'; | |
import { Icon } from '../Icon'; | |
import { availableIcons, registerIcons, registerIcon } from '../SvgIcon'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels to me that the functions declare in SvgIcon
belong to the Icon
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree, assuming we accept that Icon
is the "icon component of record" going forward. There's some follow-up work here, which I'll summarize in a separate comment.
}); | ||
|
||
it("sets the element's content to the content of the SVG", () => { | ||
const container = document.createElement('div'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
container
could be set on the beforeEach
for all tests.
import { Card, Icon, registerIcon } from '../../../'; | ||
import * as iconSrc from '../../../icons'; | ||
|
||
const icons = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I prefer the use of Map
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand a little?
<Library.Page title="Icons"> | ||
<Library.Pattern title="Hypothesis icon set"> | ||
<div className="LibraryGrid"> | ||
{Object.keys(icons).map(iconName => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{Object.keys(icons).map(iconName => ( | |
{Object.entries(icons).map(([iconName, iconSymbol]) => ( |
or if you use a Map
:
{[...icons].map(([iconName, iconSymbol])
width: 1em; | ||
height: 1em; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a developer wants to make the SVG larger than 16x16 pixels, how should he/she do it? Modifying the container style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of two ways:
- Do something that sets the inherited font size to the desired icon size, by e.g. applying a style to a containing element.
- Use the
classes
prop onIcon
to apply a class style with width-height overrides.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably we will also have some utility styles specifically for sizing icons/text in the near future, too.
Remove unused classnames from SVG icons, leaving only those classes that are directly used by applications.
Codecov Report
@@ Coverage Diff @@
## main #221 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 15 16 +1
Lines 243 260 +17
Branches 89 95 +6
=========================================
+ Hits 243 260 +17
Continue to review full report at Codecov.
|
Plan for follow-up:
I'll track these items separately. |
@esanzgar All of your feedback comments have shown up twice in this thread, so I hope I responded to at least the important ones and haven't missed anything major! Thanks! |
This PR tackles two important tasks:
Icon
component to alleviate a few longstanding issues1. Consolidating and exporting Icons
The first commit here brings in the source of all of the icons in the old pattern library collection as well as a few scattered icons from our applications.
It provides a new module,
icons
, so that external apps can use these icons. An external application could do something like:2.
Icon
componentThe new
Icon
component has a few aims, while not deviating too much from the existingSvgIcon
implementation:SvgIcon
doesn't match our conventions).classes
,containerClasses
, e.g.)Regarding the styling issues that I believe this relieves, let's see if I can articulate.
SvgIcon (Background)
The
SvgIcon
component sets classes on the wrappingspan
. This results in one of two possibilities:<span className="Hyp-SvgIcon">
— in this (default) case,display
is set toflex
. This has a side effect of being somewhat unexpected, and also resetsflex
layouts in unexpected ways. To get around that, we implemented:<span className="Hyp-SvgIcon--inline">
— which is the result if one sets the propinline={true}
. In this case,display
is set toinline
. This prevents the component from resetting flex and puts it the inline flow, but inline elements cannot have width and height set reliably. The common result from this is a few phantom pixels:In the example above, the desired width is 16x16px (1em here) but the height ends up being 18px. This is an artifact of the inline display.
With
SvgIcon
, the author can provide aclassName
prop, which will apply class(es) to the SVG element, but there is no way to manipulate the styling on the wrappingspan
, which has led to pain over time.SvgIcon
doesn't give any sizing cues to the icon, leaving that to the author to wrangle by overriding default styling using theclassName
prop.Icon (new component)
The
Icon
component takes a different default styling approach. It leaves browser defaults in place for the wrappingspan
element (inline), and sets thesvg
element to haveblock
display. It defaults to a1em
sizing, which makes the icon size scale to the current textual context by default.The result is that the component renders inline and does not incur any block-level distractions (margins, padding, unexpectedly) or interruptions of flex layouts.
Authors can control styles on both the SVG element itself (via
classes
) and/or the wrappingspan
(containerClasses
). Theinline
prop is no longer needed.See it in play
A basic representation of all of the icons, using the new
Icon
component, can be seen on this branch in a new page in the pattern library. It's basic, but a starting point:Fixes #151
Fixes #218