question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactor certain components that set css classes with dynamic values to have explicit prop types

See original GitHub issue

For example the Identifier.js component sets the class fd-identifier--${size} however, the size variables prop type validation is size: PropTypes.string. Ideally this would be an explicit range of values so that consumers are warned if they provide a value to to size that isn’t valid css. There are a few options to do this, but at SAP Concur we have abstracted out these values into arrays in their own file like so

...
export const MESSAGEBAR_TYPES = [
    'success',
    'info',
    'warning',
    'error'
];

export const MESSAGEBOX_TYPES = [
    'confirm',
    'error',
    'info',
    'success',
    'warning'
];

export const BUTTON_TYPES = [
    'default',
    'primary',
    'secondary',
    'create',
    'success',
    'info',
    'warning',
    'danger',
    'link'
];
...

and then we import them into components where they are needed.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
chrismancierocommented, Jan 22, 2019

👍 Sounds like a good idea.

0reactions
mobot11commented, Jan 24, 2019

@droshev I still think we can move forward with this piece of work. If we end up having to change / remove some of the values we will able to change them in a central location instead of having to dig through all of the separate components.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Props and PropTypes | Mastering React Native
The PropTypes module comes with functions for validating different value types, such as string , number , and func . Here, what we...
Read more >
How To Customize React Components with Props
In this step, you'll add a light type system to your components with PropTypes . PropTypes act like other type systems by explicitly...
Read more >
Dynamically build classnames in TailwindCss - Stack Overflow
Basically I define a const with the basic configuration for the different props and apply those to the component. It's a bit more...
Read more >
andreipfeiffer/css-in-js: A thorough analysis of all the ... - GitHub
Props generics, where applicable (get type-safe access to component props types when defining dynamic styles);. ⬆️ to overview. 6. & ctx (Contextual Styles)....
Read more >
Annotating React Styled Components with TypeScript -- newline
styled-components comes up with a unique class name for each set of CSS rules, feeds the CSS to a CSS preprocessor (Stylis), places...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found