Guest User

Untitled

a guest
Jan 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. const rtlTextContainer = {
  2. getAttributes: (arg) => {},
  3. createFor: (content, options) => null
  4. }
  5.  
  6. /////////////////
  7.  
  8. // Button
  9.  
  10. class Button extends UIComponent<ReactProps<ButtonProps>, ButtonState> {
  11.  
  12. public renderComponent({
  13. ElementType,
  14. classes,
  15. accessibility,
  16. variables,
  17. styles,
  18. unhandledProps,
  19. rtlAttributes,
  20. }): React.ReactNode {
  21. const { children, content, disabled, iconPosition } = this.props
  22. const hasChildren = childrenExist(children)
  23.  
  24. return (
  25. <ElementType
  26. className={classes.root}
  27. disabled={disabled}
  28. onClick={this.handleClick}
  29. onFocus={this.handleFocus}
  30. {...accessibility.attributes.root}
  31. {...rtlTextContainer.getAttributes({ forChildren: children /* sloppy, but just as an example */ })} // <---
  32. {...unhandledProps}
  33. >
  34. {hasChildren && children}
  35. {!hasChildren && iconPosition !== 'after' && this.renderIcon(variables, styles)}
  36. {Box.create(!hasChildren && content, {
  37. defaultProps: { as: 'span', styles: styles.content },
  38. })}
  39. {!hasChildren && iconPosition === 'after' && this.renderIcon(variables, styles)}
  40. </ElementType>
  41. )
  42. }
  43. ...
  44. }
  45. export default Button
  46.  
  47. ///////////////////
  48.  
  49. // Header
  50. class Header extends UIComponent<ReactProps<HeaderProps>, any> {
  51. renderComponent({ ElementType, classes, variables: v, unhandledProps, rtlAttributes }) {
  52. const { children, description, content } = this.props
  53.  
  54. const hasChildren = childrenExist(children)
  55. const contentElement = childrenExist(children) ? children : content
  56. return (
  57.  
  58. // here we are consuming attributes
  59. <ElementType {...rtlTextContainer.getAttributes({ if: !description })} {...unhandledProps} className={classes.root}>
  60. {rtlTextContainer.createFor(contentElement, { if: description} )} // <------ here we are creating element
  61. {!hasChildren &&
  62. HeaderDescription.create(description, {
  63. defaultProps: {
  64. variables: {
  65. ...(v.descriptionColor && { color: v.descriptionColor }),
  66. },
  67. },
  68. })}
  69. </ElementType>
  70. )
  71. }
  72. }
  73.  
  74. export default Header
Add Comment
Please, Sign In to add comment