-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ObservedObserver/dev
feat: badges
- Loading branch information
Showing
10 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import streamlit as st | ||
|
||
import streamlit_shadcn_ui as ui | ||
|
||
st.header("Badges") | ||
|
||
ui.badges(badge_list=[("default", "default"), ("secondary", "secondary"), ("outline", "outline"), ("Hello", "destructive"), ("World", "destructive")], class_name="flex gap-2", key="badges1") | ||
|
This file contains 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 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
17 changes: 17 additions & 0 deletions
17
streamlit_shadcn_ui/components/packages/frontend/src/components/streamlit/badge.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Badge, BadgeProps } from "@/components/ui/badge"; | ||
import { forwardRef } from "react"; | ||
|
||
interface StBadgesProps { | ||
badges: { text: string; variant: BadgeProps['variant'] }[]; | ||
className?: string; | ||
} | ||
export const StBadges = forwardRef<HTMLDivElement, StBadgesProps>((props, ref) => { | ||
const { badges, className } = props; | ||
return <div className={className} ref={ref}> | ||
{ | ||
badges.map((badge, index) => { | ||
return <Badge key={`${badge}-${index}`} variant={badge.variant}>{badge.text}</Badge> | ||
}) | ||
} | ||
</div> | ||
}) |
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions
36
streamlit_shadcn_ui/components/packages/frontend/src/components/ui/badge.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as React from "react" | ||
import { cva, type VariantProps } from "class-variance-authority" | ||
|
||
import { cn } from "@/lib/utils" | ||
|
||
const badgeVariants = cva( | ||
"inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", | ||
{ | ||
variants: { | ||
variant: { | ||
default: | ||
"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80", | ||
secondary: | ||
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", | ||
destructive: | ||
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80", | ||
outline: "text-foreground", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
}, | ||
} | ||
) | ||
|
||
export interface BadgeProps | ||
extends React.HTMLAttributes<HTMLDivElement>, | ||
VariantProps<typeof badgeVariants> {} | ||
|
||
function Badge({ className, variant, ...props }: BadgeProps) { | ||
return ( | ||
<div className={cn(badgeVariants({ variant }), className)} {...props} /> | ||
) | ||
} | ||
|
||
export { Badge, badgeVariants } |
4 changes: 2 additions & 2 deletions
4
streamlit_shadcn_ui/components/packages/frontend/src/main.tsx
This file contains 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,5 +1,5 @@ | ||
import ReactDOM from "react-dom/client"; | ||
import App from "./App.tsx"; | ||
import { StApp } from "./App.tsx"; | ||
import "./index.css"; | ||
|
||
ReactDOM.createRoot(document.getElementById("root")!).render(<App />); | ||
ReactDOM.createRoot(document.getElementById("root")!).render(<StApp />); |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from .utils import declare_component | ||
from typing import Tuple | ||
|
||
_RELEASE = True | ||
|
||
_component_func = declare_component("badges", release=_RELEASE) | ||
|
||
def badges(badge_list: list[Tuple[str, str]], class_name: str = None, key = None): | ||
bl = [{"text": b[0], "variant": b[1] } for b in badge_list] | ||
props = {"badges":bl , "className": class_name} | ||
clicked = _component_func(comp="badges", props=props, key=key, default=False) | ||
return clicked |