Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for VuiBadge #31

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/docs/components/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const Example = ({ name, component, source }: Props) => {
<VuiTab isActive={tab === "example"} onClick={() => setTab("example")}>
Example
</VuiTab>

<VuiTab isActive={tab === "source"} onClick={() => setTab("source")}>
Source
</VuiTab>
Expand Down
3 changes: 2 additions & 1 deletion src/docs/pages.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Components
import { badge } from "./pages/badge";
import { button } from "./pages/button";
import { drawer } from "./pages/drawer";
import { flex } from "./pages/flex";
Expand Down Expand Up @@ -36,7 +37,7 @@ export const categories: Category[] = [
},
{
name: "Info",
pages: [icon]
pages: [badge, icon]
},
{
name: "Containers",
Expand Down
13 changes: 13 additions & 0 deletions src/docs/pages/badge/BadgeColors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { BADGE_COLOR, VuiBadge, VuiFlexContainer, VuiFlexItem } from "../../../lib";

export const BadgeColors = () => {
return (
<VuiFlexContainer>
{BADGE_COLOR.map((color) => (
<VuiFlexItem grow={false} key={color}>
<VuiBadge color={color}>Color {color}</VuiBadge>
</VuiFlexItem>
))}
</VuiFlexContainer>
);
};
19 changes: 19 additions & 0 deletions src/docs/pages/badge/ClickableBadges.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { VuiBadge, VuiFlexContainer, VuiFlexItem } from "../../../lib";

export const ClickableBadges = () => {
return (
<VuiFlexContainer>
<VuiFlexItem grow={false}>
<VuiBadge color="primary" href="https://docs.vectara.com/" target="_blank">
Docs
</VuiBadge>
</VuiFlexItem>

<VuiFlexItem grow={false}>
<VuiBadge color="primary" onClick={() => alert("Hello, world")}>
Hello, world
</VuiBadge>
</VuiFlexItem>
</VuiFlexContainer>
);
};
22 changes: 22 additions & 0 deletions src/docs/pages/badge/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { BadgeColors } from "./BadgeColors";
import { ClickableBadges } from "./ClickableBadges";

const BadgeColorsSource = require("!!raw-loader!./BadgeColors");
const ClickableBadgesSource = require("!!raw-loader!./ClickableBadges");

export const badge = {
name: "Badge",
path: "/badge",
examples: [
{
name: "Colors",
component: <BadgeColors />,
source: BadgeColorsSource.default.toString()
},
{
name: "Clickable badges",
component: <ClickableBadges />,
source: ClickableBadgesSource.default.toString()
}
]
};
6 changes: 3 additions & 3 deletions src/lib/components/badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Link } from "react-router-dom";
import { Props as LinkProps } from "../link/Link";
import { getTrackingProps } from "../../utils/getTrackingProps";

const COLOR = ["accent", "primary", "danger", "success", "normal"] as const;
export const BADGE_COLOR = ["accent", "primary", "danger", "success", "normal"] as const;

type Props = {
children: React.ReactNode;
className?: string;
color: (typeof COLOR)[number];
color: (typeof BADGE_COLOR)[number];
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
href?: LinkProps["href"];
target?: LinkProps["target"];
Expand All @@ -31,7 +31,7 @@ export const VuiBadge = ({ children, className, color, onClick, href, target, tr

if (href) {
return (
<Link className={classes} onClick={onClick} to={href} {...getTrackingProps(track)}>
<Link className={classes} onClick={onClick} to={href} target={target} {...getTrackingProps(track)}>
{children}
</Link>
);
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/badge/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
border-radius: $sizeS;
font-family: inherit;
white-space: nowrap;
text-decoration: none;
}

.vuiBadge--clickable {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { VuiAppContent } from "./appContent/AppContent";
import { VuiAppHeader } from "./appHeader/AppHeader";
import { VuiAppLayout } from "./appLayout/AppLayout";
import { VuiAppSideNav } from "./appSideNav/AppSideNav";
import { VuiBadge } from "./badge/Badge";
import { BADGE_COLOR, VuiBadge } from "./badge/Badge";
import { BUTTON_COLOR, BUTTON_SIZE, ButtonColor } from "./button/types";
import { VuiButtonPrimary } from "./button/ButtonPrimary";
import { VuiButtonSecondary } from "./button/ButtonSecondary";
Expand Down Expand Up @@ -46,6 +46,7 @@ import { VuiToggle } from "./toggle/Toggle";
export type { ButtonColor, TabSize };

export {
BADGE_COLOR,
BUTTON_COLOR,
BUTTON_SIZE,
ICON_COLOR,
Expand Down