Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1046)

Side by Side Diff: sky/examples/editor/input.dart

Issue 983213005: Move material Input component into sky/framework (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/examples/editor/index.sky ('k') | sky/examples/editor/keyboard.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 import '../../framework/fn.dart';
6 import '../../framework/theme/colors.dart';
7 import 'editable_string.dart';
8 import 'editable_text.dart';
9 import 'keyboard.dart';
10
11 typedef void ValueChanged(value);
12
13 class Input extends Component {
14 static final Style _style = new Style('''
15 display: paragraph;
16 margin: 8px;
17 padding: 8px;
18 border-bottom: 1px solid ${Grey[200]};
19 align-self: center;
20 height: 1.2em;
21 white-space: pre;
22 overflow: hidden;'''
23 );
24
25 static final String _focusedInlineStyle = '''
26 padding: 7px;
27 border-bottom: 2px solid ${Blue[500]};''';
28
29 ValueChanged onChanged;
30 String value;
31
32 bool _focused = false;
33 EditableString _editableValue;
34
35 Input({Object key, this.value: ''}) : super(key: key, stateful: true) {
36 _editableValue = new EditableString(text: value,
37 onUpdated: _handleTextUpdated);
38 events.listen('click', _handleClick);
39 }
40
41 void _handleClick(_) {
42 keyboard.show(_editableValue.stub);
43 setState(() {
44 _focused = true;
45 });
46 }
47
48 void _handleTextUpdated() {
49 setState(() {});
50 if (value != _editableValue.text) {
51 value = _editableValue.text;
52 if (onChanged != null)
53 onChanged(value);
54 }
55 }
56
57 Node build() {
58 return new Container(
59 style: _style,
60 inlineStyle: _focused ? _focusedInlineStyle : null,
61 children: [
62 new EditableText(value: _editableValue, focused: _focused),
63 ]
64 );
65 }
66 }
OLDNEW
« no previous file with comments | « sky/examples/editor/index.sky ('k') | sky/examples/editor/keyboard.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698