From 1a4daea35985d0ce318eb5bf56c095a00ec09704 Mon Sep 17 00:00:00 2001 From: Tessa Kelly Date: Fri, 4 Mar 2022 17:04:56 -0800 Subject: [PATCH] Add general choice helper --- styleguide-app/CommonControls.elm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/styleguide-app/CommonControls.elm b/styleguide-app/CommonControls.elm index 37aafbc6..373ddff2 100644 --- a/styleguide-app/CommonControls.elm +++ b/styleguide-app/CommonControls.elm @@ -1,11 +1,13 @@ module CommonControls exposing ( css, mobileCss, quizEngineMobileCss, notMobileCss + , choice , disabledListItem, exampleHtml, httpError, premiumLevel, quickBrownFox, romeoAndJulietQuotation, uiIcon ) {-| @docs css, mobileCss, quizEngineMobileCss, notMobileCss +@docs choice -} @@ -22,9 +24,9 @@ import Nri.Ui.UiIcon.V1 as UiIcon premiumLevel : Control ( String, PremiumLevel ) premiumLevel = - Control.choice - [ ( "Free", Control.value ( "Free", Free ) ) - , ( "PremiumWithWriting", Control.value ( "PremiumWithWriting", PremiumWithWriting ) ) + choice "PremiumLevel" + [ ( "Free", Free ) + , ( "PremiumWithWriting", PremiumWithWriting ) ] @@ -116,9 +118,15 @@ uiIcon = , ( "library", UiIcon.library ) , ( "searchInCicle", UiIcon.searchInCicle ) ] + |> choice "UiIcon" + + +choice : String -> List ( String, value ) -> Control ( String, value ) +choice moduleName options = + options |> List.map (\( name, value ) -> - ( name, Control.value ( "UiIcon." ++ name, value ) ) + ( name, Control.value ( moduleName ++ "." ++ name, value ) ) ) |> Control.choice