Last active
September 21, 2016 17:29
-
-
Save kevinSuttle/fb3d4b33c83e091e7f980dda9ff8df8e to your computer and use it in GitHub Desktop.
Flow, defaultProps, and wrapper classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import React from 'react'; | |
require('./Icon.css'); | |
import * as Glyphs from './Glyphs.jsx'; | |
export type IconProps = { | |
glyph:string, | |
className?: string, | |
title?: string, | |
width?: string, | |
height?: string, | |
}; | |
export default class Icon extends React.Component { | |
static defaultProps = { | |
'className': 'icon', | |
'width': '16', | |
'height': '16', | |
} | |
constructor(props:IconProps){ | |
super(props); | |
} | |
render(){ | |
return( | |
<svg | |
id="icon" | |
className={this.props.className} | |
viewBox={`0 0 ${this.props.width} ${this.props.height}`} | |
aria-labelledby="title" | |
preserveAspectRatio="xMidYMid meet" | |
> | |
<title id={this.props.title}>{this.props.title}</title> | |
{Glyphs[this.props.glyph] || null} | |
</svg> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does
const IconButtonProps = Object.assign(...ButtonProps, ...IconProps)
work? I've never known for sure whetherimport/export type
statements actually create normal JS variables.ButtonProps & IconProps
should work though