-
Notifications
You must be signed in to change notification settings - Fork 17
/
Help.elm
133 lines (112 loc) · 4.21 KB
/
Help.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
{--
SPDX-License-Identifier: Apache-2.0
--}
module Components.Help exposing (Command, Props, cmdSize, view)
import Components.Svgs as SvgBuilder
import FeatherIcons
import Html exposing (Html, a, button, details, div, input, label, span, strong, summary, text)
import Html.Attributes exposing (attribute, class, for, href, id, readonly, size, tabindex, type_, value)
import Html.Events exposing (onClick)
import Shared
import Utils.Helpers as Util
-- TYPES
{-| Props : alias for an object representing properties for the contextual help component.
-}
type alias Props msg =
{ show : Bool
, showHide : Maybe Bool -> msg
, commands : List Command
, showCopyAlert : String -> msg
}
{-| Command : alias for an object representing the attributes of a command.
-}
type alias Command =
{ name : String
, content : String
, docs : Maybe String
}
-- VIEW
{-| view : renders contextual help component when tooltip is selected.
-}
view : Shared.Model -> Props msg -> Html msg
view shared props =
details
(class "details"
:: class "help"
:: class "-no-pad"
:: Util.open props.show
)
[ summary
[ class "summary"
, class "-no-pad"
, Util.testAttribute "help-trigger"
, tabindex 0
, Util.onClickPreventDefault (props.showHide Nothing)
]
[ SvgBuilder.terminal ]
, div [ class "tooltip", Util.testAttribute "help-tooltip" ] <|
strong [] [ text "Manage Vela resources using the CLI" ]
:: List.map (viewCommand shared props) props.commands
++ [ div [ class "help-footer", Util.testAttribute "help-footer" ]
[ a [ href <| shared.velaDocsURL ++ "/reference/cli/install" ] [ text "CLI Installation Docs" ]
, a [ href <| shared.velaDocsURL ++ "/reference/cli/authentication" ] [ text "CLI Authentication Docs" ]
]
]
]
{-| viewCommand : renders contextual cli command and cli doc link.
-}
viewCommand : Shared.Model -> Props msg -> Command -> Html msg
viewCommand shared props command =
div [ class "form-controls", class "-stack", Util.testAttribute "help-cmd-header" ]
[ span []
[ label [ class "form-label", for <| "" ] [ text <| command.name ++ " " ]
, case command.docs of
Just docs ->
a
[ class "cmd-link"
, href <| shared.velaDocsURL ++ "/reference/cli/" ++ docs
, attribute "aria-label" <| "go to cli docs page for " ++ docs
]
[ text "(docs)"
]
Nothing ->
text ""
]
, div
[ class "cmd"
, Util.testAttribute "help-row"
]
[ input
[ class "cmd-text"
, type_ "text"
, readonly True
, id command.name
, size <| cmdSize command.content
, value command.content
]
[]
, if not <| String.isEmpty command.content then
div [ class "vert-icon-container" ]
[ button
[ Util.testAttribute "help-copy"
, attribute "aria-label" <| "copy " ++ command.content ++ " to clipboard"
, class "button"
, class "-icon"
, onClick <| props.showCopyAlert command.content
, class "copy-button"
, attribute "data-clipboard-text" command.content
]
[ FeatherIcons.copy
|> FeatherIcons.withSize 18
|> FeatherIcons.toHtml []
]
]
else
text ""
]
]
{-| cmdSize : takes command content and returns appropriate size for readonly input; max value of 18 is arbitrary.
-}
cmdSize : String -> Int
cmdSize content =
max 18 <| String.length content