Advertisement
Guest User

Button Example

a guest
Apr 27th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react'
  2. // libs
  3. import { object, func, string } from 'prop-types'
  4. // components
  5. import RaisedButton from 'material-ui/RaisedButton'
  6. // helpers
  7. import get from 'lodash/get'
  8. // context
  9. import palette from 'context/palette'
  10.  
  11. const backgroundColors = {
  12.   blue: palette.main[10],
  13.   lightBlue: palette.main[26],
  14.   white: palette.white,
  15.   green: palette.main[29],
  16.   orange: palette.main[687],
  17.   red: palette.main[688]
  18. }
  19.  
  20. const fontWeights = {
  21.   white: '500',
  22.   blue: '400'
  23. }
  24.  
  25. const templateColors = {
  26.   blue: { backgroundColor: backgroundColors.blue, textColor: backgroundColors.white },
  27.   white: { backgroundColor: backgroundColors.white, textColor: backgroundColors.lightBlue },
  28.   green: { backgroundColor: backgroundColors.green, textColor: backgroundColors.white },
  29.   orange: { backgroundColor: backgroundColors.orange, textColor: backgroundColors.white },
  30.   red: { backgroundColor: backgroundColors.red, textColor: backgroundColors.white }
  31. }
  32.  
  33. const labelCommonStyle = { fontSize: 13, fontFamily: 'Roboto, sans-serif' }
  34.  
  35. const getColor = (templateColor, color, element) => {
  36.   return get(templateColors, `[${templateColor}][${element}]`) || color || templateColors.blue[element]
  37. }
  38.  
  39. const RaisedButtonComponent = ({ label, bgColor, labelColor, labelStyle, style, onClick, templateColor, ...rest }) => (
  40.   <RaisedButton
  41.     label={label}
  42.     backgroundColor={getColor(templateColor, bgColor, 'backgroundColor')}
  43.     labelColor={getColor(templateColor, labelColor, 'textColor')}
  44.     labelStyle={{ ...labelCommonStyle, ...labelStyle, fontWeight: fontWeights[templateColor] || '400' }}
  45.     style={style}
  46.     onClick={onClick}
  47.     {...rest}
  48.   />
  49. )
  50.  
  51. RaisedButtonComponent.propTypes = {
  52.   label: string.isRequired,
  53.   bgColor: string,
  54.   labelColor: string,
  55.   templateColor: string,
  56.   labelStyle: object,
  57.   style: object,
  58.   onClick: func
  59. }
  60.  
  61. RaisedButtonComponent.defaultProps = {
  62.   labelStyle: {},
  63.   onClick: () => ''
  64. }
  65.  
  66. export default RaisedButtonComponent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement