From d5bf1577b4b57b694ef47ea890cb3d136871069c Mon Sep 17 00:00:00 2001 From: Tessa Kelly Date: Fri, 12 Nov 2021 09:56:04 -0800 Subject: [PATCH] :skull: Select V7 --- deprecated-modules.csv | 1 - elm.json | 1 - src/Nri/Ui/Select/V7.elm | 176 -------------------------- tests/Spec/Nri/Ui/Select.elm | 223 --------------------------------- tests/elm-verify-examples.json | 1 - 5 files changed, 402 deletions(-) delete mode 100644 src/Nri/Ui/Select/V7.elm delete mode 100644 tests/Spec/Nri/Ui/Select.elm diff --git a/deprecated-modules.csv b/deprecated-modules.csv index c41edbfc..56c8caf4 100644 --- a/deprecated-modules.csv +++ b/deprecated-modules.csv @@ -1,7 +1,6 @@ Nri.Ui.Accordion.V1,upgrade to V3 Nri.Ui.Menu.V1,upgrade to V3 Nri.Ui.Menu.V2,upgrade to V3 -Nri.Ui.Select.V7,upgrade to V8 Nri.Ui.Table.V4,upgrade to V5 Nri.Ui.Tabs.V6,upgrade to V7 Nri.Ui.Tooltip.V1,upgrade to V2 diff --git a/elm.json b/elm.json index 142183c0..8c5e04bf 100644 --- a/elm.json +++ b/elm.json @@ -45,7 +45,6 @@ "Nri.Ui.PremiumCheckbox.V6", "Nri.Ui.RadioButton.V2", "Nri.Ui.SegmentedControl.V14", - "Nri.Ui.Select.V7", "Nri.Ui.Select.V8", "Nri.Ui.Slide.V1", "Nri.Ui.SlideModal.V2", diff --git a/src/Nri/Ui/Select/V7.elm b/src/Nri/Ui/Select/V7.elm deleted file mode 100644 index ada7bc89..00000000 --- a/src/Nri/Ui/Select/V7.elm +++ /dev/null @@ -1,176 +0,0 @@ -module Nri.Ui.Select.V7 exposing (Choice, view) - -{-| Build a select input. - -@docs Choice, view - --} - -import Css -import Dict -import Html.Styled as Html exposing (Html) -import Html.Styled.Attributes as Attributes -import Html.Styled.Events as Events -import Json.Decode exposing (Decoder) -import Nri.Ui -import Nri.Ui.Colors.Extra as ColorsExtra -import Nri.Ui.Colors.V1 as Colors -import Nri.Ui.CssVendorPrefix.V1 as VendorPrefixed -import Nri.Ui.Fonts.V1 as Fonts -import Nri.Ui.Util -import SolidColor - - -{-| A single possible choice. --} -type alias Choice a = - { label : String, value : a } - - -{-| A select dropdown. Remember to add a label! --} -view : - { choices : List (Choice a) - , current : Maybe a - , id : String - , valueToString : a -> String - , defaultDisplayText : Maybe String - , isInError : Bool - } - -> Html a -view config = - let - valueLookup = - config.choices - |> List.map (\x -> ( niceId (config.valueToString x.value), x.value )) - |> Dict.fromList - - decodeValue string = - Dict.get string valueLookup - |> Maybe.map Json.Decode.succeed - |> Maybe.withDefault - -- At present, elm/virtual-dom throws this failure away. - (Json.Decode.fail - ("Nri.Select: could not decode the value: " - ++ string - ++ "\nexpected one of: " - ++ String.join ", " (Dict.keys valueLookup) - ) - ) - - onSelectHandler = - Events.on "change" (Events.targetValue |> Json.Decode.andThen decodeValue) - - defaultOption = - config.defaultDisplayText - |> Maybe.map (viewDefaultChoice config.current >> List.singleton) - |> Maybe.withDefault [] - - currentVal = - if config.current == Nothing && config.defaultDisplayText == Nothing then - config.choices - |> List.head - |> Maybe.map .value - - else - config.current - in - config.choices - |> List.map (viewChoice currentVal config.valueToString) - |> (++) defaultOption - |> Nri.Ui.styled Html.select - "nri-select-menu" - [ -- border - Css.border3 (Css.px 1) - Css.solid - (if config.isInError then - Colors.purple - - else - Colors.gray75 - ) - , Css.borderBottomWidth (Css.px 3) - , Css.borderRadius (Css.px 8) - , Css.focus [ Css.borderColor Colors.azure ] - - -- Font and color - , Css.color Colors.gray20 - , Fonts.baseFont - , Css.fontSize (Css.px 15) - , Css.fontWeight (Css.int 600) - , Css.textOverflow Css.ellipsis - , Css.overflow Css.hidden - , Css.whiteSpace Css.noWrap - - -- Interaction - , Css.cursor Css.pointer - - -- Size and spacing - , Css.height (Css.px 45) - , Css.width (Css.pct 100) - , Css.paddingLeft (Css.px 15) - , Css.paddingRight (Css.px 30) - - -- Icons - , selectArrowsCss - ] - [ onSelectHandler - , Attributes.id config.id - ] - - -viewDefaultChoice : Maybe a -> String -> Html a -viewDefaultChoice current displayText = - Html.option - [ Attributes.selected (current == Nothing) - , Attributes.disabled True - ] - [ Html.text displayText ] - - -viewChoice : Maybe a -> (a -> String) -> Choice a -> Html a -viewChoice current toString choice = - let - isSelected = - current - |> Maybe.map ((==) choice.value) - |> Maybe.withDefault False - in - Html.option - [ Attributes.id (niceId (toString choice.value)) - , Attributes.value (niceId (toString choice.value)) - , Attributes.selected isSelected - ] - [ Html.text choice.label ] - - -niceId : String -> String -niceId x = - "nri-select-" ++ Nri.Ui.Util.dashify (Nri.Ui.Util.removePunctuation x) - - -selectArrowsCss : Css.Style -selectArrowsCss = - let - color = - SolidColor.toRGBString (ColorsExtra.fromCssColor Colors.azure) - in - Css.batch - [ """ """ - |> urlUtf8 - |> Css.property "background" - , Css.backgroundColor Colors.white - - -- "appearance: none" removes the default dropdown arrows - , VendorPrefixed.property "appearance" "none" - , Css.backgroundRepeat Css.noRepeat - , Css.property "background-position" "center right -20px" - , Css.backgroundOrigin Css.contentBox - ] - - -urlUtf8 : String -> String -urlUtf8 content = - """url('data:image/svg+xml;utf8,""" ++ content ++ """')""" diff --git a/tests/Spec/Nri/Ui/Select.elm b/tests/Spec/Nri/Ui/Select.elm deleted file mode 100644 index 738d50df..00000000 --- a/tests/Spec/Nri/Ui/Select.elm +++ /dev/null @@ -1,223 +0,0 @@ -module Spec.Nri.Ui.Select exposing (spec) - -import Expect exposing (Expectation) -import Html -import Html.Attributes as Attr -import Html.Styled -import Nri.Ui.Select.V7 -import Test exposing (..) -import Test.Html.Query as Query -import Test.Html.Selector exposing (..) - - -spec : Test -spec = - describe "view" <| - viewSuiteV7 - (\config -> - { choices = config.choices - , current = config.current - , id = "fake-id" - , valueToString = identity - , defaultDisplayText = config.defaultDisplayText - , isInError = False - } - |> Nri.Ui.Select.V7.view - |> Html.Styled.toUnstyled - ) - - -viewSuiteV6 : - ({ choices : List { label : String, value : String }, current : Maybe String, defaultDisplayText : Maybe String } -> Html.Html msg) - -> List Test -viewSuiteV6 view = - [ describe "without a default option" - [ test "shows all options" <| - \() -> - viewTestV6 - view - Nothing - Nothing - [ "Tacos", "Burritos", "Enchiladas" ] - |> Query.find [ tag "select" ] - |> Query.findAll [ tag "option" ] - |> Query.count (Expect.equal 3) - , test "selects the first option if nothing is selected and there's no default" <| - \() -> - viewTestV6 - view - Nothing - Nothing - [ "Tacos", "Burritos", "Enchiladas" ] - |> Query.find - [ tag "option" - , attribute <| Attr.selected True - ] - |> Query.has [ text "Tacos" ] - , test "selects the current option" <| - \() -> - viewTestV6 - view - Nothing - (Just "Burritos") - [ "Tacos", "Burritos", "Enchiladas" ] - |> Query.find - [ tag "option" - , attribute <| Attr.selected True - ] - |> Query.has [ text "Burritos" ] - ] - , describe "with a default option" - [ test "shows all options" <| - \() -> - viewTestV6 - view - (Just "Tasty tortilla'd foods") - Nothing - [ "Tacos", "Burritos", "Enchiladas" ] - |> Query.find [ tag "select" ] - |> Query.findAll [ tag "option" ] - |> Query.count (Expect.equal 4) - , test "selects the disabled default option if nothing is currently selected" <| - \() -> - viewTestV6 - view - (Just "Tasty tortilla'd foods") - Nothing - [ "Tacos", "Burritos", "Enchiladas" ] - |> Query.find - [ tag "option" - , attribute <| Attr.selected True - , attribute <| Attr.disabled True - ] - |> Query.has [ text "Tasty tortilla'd foods" ] - , test "selects the current option" <| - \() -> - viewTestV6 - view - (Just "Tasty tortilla'd foods") - (Just "Burritos") - [ "Tacos", "Burritos", "Enchiladas" ] - |> Query.find - [ tag "option" - , attribute <| Attr.selected True - ] - |> Query.has [ text "Burritos" ] - ] - ] - - -viewTestV6 : - ({ choices : List { label : a, value : a }, current : Maybe b, defaultDisplayText : Maybe String } -> Html.Html msg) - -> Maybe String - -> Maybe b - -> List a - -> Query.Single msg -viewTestV6 view defaultDisplayText selected items = - Query.fromHtml - (Html.div [] - [ view - { choices = List.map (\x -> { label = x, value = x }) items - , current = selected - , defaultDisplayText = defaultDisplayText - } - ] - ) - - -viewSuiteV7 : - ({ choices : List { label : String, value : String }, current : Maybe String, defaultDisplayText : Maybe String } -> Html.Html msg) - -> List Test -viewSuiteV7 view = - [ describe "without a default option" - [ test "shows all options" <| - \() -> - viewTestV7 - view - Nothing - Nothing - [ "Tacos", "Burritos", "Enchiladas" ] - |> Query.find [ tag "select" ] - |> Query.findAll [ tag "option" ] - |> Query.count (Expect.equal 3) - , test "selects the first option if nothing is selected and there's no default" <| - \() -> - viewTestV7 - view - Nothing - Nothing - [ "Tacos", "Burritos", "Enchiladas" ] - |> Query.find - [ tag "option" - , attribute <| Attr.selected True - ] - |> Query.has [ text "Tacos" ] - , test "selects the current option" <| - \() -> - viewTestV7 - view - Nothing - (Just "Burritos") - [ "Tacos", "Burritos", "Enchiladas" ] - |> Query.find - [ tag "option" - , attribute <| Attr.selected True - ] - |> Query.has [ text "Burritos" ] - ] - , describe "with a default option" - [ test "shows all options" <| - \() -> - viewTestV7 - view - (Just "Tasty tortilla'd foods") - Nothing - [ "Tacos", "Burritos", "Enchiladas" ] - |> Query.find [ tag "select" ] - |> Query.findAll [ tag "option" ] - |> Query.count (Expect.equal 4) - , test "selects the disabled default option if nothing is currently selected" <| - \() -> - viewTestV7 - view - (Just "Tasty tortilla'd foods") - Nothing - [ "Tacos", "Burritos", "Enchiladas" ] - |> Query.find - [ tag "option" - , attribute <| Attr.selected True - , attribute <| Attr.disabled True - ] - |> Query.has [ text "Tasty tortilla'd foods" ] - , test "selects the current option" <| - \() -> - viewTestV7 - view - (Just "Tasty tortilla'd foods") - (Just "Burritos") - [ "Tacos", "Burritos", "Enchiladas" ] - |> Query.find - [ tag "option" - , attribute <| Attr.selected True - ] - |> Query.has [ text "Burritos" ] - ] - ] - - -viewTestV7 : - ({ choices : List { label : a, value : a }, current : Maybe b, defaultDisplayText : Maybe String } -> Html.Html msg) - -> Maybe String - -> Maybe b - -> List a - -> Query.Single msg -viewTestV7 view defaultDisplayText selected items = - Query.fromHtml - (Html.div [] - [ view - { choices = List.map (\x -> { label = x, value = x }) items - , current = selected - , defaultDisplayText = defaultDisplayText - } - ] - ) diff --git a/tests/elm-verify-examples.json b/tests/elm-verify-examples.json index b3b4f143..1af655ab 100644 --- a/tests/elm-verify-examples.json +++ b/tests/elm-verify-examples.json @@ -41,7 +41,6 @@ "Nri.Ui.PremiumCheckbox.V6", "Nri.Ui.RadioButton.V2", "Nri.Ui.SegmentedControl.V14", - "Nri.Ui.Select.V7", "Nri.Ui.Select.V8", "Nri.Ui.Slide.V1", "Nri.Ui.SlideModal.V2",