Horizon UI Tailwind CSS React

repository·main·Indexed 19 days ago

https://github.com/horizon-ui/horizon-tailwind-react

An open-source admin dashboard template for Tailwind CSS and React (version 2.0.0). It includes pre-designed elements, blocks, and pages such as NFT, Authentication, and Profile pages. The library provides a comprehensive set of styled components including Card, BarChart, Checkbox, Dropdown, Navbar, PopoverHorizon, Progress, Radio, Sidebar, Switch, and TooltipHorizon.

Tokens
10.6K
Snippets
41
Records
45
Agent score
65%

What's inside horizon-ui-tailwind-react

  1. Quick Start with Horizon UI TailwindCSS React

    main

    To set up a local development environment with Horizon UI, ensure you have the NodeJS LTS version installed. Follow these steps to clone the repository, install dependencies, and launch the local development server.

    1. Clone the repository
    2. Install dependencies using npm
    3. Start the local server
    git clone https://github.com/horizon-ui/horizon-tailwind-react.git
    npm install
    npm start
  2. Configure routes for the Admin layout

    main

    To ensure a route is rendered within the Admin layout, the route object in your routes.js file must have its layout property set to '/admin'.

    The Admin component uses the following properties from your route objects:

    • layout: Must be '/admin' to be included in the <Routes> block.
    • path: The URL path segment.
    • component: The React element to render for that route.
    • name: The string used to update the brandText in the Navbar.
    • secondary: A value used to determine the secondary prop passed to the Navbar.
    // Example of a route object compatible with the Admin layout
    const routes = [
      {
        layout: "/admin",
        path: "default",
        name: "Main Dashboard",
        component: <DefaultDashboard />,
        secondary: true,
      },
      {
        layout: "/admin",
        path: "profile",
        name: "User Profile",
        component: <UserProfile />,
        secondary: false,
      }
    ];
  3. Configure routes for the Auth layout

    main

    The Auth layout uses a filtering mechanism to determine which routes to render. For a route to be included within the Auth layout's <Routes> block, its configuration object must have the layout property set to "/auth".

    Example route configuration structure:

    { 
      path: 'sign-in', 
      component: <SignInPage />, 
      layout: '/auth' 
    }
  4. Configure Prettier with Tailwind CSS plugin

    main

    To ensure Tailwind CSS classes are automatically sorted and formatted according to best practices, configure Prettier to use the prettier-plugin-tailwindcss plugin. This is done by creating a prettier.config.js or .prettierrc.js file in the project root and adding the plugin to the plugins array.

    module.exports = {
      plugins: [require("prettier-plugin-tailwindcss")],
    };
  5. Use the SidebarLinks component for RTL navigation

    main

    The SidebarLinks component is used to render a list of navigation links within a sidebar, specifically optimized for RTL (Right-to-Left) layouts. It accepts a routes prop, which is an array of route objects.

    Each route object in the array must follow this structure:

    • layout: A string representing the base layout path (e.g., '/admin', '/auth', or '/rtl'). The component only renders links where the layout matches one of these three values.
    • path: The specific path segment for the route.
    • name: The display name for the link.
    • icon: (Optional) A React component to be used as the link icon. If omitted, it defaults to DashIcon.

    The component automatically detects the active route using react-router-dom's useLocation and applies active styling (bold text and a colored indicator bar) to the matching link.

    import { SidebarLinks } from "components/sidebar/componentsrtl/Links";
    
    const myRoutes = [
      {
        layout: "/rtl",
        path: "dashboard",
        name: "Dashboard",
        icon: <MyCustomIcon />
      },
      {
        layout: "/rtl",
        path: "profile",
        name: "Profile"
        // icon defaults to DashIcon if not provided
      }
    ];
    
    function MySidebar() {
      return <SidebarLinks routes={myRoutes} />;
    }
  6. Configure Progress component props

    main

    The Progress component accepts the following props:

    PropTypeDescription
    valuenumberThe percentage of the progress bar to fill (e.g., 50 for 50%). This is applied via inline style width: ${value}%.
    colorstringThe color theme for the progress bar. Supported values: red, blue, green, yellow, orange, teal, navy, lime, cyan, pink, purple, amber, indigo, gray. If no valid color is provided, it defaults to brand.
    widthstringA Tailwind CSS width class to control the total width of the progress bar container. Defaults to w-full.
  7. Use the Dropdown component

    main

    The Dropdown component is a wrapper used to create selection menus. It manages its own open/closed state and includes built-in logic to close the menu when a user clicks outside of the component's container.

    It requires a button prop (the trigger element) and children (the menu content). You can also pass classNames for custom styling of the dropdown menu and an animation string to override the default transition behavior.

    import Dropdown from "@horizon-ui/components/Dropdown";
    
    <Dropdown
      button={<button>Click Me</button>}
      classNames="bg-white shadow-lg p-4"
      animation="transition-opacity duration-200"
    >
      <ul>
        <li>Option 1</li>
        <li>Option 2</li>
      </ul>
    </Dropdown>
  8. Use the NftCard component

    main

    The NftCard component is used to display individual NFT items. It accepts the following props:

    • bidders: An array of image URLs representing the avatars of recent bidders.
    • title: The name/title of the NFT.
    • author: The name of the creator/author.
    • price: The price of the NFT as a string.
    • image: The main image URL for the NFT.
    <NftCard
      bidders={[avatar1, avatar2, avatar3]}
      title="Abstract Colors"
      author="Esthera Jackson"
      price="0.91"
      image={NFt3}
    />
  9. Configure the TopCreatorTable component

    main

    The TopCreatorTable component (imported as TopCreatorTable within the Marketplace view) is used to display a list of top creators. It requires two primary props:

    • tableData: An array of objects containing the creator data (sourced from views/admin/marketplace/variables/tableDataTopCreators.json).
    • columnsData: An object or array defining the table columns (sourced from views/admin/marketplace/variables/tableColumnsTopCreators).
    • extra: A string for additional CSS classes (e.g., "mb-5").
    import TopCreatorTable from "./components/TableTopCreators";
    import tableDataTopCreators from "views/admin/marketplace/variables/tableDataTopCreators.json";
    import { tableColumnsTopCreators } from "views/admin/marketplace/variables/tableColumnsTopCreators";
    
    <TopCreatorTable
      extra="mb-5"
      tableData={tableDataTopCreators}
      columnsData={tableColumnsTopCreators}
    />
  10. Use the Dashboard component for RTL admin views

    main

    The Dashboard component serves as the default entry point for the Right-to-Left (RTL) version of the admin dashboard. It orchestrates several specialized components to create a comprehensive overview, including summary widgets, charts, tables, and task management tools.

    Key sub-components used in this view include:

    • Widget: Displays summary metrics with an icon, title, and subtitle.
    • TotalSpent & WeeklyRevenue: Data visualization components for financial tracking.
    • CheckTable: A simplified data table component.
    • ComplexTable: A more detailed data table component.
    • DailyTraffic & PieChartCard: Visual representations of traffic and distribution data.
    • TaskCard & MiniCalendar: Task management and scheduling components.
    import Dashboard from "src/views/rtl/default";
    
    // Usage within an RTL layout
    const App = () => {
      return <Dashboard />;
    };
  11. Use the Navbar component

    main

    The Navbar component provides a sticky top navigation bar for the application. It includes a search input, notification dropdowns, dark mode toggling, and a profile dropdown.

    To use it, you must provide the onOpenSidenav function (to handle mobile menu visibility) and the brandText string (to display the application name/breadcrumb).

    import Navbar from "components/navbar";
    
    // Inside your layout or page component
    <Navbar 
      onOpenSidenav={() => console.log("Open Sidenav")}
      brandText="My Dashboard"
    />
  12. Use the RTL layout component

    main

    The RTL component is a layout wrapper designed for Right-to-Left (RTL) language support. It automatically sets the document direction to rtl (document.documentElement.dir = 'rtl') and renders a layout containing an RTL-specific Sidebar, Navbar, and Footer.

    It manages responsive sidebar visibility based on window width (closing the sidebar when width is below 1200px) and dynamically determines the active route name and secondary navbar visibility based on the provided routes configuration.

    To use it, import the component and wrap your application routes. It accepts standard React props which are passed down to the Navbar component via {...rest}.

    import RTL from "src/layouts/rtl";
    
    // Usage within your router setup
    function App() {
      return (
        <RTL>
          {/* Your application content or additional providers */}
        </RTL>
      );
    }