-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
104 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import Card from '../src/Card' | ||
|
||
describe('Card', () => { | ||
it('should render without crashing', () => { | ||
mount(<Card />) | ||
}) | ||
|
||
it('should render with default styles', () => { | ||
const expected = 'bg-white dark:bg-gray-800' | ||
const wrapper = mount(<Card />) | ||
|
||
expect(wrapper.find(Card).getDOMNode().getAttribute('class')).toContain(expected) | ||
}) | ||
|
||
it('should render without default styles', () => { | ||
const expected = 'bg-white dark:bg-gray-800' | ||
const wrapper = mount(<Card colored />) | ||
|
||
expect(wrapper.find(Card).getDOMNode().getAttribute('class')).not.toContain(expected) | ||
}) | ||
|
||
it('should add classes to base styles', () => { | ||
const expected = 'min-w-0 rounded-lg shadow-xs bg-red-400' | ||
const wrapper = mount(<Card className="bg-red-400" colored />) | ||
|
||
expect(wrapper.find(Card).getDOMNode().getAttribute('class')).toBe(expected) | ||
}) | ||
}) |
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,16 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import CardBody from '../src/CardBody' | ||
|
||
describe('CardBody', () => { | ||
it('should render without crashing', () => { | ||
mount(<CardBody />) | ||
}) | ||
|
||
it('should render with default styles', () => { | ||
const expected = 'p-4' | ||
const wrapper = mount(<CardBody />) | ||
|
||
expect(wrapper.find(CardBody).getDOMNode().getAttribute('class')).toContain(expected) | ||
}) | ||
}) |
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,28 @@ | ||
import React, { useContext } from 'react' | ||
import classNames from 'classnames' | ||
import PropTypes from 'prop-types' | ||
import { ThemeContext } from './context/ThemeContext' | ||
import defaultTheme from './themes/default' | ||
|
||
function Card({ className, children, colored }) { | ||
const { card } = useContext(ThemeContext) || defaultTheme | ||
|
||
const baseStyle = card.base | ||
const uncoloredStyle = card.default | ||
|
||
const cls = classNames(baseStyle, !colored && uncoloredStyle, className) | ||
|
||
return <div className={cls}>{children}</div> | ||
} | ||
|
||
Card.propTypes = { | ||
children: PropTypes.element, | ||
colored: PropTypes.bool, | ||
className: PropTypes.string, | ||
} | ||
|
||
Card.defaultProps = { | ||
colored: false, | ||
} | ||
|
||
export default Card |
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,22 @@ | ||
import React, { useContext } from 'react' | ||
import classNames from 'classnames' | ||
import PropTypes from 'prop-types' | ||
import { ThemeContext } from './context/ThemeContext' | ||
import defaultTheme from './themes/default' | ||
|
||
function CardBody({ className, children }) { | ||
const { cardBody } = useContext(ThemeContext) || defaultTheme | ||
|
||
const baseStyle = cardBody.base | ||
|
||
const cls = classNames(baseStyle, className) | ||
|
||
return <div className={cls}>{children}</div> | ||
} | ||
|
||
CardBody.propTypes = { | ||
children: PropTypes.element, | ||
className: PropTypes.string, | ||
} | ||
|
||
export default CardBody |
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