mirror of
https://github.com/NoRedInk/noredink-ui.git
synced 2024-12-29 00:21:42 +03:00
Merge remote-tracking branch 'origin' into ink/ally/text-area-update
This commit is contained in:
commit
961f2a0c74
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,6 +6,9 @@ elm-stuff
|
||||
# elm-repl generated files
|
||||
repl-temp-*
|
||||
|
||||
### Styleguide App
|
||||
styleguide-app/bundle.js
|
||||
|
||||
### Emacs ###
|
||||
# -*- mode: gitignore; -*-
|
||||
*~
|
||||
|
8
Makefile
8
Makefile
@ -20,7 +20,7 @@ format: node_modules
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf node_modules styleguide-app/elm.js styleguide-app/javascript.js $(shell find . -type d -name 'elm-stuff')
|
||||
rm -rf node_modules styleguide-app/elm.js styleguide-app/bundle.js $(shell find . -type d -name 'elm-stuff')
|
||||
|
||||
.PHONY: styleguide-app
|
||||
styleguide-app: styleguide-app/elm.js
|
||||
@ -30,10 +30,10 @@ styleguide-app: styleguide-app/elm.js
|
||||
documentation.json: node_modules
|
||||
elm make --docs $@
|
||||
|
||||
styleguide-app/javascript.js: lib/index.js
|
||||
npx browserify --entry lib/index.js --outfile styleguide-app/javascript.js
|
||||
styleguide-app/bundle.js: lib/index.js node_modules
|
||||
npx browserify --entry styleguide-app/manifest.js --outfile styleguide-app/bundle.js
|
||||
|
||||
styleguide-app/elm.js: styleguide-app/javascript.js $(shell find src styleguide-app -type f -name '*.elm')
|
||||
styleguide-app/elm.js: styleguide-app/bundle.js $(shell find src styleguide-app -type f -name '*.elm')
|
||||
cd styleguide-app; elm make Main.elm --output=$(@F)
|
||||
|
||||
# plumbing
|
||||
|
@ -16,6 +16,7 @@
|
||||
"Nri.Ui.Button.V5",
|
||||
"Nri.Ui.Button.V6",
|
||||
"Nri.Ui.Checkbox.V3",
|
||||
"Nri.Ui.Checkbox.V4",
|
||||
"Nri.Ui.Colors.Extra",
|
||||
"Nri.Ui.Colors.V1",
|
||||
"Nri.Ui.DisclosureIndicator.V1",
|
||||
@ -35,6 +36,7 @@
|
||||
"Nri.Ui.Palette.V1",
|
||||
"Nri.Ui.PremiumCheckbox.V1",
|
||||
"Nri.Ui.PremiumCheckbox.V2",
|
||||
"Nri.Ui.PremiumCheckbox.V3",
|
||||
"Nri.Ui.SegmentedControl.V6",
|
||||
"Nri.Ui.Select.V5",
|
||||
"Nri.Ui.Table.V3",
|
||||
|
2
elm.json
2
elm.json
@ -13,6 +13,7 @@
|
||||
"Nri.Ui.Button.V5",
|
||||
"Nri.Ui.Button.V6",
|
||||
"Nri.Ui.Checkbox.V3",
|
||||
"Nri.Ui.Checkbox.V4",
|
||||
"Nri.Ui.Colors.Extra",
|
||||
"Nri.Ui.Colors.V1",
|
||||
"Nri.Ui.DisclosureIndicator.V1",
|
||||
@ -32,6 +33,7 @@
|
||||
"Nri.Ui.Palette.V1",
|
||||
"Nri.Ui.PremiumCheckbox.V1",
|
||||
"Nri.Ui.PremiumCheckbox.V2",
|
||||
"Nri.Ui.PremiumCheckbox.V3",
|
||||
"Nri.Ui.SegmentedControl.V6",
|
||||
"Nri.Ui.Select.V5",
|
||||
"Nri.Ui.Table.V3",
|
||||
|
332
src/Nri/Ui/Checkbox/V4.elm
Normal file
332
src/Nri/Ui/Checkbox/V4.elm
Normal file
@ -0,0 +1,332 @@
|
||||
module Nri.Ui.Checkbox.V4 exposing
|
||||
( Model, Theme(..), IsSelected(..)
|
||||
, view, viewWithLabel, Assets
|
||||
, selectedFromBool
|
||||
)
|
||||
|
||||
{-|
|
||||
|
||||
@docs Model, Theme, IsSelected
|
||||
|
||||
@docs view, viewWithLabel, Assets
|
||||
|
||||
@docs selectedFromBool
|
||||
|
||||
-}
|
||||
|
||||
import Accessibility.Styled as Html
|
||||
import Accessibility.Styled.Aria as Aria
|
||||
import Accessibility.Styled.Style
|
||||
import Accessibility.Styled.Widget as Widget
|
||||
import Css exposing (..)
|
||||
import Css.Global exposing (Snippet, children, descendants, everything, selector)
|
||||
import Html.Events
|
||||
import Html.Styled
|
||||
import Html.Styled.Attributes as Attributes exposing (css)
|
||||
import Html.Styled.Events as Events
|
||||
import Json.Decode
|
||||
import Nri.Ui.AssetPath exposing (Asset(..))
|
||||
import Nri.Ui.AssetPath.Css
|
||||
import Nri.Ui.Colors.V1 as Colors
|
||||
import Nri.Ui.Fonts.V1 as Fonts
|
||||
import Nri.Ui.Html.Attributes.V2 as ExtraAttributes
|
||||
import Nri.Ui.Html.V3 as HtmlExtra exposing (defaultOptions)
|
||||
|
||||
|
||||
{-| -}
|
||||
type alias Model msg =
|
||||
{ identifier : String
|
||||
, label : String
|
||||
, setterMsg : Bool -> msg
|
||||
, selected : IsSelected
|
||||
, disabled : Bool
|
||||
, theme : Theme
|
||||
, noOpMsg : msg
|
||||
}
|
||||
|
||||
|
||||
{-|
|
||||
|
||||
= Selected -- Checked (rendered with a checkmark)
|
||||
| NotSelected -- Not Checked (rendered blank)
|
||||
| PartiallySelected -- Indeterminate (rendered dash)
|
||||
|
||||
-}
|
||||
type IsSelected
|
||||
= Selected
|
||||
| NotSelected
|
||||
| PartiallySelected
|
||||
|
||||
|
||||
{-| -}
|
||||
type Theme
|
||||
= Square
|
||||
| Locked
|
||||
|
||||
|
||||
{-| If your selectedness is always selected or not selected,
|
||||
you will likely store that state as a `Bool` in your model.
|
||||
`selectedFromBool` lets you easily convert that into an `IsSelected` value
|
||||
for use with `Nri.Ui.Checkbox`.
|
||||
-}
|
||||
selectedFromBool : Bool -> IsSelected
|
||||
selectedFromBool isSelected =
|
||||
case isSelected of
|
||||
True ->
|
||||
Selected
|
||||
|
||||
False ->
|
||||
NotSelected
|
||||
|
||||
|
||||
selectedToMaybe : IsSelected -> Maybe Bool
|
||||
selectedToMaybe selected =
|
||||
case selected of
|
||||
Selected ->
|
||||
Just True
|
||||
|
||||
NotSelected ->
|
||||
Just False
|
||||
|
||||
PartiallySelected ->
|
||||
Nothing
|
||||
|
||||
|
||||
{-| Shows a checkbox (the label is only used for accessibility hints)
|
||||
-}
|
||||
view : Assets a -> Model msg -> Html.Html msg
|
||||
view assets model =
|
||||
buildCheckbox assets model <|
|
||||
Html.span Accessibility.Styled.Style.invisible
|
||||
[ Html.text model.label ]
|
||||
|
||||
|
||||
{-| Shows a checkbox and its label text
|
||||
-}
|
||||
viewWithLabel : Assets a -> Model msg -> Html.Html msg
|
||||
viewWithLabel assets model =
|
||||
buildCheckbox assets model <|
|
||||
Html.span [] [ Html.text model.label ]
|
||||
|
||||
|
||||
buildCheckbox : Assets a -> Model msg -> Html.Html msg -> Html.Html msg
|
||||
buildCheckbox assets model labelContent =
|
||||
viewCheckbox model <|
|
||||
case model.theme of
|
||||
Square ->
|
||||
{ containerClasses = toClassList [ "SquareClass" ]
|
||||
, labelStyles =
|
||||
squareLabelStyles model <|
|
||||
case model.selected of
|
||||
Selected ->
|
||||
assets.checkboxChecked_svg
|
||||
|
||||
NotSelected ->
|
||||
assets.checkboxUnchecked_svg
|
||||
|
||||
PartiallySelected ->
|
||||
assets.checkboxCheckedPartially_svg
|
||||
, labelClasses = labelClass model.selected
|
||||
, labelContent = labelContent
|
||||
}
|
||||
|
||||
Locked ->
|
||||
{ containerClasses = toClassList [ "Locked" ]
|
||||
, labelStyles = lockLabelStyles model assets.checkboxLockOnInside_svg
|
||||
, labelClasses = labelClass model.selected
|
||||
, labelContent = labelContent
|
||||
}
|
||||
|
||||
|
||||
squareLabelStyles : { b | disabled : Bool } -> Asset -> Html.Styled.Attribute msg
|
||||
squareLabelStyles model image =
|
||||
let
|
||||
baseStyles =
|
||||
[ positioning
|
||||
, textStyle
|
||||
, outline none
|
||||
, addIcon image
|
||||
]
|
||||
in
|
||||
css
|
||||
(baseStyles
|
||||
++ (if model.disabled then
|
||||
[ cursor auto, checkboxImageSelector [ opacity (num 0.4) ] ]
|
||||
|
||||
else
|
||||
[ cursor pointer ]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
lockLabelStyles : { b | disabled : Bool } -> Asset -> Html.Styled.Attribute msg
|
||||
lockLabelStyles model image =
|
||||
let
|
||||
baseStyles =
|
||||
[ positioning
|
||||
, textStyle
|
||||
, outline none
|
||||
, addIcon image
|
||||
]
|
||||
in
|
||||
css
|
||||
(baseStyles
|
||||
++ (if model.disabled then
|
||||
[ cursor auto
|
||||
, checkboxImageSelector [ opacity (num 0.4) ]
|
||||
]
|
||||
|
||||
else
|
||||
[ cursor pointer ]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
positioning : Style
|
||||
positioning =
|
||||
batch
|
||||
[ display inlineBlock
|
||||
, padding4 (px 13) zero (px 13) (px 35)
|
||||
]
|
||||
|
||||
|
||||
textStyle : Style
|
||||
textStyle =
|
||||
batch
|
||||
[ Fonts.baseFont
|
||||
, fontSize (px 16)
|
||||
, fontWeight (int 600)
|
||||
, color Colors.navy
|
||||
]
|
||||
|
||||
|
||||
addIcon : Asset -> Style
|
||||
addIcon icon =
|
||||
batch
|
||||
[ position relative
|
||||
, checkboxImageSelector
|
||||
[ backgroundImage icon
|
||||
, backgroundRepeat noRepeat
|
||||
, backgroundSize (px 24)
|
||||
, property "content" "''"
|
||||
, position absolute
|
||||
, left zero
|
||||
, top (px 10)
|
||||
, width (px 24)
|
||||
, height (px 24)
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
checkboxImageSelector : List Style -> Style
|
||||
checkboxImageSelector =
|
||||
before
|
||||
|
||||
|
||||
labelClass : IsSelected -> Html.Styled.Attribute msg
|
||||
labelClass isSelected =
|
||||
case isSelected of
|
||||
Selected ->
|
||||
toClassList [ "Label", "Checked" ]
|
||||
|
||||
NotSelected ->
|
||||
toClassList [ "Label", "Unchecked" ]
|
||||
|
||||
PartiallySelected ->
|
||||
toClassList [ "Label", "Indeterminate" ]
|
||||
|
||||
|
||||
toClassList : List String -> Html.Styled.Attribute msg
|
||||
toClassList =
|
||||
List.map (\a -> ( "checkbox-V3__" ++ a, True )) >> Attributes.classList
|
||||
|
||||
|
||||
viewCheckbox :
|
||||
Model msg
|
||||
->
|
||||
{ containerClasses : Html.Attribute msg
|
||||
, labelStyles : Html.Attribute msg
|
||||
, labelClasses : Html.Attribute msg
|
||||
, labelContent : Html.Html msg
|
||||
}
|
||||
-> Html.Html msg
|
||||
viewCheckbox model config =
|
||||
let
|
||||
toggledValue =
|
||||
selectedToMaybe model.selected
|
||||
|> Maybe.withDefault False
|
||||
|> not
|
||||
in
|
||||
Html.Styled.span
|
||||
[ css
|
||||
[ display block
|
||||
, height inherit
|
||||
, descendants [ Css.Global.input [ display none ] ]
|
||||
]
|
||||
, config.containerClasses
|
||||
, Attributes.id <| model.identifier ++ "-container"
|
||||
, -- This is necessary to prevent event propagation.
|
||||
-- See https://github.com/elm-lang/html/issues/96
|
||||
Attributes.map (always model.noOpMsg) <|
|
||||
Events.stopPropagationOn "click"
|
||||
(Json.Decode.succeed ( "stop click propagation", True ))
|
||||
]
|
||||
[ Html.checkbox model.identifier
|
||||
(selectedToMaybe model.selected)
|
||||
[ Widget.label model.label
|
||||
, Events.onCheck (\_ -> model.setterMsg toggledValue)
|
||||
, Attributes.id model.identifier
|
||||
, Attributes.disabled model.disabled
|
||||
]
|
||||
, viewLabel model config.labelContent config.labelClasses config.labelStyles
|
||||
]
|
||||
|
||||
|
||||
viewLabel : Model msg -> Html.Html msg -> Html.Attribute msg -> Html.Attribute msg -> Html.Html msg
|
||||
viewLabel model content class theme =
|
||||
Html.Styled.label
|
||||
[ Attributes.for model.identifier
|
||||
, Aria.controls model.identifier
|
||||
, Widget.disabled model.disabled
|
||||
, Widget.checked (selectedToMaybe model.selected)
|
||||
, if not model.disabled then
|
||||
Attributes.tabindex 0
|
||||
|
||||
else
|
||||
ExtraAttributes.none
|
||||
, if not model.disabled then
|
||||
--TODO: the accessibility keyboard module might make this a tad more readable.
|
||||
HtmlExtra.onKeyUp
|
||||
{ defaultOptions | preventDefault = True }
|
||||
(\keyCode ->
|
||||
-- 32 is the space bar, 13 is enter
|
||||
if (keyCode == 32 || keyCode == 13) && not model.disabled then
|
||||
Just <| model.setterMsg (Maybe.map not (selectedToMaybe model.selected) |> Maybe.withDefault True)
|
||||
|
||||
else
|
||||
Nothing
|
||||
)
|
||||
|
||||
else
|
||||
ExtraAttributes.none
|
||||
, class
|
||||
, theme
|
||||
]
|
||||
[ content ]
|
||||
|
||||
|
||||
{-| The assets used in this module.
|
||||
-}
|
||||
type alias Assets r =
|
||||
{ r
|
||||
| checkboxUnchecked_svg : Asset
|
||||
, checkboxChecked_svg : Asset
|
||||
, checkboxCheckedPartially_svg : Asset
|
||||
, checkboxLockOnInside_svg : Asset
|
||||
}
|
||||
|
||||
|
||||
backgroundImage : Asset -> Style
|
||||
backgroundImage =
|
||||
Nri.Ui.AssetPath.Css.url
|
||||
>> property "background-image"
|
119
src/Nri/Ui/PremiumCheckbox/V3.elm
Normal file
119
src/Nri/Ui/PremiumCheckbox/V3.elm
Normal file
@ -0,0 +1,119 @@
|
||||
module Nri.Ui.PremiumCheckbox.V3 exposing (PremiumConfig, premium, Pennant(..))
|
||||
|
||||
{-|
|
||||
|
||||
@docs PremiumConfig, premium, Pennant
|
||||
|
||||
-}
|
||||
|
||||
import Accessibility.Styled as Html
|
||||
import Css exposing (..)
|
||||
import Html.Styled.Attributes as Attributes exposing (css)
|
||||
import Nri.Ui.AssetPath exposing (Asset(..))
|
||||
import Nri.Ui.AssetPath.Css
|
||||
import Nri.Ui.Checkbox.V4 as Checkbox
|
||||
|
||||
|
||||
{-|
|
||||
|
||||
- `onChange`: A message for when the user toggles the checkbox
|
||||
- `onLockedClick`: A message for when the user clicks a checkbox they don't have PremiumLevel for.
|
||||
If you get this message, you should show an `Nri.Ui.Premium.Model.view`
|
||||
|
||||
-}
|
||||
type alias PremiumConfig msg =
|
||||
{ label : String
|
||||
, id : String
|
||||
, selected : Checkbox.IsSelected
|
||||
, disabled : Bool
|
||||
, isLocked : Bool
|
||||
, pennant : Maybe Pennant
|
||||
, onChange : Bool -> msg
|
||||
, onLockedClick : msg
|
||||
, noOpMsg : msg
|
||||
}
|
||||
|
||||
|
||||
{-| Premium is the yellow "P" pennant
|
||||
PremiumWithWriting is the yellow "P+" pennant
|
||||
-}
|
||||
type Pennant
|
||||
= Premium
|
||||
| PremiumWithWriting
|
||||
|
||||
|
||||
{-| A checkbox that should be used for premium content
|
||||
-}
|
||||
premium : Assets a -> PremiumConfig msg -> Html.Html msg
|
||||
premium assets config =
|
||||
Html.div
|
||||
[ css
|
||||
[ displayFlex
|
||||
, alignItems center
|
||||
]
|
||||
]
|
||||
[ Checkbox.viewWithLabel assets
|
||||
{ identifier = config.id
|
||||
, label = config.label
|
||||
, setterMsg =
|
||||
if config.isLocked then
|
||||
\_ -> config.onLockedClick
|
||||
|
||||
else
|
||||
config.onChange
|
||||
, selected = config.selected
|
||||
, disabled = config.disabled
|
||||
, theme =
|
||||
if config.isLocked then
|
||||
Checkbox.Locked
|
||||
|
||||
else
|
||||
Checkbox.Square
|
||||
, noOpMsg = config.noOpMsg
|
||||
}
|
||||
, case config.pennant of
|
||||
Just pennant ->
|
||||
Html.div
|
||||
[ Attributes.class "premium-checkbox-V1__PremiumClass"
|
||||
, css
|
||||
[ property "content" "''"
|
||||
, display inlineBlock
|
||||
, width (px 26)
|
||||
, height (px 24)
|
||||
, marginLeft (px 8)
|
||||
, backgroundImage
|
||||
(case pennant of
|
||||
Premium ->
|
||||
assets.iconPremiumFlag_svg
|
||||
|
||||
PremiumWithWriting ->
|
||||
assets.iconPremiumWithWritingFlag_svg
|
||||
)
|
||||
, backgroundRepeat noRepeat
|
||||
, backgroundPosition center
|
||||
]
|
||||
]
|
||||
[]
|
||||
|
||||
Nothing ->
|
||||
Html.text ""
|
||||
]
|
||||
|
||||
|
||||
{-| The assets used in this module.
|
||||
-}
|
||||
type alias Assets r =
|
||||
{ r
|
||||
| checkboxUnchecked_svg : Asset
|
||||
, checkboxChecked_svg : Asset
|
||||
, checkboxCheckedPartially_svg : Asset
|
||||
, checkboxLockOnInside_svg : Asset
|
||||
, iconPremiumFlag_svg : Asset
|
||||
, iconPremiumWithWritingFlag_svg : Asset
|
||||
}
|
||||
|
||||
|
||||
backgroundImage : Asset -> Style
|
||||
backgroundImage =
|
||||
Nri.Ui.AssetPath.Css.url
|
||||
>> property "background-image"
|
@ -9,9 +9,9 @@ module Examples.Checkbox exposing (Msg, State, example, init, update)
|
||||
import Assets exposing (assets)
|
||||
import Html.Styled as Html exposing (..)
|
||||
import ModuleExample as ModuleExample exposing (Category(..), ModuleExample)
|
||||
import Nri.Ui.Checkbox.V3 as Checkbox
|
||||
import Nri.Ui.Checkbox.V4 as Checkbox
|
||||
import Nri.Ui.Data.PremiumLevel as PremiumLevel exposing (PremiumLevel(..))
|
||||
import Nri.Ui.PremiumCheckbox.V2 as PremiumCheckbox
|
||||
import Nri.Ui.PremiumCheckbox.V3 as PremiumCheckbox
|
||||
import Set exposing (Set)
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@ module Examples.TextArea exposing (Msg, State, example, init, update)
|
||||
|
||||
-}
|
||||
|
||||
import Assets exposing (assets)
|
||||
import Dict exposing (Dict)
|
||||
import Html.Styled as Html
|
||||
import ModuleExample as ModuleExample exposing (Category(..), ModuleExample)
|
||||
@ -171,16 +172,3 @@ update msg state =
|
||||
|
||||
type alias Id =
|
||||
Int
|
||||
|
||||
|
||||
assets : { iconPremiumFlag_svg : Asset, iconPremiumKey_png : Asset, iconPremiumLocked_png : Asset, iconPremiumUnlocked_png : Asset, checkboxCheckedPartially_svg : Asset, checkboxChecked_svg : Asset, checkboxLockOnInside_svg : Asset, checkboxUnchecked_svg : Asset }
|
||||
assets =
|
||||
{ checkboxUnchecked_svg = Asset "checkboxUnchecked_svg"
|
||||
, checkboxChecked_svg = Asset "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAb1BMVEX///9DoEc2nDt1tXcoly601bU5nD1nr2o/n0Pw9vAzmzhAn0QxmjYumTMqmDAsmTK92r6UxJacyJ1YqFu52LvC3MOQwpIZlCGLwI3M4s2u0q+q0KueyaCkzKX1+fXq8+rh7uHW6NeDvIVztHVssW4Cx6cUAAACZUlEQVR4nO3Zi1LTYBRF4dOSQkqt4AURL6Di+z+jQWVsadJcen5z9pm1HiDZ3yQzSSZmRERERERERERERERERERERERERERERERElKj7uQeUbrVdzz2hbKuqrlMTV9VikZr4BExN/ANMTHwGpiX+AyYl7gJTEveBCYkvgemIh8BkxDZgKmI7sCEuH+ae5lMXcLF8nHuaT93As7mn+QRQPYDqAVQPoHoA1QOoHkD1AKoHUD2A6gFUD6B6ANUDqB5A9QCqB1A9gOoBVA+gegDVA6geQPUAqgfw/3Rd7MhRgLcXhY4cBHhTLc7LEIMA755mFCFGAhYhBgF+f57hTowGdCcGAX672jm1KzEI8GG7WZQhRgFebvZP70YMAlwvNy8HOBGjAOsDoBMxCPB+U7eNcCAGAa7bgQ7EIECzi/OOIScSwwBLEQMByxBDAUsQgwHNfjoTwwG9iQGBDXHpRwwJ9CQGBZo9OhHDAr2IgYFmZw7E0EAPYnDg6cTwwFOJAsDTiBJAsx+TiSLAhng5jSgDnEoUAk4jSgGnEMWA44lywLFEQaDZxxFESeAYoiiwIb4aRpQFDiUKA80+DCBKA4cQxYFmb3qI8sCGuD1GTAA8TkwBPEKs33U9MbWAZm+7iC3/xiWBR4hZgCOJikCzL1f9MmngCKIq0Ozr6+TAhjjkKioDBxG1gWaf+25UdWAvUR/YQ8wANPvU9aqdBXiEmAXYScwD7PjozQRsJeYCthCzAQ+I+YBm76vkwD1iTuAOMSvQ7LpKDvxLzAz8TcwNNLu5TQ40u5t7ABERERERERERERERERFN7hdTvSHAHrHcMgAAAABJRU5ErkJggg=="
|
||||
, checkboxCheckedPartially_svg = Asset "checkboxCheckedPartially_svg"
|
||||
, iconPremiumUnlocked_png = Asset "iconPremiumUnlocked_png"
|
||||
, iconPremiumLocked_png = Asset "iconPremiumLocked_png"
|
||||
, checkboxLockOnInside_svg = Asset "checkboxLockOnInside_svg"
|
||||
, iconPremiumKey_png = Asset "iconPremiumKey_png"
|
||||
, iconPremiumFlag_svg = Asset "iconPremiumFlag_svg"
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -5,14 +5,13 @@
|
||||
<title>NoRedInk style guide</title>
|
||||
<link href="assets/reset.css" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css?family=Muli:400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
|
||||
<script src="assets/custom-elements/custom-elements.min.js"></script>
|
||||
<script src="assets/generated_svgs.js"></script>
|
||||
<script src="javascript.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="svg-target"></div>
|
||||
<script src="elm.js"></script>
|
||||
<script>
|
||||
const app = Elm.Main.init();
|
||||
</script>
|
||||
<script src="bundle.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
2
styleguide-app/manifest.js
Normal file
2
styleguide-app/manifest.js
Normal file
@ -0,0 +1,2 @@
|
||||
require('../lib/index.js')
|
||||
require('./assets/generated_svgs.js')
|
21
tests/Spec/Nri/Ui/Checkbox/V4.elm
Normal file
21
tests/Spec/Nri/Ui/Checkbox/V4.elm
Normal file
@ -0,0 +1,21 @@
|
||||
module Spec.Nri.Ui.Checkbox.V4 exposing (all)
|
||||
|
||||
import Expect exposing (Expectation)
|
||||
import Nri.Ui.Checkbox.V4 as Checkbox
|
||||
import Test exposing (..)
|
||||
|
||||
|
||||
all : Test
|
||||
all =
|
||||
describe "Nri.Ui.Checkbox.V3"
|
||||
[ describe "selectedFromBool"
|
||||
[ test "it handles Selected" <|
|
||||
\() ->
|
||||
Checkbox.selectedFromBool True
|
||||
|> Expect.equal Checkbox.Selected
|
||||
, test "it handles NotSelected" <|
|
||||
\() ->
|
||||
Checkbox.selectedFromBool False
|
||||
|> Expect.equal Checkbox.NotSelected
|
||||
]
|
||||
]
|
141
tests/Spec/Nri/Ui/PremiumCheckbox/V3.elm
Normal file
141
tests/Spec/Nri/Ui/PremiumCheckbox/V3.elm
Normal file
@ -0,0 +1,141 @@
|
||||
module Spec.Nri.Ui.PremiumCheckbox.V3 exposing (spec)
|
||||
|
||||
import Html.Attributes
|
||||
import Html.Styled
|
||||
import Nri.Ui.AssetPath exposing (Asset(..))
|
||||
import Nri.Ui.Checkbox.V4 exposing (IsSelected(..))
|
||||
import Nri.Ui.Data.PremiumLevel as PremiumLevel exposing (PremiumLevel(..))
|
||||
import Nri.Ui.PremiumCheckbox.V3 as PremiumCheckbox
|
||||
import Test exposing (..)
|
||||
import Test.Html.Query as Query
|
||||
import Test.Html.Selector as Selector
|
||||
|
||||
|
||||
premiumView config =
|
||||
PremiumCheckbox.premium assets
|
||||
{ label = "i am label"
|
||||
, id = "id"
|
||||
, selected = config.selected
|
||||
, disabled = config.disabled
|
||||
, isLocked = config.isLocked
|
||||
, pennant = config.pennant
|
||||
, onChange = \_ -> ()
|
||||
, onLockedClick = ()
|
||||
, noOpMsg = ()
|
||||
}
|
||||
|> Html.Styled.toUnstyled
|
||||
|> Query.fromHtml
|
||||
|
||||
|
||||
spec : Test
|
||||
spec =
|
||||
describe "Nri.Ui.PremiumCheckbox.V2"
|
||||
[ describe "premium"
|
||||
[ test "displays the label" <|
|
||||
\() ->
|
||||
premiumView
|
||||
{ selected = Selected
|
||||
, disabled = False
|
||||
, isLocked = False
|
||||
, pennant = Nothing
|
||||
}
|
||||
|> Query.has [ Selector.text "i am label" ]
|
||||
, test "appears selected when Selected is passed in" <|
|
||||
\() ->
|
||||
premiumView
|
||||
{ selected = Selected
|
||||
, disabled = False
|
||||
, isLocked = False
|
||||
, pennant = Nothing
|
||||
}
|
||||
|> Query.has [ Selector.class "checkbox-V3__Checked" ]
|
||||
, test "appears unselected when NotSelected is passed in" <|
|
||||
\() ->
|
||||
premiumView
|
||||
{ selected = NotSelected
|
||||
, disabled = False
|
||||
, isLocked = False
|
||||
, pennant = Nothing
|
||||
}
|
||||
|> Query.has [ Selector.class "checkbox-V3__Unchecked" ]
|
||||
, test "appears partially selected when PartiallySelected is passed in" <|
|
||||
\() ->
|
||||
premiumView
|
||||
{ selected = PartiallySelected
|
||||
, disabled = False
|
||||
, isLocked = False
|
||||
, pennant = Nothing
|
||||
}
|
||||
|> Query.has [ Selector.class "checkbox-V3__Indeterminate" ]
|
||||
, test "appears locked when isLocked = True" <|
|
||||
\() ->
|
||||
premiumView
|
||||
{ selected = Selected
|
||||
, disabled = False
|
||||
, isLocked = True
|
||||
, pennant = Nothing
|
||||
}
|
||||
|> Query.has [ Selector.class "checkbox-V3__Locked" ]
|
||||
, test "appears unlocked when isLocked = False" <|
|
||||
\() ->
|
||||
premiumView
|
||||
{ selected = Selected
|
||||
, disabled = False
|
||||
, isLocked = False
|
||||
, pennant = Nothing
|
||||
}
|
||||
|> Query.hasNot [ Selector.class "checkbox-V3__Locked" ]
|
||||
, test "appears with P flag when Premium pennant is passed in" <|
|
||||
\() ->
|
||||
premiumView
|
||||
{ selected = Selected
|
||||
, disabled = False
|
||||
, isLocked = False
|
||||
, pennant = Just PremiumCheckbox.Premium
|
||||
}
|
||||
|> Query.find [ Selector.tag "style" ]
|
||||
|> Query.has [ Selector.text "iconPremiumFlag reference" ]
|
||||
, test "appears with P+ flag when Premium pennant is passed in" <|
|
||||
\() ->
|
||||
premiumView
|
||||
{ selected = Selected
|
||||
, disabled = False
|
||||
, isLocked = False
|
||||
, pennant = Just PremiumCheckbox.PremiumWithWriting
|
||||
}
|
||||
|> Query.find [ Selector.tag "style" ]
|
||||
|> Query.has [ Selector.text "iconPremiumWritingFlag reference" ]
|
||||
, test "is not disabled when disabled = False" <|
|
||||
\() ->
|
||||
premiumView
|
||||
{ selected = Selected
|
||||
, disabled = False
|
||||
, isLocked = False
|
||||
, pennant = Nothing
|
||||
}
|
||||
|> Query.has [ Selector.disabled False ]
|
||||
, test "is disabled when disabled = True" <|
|
||||
\() ->
|
||||
premiumView
|
||||
{ selected = Selected
|
||||
, disabled = True
|
||||
, isLocked = False
|
||||
, pennant = Nothing
|
||||
}
|
||||
|> Query.has [ Selector.disabled True ]
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
assets =
|
||||
{ checkboxUnchecked_svg = Asset "checkboxUnchecked reference"
|
||||
, checkboxChecked_svg = Asset "checkboxChecked reference"
|
||||
, checkboxCheckedPartially_svg = Asset "checkboxCheckedPartially reference"
|
||||
, iconPremiumUnlocked_png = Asset "iconPremiumUnlocked reference"
|
||||
, iconCheck_png = Asset "iconCheck reference"
|
||||
, iconPremiumLocked_png = Asset "iconPremiumLocked reference"
|
||||
, checkboxLockOnInside_svg = Asset "checkboxLockOnInside reference"
|
||||
, iconPremiumKey_png = Asset "iconPremiumKey reference"
|
||||
, iconPremiumFlag_svg = Asset "iconPremiumFlag reference"
|
||||
, iconPremiumWithWritingFlag_svg = Asset "iconPremiumWritingFlag reference"
|
||||
}
|
Loading…
Reference in New Issue
Block a user