Skip to content

Commit

Permalink
Move PublisherList to templates and set with best practice for ease o…
Browse files Browse the repository at this point in the history
…f use
  • Loading branch information
dgading committed Mar 2, 2021
1 parent 70e4df8 commit 134d8d6
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 106 deletions.
22 changes: 0 additions & 22 deletions src/components/PublisherList/doc.mdx

This file was deleted.

47 changes: 0 additions & 47 deletions src/components/PublisherList/index.jsx

This file was deleted.

31 changes: 0 additions & 31 deletions src/components/PublisherList/index.test.jsx

This file was deleted.

17 changes: 11 additions & 6 deletions src/examples/publishers.json
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"
}
]
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export { default as DataTable } from './templates/DataTable';
export { default as Header } from './templates/Header';
export { default as Hero } from './templates/Hero';
export { default as Footer } from './templates/Footer';
export { default as PublisherList } from './templates/PublisherList';
export { default as StatBlock } from './templates/Blocks/StatBlock';
export { default as StepsBlock } from './templates/Blocks/StepsBlock';
export { default as TopicIcon } from './templates/TopicIcon';
Expand Down
28 changes: 28 additions & 0 deletions src/templates/PublisherList/doc.mdx
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} />
41 changes: 41 additions & 0 deletions src/templates/PublisherList/index.jsx
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;
25 changes: 25 additions & 0 deletions src/templates/PublisherList/index.test.jsx
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();
});
});

0 comments on commit 134d8d6

Please sign in to comment.