From ec0c6de5300576c9b94da7844d20bd195d27b0e4 Mon Sep 17 00:00:00 2001 From: Aaron VonderHaar Date: Thu, 16 Apr 2020 17:06:36 -0700 Subject: [PATCH] Update TextInput.V6 upgrade script --- elm-refactor/v8-to-v9/TextInputV6.elm | 281 +++++++++++++++++++++----- 1 file changed, 226 insertions(+), 55 deletions(-) diff --git a/elm-refactor/v8-to-v9/TextInputV6.elm b/elm-refactor/v8-to-v9/TextInputV6.elm index c4045a12..0d5c5f75 100644 --- a/elm-refactor/v8-to-v9/TextInputV6.elm +++ b/elm-refactor/v8-to-v9/TextInputV6.elm @@ -1,9 +1,186 @@ -module Main exposing (upgrade_Nri_Ui_TextInput_V5_view) +module Main exposing (..) + +{-| NOTE: requires elm-refactor alpha-220-g24db2f5 or later. +-} -import ElmFix import Nri.Ui.TextInput.V6 as TextInput + +-- +-- Nri.Ui.TextInput.V3 to V6 +-- + + +upgrade_Nri_Ui_TextInput_V3_view config = + TextInput.view + config.label + (config.type_ config.onInput) + (List.filterMap identity + [ case config.isInError of + False -> + Nothing + + _ -> + Just (TextInput.errorIf config.isInError) + , if config.placeholder == config.label then + Nothing + + else + Just (TextInput.placeholder config.placeholder) + , if config.autofocus then + Just TextInput.autofocus + + else + Nothing + , if config.showLabel then + Nothing + + else + Just TextInput.hiddenLabel + ] + ) + config.value + + +upgrade_Nri_Ui_TextInput_V3_writing config = + TextInput.view + config.label + (config.type_ config.onInput) + (List.filterMap identity + [ Just TextInput.writing + , Just (TextInput.errorIf config.isInError) + , if config.placeholder == config.label then + Nothing + + else + Just (TextInput.placeholder config.placeholder) + , if config.autofocus then + Just TextInput.autofocus + + else + Nothing + , if config.showLabel then + Nothing + + else + Just TextInput.hiddenLabel + ] + ) + config.value + + +upgrade_Nri_Ui_TextInput_V3_number = + TextInput.number + + +upgrade_Nri_Ui_TextInput_V3_text = + TextInput.text + + + +-- +-- Nri.Ui.TextInput.V4 to V6 +-- + + +upgrade_Nri_Ui_TextInput_V4_view config = + TextInput.view + config.label + (config.type_ config.onInput) + (List.filterMap identity + [ case config.isInError of + False -> + Nothing + + _ -> + Just (TextInput.errorIf config.isInError) + , case config.onBlur of + Nothing -> + Nothing + + Just onBlur -> + Just (TextInput.onBlur onBlur) + , if config.placeholder == config.label then + Nothing + + else + Just (TextInput.placeholder config.placeholder) + , case config.autofocus of + False -> + Nothing + + True -> + Just TextInput.autofocus + , case config.showLabel of + True -> + Nothing + + False -> + Just TextInput.hiddenLabel + ] + ) + config.value + + +upgrade_Nri_Ui_TextInput_V4_writing config = + TextInput.view + config.label + (config.type_ config.onInput) + (List.filterMap identity + [ Just TextInput.writing + , case config.isInError of + False -> + Nothing + + _ -> + Just (TextInput.errorIf config.isInError) + , case config.onBlur of + Nothing -> + Nothing + + Just onBlur -> + Just (TextInput.onBlur onBlur) + , if config.placeholder == config.label then + Nothing + + else + Just (TextInput.placeholder config.placeholder) + , case config.autofocus of + False -> + Nothing + + True -> + Just TextInput.autofocus + , case config.showLabel of + True -> + Nothing + + False -> + Just TextInput.hiddenLabel + ] + ) + config.value + + +upgrade_Nri_Ui_TextInput_V4_generateId = + TextInput.generateId + + +upgrade_Nri_Ui_TextInput_V4_number = + TextInput.number + + +upgrade_Nri_Ui_TextInput_V4_text = + TextInput.text + + + +-- +-- Nri.Ui.TextInput.V5 to V6 +-- + + upgrade_Nri_Ui_TextInput_V5_text = TextInput.text @@ -27,73 +204,67 @@ upgrade_Nri_Ui_TextInput_V5_email = upgrade_Nri_Ui_TextInput_V5_view model = TextInput.view model.label (model.type_ model.onInput) - [ case model.isInError of - False -> - ElmFix.remove + (List.filterMap identity + [ case model.isInError of + False -> + Nothing - _ -> - TextInput.errorIf model.isInError - , case model.showLabel of - True -> - ElmFix.remove + _ -> + Just (TextInput.errorIf model.isInError) + , case model.showLabel of + True -> + Nothing - False -> - TextInput.hiddenLabel - , if model.placeholder == model.label then - ElmFix.remove + False -> + Just TextInput.hiddenLabel + , if model.placeholder == model.label then + Nothing - else - TextInput.placeholder model.placeholder - , case model.onBlur of - Nothing -> - ElmFix.remove + else + Just (TextInput.placeholder model.placeholder) + , Maybe.map TextInput.onBlur model.onBlur + , case model.autofocus of + True -> + Just TextInput.autofocus - Just msg -> - TextInput.onBlur msg - , case model.autofocus of - True -> - TextInput.autofocus - - False -> - ElmFix.remove - ] + False -> + Nothing + ] + ) model.value upgrade_Nri_Ui_TextInput_V5_writing model = TextInput.view model.label (model.type_ model.onInput) - [ TextInput.writing - , case model.isInError of - False -> - ElmFix.remove + (List.filterMap identity + [ Just TextInput.writing + , case model.isInError of + False -> + Nothing - _ -> - TextInput.errorIf model.isInError - , case model.showLabel of - True -> - ElmFix.remove + _ -> + Just (TextInput.errorIf model.isInError) + , case model.showLabel of + True -> + Nothing - False -> - TextInput.hiddenLabel - , if model.placeholder == model.label then - ElmFix.remove + False -> + Just TextInput.hiddenLabel + , if model.placeholder == model.label then + Nothing - else - TextInput.placeholder model.placeholder - , case model.onBlur of - Nothing -> - ElmFix.remove + else + Just (TextInput.placeholder model.placeholder) + , Maybe.map TextInput.onBlur model.onBlur + , case model.autofocus of + True -> + Just TextInput.autofocus - Just msg -> - TextInput.onBlur msg - , case model.autofocus of - True -> - TextInput.autofocus - - False -> - ElmFix.remove - ] + False -> + Nothing + ] + ) model.value