-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
2,226 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}, | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.