-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from lshadler/lshadler/business-card-design
- Loading branch information
Showing
19 changed files
with
680 additions
and
17 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,45 @@ | ||
import React from 'react'; | ||
|
||
import {BusinessInfoType} from '../test-data/data-types'; | ||
import {Card, Box, Button, withStyles} from '@material-ui/core'; | ||
import {useState} from 'react'; | ||
|
||
import BusinessCardDetail from './BusinessCardDetail'; | ||
import BusinessCardSummary from './BusinessCardSummary'; | ||
|
||
const ShowMoreButton = withStyles(({spacing}) => ({ | ||
root: { | ||
width: '80%', | ||
marginTop: spacing(2), | ||
marginBottom: spacing(2), | ||
}, | ||
}))(Button); | ||
|
||
const BusinessCard = ({businessInfo}) => { | ||
const [isExpanded, setIsExpanded] = useState(false); | ||
const buttonText = isExpanded ? 'Show less...' : 'Show more...'; | ||
|
||
|
||
return ( | ||
<Box component={Card} m={3} p={1} | ||
variant="outlined" | ||
justifyContent="space-evenly" | ||
alignItems="center" | ||
display="flex" | ||
minHeight="200px" | ||
flexDirection="column"> | ||
<BusinessCardSummary businessInfo={businessInfo} /> | ||
<BusinessCardDetail expanded={isExpanded} businessInfo={businessInfo}/> | ||
<ShowMoreButton | ||
color="primary" | ||
variant="contained" | ||
onClick={() => setIsExpanded(!isExpanded)}>{buttonText}</ShowMoreButton> | ||
</Box> | ||
); | ||
}; | ||
|
||
BusinessCard.propTypes = { | ||
businessInfo: BusinessInfoType.isRequired, | ||
}; | ||
|
||
export default BusinessCard; |
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 from 'react'; | ||
import {bool} from 'prop-types'; | ||
import {BusinessInfoType} from '../test-data/data-types'; | ||
import {Box, Typography, Collapse} from '@material-ui/core'; | ||
|
||
const CardDetail = ({businessInfo, expanded}) => { | ||
const {tags} = businessInfo; | ||
return ( | ||
<Box component={Collapse} in={expanded} m={1}> | ||
{tags ? ( | ||
<Typography>Tags: {tags.join(', ')}</Typography> | ||
) : 'No details yet...'} | ||
</Box> | ||
); | ||
}; | ||
|
||
CardDetail.propTypes = { | ||
businessInfo: BusinessInfoType.isRequired, | ||
expanded: bool.isRequired, | ||
}; | ||
|
||
export default CardDetail; |
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,29 @@ | ||
import React from 'react'; | ||
|
||
import {BusinessInfoType} from '../test-data/data-types'; | ||
import {Typography} from '@material-ui/core'; | ||
import WebsiteLink from './WebsiteLink'; | ||
|
||
const CardSummary = ({businessInfo}) => { | ||
const {name, website} = businessInfo; | ||
|
||
return ( | ||
<> | ||
<Typography variant="h4">{name}</Typography> | ||
<Typography> | ||
{website ? ( | ||
<WebsiteLink | ||
href={website} | ||
color="primary" | ||
label='Website' /> | ||
) : ''} | ||
</Typography> | ||
</> | ||
); | ||
}; | ||
|
||
CardSummary.propTypes = { | ||
businessInfo: BusinessInfoType.isRequired, | ||
}; | ||
|
||
export default CardSummary; |
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,23 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {BusinessInfoType} from '../test-data/data-types'; | ||
import {Grid} from '@material-ui/core'; | ||
import BusinessCard from './BusinessCard'; | ||
|
||
const BusinessGrid = ({places}) => { | ||
return ( | ||
<Grid container spacing={1}> | ||
{places.map((businessInfo, index) => ( | ||
<Grid key={index} item xs={12} sm={6} md={4} lg={3}> | ||
<BusinessCard businessInfo={businessInfo} /> | ||
</Grid> | ||
))} | ||
</Grid> | ||
); | ||
}; | ||
|
||
BusinessGrid.propTypes = { | ||
places: PropTypes.arrayOf(BusinessInfoType), | ||
}; | ||
|
||
export default BusinessGrid; |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
'.{js,jsx}': 'eslint --fix', | ||
'*.{js,jsx}': 'eslint --fix', | ||
}; |
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,11 @@ | ||
import {shape, string, number, array} from 'prop-types'; | ||
|
||
export const BusinessInfoType = shape({ | ||
name: string.isRequired, | ||
iconType: string, | ||
venmo: string, | ||
website: string, | ||
lat: number, | ||
lng: number, | ||
tags: array, | ||
}); |
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,32 @@ | ||
import React from 'react'; | ||
import {render, fireEvent} from '@testing-library/react'; | ||
|
||
import BusinessCard from '../../components/BusinessCard'; | ||
|
||
describe('BusinessCard Component', () => { | ||
let businessInfo; | ||
|
||
beforeEach(() => { | ||
businessInfo = { | ||
name: 'Heartwork', | ||
website: 'https://heartwork.com', | ||
tags: ['coffee', 'test'], | ||
}; | ||
}); | ||
test('renders in default state', () => { | ||
const {asFragment} = render(<BusinessCard | ||
businessInfo={businessInfo}/>); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
test('click to expand', () => { | ||
const {asFragment, getByText} = render(<BusinessCard | ||
businessInfo={businessInfo} />); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
|
||
fireEvent.click(getByText(/Show more\.\.\./)); | ||
expect(asFragment()).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,33 @@ | ||
import React from 'react'; | ||
import {render} from '@testing-library/react'; | ||
|
||
import BusinessCardDetail from '../../components/BusinessCardDetail'; | ||
|
||
describe('BusinessCardDetail Component', () => { | ||
let businessInfo; | ||
|
||
beforeEach(() => { | ||
businessInfo = { | ||
name: 'Heartwork', | ||
website: 'https://heartwork.com', | ||
tags: ['coffee', 'test'], | ||
}; | ||
}); | ||
test('renders in default collapsed state', () => { | ||
const {asFragment} = render(<BusinessCardDetail | ||
businessInfo={businessInfo} | ||
expanded={false}/>); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
test('handles empty tags gracefully', () => { | ||
delete businessInfo.tags; | ||
|
||
const {asFragment} = render(<BusinessCardDetail | ||
businessInfo={businessInfo} | ||
expanded={false}/>); | ||
|
||
expect(asFragment()).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,31 @@ | ||
import React from 'react'; | ||
import {render} from '@testing-library/react'; | ||
|
||
import BusinessCardSummary from '../../components/BusinessCardSummary'; | ||
|
||
describe('BusinessCardSummary Component', () => { | ||
let businessInfo; | ||
|
||
beforeEach(() => { | ||
businessInfo = { | ||
name: 'Heartwork', | ||
website: 'https://heartwork.com', | ||
tags: ['coffee', 'test'], | ||
}; | ||
}); | ||
test('renders in default state', () => { | ||
const {asFragment} = render(<BusinessCardSummary | ||
businessInfo={businessInfo}/>); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
test('handles empty website gracefully', () => { | ||
delete businessInfo.website; | ||
|
||
const {asFragment} = render(<BusinessCardSummary | ||
businessInfo={businessInfo}/>); | ||
|
||
expect(asFragment()).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,21 @@ | ||
import React from 'react'; | ||
import {render} from '@testing-library/react'; | ||
|
||
import BusinessGrid from '../../components/BusinessGrid'; | ||
|
||
describe('BusinessGrid Component', () => { | ||
let places; | ||
|
||
beforeEach(() => { | ||
places = [{ | ||
name: 'Heartwork', | ||
website: 'https://heartwork.com', | ||
tags: ['coffee', 'test'], | ||
}]; | ||
}); | ||
test('renders in default collapsed state', () => { | ||
const {asFragment} = render(<BusinessGrid places={places}/>); | ||
|
||
expect(asFragment()).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
Oops, something went wrong.
5dec682
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: