revert optional config because there's only one config option

This commit is contained in:
Michael Glass 2019-10-23 18:33:27 +02:00
parent 091fc357d6
commit 32de6d0a9b
No known key found for this signature in database
GPG Key ID: 9CDD376916491385
2 changed files with 10 additions and 92 deletions

View File

@ -6,8 +6,6 @@ module Nri.Ui.Modal.V8 exposing
, ViewFuncs
, Focusable
, multipleFocusableElementView, onlyFocusableElementView
, OptionalConfig
, invisibleTitle
)
{-| Changes from V7:
@ -116,10 +114,6 @@ type alias Model =
Modal.Model
type alias RequiredConfig msg =
{ title : String, wrapMsg : Msg -> msg }
type alias Config msg =
{ visibleTitle : Bool
, title : String
@ -127,57 +121,6 @@ type alias Config msg =
}
{-| expose intermediate type to make type signatures out of the library nicer
-}
type OptionalConfig msg
= OptionalConfig (Config msg -> Config msg)
| Attribute (Modal.Attribute msg)
configFuncs : List (OptionalConfig msg) -> List (Config msg -> Config msg)
configFuncs configs =
List.filterMap
(\optionalConfig ->
case optionalConfig of
OptionalConfig f ->
Just f
Attribute _ ->
Nothing
)
configs
modalAttributes : List (OptionalConfig msg) -> List (Modal.Attribute msg)
modalAttributes configs =
List.filterMap
(\optionalConfig ->
case optionalConfig of
OptionalConfig _ ->
Nothing
Attribute attrib ->
Just attrib
)
configs
{-| This hides the modal's title
-}
invisibleTitle : OptionalConfig msg
invisibleTitle =
OptionalConfig (\config -> { config | visibleTitle = False })
makeConfig : RequiredConfig msg -> List (OptionalConfig msg) -> Config msg
makeConfig { title, wrapMsg } optionalConfigs =
optionalConfigs
|> configFuncs
|> List.foldl
(\func accum -> func accum)
(Config True title wrapMsg)
{-| -}
init : Model
init =
@ -217,24 +160,22 @@ open =
{-| -}
info :
RequiredConfig msg
-> List (OptionalConfig msg)
Config msg
-> (ViewFuncs msg -> Focusable msg)
-> Model
-> Html msg
info config optionalConfigs getFocusable model =
view Info config optionalConfigs getFocusable model
info config getFocusable model =
view Info config getFocusable model
{-| -}
warning :
RequiredConfig msg
-> List (OptionalConfig msg)
Config msg
-> (ViewFuncs msg -> Focusable msg)
-> Model
-> Html msg
warning config optionalConfigs getFocusable model =
view Warning config optionalConfigs getFocusable model
warning config getFocusable model =
view Warning config getFocusable model
type Theme
@ -295,16 +236,12 @@ type alias ViewFuncs msg =
view :
Theme
-> RequiredConfig msg
-> List (OptionalConfig msg)
-> Config msg
-> (ViewFuncs msg -> Focusable msg)
-> Model
-> Html msg
view theme requiredConfig optionalConfigs getFocusable model =
view theme config getFocusable model =
let
config =
makeConfig requiredConfig optionalConfigs
viewFuncs : ViewFuncs msg
viewFuncs =
{ viewContent = viewContent config.visibleTitle
@ -352,7 +289,6 @@ view theme requiredConfig optionalConfigs getFocusable model =
, Css.border Css.zero
]
]
++ modalAttributes optionalConfigs
++ focusables
)
model

View File

@ -50,14 +50,6 @@ init =
{-| -}
example : (Msg -> msg) -> State -> ModuleExample msg
example parentMessage state =
let
config =
if state.visibleTitle then
[]
else
[ Modal.invisibleTitle ]
in
{ name = "Nri.Ui.Modal.V8"
, category = Modals
, content =
@ -81,16 +73,14 @@ example parentMessage state =
params =
( state, InfoModalMsg, Button.primary )
in
Modal.info { title = "Modal.info", wrapMsg = InfoModalMsg }
config
Modal.info { title = "Modal.info", wrapMsg = InfoModalMsg, visibleTitle = state.visibleTitle }
(getFocusable params)
state.infoModal
, let
params =
( state, WarningModalMsg, Button.danger )
in
Modal.warning { title = "Modal.warning", wrapMsg = WarningModalMsg }
config
Modal.warning { title = "Modal.warning", wrapMsg = WarningModalMsg, visibleTitle = state.visibleTitle }
(getFocusable params)
state.warningModal
]
@ -103,14 +93,6 @@ getFocusable :
-> Modal.ViewFuncs Msg
-> Modal.Focusable Msg
getFocusable ( state, wrapMsg, firstButtonStyle ) { viewContent, closeButton } =
let
defaultOptions =
if state.visibleTitle then
[]
else
[ Modal.invisibleTitle ]
in
case ( state.showX, state.showContinue, state.showSecondary ) of
( True, True, True ) ->
Modal.multipleFocusableElementView