-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Icon house keeping updates #16621
Merged
Merged
Icon house keeping updates #16621
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
ui/components/component-library/icon/__snapshots__/icon.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Icon should render correctly 1`] = ` | ||
<div> | ||
<div | ||
class="box mm-icon mm-icon--size-md box--flex-direction-row box--color-inherit" | ||
data-testid="icon" | ||
style="mask-image: url('./images/icons/icon-add-square-filled.svg');" | ||
/> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
import { SIZES } from '../../../helpers/constants/design-system'; | ||
|
||
/** | ||
* The ICON_NAMES object contains all the possible icon names. | ||
* It is generated using the generateIconNames script in development/generate-icon-names.js | ||
* and stored in the environment variable ICON_NAMES | ||
* To add a new icon, add the icon svg file to app/images/icons | ||
* Ensure the svg has been optimized, is kebab case and starts with "icon-" | ||
* See "Adding a new icon" in ./README.md for more details | ||
* | ||
* Search for an icon: https://metamask.github.io/metamask-storybook/?path=/story/ui-components-component-library-icon-icon-stories-js--default-story | ||
* | ||
* Add an icon: https://metamask.github.io/metamask-storybook/?path=/docs/ui-components-component-library-icon-icon-stories-js--default-story#adding-a-new-icon | ||
* | ||
* ICON_NAMES is generated using svgs in app/images/icons and | ||
* the generateIconNames script in development/generate-icon-names.js | ||
* then stored as an environment variable | ||
*/ | ||
|
||
/* eslint-disable prefer-destructuring*/ // process.env is not a standard JavaScript object, so we are not able to use object destructuring | ||
export const ICON_NAMES = JSON.parse(process.env.ICON_NAMES); | ||
export const ICON_SIZES = { | ||
XXS: SIZES.XXS, | ||
XS: SIZES.XS, | ||
SM: SIZES.SM, | ||
MD: SIZES.MD, | ||
LG: SIZES.LG, | ||
XL: SIZES.XL, | ||
AUTO: SIZES.AUTO, | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding ICON_SIZES to curate sizes passed to storybook controls and propTypes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ import { | |
ICON_COLORS, | ||
} from '../../../helpers/constants/design-system'; | ||
|
||
import { ICON_SIZES } from './icon.constants'; | ||
|
||
export const Icon = ({ | ||
name, | ||
size = SIZES.MD, | ||
|
@@ -21,15 +23,15 @@ export const Icon = ({ | |
return ( | ||
<Box | ||
color={color} | ||
className={classnames(className, 'icon', `icon--size-${size}`)} | ||
className={classnames(className, 'mm-icon', `mm-icon--size-${size}`)} | ||
style={{ | ||
/** | ||
* To reduce the possibility of injection attacks | ||
* the icon component uses mask-image instead of rendering | ||
* the svg directly. | ||
*/ | ||
maskImage: `url('./images/icons/icon-${name}.svg`, | ||
WebkitMaskImage: `url('./images/icons/icon-${name}.svg`, | ||
maskImage: `url('./images/icons/icon-${name}.svg')`, | ||
WebkitMaskImage: `url('./images/icons/icon-${name}.svg')`, | ||
...style, | ||
}} | ||
{...props} | ||
|
@@ -44,10 +46,10 @@ Icon.propTypes = { | |
name: PropTypes.string.isRequired, // Can't set PropTypes.oneOf(ICON_NAMES) because ICON_NAMES is an environment variable | ||
/** | ||
* The size of the Icon. | ||
* Possible values could be 'SIZES.XXS', 'SIZES.XS', 'SIZES.SM', 'SIZES.MD', 'SIZES.LG', 'SIZES.XL', | ||
* Default value is 'SIZES.MD'. | ||
* Possible values could be SIZES.XXS (10px), SIZES.XS (12px), SIZES.SM (16px), SIZES.MD (20px), SIZES.LG (24px), SIZES.XL (32px), | ||
* Default value is SIZES.MD (20px). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding pixel values for sizes in propType comments |
||
*/ | ||
size: PropTypes.oneOf(Object.values(SIZES)), | ||
size: PropTypes.oneOf(Object.values(ICON_SIZES)), | ||
/** | ||
* The color of the icon. | ||
* Defaults to COLORS.INHERIT. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.icon { | ||
.mm-icon { | ||
--icon-size: var(--size, 16px); | ||
|
||
font-size: var(--icon-size); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Updating description here in hopes of directing engineers to the search icon page in storybook