noredink-ui/styleguide-app/Examples/Message.elm

251 lines
14 KiB
Elm
Raw Normal View History

module Examples.Message exposing (Msg, State, example)
2018-08-16 01:05:55 +03:00
2022-03-15 21:06:13 +03:00
import Accessibility.Styled exposing (..)
import Category exposing (Category(..))
import CommonControls
2022-03-15 21:06:13 +03:00
import Css
2020-04-28 03:19:51 +03:00
import Debug.Control as Control exposing (Control)
import Debug.Control.Extra as ControlExtra
2022-03-10 02:01:06 +03:00
import Debug.Control.View as ControlView
2020-03-31 23:33:05 +03:00
import Example exposing (Example)
import Nri.Ui.Colors.V1 as Colors
import Nri.Ui.Heading.V2 as Heading
2021-01-19 23:23:48 +03:00
import Nri.Ui.Message.V3 as Message
2021-10-28 02:40:03 +03:00
import ViewHelpers exposing (viewExamples)
2018-08-16 01:05:55 +03:00
2020-04-01 02:00:29 +03:00
type alias State =
2020-04-28 03:19:51 +03:00
{ show : Bool
2022-03-10 02:01:06 +03:00
, control : Control (List ( String, Message.Attribute Msg ))
2020-04-28 03:19:51 +03:00
}
2020-04-01 02:00:29 +03:00
init : State
init =
2020-04-28 03:19:51 +03:00
{ show = True
, control =
ControlExtra.list
|> ControlExtra.optionalListItem "theme" controlTheme
2022-03-10 02:07:57 +03:00
|> ControlExtra.listItem "content"
(CommonControls.content
{ moduleName = "Message"
, plaintext = Message.plaintext
, markdown = Message.markdown
, html = Message.html
2022-03-10 02:59:41 +03:00
, httpError = Just Message.httpError
2022-03-10 02:07:57 +03:00
}
)
|> ControlExtra.optionalListItem "role" controlRole
2022-03-10 02:01:06 +03:00
|> ControlExtra.optionalBoolListItem "dismissable"
( "Message.onDismiss Dismiss", Message.onDismiss Dismiss )
2022-03-10 02:01:06 +03:00
|> CommonControls.iconNotCheckedByDefault "Message" Message.icon
|> ControlExtra.optionalBoolListItem "hideIconForMobile"
( "Message.hideIconForMobile", Message.hideIconForMobile )
2022-03-10 02:01:06 +03:00
|> CommonControls.css
{ moduleName = "Message"
, use = Message.css
}
2022-03-10 02:15:47 +03:00
|> CommonControls.mobileCss
{ moduleName = "Message"
, use = Message.mobileCss
}
|> CommonControls.quizEngineMobileCss
{ moduleName = "Message"
, use = Message.quizEngineMobileCss
}
|> CommonControls.notMobileCss
{ moduleName = "Message"
, use = Message.notMobileCss
}
2020-08-28 22:59:06 +03:00
}
2022-03-10 02:01:06 +03:00
controlTheme : Control ( String, Message.Attribute msg )
2020-08-28 22:59:06 +03:00
controlTheme =
Control.choice
2022-03-10 02:01:06 +03:00
[ ( "tip", Control.value ( "Message.tip", Message.tip ) )
, ( "error", Control.value ( "Message.error", Message.error ) )
, ( "alert", Control.value ( "Message.alert", Message.alert ) )
, ( "success", Control.value ( "Message.success", Message.success ) )
, ( "customTheme", controlCustomTheme )
2020-08-28 22:59:06 +03:00
]
2022-03-10 02:01:06 +03:00
controlCustomTheme : Control ( String, Message.Attribute msg )
controlCustomTheme =
2022-03-10 02:01:06 +03:00
Control.record
(\( aStr, a ) ( bStr, b ) ->
( "Message.customTheme { color = " ++ aStr ++ ", backgroundColor = " ++ bStr ++ " }"
, Message.customTheme { color = a, backgroundColor = b }
)
)
|> Control.field "color"
2022-03-10 02:01:06 +03:00
(CommonControls.choice "Colors"
[ ( "aquaDark", Colors.aquaDark )
]
)
|> Control.field "backgroundColor"
2022-03-10 02:01:06 +03:00
(CommonControls.choice "Colors"
[ ( "gray92", Colors.gray92 )
]
)
2022-03-10 02:01:06 +03:00
controlRole : Control ( String, Message.Attribute msg )
2020-08-28 22:59:06 +03:00
controlRole =
2022-03-10 02:01:06 +03:00
CommonControls.choice "Message"
[ ( "alertRole", Message.alertRole )
, ( "alertDialogRole", Message.alertDialogRole )
]
type Msg
2020-08-28 23:21:49 +03:00
= Dismiss
2022-03-10 02:01:06 +03:00
| UpdateControl (Control (List ( String, Message.Attribute Msg )))
update : Msg -> State -> ( State, Cmd Msg )
update msg state =
case msg of
Dismiss ->
( { state | show = False }, Cmd.none )
2020-04-01 02:00:29 +03:00
2020-04-28 03:19:51 +03:00
UpdateControl newControl ->
( { state | control = newControl }, Cmd.none )
2020-04-01 02:00:29 +03:00
example : Example State Msg
2018-08-16 01:05:55 +03:00
example =
2020-09-09 21:43:10 +03:00
{ name = "Message"
2021-01-25 23:04:39 +03:00
, version = 3
2020-03-31 23:33:05 +03:00
, categories = [ Messaging ]
, keyboardSupport = []
, state = init
, update = update
2020-03-31 23:33:05 +03:00
, subscriptions = \_ -> Sub.none
2021-11-05 21:48:09 +03:00
, preview =
[ Message.view [ Message.plaintext "Tiny tip" ]
, Message.view [ Message.success, Message.plaintext "Tiny success" ]
, Message.view [ Message.error, Message.plaintext "Tiny error" ]
]
2020-03-31 23:33:05 +03:00
, view =
\state ->
2020-04-28 03:19:51 +03:00
let
attributes =
2022-03-10 02:01:06 +03:00
List.map Tuple.second (Control.currentValue state.control)
orDismiss view =
if state.show then
view
else
2020-08-29 02:01:56 +03:00
text "Nice! The messages were dismissed. 👍"
2020-04-28 03:19:51 +03:00
in
2022-03-10 02:01:06 +03:00
[ ControlView.view
{ update = UpdateControl
, settings = state.control
, toExampleCode =
\settings ->
let
toCode maybeSize =
"Message.view\n\t[ "
++ (maybeSize
:: List.map (Tuple.first >> Just) settings
|> List.filterMap identity
|> String.join "\n\t, "
)
++ "\n\t]"
in
[ { sectionName = "Tiny"
, code = toCode Nothing
}
, { sectionName = "Large"
, code = toCode (Just "Message.large")
}
, { sectionName = "Banner"
, code = toCode (Just "Message.banner")
}
]
}
2020-08-29 02:01:56 +03:00
, orDismiss <|
2021-10-28 02:40:03 +03:00
viewExamples
2022-03-10 02:01:06 +03:00
[ ( "tiny", Message.view attributes )
2021-10-28 02:40:03 +03:00
, ( "large", Message.view (Message.large :: attributes) )
, ( "banner", Message.view (Message.banner :: attributes) )
2020-08-29 02:01:56 +03:00
]
, Heading.h3
[ Heading.css
[ Css.marginTop (Css.px 20)
, Css.borderTop3 (Css.px 2) Css.solid Colors.gray96
, Css.paddingTop (Css.px 20)
]
]
[ text "Message.somethingWentWrong" ]
2020-04-28 03:19:51 +03:00
, Message.somethingWentWrong exampleRailsError
2020-03-31 23:33:05 +03:00
]
2018-08-16 01:05:55 +03:00
}
exampleRailsError : String
exampleRailsError =
"""web : Completed 500 Internal Server Error in 273.5ms
web :
web : ActionView::MissingTemplate - Missing template teach/assignables/blueprint, teach/base/blueprint, application/blueprint with {:locale=>[:en], :formats=>[:json, :js, :html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :xlsx], :handlers=>[:erb, :builder, :axlsx, :coffee, :haml, :rabl, :hamlc]}. Searched in:
web : * "/Users/avh4/workspace/NoRedInk/app/views"
web : * "/Users/avh4/.gem/ruby/2.3.3/gems/sextant-0.2.4/app/views"
web : * "/Users/avh4/.gem/ruby/2.3.3/gems/configurable_engine-0.4.8/app/views"
web : * "/Users/avh4/.gem/ruby/2.3.3/gems/kaminari-0.17.0/app/views"
web : * "/Users/avh4/workspace/NoRedInk/app/assets/javascripts/templates"
web : :
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_view/path_set.rb:58:in `find'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_view/lookup_context.rb:122:in `find'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_view/renderer/abstract_renderer.rb:3:in `find_template'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_view/renderer/template_renderer.rb:35:in `determine_template'
web : newrelic_rpm (4.0.0.332) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:149:in `render_with_newrelic'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_view/renderer/renderer.rb:43:in `render_template'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_view/renderer/renderer.rb:24:in `render'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/abstract_controller/rendering.rb:111:in `_render_template'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/streaming.rb:225:in `_render_template'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/abstract_controller/rendering.rb:104:in `render_to_body'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/renderers.rb:28:in `render_to_body'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/abstract_controller/rendering.rb:89:in `render'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/rendering.rb:16:in `render'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/activesupport/lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
web : /Users/avh4/.rubies/ruby-2.3.3/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/activesupport/lib/active_support/core_ext/benchmark.rb:5:in `ms'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/instrumentation.rb:40:in `block in render'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/activerecord/lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/instrumentation.rb:39:in `render'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/abstract_controller/base.rb:167:in `process_action'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/rendering.rb:10:in `process_action'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/activesupport/lib/active_support/callbacks.rb:502:in `_run__46453218882797464__process_action__3621715315305983900__callbacks'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/activesupport/lib/active_support/callbacks.rb:405:in `__run_callback'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/activesupport/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/activesupport/lib/active_support/callbacks.rb:81:in `run_callbacks'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/abstract_controller/callbacks.rb:17:in `process_action'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/rescue.rb:29:in `process_action'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/activesupport/lib/active_support/notifications.rb:123:in `block in instrument'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/activesupport/lib/active_support/notifications.rb:123:in `instrument'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/activerecord/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
web : newrelic_rpm (4.0.0.332) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:30:in `block in process_action'
web : newrelic_rpm (4.0.0.332) lib/new_relic/agent/instrumentation/controller_instrumentation.rb:362:in `perform_action_with_newrelic_trace'
web : newrelic_rpm (4.0.0.332) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:25:in `process_action'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/abstract_controller/base.rb:121:in `process'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/abstract_controller/rendering.rb:46:in `process'
web : rack-mini-profiler (0.10.2) lib/mini_profiler/profiling_methods.rb:102:in `block in profile_method'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal.rb:203:in `dispatch'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_controller/metal.rb:246:in `block in action'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
web : () Users/avh4/.gem/ruby/2.3.3/bundler/gems/rails-e17e25cd23e8/actionpack/lib/action_dispatch/routing/route_set.rb:36:in `call'"""