Skip to content

Commit d6cbbf3

Browse files
authored
chore: date cell & header editor UI + move to theme.of(context).texttheme (#1473)
* chore: textstyles * chore: sizing
1 parent 8c7e2d3 commit d6cbbf3

File tree

4 files changed

+105
-133
lines changed

4 files changed

+105
-133
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:flowy_infra/size.dart';
21
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
32
import 'package:flowy_infra_ui/style_widget/text.dart';
43
import 'package:flutter/widgets.dart';
@@ -69,7 +68,7 @@ class _DateCellState extends GridCellState<GridDateCell> {
6968
controller: _popover,
7069
triggerActions: PopoverTriggerFlags.none,
7170
direction: PopoverDirection.bottomWithLeftAligned,
72-
constraints: BoxConstraints.loose(const Size(320, 520)),
71+
constraints: BoxConstraints.loose(const Size(260, 500)),
7372
margin: EdgeInsets.zero,
7473
child: SizedBox.expand(
7574
child: GestureDetector(
@@ -81,7 +80,7 @@ class _DateCellState extends GridCellState<GridDateCell> {
8180
padding: GridSize.cellContentInsets,
8281
child: FlowyText.medium(
8382
state.dateStr,
84-
fontSize: FontSizes.s14,
83+
overflow: TextOverflow.ellipsis,
8584
),
8685
),
8786
),

frontend/app_flowy/lib/plugins/grid/presentation/widgets/cell/date_cell/date_editor.dart

Lines changed: 86 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:easy_localization/easy_localization.dart';
99
import 'package:flowy_infra/color_extension.dart';
1010
import 'package:flowy_infra/image.dart';
1111
import 'package:flowy_infra/size.dart';
12-
import 'package:flowy_infra/text_style.dart';
1312
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
1413
import 'package:flowy_infra_ui/style_widget/button.dart';
1514
import 'package:flowy_infra_ui/style_widget/text.dart';
@@ -29,7 +28,6 @@ import '../../header/type_option/date.dart';
2928
final kToday = DateTime.now();
3029
final kFirstDay = DateTime(kToday.year, kToday.month - 3, kToday.day);
3130
final kLastDay = DateTime(kToday.year, kToday.month + 3, kToday.day);
32-
const kMargin = EdgeInsets.symmetric(horizontal: 6, vertical: 10);
3331

3432
class DateCellEditor extends StatefulWidget {
3533
final VoidCallback onDismissed;
@@ -116,25 +114,25 @@ class _CellCalendarWidgetState extends State<_CellCalendarWidget> {
116114
return BlocProvider.value(
117115
value: bloc,
118116
child: BlocBuilder<DateCalBloc, DateCalState>(
119-
buildWhen: (p, c) => false,
117+
buildWhen: (p, c) => p != c,
120118
builder: (context, state) {
121119
List<Widget> children = [
122120
_buildCalendar(context),
123-
_TimeTextField(
124-
bloc: context.read<DateCalBloc>(),
125-
popoverMutex: popoverMutex,
126-
),
127-
Divider(height: 1, color: Theme.of(context).dividerColor),
121+
if (state.dateTypeOptionPB.includeTime)
122+
_TimeTextField(
123+
bloc: context.read<DateCalBloc>(),
124+
popoverMutex: popoverMutex,
125+
),
126+
Divider(height: 1.0, color: Theme.of(context).dividerColor),
128127
const _IncludeTimeButton(),
128+
Divider(height: 1.0, color: Theme.of(context).dividerColor),
129129
_DateTypeOptionButton(popoverMutex: popoverMutex)
130130
];
131131

132132
return ListView.separated(
133133
shrinkWrap: true,
134134
controller: ScrollController(),
135-
separatorBuilder: (context, index) {
136-
return VSpace(GridSize.typeOptionSeparatorHeight);
137-
},
135+
separatorBuilder: (context, index) => VSpace(GridSize.cellVPadding),
138136
itemCount: children.length,
139137
itemBuilder: (BuildContext context, int index) {
140138
return children[index];
@@ -155,17 +153,23 @@ class _CellCalendarWidgetState extends State<_CellCalendarWidget> {
155153
Widget _buildCalendar(BuildContext context) {
156154
return BlocBuilder<DateCalBloc, DateCalState>(
157155
builder: (context, state) {
156+
final textStyle = Theme.of(context).textTheme.bodyMedium!;
157+
final boxDecoration = BoxDecoration(
158+
color: Theme.of(context).colorScheme.surface,
159+
shape: BoxShape.rectangle,
160+
borderRadius: Corners.s6Border,
161+
);
158162
return TableCalendar(
159163
firstDay: kFirstDay,
160164
lastDay: kLastDay,
161165
focusedDay: state.focusedDay,
162-
rowHeight: 40,
166+
rowHeight: GridSize.typeOptionItemHeight,
163167
calendarFormat: state.format,
164-
daysOfWeekHeight: 40,
168+
daysOfWeekHeight: GridSize.typeOptionItemHeight,
165169
headerStyle: HeaderStyle(
166170
formatButtonVisible: false,
167171
titleCentered: true,
168-
titleTextStyle: TextStyles.body1.size(FontSizes.s14),
172+
titleTextStyle: textStyle,
169173
leftChevronMargin: EdgeInsets.zero,
170174
leftChevronPadding: EdgeInsets.zero,
171175
leftChevronIcon: svgWidget("home/arrow_left"),
@@ -177,57 +181,25 @@ class _CellCalendarWidgetState extends State<_CellCalendarWidget> {
177181
daysOfWeekStyle: DaysOfWeekStyle(
178182
dowTextFormatter: (date, locale) =>
179183
DateFormat.E(locale).format(date).toUpperCase(),
180-
weekdayStyle: TextStyles.general(
181-
fontSize: 13,
182-
fontWeight: FontWeight.w400,
183-
color: Theme.of(context).hintColor,
184-
),
185-
weekendStyle: TextStyles.general(
186-
fontSize: 13,
187-
fontWeight: FontWeight.w400,
188-
color: Theme.of(context).hintColor,
189-
),
184+
weekdayStyle: AFThemeExtension.of(context).caption,
185+
weekendStyle: AFThemeExtension.of(context).caption,
190186
),
191187
calendarStyle: CalendarStyle(
192188
cellMargin: const EdgeInsets.all(3),
193-
defaultDecoration: BoxDecoration(
194-
color: Theme.of(context).colorScheme.surface,
195-
shape: BoxShape.rectangle,
196-
borderRadius: const BorderRadius.all(Radius.circular(6)),
197-
),
198-
selectedDecoration: BoxDecoration(
199-
color: Theme.of(context).colorScheme.primary,
200-
shape: BoxShape.rectangle,
201-
borderRadius: const BorderRadius.all(Radius.circular(6)),
202-
),
203-
todayDecoration: BoxDecoration(
204-
color: AFThemeExtension.of(context).lightGreyHover,
205-
shape: BoxShape.rectangle,
206-
borderRadius: const BorderRadius.all(Radius.circular(6)),
207-
),
208-
weekendDecoration: BoxDecoration(
209-
color: Theme.of(context).colorScheme.surface,
210-
shape: BoxShape.rectangle,
211-
borderRadius: const BorderRadius.all(Radius.circular(6)),
212-
),
213-
outsideDecoration: BoxDecoration(
214-
color: Theme.of(context).colorScheme.surface,
215-
shape: BoxShape.rectangle,
216-
borderRadius: const BorderRadius.all(Radius.circular(6)),
217-
),
218-
defaultTextStyle: TextStyles.body1.size(FontSizes.s14),
219-
weekendTextStyle: TextStyles.body1.size(FontSizes.s14),
220-
selectedTextStyle: TextStyles.general(
221-
fontSize: FontSizes.s14,
222-
color: Theme.of(context).colorScheme.surface,
223-
),
224-
todayTextStyle: TextStyles.general(
225-
fontSize: FontSizes.s14,
226-
),
227-
outsideTextStyle: TextStyles.general(
228-
fontSize: FontSizes.s14,
229-
color: Theme.of(context).disabledColor,
230-
),
189+
defaultDecoration: boxDecoration,
190+
selectedDecoration: boxDecoration.copyWith(
191+
color: Theme.of(context).colorScheme.primary),
192+
todayDecoration: boxDecoration.copyWith(
193+
color: AFThemeExtension.of(context).lightGreyHover),
194+
weekendDecoration: boxDecoration,
195+
outsideDecoration: boxDecoration,
196+
defaultTextStyle: textStyle,
197+
weekendTextStyle: textStyle,
198+
selectedTextStyle:
199+
textStyle.textColor(Theme.of(context).colorScheme.surface),
200+
todayTextStyle: textStyle,
201+
outsideTextStyle:
202+
textStyle.textColor(Theme.of(context).disabledColor),
231203
),
232204
selectedDayPredicate: (day) {
233205
return state.calData.fold(
@@ -263,20 +235,17 @@ class _IncludeTimeButton extends StatelessWidget {
263235
selector: (state) => state.dateTypeOptionPB.includeTime,
264236
builder: (context, includeTime) {
265237
return SizedBox(
266-
height: 50,
238+
height: GridSize.typeOptionItemHeight,
267239
child: Padding(
268-
padding: kMargin,
240+
padding: GridSize.typeOptionContentInsets,
269241
child: Row(
270242
children: [
271243
svgWidget(
272244
"grid/clock",
273245
color: Theme.of(context).colorScheme.onSurface,
274246
),
275247
const HSpace(4),
276-
FlowyText.medium(
277-
LocaleKeys.grid_field_includeTime.tr(),
278-
fontSize: FontSizes.s14,
279-
),
248+
FlowyText.medium(LocaleKeys.grid_field_includeTime.tr()),
280249
const Spacer(),
281250
Toggle(
282251
value: includeTime,
@@ -298,6 +267,7 @@ class _IncludeTimeButton extends StatelessWidget {
298267
class _TimeTextField extends StatefulWidget {
299268
final DateCalBloc bloc;
300269
final PopoverMutex popoverMutex;
270+
301271
const _TimeTextField({
302272
required this.bloc,
303273
required this.popoverMutex,
@@ -316,58 +286,51 @@ class _TimeTextFieldState extends State<_TimeTextField> {
316286
void initState() {
317287
_focusNode = FocusNode();
318288
_controller = TextEditingController(text: widget.bloc.state.time);
319-
if (widget.bloc.state.dateTypeOptionPB.includeTime) {
320-
_focusNode.addListener(() {
321-
if (mounted) {
322-
widget.bloc.add(DateCalEvent.setTime(_controller.text));
323-
}
324289

325-
if (_focusNode.hasFocus) {
326-
widget.popoverMutex.close();
327-
}
328-
});
290+
_focusNode.addListener(() {
291+
if (mounted) {
292+
widget.bloc.add(DateCalEvent.setTime(_controller.text));
293+
}
294+
});
295+
296+
_focusNode.addListener(() {
297+
if (_focusNode.hasFocus) {
298+
widget.popoverMutex.close();
299+
}
300+
});
301+
302+
widget.popoverMutex.listenOnPopoverChanged(() {
303+
if (_focusNode.hasFocus) {
304+
_focusNode.unfocus();
305+
}
306+
});
329307

330-
widget.popoverMutex.listenOnPopoverChanged(() {
331-
if (_focusNode.hasFocus) {
332-
_focusNode.unfocus();
333-
}
334-
});
335-
}
336308
super.initState();
337309
}
338310

339311
@override
340312
Widget build(BuildContext context) {
341-
return BlocConsumer<DateCalBloc, DateCalState>(
342-
listener: (context, state) {
343-
_controller.text = state.time ?? "";
344-
},
345-
listenWhen: (p, c) => p.time != c.time,
346-
builder: (context, state) {
347-
if (state.dateTypeOptionPB.includeTime) {
348-
return Padding(
349-
padding: kMargin,
350-
child: RoundedInputField(
351-
height: 40,
352-
focusNode: _focusNode,
353-
autoFocus: true,
354-
hintText: state.timeHintText,
355-
controller: _controller,
356-
style: TextStyles.body1.size(FontSizes.s14),
357-
normalBorderColor: Theme.of(context).colorScheme.outline,
358-
errorBorderColor: Theme.of(context).colorScheme.error,
359-
focusBorderColor: Theme.of(context).colorScheme.primary,
360-
cursorColor: Theme.of(context).colorScheme.primary,
361-
errorText: state.timeFormatError.fold(() => "", (error) => error),
362-
onEditingComplete: (value) {
363-
widget.bloc.add(DateCalEvent.setTime(value));
364-
},
365-
),
366-
);
367-
} else {
368-
return const SizedBox();
369-
}
370-
},
313+
_controller.text = widget.bloc.state.time ?? "";
314+
_controller.selection =
315+
TextSelection.collapsed(offset: _controller.text.length);
316+
return Padding(
317+
padding: GridSize.typeOptionContentInsets,
318+
child: RoundedInputField(
319+
height: GridSize.typeOptionItemHeight,
320+
focusNode: _focusNode,
321+
autoFocus: true,
322+
hintText: widget.bloc.state.timeHintText,
323+
controller: _controller,
324+
style: Theme.of(context).textTheme.bodyMedium!,
325+
normalBorderColor: Theme.of(context).colorScheme.outline,
326+
errorBorderColor: Theme.of(context).colorScheme.error,
327+
focusBorderColor: Theme.of(context).colorScheme.primary,
328+
cursorColor: Theme.of(context).colorScheme.primary,
329+
errorText:
330+
widget.bloc.state.timeFormatError.fold(() => "", (error) => error),
331+
onEditingComplete: (value) =>
332+
widget.bloc.add(DateCalEvent.setTime(value)),
333+
),
371334
);
372335
}
373336

@@ -397,12 +360,14 @@ class _DateTypeOptionButton extends StatelessWidget {
397360
triggerActions: PopoverTriggerFlags.hover | PopoverTriggerFlags.click,
398361
offset: const Offset(20, 0),
399362
constraints: BoxConstraints.loose(const Size(140, 100)),
400-
child: FlowyButton(
401-
text: FlowyText.medium(title, fontSize: 14),
402-
margin: kMargin,
403-
rightIcon: svgWidget(
404-
"grid/more",
405-
color: Theme.of(context).colorScheme.onSurface,
363+
child: SizedBox(
364+
height: GridSize.typeOptionItemHeight,
365+
child: FlowyButton(
366+
text: FlowyText.medium(title),
367+
rightIcon: svgWidget(
368+
"grid/more",
369+
color: Theme.of(context).colorScheme.onSurface,
370+
),
406371
),
407372
),
408373
popupBuilder: (BuildContext popContext) {
@@ -476,9 +441,8 @@ class _CalDateTimeSettingState extends State<_CalDateTimeSetting> {
476441
child: ListView.separated(
477442
shrinkWrap: true,
478443
controller: ScrollController(),
479-
separatorBuilder: (context, index) {
480-
return VSpace(GridSize.typeOptionSeparatorHeight);
481-
},
444+
separatorBuilder: (context, index) =>
445+
VSpace(GridSize.typeOptionSeparatorHeight),
482446
itemCount: children.length,
483447
itemBuilder: (BuildContext context, int index) {
484448
return children[index];

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,22 @@ class DateTypeOptionWidget extends TypeOptionWidget {
5353
listener: (context, state) =>
5454
typeOptionContext.typeOption = state.typeOption,
5555
builder: (context, state) {
56-
return Column(
57-
children: [
58-
const TypeOptionSeparator(),
59-
_renderDateFormatButton(context, state.typeOption.dateFormat),
60-
_renderTimeFormatButton(context, state.typeOption.timeFormat),
61-
const _IncludeTimeButton(),
62-
],
56+
final List<Widget> children = [
57+
const TypeOptionSeparator(),
58+
_renderDateFormatButton(context, state.typeOption.dateFormat),
59+
_renderTimeFormatButton(context, state.typeOption.timeFormat),
60+
const _IncludeTimeButton(),
61+
];
62+
63+
return ListView.separated(
64+
shrinkWrap: true,
65+
controller: ScrollController(),
66+
separatorBuilder: (context, index) =>
67+
VSpace(GridSize.typeOptionSeparatorHeight),
68+
itemCount: children.length,
69+
itemBuilder: (BuildContext context, int index) {
70+
return children[index];
71+
},
6372
);
6473
},
6574
),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class _RoundedInputFieldState extends State<RoundedInputField> {
118118
contentPadding: widget.contentPadding,
119119
hintText: widget.hintText,
120120
hintStyle:
121-
Theme.of(context).textTheme.bodyMedium!.textColor(borderColor),
121+
Theme.of(context).textTheme.bodySmall!.textColor(borderColor),
122122
enabledBorder: OutlineInputBorder(
123123
borderSide: BorderSide(
124124
color: borderColor,

0 commit comments

Comments
 (0)