Skip to content

Commit 65516e6

Browse files
authored
Add remove button to stac badge (#806)
* Add cn to components * Add icon-sm size * Add remove button to badges in stac section * Remove log
1 parent 3ed589d commit 65516e6

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

packages/base/src/shared/components/Badge.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import * as React from 'react';
22

3+
import { cn } from './utils';
4+
35
interface IBadgeProps extends React.HTMLAttributes<HTMLButtonElement> {
46
variant?: 'destructive' | 'outline' | 'secondary';
57
size?: 'sm' | 'lg' | 'icon';
68
}
79

8-
function Badge({ variant, ...props }: IBadgeProps) {
10+
function Badge({ variant, className, ...props }: IBadgeProps) {
911
return (
1012
// @ts-expect-error lol
11-
<div data-variant={variant} className={'jgis-badge'} {...props} />
13+
<div
14+
data-variant={variant}
15+
className={cn('jgis-badge', className)}
16+
{...props}
17+
/>
1218
);
1319
}
1420

packages/base/src/shared/components/Button.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Slot } from '@radix-ui/react-slot';
22
import * as React from 'react';
33

4+
import { cn } from './utils';
5+
46
interface IButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
57
asChild?: boolean;
68
variant?: 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link' | 'icon';
7-
size?: 'sm' | 'lg' | 'icon';
9+
size?: 'sm' | 'lg' | 'icon' | 'icon-sm';
810
}
911

1012
const Button = React.forwardRef<HTMLButtonElement, IButtonProps>(
@@ -14,7 +16,7 @@ const Button = React.forwardRef<HTMLButtonElement, IButtonProps>(
1416
<Comp
1517
data-size={size}
1618
data-variant={variant}
17-
className={`jgis-button ${className ? className : ''}`}
19+
className={cn('jgis-button', className)}
1820
ref={ref}
1921
{...props}
2022
/>

packages/base/src/stacBrowser/components/StacFilterSection.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { faXmark } from '@fortawesome/free-solid-svg-icons';
2+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
13
import { ChevronRight } from 'lucide-react';
24
import React, { useMemo } from 'react';
35

46
import Badge from '@/src/shared/components/Badge';
7+
import { Button } from '@/src/shared/components/Button';
58
import {
69
DropdownMenu,
710
DropdownMenuCheckboxItem,
@@ -157,7 +160,19 @@ const StacFilterSection = ({
157160
</DropdownMenu>
158161
<div className="jgis-stac-filter-section-badges">
159162
{selectedData.map(data => (
160-
<Badge key={data}>{data}</Badge>
163+
<Badge key={data} className="jgis-stac-badge">
164+
<span>{data}</span>
165+
<Button
166+
variant="icon"
167+
size="icon-sm"
168+
className="jgis-stac-badge-icon"
169+
onClick={() => {
170+
handleCheckedChange(data, '');
171+
}}
172+
>
173+
<FontAwesomeIcon icon={faXmark} />
174+
</Button>
175+
</Badge>
161176
))}
162177
</div>
163178
</div>

packages/base/style/shared/button.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,8 @@
162162
height: 2.5rem;
163163
width: 2.5rem;
164164
}
165+
166+
.jgis-button[data-size='icon-sm'] {
167+
height: 1rem;
168+
width: 1rem;
169+
}

packages/base/style/stacBrowser.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,16 @@
7676
width: 1rem;
7777
height: 1rem;
7878
}
79+
80+
.jgis-stac-badge {
81+
gap: 0.25rem;
82+
padding-right: 0.3rem !important;
83+
}
84+
85+
.jgis-stac-badge-icon:hover {
86+
background-color: color-mix(
87+
in srgb,
88+
var(--jp-error-color0),
89+
transparent 20%
90+
) !important;
91+
}

0 commit comments

Comments
 (0)