Skip to content

Commit

Permalink
Merge pull request #21 from thep0y/main
Browse files Browse the repository at this point in the history
0.1.6
  • Loading branch information
thep0y authored Dec 11, 2024
2 parents 8351cf0 + bbc9ab5 commit 4ae441b
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 3 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fluent-solid",
"version": "0.1.5",
"version": "0.1.6",
"repository": "https://github.com/thep0y/fluent",
"keywords": [
"solid",
Expand Down Expand Up @@ -29,9 +29,9 @@
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@rollup/plugin-typescript": "^12.1.1",
"@types/node": "^22.10.1",
"@types/node": "^22.10.2",
"rollup-plugin-external-globals": "^0.13.0",
"sass": "^1.81.0",
"sass": "^1.82.0",
"tsc-alias": "^1.8.10",
"tslib": "^2.8.1",
"typescript": "^5.7.2",
Expand Down
129 changes: 129 additions & 0 deletions packages/components/badge/badge/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
.fluent-badge {
display: inline-flex;
box-sizing: border-box;
align-items: center;
justify-content: center;
position: relative;
font-family: var(--fontFamilyBase);
font-size: var(--fontSizeBase200);
font-weight: var(--fontWeightSemibold);
line-height: var(--lineHeightBase200);
height: 20px;
width: 20px;
min-width: max-content;
padding: 0 calc(var(--spacingHorizontalXS) + var(--spacingHorizontalXXS));
border-radius: var(--borderRadiusCircular);
border-color: var(--colorTransparentStroke);

&::after {
content: "";
position: absolute;
inset: 0px;
border-style: solid;
border-color: inherit;
border-width: var(--strokeWidthThin);
border-radius: inherit;
}

&-filled {
color: var(--colorNeutralForegroundOnBrand);
background-color: var(--colorBrandBackground);
}

&-ghost {
color: var(--colorBrandForeground1);
}

&-outline {
border-color: currentcolor;
color: var(--colorBrandForeground1);
}

&-tint {
border-color: var(--colorBrandStroke2);
color: var(--colorBrandForeground2);
}

&-tiny {
min-width: unset;
line-height: 4px;
font-size: 4px;
height: 6px;
width: 6px;
padding: unset;
}

&-extra-small {
min-width: unset;
line-height: 6px;
font-size: 6px;
height: 10px;
width: 10px;
padding: unset;
}

&-small {
line-height: var(--lineHeightBase100);
font-size: var(--fontSizeBase100);
width: 16px;
height: 16px;
}

&-large {
width: 24px;
height: 24px;
}

&-extra-large {
width: 32px;
height: 32px;
padding: 0
calc(var(--spacingHorizontalSNudge) + var(--spacingHorizontalXXS));
}

&-square {
border-radius: var(--borderRadiusNone);
}

&-rounded {
border-radius: var(--borderRadiusMedium);
}

&-danger {
background-color: var(--colorPaletteRedBackground3);
}

&-important {
background-color: var(--colorNeutralForeground1);
}

&-informative {
color: var(--colorNeutralForeground3);
background-color: var(--colorNeutralBackground5);
}

&-severe {
background-color: var(--colorPaletteDarkOrangeBackground3);
}

&-subtle {
color: var(--colorNeutralForeground1);
background-color: var(--colorNeutralBackground1);
}

&-success {
background-color: var(--colorPaletteGreenBackground3);
}

&-warning {
background-color: var(--colorPaletteYellowBackground3);
color: var(--colorNeutralForeground1Static);
}

&__icon {
display: flex;
line-height: 1;
margin: 0 calc(-1 * var(--spacingHorizontalXXS));
font-size: 12px;
}
}
88 changes: 88 additions & 0 deletions packages/components/badge/badge/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { children, mergeProps, Show } from "solid-js";
import type { JSX } from "solid-js";
import type { BaseComponentProps } from "~/interface";
import { addClassList } from "~/utils";
import "./index.scss";

export interface BadgeProps extends BaseComponentProps<HTMLDivElement> {
/**
* A Badge can be filled, outline, ghost, inverted
* @defaultvalue filled
*/
appearance?: "filled" | "ghost" | "outline" | "tint";

/**
* A Badge can be one of preset colors
* @defaultvalue brand
*/
color?:
| "brand"
| "danger"
| "important"
| "informative"
| "severe"
| "subtle"
| "success"
| "warning";

/**
* A Badge can position the icon before or after the content.
* @defaultvalue before
*/
iconPosition?: "before" | "after";

/**
* A Badge can be square, circular or rounded.
* @defaultvalue circular
*/
shape?: "circular" | "rounded" | "square";

/**
* A Badge can be on of several preset sizes.
* @defaultvalue medium
*/
size?: "tiny" | "extra-small" | "small" | "medium" | "large" | "extra-large";

icon?: JSX.Element;
}

const baseClassName = "fluent-badge";

const Badge = (props: BadgeProps) => {
const merged = mergeProps(
{ appearance: "filled", iconPosition: "before", size: "medium" },
props,
);

const classes = () =>
addClassList({
base: baseClassName,
others: {
[merged.class ?? ""]: merged.class,
[`${baseClassName}-${merged.appearance}`]: merged.appearance,
[`${baseClassName}-${merged.size}`]: merged.size,
[`${baseClassName}-${merged.shape}`]: merged.shape,
[`${baseClassName}-${merged.color}`]: merged.color,
},
});

const icon = children(() => (
<span class={`${baseClassName}__icon`}>{merged.icon}</span>
));

return (
<div classList={classes()} style={merged.style}>
<Show when={merged.iconPosition === "before" && merged.icon}>
{icon()}
</Show>

{merged.children}

<Show when={merged.iconPosition === "after" && merged.icon}>
{icon()}
</Show>
</div>
);
};

export default Badge;
2 changes: 2 additions & 0 deletions packages/components/badge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as Badge } from "./badge";
export type { BadgeProps } from "./badge";
3 changes: 3 additions & 0 deletions packages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ export type { DividerProps } from "./components/divider";
export { default as Slider } from "./components/slider";
export type { SliderProps } from "./components/slider";

export { Badge } from "./components/badge";
export type { BadgeProps } from "./components/badge";

export * from "./utils";
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const examples = [
lazy(() => import("./components/switch")),
lazy(() => import("./components/divider")),
lazy(() => import("./components/slider")),
lazy(() => import("./components/badge")),
];

//const menus = ["Button"];
Expand Down
67 changes: 67 additions & 0 deletions src/components/badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { BiSolidPaste } from "solid-icons/bi";
import { Badge } from "~/index";

const BadgeDemo = () => {
return (
<div>
<div>
<Badge />
</div>

<div>
<Badge appearance="filled">999+</Badge>
<Badge appearance="ghost">999+</Badge>
<Badge appearance="outline">999+</Badge>
<Badge appearance="tint">999+</Badge>
</div>

<div>
<Badge size="tiny" />
<Badge size="extra-small" />
<Badge size="small" />
<Badge size="medium" />
<Badge size="large" />
<Badge size="extra-large" />{" "}
</div>

<div>
<Badge shape="square" />
<Badge shape="rounded" />
<Badge shape="circular" />
</div>

<div>
<Badge appearance="filled" color="brand">
999+
</Badge>
<Badge appearance="filled" color="danger">
999+
</Badge>
<Badge appearance="filled" color="important">
999+
</Badge>
<Badge appearance="filled" color="informative">
999+
</Badge>
<Badge appearance="filled" color="severe">
999+
</Badge>
<Badge appearance="filled" color="subtle">
999+
</Badge>
<Badge appearance="filled" color="success">
999+
</Badge>
<Badge appearance="filled" color="warning">
999+
</Badge>
</div>

<div>
<Badge size="medium" icon={<BiSolidPaste />} />
</div>
</div>
);
};

export default BadgeDemo;

0 comments on commit 4ae441b

Please sign in to comment.