From 4cb887fb815b67de1021ae34f242b13713184a5e Mon Sep 17 00:00:00 2001 From: Tessa Kelly Date: Fri, 24 Apr 2020 12:55:51 -0700 Subject: [PATCH] :skull: replace attribute extras --- src/AttributeExtras.elm | 20 -------------- src/ClickableAttributes.elm | 2 +- src/Nri/Ui/Html/Attributes/Extra.elm | 39 ---------------------------- src/Nri/Ui/Html/Attributes/V2.elm | 17 +++++++++++- src/Nri/Ui/Icon/V5.elm | 2 +- 5 files changed, 18 insertions(+), 62 deletions(-) delete mode 100644 src/AttributeExtras.elm delete mode 100644 src/Nri/Ui/Html/Attributes/Extra.elm diff --git a/src/AttributeExtras.elm b/src/AttributeExtras.elm deleted file mode 100644 index f671e73b..00000000 --- a/src/AttributeExtras.elm +++ /dev/null @@ -1,20 +0,0 @@ -module AttributeExtras exposing (targetBlank) - -import Html.Styled exposing (Attribute) -import Html.Styled.Attributes as Attributes - - -{-| Use this list of attributes instead of applying `Attributes.target "_blank"` -directly. This prevents an exploits like "tabnabbing", among other things. - -See these resources: - - - - - - --} -targetBlank : List (Attribute msg) -targetBlank = - [ Attributes.target "_blank" - , Attributes.rel "noopener noreferrer" - ] diff --git a/src/ClickableAttributes.elm b/src/ClickableAttributes.elm index ac036f34..d1169334 100644 --- a/src/ClickableAttributes.elm +++ b/src/ClickableAttributes.elm @@ -14,7 +14,7 @@ module ClickableAttributes exposing {-| -} -import AttributeExtras exposing (targetBlank) +import Nri.Ui.Html.Attributes.V2 as AttributeExtras exposing (targetBlank) import EventExtras import Html.Styled exposing (Attribute) import Html.Styled.Attributes as Attributes diff --git a/src/Nri/Ui/Html/Attributes/Extra.elm b/src/Nri/Ui/Html/Attributes/Extra.elm deleted file mode 100644 index 42dc8dd7..00000000 --- a/src/Nri/Ui/Html/Attributes/Extra.elm +++ /dev/null @@ -1,39 +0,0 @@ -module Nri.Ui.Html.Attributes.Extra exposing (none, includeIf) - -{-| Extras for working with Html.Attributes - -@docs none, includeIf - --} - -import Html exposing (Attribute) -import Html.Attributes as Attributes -import Json.Encode as Encode - - -{-| Represents an attribute with no semantic meaning, useful for conditionals. - -This is implemented such that whenever Html.Attributes.Extra.none is encountered -by VirtualDom it will set a meaningless property on the element object itself to -null: - - domNode['Html.Attributes.Extra.none'] = null - -It's totally safe and lets us clean up conditional and maybe attributes - --} -none : Attribute msg -none = - Attributes.property "Html.Attributes.Extra.none" Encode.null - - -{-| conditionally include an attribute. Useful for CSS classes generated with -`UniqueClass`! --} -includeIf : Bool -> Attribute msg -> Attribute msg -includeIf cond attr = - if cond then - attr - - else - none diff --git a/src/Nri/Ui/Html/Attributes/V2.elm b/src/Nri/Ui/Html/Attributes/V2.elm index 3ff230af..11b085e0 100644 --- a/src/Nri/Ui/Html/Attributes/V2.elm +++ b/src/Nri/Ui/Html/Attributes/V2.elm @@ -1,4 +1,4 @@ -module Nri.Ui.Html.Attributes.V2 exposing (none, includeIf) +module Nri.Ui.Html.Attributes.V2 exposing (none, includeIf, targetBlank) {-| Extras for working with Html.Attributes. @@ -39,3 +39,18 @@ includeIf cond attr = else none + +{-| Use this list of attributes instead of applying `Attributes.target "_blank"` +directly. This prevents an exploits like "tabnabbing", among other things. + +See these resources: + + - + - + +-} +targetBlank : List (Attribute msg) +targetBlank = + [ Attributes.target "_blank" + , Attributes.rel "noopener noreferrer" + ] diff --git a/src/Nri/Ui/Icon/V5.elm b/src/Nri/Ui/Icon/V5.elm index 372f21c3..ee015072 100644 --- a/src/Nri/Ui/Icon/V5.elm +++ b/src/Nri/Ui/Icon/V5.elm @@ -139,7 +139,7 @@ module Nri.Ui.Icon.V5 exposing import Accessibility.Role as Role import Accessibility.Styled exposing (..) -import AttributeExtras +import Nri.Ui.Html.Attributes.V2 as AttributeExtras import Css exposing (..) import EventExtras import Html as RootHtml