UNPKG

react-components-library

Version:
68 lines (54 loc) 1.87 kB
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 'use strict'; var React = require('react'); var classNames = require('classnames'); var _ = require('lodash'); var Link = React.createClass({ displayName: 'Link', propTypes: { linkType: React.PropTypes.oneOf(['primary', 'secondary', 'tertiary']), linkSize: React.PropTypes.oneOf(['small', 'medium', 'large']), disabled: React.PropTypes.bool, href: React.PropTypes.string, leftIcon: React.PropTypes.string, rightIcon: React.PropTypes.string }, getDefaultProps: function getDefaultProps() { return { linkSize: 'small', linkType: 'primary' }; }, render: function render() { return React.createElement( 'a', this.getProps(), this.props.children ); }, getProps: function getProps() { var props = _.extend({}, this.props, { className: this.getClass() }); return props; }, getClass: function getClass() { var linkSize = this.props.linkSize; var linkType = this.props.linkType; var classes = { 'link': true, 'link_disabled': this.props.disabled, 'link_primary': linkType === 'primary', 'link_secondary': linkType === 'secondary', 'link_tertiary': linkType === 'tertiary', 'link_small': linkSize === 'small', 'link_medium': linkSize === 'medium', 'link_large': linkSize === 'large' }; classes[this.props.className] = this.props.className; return classNames(classes); } }); module.exports = Link;