Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .bitmap
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/* THIS IS A BIT-AUTO-GENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */

{
"guya-ltd.gcss/atoms/button@0.0.1": {
"guya-ltd.gcss/atoms/button@0.0.7": {
"files": [
{
"name": "Button.js",
"relativePath": "src/components/atoms/Button/Button.js",
"test": false,
"name": "Button.js"
"test": false
},
{
"name": "ButtonLink.js",
"relativePath": "src/components/atoms/Button/_Link/ButtonLink.js",
"test": false,
"name": "ButtonLink.js"
"test": false
},
{
"name": "ButtonIcon.js",
"relativePath": "src/components/atoms/Button/__Icon/ButtonIcon.js",
"test": false,
"name": "ButtonIcon.js"
"test": false
},
{
"name": "index.js",
"relativePath": "src/components/atoms/Button/index.js",
"test": false,
"name": "index.js"
"test": false
}
],
"mainFile": "src/components/atoms/Button/index.js",
Expand Down
45 changes: 40 additions & 5 deletions src/components/atoms/Button/Button.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withNaming } from '@bem-react/classname'
import { withNaming } from '@bem-react/classname';
import { classnames } from '@bem-react/classnames';

import ButtonLink from './_Link/ButtonLink';
import ButtonIcon from './__Icon/ButtonIcon';
Expand All @@ -24,19 +25,33 @@ import ButtonIcon from './__Icon/ButtonIcon';
class Button extends Component {
render() {
/* Props */
const {bsPrefix, children, size, type, href, icon} = this.props;
const {bsPrefix, children, size, type, href, icon, theme, variant, block, onClick} = this.props;

/* Class name generator */
const cn = withNaming({ e: '__', m: '', v: '--' })

/* Set base classname */
let classname = cn(bsPrefix)

/* Theme name */
const themeName = theme ? 'theme-' + theme : null

/* Block name */
const blockName = block ? 'block' : null;

/* Classnames */
const classnametext = classnames(
classname({'': size}),
classname({'': variant}),
classname({'': blockName}),
themeName
);

if(href && type === 'link')
return <ButtonLink cn={classname} children={children} href={href} />
return <ButtonLink cn={classname} size={size} variant={variant} theme={themeName} children={children} href={href} />
else
return (
<button type={type} className={classname({'': size})}>
<button type={type} className={classnametext} onClick={onClick}>
{!!(icon)? <ButtonIcon cn={classname} icon={icon} /> : null}
{children}
</button>
Expand Down Expand Up @@ -80,7 +95,26 @@ Button.propTypes = {
* @property {node}
* @default null
*/
icon: PropTypes.node
icon: PropTypes.node,
/**
* @description Theme.
* @enum {('theme-red'|'theme-royal-blue')}
* @default null
*/
theme: PropTypes.oneOf(['theme-red', 'theme-royal-blue']),
/**
* @description Variant colors.
* @enum {('primary'|'success'|'warning'|'danger')}
* @default null
*/
variant: PropTypes.oneOf(['primary', 'success', 'warning', 'danger']),
block: PropTypes.bool,
/**
* @description On click function
* @property {element}
* @default null
*/
onClick: PropTypes.element,
}

Button.defaultProps = {
Expand All @@ -90,6 +124,7 @@ Button.defaultProps = {
type: 'button',
href: null,
icon: null,
theme: null,
}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/components/atoms/Button/_Link/ButtonLink.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { classnames } from '@bem-react/classnames';

/**
* A Button Link component represents an object or entity.
Expand All @@ -16,9 +17,15 @@ import React from 'react';
* @example
*/

const ButtonLink = ({cn, href, children}) => {
const ButtonLink = ({cn, theme, href, children, size, variant}) => {
/* Class names collection */
const classname = cn({'': 'link'})
const classname = classnames(
cn({'': 'link'}),
cn({'': size}),
cn({'': variant}),
theme
)


return <a href={href} className={classname}>{children}</a>
}
Expand Down