Skip to content

Commit 3b3b61e

Browse files
authored
chore: select option cell & header editor UI + move to theme.of(context).texttheme (#1483)
* chore: improvements for suffix text in textfields * chore: port more const textstyles to theme provider styles * chore: select option editor UI improvements
1 parent f02e77f commit 3b3b61e

File tree

7 files changed

+107
-95
lines changed

7 files changed

+107
-95
lines changed

frontend/app_flowy/lib/plugins/grid/presentation/widgets/cell/select_option_cell/extension.dart

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flowy_infra/color_extension.dart';
2+
import 'package:flowy_infra/size.dart';
23
import 'package:flowy_infra_ui/style_widget/hover.dart';
34
import 'package:flowy_infra_ui/style_widget/text.dart';
45
import 'package:flowy_sdk/protobuf/flowy-grid/select_type_option.pb.dart';
@@ -87,17 +88,13 @@ class SelectOptionTag extends StatelessWidget {
8788

8889
@override
8990
Widget build(BuildContext context) {
90-
return ChoiceChip(
91-
pressElevation: 1,
92-
label: FlowyText.medium(
93-
name,
94-
overflow: TextOverflow.clip,
91+
return Container(
92+
padding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 8.0),
93+
decoration: BoxDecoration(
94+
color: color,
95+
borderRadius: Corners.s6Border,
9596
),
96-
selectedColor: color,
97-
backgroundColor: color,
98-
labelPadding: const EdgeInsets.symmetric(horizontal: 6),
99-
selected: true,
100-
onSelected: (_) => onSelected?.call(),
97+
child: FlowyText.medium(name, overflow: TextOverflow.ellipsis),
10198
);
10299
}
103100
}
@@ -115,30 +112,29 @@ class SelectOptionTagCell extends StatelessWidget {
115112

116113
@override
117114
Widget build(BuildContext context) {
118-
return Stack(
119-
fit: StackFit.expand,
120-
children: [
121-
FlowyHover(
122-
child: InkWell(
123-
child: Padding(
124-
padding: const EdgeInsets.symmetric(horizontal: 3),
125-
child: Row(
126-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
127-
children: [
128-
SelectOptionTag.fromOption(
115+
return FlowyHover(
116+
child: InkWell(
117+
child: Row(
118+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
119+
children: [
120+
Expanded(
121+
child: Align(
122+
alignment: Alignment.centerLeft,
123+
child: Padding(
124+
padding: const EdgeInsets.all(5.0),
125+
child: SelectOptionTag.fromOption(
129126
context: context,
130127
option: option,
131128
onSelected: () => onSelected(option),
132129
),
133-
const Spacer(),
134-
...children,
135-
],
130+
),
136131
),
137132
),
138-
onTap: () => onSelected(option),
139-
),
133+
...children,
134+
],
140135
),
141-
],
136+
onTap: () => onSelected(option),
137+
),
142138
);
143139
}
144140
}

frontend/app_flowy/lib/plugins/grid/presentation/widgets/cell/select_option_cell/select_option_cell.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class _SelectOptionWrapState extends State<SelectOptionWrap> {
223223
).toList();
224224

225225
child = Wrap(
226-
runSpacing: 2,
226+
runSpacing: 4,
227227
children: children,
228228
);
229229
}

frontend/app_flowy/lib/plugins/grid/presentation/widgets/cell/select_option_cell/select_option_editor.dart

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,24 @@ class _SelectOptionCellEditorState extends State<SelectOptionCellEditor> {
5353
)..add(const SelectOptionEditorEvent.initial()),
5454
child: BlocBuilder<SelectOptionCellEditorBloc, SelectOptionEditorState>(
5555
builder: (context, state) {
56+
final List<Widget> children = [
57+
_TextField(popoverMutex: popoverMutex),
58+
const TypeOptionSeparator(),
59+
const _Title(),
60+
_OptionList(popoverMutex: popoverMutex),
61+
];
62+
5663
return Padding(
5764
padding: const EdgeInsets.all(6.0),
58-
child: CustomScrollView(
65+
child: ListView.separated(
5966
shrinkWrap: true,
60-
slivers: [
61-
SliverToBoxAdapter(
62-
child: _TextField(popoverMutex: popoverMutex),
63-
),
64-
const SliverToBoxAdapter(child: TypeOptionSeparator()),
65-
const SliverToBoxAdapter(child: VSpace(6)),
66-
const SliverToBoxAdapter(child: _Title()),
67-
SliverToBoxAdapter(
68-
child: _OptionList(popoverMutex: popoverMutex),
69-
),
70-
],
67+
itemCount: children.length,
68+
itemBuilder: (BuildContext context, int index) {
69+
return children[index];
70+
},
71+
separatorBuilder: (BuildContext context, int index) {
72+
return VSpace(GridSize.typeOptionSeparatorHeight);
73+
},
7174
),
7275
);
7376
},
@@ -143,35 +146,32 @@ class _TextField extends StatelessWidget {
143146
key: (option) => option.name,
144147
value: (option) => option);
145148

146-
return SizedBox(
147-
height: 52,
148-
child: SelectOptionTextField(
149-
options: state.options,
150-
selectedOptionMap: optionMap,
151-
distanceToText: _editorPanelWidth * 0.7,
152-
maxLength: 30,
153-
tagController: _tagController,
154-
textSeparators: const [','],
155-
onClick: () => popoverMutex.close(),
156-
newText: (text) {
157-
context
158-
.read<SelectOptionCellEditorBloc>()
159-
.add(SelectOptionEditorEvent.filterOption(text));
160-
},
161-
onSubmitted: (tagName) {
162-
context
163-
.read<SelectOptionCellEditorBloc>()
164-
.add(SelectOptionEditorEvent.trySelectOption(tagName));
165-
},
166-
onPaste: (tagNames, remainder) {
167-
context
168-
.read<SelectOptionCellEditorBloc>()
169-
.add(SelectOptionEditorEvent.selectMultipleOptions(
170-
tagNames,
171-
remainder,
172-
));
173-
},
174-
),
149+
return SelectOptionTextField(
150+
options: state.options,
151+
selectedOptionMap: optionMap,
152+
distanceToText: _editorPanelWidth * 0.7,
153+
maxLength: 30,
154+
tagController: _tagController,
155+
textSeparators: const [','],
156+
onClick: () => popoverMutex.close(),
157+
newText: (text) {
158+
context
159+
.read<SelectOptionCellEditorBloc>()
160+
.add(SelectOptionEditorEvent.filterOption(text));
161+
},
162+
onSubmitted: (tagName) {
163+
context
164+
.read<SelectOptionCellEditorBloc>()
165+
.add(SelectOptionEditorEvent.trySelectOption(tagName));
166+
},
167+
onPaste: (tagNames, remainder) {
168+
context
169+
.read<SelectOptionCellEditorBloc>()
170+
.add(SelectOptionEditorEvent.selectMultipleOptions(
171+
tagNames,
172+
remainder,
173+
));
174+
},
175175
);
176176
},
177177
);
@@ -209,12 +209,17 @@ class _CreateOptionCell extends StatelessWidget {
209209
color: Theme.of(context).hintColor,
210210
),
211211
const HSpace(10),
212-
SelectOptionTag(
213-
name: name,
214-
color: AFThemeExtension.of(context).lightGreyHover,
215-
onSelected: () => context
216-
.read<SelectOptionCellEditorBloc>()
217-
.add(SelectOptionEditorEvent.newOption(name)),
212+
Expanded(
213+
child: Align(
214+
alignment: Alignment.centerLeft,
215+
child: SelectOptionTag(
216+
name: name,
217+
color: AFThemeExtension.of(context).lightGreyHover,
218+
onSelected: () => context
219+
.read<SelectOptionCellEditorBloc>()
220+
.add(SelectOptionEditorEvent.newOption(name)),
221+
),
222+
),
218223
),
219224
],
220225
);
@@ -271,14 +276,13 @@ class _SelectOptionCellState extends State<_SelectOptionCell> {
271276
children: [
272277
if (widget.isSelected)
273278
Padding(
274-
padding: const EdgeInsets.only(right: 6),
279+
padding: const EdgeInsets.only(left: 6),
275280
child: svgWidget("grid/checkmark"),
276281
),
277282
FlowyIconButton(
278-
width: 30,
279283
onPressed: () => _popoverController.show(),
280284
hoverColor: Colors.transparent,
281-
iconPadding: const EdgeInsets.fromLTRB(4, 4, 4, 4),
285+
iconPadding: const EdgeInsets.symmetric(horizontal: 6.0),
282286
icon: svgWidget(
283287
"editor/details",
284288
color: Theme.of(context).colorScheme.onSurface,

frontend/app_flowy/lib/plugins/grid/presentation/widgets/cell/select_option_cell/text_field.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'dart:collection';
22

33
import 'package:flowy_infra/size.dart';
4-
import 'package:flowy_infra/text_style.dart';
54
import 'package:flowy_sdk/protobuf/flowy-grid/select_type_option.pb.dart';
65
import 'package:flutter/gestures.dart';
76
import 'package:flutter/material.dart';
@@ -49,7 +48,6 @@ class SelectOptionTextField extends StatefulWidget {
4948
class _SelectOptionTextFieldState extends State<SelectOptionTextField> {
5049
late FocusNode focusNode;
5150
late TextEditingController controller;
52-
var textLength = 0;
5351

5452
@override
5553
void initState() {
@@ -64,7 +62,7 @@ class _SelectOptionTextFieldState extends State<SelectOptionTextField> {
6462

6563
String? _suffixText() {
6664
if (widget.maxLength != null) {
67-
return '${textLength.toString()}/${widget.maxLength.toString()}';
65+
return ' ${controller.text.length}/${widget.maxLength}';
6866
} else {
6967
return null;
7068
}
@@ -92,7 +90,6 @@ class _SelectOptionTextFieldState extends State<SelectOptionTextField> {
9290
focusNode: focusNode,
9391
onTap: widget.onClick,
9492
onChanged: (text) {
95-
textLength = text.length;
9693
if (onChanged != null) {
9794
onChanged(text);
9895
}
@@ -112,18 +109,22 @@ class _SelectOptionTextFieldState extends State<SelectOptionTextField> {
112109
maxLength: widget.maxLength,
113110
maxLengthEnforcement:
114111
MaxLengthEnforcement.truncateAfterCompositionEnds,
115-
style: TextStyles.body1.size(FontSizes.s14),
112+
style: Theme.of(context).textTheme.bodyMedium,
116113
decoration: InputDecoration(
117114
enabledBorder: OutlineInputBorder(
118115
borderSide: BorderSide(
119-
color: Theme.of(context).colorScheme.primary,
116+
color: Theme.of(context).colorScheme.outline,
120117
width: 1.0,
121118
),
122119
borderRadius: Corners.s10Border,
123120
),
124121
isDense: true,
125122
prefixIcon: _renderTags(context, sc),
126123
hintText: LocaleKeys.grid_selectOption_searchOption.tr(),
124+
hintStyle: Theme.of(context)
125+
.textTheme
126+
.bodySmall!
127+
.textColor(Theme.of(context).hintColor),
127128
suffixText: _suffixText(),
128129
counterText: "",
129130
prefixIconConstraints:

frontend/app_flowy/lib/plugins/grid/presentation/widgets/common/text_field.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import 'package:flowy_infra/text_style.dart';
21
import 'package:flowy_infra_ui/widget/rounded_input_field.dart';
32
import 'package:flutter/material.dart';
43
import 'package:flutter/scheduler.dart';
5-
import 'package:textstyle_extensions/textstyle_extensions.dart';
64

75
class InputTextField extends StatefulWidget {
86
final void Function(String)? onDone;
@@ -47,15 +45,13 @@ class _InputTextFieldState extends State<InputTextField> {
4745

4846
@override
4947
Widget build(BuildContext context) {
50-
final height = widget.maxLength == null ? 36.0 : 56.0;
51-
5248
return RoundedInputField(
5349
controller: _controller,
5450
focusNode: _focusNode,
5551
autoFocus: true,
56-
height: height,
52+
height: 36.0,
5753
maxLength: widget.maxLength,
58-
style: TextStyles.body1.size(13),
54+
style: Theme.of(context).textTheme.bodyMedium,
5955
onChanged: (text) {
6056
if (widget.onChanged != null) {
6157
widget.onChanged!(text);

frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/type_option/select_option.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,12 @@ class _OptionCellState extends State<_OptionCell> {
193193
_popoverController.show();
194194
},
195195
children: [
196-
svgWidget(
197-
"grid/details",
198-
color: Theme.of(context).colorScheme.onSurface,
196+
Padding(
197+
padding: const EdgeInsets.symmetric(horizontal: 6.0),
198+
child: svgWidget(
199+
"grid/details",
200+
color: Theme.of(context).colorScheme.onSurface,
201+
),
199202
),
200203
],
201204
),

frontend/app_flowy/packages/flowy_infra_ui/lib/widget/rounded_input_field.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ class _RoundedInputFieldState extends State<RoundedInputField> {
7373
super.initState();
7474
}
7575

76+
String? _suffixText() {
77+
if (widget.maxLength != null) {
78+
return ' ${widget.controller!.text.length}/${widget.maxLength}';
79+
} else {
80+
return null;
81+
}
82+
}
83+
7684
@override
7785
Widget build(BuildContext context) {
7886
var borderColor =
@@ -117,8 +125,12 @@ class _RoundedInputFieldState extends State<RoundedInputField> {
117125
decoration: InputDecoration(
118126
contentPadding: widget.contentPadding,
119127
hintText: widget.hintText,
120-
hintStyle:
121-
Theme.of(context).textTheme.bodySmall!.textColor(borderColor),
128+
hintStyle: Theme.of(context)
129+
.textTheme
130+
.bodySmall!
131+
.textColor(Theme.of(context).hintColor),
132+
suffixText: _suffixText(),
133+
counterText: "",
122134
enabledBorder: OutlineInputBorder(
123135
borderSide: BorderSide(
124136
color: borderColor,

0 commit comments

Comments
 (0)