Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize MenuItems Widgets #243

Merged
merged 6 commits into from
May 17, 2024
Merged

Normalize MenuItems Widgets #243

merged 6 commits into from
May 17, 2024

Conversation

edgarfgp
Copy link
Member

@edgarfgp edgarfgp commented May 13, 2024

This PR uses the newly added AttributeBundle to CollectionBuilder. See fabulous-dev/Fabulous#1081

This will allow us to have more advance and useful widget constructors. in the case MenuItem and MenuItems

    /// <summary>Creates a MenuItem widget.</summary>
    /// <param name="header">The header of the menu item.</param>
    static member MenuItem(header: string) =
        WidgetBuilder<'msg, IFabMenuItem>(MenuItem.WidgetKey, HeaderedContentControl.HeaderString.WithValue(header))

    /// <summary>Creates a MenuItem widget.</summary>
    /// <param name="header">The header of the menu item.</param>
    /// <param name="onClick">Raised when the menu item is clicked.</param>
    static member MenuItem(header: string, onClick: 'msg) =
        WidgetBuilder<'msg, IFabMenuItem>(
            MenuItem.WidgetKey,
            HeaderedContentControl.HeaderString.WithValue(header),
            MenuItem.Clicked.WithValue(fun _ -> box onClick)
        )

    /// <summary>Creates a MenuItem widget.</summary>
    /// <param name="header">The header of the menu item.</param>
    static member MenuItem(header: WidgetBuilder<'msg, #IFabControl>) =
        WidgetBuilder<'msg, IFabMenuItem>(
            MenuItem.WidgetKey,
            AttributesBundle(StackList.empty(), ValueSome [| HeaderedContentControl.HeaderWidget.WithValue(header.Compile()) |], ValueNone)
        )

    /// <summary>Creates a MenuItem widget.</summary>
    /// <param name="header">The header of the menu item.</param>
    /// <param name="onClick">Raised when the menu item is clicked.</param>
    static member MenuItem(header: WidgetBuilder<'msg, #IFabControl>, onClick: 'msg) =
        WidgetBuilder<'msg, IFabMenuItem>(
            MenuItem.WidgetKey,
            AttributesBundle(
                StackList.one(MenuItem.Clicked.WithValue(fun _ -> box onClick)),
                ValueSome [| HeaderedContentControl.HeaderWidget.WithValue(header.Compile()) |],
                ValueNone
            )
        )

    /// <summary>Creates a MenuItems widget.</summary>
    static member MenuItems() =
        CollectionBuilder<'msg, IFabMenuItem, IFabMenuItem>(MenuItem.WidgetKey, ItemsControl.Items)

    /// <summary>Creates a MenuItems widget.</summary>
    static member MenuItems(header: WidgetBuilder<'msg, #IFabControl>) =
        CollectionBuilder<'msg, IFabMenuItem, IFabMenuItem>(
            MenuItem.WidgetKey,
            ItemsControl.Items,
            AttributesBundle(StackList.empty(), ValueSome [| HeaderedContentControl.HeaderWidget.WithValue(header.Compile()) |], ValueNone)
        )

    /// <summary>Creates a MenuItems widget.</summary>
    /// <param name="header">The header of the menu item.</param>
    /// <param name="onClick">Raised when the menu item is clicked.</param>
    static member MenuItems(header: WidgetBuilder<'msg, #IFabControl>, onClick: 'msg) =
        CollectionBuilder<'msg, IFabMenuItem, IFabMenuItem>(
            MenuItem.WidgetKey,
            ItemsControl.Items,
            AttributesBundle(
                StackList.one(MenuItem.Clicked.WithValue(fun _ -> box onClick)),
                ValueSome [| HeaderedContentControl.HeaderWidget.WithValue(header.Compile()) |],
                ValueNone
            )
        )

    /// <summary>Creates a MenuItems widget.</summary>
    /// <param name="header">The header of the menu item.</param>
    static member MenuItems(header: string) =
        CollectionBuilder<'msg, IFabMenuItem, IFabMenuItem>(
            MenuItem.WidgetKey,
            ItemsControl.Items,
            AttributesBundle(StackList.one(HeaderedContentControl.HeaderString.WithValue(header)), ValueNone, ValueNone)
        )

    /// <summary>Creates a MenuItems widget.</summary>
    /// <param name="header">The header of the menu item.</param>
    /// <param name="onClick">Raised when the menu item is clicked.</param>
    static member MenuItems(header: string, onClick: 'msg) =
        CollectionBuilder<'msg, IFabMenuItem, IFabMenuItem>(
            MenuItem.WidgetKey,
            ItemsControl.Items,
            AttributesBundle(
                StackList.two(MenuItem.Clicked.WithValue(fun _ -> box onClick), HeaderedContentControl.HeaderString.WithValue(header)),
                ValueNone,
                ValueNone
            )
        )

    /// <summary>Creates a MenuItems widget.</summary>
    /// <param name="onClick">Raised when the menu item is clicked.</param>
    static member inline MenuItems(onClick: 'msg) =
        CollectionBuilder<'msg, IFabMenuItem, IFabMenuItem>(MenuItem.WidgetKey, ItemsControl.Items, MenuItem.Clicked.WithValue(fun _ -> box onClick))

@edgarfgp edgarfgp force-pushed the normalize-menu-items-widgets branch from d220832 to f62d693 Compare May 17, 2024 07:35
@edgarfgp edgarfgp marked this pull request as ready for review May 17, 2024 07:46
@edgarfgp edgarfgp merged commit 86472bb into main May 17, 2024
1 check passed
@edgarfgp edgarfgp deleted the normalize-menu-items-widgets branch May 17, 2024 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant