Skip to content

Commit

Permalink
refactor!: rename context menu children into items
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Rename `children` parameter of `ShadContextMenu` and
`ShadContextMenuRegion` into `items`.
  • Loading branch information
nank1ro committed Oct 2, 2024
1 parent 3f72455 commit 49a69d8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.0

- __BREAKING CHANGE__: Rename `children` parameter of `ShadContextMenu` and `ShadContextMenuRegion` into `items`.

## 0.9.8

- Improve the `ShadContextMenu` right click behavior on Web.
Expand Down
8 changes: 4 additions & 4 deletions docs/src/content/docs/Components/context-menu.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ title: Context Menu
sidebar:
order: 4
---
import Preview from '../../../components/Preview.astro';

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

Displays a menu to the user — such as a set of actions or functions — triggered by a mouse right-click.

Expand Down Expand Up @@ -34,7 +35,7 @@ class ContextMenuPage extends StatelessWidget {
),
child: const Text('Right click here'),
),
children: [
items: [
const ShadContextMenuItem.inset(
child: Text('Back'),
),
Expand All @@ -51,7 +52,7 @@ class ContextMenuPage extends StatelessWidget {
LucideIcons.chevronRight,
size: 16,
),
children: [
items: [
ShadContextMenuItem(
child: Text('Save Page As...'),
),
Expand Down Expand Up @@ -105,4 +106,3 @@ class ContextMenuPage extends StatelessWidget {
```

</Preview>

12 changes: 6 additions & 6 deletions lib/src/components/context_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -388,18 +388,18 @@ class ShadContextMenuItemController extends ChangeNotifier {

final Key itemKey;

/// Maps the children key to the item controller
final Map<Key, ShadContextMenuItemController> children = {};
/// Maps the item key to the item controller
final Map<Key, ShadContextMenuItemController> items = {};

bool get selected =>
_hovered || _focused || children.values.any((e) => e.selected);
_hovered || _focused || items.values.any((e) => e.selected);

void registerSubItem(ShadContextMenuItemController controller) {
children[controller.itemKey] = controller;
items[controller.itemKey] = controller;
}

void unregisterSubItem(ShadContextMenuItemController controller) {
children.remove(controller.itemKey);
items.remove(controller.itemKey);
}
}

Expand Down Expand Up @@ -784,7 +784,7 @@ class _ShadContextMenuItemState extends State<ShadContextMenuItem> {
),
);

// if the item has at least one submenu item, wrap it in a provider to
// if the item has at least one submenu item, wrap it in a provider to
//provide the controller to the submenu items
if (widget.items.isNotEmpty) {
child = ShadProvider(
Expand Down
22 changes: 11 additions & 11 deletions playground/lib/pages/context_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ class ContextMenuPage extends StatelessWidget {
padding: const EdgeInsets.all(16),
child: ShadContextMenuRegion(
constraints: const BoxConstraints(minWidth: 300),
child: Container(
width: 300,
height: 200,
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(color: theme.colorScheme.border),
borderRadius: BorderRadius.circular(8),
),
child: const Text('Right click here'),
),
items: [
const ShadContextMenuItem.inset(
child: Text('Back'),
Expand All @@ -34,7 +24,6 @@ class ContextMenuPage extends StatelessWidget {
child: Text('Reload'),
),
const ShadContextMenuItem.inset(
child: Text('More Tools'),
trailing: ShadImage.square(
LucideIcons.chevronRight,
size: 16,
Expand All @@ -54,6 +43,7 @@ class ContextMenuPage extends StatelessWidget {
child: Text('Developer Tools'),
),
],
child: Text('More Tools'),
),
const Divider(height: 8),
const ShadContextMenuItem(
Expand Down Expand Up @@ -85,6 +75,16 @@ class ContextMenuPage extends StatelessWidget {
),
const ShadContextMenuItem.inset(child: Text('Colm Tuite')),
],
child: Container(
width: 300,
height: 200,
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(color: theme.colorScheme.border),
borderRadius: BorderRadius.circular(8),
),
child: const Text('Right click here'),
),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: shadcn_ui
description: shadcn-ui ported in Flutter. Awesome UI components for Flutter, fully customizable.
version: 0.9.8
version: 0.10.0
homepage: https://mariuti.com/shadcn-ui
repository: https://github.com/nank1ro/flutter-shadcn-ui
documentation: https://mariuti.com/shadcn-ui
Expand Down

0 comments on commit 49a69d8

Please sign in to comment.