2018-04-30 14:14:20 +03:00
|
|
|
module Examples.Button exposing (Msg, State, example, init, update)
|
|
|
|
|
|
|
|
{- \
|
|
|
|
@docs Msg, State, example, init, update,
|
|
|
|
-}
|
|
|
|
|
2018-08-18 02:06:31 +03:00
|
|
|
import Css exposing (middle, verticalAlign)
|
2018-04-30 14:14:20 +03:00
|
|
|
import Debug.Control as Control exposing (Control)
|
2018-06-22 12:41:38 +03:00
|
|
|
import Headings
|
2018-08-18 00:37:26 +03:00
|
|
|
import Html.Styled exposing (..)
|
2018-12-13 23:59:35 +03:00
|
|
|
import Html.Styled.Attributes exposing (css, id)
|
2018-04-30 14:14:20 +03:00
|
|
|
import ModuleExample as ModuleExample exposing (Category(..), ModuleExample, ModuleMessages)
|
2018-04-30 14:24:03 +03:00
|
|
|
import Nri.Ui.AssetPath exposing (Asset)
|
2019-01-31 00:45:13 +03:00
|
|
|
import Nri.Ui.BorderlessButton.V1 as BorderlessButton
|
2018-12-13 20:09:32 +03:00
|
|
|
import Nri.Ui.Button.V7 as Button
|
|
|
|
import Nri.Ui.Icon.V4 as Icon
|
2018-12-13 23:59:35 +03:00
|
|
|
import Nri.Ui.Text.V2 as Text
|
2018-04-30 14:14:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type Msg
|
|
|
|
= SetState State
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type State
|
|
|
|
= State (Control Model)
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type ButtonType
|
|
|
|
= Button
|
|
|
|
| Link
|
|
|
|
| CopyToClipboard
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
example :
|
2018-08-18 01:37:33 +03:00
|
|
|
{ r | teach_assignments_copyWhite_svg : Asset, x : String }
|
2018-04-30 14:14:20 +03:00
|
|
|
-> (String -> ModuleMessages Msg parentMsg)
|
|
|
|
-> State
|
|
|
|
-> ModuleExample parentMsg
|
|
|
|
example assets unnamedMessages state =
|
|
|
|
let
|
|
|
|
messages =
|
|
|
|
unnamedMessages "ButtonExample"
|
|
|
|
in
|
2018-12-13 20:09:32 +03:00
|
|
|
{ filename = "Nri.Ui.Button.V7"
|
2018-04-30 14:24:03 +03:00
|
|
|
, category = Buttons
|
|
|
|
, content =
|
|
|
|
[ viewButtonExamples assets messages state ]
|
|
|
|
}
|
2018-04-30 14:14:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
init : { r | performance : String, lock : String } -> State
|
|
|
|
init assets =
|
|
|
|
Control.record Model
|
|
|
|
|> Control.field "label" (Control.string "Button")
|
2018-10-01 17:12:21 +03:00
|
|
|
|> Control.field "icon (copyToClipboard has only one choice)"
|
2018-04-30 14:14:20 +03:00
|
|
|
(Control.maybe False <|
|
|
|
|
Control.choice
|
2018-12-05 01:36:15 +03:00
|
|
|
( "Performance", Control.value (Icon.performance assets) )
|
|
|
|
[ ( "Lock", Control.value (Icon.lock assets) )
|
2018-04-30 14:14:20 +03:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|> Control.field "width"
|
2018-10-02 15:06:29 +03:00
|
|
|
(Control.choice
|
2018-12-13 20:09:32 +03:00
|
|
|
( "Nri.Ui.Button.V7.WidthExact 120", Control.value <| Button.WidthExact 120 )
|
|
|
|
[ ( "Nri.Ui.Button.V7.WidthExact 70", Control.value <| Button.WidthExact 70 )
|
|
|
|
, ( "Nri.Ui.Button.V7.WidthUnbounded", Control.value <| Button.WidthUnbounded )
|
2018-12-20 21:53:09 +03:00
|
|
|
, ( "Nri.Ui.Button.V7.WidthFillContainer", Control.value <| Button.WidthFillContainer )
|
2018-10-02 15:06:29 +03:00
|
|
|
]
|
2018-04-30 14:14:20 +03:00
|
|
|
)
|
|
|
|
|> Control.field "button type"
|
|
|
|
(Control.choice
|
2018-12-13 20:09:32 +03:00
|
|
|
( "Nri.Ui.Button.V7.button", Control.value Button )
|
|
|
|
[ ( "Nri.Ui.Button.V7.link", Control.value Link )
|
|
|
|
, ( "Nri.Ui.Button.V7.copyToClipboard", Control.value CopyToClipboard )
|
2018-04-30 14:14:20 +03:00
|
|
|
]
|
|
|
|
)
|
2018-10-01 17:12:21 +03:00
|
|
|
|> Control.field "state (button only)"
|
2018-12-05 01:36:15 +03:00
|
|
|
(Control.choice
|
|
|
|
( Debug.toString Button.Enabled, Control.value Button.Enabled )
|
|
|
|
(List.map (\x -> ( Debug.toString x, Control.value x ))
|
|
|
|
[ Button.Disabled
|
2018-04-30 14:14:20 +03:00
|
|
|
, Button.Error
|
|
|
|
, Button.Unfulfilled
|
|
|
|
, Button.Loading
|
|
|
|
, Button.Success
|
|
|
|
]
|
2018-12-05 01:36:15 +03:00
|
|
|
)
|
2018-04-30 14:14:20 +03:00
|
|
|
)
|
|
|
|
|> State
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg state =
|
|
|
|
case msg of
|
|
|
|
SetState newState ->
|
|
|
|
( newState, Cmd.none )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- INTERNAL
|
|
|
|
|
|
|
|
|
|
|
|
type alias Model =
|
|
|
|
{ label : String
|
|
|
|
, icon : Maybe Icon.IconType
|
2018-10-02 13:13:09 +03:00
|
|
|
, width : Button.ButtonWidth
|
2018-04-30 14:14:20 +03:00
|
|
|
, buttonType : ButtonType
|
|
|
|
, state : Button.ButtonState
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-01 17:12:21 +03:00
|
|
|
viewButtonExamples :
|
|
|
|
{ r | teach_assignments_copyWhite_svg : Asset, x : String }
|
|
|
|
-> ModuleMessages Msg parentMsg
|
|
|
|
-> State
|
|
|
|
-> Html parentMsg
|
2018-04-30 14:14:20 +03:00
|
|
|
viewButtonExamples assets messages (State control) =
|
|
|
|
let
|
|
|
|
model =
|
|
|
|
Control.currentValue control
|
2018-12-13 23:59:35 +03:00
|
|
|
|
|
|
|
maybeExplanation =
|
|
|
|
if model.buttonType == CopyToClipboard then
|
|
|
|
div [ css [ Css.margin2 (Css.px 10) Css.zero ] ]
|
|
|
|
[ Text.smallBody
|
|
|
|
[ text "CopyToClipboard requires 'clipboard.js'. See assets/clipboard-setup.js for example configuration."
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
else
|
|
|
|
text ""
|
2018-04-30 14:14:20 +03:00
|
|
|
in
|
2018-04-30 14:24:03 +03:00
|
|
|
[ Control.view (State >> SetState >> messages.wrapper) control
|
2018-08-18 00:37:26 +03:00
|
|
|
|> fromUnstyled
|
2018-12-13 23:59:35 +03:00
|
|
|
, maybeExplanation
|
2018-12-05 01:36:15 +03:00
|
|
|
, buttons assets messages model
|
2018-04-30 14:24:03 +03:00
|
|
|
, toggleButtons messages
|
2018-08-18 01:37:33 +03:00
|
|
|
, Button.delete assets
|
2018-04-30 14:24:03 +03:00
|
|
|
{ label = "Delete Something"
|
|
|
|
, onClick = messages.showItWorked "delete"
|
|
|
|
}
|
2018-08-29 03:18:17 +03:00
|
|
|
, Button.linkExternalWithTracking
|
|
|
|
(messages.showItWorked "linkExternalWithTracking clicked")
|
|
|
|
{ size = Button.Medium
|
|
|
|
, style = Button.Secondary
|
2018-10-02 15:06:29 +03:00
|
|
|
, width = Button.WidthUnbounded
|
2018-08-29 03:18:17 +03:00
|
|
|
, label = "linkExternalWithTracking"
|
|
|
|
, icon = Nothing
|
|
|
|
, url = "#"
|
|
|
|
}
|
2019-01-31 00:56:12 +03:00
|
|
|
, BorderlessButton.button
|
|
|
|
{ label = "I am borderless small"
|
|
|
|
, size = BorderlessButton.Small
|
2019-01-31 01:20:35 +03:00
|
|
|
, icon = model.icon
|
2019-01-31 01:22:49 +03:00
|
|
|
, onClick = messages.showItWorked "borderless small"
|
2019-01-31 00:56:12 +03:00
|
|
|
}
|
|
|
|
, BorderlessButton.button
|
|
|
|
{ label = "I am borderless medium"
|
|
|
|
, size = BorderlessButton.Medium
|
2019-01-31 01:20:35 +03:00
|
|
|
, icon = model.icon
|
2019-01-31 01:22:49 +03:00
|
|
|
, onClick = messages.showItWorked "borderless medium"
|
2019-01-31 00:56:12 +03:00
|
|
|
}
|
|
|
|
, BorderlessButton.button
|
|
|
|
{ label = "I am borderless large"
|
|
|
|
, size = BorderlessButton.Large
|
2019-01-31 01:20:35 +03:00
|
|
|
, icon = model.icon
|
2019-01-31 01:22:49 +03:00
|
|
|
, onClick = messages.showItWorked "borderless large"
|
2019-01-31 00:56:12 +03:00
|
|
|
}
|
2019-02-15 21:31:16 +03:00
|
|
|
, BorderlessButton.link
|
|
|
|
{ label = "I am borderless small link"
|
|
|
|
, size = BorderlessButton.Small
|
|
|
|
, icon = model.icon
|
|
|
|
, url = "https://www.noredink.com"
|
|
|
|
}
|
|
|
|
[]
|
|
|
|
, BorderlessButton.link
|
|
|
|
{ label = "I am borderless medium"
|
|
|
|
, size = BorderlessButton.Medium
|
|
|
|
, icon = model.icon
|
|
|
|
, url = "https://www.noredink.com"
|
|
|
|
}
|
|
|
|
[]
|
|
|
|
, BorderlessButton.link
|
|
|
|
{ label = "I am borderless large"
|
|
|
|
, size = BorderlessButton.Large
|
|
|
|
, icon = model.icon
|
|
|
|
, url = "https://www.noredink.com"
|
|
|
|
}
|
|
|
|
[]
|
2018-04-30 14:24:03 +03:00
|
|
|
]
|
|
|
|
|> div []
|
2018-04-30 14:14:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
sizes : List Button.ButtonSize
|
|
|
|
sizes =
|
|
|
|
[ Button.Small
|
|
|
|
, Button.Medium
|
|
|
|
, Button.Large
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
allStyles : List Button.ButtonStyle
|
|
|
|
allStyles =
|
|
|
|
[ Button.Primary
|
|
|
|
, Button.Secondary
|
|
|
|
, Button.Borderless
|
|
|
|
, Button.Danger
|
|
|
|
, Button.Premium
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2018-10-01 17:12:21 +03:00
|
|
|
buttons :
|
|
|
|
{ r | teach_assignments_copyWhite_svg : Asset }
|
|
|
|
-> ModuleMessages Msg parentMsg
|
|
|
|
-> Model
|
|
|
|
-> Html parentMsg
|
2018-12-05 01:36:15 +03:00
|
|
|
buttons assets messages model =
|
2018-04-30 14:14:20 +03:00
|
|
|
let
|
2018-10-03 11:50:20 +03:00
|
|
|
exampleRow style =
|
2018-04-30 14:14:20 +03:00
|
|
|
List.concat
|
2018-08-18 02:06:31 +03:00
|
|
|
[ [ td
|
|
|
|
[ css
|
|
|
|
[ verticalAlign middle
|
|
|
|
]
|
|
|
|
]
|
2018-12-05 01:36:15 +03:00
|
|
|
[ text <| Debug.toString style ]
|
2018-04-30 14:14:20 +03:00
|
|
|
]
|
|
|
|
, sizes
|
2018-10-03 11:50:20 +03:00
|
|
|
|> List.map (exampleCell style)
|
2018-04-30 14:14:20 +03:00
|
|
|
]
|
|
|
|
|> tr []
|
|
|
|
|
2018-10-03 11:50:20 +03:00
|
|
|
exampleCell style size =
|
2018-04-30 14:14:20 +03:00
|
|
|
(case model.buttonType of
|
|
|
|
Link ->
|
|
|
|
Button.link
|
|
|
|
{ size = size
|
|
|
|
, style = style
|
|
|
|
, label = model.label
|
|
|
|
, icon = model.icon
|
|
|
|
, url = ""
|
|
|
|
, width = model.width
|
|
|
|
}
|
|
|
|
|
|
|
|
Button ->
|
|
|
|
Button.button
|
|
|
|
{ size = size
|
|
|
|
, style = style
|
2018-12-05 01:36:15 +03:00
|
|
|
, onClick = messages.showItWorked (Debug.toString ( style, size ))
|
2018-04-30 14:14:20 +03:00
|
|
|
, width = model.width
|
|
|
|
}
|
|
|
|
{ label = model.label
|
|
|
|
, icon = model.icon
|
|
|
|
, state = model.state
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyToClipboard ->
|
2018-12-13 23:59:35 +03:00
|
|
|
div [ id "clipboard-container" ]
|
|
|
|
[ Button.copyToClipboard
|
|
|
|
assets
|
|
|
|
{ size = size
|
|
|
|
, style = style
|
|
|
|
, copyText = "wire up in your coffee file with clipboard.js"
|
|
|
|
, buttonLabel = model.label
|
|
|
|
, withIcon = model.icon /= Nothing
|
|
|
|
, width = model.width
|
|
|
|
}
|
|
|
|
]
|
2018-04-30 14:14:20 +03:00
|
|
|
)
|
|
|
|
|> List.singleton
|
2018-12-20 21:53:09 +03:00
|
|
|
|> td
|
|
|
|
[ css
|
|
|
|
[ verticalAlign middle
|
|
|
|
, Css.width (Css.px 200)
|
|
|
|
]
|
|
|
|
]
|
2018-04-30 14:14:20 +03:00
|
|
|
in
|
2018-04-30 14:24:03 +03:00
|
|
|
List.concat
|
|
|
|
[ [ sizes
|
2018-12-05 01:36:15 +03:00
|
|
|
|> List.map (\size -> th [] [ text <| Debug.toString size ])
|
2018-04-30 14:24:03 +03:00
|
|
|
|> (\cells -> tr [] (th [] [] :: cells))
|
|
|
|
]
|
|
|
|
, allStyles
|
2018-10-03 11:50:20 +03:00
|
|
|
|> List.map exampleRow
|
2018-04-30 14:24:03 +03:00
|
|
|
]
|
|
|
|
|> table []
|
2018-04-30 14:14:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
toggleButtons : ModuleMessages Msg parentMsg -> Html parentMsg
|
|
|
|
toggleButtons messages =
|
|
|
|
div []
|
2018-10-23 19:55:30 +03:00
|
|
|
[ Headings.h3 [ text "Button toggle" ]
|
2018-04-30 14:14:20 +03:00
|
|
|
, Button.toggleButton
|
|
|
|
{ onDeselect = messages.showItWorked "onDeselect"
|
|
|
|
, onSelect = messages.showItWorked "onSelect"
|
|
|
|
, label = "5"
|
|
|
|
, pressed = False
|
|
|
|
}
|
|
|
|
, Button.toggleButton
|
|
|
|
{ onDeselect = messages.showItWorked "onDeselect"
|
|
|
|
, onSelect = messages.showItWorked "onSelect"
|
|
|
|
, label = "5"
|
|
|
|
, pressed = True
|
|
|
|
}
|
|
|
|
]
|