Skip to content

Commit

Permalink
feat: command menu added
Browse files Browse the repository at this point in the history
  • Loading branch information
vanlooverenkoen committed Oct 5, 2024
1 parent 1af7cf3 commit 7958f2e
Show file tree
Hide file tree
Showing 22 changed files with 597 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"android":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"macos":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"linux":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"windows":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"web":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","dependencies":[]}]},"dependencyGraph":[{"name":"rive_common","dependencies":[]}],"date_created":"2024-10-04 13:48:26.978666","version":"3.24.1","swift_package_manager_enabled":false}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"android":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"macos":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"linux":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"windows":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"web":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","dependencies":[]}]},"dependencyGraph":[{"name":"rive_common","dependencies":[]}],"date_created":"2024-10-04 15:51:00.531304","version":"3.24.1","swift_package_manager_enabled":false}
14 changes: 14 additions & 0 deletions example/lib/src/app.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:impaktfull_ui_2/impaktfull_ui.dart';
import 'package:impaktfull_ui_example/src/screen/home/home_screen.dart';
import 'package:impaktfull_ui_example/src/widget/theme/theme_button.dart';
Expand All @@ -21,6 +22,19 @@ class MyAppState extends State<MyApp> {
title: 'impaktfull ui',
impaktfullUiTheme: ThemeButton.activeTheme,
flavorBannerText: kDebugMode ? null : 'Prod',
builder: (context, app) => ImpaktfullUiCommandMenu(
shortcutActivator: const SingleActivator(
LogicalKeyboardKey.space,
meta: true,
control: true,
),
builder: (context, theme, controller) => CommandMenuWindow(
onCloseWindow: () => controller.hide(),
onInputChanged: (value) {},
hasBlurredBackground: true,
),
child: app,
),
// const is disabled here because it would not rebuild when the theme is set again.
// ignore: prefer_const_constructors
home: HomeScreen(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:impaktfull_ui_example/src/component_library/components/command_menu/command_menu_library_variant.dart';
import 'package:impaktfull_ui_example/src/component_library/config/component_library_inputs.dart';
import 'package:impaktfull_ui_example/src/component_library/config/component_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/inputs/component_library_boolean_input.dart';
import 'package:impaktfull_ui_example/src/component_library/inputs/component_library_string_input.dart';

class CommandMenuLibraryItem extends ComponentLibraryItem {
const CommandMenuLibraryItem();

@override
String get title => 'ImpaktfullUiCommandMenu';

@override
List<ComponentLibraryVariant> getComponentVariants() {
return [
const CommandMenuLibraryVariant(),
];
}
}

class CommandMenuLibraryInputs extends ComponentLibraryInputs {
final ComponentLibraryStringInput input =
ComponentLibraryStringInput('Search value');
final ComponentLibraryBoolInput blurBackground =
ComponentLibraryBoolInput('Blur background');
@override
List<ComponentLibraryInputItem> buildInputItems() => [
input,
blurBackground,
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:impaktfull_ui_2/impaktfull_ui.dart';
import 'package:impaktfull_ui_example/src/component_library/components/command_menu/command_menu_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/config/component_library_item.dart';

class CommandMenuLibraryVariant
extends ComponentLibraryVariant<CommandMenuLibraryPrimaryInputs> {
const CommandMenuLibraryVariant();

@override
String get title => 'Default';

@override
List<Widget> build(
BuildContext context, CommandMenuLibraryPrimaryInputs inputs) {
return [
ImpaktfullUiCommandMenu(
shortcutActivator: const SingleActivator(
LogicalKeyboardKey.keyK,
meta: true,
),
builder: (context, theme, controller) => CommandMenuWindow(
onCloseWindow: () => controller.hide(),
onInputChanged: (value) => inputs.input.updateState(value),
hasBlurredBackground: inputs.blurBackground.value ?? false,
padding: EdgeInsets.zero,
marginInputField: const EdgeInsetsDirectional.all(16),
bottomBuilder: (context) {
if (inputs.input.value == null || inputs.input.value!.isEmpty) {
return null;
}
return ImpaktfullUiListView.builder(
items: List.generate(100, (i) => '${inputs.input.value}: $i'),
itemBuilder: (context, item, index) => ImpaktfullUiListItem(
title: item,
onTap: () {
ImpaktfullUiNotification.show(title: 'On $item tapped');
controller.hide();
},
),
noDataLabel: 'No data found',
);
},
),
child: Focus(
autofocus: true,
child: Container(
color: theme.colors.accent,
width: double.infinity,
height: 500,
padding: const EdgeInsets.all(16),
alignment: Alignment.center,
child: Center(
child: ImpaktfullUiInputField(
value: '',
hint:
'If you are inside this input field, you can use the keyboard shortcut to open the command menu (cmd +k or win +)',
onChanged: (value) {},
),
),
),
),
),
];
}

@override
CommandMenuLibraryPrimaryInputs inputs() => CommandMenuLibraryPrimaryInputs();
}

class CommandMenuLibraryPrimaryInputs extends CommandMenuLibraryInputs {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:impaktfull_ui_example/src/component_library/config/component_library_inputs.dart';
import 'package:impaktfull_ui_example/src/component_library/config/component_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/inputs/component_library_boolean_input.dart';
import 'package:impaktfull_ui_example/src/component_library/inputs/component_library_icon_input.dart';
import 'package:impaktfull_ui_example/src/component_library/inputs/component_library_string_input.dart';
import 'package:impaktfull_ui_example/src/component_library/components/input_field/input_field_library_variant.dart';
Expand All @@ -26,12 +27,15 @@ class InputLibraryInputs extends ComponentLibraryInputs {
final ComponentLibraryStringInput hint = ComponentLibraryStringInput('Hint');
final ComponentLibraryStringInput value =
ComponentLibraryStringInput('Value');
final ComponentLibraryBoolInput showTrailingAction =
ComponentLibraryBoolInput('Show trailing action');

@override
List<ComponentLibraryInputItem> buildInputItems() => [
label,
leadingIcon,
hint,
value,
showTrailingAction,
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class InputFieldVariant
final hint = inputs.hint.value ?? '{hint}';
final value = inputs.value.value;
final leadingIcon = inputs.leadingIcon.value;
final showTrailingAction = inputs.showTrailingAction.value ?? false;
return [
ImpaktfullUiInputField(
leadingIcon:
Expand All @@ -25,13 +26,15 @@ class InputFieldVariant
hint: hint,
value: value,
onChanged: inputs.value.updateState,
trailingAction: ImpaktfullUiInputFieldAction(
label: 'Copy',
asset: theme.assets.icons.copy,
onTap: () => ImpaktfullUiNotification.show(
title: 'Copied to clipboard',
),
),
trailingAction: showTrailingAction
? ImpaktfullUiInputFieldAction(
label: 'Copy',
asset: theme.assets.icons.copy,
onTap: () => ImpaktfullUiNotification.show(
title: 'Copied to clipboard',
),
)
: null,
),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:impaktfull_ui_example/src/component_library/components/card/card
import 'package:impaktfull_ui_example/src/component_library/components/checkbox/checkbox_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/components/cms_header/cms_header_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/components/color_picker/color_picker_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/components/command_menu/command_menu_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/components/dropdown/dropdown_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/components/grid_view/grid_view_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/components/horizontal_tabs/horizontal_tabs_library_item.dart';
Expand Down Expand Up @@ -44,6 +45,7 @@ class ComponentLibrary {
const CardLibraryItem(),
const CmsHeaderLibraryItem(),
const ColorPickerLibraryItem(),
const CommandMenuLibraryItem(),
const DropdownLibraryItem(),
const GridViewLibraryItem(),
const HorizontalTabsLibraryItem(),
Expand Down
5 changes: 4 additions & 1 deletion example/lib/src/widget/components/component_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class ComponentCard extends StatelessWidget {
padding: const EdgeInsets.all(16),
alignment: Alignment.center,
child: IgnorePointer(
child: correctChild,
child: Focus(
descendantsAreFocusable: false,
child: correctChild,
),
),
),
),
Expand Down
2 changes: 2 additions & 0 deletions lib/impaktfull_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export 'src/components/card/card.dart';
export 'src/components/checkbox/checkbox.dart';
export 'src/components/cms_header/cms_header.dart';
export 'src/components/color_picker/color_picker.dart';
export 'src/components/command_menu/command_menu.dart';
export 'src/components/command_menu/command_menu_window.dart';
export 'src/components/divider/divider.dart';
export 'src/components/dropdown/dropdown.dart';
export 'src/components/grid_view/grid_view.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/card/card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ImpaktfullUiCard extends StatefulWidget with ComponentDescriptorMixin {
final VoidCallback? onTap;
final MouseCursor cursor;
final VoidCallback? onFocus;
final EdgeInsets? padding;
final EdgeInsetsGeometry? padding;
final BorderRadiusGeometry? borderRadius;
final ImpaktfullUiCardTheme? theme;

Expand Down
57 changes: 57 additions & 0 deletions lib/src/components/command_menu/command_menu.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'package:flutter/material.dart';
import 'package:impaktfull_ui_2/src/components/command_menu/command_menu_style.dart';
import 'package:impaktfull_ui_2/src/components/command_menu/commander/commander.dart';
import 'package:impaktfull_ui_2/src/components/theme/theme_component_builder.dart';
import 'package:impaktfull_ui_2/src/util/descriptor/component_descriptor_mixin.dart';

export 'command_menu_style.dart';

part 'command_menu.describe.dart';

class ImpaktfullUiCommandMenu extends StatefulWidget with ComponentDescriptorMixin {
final ShortcutActivator? shortcutActivator;
final Widget child;
final Widget Function(BuildContext context, ImpaktfullUiCommandMenuTheme theme, CommanderController controller)
builder;
final ImpaktfullUiCommandMenuTheme? theme;

const ImpaktfullUiCommandMenu({
required this.child,
required this.builder,
this.shortcutActivator,
this.theme,
super.key,
});

@override
State<ImpaktfullUiCommandMenu> createState() => _ImpaktfullUiCommandMenuState();

@override
String describe(BuildContext context) => _describeInstance(context, this);
}

class _ImpaktfullUiCommandMenuState extends State<ImpaktfullUiCommandMenu> {
final _commanderController = CommanderController();

@override
Widget build(BuildContext context) {
return ImpaktfullUiComponentThemeBuidler<ImpaktfullUiCommandMenuTheme>(
overrideComponentTheme: widget.theme,
builder: (context, theme, componentTheme) {
final shortcutActivator = widget.shortcutActivator;
if (widget.shortcutActivator == null) return widget.child;
return CommanderConfiguratorWidget(
commanderController: _commanderController,
shortcutActivator: shortcutActivator!,
builder: (context) => CallbackShortcuts(
bindings: <ShortcutActivator, VoidCallback>{
shortcutActivator: () => _commanderController.hide(),
},
child: widget.builder(context, componentTheme, _commanderController),
),
child: widget.child,
);
},
);
}
}
8 changes: 8 additions & 0 deletions lib/src/components/command_menu/command_menu.describe.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
part of 'command_menu.dart';

String _describeInstance(
BuildContext context, ImpaktfullUiCommandMenu instance) {
final descriptor = ComponentDescriptor();
descriptor.add('theme', instance.theme);
return descriptor.describe();
}
39 changes: 39 additions & 0 deletions lib/src/components/command_menu/command_menu_style.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:flutter/widgets.dart';
import 'package:impaktfull_ui_2/src/theme/theme.dart';

class ImpaktfullUiCommandMenuTheme extends ImpaktfullUiComponentTheme {
final ImpaktfullUiCommandMenuAssetsTheme assets;
final ImpaktfullUiCommandMenuColorTheme colors;
final ImpaktfullUiCommandMenuDimensTheme dimens;
final ImpaktfullUiCommandMenuTextStyleTheme textStyles;

const ImpaktfullUiCommandMenuTheme({
required this.assets,
required this.colors,
required this.dimens,
required this.textStyles,
});

static ImpaktfullUiCommandMenuTheme of(BuildContext context) =>
ImpaktfullUiTheme.of(context).components.commandMenu;
}

class ImpaktfullUiCommandMenuAssetsTheme {
const ImpaktfullUiCommandMenuAssetsTheme();
}

class ImpaktfullUiCommandMenuColorTheme {
const ImpaktfullUiCommandMenuColorTheme();
}

class ImpaktfullUiCommandMenuDimensTheme {
final BorderRadiusGeometry windowBorderRadius;

const ImpaktfullUiCommandMenuDimensTheme({
required this.windowBorderRadius,
});
}

class ImpaktfullUiCommandMenuTextStyleTheme {
const ImpaktfullUiCommandMenuTextStyleTheme();
}
Loading

0 comments on commit 7958f2e

Please sign in to comment.