Skip to content

Commit fefee46

Browse files
Make AbstractTransitionProps available in mixin form
1 parent 61fbe7a commit fefee46

File tree

3 files changed

+73
-26
lines changed

3 files changed

+73
-26
lines changed

lib/over_react.dart

Lines changed: 1 addition & 0 deletions
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

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,7 @@ import 'dart:html';
2020
import 'package:over_react/over_react.dart';
2121

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

4825
@AbstractState()
4926
abstract class AbstractTransitionState extends UiState {
@@ -100,10 +77,18 @@ abstract class AbstractTransitionState extends UiState {
10077
/// * [hide]
10178
/// * [toggle]
10279
@AbstractComponent()
103-
abstract class AbstractTransitionComponent<T extends AbstractTransitionProps, S extends AbstractTransitionState> extends UiStatefulComponent<T, S> {
80+
abstract class AbstractTransitionComponent<T extends AbstractTransitionProps,
81+
S extends AbstractTransitionState>
82+
extends UiStatefulComponent<T, S> {
83+
@override
84+
get consumedProps => const [
85+
const $Props(AbstractTransitionProps),
86+
const $Props(TransitionPropsMixin),
87+
];
88+
10489
@override
10590
Map getDefaultProps() => (newProps()
106-
..transitionCount = 1
91+
..addProps(TransitionPropsMixin.defaultProps)
10792
);
10893

10994
@override
Lines changed: 61 additions & 0 deletions
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)