Badges


Scale to parent

Badge - 图1

  1. import React from 'react';
  2. import { Badge } from 'reactstrap';
  3. export default class Example extends React.Component {
  4. render() {
  5. return (
  6. <div>
  7. <h1>Heading <Badge color="secondary">New</Badge></h1>
  8. <h2>Heading <Badge color="secondary">New</Badge></h2>
  9. <h3>Heading <Badge color="secondary">New</Badge></h3>
  10. <h4>Heading <Badge color="secondary">New</Badge></h4>
  11. <h5>Heading <Badge color="secondary">New</Badge></h5>
  12. <h6>Heading <Badge color="secondary">New</Badge></h6>
  13. </div>
  14. );
  15. }
  16. }

Badges can be used as part of links or buttons to provide a counter.

Badge - 图2

  1. import React from 'react';
  2. import { Badge, Button } from 'reactstrap';
  3. export default class Example extends React.Component {
  4. render() {
  5. return (
  6. <div>
  7. <Button color="primary" outline>
  8. Notifications <Badge color="secondary">4</Badge>
  9. </Button>
  10. </div>
  11. );
  12. }
  13. }

Contextual variations

Badge - 图3

  1. import React from 'react';
  2. import { Badge } from 'reactstrap';
  3. export default class Example extends React.Component {
  4. render() {
  5. return (
  6. <div>
  7. <Badge color="primary">Primary</Badge>
  8. <Badge color="secondary">Secondary</Badge>
  9. <Badge color="success">Success</Badge>
  10. <Badge color="danger">Danger</Badge>
  11. <Badge color="warning">Warning</Badge>
  12. <Badge color="info">Info</Badge>
  13. <Badge color="light">Light</Badge>
  14. <Badge color="dark">Dark</Badge>
  15. </div>
  16. );
  17. }
  18. }

Pills

Badge - 图4

  1. import React from 'react';
  2. import { Badge } from 'reactstrap';
  3. export default class Example extends React.Component {
  4. render() {
  5. return (
  6. <div>
  7. <Badge color="primary" pill>Primary</Badge>
  8. <Badge color="secondary" pill>Secondary</Badge>
  9. <Badge color="success" pill>Success</Badge>
  10. <Badge color="danger" pill>Danger</Badge>
  11. <Badge color="warning" pill>Warning</Badge>
  12. <Badge color="info" pill>Info</Badge>
  13. <Badge color="light" pill>Light</Badge>
  14. <Badge color="dark" pill>Dark</Badge>
  15. </div>
  16. );
  17. }
  18. }

Adding the href prop (without specifying a tag prop) will default the badge to a link.

Badge - 图5

  1. import React from 'react';
  2. import { Badge } from 'reactstrap';
  3. export default class Example extends React.Component {
  4. render() {
  5. return (
  6. <div>
  7. <Badge href="#" color="primary">Primary</Badge>
  8. <Badge href="#" color="secondary">Secondary</Badge>
  9. <Badge href="#" color="success">Success</Badge>
  10. <Badge href="#" color="danger">Danger</Badge>
  11. <Badge href="#" color="warning">Warning</Badge>
  12. <Badge href="#" color="info">Info</Badge>
  13. <Badge href="#" color="light">Light</Badge>
  14. <Badge href="#" color="dark">Dark</Badge>
  15. </div>
  16. );
  17. }
  18. }