Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Commit d820bb8

Browse files
committed
Perspective: Improve rendering of very long names
Now, with a very long namespace perspective, always ensure that the visual slug is visible and clip the namespace on the left side, favoring the tail end of the namespace: `base.List.NonEmpty` might become `...List.NonEmpty` rather than `base.List.NonE...`.
1 parent a1532a9 commit d820bb8

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

src/App.elm

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import UI.Click as Click exposing (Click(..))
2929
import UI.Icon as Icon
3030
import UI.Modal as Modal
3131
import UI.Sidebar as Sidebar
32+
import UI.Size as Size
3233
import UI.Tooltip as Tooltip
3334
import UnisonShare.SidebarContent
3435
import Url exposing (Url)
@@ -504,26 +505,19 @@ viewPerspective env =
504505
Codebase _ ->
505506
UI.nothing
506507

507-
Namespace { codebaseHash, fqn } ->
508+
Namespace { fqn } ->
508509
let
509-
fqnText =
510-
FQN.toString fqn
511-
512-
context =
513-
Env.appContextToString env.appContext
514-
515-
back =
516-
Tooltip.tooltip
517-
(Button.icon (ChangePerspective (Codebase codebaseHash)) Icon.arrowLeftUp |> Button.small |> Button.uncontained |> Button.view)
518-
(Tooltip.Text ("You're currently viewing a subset of " ++ context ++ " (" ++ fqnText ++ "), click to reveal everything."))
519-
|> Tooltip.withArrow Tooltip.Start
520-
|> Tooltip.view
510+
-- Imprecise, but close enough, approximation of overflowing,
511+
-- which results in a slight faded left edge A better way would
512+
-- be to measure the DOM like we do for overflowing docs, but
513+
-- thats quite involved...
514+
isOverflowing =
515+
fqn |> FQN.toString |> String.length |> (\l -> l > 20)
521516
in
522517
header
523-
[ class "perspective" ]
524-
[ div [ class "namespace-slug" ] []
525-
, h2 [] [ FQN.view fqn ]
526-
, back
518+
[ classList [ ( "perspective", True ), ( "is-overflowing", isOverflowing ) ] ]
519+
[ UI.namespaceSlug
520+
, h2 [ class "namespace" ] [ FQN.view fqn ]
527521
]
528522

529523

src/UI.elm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,8 @@ divider =
6666
charWidth : Int -> String
6767
charWidth numChars =
6868
String.fromInt numChars ++ "ch"
69+
70+
71+
namespaceSlug : Html msg
72+
namespaceSlug =
73+
div [ class "namespace-slug" ] []

src/css/app.css

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
display: flex;
193193
flex-direction: row;
194194
position: relative;
195+
gap: 0.75rem;
195196
}
196197

197198
#main-sidebar .perspective:after {
@@ -209,14 +210,34 @@
209210
}
210211

211212
#main-sidebar .perspective .namespace-slug {
212-
margin-right: 0.75rem;
213+
position: relative;
213214
}
214215

215-
#main-sidebar .perspective h2 {
216+
#main-sidebar .perspective.is-overflowing .namespace-slug:after {
217+
position: absolute;
218+
top: 0;
219+
right: -1.5rem;
220+
bottom: 0;
221+
content: "";
222+
width: 1.5rem;
223+
background: linear-gradient(
224+
90deg,
225+
var(--color-sidebar-bg),
226+
var(--color-sidebar-bg),
227+
var(--color-sidebar-bg-transparent)
228+
);
229+
}
230+
231+
#main-sidebar .perspective .namespace {
232+
display: inline-flex;
216233
color: var(--color-sidebar-fg-em);
217234
font-size: 1rem;
218235
font-weight: 500;
219236
height: 1.5rem;
237+
overflow: hidden;
238+
white-space: nowrap;
239+
text-align: right;
240+
flex-direction: row-reverse;
220241
}
221242

222243
#main-sidebar .perspective .tooltip-bubble {

src/css/elements.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ hr {
174174
/* Namespace Slug */
175175
.namespace-slug {
176176
display: inline-flex;
177+
flex: 0 0 1.5rem;
177178
width: 1.5rem;
178179
height: 1.5rem;
179180
background: url(../img/namespace-slug-untitled.svg);

0 commit comments

Comments
 (0)