-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added card actionIcon prop with 'dismiss' and 'overflow'
- Loading branch information
1 parent
dfc009c
commit 304143b
Showing
7 changed files
with
194 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.DS_Store | ||
.eslintcache | ||
.prettierrc | ||
node_modules | ||
npm-debug.log | ||
coverage | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import { IconButton, Icon } from '..'; | ||
import { Close, MoreVert } from '../../icons'; | ||
|
||
const CardActionIcon = React.forwardRef( | ||
({ | ||
className, | ||
actionIcon, | ||
onClick, | ||
isActive, | ||
variant, | ||
}, ref) => { | ||
if (actionIcon === 'overflow') { | ||
return ( | ||
<div | ||
className={classNames( | ||
className, | ||
'd-flex flex-wrap pgn__card-close-container', | ||
)} | ||
ref={ref} | ||
> | ||
<IconButton | ||
src={MoreVert} | ||
iconAs={Icon} | ||
alt="See more" | ||
onClick={onClick} | ||
variant={variant} | ||
invertColors={variant === 'dark'} | ||
isActive={isActive} | ||
className="mr-2" | ||
/> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div | ||
className={classNames( | ||
className, | ||
'd-flex flex-wrap pgn__card-close-container', | ||
)} | ||
ref={ref} | ||
> | ||
<IconButton | ||
src={Close} | ||
iconAs={Icon} | ||
alt="Close" | ||
onClick={onClick} | ||
variant={variant} | ||
invertColors={variant === 'dark'} | ||
isActive={isActive} | ||
className="mr-2" | ||
/> | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
CardActionIcon.propTypes = { | ||
/** Specifies class name to append to the base element. */ | ||
className: PropTypes.string, | ||
/** Options for which type of actionIcon the Card will use. */ | ||
actionIcon: PropTypes.oneOf(['overflow', 'dismiss']), | ||
/** Click handler for the button */ | ||
onClick: PropTypes.func, | ||
/** whether to show the `IconButton` in an active state, whose styling is distinct from default state */ | ||
isActive: PropTypes.bool, | ||
/** The visual style of the dialog box */ | ||
variant: PropTypes.oneOf(['default', 'warning', 'danger', 'success', 'dark']), | ||
}; | ||
|
||
CardActionIcon.defaultProps = { | ||
className: undefined, | ||
actionIcon: 'dismiss', | ||
onClick: () => {}, | ||
isActive: false, | ||
variant: 'dark', | ||
}; | ||
|
||
export default CardActionIcon; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import CardActionIcon from '../CardActionIcon'; | ||
|
||
describe('<CardActionIcon />', () => { | ||
it('renders without props', () => { | ||
const tree = renderer.create(( | ||
<CardActionIcon /> | ||
)).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
it('renders with "overflow" option for actionIcon prop', () => { | ||
const tree = renderer.create(( | ||
<CardActionIcon actionIcon="overflow" /> | ||
)).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<CardActionIcon /> renders with "overflow" option for actionIcon prop 1`] = ` | ||
<div | ||
className="d-flex flex-wrap pgn__card-close-container" | ||
> | ||
<button | ||
aria-label="See more" | ||
className="btn-icon btn-icon-inverse-dark btn-icon-md mr-2" | ||
onClick={[Function]} | ||
type="button" | ||
> | ||
<span | ||
className="btn-icon__icon-container" | ||
> | ||
<span | ||
className="pgn__icon btn-icon__icon" | ||
> | ||
<svg | ||
aria-hidden={true} | ||
fill="none" | ||
focusable={false} | ||
height={24} | ||
role="img" | ||
viewBox="0 0 24 24" | ||
width={24} | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
</span> | ||
</span> | ||
</button> | ||
</div> | ||
`; | ||
|
||
exports[`<CardActionIcon /> renders without props 1`] = ` | ||
<div | ||
className="d-flex flex-wrap pgn__card-close-container" | ||
> | ||
<button | ||
aria-label="Close" | ||
className="btn-icon btn-icon-inverse-dark btn-icon-md mr-2" | ||
onClick={[Function]} | ||
type="button" | ||
> | ||
<span | ||
className="btn-icon__icon-container" | ||
> | ||
<span | ||
className="pgn__icon btn-icon__icon" | ||
> | ||
<svg | ||
aria-hidden={true} | ||
fill="none" | ||
focusable={false} | ||
height={24} | ||
role="img" | ||
viewBox="0 0 24 24" | ||
width={24} | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
</span> | ||
</span> | ||
</button> | ||
</div> | ||
`; |