Skip to content

Commit 52ea257

Browse files
authored
feat(status-badge): add borderless size (#4094)
1 parent 85a7545 commit 52ea257

File tree

10 files changed

+494
-381
lines changed

10 files changed

+494
-381
lines changed

.changeset/clean-llamas-joke.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@twilio-paste/status": minor
3+
"@twilio-paste/core": minor
4+
---
5+
6+
[Status Badge] add new `size` value "borderless" which removes padding and border (box shadow) for a less stylized option of Status Badge for use in Tables and other crowded layouts.

.changeset/fuzzy-crews-brake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@twilio-paste/codemods": minor
3+
---
4+
5+
[Codemods] new export from badge package (type)

.changeset/soft-snails-crash.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@twilio-paste/badge": minor
3+
"@twilio-paste/core": minor
4+
---
5+
6+
[Badge] new type export: BadgeSizes for use in status-badge package

packages/paste-core/components/badge/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type { BadgeBaseProps, BadgeProps, BadgeButtonProps, BadgeSpanProps } from "./types";
1+
export type { BadgeBaseProps, BadgeProps, BadgeButtonProps, BadgeSpanProps, BadgeSizes } from "./types";
22
export { useResizeChildIcons } from "./hooks";
33
export { badgeBaseStyles, badgeVariantStyles, badgeButtonStyles, getBadgeButtonStyles } from "./styles";
44
export { BadgeVariants } from "./constants";

packages/paste-core/components/status/src/StatusBadge.tsx

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { badgeBaseStyles, badgeVariantStyles } from "@twilio-paste/badge";
2-
import type { BadgeBaseProps, BadgeSpanProps } from "@twilio-paste/badge";
3-
import { Box, safelySpreadBoxProps } from "@twilio-paste/box";
2+
import type { BadgeBaseProps, BadgeSizes, BadgeSpanProps } from "@twilio-paste/badge";
3+
import { Box, BoxStyleProps, safelySpreadBoxProps } from "@twilio-paste/box";
4+
import { Space } from "@twilio-paste/style-props";
45
import * as React from "react";
56

67
import { StatusObject } from "./constants";
78
import type { StatusBadgeVariants } from "./types";
89

9-
export type StatusBadgeProps = Omit<BadgeBaseProps, "variant"> &
10+
export type StatusBadgeProps = Omit<BadgeBaseProps, "variant" | "size"> &
1011
BadgeSpanProps & {
1112
/**
1213
* Overrides the default element name to apply unique styles with the Customization Provider
@@ -21,10 +22,43 @@ export type StatusBadgeProps = Omit<BadgeBaseProps, "variant"> &
2122
* @type {StatusBadgeVariants}
2223
*/
2324
variant: StatusBadgeVariants;
25+
/**
26+
* Sets the size of the Status Badge
27+
*
28+
* @default "default"
29+
* @type {"default" | "small" | "borderless"}
30+
*/
31+
size?: BadgeSizes | "borderless";
2432
};
2533

34+
const paddingX = (size: StatusBadgeProps["size"]): Space => {
35+
switch (size) {
36+
case "small":
37+
return "space20";
38+
case "borderless":
39+
return "space0";
40+
default:
41+
return "space30";
42+
}
43+
};
44+
const paddingY = (size: StatusBadgeProps["size"]): Space => {
45+
switch (size) {
46+
case "small":
47+
return "space10";
48+
case "borderless":
49+
return "space0";
50+
default:
51+
return "space20";
52+
}
53+
};
54+
2655
const badgeStyles = { ...badgeBaseStyles, ...badgeVariantStyles.default };
2756

57+
const badgeBorderlessStyles: BoxStyleProps = {
58+
boxShadow: "none",
59+
backgroundColor: "transparent",
60+
};
61+
2862
const StatusBadge = React.forwardRef<HTMLElement, StatusBadgeProps>(
2963
({ children, element = "STATUS_BADGE", size, variant, ...props }, ref) => {
3064
return (
@@ -35,12 +69,13 @@ const StatusBadge = React.forwardRef<HTMLElement, StatusBadgeProps>(
3569
variant={variant}
3670
{...badgeStyles}
3771
color={StatusObject[variant].color}
38-
paddingX={size === "small" ? "space20" : "space30"}
39-
paddingY={size === "small" ? "space10" : "space20"}
72+
paddingX={paddingX(size)}
73+
paddingY={paddingY(size)}
4074
display="flex"
4175
flexDirection="row"
4276
columnGap="space20"
4377
alignItems="center"
78+
{...(size === "borderless" && badgeBorderlessStyles)}
4479
ref={ref}
4580
>
4681
{StatusObject[variant].icon}

packages/paste-core/components/status/stories/StatusBadge.stories.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Meta, StoryFn } from "@storybook/react";
2+
import { Box } from "@twilio-paste/box";
23
import * as React from "react";
34

45
import { StatusBadge } from "../src";
@@ -18,9 +19,17 @@ export default {
1819
} as Meta<typeof StatusBadge>;
1920

2021
const Template: StoryFn<typeof StatusBadge> = ({ variant }) => (
21-
<StatusBadge as="span" variant={variant}>
22-
{variant}
23-
</StatusBadge>
22+
<Box display="flex" flexDirection="column" rowGap="space60">
23+
<StatusBadge as="span" variant={variant} size="default">
24+
{variant}
25+
</StatusBadge>
26+
<StatusBadge as="span" variant={variant} size="small">
27+
{variant}
28+
</StatusBadge>
29+
<StatusBadge as="span" variant={variant} size="borderless">
30+
{variant}
31+
</StatusBadge>
32+
</Box>
2433
);
2534

2635
export const ProcessSuccessStatusBadge = Template.bind({});

packages/paste-core/components/status/type-docs.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,10 +1542,11 @@
15421542
"externalProp": true
15431543
},
15441544
"size": {
1545-
"type": "BadgeSizes",
1545+
"type": "BadgeSizes | \"borderless\"",
15461546
"defaultValue": "default",
15471547
"required": false,
1548-
"externalProp": false
1548+
"externalProp": false,
1549+
"description": "Sets the size of the Status Badge"
15491550
},
15501551
"slot": {
15511552
"type": "string",

0 commit comments

Comments
 (0)