-
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.
Merge pull request #21 from thep0y/main
0.1.6
- Loading branch information
Showing
7 changed files
with
293 additions
and
3 deletions.
There are no files selected for viewing
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
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,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; | ||
} | ||
} |
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,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; |
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,2 @@ | ||
export { default as Badge } from "./badge"; | ||
export type { BadgeProps } from "./badge"; |
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
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
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,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; |