Search results

Add Toggle Button

Toolbar supports to add a toggle Button by using the Template property. Refer below steps

  • By using Toolbar template property, pass required HTML String to render toggle button.
    <Template>
        <EjsButton></EjsButton>
    </Template>
  • Now render the toggle Button into the targeted element in Toolbar created event handler and bind click event for it. On clicking the toggle Button, change the required icon and content based on current active state.
@using Syncfusion.EJ2.Blazor.Navigations
@using Syncfusion.EJ2.Blazor.Buttons

<EjsToolbar>
    <ToolbarItems>
        <ToolbarItem>
            <Template>
                <div><EjsButton @ref="MediaButton" CssClass="e-flat" IconCss="@MediaIconCss" IsToggle="true" @onclick="@OnMediaClick"></EjsButton></div>
            </Template>
        </ToolbarItem>
        <ToolbarItem Type="@ItemType.Separator"></ToolbarItem>
        <ToolbarItem>
            <Template>
                <div><EjsButton @ref="ZoomButton" CssClass="e-flat" IconCss="@ZoomIconCss" IsToggle="true" @onclick="@OnZoomClick"></EjsButton></div>
            </Template>
        </ToolbarItem>
        <ToolbarItem Type="@ItemType.Separator"></ToolbarItem>
        <ToolbarItem>
            <Template>
                <div><EjsButton @ref="UndoButton" CssClass="e-flat" IconCss="@UndoIconCss" IsToggle="true" @onclick="@OnUndoClick"></EjsButton></div>
            </Template>
        </ToolbarItem>
        <ToolbarItem Type="@ItemType.Separator"></ToolbarItem>
        <ToolbarItem>
            <Template>
                <div><EjsButton @ref="FilterButton" CssClass="e-flat" IconCss="@FilterIconCss" IsToggle="true" @onclick="@OnFilterClick"></EjsButton></div>
            </Template>
        </ToolbarItem>
        <ToolbarItem Type="@ItemType.Separator"></ToolbarItem>
        <ToolbarItem>
            <Template>
                <div><EjsButton @ref="VisibleButton" CssClass="e-flat" IconCss="@VisibleIconCss" IsToggle="true" Content="@Content" @onclick="@OnVisibleClick"></EjsButton></div>
            </Template>
        </ToolbarItem>
    </ToolbarItems>
</EjsToolbar>
<br />
<div id="content" style="display:@DisplayValue">
    This content will be hidden, when you click on hide button and toggle get an active state as show, otherwise it will be visible.
</div>

<style>
    @@font-face {
        font-family: 'Toolbar';
        src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EAAAAAAAEABwABAAEAAAAAAAIABwAIAAEAAAAAAAMABwAPAAEAAAAAAAQABwAWAAEAAAAAAAUACwAdAAEAAAAAAAYABwAoAAEAAAAAAAoALAAvAAEAAAAAAAsAEgBbAAMAAQQJAAAAAgBtAAMAAQQJAAEADgBvAAMAAQQJAAIADgB9AAMAAQQJAAMADgCLAAMAAQQJAAQADgCZAAMAAQQJAAUAFgCnAAMAAQQJAAYADgC9AAMAAQQJAAoAWADLAAMAAQQJAAsAJAEjIHRvb2xiYXJSZWd1bGFydG9vbGJhcnRvb2xiYXJWZXJzaW9uIDEuMHRvb2xiYXJGb250IGdlbmVyYXRlZCB1c2luZyBTeW5jZnVzaW9uIE1ldHJvIFN0dWRpb3d3dy5zeW5jZnVzaW9uLmNvbQAgAHQAbwBvAGwAYgBhAHIAUgBlAGcAdQBsAGEAcgB0AG8AbwBsAGIAYQByAHQAbwBvAGwAYgBhAHIAVgBlAHIAcwBpAG8AbgAgADEALgAwAHQAbwBvAGwAYgBhAHIARgBvAG4AdAAgAGcAZQBuAGUAcgBhAHQAZQBkACAAdQBzAGkAbgBnACAAUwB5AG4AYwBmAHUAcwBpAG8AbgAgAE0AZQB0AHIAbwAgAFMAdAB1AGQAaQBvAHcAdwB3AC4AcwB5AG4AYwBmAHUAcwBpAG8AbgAuAGMAbwBtAAAAAAIAAAAAAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwECAQMBBAEFAQYBBwEIAQkBCgELAQwACnNob3ctMDEtd2YIaGlkZTEtd2YHem9vbS1pbgh6b29tLW91dAptZWRpYS1wbGF5C21lZGlhLXBhdXNlBHVuZG8EcmVkbwtmaWx0ZXItbm9uZQZmaWx0ZXIAAA==) format('truetype');
        font-weight: normal;
        font-style: normal;
    }

    .e-toolbar .e-btn .e-icons {
        font-family: 'Toolbar' !important;
        font-size: 16px;
        font-style: normal;
        font-weight: normal;
        font-variant: normal;
        text-transform: none;
    }

    .e-hide-icon::before {
        content: '\a701';
    }

    .e-show-icon::before {
        content: '\a700';
    }

    .e-filter-icon::before {
        content: '\a709';
    }

    .e-filternone-icon::before {
        content: '\a708';
    }

    .e-undo-icon::before {
        content: '\a706';
    }

    .e-redo-icon::before {
        content: '\a707';
    }

    .e-play-icon::before {
        content: '\a704';
    }

    .e-pause-icon::before {
        content: '\a705';
    }

    .e-zoomin-icon::before {
        content: '\a702';
    }

    .e-zoomout-icon::before {
        content: '\a703';
    }
</style>

@code{

    EjsButton MediaButton;
    EjsButton ZoomButton;
    EjsButton UndoButton;
    EjsButton FilterButton;
    EjsButton VisibleButton;
    public string Content = "Hide";
    public string DisplayValue { get; set; } = "block";
    public string MediaIconCss = "e-icons e-play-icon";
    public string ZoomIconCss = "e-icons e-zoomin-icon";
    public string UndoIconCss = "e-icons e-undo-icon";
    public string FilterIconCss = "e-icons e-filter-icon";
    public string VisibleIconCss = "e-icons e-hide-icon";
    public void OnMediaClick(MouseEventArgs args)
    {
        if (this.MediaButton.IconCss == "e-icons e-play-icon")
        {
            this.MediaIconCss = "e-icons e-pause-icon";
        }
        else
        {
            this.MediaIconCss = "e-icons e-play-icon";
        }
    }

    public void OnZoomClick(MouseEventArgs args)
    {
        if (this.ZoomButton.IconCss == "e-icons e-zoomin-icon")
        {
            this.ZoomIconCss = "e-icons e-zoomout-icon";
        }
        else
        {
            this.ZoomIconCss = "e-icons e-zoomin-icon";
        }
    }

    public void OnUndoClick(MouseEventArgs args)
    {
        if (this.UndoButton.IconCss == "e-icons e-undo-icon")
        {
            this.UndoIconCss = "e-icons e-redo-icon";
        }
        else
        {
            this.UndoIconCss = "e-icons e-undo-icon";
        }
    }

    public void OnFilterClick(MouseEventArgs args)
    {
        if (this.FilterButton.IconCss == "e-icons e-filter-icon")
        {
            this.FilterIconCss = "e-icons e-filternone-icon";
        }
        else
        {
            this.FilterIconCss = "e-icons e-filter-icon";
        }
    }

    public void OnVisibleClick(MouseEventArgs args)
    {
        if (this.VisibleButton.Content == "Hide")
        {
            this.DisplayValue = "none";
            this.Content = "Show";
            this.VisibleIconCss = "e-icons e-show-icon";
        }
        else
        {
            this.DisplayValue = "block";
            this.Content = "Hide";
            this.VisibleIconCss = "e-icons e-hide-icon";
        }
    }
}