Skip to content

Commit a1ced30

Browse files
author
Madeline Trotter
committed
Share button state definition between original and new button
1 parent da5a0d9 commit a1ced30

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/Lumi/Components/Button.purs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module Lumi.Components.Button where
1+
module Lumi.Components.Button
2+
( module Lumi.Components.Button
3+
, module Lumi.Components2.Button
4+
) where
25

36
import Prelude
47

@@ -16,13 +19,12 @@ import Lumi.Components.Color (ColorName, colorNames, colors)
1619
import Lumi.Components.Icon (IconType, icon)
1720
import Lumi.Components.Loader (spinnerMixin)
1821
import Lumi.Components.Size (Size(..))
22+
import Lumi.Components2.Button (ButtonState(..))
1923
import React.Basic.Classic (Component, JSX, createComponent, element, makeStateless)
2024
import React.Basic.DOM (CSS, css, unsafeCreateDOMComponent)
2125
import React.Basic.DOM as R
2226
import React.Basic.Events (EventHandler)
2327

24-
data ButtonState = Enabled | Disabled | Loading
25-
2628
type CommonButtonProps rest =
2729
{ accessibilityLabel :: Nullable String
2830
, color :: Nullable ColorName

src/Lumi/Components2/Button.purs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module Lumi.Components2.Button
1616
, varButtonHueDisabled, varButtonGrey1, varButtonGrey2
1717
, varButtonBlack, varButtonWhite
1818

19-
, submit, reset, onPress, onPress'
19+
, submit, reset, state, onPress, onPress'
2020
, autoFocus, tabIndex, ariaLabel
2121
) where
2222

@@ -31,7 +31,6 @@ import Effect.Class (liftEffect)
3131
import Effect.Unsafe (unsafePerformEffect)
3232
import Foreign.Object (fromHomogeneous)
3333
import Lumi.Components (LumiComponent, PropsModifier, lumiComponent, propsModifier, unsafeMaybeToNullableAttr)
34-
import Lumi.Components.Button (invisibleSpace)
3534
import Lumi.Components.Color (ColorMap, shade)
3635
import Lumi.Components.Size (Size(..))
3736
import Lumi.Components2.Box as Box
@@ -523,15 +522,29 @@ varButtonWhite = var "--button-white"
523522
-- | rather than providing an `onPress` action to the button
524523
-- | itself.
525524
submit :: forall c. ButtonState -> ButtonModifier c
526-
submit state = propsModifier _ { type = Submit, state = state }
525+
submit s = propsModifier _ { type = Submit, state = s }
527526

528527
-- | A form reset button. This helper takes the button state
529528
-- | as an argument because a form's buttons are generally
530529
-- | tied to the validity and `onSubmit` behavior of the form,
531530
-- | rather than providing an `onPress` action to the button
532531
-- | itself.
533532
reset :: forall c. ButtonState -> ButtonModifier c
534-
reset state = propsModifier _ { type = Reset, state = state }
533+
reset s = propsModifier _ { type = Reset, state = s }
534+
535+
-- | Set the button state. Generally you'll want to use `submit` or
536+
-- | `reset` instead, but this can still be useful for `onPress`
537+
-- | buttons which need to be disabled while some page state is
538+
-- | invalid or share in a collective page loading state.
539+
-- |
540+
-- | Note: When a page is in a loading state, any buttons which
541+
-- | were _not_ interacted with should be set to `Disabled`, not
542+
-- | `Loading`. A row of buttons containing the same spinner
543+
-- | looks strange. You also do not need to track which button
544+
-- | was interacted with, usually, because the `onPress` loading
545+
-- | state will override this one within the button pressed.
546+
state :: forall c. ButtonState -> ButtonModifier c
547+
state s = propsModifier _ { state = s }
535548

536549
-- | A button with customized `onPress` behavior. The button will
537550
-- | automatically display a loading state while the action is in-progress.
@@ -558,3 +571,8 @@ tabIndex i = propsModifier _ { tabIndex = Just i }
558571
-- | label to "Close".
559572
ariaLabel :: forall c. String -> ButtonModifier c
560573
ariaLabel l = propsModifier _ { ariaLabel = Just l }
574+
575+
----------------------------
576+
577+
invisibleSpace :: String
578+
invisibleSpace = "\x2063"

0 commit comments

Comments
 (0)