-
Notifications
You must be signed in to change notification settings - Fork 896
refactor: match StatusIndicator component with the new designs #16458
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
170a731
Refactor status indicator
BrunoQuaresma dd31141
Replace StatusIndicator in old components
BrunoQuaresma 1d78533
Apply fmt
BrunoQuaresma c114d37
Merge branch 'main' of https://github.com/coder/coder into bq/refacto…
BrunoQuaresma 4cb0c64
Apply PR comments
BrunoQuaresma f3da2cc
Fix wrong variants
BrunoQuaresma 38554ea
Fix status icons
BrunoQuaresma 02618d5
Fix status
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 21 additions & 29 deletions
50
site/src/components/StatusIndicator/StatusIndicator.stories.tsx
This file contains hidden or 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 |
---|---|---|
@@ -1,63 +1,55 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { StatusIndicator } from "./StatusIndicator"; | ||
import { StatusIndicator, StatusIndicatorDot } from "./StatusIndicator"; | ||
|
||
const meta: Meta<typeof StatusIndicator> = { | ||
title: "components/StatusIndicator", | ||
component: StatusIndicator, | ||
args: {}, | ||
args: { | ||
children: ( | ||
<> | ||
<StatusIndicatorDot /> | ||
Status | ||
</> | ||
), | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof StatusIndicator>; | ||
|
||
export const Success: Story = { | ||
args: { | ||
color: "success", | ||
}, | ||
}; | ||
|
||
export const SuccessOutline: Story = { | ||
args: { | ||
color: "success", | ||
variant: "outlined", | ||
}, | ||
}; | ||
|
||
export const Warning: Story = { | ||
args: { | ||
color: "warning", | ||
variant: "success", | ||
}, | ||
}; | ||
|
||
export const WarningOutline: Story = { | ||
export const Failed: Story = { | ||
args: { | ||
color: "warning", | ||
variant: "outlined", | ||
variant: "failed", | ||
}, | ||
}; | ||
|
||
export const Danger: Story = { | ||
export const Inactive: Story = { | ||
args: { | ||
color: "danger", | ||
variant: "inactive", | ||
}, | ||
}; | ||
|
||
export const DangerOutline: Story = { | ||
export const Warning: Story = { | ||
args: { | ||
color: "danger", | ||
variant: "outlined", | ||
variant: "warning", | ||
}, | ||
}; | ||
|
||
export const Inactive: Story = { | ||
export const Pending: Story = { | ||
args: { | ||
color: "inactive", | ||
variant: "pending", | ||
}, | ||
}; | ||
|
||
export const InactiveOutline: Story = { | ||
export const Small: Story = { | ||
args: { | ||
color: "inactive", | ||
variant: "outlined", | ||
variant: "success", | ||
size: "sm", | ||
}, | ||
}; |
110 changes: 87 additions & 23 deletions
110
site/src/components/StatusIndicator/StatusIndicator.tsx
This file contains hidden or 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 |
---|---|---|
@@ -1,33 +1,97 @@ | ||
import { useTheme } from "@emotion/react"; | ||
import type { FC } from "react"; | ||
import type { ThemeRole } from "theme/roles"; | ||
import { type VariantProps, cva } from "class-variance-authority"; | ||
import { type FC, createContext, useContext } from "react"; | ||
import { cn } from "utils/cn"; | ||
|
||
interface StatusIndicatorProps { | ||
color: ThemeRole; | ||
variant?: "solid" | "outlined"; | ||
} | ||
const statusIndicatorVariants = cva( | ||
"font-medium inline-flex items-center gap-2", | ||
{ | ||
variants: { | ||
variant: { | ||
success: "text-content-success", | ||
failed: "text-content-destructive", | ||
inactive: "text-highlight-grey", | ||
warning: "text-content-warning", | ||
pending: "text-highlight-sky", | ||
}, | ||
size: { | ||
sm: "text-xs", | ||
md: "text-sm", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "success", | ||
size: "md", | ||
}, | ||
}, | ||
); | ||
|
||
type StatusIndicatorContextValue = VariantProps<typeof statusIndicatorVariants>; | ||
|
||
const StatusIndicatorContext = createContext<StatusIndicatorContextValue>({}); | ||
|
||
export interface StatusIndicatorProps | ||
extends React.HTMLAttributes<HTMLDivElement>, | ||
StatusIndicatorContextValue {} | ||
|
||
export const StatusIndicator: FC<StatusIndicatorProps> = ({ | ||
color, | ||
variant = "solid", | ||
size, | ||
variant, | ||
className, | ||
...props | ||
}) => { | ||
const theme = useTheme(); | ||
return ( | ||
<StatusIndicatorContext.Provider value={{ size, variant }}> | ||
<div | ||
className={cn(statusIndicatorVariants({ variant, size }), className)} | ||
{...props} | ||
/> | ||
</StatusIndicatorContext.Provider> | ||
); | ||
}; | ||
|
||
const dotVariants = cva("rounded-full inline-block border-4 border-solid", { | ||
variants: { | ||
variant: { | ||
success: "bg-content-success border-surface-green", | ||
failed: "bg-content-destructive border-surface-destructive", | ||
inactive: "bg-highlight-grey border-surface-grey", | ||
warning: "bg-content-warning border-surface-orange", | ||
pending: "bg-highlight-sky border-surface-sky", | ||
}, | ||
size: { | ||
sm: "size-3 border-4", | ||
md: "size-4 border-4", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "success", | ||
size: "md", | ||
}, | ||
}); | ||
|
||
export interface StatusIndicatorDotProps | ||
extends React.HTMLAttributes<HTMLDivElement>, | ||
VariantProps<typeof dotVariants> {} | ||
|
||
export const StatusIndicatorDot: FC<StatusIndicatorDotProps> = ({ | ||
className, | ||
// We allow the size and variant to be overridden directly by the component. | ||
// This allows StatusIndicatorDot to be used alone. | ||
size, | ||
variant, | ||
...props | ||
}) => { | ||
const { size: ctxSize, variant: ctxVariant } = useContext( | ||
StatusIndicatorContext, | ||
); | ||
|
||
return ( | ||
<div | ||
css={[ | ||
{ | ||
height: 8, | ||
width: 8, | ||
borderRadius: 4, | ||
}, | ||
variant === "solid" && { | ||
backgroundColor: theme.roles[color].fill.solid, | ||
}, | ||
variant === "outlined" && { | ||
border: `1px solid ${theme.roles[color].outline}`, | ||
}, | ||
]} | ||
className={cn( | ||
dotVariants({ variant: variant ?? ctxVariant, size: size ?? ctxSize }), | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
); | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.