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

DRYing out icon code #1562

Closed
wants to merge 2 commits into from
Closed

Conversation

jpdevries
Copy link
Contributor

This PR creates a component for icons so that changes to icons in the future can be made in just one place 💯

Just removes duplication for now but does so as a step
towards #1469

also see #1349 which proposes adding descriptive text to icons (for the toolbar but eventually would be great across the board)

Usage

The Icon component just takes the name of the icon now:

  <Icon icon={this.props.icon} />

You can pass an active property which will add an .active class to the icon.

  <Icon icon={this.props.icon} active={true} />

You can also pass a fixedWidth property which will add a fa-fw class to the icon:

  <Icon icon={this.props.icon} fixedWidth={true} />

or override the iconPrefix:

  <Icon icon={this.props.icon} iconPrefix="foo" />

The Icon component sets the className for you. If for some reason you want to override this, pass a className property.

  <Icon icon={this.props.icon} className={`foo foo-${this.props.icon} foo-bar`} />

This commit just removes duplication for now but does so as a step
towards tootsuite/mastodon/1469

also see tootsuite/mastodon/1349 which proposes adding descriptive text
to icons (for the toolbar but eventually would be great across the
board)
@jpdevries jpdevries mentioned this pull request Apr 11, 2017
1 task
Copy link
Member

@Gargron Gargron left a comment

Choose a reason for hiding this comment

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

I realize this quite a lot of work, but I don't see a lot of benefit to doing this, when aria-labels should be added on buttons and links anyway, and not on the icons themselves (right?)

I fear this could introduce a lot of small bugs like the one I commented on.

@@ -39,7 +40,7 @@ const StatusContent = React.createClass({
} else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false);
} else if (media) {
link.innerHTML = '<i class="fa fa-fw fa-photo"></i>';
link.innerHTML = '<Icon icon="photo" />';
Copy link
Member

Choose a reason for hiding this comment

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

This won't actually work. Icon is not html, it's a react component. It works with i because that is html.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Gargron It works. <Icon> references the icon component just like any of our other components
https://github.com/tootsuite/mastodon/pull/1562/files#diff-38b8991419d1039766d703c68c4a4ebdR3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry @Gargron I stand corrected. I thought that was being parsed by React and assumed you didn't see the new React component. I'll work on fixing that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

went back to the static HTML string in b18d475

so icon code isn't 100% DRY 😞 due to the one spot .innerHTML is used

@jpdevries
Copy link
Contributor Author

jpdevries commented Apr 12, 2017

@Gargron

when aria-labels should be added on buttons and links anyway, and not on the icons themselves (right?)

I assumed so also but see #1349 (comment)

but I don't see a lot of benefit to doing this

See #1469

@Gargron sorry about this one. It looks like I can’t 100% DRY the icon
code out because of innerHTML being used here, so if/when changes are
made to icon code need to remember to make them here too
@ashfurrow
Copy link
Contributor

@jpdevries thanks for the pull request. It looks like it wasn't something that @Gargron wanted to include in the project, and there are a lot of merge conflicts since opening the pull request. I'm going to recommend we close the pull request, but it's totally open for discussion.

@jpdevries
Copy link
Contributor Author

@ashfurrow no problem. if you ever want me to rebase and resubmit it let me know. i think it could be a good step towards a larger theming and accessibility effort and eventually switching to SVG icons #1469

@ashfurrow
Copy link
Contributor

Yup yup, thanks again!

@ashfurrow ashfurrow closed this Apr 30, 2017
ClearlyClaire added a commit to ClearlyClaire/mastodon that referenced this pull request Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants