Skip to content

feat(status-badge): add borderless size #4094

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

Merged
merged 1 commit into from
Oct 3, 2024
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
6 changes: 6 additions & 0 deletions .changeset/clean-llamas-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-paste/status": minor
"@twilio-paste/core": minor
---

[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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: great description

5 changes: 5 additions & 0 deletions .changeset/fuzzy-crews-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@twilio-paste/codemods": minor
---

[Codemods] new export from badge package (type)
6 changes: 6 additions & 0 deletions .changeset/soft-snails-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-paste/badge": minor
"@twilio-paste/core": minor
---

[Badge] new type export: BadgeSizes for use in status-badge package
2 changes: 1 addition & 1 deletion packages/paste-core/components/badge/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type { BadgeBaseProps, BadgeProps, BadgeButtonProps, BadgeSpanProps } from "./types";
export type { BadgeBaseProps, BadgeProps, BadgeButtonProps, BadgeSpanProps, BadgeSizes } from "./types";
export { useResizeChildIcons } from "./hooks";
export { badgeBaseStyles, badgeVariantStyles, badgeButtonStyles, getBadgeButtonStyles } from "./styles";
export { BadgeVariants } from "./constants";
Expand Down
45 changes: 40 additions & 5 deletions packages/paste-core/components/status/src/StatusBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { badgeBaseStyles, badgeVariantStyles } from "@twilio-paste/badge";
import type { BadgeBaseProps, BadgeSpanProps } from "@twilio-paste/badge";
import { Box, safelySpreadBoxProps } from "@twilio-paste/box";
import type { BadgeBaseProps, BadgeSizes, BadgeSpanProps } from "@twilio-paste/badge";
import { Box, BoxStyleProps, safelySpreadBoxProps } from "@twilio-paste/box";
import { Space } from "@twilio-paste/style-props";
import * as React from "react";

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

export type StatusBadgeProps = Omit<BadgeBaseProps, "variant"> &
export type StatusBadgeProps = Omit<BadgeBaseProps, "variant" | "size"> &
BadgeSpanProps & {
/**
* Overrides the default element name to apply unique styles with the Customization Provider
Expand All @@ -21,10 +22,43 @@ export type StatusBadgeProps = Omit<BadgeBaseProps, "variant"> &
* @type {StatusBadgeVariants}
*/
variant: StatusBadgeVariants;
/**
* Sets the size of the Status Badge
*
* @default "default"
* @type {"default" | "small" | "borderless"}
*/
size?: BadgeSizes | "borderless";
};

const paddingX = (size: StatusBadgeProps["size"]): Space => {
switch (size) {
case "small":
return "space20";
case "borderless":
return "space0";
default:
return "space30";
}
};
const paddingY = (size: StatusBadgeProps["size"]): Space => {
switch (size) {
case "small":
return "space10";
case "borderless":
return "space0";
default:
return "space20";
}
};

const badgeStyles = { ...badgeBaseStyles, ...badgeVariantStyles.default };

const badgeBorderlessStyles: BoxStyleProps = {
boxShadow: "none",
backgroundColor: "transparent",
};

const StatusBadge = React.forwardRef<HTMLElement, StatusBadgeProps>(
({ children, element = "STATUS_BADGE", size, variant, ...props }, ref) => {
return (
Expand All @@ -35,12 +69,13 @@ const StatusBadge = React.forwardRef<HTMLElement, StatusBadgeProps>(
variant={variant}
{...badgeStyles}
color={StatusObject[variant].color}
paddingX={size === "small" ? "space20" : "space30"}
paddingY={size === "small" ? "space10" : "space20"}
paddingX={paddingX(size)}
paddingY={paddingY(size)}
display="flex"
flexDirection="row"
columnGap="space20"
alignItems="center"
{...(size === "borderless" && badgeBorderlessStyles)}
ref={ref}
>
{StatusObject[variant].icon}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryFn } from "@storybook/react";
import { Box } from "@twilio-paste/box";
import * as React from "react";

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

const Template: StoryFn<typeof StatusBadge> = ({ variant }) => (
<StatusBadge as="span" variant={variant}>
{variant}
</StatusBadge>
<Box display="flex" flexDirection="column" rowGap="space60">
<StatusBadge as="span" variant={variant} size="default">
{variant}
</StatusBadge>
<StatusBadge as="span" variant={variant} size="small">
{variant}
</StatusBadge>
<StatusBadge as="span" variant={variant} size="borderless">
{variant}
</StatusBadge>
</Box>
);

export const ProcessSuccessStatusBadge = Template.bind({});
Expand Down
5 changes: 3 additions & 2 deletions packages/paste-core/components/status/type-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1542,10 +1542,11 @@
"externalProp": true
},
"size": {
"type": "BadgeSizes",
"type": "BadgeSizes | \"borderless\"",
"defaultValue": "default",
"required": false,
"externalProp": false
"externalProp": false,
"description": "Sets the size of the Status Badge"
},
"slot": {
"type": "string",
Expand Down
Loading
Loading