Giter Site home page Giter Site logo

nice try about tailwind-blazor-starter HOT 2 OPEN

themesberg avatar themesberg commented on May 27, 2024
nice try

from tailwind-blazor-starter.

Comments (2)

chrisoChen avatar chrisoChen commented on May 27, 2024 5

I looked into this because I'm considering using Flowbite for a Blazor/Tailwind project I'm working on and I got it to fix by doing this:

(Ensure npm/tailwind is downloaded and already set up)

  1. Use libman instead of npm to add Flowbite to your wwwroot folder. I used cdnjs as the provider

Screenshot 2023-12-10 121335
Screenshot 2023-12-10 121453

  1. Update _Host.cshtml to use the flowbite.min.js file we just added in wwwroot
@page "/"
@using Microsoft.AspNetCore.Components.Web
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@namespace BlazorApp.Pages

<!DOCTYPE html>
<html lang="en">
    ...
    <script src="~/flowbite/flowbite.min.js"></script>
</html>
  1. Update tailwind.config.js to add the new javascript file to the content module:
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    // other files...
    "./wwwroot/**/*.js"
  ],
...
}
  1. Update Index.razor to do the following:
  • Inject and use the IJSRuntime to invoke the flowbite function initModals to initialize the modal.
  • Include a missing attribute data-modal-target to the button that opens the modal. The value should be the id of the modal you want to open.
@page "/"
@inject IJSRuntime JSRuntime;

<!-- Modal toggle -->
<div class="flex justify-center m-5">
    <button id="defaultModalButton" data-modal-toggle="defaultModal" data-modal-target="defaultModal" class="block text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" type="button">
    Show modal
    </button>
</div>

<!-- Main modal -->
...

@code {
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);
        await JSRuntime.InvokeVoidAsync("initModals");
    }
}

The result looks like this on my end:

template-modal

Also make sure to run the npx tailwind command to recreate your css file again

from tailwind-blazor-starter.

duynguyen224 avatar duynguyen224 commented on May 27, 2024

Thank for your example. I implement and it work as expected with modal, dropdown, ...
But seem like the datepicker component doesn't work. I'm trying to figure out the issue.
Could you please try to implement it?

from tailwind-blazor-starter.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.