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

PropTypes when adding the title #268

Closed
julien51 opened this issue Jan 17, 2019 · 2 comments
Closed

PropTypes when adding the title #268

julien51 opened this issue Jan 17, 2019 · 2 comments

Comments

@julien51
Copy link

julien51 commented Jan 17, 2019

🚀 Feature Proposal

Having the ability to add a title prop is a very useful feature. We also use fairly strict linting rules which require us to add propTypes on any React component. It would be great when using --title-prop to have the ability to add the corresponding propType.

I understand that one could use --template for this, but since --title-prop exists, we may as well complete that feature.

Motivation

This would make the component pass when eslint-ing with strict rules.

Example

svgr --title-prop --title-prop-type string --title-defafult-prop "" would generate something like

import React from 'react'
import PropTypes from 'prop-types'

const SvgComponent = ({ title, ...props }) => (
  <svg width="1em" height="1em" viewBox="0 0 48 1" {...props}>
    <title>{title}</title>
    <path d="M0 0h48v1H0z" fill="currentColor" fillRule="evenodd" />
  </svg>
)

SvgComponent.propTypes = {
  title: PropTypes.string,
}


SvgComponent.defaultProps = {
  title: "",
}

export default SvgComponent

Pitch

It would be a good addition to the --title-prop

I am happy to try submitting a patch if this is approved!

@gregberge
Copy link
Owner

Hmm, maybe we could change the API to be able to accept children, see #88 (comment). I think it could match your need isn't it?

@gregberge
Copy link
Owner

Hello @julien51, prop-types will not be integrated in the project. If you want to use them, I suggest you to create a custom template.

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

No branches or pull requests

2 participants