Skip to content

Commit

Permalink
Adds a small Badge component (opensearch-project#39)
Browse files Browse the repository at this point in the history
Signed-off-by: Drew Baugher <[email protected]>
  • Loading branch information
dbbaughe authored Aug 10, 2021
1 parent c9fefc9 commit bb691d2
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
22 changes: 22 additions & 0 deletions public/pages/VisualCreatePolicy/components/Badge/Badge.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import React from "react";
import "@testing-library/jest-dom/extend-expect";
import { render } from "@testing-library/react";
import Badge from "./Badge";

describe("<Badge /> spec", () => {
it("renders the component", () => {
const { container } = render(<Badge text="Some text" number={2} />);
expect(container.firstChild).toMatchSnapshot();
});
});
34 changes: 34 additions & 0 deletions public/pages/VisualCreatePolicy/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import React from "react";
import { EuiText, EuiNotificationBadge, EuiTextColor } from "@elastic/eui";

interface BadgeProps {
text: string;
number: number;
color?: "subdued" | "accent" | undefined;
}

const Badge = ({ text, number, color = "subdued" }: BadgeProps) => (
<EuiText size="xs" textAlign="center">
<EuiTextColor color={color}>
<p>
{text}{" "}
<EuiNotificationBadge size="s" color={color}>
{number}
</EuiNotificationBadge>
</p>
</EuiTextColor>
</EuiText>
);

export default Badge;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Badge /> spec renders the component 1`] = `
<div
class="euiText euiText--extraSmall"
>
<div
class="euiTextAlign euiTextAlign--center"
>
<span
class="euiTextColor euiTextColor--subdued"
>
<p>
Some text
<span
class="euiNotificationBadge euiNotificationBadge--subdued"
>
2
</span>
</p>
</span>
</div>
</div>
`;
14 changes: 14 additions & 0 deletions public/pages/VisualCreatePolicy/components/Badge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import Badge from "./Badge";

export default Badge;

0 comments on commit bb691d2

Please sign in to comment.