-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from PhlexUI/cirdes/add-lookbook
Add LookBook Integration
- Loading branch information
Showing
39 changed files
with
1,142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class TestView < Phlex::HTML | ||
include PhlexUI | ||
|
||
def view_template(&) | ||
div(&) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html style="background-color: <%= params[:lookbook][:display][:bg_color] || "white" %>"> | ||
<head> | ||
<title>Component Preview</title> | ||
<meta name="viewport" content="width=device-width,initial-scale=1"> | ||
<%= stylesheet_link_tag 'application' %> | ||
<%= javascript_include_tag 'application', defer: true %> | ||
</head> | ||
<body> | ||
<div style=" | ||
max-width: <%= params[:lookbook][:display][:max_width] || "100%" %> | ||
"> | ||
<div class="h-screen flex items-center justify-center"> | ||
<%= yield %> <!-- rendered preview will be injected here --> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
# lookbook workaround for phlex components | ||
if defined?(Lookbook) | ||
module Lookbook::PreviewOverrides | ||
# see https://github.com/ViewComponent/lookbook/issues/584 | ||
def render(component = nil, **args, &block) | ||
if block | ||
super { component.instance_exec component, &block } | ||
else | ||
super | ||
end | ||
end | ||
end | ||
|
||
Rails.application.configure { Lookbook::Preview.prepend Lookbook::PreviewOverrides } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module PhlexUi | ||
class AccordionPreview < Lookbook::Preview | ||
ITEMS = [ | ||
{title: "Item 1", content: "Content 1"}, | ||
{title: "Item 2", content: "Content 2"}, | ||
{title: "Item 3", content: "Content 3"} | ||
] | ||
|
||
# Default Accordion | ||
# --------------- | ||
def default | ||
render(TestView.new) do | ||
Accordion do | ||
ITEMS.each do |it| | ||
AccordionItem do | ||
AccordionTrigger { AccordionDefaultTrigger { AccordionIcon { it[:title] } } } | ||
AccordionContent { AccordionDefaultContent { it[:content] } } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module PhlexUi | ||
class AlertDialogPreview < Lookbook::Preview | ||
# Default AlertDialog | ||
# --------------- | ||
def default | ||
render(TestView.new) do | ||
AlertDialog do | ||
AlertDialogTrigger { Button { "Show dialog" } } | ||
|
||
AlertDialogContent do | ||
AlertDialogHeader do | ||
AlertDialogTitle { "Are you absolutely sure?" } | ||
AlertDialogDescription do | ||
"This action cannot be undone. This will permanently delete your account and remove your data from our servers." | ||
end | ||
end | ||
|
||
AlertDialogFooter do | ||
AlertDialogCancel { "Cancel" } | ||
AlertDialogAction { "Continue" } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module PhlexUi | ||
class AlertPreview < Lookbook::Preview | ||
# Default Alert | ||
# --------------- | ||
# @param variant [Symbol] select { choices: [nil, warning, success, destructive] } | ||
def variants(variant: nil) | ||
render(TestView.new) do | ||
Alert(variant:) do | ||
AlertTitle { "Pro tip" } | ||
AlertDescription { "With PhlexUI you'll ship faster." } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module PhlexUi | ||
class AspectRatioPreview < Lookbook::Preview | ||
# AspectRatio 16/9 | ||
# --------------- | ||
def aspect_16x9 | ||
render(TestView.new) do | ||
div(class: "w-96") do | ||
AspectRatio(aspect_ratio: "16/9") do |aspect_ratio| | ||
aspect_ratio.img(alt: "Placeholder", loading: "lazy", src: helpers.image_path("pattern.jpg")) | ||
end | ||
end | ||
end | ||
end | ||
|
||
# AspectRatio 4/3 | ||
def aspect_4x3 | ||
render(TestView.new) do | ||
div(class: "w-96") do | ||
AspectRatio(aspect_ratio: "4/3") do |aspect_ratio| | ||
aspect_ratio.img(alt: "Placeholder", loading: "lazy", src: helpers.image_path("pattern.jpg")) | ||
end | ||
end | ||
end | ||
end | ||
|
||
# AspectRatio 1/1 | ||
def aspect_1x1 | ||
render(TestView.new) do | ||
div(class: "w-96") do | ||
AspectRatio(aspect_ratio: "1/1") do |aspect_ratio| | ||
aspect_ratio.img(alt: "Placeholder", loading: "lazy", src: helpers.image_path("pattern.jpg")) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module PhlexUi | ||
class AvatarPreview < Lookbook::Preview | ||
# Avatar sizes | ||
# --------------- | ||
# @param size [Symbol] select { choices: [sm, md, lg, xl] } | ||
def sizes(size: :md) | ||
render(TestView.new) do | ||
Avatar(size:) do | ||
AvatarImage(src: "https://avatars.githubusercontent.com/u/246692?v=4", alt: "joeldrapper") | ||
end | ||
end | ||
end | ||
|
||
# Avatar Images | ||
def image | ||
render(TestView.new) do | ||
Avatar do | ||
AvatarImage(src: "https://avatars.githubusercontent.com/u/246692?v=4", alt: "joeldrapper") | ||
end | ||
end | ||
end | ||
|
||
# Avatar fallback | ||
def fallback | ||
render(TestView.new) do | ||
Avatar { AvatarFallback { "JD" } } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
# rubocop:disable Layout/LineLength | ||
|
||
module PhlexUi | ||
class BadgePreview < Lookbook::Preview | ||
# Default Badge | ||
# --------------- | ||
# @param variant [Symbol] select { choices: [primary, secondary, outline, destructive, success, warning, slate, gray, zinc, neutral, stone, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose] } | ||
def default(variant: :primary) | ||
render(TestView.new) do | ||
Badge(variant:) { "My Badge" } | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable Layout/LineLength |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module PhlexUi | ||
class ButtonPreview < Lookbook::Preview | ||
# Primary Button | ||
# --------------- | ||
# @param variant [Symbol] select { choices: [primary, destructive, outline, secondary, ghost, link] } | ||
# @param size [Symbol] select { choices: [sm, md, lg, xl] } | ||
def primary(variant: :primary, size: :md) | ||
render(TestView.new) do | ||
Button(variant:, size:) { variant.capitalize } | ||
end | ||
end | ||
|
||
# Destructive Button | ||
def destructive(variant: :destructive, size: :md) | ||
render(TestView.new) do | ||
Button(variant:, size:) { variant.capitalize } | ||
end | ||
end | ||
|
||
# Outline Button | ||
def outline(variant: :outline, size: :md) | ||
render(TestView.new) do | ||
Button(variant:, size:) { variant.capitalize } | ||
end | ||
end | ||
|
||
# Secondary Button | ||
def secondary(variant: :secondary, size: :md) | ||
render(TestView.new) do | ||
Button(variant:, size:) { variant.capitalize } | ||
end | ||
end | ||
|
||
# Ghost Button | ||
def ghost(variant: :ghost, size: :md) | ||
render(TestView.new) do | ||
Button(variant:, size:) { variant.capitalize } | ||
end | ||
end | ||
|
||
# Link Button | ||
def link(variant: :link, size: :md) | ||
render(TestView.new) do | ||
Button(variant:, size:) { variant.capitalize } | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.