Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Nov 29, 2024
1 parent 7bb3062 commit 06949f7
Show file tree
Hide file tree
Showing 4 changed files with 348 additions and 32 deletions.
189 changes: 189 additions & 0 deletions docs/pages/docs/overlay/modal-sheet.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import { Tabs } from 'nextra/components';
import { Widget } from "../../../components/widget.tsx";
import LinkBadge from "../../../components/link-badge/link-badge.tsx";
import LinkBadgeGroup from "../../../components/link-badge/link-badge-group.tsx";

# Modal Sheet

A modal sheet is an alternative to a menu or a dialog and prevents the user from interacting with the rest of the app.

<LinkBadgeGroup>
<LinkBadge label="API Reference" href="https://pub.dev/documentation/forui/latest/forui.widgets.sheet/forui.widgets.sheet-library.html"/>
</LinkBadgeGroup>

<Tabs items={['Preview', 'Code']}>
<Tabs.Tab>
<Widget name='modal-sheet' query={{}} height={500}/>
</Tabs.Tab>
<Tabs.Tab>
```dart
class ModalSheet extends StatelessWidget {
@override
Widget build(BuildContext context) => Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
FButton(
label: const Text('Left'),
onPress: () => showFModalSheet(
context: context,
side: Layout.ltr,
builder: (context) => const Form(side: Layout.ltr),
),
),
const SizedBox(height: 5),
FButton(
label: const Text('Top'),
onPress: () => showFModalSheet(
context: context,
side: Layout.ttb,
builder: (context) => const Form(side: Layout.ttb),
),
),
const SizedBox(height: 5),
FButton(
label: const Text('Right'),
onPress: () => showFModalSheet(
context: context,
side: Layout.rtl,
builder: (context) => const Form(side: Layout.btt),
),
),
const SizedBox(height: 5),
FButton(
label: const Text('Bottom'),
onPress: () => showFModalSheet(
context: context,
side: Layout.btt,
builder: (context) => const Form(side: Layout.btt),
),
),
],
);
}
class Form extends StatelessWidget {
final Layout side;
const Form({required this.side, super.key});
@override
Widget build(BuildContext context) => Container(
height: double.infinity,
width: double.infinity,
decoration: BoxDecoration(
color: context.theme.colorScheme.background,
border: side.vertical
? Border.symmetric(horizontal: BorderSide(color: context.theme.colorScheme.border))
: Border.symmetric(vertical: BorderSide(color: context.theme.colorScheme.border)),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8.0),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Account',
style: context.theme.typography.xl2.copyWith(
fontWeight: FontWeight.w600,
color: context.theme.colorScheme.foreground,
height: 1.5,
),
),
Text(
'Make changes to your account here. Click save when you are done.',
style: context.theme.typography.sm.copyWith(
color: context.theme.colorScheme.mutedForeground,
),
),
const SizedBox(height: 8),
SizedBox(
width: 450,
child: Column(
children: [
const FTextField(
label: Text('Name'),
hint: 'John Renalo',
),
const SizedBox(height: 10),
const FTextField(
label: Text('Email'),
hint: '[email protected]',
),
const SizedBox(height: 16),
FButton(
label: const Text('Save'),
onPress: () => Navigator.of(context).pop(),
),
],
),
),
],
),
),
),
);
}
```
</Tabs.Tab>
</Tabs>

## Usage

### `showFModalSheet(...)`

```dart
showFModalSheet(
context: context,
side: Layout.ltr,
useRootNavigator: true,
useSafeArea: false,
mainAxisMaxRatio: null,
constraints: const BoxConstraints(maxWidth: 450, maxHeight: 450),
barrierDismissible: true,
draggable: true,
builder: (context) => const Placeholder(),
);
```

## Examples

### With `DraggableScrollableSheet`

<Tabs items={['Preview', 'Code']}>
<Tabs.Tab>
<Widget name='modal-sheet' query={{}} height={400} variant='draggable'/>
</Tabs.Tab>
<Tabs.Tab>
```dart
FButton(
label: const Text('Click me'),
onPress: () => showFModalSheet(
context: context,
side: Layout.btt,
mainAxisMaxRatio: null,
builder: (context) => DraggableScrollableSheet(
expand: false,
builder: (context, controller) => ScrollConfiguration(
// This is required to enable dragging on desktop.
// See https://github.com/flutter/flutter/issues/101903 for more information.
behavior: ScrollConfiguration.of(context).copyWith(dragDevices: {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
PointerDeviceKind.trackpad,
}),
child: FTileGroup.builder(
count: 25,
controller: controller,
tileBuilder: (context, index) => FTile(title: Text('Tile $index')),
),
),
),
),
);
```
</Tabs.Tab>
</Tabs>

33 changes: 1 addition & 32 deletions forui/lib/src/widgets/sheet/sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,14 @@ class Sheet extends StatefulWidget {

static void _onClosing() {}

/// The animation controller that controls the bottom sheet's entrance and exit animations.
///
/// This widget will manipulate the position of this animation, it is not just a passive observer.
final AnimationController? controller;

/// The sheet's layout.
final Layout layout;

/// The sheet's style.
final FSheetStyle style;

/// The minimum and maximum size.
final Layout layout;
final BoxConstraints constraints;

/// True if the sheet can be dragged up and down/left and right, and dismissed by swiping in the opposite direction.
///
/// Defaults to true.
///
/// If this is true, the [controller] must not be null.
final bool draggable;

/// A builder for the sheet's contents.
final WidgetBuilder builder;

/// Called when the user begins dragging the bottom sheet vertically, if [draggable] is true.
///
/// Would typically be used to change the bottom sheet animation curve so that it tracks the user's finger accurately.
final GestureDragStartCallback? onDragStart;

/// Called when the user stops dragging the sheet, if [draggable] is true.
///
/// Would typically be used to reset the bottom sheet animation curve, so that it animates non-linearly. Called before
/// [onClosing] if the sheet is closing.
final void Function(DragEndDetails details, {required bool closing})? onDragEnd;

/// Called when the sheet begins to close.
///
/// A sheet might be prevented from closing (e.g., by user interaction) even after this callback is called. For this
/// reason, this callback might be call multiple times for a given sheet.
final VoidCallback onClosing;

const Sheet({
Expand Down
2 changes: 2 additions & 0 deletions samples/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class _AppRouter extends RootStackRouter {
AutoRoute(path: '/icon/image', page: ImageIconRoute.page),
AutoRoute(path: '/label/vertical', page: VerticalLabelRoute.page),
AutoRoute(path: '/label/horizontal', page: HorizontalLabelRoute.page),
AutoRoute(path: '/modal-sheet/default', page: ModalSheetRoute.page),
AutoRoute(path: '/modal-sheet/draggable', page: DraggableModalSheetRoute.page),
AutoRoute(path: '/popover/default', page: PopoverRoute.page),
AutoRoute(path: '/popover-menu/default', page: PopoverMenuRoute.page),
AutoRoute(path: '/portal/default', page: PortalRoute.page),
Expand Down
Loading

0 comments on commit 06949f7

Please sign in to comment.