-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a small Badge component (opensearch-project#39)
Signed-off-by: Drew Baugher <[email protected]>
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
public/pages/VisualCreatePolicy/components/Badge/Badge.test.tsx
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,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
34
public/pages/VisualCreatePolicy/components/Badge/Badge.tsx
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,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; |
25 changes: 25 additions & 0 deletions
25
public/pages/VisualCreatePolicy/components/Badge/__snapshots__/Badge.test.tsx.snap
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 @@ | ||
// 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> | ||
`; |
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,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; |