Skip to content

Commit

Permalink
Create pages
Browse files Browse the repository at this point in the history
  • Loading branch information
naofumi committed Sep 2, 2024
1 parent 921e929 commit 255d045
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/controllers/components_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ComponentsController < ApplicationController
@@available_templates = %w[toggle select tabs]
@@available_templates = %w[toggle select tabs navigation]
def index
@available_templates = @@available_templates
end
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/breadcrumbs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module BreadcrumbsHelper
# set_breadcrumbs [[name1, url1], [name2, url2], ...]
def set_breadcrumbs(breadcrumbs_array)
content_for(:breadcrumbs) do
render "breadcrumbs", breadcrumbs: breadcrumbs_array
end
end
end
3 changes: 3 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { application } from "./application"
import HelloController from "./hello_controller"
application.register("hello", HelloController)

import NavbarController from "./navbar_controller"
application.register("navbar", NavbarController)

import SelectMenuController from "./select_menu_controller"
application.register("select-menu", SelectMenuController)

Expand Down
7 changes: 7 additions & 0 deletions app/javascript/controllers/navbar_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Controller } from "@hotwired/stimulus"

// Connects to data-controller="navbar"
export default class extends Controller {
connect() {
}
}
27 changes: 27 additions & 0 deletions app/views/application/_breadcrumbs.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%# locals: (breadcrumbs: []) %>
<nav class="flex" aria-label="Breadcrumb">
<ol role="list" class="flex items-center space-x-4">
<li>
<div>
<a href="<%= root_path %>" class="text-gray-400 hover:text-gray-500">
<svg class="h-5 w-5 flex-shrink-0" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M9.293 2.293a1 1 0 011.414 0l7 7A1 1 0 0117 11h-1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-3a1 1 0 00-1-1H9a1 1 0 00-1 1v3a1 1 0 01-1 1H5a1 1 0 01-1-1v-6H3a1 1 0 01-.707-1.707l7-7z" clip-rule="evenodd" />
</svg>
<span class="sr-only">Home</span>
</a>
</div>
</li>
<% breadcrumbs.each do |name, url| %>
<li>
<div class="flex items-center">
<svg class="h-5 w-5 flex-shrink-0 text-gray-300" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
<path d="M5.555 17.776l8-16 .894.448-8 16-.894-.448z" />
</svg>
<%= link_to_unless_current name, url, class: "ml-4 text-sm font-medium text-gray-500 hover:text-gray-700" do %>
<span class="ml-4 text-sm font-medium text-gray-500"><%= name %></span>
<% end %>
</div>
</li>
<% end %>
</ol>
</nav>
4 changes: 3 additions & 1 deletion app/views/components/_template.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<%# locals:(title:, description:) %>

<% content_for(:title, "#{title} | Tailwind, ERB & Stimulus") %>

<div class="container mx-auto px-4 my-6 sm:px-6 lg:px-8">
<div class="divide-y divide-gray-200 overflow-hidden rounded-lg bg-white shadow">
<div class="px-4 py-5 sm:px-6">
Expand All @@ -10,7 +12,7 @@
<%= description %>
</p>
</div>
<div class="px-4 py-5 sm:p-6 text-center">
<div class="px-4 py-5 sm:p-6 text-center h-96">
<%= yield %>
</div>
</div>
Expand Down
24 changes: 18 additions & 6 deletions app/views/components/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<% @available_templates.each do |template| %>
<div>
<%= link_to template, component_path(template),
class: "text-indigo-600 underline"%>
</div>
<% end %>
<h1 class="text-5xl font-extralight text-center">Tailwind Components with ERB and Stimulus</h1>

<p class="text-lg leading-6 mt-12">
This site provides examples of Tailwind widgets using Simulus for animation and responsiveness.
</p>

<div class="flex flex-row space-x-2 mt-12">
<% @available_templates.each do |template| %>
<div class="overflow-hidden rounded-lg bg-white shadow">
<%= link_to component_path(template),
class: "text-center text-gray-600 font-bold text-lg" do %>
<div class="px-4 py-5 sm:p-6 bg-orange-100 hover:bg-orange-600 hover:text-white">
<%= template %>
</div>
<% end %>
</div>
<% end %>
</div>
125 changes: 125 additions & 0 deletions app/views/components/navigation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<%= render 'template',
title: "Navigation",
description: "" do %>




<nav class="bg-white shadow">
<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
<div class="flex h-16 justify-between">
<div class="flex">
<div class="flex flex-shrink-0 items-center">
<img class="h-8 w-auto" src="https://tailwindui.com/img/logos/mark.svg?color=indigo&shade=600" alt="Your Company">
</div>
<div class="hidden sm:ml-6 sm:flex sm:space-x-8">
<!-- Current: "border-indigo-500 text-gray-900", Default: "border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700" -->
<a href="javascript:void(0)" class="inline-flex items-center border-b-2 border-indigo-500 px-1 pt-1 text-sm font-medium text-gray-900" aria-current="page">Dashboard</a>
<a href="javascript:void(0)" class="inline-flex items-center border-b-2 border-transparent px-1 pt-1 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700">Team</a>
<a href="javascript:void(0)" class="inline-flex items-center border-b-2 border-transparent px-1 pt-1 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700">Projects</a>
<a href="javascript:void(0)" class="inline-flex items-center border-b-2 border-transparent px-1 pt-1 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700">Calendar</a>
</div>
</div>
<div class="hidden sm:ml-6 sm:flex sm:items-center">
<button type="button" class="relative rounded-full bg-white p-1 text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
<span class="absolute -inset-1.5"></span>
<span class="sr-only">View notifications</span>
<svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M14.857 17.082a23.848 23.848 0 005.454-1.31A8.967 8.967 0 0118 9.75v-.7V9A6 6 0 006 9v.75a8.967 8.967 0 01-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 01-5.714 0m5.714 0a3 3 0 11-5.714 0" />
</svg>
</button>

<!-- Profile dropdown -->
<div class="relative ml-3">
<div>
<button type="button" class="relative flex rounded-full bg-white text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2" id="user-menu-button" aria-expanded="false" aria-haspopup="true">
<span class="absolute -inset-1.5"></span>
<span class="sr-only">Open user menu</span>
<img class="h-8 w-8 rounded-full" src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="">
</button>
</div>

<!--
Dropdown menu, show/hide based on menu state.
Entering: "transition ease-out duration-200"
From: "transform opacity-0 scale-95"
To: "transform opacity-100 scale-100"
Leaving: "transition ease-in duration-75"
From: "transform opacity-100 scale-100"
To: "transform opacity-0 scale-95"
-->
<div class="absolute right-0 z-10 mt-2 w-48 origin-top-right rounded-md bg-white py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none" role="menu" aria-orientation="vertical" aria-labelledby="user-menu-button" tabindex="-1">
<!-- Active: "bg-gray-100", Not Active: "" -->
<a href="#" class="block px-4 py-2 text-sm text-gray-700" role="menuitem" tabindex="-1" id="user-menu-item-0">Your Profile</a>
<a href="#" class="block px-4 py-2 text-sm text-gray-700" role="menuitem" tabindex="-1" id="user-menu-item-1">Settings</a>
<a href="#" class="block px-4 py-2 text-sm text-gray-700" role="menuitem" tabindex="-1" id="user-menu-item-2">Sign out</a>
</div>
</div>
</div>
<div class="-mr-2 flex items-center sm:hidden">
<!-- Mobile menu button -->
<button type="button" class="relative inline-flex items-center justify-center rounded-md p-2 text-gray-400 hover:bg-gray-100 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-indigo-500" aria-controls="mobile-menu" aria-expanded="false">
<span class="absolute -inset-0.5"></span>
<span class="sr-only">Open main menu</span>
<!--
Icon when menu is closed.
Menu open: "hidden", Menu closed: "block"
-->
<svg class="block h-6 w-6" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" />
</svg>
<!--
Icon when menu is open.
Menu open: "block", Menu closed: "hidden"
-->
<svg class="hidden h-6 w-6" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
</div>
</div>

<!-- Mobile menu, show/hide based on menu state. -->
<div class="sm:hidden" id="mobile-menu">
<div class="space-y-1 pb-3 pt-2">
<!-- Current: "bg-indigo-50 border-indigo-500 text-indigo-700", Default: "border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700" -->
<a href="javascript:void(0)" class="block border-l-4 border-indigo-500 bg-indigo-50 py-2 pl-3 pr-4 text-base font-medium text-indigo-700">Dashboard</a>
<a href="javascript:void(0)" class="block border-l-4 border-transparent py-2 pl-3 pr-4 text-base font-medium text-gray-500 hover:border-gray-300 hover:bg-gray-50 hover:text-gray-700">Team</a>
<a href="javascript:void(0)" class="block border-l-4 border-transparent py-2 pl-3 pr-4 text-base font-medium text-gray-500 hover:border-gray-300 hover:bg-gray-50 hover:text-gray-700">Projects</a>
<a href="javascript:void(0)" class="block border-l-4 border-transparent py-2 pl-3 pr-4 text-base font-medium text-gray-500 hover:border-gray-300 hover:bg-gray-50 hover:text-gray-700">Calendar</a>
</div>
<div class="border-t border-gray-200 pb-3 pt-4">
<div class="flex items-center px-4">
<div class="flex-shrink-0">
<img class="h-10 w-10 rounded-full" src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="">
</div>
<div class="ml-3">
<div class="text-base font-medium text-gray-800">Tom Cook</div>
<div class="text-sm font-medium text-gray-500">tom@example.com</div>
</div>
<button type="button" class="relative ml-auto flex-shrink-0 rounded-full bg-white p-1 text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
<span class="absolute -inset-1.5"></span>
<span class="sr-only">View notifications</span>
<svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M14.857 17.082a23.848 23.848 0 005.454-1.31A8.967 8.967 0 0118 9.75v-.7V9A6 6 0 006 9v.75a8.967 8.967 0 01-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 01-5.714 0m5.714 0a3 3 0 11-5.714 0" />
</svg>
</button>
</div>
<div class="mt-3 space-y-1">
<a href="#" class="block px-4 py-2 text-base font-medium text-gray-500 hover:bg-gray-100 hover:text-gray-800">Your Profile</a>
<a href="#" class="block px-4 py-2 text-base font-medium text-gray-500 hover:bg-gray-100 hover:text-gray-800">Settings</a>
<a href="#" class="block px-4 py-2 text-base font-medium text-gray-500 hover:bg-gray-100 hover:text-gray-800">Sign out</a>
</div>
</div>
</div>
</nav>





<% end %>
2 changes: 2 additions & 0 deletions app/views/components/toggle.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% set_breadcrumbs [["Toggle switch", component_path(:toggle)]] %>

<%= render 'template',
title: "Toggle switch Component",
description: "Simple Toggle Switch" do %>
Expand Down
37 changes: 20 additions & 17 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title><%= content_for(:title) || "Tailwind Rails" %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<head>
<title><%= content_for(:title) || "Tailwind Rails" %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= yield :head %>
<%= yield :head %>

<link rel="manifest" href="/manifest.json">
<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>
</head>
<link rel="manifest" href="/manifest.json">
<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>
</head>

<body>
<%= yield %>
</body>
<body>
<div class="container container-lg mx-auto px-4 mt-16">
<div><%= content_for(:breadcrumbs) %></div>
<%= yield %>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
get "manifest" => "rails/pwa#manifest", as: :pwa_manifest

# Defines the root path route ("/")
# root "posts#index"
root "components#index"

resources :components, only: [ :index, :show ]
end
14 changes: 14 additions & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 255d045

Please sign in to comment.