Skip to content

Commit 40f4735

Browse files
authored
Merge pull request #74 from aaronlademann-wf/abstract_transition_props_mixin
UIP-2373 Make AbstractTransitionProps available in mixin form
2 parents e1e0321 + fefee46 commit 40f4735

File tree

3 files changed

+73
-26
lines changed

3 files changed

+73
-26
lines changed

lib/over_react.dart

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export 'package:react/react.dart' show
3030
export 'package:react/react_client.dart' show setClientConfiguration, ReactElement;
3131

3232
export 'src/component/abstract_transition.dart';
33+
export 'src/component/abstract_transition_props.dart';
3334
export 'src/component/aria_mixin.dart';
3435
export 'src/component/callback_typedefs.dart';
3536
export 'src/component/dom_components.dart';

lib/src/component/abstract_transition.dart

+11-26
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,7 @@ import 'package:meta/meta.dart';
2121
import 'package:over_react/over_react.dart';
2222

2323
@AbstractProps()
24-
abstract class AbstractTransitionProps extends UiProps {
25-
/// Number of transitions to occur within the [AbstractTransitionComponent].
26-
///
27-
/// _If the [AbstractTransitionComponent] does not transition set [AbstractTransitionProps.transition] to [Transition.NONE] rather than setting this to 0._
28-
///
29-
/// Default: 1
30-
int transitionCount;
31-
32-
/// Optional callback that fires before the [AbstractTransitionComponent] is hidden.
33-
///
34-
/// Returning `false` will cancel default behavior, and the [AbstractTransitionComponent] will remain visible.
35-
Callback onWillHide;
36-
37-
/// Optional callback that fires after the [AbstractTransitionComponent] is hidden.
38-
Callback onDidHide;
39-
40-
/// Optional callback that fires before the [AbstractTransitionComponent] appears.
41-
///
42-
/// Returning `false` will cancel default behavior, and the [AbstractTransitionComponent] will not appear.
43-
Callback onWillShow;
44-
45-
/// Optional callback that fires after the [AbstractTransitionComponent] appears.
46-
Callback onDidShow;
47-
}
24+
abstract class AbstractTransitionProps extends UiProps with TransitionPropsMixin {}
4825

4926
@AbstractState()
5027
abstract class AbstractTransitionState extends UiState {
@@ -101,10 +78,18 @@ abstract class AbstractTransitionState extends UiState {
10178
/// * [hide]
10279
/// * [toggle]
10380
@AbstractComponent()
104-
abstract class AbstractTransitionComponent<T extends AbstractTransitionProps, S extends AbstractTransitionState> extends UiStatefulComponent<T, S> {
81+
abstract class AbstractTransitionComponent<T extends AbstractTransitionProps,
82+
S extends AbstractTransitionState>
83+
extends UiStatefulComponent<T, S> {
84+
@override
85+
get consumedProps => const [
86+
const $Props(AbstractTransitionProps),
87+
const $Props(TransitionPropsMixin),
88+
];
89+
10590
@override
10691
Map getDefaultProps() => (newProps()
107-
..transitionCount = 1
92+
..addProps(TransitionPropsMixin.defaultProps)
10893
);
10994

11095
@override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2017 Workiva Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
library abstract_transition_props;
16+
17+
import 'dart:collection';
18+
19+
import 'package:over_react/over_react.dart';
20+
21+
/// Props that mirror the implementation of [AbstractTransitionProps], made available as a mixin for components
22+
/// that cannot extend directly from [AbstractTransitionComponent].
23+
@PropsMixin()
24+
abstract class TransitionPropsMixin {
25+
static final TransitionPropsMapView defaultProps = new TransitionPropsMapView({})
26+
..transitionCount = 1;
27+
28+
Map get props;
29+
30+
/// Number of transitions to occur within the [AbstractTransitionComponent].
31+
///
32+
/// Default: 1
33+
int transitionCount;
34+
35+
/// Optional callback that fires before the [AbstractTransitionComponent] is hidden.
36+
///
37+
/// Returning `false` will cancel default behavior, and the [AbstractTransitionComponent] will remain visible.
38+
Callback onWillHide;
39+
40+
/// Optional callback that fires after the [AbstractTransitionComponent] is hidden.
41+
Callback onDidHide;
42+
43+
/// Optional callback that fires before the [AbstractTransitionComponent] appears.
44+
///
45+
/// Returning `false` will cancel default behavior, and the [AbstractTransitionComponent] will not appear.
46+
Callback onWillShow;
47+
48+
/// Optional callback that fires after the [AbstractTransitionComponent] appears.
49+
Callback onDidShow;
50+
}
51+
52+
class TransitionPropsMapView extends MapView with
53+
TransitionPropsMixin {
54+
/// Create a new instance backed by the specified map.
55+
TransitionPropsMapView(Map map) : super(map);
56+
57+
/// The props to be manipulated via the getters/setters.
58+
/// In this case, it's the current MapView object.
59+
@override
60+
Map get props => this;
61+
}

0 commit comments

Comments
 (0)