From a9fa26a0238cd60c8f8cb09699c19802f85dca8f Mon Sep 17 00:00:00 2001 From: Tessa Kelly Date: Mon, 22 Nov 2021 11:51:57 -0800 Subject: [PATCH] Only show the premium pennant when the content is not free --- src/Nri/Ui/RadioButton/V3.elm | 44 ++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/Nri/Ui/RadioButton/V3.elm b/src/Nri/Ui/RadioButton/V3.elm index 2759012a..b062216e 100644 --- a/src/Nri/Ui/RadioButton/V3.elm +++ b/src/Nri/Ui/RadioButton/V3.elm @@ -110,9 +110,13 @@ valueToString valueToString_ = Attribute { emptyEventsAndValues | valueToString = Just valueToString_ } identity -{-| Lock the content if the teacher does not have premium access +{-| Lock Premium content if the user does not have Premium. -} -premium : { teacherPremiumLevel : PremiumLevel, contentPremiumLevel : PremiumLevel } -> Attribute value msg +premium : + { teacherPremiumLevel : PremiumLevel + , contentPremiumLevel : PremiumLevel + } + -> Attribute value msg premium { teacherPremiumLevel, contentPremiumLevel } = Attribute emptyEventsAndValues <| \config -> @@ -122,7 +126,10 @@ premium { teacherPremiumLevel, contentPremiumLevel } = } -{-| Show the pennant and attach this onClick handler +{-| Show Premium pennant on Premium content. + +When the pennant is clicked, the msg that's passed in will fire. + -} showPennant : msg -> Attribute value msg showPennant premiumMsg = @@ -441,17 +448,15 @@ view label attributes = [] ] [ Html.text label ] - , case ( config.hideLabel, eventsAndValues.premiumMsg ) of - ( False, Just premiumMsg ) -> - -- TODO: should this flag show when the content premium - -- level is Free?? I somewhat think not! - ClickableSvg.button "Premium" - Pennant.premiumFlag - [ ClickableSvg.onClick premiumMsg - , ClickableSvg.exactWidth 26 - , ClickableSvg.exactHeight 24 - , ClickableSvg.css [ marginLeft (px 8) ] - ] + , case ( config.contentPremiumLevel, eventsAndValues.premiumMsg ) of + ( Nothing, _ ) -> + text "" + + ( Just PremiumLevel.Free, _ ) -> + text "" + + ( Just _, Just premiumMsg ) -> + premiumPennant premiumMsg _ -> text "" @@ -461,6 +466,17 @@ view label attributes = ] +premiumPennant : msg -> Html msg +premiumPennant onClick = + ClickableSvg.button "Premium" + Pennant.premiumFlag + [ ClickableSvg.onClick onClick + , ClickableSvg.exactWidth 26 + , ClickableSvg.exactHeight 24 + , ClickableSvg.css [ marginLeft (px 8) ] + ] + + radioInputIcon : { isChecked : Bool , isLocked : Bool