Skip to content

Commit 05d1887

Browse files
committed
Add UI.ContextualTag
1 parent caf8eaf commit 05d1887

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

src/UI/ContextualTag.elm

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
module UI.ContextualTag exposing (..)
2+
3+
import Html exposing (Html, div, text)
4+
import Html.Attributes exposing (class)
5+
import UI.Icon as Icon exposing (Icon)
6+
import UI.Tooltip as Tooltip
7+
8+
9+
type TagColor
10+
= Subdued
11+
| DecorativePurple
12+
| DecorativeBlue
13+
14+
15+
type alias ContextualTag msg =
16+
{ icon : Icon msg
17+
, label : Html msg
18+
, color : TagColor
19+
, tooltipText : Maybe String
20+
}
21+
22+
23+
24+
-- CREATE
25+
26+
27+
contextualTag : Icon msg -> String -> ContextualTag msg
28+
contextualTag icon label =
29+
contextualTag_ icon (text label)
30+
31+
32+
contextualTag_ : Icon msg -> Html msg -> ContextualTag msg
33+
contextualTag_ icon label =
34+
{ icon = icon
35+
, label = label
36+
, color = Subdued
37+
, tooltipText = Nothing
38+
}
39+
40+
41+
42+
-- MODIFY
43+
44+
45+
subdued : ContextualTag msg -> ContextualTag msg
46+
subdued tag =
47+
{ tag | color = Subdued }
48+
49+
50+
decorativePurple : ContextualTag msg -> ContextualTag msg
51+
decorativePurple tag =
52+
{ tag | color = DecorativePurple }
53+
54+
55+
decorativeBlue : ContextualTag msg -> ContextualTag msg
56+
decorativeBlue tag =
57+
{ tag | color = DecorativeBlue }
58+
59+
60+
withTooltipText : String -> ContextualTag msg -> ContextualTag msg
61+
withTooltipText text tag =
62+
{ tag | tooltipText = Just text }
63+
64+
65+
66+
-- VIEW
67+
68+
69+
view : ContextualTag msg -> Html msg
70+
view tag =
71+
let
72+
color =
73+
case tag.color of
74+
Subdued ->
75+
"subdued"
76+
77+
DecorativePurple ->
78+
"decorative-purple"
79+
80+
DecorativeBlue ->
81+
"decorative-blue"
82+
83+
tag_ =
84+
div
85+
[ class "contextual-tag", class color ]
86+
[ Icon.view tag.icon, tag.label ]
87+
in
88+
case tag.tooltipText of
89+
Just t ->
90+
Tooltip.text t
91+
|> Tooltip.tooltip
92+
|> Tooltip.below
93+
|> Tooltip.withArrow Tooltip.Start
94+
|> Tooltip.view tag_
95+
96+
Nothing ->
97+
tag_

src/css/ui/components.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import "./components/icon.css";
2+
@import "./components/contextual-tag.css";
23
@import "./components/by-at.css";
34
@import "./components/text.css";
45
@import "./components/button.css";
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.contextual-tag {
2+
display: flex;
3+
flex-direction: row;
4+
gap: 0.25rem;
5+
align-items: center;
6+
background: var(--c-contextual-tag_background);
7+
border: 1px solid var(--c-contextual-tag_border);
8+
color: var(--c-contextual-tag_text);
9+
font-size: var(--font-size-small);
10+
padding: 0.25rem 0.375rem;
11+
border-radius: var(--border-radius-base);
12+
line-height: 1;
13+
14+
& .icon {
15+
color: var(--c-contextual-tag_icon);
16+
font-size: var(--font-size-medium);
17+
}
18+
}
19+
20+
.contextual-tag.subdued {
21+
--c-contextual-tag_background: var(--u-color_element);
22+
--c-contextual-tag_text: var(--u-color_text);
23+
--c-contextual-tag_icon: var(--u-color_icon);
24+
--c-contextual-tag_border: var(--u-color_icon);
25+
}
26+
27+
.contextual-tag.decorative-purple {
28+
--c-contextual-tag_background: var(--u-color_element_decorative-purple);
29+
--c-contextual-tag_text: var(--u-color_text-on-element-decorative-purple);
30+
--c-contextual-tag_icon: var(--u-color_icon-on-element-decorative-purple);
31+
--c-contextual-tag_border: var(--u-color_border-on-element-decorative-purple);
32+
}

0 commit comments

Comments
 (0)