Refactor certain components that set css classes with dynamic values to have explicit prop types
See original GitHub issueFor 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:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
👍 Sounds like a good idea.
@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.