Skip to content
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

DATA-3167 add progress variant of badge #578

Merged
merged 3 commits into from
Sep 18, 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
13 changes: 13 additions & 0 deletions packages/core/src/lib/__tests__/badge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ describe('Badge', () => {
);
});

it('Renders a progress badge with spinning loader if the variant is specified as progress', () => {
render(Badge, { variant: 'progress', label: 'Progress' });
const badge = screen.getByText('Progress');
const progress = screen.getByLabelText(/progress spinner/iu);

expect(badge).toHaveClass(
'border-info-medium',
'bg-info-light',
'text-info-dark'
);
expect(progress).toBeInTheDocument();
});

it('Renders with the passed cx classes', () => {
render(Badge, {
label: 'Inactive',
Expand Down
52 changes: 32 additions & 20 deletions packages/core/src/lib/badge.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,46 @@

<script lang="ts">
import cx from 'classnames';
import Progress from './progress/progress.svelte';

/** The badge text. */
export let label = '';

/** The color theme of the badge. */
export let variant: 'success' | 'warning' | 'danger' | 'inactive' | 'neutral' =
'inactive';
export let variant:
| 'success'
| 'warning'
| 'danger'
| 'inactive'
| 'neutral'
| 'progress' = 'inactive';

/** Additional CSS classes to pass to the badge. */
let extraClasses: cx.Argument = '';
export { extraClasses as cx };
</script>

<small
class={cx(
'inline-block rounded-full border px-2.5 py-0.5 text-xs',
{
'border-success-medium bg-success-light text-success-dark':
variant === 'success',
'border-warning-medium bg-warning-light text-warning-dark':
variant === 'warning',
'border-danger-medium bg-danger-light text-danger-dark':
variant === 'danger',
'border-medium bg-disabled-light text-default': variant === 'inactive',
'border-info-medium bg-info-light text-info-dark': variant === 'neutral',
},
extraClasses
)}
>
{label}
</small>
<div class="inline-block">
<small
class={cx(
'flex items-center gap-1 rounded-full border px-2.5 py-0.5 text-xs',
{
'border-success-medium bg-success-light text-success-dark':
variant === 'success',
'border-warning-medium bg-warning-light text-warning-dark':
variant === 'warning',
'border-danger-medium bg-danger-light text-danger-dark':
variant === 'danger',
'border-medium bg-disabled-light text-default': variant === 'inactive',
'border-info-medium bg-info-light text-info-dark':
variant === 'neutral' || variant === 'progress',
},
extraClasses
)}
>
{#if variant === 'progress'}
<Progress />
{/if}
{label}
</small>
</div>
1 change: 1 addition & 0 deletions packages/core/src/lib/progress/progress.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export let variant: 'dark' | 'light' = 'dark';
'scale-[1.125]': size === 'medium',
'scale-[1.5]': size === 'large',
})}
aria-label="Progress spinner"
>
<div class="translate-x-[-6.5px]">
{#each { length: 8 } as _, index}
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ const onHoverDelayMsInput = (event: Event) => {
<div class="container mx-auto my-4 flex flex-col gap-8 p-4">
<!-- Badge -->
<h1 class="text-2xl">Badge</h1>
<div>
<div class="flex items-center gap-2">
<Badge
variant="inactive"
label="Inactive"
Expand All @@ -483,6 +483,10 @@ const onHoverDelayMsInput = (event: Event) => {
variant="neutral"
label="Neutral"
/>
<Badge
variant="progress"
label="Progress"
/>
</div>

<!-- Banner -->
Expand Down
Loading