-
Notifications
You must be signed in to change notification settings - Fork 0
feat(api): add LabelBadge type for two-part pill badges Introduce LabelBadge struct that renders a muted label followed by an emphasized value, supporting customizable colors, text colors, shapes, and optional icons. Implements Textable interface with String(), ANSI(), HTML(), and Markdown() methods. Add HTML React formatter support to convert LabelBadge to clicky-ui Badge component. Also add DetailLevel enum and Detailable interface to text.go for multi-section detail views with context-aware rendering. #99
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
572665d
feat(entity): Add filter lookup support for dynamic filter metadata a…
moshloop 530ddd8
feat(prompt): Add interactive prompt APIs with select, multi-select, …
moshloop 80a36f8
feat(task,examples): Add interactive prompt support and task terminal…
moshloop 252e017
feat(formatters): standardize clicky JSON content type to application…
moshloop 2eac43a
feat(api,ui,example): add time range filtering and entity detail page…
moshloop c0312a3
feat(entity-example): add link and linkcommand examples page with dee…
moshloop 95718d3
feat(api,rpc,entity): Add Link types and entity operation annotations…
moshloop cd1a773
feat(formatters): add format callbacks and link/command support
moshloop 57bf1e8
feat(task,lint,log): add output capture and log serialization for cle…
moshloop c7af84e
feat(api): add LabelBadge type for two-part pill badges
moshloop 23de4c6
chore(examples): remove legacy example files and update dependencies
moshloop 2526808
feat(task): improve task rendering with priority-based ordering and c…
moshloop ef6e5d8
fix: address PR #99 test failures and CodeRabbit review
moshloop 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
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 |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ permissions: | |
| id-token: write | ||
|
|
||
| env: | ||
| GO_VERSION: "1.25" | ||
| GO_VERSION: "1.26" | ||
|
|
||
| jobs: | ||
| semantic-release: | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -81,3 +81,4 @@ __debug* | |
| ginkgo.report | ||
| *.bak | ||
| examples/uber_demo/uber_demo | ||
| .gavel/ | ||
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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "html" | ||
| "strings" | ||
| ) | ||
|
|
||
| // LabelBadge is a two-part pill: a muted label followed by an emphasised | ||
| // value, rendered by clicky-ui's <Badge variant="label" />. It is distinct | ||
| // from the single-label Badge() helper in html.go, which produces a plain | ||
| // pill with no label/value split. | ||
| // | ||
| // The Color/TextColor fields accept tailwind class names (e.g. "bg-blue-100" | ||
| // and "text-slate-700"); Shape controls the corner radius and Icon is an | ||
| // optional iconify name rendered before the label. | ||
| type LabelBadge struct { | ||
| Label string | ||
| Value string | ||
| Color string // tailwind bg class, e.g. "bg-blue-100" | ||
| TextColor string // tailwind text class, e.g. "text-slate-700" | ||
| Shape string // "pill" | "rounded" | "square"; default "rounded" | ||
| Icon string // iconify icon name, optional | ||
| } | ||
|
|
||
| func (b LabelBadge) String() string { | ||
| if b.Label == "" { | ||
| return b.Value | ||
| } | ||
| if b.Value == "" { | ||
| return b.Label | ||
| } | ||
| return b.Label + ": " + b.Value | ||
| } | ||
|
|
||
| func (b LabelBadge) ANSI() string { | ||
| return b.String() | ||
| } | ||
|
|
||
| func (b LabelBadge) HTML() string { | ||
| shape := "rounded-md" | ||
| switch b.Shape { | ||
| case "pill": | ||
| shape = "rounded-full" | ||
| case "square": | ||
| shape = "rounded-none" | ||
| } | ||
| classes := []string{"inline-flex", "items-center", shape, "text-xs"} | ||
| if b.Color != "" { | ||
| classes = append(classes, b.Color) | ||
| } else { | ||
| classes = append(classes, "bg-gray-100") | ||
| } | ||
| if b.TextColor != "" { | ||
| classes = append(classes, b.TextColor) | ||
| } | ||
|
|
||
| var inner strings.Builder | ||
| if b.Icon != "" { | ||
| fmt.Fprintf(&inner, `<span class="px-1 iconify" data-icon="%s" aria-hidden="true"></span>`, html.EscapeString(b.Icon)) | ||
| } | ||
| if b.Label != "" { | ||
| fmt.Fprintf(&inner, `<span class="px-1 font-medium opacity-70">%s</span>`, html.EscapeString(b.Label)) | ||
| } | ||
| if b.Value != "" { | ||
| fmt.Fprintf(&inner, `<span class="px-1">%s</span>`, html.EscapeString(b.Value)) | ||
| } | ||
|
|
||
| return fmt.Sprintf(`<span class="%s">%s</span>`, strings.Join(classes, " "), inner.String()) | ||
| } | ||
|
|
||
| func (b LabelBadge) Markdown() string { | ||
| if b.Label == "" { | ||
| return b.Value | ||
| } | ||
| if b.Value == "" { | ||
| return fmt.Sprintf("**%s**", b.Label) | ||
| } | ||
| return fmt.Sprintf("**%s**: %s", b.Label, b.Value) | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestLabelBadge_String(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| b LabelBadge | ||
| want string | ||
| }{ | ||
| {"label and value", LabelBadge{Label: "env", Value: "prod"}, "env: prod"}, | ||
| {"only value", LabelBadge{Value: "prod"}, "prod"}, | ||
| {"only label", LabelBadge{Label: "env"}, "env"}, | ||
| {"empty", LabelBadge{}, ""}, | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| if got := tc.b.String(); got != tc.want { | ||
| t.Errorf("String() = %q, want %q", got, tc.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestLabelBadge_Markdown(t *testing.T) { | ||
| b := LabelBadge{Label: "env", Value: "prod"} | ||
| if got, want := b.Markdown(), "**env**: prod"; got != want { | ||
| t.Errorf("Markdown() = %q, want %q", got, want) | ||
| } | ||
| if got, want := (LabelBadge{Value: "prod"}).Markdown(), "prod"; got != want { | ||
| t.Errorf("Markdown(value-only) = %q, want %q", got, want) | ||
| } | ||
| } | ||
|
|
||
| func TestLabelBadge_HTML_EscapesUserInput(t *testing.T) { | ||
| b := LabelBadge{Label: "<script>", Value: `"bad"`} | ||
| got := b.HTML() | ||
| if strings.Contains(got, "<script>") { | ||
| t.Errorf("HTML() did not escape label: %q", got) | ||
| } | ||
| if strings.Contains(got, `"bad"`) { | ||
| t.Errorf("HTML() did not escape value: %q", got) | ||
| } | ||
| if !strings.Contains(got, "<script>") { | ||
| t.Errorf("HTML() missing escaped label: %q", got) | ||
| } | ||
| } | ||
|
|
||
| func TestLabelBadge_HTML_UsesColorClasses(t *testing.T) { | ||
| b := LabelBadge{Label: "k", Value: "v", Color: "bg-blue-100", TextColor: "text-slate-700"} | ||
| got := b.HTML() | ||
| for _, want := range []string{"bg-blue-100", "text-slate-700"} { | ||
| if !strings.Contains(got, want) { | ||
| t.Errorf("HTML() missing class %q in %q", want, got) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestLabelBadge_ImplementsTextable(t *testing.T) { | ||
| var _ Textable = LabelBadge{} | ||
| } |
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.