Skip to content

Commit

Permalink
feat(ListGroup): Add ListGroupNumbered
Browse files Browse the repository at this point in the history
  • Loading branch information
bestguy authored and phwebi committed Oct 27, 2021
1 parent c77ac36 commit 02b3b71
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
12 changes: 12 additions & 0 deletions docs/lib/Components/ListGroupPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ListGroupContextualClassesExample from '../examples/ListGroupContextualCl
import ListGroupCustomContentExample from '../examples/ListGroupCustomContent';
import ListGroupFlushExample from '../examples/ListGroupFlush';
import ListGroupHorizontalExample from '../examples/ListGroupHorizontal';
import ListGroupNumberedExample from '../examples/ListGroupNumbered';

const ListGroupBadgeExampleSource = require('!!raw-loader!../examples/ListGroupBadge');
const ListGroupExampleSource = require('!!raw-loader!../examples/ListGroup');
Expand All @@ -20,6 +21,7 @@ const ListGroupContextualClassesExampleSource = require('!!raw-loader!../example
const ListGroupCustomContentExampleSource = require('!!raw-loader!../examples/ListGroupCustomContent');
const ListGroupFlushExampleSource = require('!!raw-loader!../examples/ListGroupFlush')
const ListGroupHorizontalExampleSource = require("!!raw-loader!../examples/ListGroupHorizontal");
const ListGroupNumberedExampleSource = require("!!raw-loader!../examples/ListGroupNumbered");

export default class ListGroupPage extends React.Component {
render() {
Expand Down Expand Up @@ -121,6 +123,16 @@ export default class ListGroupPage extends React.Component {
{ListGroupHorizontalExampleSource}
</PrismCode>
</pre>

<legend>Numbered</legend>
<div className="docs-example">
<ListGroupNumberedExample />
</div>
<pre>
<PrismCode className="language-jsx">
{ListGroupNumberedExampleSource}
</PrismCode>
</pre>
</div>
);
}
Expand Down
20 changes: 20 additions & 0 deletions docs/lib/examples/ListGroupNumbered.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { ListGroup, ListGroupItem } from 'reactstrap';

const Example = (props) => {
return (
<div>
<p>The <code>numbered</code> prop can be used to opt into numbered list group items.</p>
<ListGroup numbered>
<ListGroupItem>Cras justo odio</ListGroupItem>
<ListGroupItem>Dapibus ac facilisis in</ListGroupItem>
<ListGroupItem>Morbi leo risus</ListGroupItem>
<ListGroupItem>Porta ac consectetur ac</ListGroupItem>
<ListGroupItem>Vestibulum at eros</ListGroupItem>
</ListGroup>
</div>

);
}

export default Example;
12 changes: 9 additions & 3 deletions src/ListGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ const propTypes = {
flush: PropTypes.bool,
className: PropTypes.string,
cssModule: PropTypes.object,
horizontal: PropTypes.oneOfType([PropTypes.bool, PropTypes.string])
horizontal: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
numbered: PropTypes.bool
};

const defaultProps = {
tag: 'ul',
horizontal: false
horizontal: false,
numbered: false
};

const getHorizontalClass = horizontal => {
Expand All @@ -32,14 +34,18 @@ const ListGroup = (props) => {
tag: Tag,
flush,
horizontal,
numbered,
...attributes
} = props;
const classes = mapToCssModules(classNames(
className,
'list-group',
// list-group-horizontal cannot currently be mixed with list-group-flush
// we only try to apply horizontal classes if flush is false
flush ? 'list-group-flush' : getHorizontalClass(horizontal)
flush ? 'list-group-flush' : getHorizontalClass(horizontal),
{
'list-group-numbered': numbered
}
), cssModule);

return (
Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/ListGroup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ describe('ListGroup', () => {
expect(wrapper.hasClass("list-group-horizontal-lg")).toBe(true);
});

it('should render with "numbered"', () => {
const wrapper = shallow(<ListGroup numbered>Yo!</ListGroup>);

expect(wrapper.text()).toBe("Yo!");
expect(wrapper.hasClass("list-group")).toBe(true);
expect(wrapper.hasClass("list-group-numbered")).toBe(true);
});

it('should render additional classes', () => {
const wrapper = shallow(<ListGroup className="other">Yo!</ListGroup>);

Expand Down
1 change: 1 addition & 0 deletions types/lib/ListGroup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface ListGroupProps extends React.HTMLAttributes<HTMLElement> {
tag?: React.ElementType;
flush?: boolean;
horizontal?: boolean | string;
numbered?: boolean;
cssModule?: CSSModule;
}

Expand Down

0 comments on commit 02b3b71

Please sign in to comment.