Skip to content

Commit

Permalink
return CloseButton for Button with close prop
Browse files Browse the repository at this point in the history
- add CloseButton disabled example
- remove variant black
  • Loading branch information
illiteratewriter authored and davidacevedo committed Jun 7, 2022
1 parent 1ac89a3 commit 681558a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
18 changes: 12 additions & 6 deletions src/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useCallback } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules, tagPropType } from './utils';
import CloseButton from './CloseButton';

const propTypes = {
active: PropTypes.bool,
Expand Down Expand Up @@ -54,13 +55,20 @@ function Button(props) {
...attributes
} = props;

if (close) {
return (
<CloseButton
{...attributes}
/>
)
}

const btnOutlineColor = `btn${outline ? '-outline' : ''}-${color}`;

const classes = mapToCssModules(classNames(
className,
close && 'btn-close',
close || 'btn',
close || btnOutlineColor,
'btn',
btnOutlineColor,
size ? `btn-${size}` : false,
block ? 'd-block w-100' : false,
{ active, disabled: props.disabled }
Expand All @@ -70,16 +78,14 @@ function Button(props) {
Tag = 'a';
}

const defaultAriaLabel = close ? 'Close' : null;

return (
<Tag
type={(Tag === 'button' && attributes.onClick) ? 'button' : undefined}
{...attributes}
className={classes}
ref={innerRef}
onClick={onClick}
aria-label={ariaLabel || defaultAriaLabel}
aria-label={ariaLabel}
/>
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/CloseButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ const propTypes = {
active: PropTypes.bool,
'aria-label': PropTypes.string,
onClick: PropTypes.func,
variant: PropTypes.oneOf(['white', 'black'])
variant: PropTypes.oneOf(['white'])
}

const defaultProps = {
variant: 'black',
'aria-label': 'close'
}

Expand Down
1 change: 1 addition & 0 deletions stories/CloseButton.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export default {

export { default as CloseButton } from './examples/CloseButton';
export { default as CloseButtonWhite } from './examples/CloseButtonWhite';
export { default as CloseButtonDisabled } from './examples/CloseButtonDisabled';
export { default as Props } from './examples/CloseButtonProps';
9 changes: 9 additions & 0 deletions stories/examples/CloseButtonDisabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import { CloseButton } from 'reactstrap';

const Example = (args) => {
return (
<CloseButton disabled />
)
}
export default Example;

0 comments on commit 681558a

Please sign in to comment.