Skip to content

Commit

Permalink
feat/time-picker (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
nank1ro authored Nov 27, 2024
1 parent c7c1d32 commit bf7028f
Show file tree
Hide file tree
Showing 22 changed files with 2,226 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 0.15.4
## 0.16.0

- **FEAT**: New `ShadTimePicker` and `ShadDatePickerFormField` components.
- **FIX**: `maxLength`, `maxLengthEnforcement` and `showCursor` not working on `ShadInput`
- **FIX**: `ShadCalendar` range day button text style when `disableSecondaryBorder` is `true`.
- **CHORE**: Set minimum Flutter version to `3.24.0`
- **CHORE**: Remove `trackColor` from `ShadSwitch` (thanks to @RaghavTheGreat)
- **FIX**: `ShadSlider` `onChanged` called on every controller update (thanks to @helightdev).

## 0.15.3

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ See the [documentation](https://flutter-shadcn-ui.mariuti.com/) to interact with
- [x] [Table](https://flutter-shadcn-ui.mariuti.com/components/table/)
- [x] [Tabs](https://flutter-shadcn-ui.mariuti.com/components/tabs/)
- [ ] TextArea
- [x] [Time Picker](https://flutter-shadcn-ui.mariuti.com/components/time-picker/)
- [x] [Toast](https://flutter-shadcn-ui.mariuti.com/components/toast/)
- [ ] Toggle
- [ ] ToggleGroup
Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/Components/form.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ See the following links for more examples on how to use the `ShadForm` component
- [Select](../select#form)
- [RadioGroup](../radio-group#form)
- [DatePicker](../date-picker#form)
- [TimePicker](../time-picker#form)
64 changes: 64 additions & 0 deletions docs/src/content/docs/Components/time-picker.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: Time Picker
sidebar:
order: 4
---

import Preview from "../../../components/Preview.astro";

A time picker component.

<Preview src="https://shadcn-ui-playground.pages.dev/time-picker?style=primary">

```dart
class PrimaryTimePicker extends StatelessWidget {
const PrimaryTimePicker({super.key});
@override
Widget build(BuildContext context) {
return ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600),
child: const ShadTimePicker(
trailing: Padding(
padding: EdgeInsets.only(left: 8, top: 14),
child: ShadImage.square(LucideIcons.clock4, size: 16),
),
),
);
}
}
```

</Preview>

## Form

<Preview src="https://shadcn-ui-playground.pages.dev/form?style=timePickerField" minHeight="400px">

```dart
ShadTimePickerFormField(
label: const Text('Pick a time'),
onChanged: print,
description:
const Text('The time of the day you want to pick'),
validator: (v) => v == null ? 'A time is required' : null,
)
```

</Preview>

## ShadTimePickerFormField.period

<Preview src="https://shadcn-ui-playground.pages.dev/form?style=periodTimePickerField" minHeight="400px">

```dart
ShadTimePickerFormField.period(
label: const Text('Pick a time'),
onChanged: print,
description:
const Text('The time of the day you want to pick'),
validator: (v) => v == null ? 'A time is required' : null,
),
```

</Preview>
4 changes: 4 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import 'package:example/pages/switch.dart';
import 'package:example/pages/switch_form_field.dart';
import 'package:example/pages/tabs.dart';
import 'package:example/pages/table.dart';
import 'package:example/pages/time_picker.dart';
import 'package:example/pages/time_picker_form_field.dart';
import 'package:example/pages/toast.dart';
import 'package:example/pages/tooltip.dart';
import 'package:example/pages/typography.dart';
Expand Down Expand Up @@ -72,6 +74,8 @@ final routes = <String, WidgetBuilder>{
'/switch-form-field': (_) => const SwitchFormFieldPage(),
'/table': (_) => const TablePage(),
'/tabs': (_) => const TabsPage(),
'/time-picker': (_) => const TimePickerPage(),
'/time-picker-form-field': (_) => const TimePickerFormFieldPage(),
'/toast': (_) => const ToastPage(),
'/tooltip': (_) => const TooltipPage(),
'/typography': (_) => const TypographyPage(),
Expand Down
37 changes: 37 additions & 0 deletions example/lib/pages/time_picker.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:example/common/base_scaffold.dart';
import 'package:flutter/material.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

class TimePickerPage extends StatelessWidget {
const TimePickerPage({super.key});

@override
Widget build(BuildContext context) {
return BaseScaffold(
appBarTitle: 'TimePicker',
children: [
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600),
child: ShadTimePicker(
trailing: const Padding(
padding: EdgeInsets.only(left: 8, top: 14),
child: ShadImage.square(LucideIcons.clock4, size: 16),
),
onChanged: (time) {
print('time: $time');
},
),
),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600),
child: ShadTimePicker.period(
crossAxisAlignment: WrapCrossAlignment.end,
onChanged: (time) {
print('time: $time');
},
),
),
],
);
}
}
101 changes: 101 additions & 0 deletions example/lib/pages/time_picker_form_field.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// ignore_for_file: avoid_print

import 'dart:convert';

import 'package:example/common/base_scaffold.dart';
import 'package:example/common/properties/bool_property.dart';
import 'package:example/common/properties/enum_property.dart';
import 'package:flutter/material.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

class TimePickerFormFieldPage extends StatefulWidget {
const TimePickerFormFieldPage({super.key});

@override
State<TimePickerFormFieldPage> createState() =>
_TimePickerFormFieldPageState();
}

class _TimePickerFormFieldPageState extends State<TimePickerFormFieldPage> {
bool enabled = true;
var autovalidateMode = ShadAutovalidateMode.alwaysAfterFirstValidation;
Map<Object, dynamic> formValue = {};
final formKey = GlobalKey<ShadFormState>();

@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
return ShadForm(
key: formKey,
enabled: enabled,
autovalidateMode: autovalidateMode,
child: BaseScaffold(
appBarTitle: 'TimePickerFormField',
editable: [
MyBoolProperty(
label: 'Enabled',
value: enabled,
onChanged: (value) => setState(() => enabled = value),
),
MyEnumProperty(
label: 'autovalidateMode',
value: autovalidateMode,
values: ShadAutovalidateMode.values,
onChanged: (value) {
if (value != null) {
setState(() => autovalidateMode = value);
}
},
),
],
children: [
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 350),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadTimePickerFormField(
id: 'time',
label: const Text('Pick a time'),
onChanged: print,
description:
const Text('The time of the day you want to pick'),
validator: (v) => v == null ? 'A time is required' : null,
),
const SizedBox(height: 16),
ShadButton(
child: const Text('Submit'),
onPressed: () {
print('submitted');
if (formKey.currentState!.saveAndValidate()) {
setState(() {
formValue = formKey.currentState!.value;
});
} else {
print('validation failed');
}
},
),
if (formValue.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 24, left: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('FormValue', style: theme.textTheme.p),
const SizedBox(height: 4),
SelectableText(
formValue.toString(),
style: theme.textTheme.small,
),
],
),
),
],
),
),
],
),
);
}
}
3 changes: 3 additions & 0 deletions lib/shadcn_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export 'src/components/form/fields/input.dart';
export 'src/components/form/fields/radio.dart';
export 'src/components/form/fields/select.dart';
export 'src/components/form/fields/switch.dart';
export 'src/components/form/fields/time_picker.dart';
export 'src/components/form/form.dart';
export 'src/components/image.dart';
export 'src/components/input.dart';
Expand All @@ -36,6 +37,7 @@ export 'src/components/slider.dart';
export 'src/components/switch.dart';
export 'src/components/table.dart';
export 'src/components/tabs.dart';
export 'src/components/time_picker.dart';
export 'src/components/toast.dart';
export 'src/components/tooltip.dart';

Expand Down Expand Up @@ -88,6 +90,7 @@ export 'src/theme/components/slider.dart';
export 'src/theme/components/switch.dart';
export 'src/theme/components/table.dart';
export 'src/theme/components/tabs.dart';
export 'src/theme/components/time_picker.dart';
export 'src/theme/components/toast.dart';
export 'src/theme/components/tooltip.dart';
export 'src/theme/text_theme/text_styles_default.dart';
Expand Down
Loading

0 comments on commit bf7028f

Please sign in to comment.