Skip to content

Conversation

@bbohen
Copy link
Contributor

@bbohen bbohen commented Oct 5, 2017

Thanks for the awesome icons, I saw a chance to contribute with #186 and figured I would open up a PR. It does the following.

  • Grabs the id from the placeholder element and adds it to the toSvg() options parameter.
  • Makes optionsToAttributes() a bit more nullsafe in case id is undefined (or any other attributes that may be added), fixed minor typo.
  • Updates the readme to reflect the change.

Closes #186

Copy link
Member

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

Awesome job! Just left a few minor comments.

src/replace.js Outdated
}

const elementClassAttr = element.getAttribute('class') || '';
const elementId = element.getAttribute('id');
Copy link
Member

Choose a reason for hiding this comment

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

I think this should probably be elementIdAttr to be consistent with elementClassAttr.

combinedOptions.class = addDefaultClassNames(combinedOptions.class, key);

const attributes = optionsToAtrributes(combinedOptions);
const attributes = optionsToAttributes(combinedOptions);
Copy link
Member

Choose a reason for hiding this comment

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

Haha thanks for catching my typo!


Object.keys(options).forEach(key => {
attributes.push(`${key}="${options[key]}"`);
if (options[key]) {
Copy link
Member

Choose a reason for hiding this comment

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

When would options[key] ever be falsey in this context? Object.keys(options) is generating an array of all the keys in the object and we're using forEach to iterate over all the keys. I'm not sure options[key] would ever be undefined.

Copy link
Contributor Author

@bbohen bbohen Oct 5, 2017

Choose a reason for hiding this comment

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

In this case it was the lack of a value for id where element.getAttribute('id') results in null. This doesn't cause any errors but ends up with an eventual id="null" attribute on the SVG element. The only other situation where I could see this being falsey is if someone was to pass a null value for an option when using replace or toSvg.

I could instead check if id has a value before passing it as an option to toSvg, let me know if that would be preferable here.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. I didn't think about that. I think this is fine!

Copy link
Member

Choose a reason for hiding this comment

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

It may be a good idea to use TypeScript to catch these kinds of bugs 😄

Copy link
Member

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

Thanks so much, @bbohen! This looks great 👍

@colebemis colebemis merged commit e80f805 into feathericons:master Oct 11, 2017
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.

Copy id's from placeholder element to created svg

2 participants