Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Commit dd14485

Browse files
committed
Add Material Stepper to open source export.
PiperOrigin-RevId: 199358483
1 parent c3c0b1f commit dd14485

16 files changed

+3270
-0
lines changed

lib/material_stepper/_mixins.scss

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
@import 'package:angular_components/css/material/material';
6+
7+
/// Changes the `$step-color` in the stepper.
8+
///
9+
/// Optionally specify a `$selector`. Example usage:
10+
/// @include material-stepper-theme(
11+
/// $step-color: $mat-teal-500,
12+
/// $selector: 'table-view');
13+
14+
@mixin material-stepper-theme(
15+
$step-selector: '',
16+
$step-color : $mat-blue-500,
17+
$disabled-color : $mat-grey-500,
18+
$button-color : $mat-blue-500,
19+
$selector: ''
20+
) {
21+
#{$selector} ::ng-deep material-stepper.themeable .stepper-yes-no-buttons {
22+
@include material-yes-button-color($button-color);
23+
}
24+
25+
#{$selector} ::ng-deep material-stepper.themeable .stepper-step-index {
26+
&[active = true] {
27+
background-color: $step-color;
28+
}
29+
30+
&[active = false] {
31+
background-color: $disabled-color;
32+
}
33+
34+
&[complete = true] {
35+
background-color: $step-color;
36+
}
37+
}
38+
}
39+
40+
@mixin stepper-body {
41+
::ng-deep .stepper.stepper-body.mixin {
42+
@content;
43+
}
44+
}
45+
46+
@mixin stepper-content {
47+
::ng-deep .stepper-content.mixin {
48+
@content;
49+
}
50+
}

lib/material_stepper/common.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
const String HORIZONTAL = 'horizontal';
6+
const String VERTICAL = 'vertical';
7+
const String SIZE_DEFAULT = 'default';
8+
const String SIZE_MINI = 'mini';
9+
const String ALL = 'all';
10+
const String BACKWARDS = 'backwards';
11+
const String NONE = 'none';
12+
13+
const Orientations = const <String>[HORIZONTAL, VERTICAL];
14+
15+
const Sizes = const <String>[SIZE_DEFAULT, SIZE_MINI];
16+
17+
const Jumps = const <String>[ALL, BACKWARDS, NONE];
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
import 'package:angular/angular.dart';
8+
import 'package:angular_components/laminate/portal/portal.dart';
9+
import 'package:angular_components/model/action/async_action.dart';
10+
import 'package:angular_components/utils/angular/properties/properties.dart';
11+
12+
/// A step within the stepper.
13+
///
14+
/// __Example usage:__
15+
///
16+
/// <material-stepper>
17+
/// <template step name="Step A">
18+
/// <div>
19+
/// [...]
20+
/// </div>
21+
/// </template>
22+
/// <template step name="Step B">
23+
/// <div>
24+
/// [...]
25+
/// </div>
26+
/// </template>
27+
/// <material-stepper>
28+
///
29+
@Directive(
30+
selector: '[step]',
31+
exportAs: 'step',
32+
)
33+
class StepDirective extends TemplatePortal {
34+
final _continueController =
35+
new StreamController<AsyncAction<bool>>.broadcast(sync: true);
36+
37+
final _cancelController =
38+
new StreamController<AsyncAction<bool>>.broadcast(sync: true);
39+
40+
final _jumpController =
41+
new StreamController<AsyncAction<bool>>.broadcast(sync: true);
42+
43+
/// Name shown as the title.
44+
@Input()
45+
String name;
46+
47+
bool _optional = false;
48+
49+
/// Whether the step is optional. Optional steps have an extra label denoting
50+
/// that they're optional and should be skip-able. Default is false.
51+
bool get optional => _optional;
52+
@Input()
53+
set optional(value) {
54+
_optional = getBool(value);
55+
}
56+
57+
/// Summary text shown when the step is completed in a vertical default-sized
58+
/// stepper. For other steppers, this doesn't apply.
59+
@Input()
60+
String completeSummary;
61+
62+
bool _hideButtons = false;
63+
64+
/// Whether the buttons should be hidden on this step.
65+
bool get hideButtons => _hideButtons;
66+
@Input()
67+
set hideButtons(value) {
68+
_hideButtons = getBool(value);
69+
}
70+
71+
bool _cancelHidden = false;
72+
73+
/// Whether the cancel button should be hidden on this step.
74+
bool get cancelHidden => _cancelHidden;
75+
@Input()
76+
set cancelHidden(value) {
77+
_cancelHidden = getBool(value);
78+
}
79+
80+
bool _complete = false;
81+
82+
/// Whether the step is completed.
83+
///
84+
/// This is set when the stepper goes to the next step.
85+
bool get complete => _complete;
86+
@Input()
87+
set complete(value) {
88+
_complete = getBool(value);
89+
}
90+
91+
bool _canContinue = true;
92+
93+
/// Whether the step can continue.
94+
///
95+
/// This can be used to prevent continuing on from a step until all parts of
96+
/// the current step meet validation requirements.
97+
bool get canContinue => _canContinue;
98+
@Input()
99+
set canContinue(value) {
100+
_canContinue = getBool(value);
101+
}
102+
103+
/// The selection state of the step.
104+
bool _active = false;
105+
bool busy = false;
106+
bool isLast = false;
107+
bool isSelectable = false;
108+
int index;
109+
110+
/// Optional summary directive associated with this step.
111+
SummaryDirective summaryDirective;
112+
113+
StepDirective(TemplateRef ref, ViewContainerRef viewContainerRef)
114+
: super(ref, viewContainerRef);
115+
116+
set active(bool value) {
117+
_active = value;
118+
}
119+
120+
bool get isOptional => optional;
121+
122+
bool get active => _active;
123+
124+
bool get isFirst => index == 0;
125+
126+
bool get isNotSelectable => !isSelectable;
127+
128+
/// Called when the Continue button is clicked. If the event handler calls
129+
/// $event.cancel(), the step won't be continued.
130+
@Output('continue')
131+
Stream<AsyncAction<bool>> get continueStream => _continueController.stream;
132+
133+
/// Called when the Cancel button is clicked. If the event handler calls
134+
/// $event.cancel(), the step won't be cancelled.
135+
@Output('cancel')
136+
Stream<AsyncAction<bool>> get cancelStream => _cancelController.stream;
137+
138+
@Output('jumpHere')
139+
Stream<AsyncAction<bool>> get jumpStream => _jumpController.stream;
140+
141+
void requestStepContinue(AsyncAction<bool> action) {
142+
_requestStepAction(action, _continueController);
143+
}
144+
145+
void requestStepCancel(AsyncAction<bool> action) {
146+
_requestStepAction(action, _cancelController);
147+
}
148+
149+
void requestStepJump(AsyncAction<bool> action) {
150+
_requestStepAction(action, _jumpController);
151+
}
152+
153+
bool get shouldShowSummary => !active && completeSummary != null && complete;
154+
155+
void _requestStepAction(AsyncAction<bool> action,
156+
StreamController<AsyncAction<bool>> controller) {
157+
busy = true;
158+
controller.add(action);
159+
action.onDone.then((_) {
160+
busy = false;
161+
});
162+
}
163+
}
164+
165+
/// A [TemplatePortal] which is used to house an optional summary view for a
166+
/// [StepDirective].
167+
///
168+
/// Note: Only works with vertical orrientation.
169+
///
170+
/// __Example usage:__
171+
///
172+
/// <material-stepper orientation="vertical">
173+
/// <template step name="A" #stepA="step">Step</template>
174+
/// <template [summary]="stepA"><h3>Summary A</h3></template>
175+
/// </material-stepper>
176+
///
177+
@Directive(
178+
selector: '[summary]',
179+
)
180+
class SummaryDirective extends TemplatePortal {
181+
/// The [StepDirective] associated with this summary.
182+
@Input()
183+
set summary(StepDirective step) {
184+
assert(step != null, 'Should pass in a valid step for a summary.');
185+
step.summaryDirective = this;
186+
}
187+
188+
SummaryDirective(TemplateRef ref, ViewContainerRef viewContainerRef)
189+
: super(ref, viewContainerRef);
190+
}

0 commit comments

Comments
 (0)