8000 feat: add UI badges for labeling beta features by lizard-boy · Pull Request #11 · grepdemos/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: add UI badges for labeling beta features #11

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: change component API to be more obvious/ergonomic
  • Loading branch information
Parkreiner committed Sep 16, 2024
commit ad61763536431103318b6a1295392e3f9c8c2660
3 changes: 2 additions & 1 deletion site/src/components/FeatureBadge/FeatureBadge.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export const HoverControlledByParent: Story = {
{Story({
args: {
...context.initialArgs,
variant: isHovering ? "staticHover" : "static",
variant: "static",
highlighted: isHovering,
},
})}
</button>
Expand Down
54 changes: 29 additions & 25 deletions site/src/components/FeatureBadge/FeatureBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,43 @@ const styles = {
},
} as const satisfies Record<string, Interpolation<Theme>>;

function grammaticalArticle(nextWord: string): string {
const vowels = ["a", "e", "i", "o", "u"];
const firstLetter = nextWord.slice(0, 1).toLowerCase();
return vowels.includes(firstLetter) ? "an" : "a";
}

function capitalizeFirstLetter(text: string): string {
return text.slice(0, 1).toUpperCase() + text.slice(1);
}

type FeatureBadgeProps = Readonly<
Omit<HTMLAttributes<HTMLSpanElement>, "children"> & {
type: keyof typeof featureBadgeTypes;
size?: "sm" | "lg";

/**
* Defines how the FeatureBadge should render.
* - interactive (default) - The badge functions like a link and
* controls its own hover styling.
* - static - The badge is completely static and has no interaction
* behavior.
* - staticHover - The badge is completely static, but displays badge
hover styling (but nothing related to links). Useful if you want a
parent component to control the hover styling.
*/
variant?: "interactive" | "static" | "staticHover";
}
} & (
| {
/**
* Defines whether the FeatureBadge should act as a
* controlled or uncontrolled component with its hover and
* general interaction styling.
*/
variant: "interactive";

// Had to specify the highlighted key for this union option
// even though it won't be used, because otherwise the type
// ergonomics for users would be too clunky.
highlighted?: undefined;
}
| { variant: "static"; highlighted?: boolean }
)
>;

export const FeatureBadge: FC<FeatureBadgeProps> = ({
type,
size = "sm",
variant = "interactive",
highlighted = false,
onPointerEnter,
onPointerLeave,
...delegatedProps
Expand All @@ -121,7 +135,7 @@ export const FeatureBadge: FC<FeatureBadgeProps> = ({

const featureType = featureBadgeTypes[type];
const showBadgeHoverStyle =
variant === "staticHover" ||
highlighted ||
(variant === "interactive" && (isBadgeHovering || isTooltipHovering));

const coreContent = (
Expand Down Expand Up @@ -171,7 +185,7 @@ export const FeatureBadge: FC<FeatureBadgeProps> = ({
</h5>

<p css={styles.tooltipDescription}>
This is {getGrammaticalArticle(featureType)} {featureType} feature. It
This is {grammaticalArticle(featureType)} {featureType} feature. It
has not yet reached generally availability (GA).
</p>

Expand All @@ -188,13 +202,3 @@ export const FeatureBadge: FC<FeatureBadgeProps> = ({
</Popover>
);
};

function getGrammaticalArticle(nextWord: string): string {
const vowels = ["a", "e", "i", "o", "u"];
const firstLetter = nextWord.slice(0, 1).toLowerCase();
return vowels.includes(firstLetter) ? "an" : "a";
}

function capitalizeFirstLetter(text: string): string {
return text.slice(0, 1).toUpperCase() + text.slice(1);
}
0