Skip to content

Commit

Permalink
ui: CSS modules for Badge component
Browse files Browse the repository at this point in the history
Define styles for Badge component as
CSS modules.

Release note: None
  • Loading branch information
koorosh committed Jun 9, 2020
1 parent 249db86 commit 49cd4a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
File renamed without changes.
16 changes: 9 additions & 7 deletions pkg/ui/src/components/badge/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,37 @@
// licenses/APL.txt.

import * as React from "react";
import cn from "classnames";
import classNames from "classnames/bind";

import "./badge.styl";
import styles from "./badge.module.styl";

export type BadgeStatus = "success" | "danger" | "default" | "info" | "warning";

export interface BadgeProps {
text: React.ReactNode;
size?: "small" | "medium" | "large";
status?: BadgeStatus;
tag?: boolean; // TODO (koorosh): Tag behavior isn't implemented yet.
icon?: React.ReactNode;
iconPosition?: "left" | "right";
}

Badge.defaultProps = {
size: "medium",
status: "default",
tag: false,
};

const cx = classNames.bind(styles);

export function Badge(props: BadgeProps) {
const { size, status, icon, iconPosition, text } = props;
const classes = cn("badge", `badge--size-${size}`, `badge--status-${status}`);
const iconClasses = cn("badge__icon", `badge__icon--position-${iconPosition || "left"}`);
const classes = cx("badge", `badge--size-${size}`, `badge--status-${status}`);
const iconClasses = cx("badge__icon", `badge__icon--position-${iconPosition || "left"}`);
return (
<div className={classes}>
{ icon && <div className={iconClasses}>{icon}</div> }
<div className="badge__text badge__text--no-wrap">
<div
className={cx("badge__text", "badge__text--no-wrap")}
>
{ text }
</div>
</div>
Expand Down

0 comments on commit 49cd4a3

Please sign in to comment.