|
| 1 | +module Fable.Helpers.ReactTransitionGroup |
| 2 | + |
| 3 | +open Fable.Core |
| 4 | +open Fable.Core.JsInterop |
| 5 | +open Fable.Import |
| 6 | +open Fable.Helpers.React |
| 7 | + |
| 8 | +type Timeout = { |
| 9 | + enter: int option |
| 10 | + exit: int option |
| 11 | +} |
| 12 | + |
| 13 | +type [<StringEnum>] TransitionStatus = |
| 14 | + | [<CompiledName("entering")>] Entering |
| 15 | + | [<CompiledName("entered")>] Entered |
| 16 | + | [<CompiledName("exiting")>] Exiting |
| 17 | + | [<CompiledName("exited")>] Exited |
| 18 | + | [<CompiledName("unmounted")>] Unmounted |
| 19 | + |
| 20 | +[<RequireQualifiedAccess>] |
| 21 | +type TransitionProp = |
| 22 | + /// Show the element; triggers the `enter` or `exit` states |
| 23 | + | In of bool |
| 24 | + /// Normally a element is not transitioned if it is shown when the `transition` element mounts. |
| 25 | + /// If you want to transition on the first mount set appear to true, |
| 26 | + /// and the element will transition in as soon as the `transition` mounts. |
| 27 | + | Appear of bool |
| 28 | + /// Enable or disable enter transitions. |
| 29 | + | Enter of bool |
| 30 | + /// Enable or disable exit transitions. |
| 31 | + | Exit of bool |
| 32 | + /// By default the child element is mounted immediately along with the parent `transition` element. |
| 33 | + /// If you want to "lazy mount" the element on the first `In true` you can set `MountOnEnter`. |
| 34 | + /// After the first enter transition the element will stay mounted, even on `exited`, unless you also specify `UnmountOnExit`. |
| 35 | + | MountOnEnter of bool |
| 36 | + /// By default the child element stays mounted after it reaches the `exited` state. |
| 37 | + /// Set `UnmountOnExit` if you'd prefer to unmount the element after it finishes exiting. |
| 38 | + | UnmountOnExit of bool |
| 39 | + /// The duration of the transition, in milliseconds. Required unless `AddEndListener` is provided |
| 40 | + | Timeout of U2<int, Timeout> |
| 41 | + /// Add a custom transition end trigger. |
| 42 | + /// Called with the transitioning DOM node and a done callback. |
| 43 | + /// Allows for more fine grained transition end logic. |
| 44 | + /// Note: Timeouts are still used as a fallback if provided. |
| 45 | + | AddEndListener of (Browser.HTMLElement -> (unit -> unit) -> unit) |
| 46 | + /// A transition callback fired immediately after the `enter` or `appear` class is applied. |
| 47 | + | OnEnter of (Browser.HTMLElement -> bool -> unit) |
| 48 | + /// A transition callback fired immediately after the `enter-active` or `appear-active` class is applied. |
| 49 | + | OnEntering of (Browser.HTMLElement -> bool -> unit) |
| 50 | + /// A transition callback fired immediately after the `enter` or `appear` classes are removed and the done class is added to the DOM node. |
| 51 | + | OnEntered of (Browser.HTMLElement -> bool -> unit) |
| 52 | + /// A transition callback fired immediately after the `exit` class is applied. |
| 53 | + | OnExit of (Browser.HTMLElement -> unit) |
| 54 | + /// A transition callback fired immediately after the `exit-active` is applied. |
| 55 | + | OnExiting of (Browser.HTMLElement -> unit) |
| 56 | + /// A transition callback fired immediately after the `exit` classes are removed and the exit-done class is added to the DOM node. |
| 57 | + | OnExited of (Browser.HTMLElement -> unit) |
| 58 | + /// A function child can be used instead of a React element. |
| 59 | + /// This function is called with the current transition status |
| 60 | + /// (`entering`, `entered`, `exiting`, `exited`, `unmounted`), |
| 61 | + /// which can be used to apply context specific props to a element. |
| 62 | + | Children of U2<React.ReactElement, TransitionStatus -> React.ReactElement> |
| 63 | + | [<CompiledName "className">] Class of string |
| 64 | + | Ref of (obj -> obj) |
| 65 | + | Key of string |
| 66 | + static member Custom(key: string, value: obj): TransitionProp = |
| 67 | + unbox(key, value) |
| 68 | + |
| 69 | +type CSSTransitionClassNames = { |
| 70 | + appear: string option |
| 71 | + appearActive: string option |
| 72 | + enter: string option |
| 73 | + enterActive: string option |
| 74 | + enterDone: string option |
| 75 | + exit: string option |
| 76 | + exitActive: string option |
| 77 | + exitDone: string option |
| 78 | +} |
| 79 | + |
| 80 | +[<RequireQualifiedAccess>] |
| 81 | +type CSSTransitionProp = |
| 82 | + /// Show the element; triggers the `enter` or `exit` states |
| 83 | + | In of bool |
| 84 | + /// Normally a element is not transitioned if it is shown when the `transition` element mounts. |
| 85 | + /// If you want to transition on the first mount set appear to true, |
| 86 | + /// and the element will transition in as soon as the `transition` mounts. |
| 87 | + | Appear of bool |
| 88 | + /// Enable or disable enter transitions. |
| 89 | + | Enter of bool |
| 90 | + /// Enable or disable exit transitions. |
| 91 | + | Exit of bool |
| 92 | + /// By default the child element is mounted immediately along with the parent `transition` element. |
| 93 | + /// If you want to "lazy mount" the element on the first `In true` you can set `MountOnEnter`. |
| 94 | + /// After the first enter transition the element will stay mounted, even on `exited`, unless you also specify `UnmountOnExit`. |
| 95 | + | MountOnEnter of bool |
| 96 | + /// By default the child element stays mounted after it reaches the `exited` state. |
| 97 | + /// Set `UnmountOnExit` if you'd prefer to unmount the element after it finishes exiting. |
| 98 | + | UnmountOnExit of bool |
| 99 | + /// The duration of the transition, in milliseconds. Required unless `AddEndListener` is provided |
| 100 | + | Timeout of U2<int, Timeout> |
| 101 | + /// Add a custom transition end trigger. |
| 102 | + /// Called with the transitioning DOM node and a done callback. |
| 103 | + /// Allows for more fine grained transition end logic. |
| 104 | + /// Note: Timeouts are still used as a fallback if provided. |
| 105 | + | AddEndListener of (Browser.HTMLElement -> (unit -> unit) -> unit) |
| 106 | + /// A transition callback fired immediately after the `enter` or `appear` class is applied. |
| 107 | + | OnEnter of (Browser.HTMLElement -> bool -> unit) |
| 108 | + /// A transition callback fired immediately after the `enter-active` or `appear-active` class is applied. |
| 109 | + | OnEntering of (Browser.HTMLElement -> bool -> unit) |
| 110 | + /// A transition callback fired immediately after the `enter` or `appear` classes are removed and the done class is added to the DOM node. |
| 111 | + | OnEntered of (Browser.HTMLElement -> bool -> unit) |
| 112 | + /// A transition callback fired immediately after the `exit` class is applied. |
| 113 | + | OnExit of (Browser.HTMLElement -> unit) |
| 114 | + /// A transition callback fired immediately after the `exit-active` is applied. |
| 115 | + | OnExiting of (Browser.HTMLElement -> unit) |
| 116 | + /// A transition callback fired immediately after the `exit` classes are removed and the exit-done class is added to the DOM node. |
| 117 | + | OnExited of (Browser.HTMLElement -> unit) |
| 118 | + /// A function child can be used instead of a React element. |
| 119 | + /// This function is called with the current transition status |
| 120 | + /// (`entering`, `entered`, `exiting`, `exited`, `unmounted`), |
| 121 | + /// which can be used to apply context specific props to a element. |
| 122 | + | Children of U2<React.ReactElement, TransitionStatus -> React.ReactElement> |
| 123 | + /// The animation ClassNames applied to the element as it enters or exits. |
| 124 | + /// A single name can be provided and it will be suffixed for each stage: e.g. |
| 125 | + /// |
| 126 | + /// `classNames="fade"` applies `fade-enter`, `fade-enter-active`, |
| 127 | + /// `fade-exit`, `fade-exit-active`, `fade-appear`, and `fade-appear-active`. |
| 128 | + /// Each individual classNames can also be specified independently. |
| 129 | + | ClassNames of U2<string, CSSTransitionClassNames> |
| 130 | + | [<CompiledName "className">] Class of string |
| 131 | + | Ref of (obj -> obj) |
| 132 | + | Key of string |
| 133 | + static member Custom(key: string, value: obj): CSSTransitionProp = |
| 134 | + unbox(key, value) |
| 135 | + |
| 136 | +[<RequireQualifiedAccess>] |
| 137 | +type TransitionGroupProp = |
| 138 | + /// `transitionGroup` renders a <div> by default. |
| 139 | + /// You can change this behavior by providing a component prop. |
| 140 | + /// If you use React v16+ and would like to avoid a wrapping <div> element you can pass in `Component null`. |
| 141 | + /// This is useful if the wrapping div borks your css styles. |
| 142 | + | Component of React.ReactType |
| 143 | + /// A convenience prop that enables or disables appear animations for all children. |
| 144 | + /// Note that specifying this will override any defaults set on individual children Transitions. |
| 145 | + | Appear of bool |
| 146 | + /// A convenience prop that enables or disables enter animations for all children. |
| 147 | + /// Note that specifying this will override any defaults set on individual children Transitions. |
| 148 | + | Enter of bool |
| 149 | + /// A convenience prop that enables or disables exit animations for all children. |
| 150 | + /// Note that specifying this will override any defaults set on individual children Transitions. |
| 151 | + | Exit of bool |
| 152 | + /// You may need to apply reactive updates to a child as it is exiting. |
| 153 | + /// This is generally done by using cloneElement however in the case of an |
| 154 | + /// exiting child the element has already been removed and not accessible to the consumer. |
| 155 | + | ChildFactory of (React.ReactElement -> React.ReactElement) |
| 156 | + | [<CompiledName "className">] Class of string |
| 157 | + | Ref of (obj -> obj) |
| 158 | + | Key of string |
| 159 | + static member Custom(key: string, value: obj): TransitionGroupProp = |
| 160 | + unbox(key, value) |
| 161 | + |
| 162 | +/// The transition element lets you describe a transition from one element |
| 163 | +/// state to another _over time_ with a simple declarative API. Most commonly |
| 164 | +/// It's used to animate the mounting and unmounting of Component, but can also |
| 165 | +/// be used to describe in-place transition states as well. |
| 166 | +/// |
| 167 | +/// By default the `transition` element does not alter the behavior of the |
| 168 | +/// element it renders, it only tracks Enter and Exit states for the elements. |
| 169 | +/// It's up to you to give meaning and effect to those states. For example we can |
| 170 | +/// add styles to a element when it enters or exits. |
| 171 | +let transition (props: TransitionProp list) (child: React.ReactElement): React.ReactElement = |
| 172 | + let props = (TransitionProp.Children !^child)::props |
| 173 | + ofImport "Transition" "react-transition-group" (keyValueList CaseRules.LowerFirst props) [] |
| 174 | + |
| 175 | +/// The transition element lets you describe a transition from one component |
| 176 | +/// state to another _over time_ with a simple declarative API. Most commonly |
| 177 | +/// It's used to animate the mounting and unmounting of Component, but can also |
| 178 | +/// be used to describe in-place transition states as well. |
| 179 | +/// |
| 180 | +/// By default the `transition` element does not alter the behavior of the |
| 181 | +/// element it renders, it only tracks Enter and Exit states for the elements. |
| 182 | +/// It's up to you to give meaning and effect to those states. For example we can |
| 183 | +/// add styles to a element when it enters or exits. |
| 184 | +let transitionWithRender (props: TransitionProp list) (render: TransitionStatus -> React.ReactElement): React.ReactElement = |
| 185 | + let props = (TransitionProp.Children !^render)::props |
| 186 | + ofImport "Transition" "react-transition-group" (keyValueList CaseRules.LowerFirst props) [] |
| 187 | + |
| 188 | +/// A transition element using CSS transitions and animations. |
| 189 | +/// See `transition` for more information. |
| 190 | +let cssTransition (props: CSSTransitionProp list) (child: React.ReactElement): React.ReactElement = |
| 191 | + let props = (CSSTransitionProp.Children !^child)::props |
| 192 | + ofImport "CSSTransition" "react-transition-group" (keyValueList CaseRules.LowerFirst props) [] |
| 193 | + |
| 194 | +/// A transition element using CSS transitions and animations. |
| 195 | +/// See `transitionWithRender` for more information. |
| 196 | +let cssTransitionWithRender (props: CSSTransitionProp list) (render: TransitionStatus -> React.ReactElement): React.ReactElement = |
| 197 | + let props = (CSSTransitionProp.Children !^render)::props |
| 198 | + ofImport "CSSTransition" "react-transition-group" (keyValueList CaseRules.LowerFirst props) [] |
| 199 | + |
| 200 | +/// The `transitionGroup` element manages a set of `transition` elements |
| 201 | +/// in a list. Like with the `transition` element, `transitionGroup`, is a |
| 202 | +/// state machine for managing the mounting and unmounting of elements over |
| 203 | +/// time. |
| 204 | +let transitionGroup (props: TransitionGroupProp list) (children: React.ReactElement list): React.ReactElement = |
| 205 | + ofImport "TransitionGroup" "react-transition-group" (keyValueList CaseRules.LowerFirst props) children |
0 commit comments