-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move PublisherList to templates and set with best practice for ease o…
…f use
- Loading branch information
Showing
8 changed files
with
106 additions
and
106 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,14 +1,19 @@ | ||
[ | ||
{ | ||
"name": "CDC", | ||
"key": "1" | ||
"name": "DKAN", | ||
"description": "Description for DKAN", | ||
"searchUrl":"/search/?publisher__name=DKAN" | ||
}, | ||
{ | ||
"name": "EPA", | ||
"key": "2" | ||
"name": "Clipboards", | ||
"imageUrl": "https://dkan-default-content-files.s3.amazonaws.com/files/publishers/clipboard.png", | ||
"description": "Description for Clipboards", | ||
"searchUrl":"/search/?publisher__name=Clipboards" | ||
}, | ||
{ | ||
"name": "USDA", | ||
"key": "3" | ||
"name": "Maps", | ||
"imageUrl": "https://dkan-default-content-files.s3.amazonaws.com/files/publishers/map.png", | ||
"description": "Description for maps", | ||
"searchUrl":"/search/?publisher__name=Maps" | ||
} | ||
] |
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,28 @@ | ||
--- | ||
name: Publisher List | ||
menu: Templates | ||
route: /templates/publisher-list | ||
--- | ||
|
||
import { Playground, Props } from 'docz' | ||
import PublisherList from './index' | ||
import orgs from '../../examples/publishers.json' | ||
|
||
# Publisher List | ||
A prebuilt template for showing a list of Publishers using the [Organization](/components/organization) component. | ||
|
||
## Basic usage | ||
<Playground> | ||
<PublisherList orgs={orgs}/> | ||
</Playground> | ||
|
||
## Custom Button Prefix | ||
<Playground> | ||
<PublisherList | ||
orgs={orgs} | ||
buttonTextPrefix="Explore" | ||
/> | ||
</Playground> | ||
|
||
## Properties | ||
<Props of={PublisherList} /> |
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,41 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Organization from '../../components/Organization'; | ||
|
||
const PublisherList = ({ orgs, buttonTextPrefix }) => { | ||
|
||
return ( | ||
<ul className="usa-card-group"> | ||
{orgs.map((org) => ( | ||
<Organization | ||
key={org.name} | ||
org={org} | ||
buttonText={buttonTextPrefix ? `${buttonTextPrefix} ${org.name}` : null} | ||
isCard | ||
/> | ||
))} | ||
</ul> | ||
); | ||
} | ||
|
||
PublisherList.defaultProps = { | ||
buttonTextPrefix: '', | ||
}; | ||
|
||
PublisherList.propTypes = { | ||
/** | ||
* This is the content of the component. imageUrl are not required, but most organizations will have an icon to use. The search url should be a relative link starting with /. | ||
*/ | ||
orgs: PropTypes.arrayOf(PropTypes.shape({ | ||
name: PropTypes.string.isRequired, | ||
description: PropTypes.string.isRequired, | ||
imageUrl: PropTypes.string.isRequired, | ||
searchUrl: PropTypes.string, | ||
})).isRequired, | ||
/** | ||
* By default Organizations will set the button to "Search <name>"". Search can be changed with this prop to things like "Explore". | ||
*/ | ||
buttonTextPrefix: PropTypes.string, | ||
}; | ||
|
||
export default PublisherList; |
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,25 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import PublisherList from './index'; | ||
import orgs from '../../examples/publishers.json' | ||
|
||
describe('<PublisherList />', () => { | ||
test('renders list of orgs', () => { | ||
render( | ||
<PublisherList orgs={orgs} />, | ||
); | ||
expect(screen.getAllByRole('listitem')).toHaveLength(3); | ||
}); | ||
|
||
test('renders list of orgs with custom button text', () => { | ||
render( | ||
<PublisherList | ||
orgs={orgs} | ||
buttonTextPrefix="Explore" | ||
/>, | ||
); | ||
expect(screen.getAllByRole('listitem')).toHaveLength(3); | ||
expect(screen.getByRole('button', {name: 'Explore Clipboards'})).toBeInTheDocument(); | ||
}); | ||
}); |