Skip to content

Commit 071b0a7

Browse files
authored
Migrate the docs components to app/components to align with Phlex conversions (#165)
1 parent 8fd1d44 commit 071b0a7

File tree

15 files changed

+462
-442
lines changed

15 files changed

+462
-442
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# frozen_string_literal: true
2+
3+
module Components
4+
module Docs
5+
class ComponentsTable < Components::Base
6+
def initialize(component_files)
7+
@component_files = component_files.sort_by { |component| [component.built_using, component.name] }
8+
end
9+
10+
def view_template
11+
Heading(level: 2) { "Components" }
12+
13+
component_table_view(@component_files)
14+
end
15+
16+
private
17+
18+
def component_table_view(components)
19+
div(class: "border rounded-lg overflow-hidden") do
20+
Table do
21+
TableHeader do
22+
TableRow do
23+
div(class: "flex items-center space-x-2") do
24+
TableHead { "Component" }
25+
end
26+
TableHead(class: "w-full grow-1") { "Built using" }
27+
TableHead(class: "text-right") { "Source" }
28+
end
29+
end
30+
31+
TableBody do
32+
components.each do |component|
33+
TableRow do
34+
TableCell do
35+
InlineCode { component.name }
36+
end
37+
TableCell do
38+
component.built_using
39+
case component.built_using&.to_sym
40+
when :phlex
41+
Badge(size: :sm, variant: :rose) { "Phlex" }
42+
when :stimulus
43+
Badge(size: :sm, variant: :amber) { "Stimulus JS" }
44+
end
45+
end
46+
TableCell do
47+
div(class: "flex justify-end") do
48+
Link(href: component.source, variant: :outline, size: :sm, target: "_blank") do
49+
github_icon
50+
span(class: "ml-2") { "See source" }
51+
end
52+
end
53+
end
54+
end
55+
end
56+
end
57+
end
58+
end
59+
end
60+
61+
def github_icon
62+
svg(viewbox: "0 0 438.549 438.549", class: "h-4 w-4") do |s|
63+
s.path(
64+
fill: "currentColor",
65+
d:
66+
"M409.132 114.573c-19.608-33.596-46.205-60.194-79.798-79.8-33.598-19.607-70.277-29.408-110.063-29.408-39.781 0-76.472 9.804-110.063 29.408-33.596 19.605-60.192 46.204-79.8 79.8C9.803 148.168 0 184.854 0 224.63c0 47.78 13.94 90.745 41.827 128.906 27.884 38.164 63.906 64.572 108.063 79.227 5.14.954 8.945.283 11.419-1.996 2.475-2.282 3.711-5.14 3.711-8.562 0-.571-.049-5.708-.144-15.417a2549.81 2549.81 0 01-.144-25.406l-6.567 1.136c-4.187.767-9.469 1.092-15.846 1-6.374-.089-12.991-.757-19.842-1.999-6.854-1.231-13.229-4.086-19.13-8.559-5.898-4.473-10.085-10.328-12.56-17.556l-2.855-6.57c-1.903-4.374-4.899-9.233-8.992-14.559-4.093-5.331-8.232-8.945-12.419-10.848l-1.999-1.431c-1.332-.951-2.568-2.098-3.711-3.429-1.142-1.331-1.997-2.663-2.568-3.997-.572-1.335-.098-2.43 1.427-3.289 1.525-.859 4.281-1.276 8.28-1.276l5.708.853c3.807.763 8.516 3.042 14.133 6.851 5.614 3.806 10.229 8.754 13.846 14.842 4.38 7.806 9.657 13.754 15.846 17.847 6.184 4.093 12.419 6.136 18.699 6.136 6.28 0 11.704-.476 16.274-1.423 4.565-.952 8.848-2.383 12.847-4.285 1.713-12.758 6.377-22.559 13.988-29.41-10.848-1.14-20.601-2.857-29.264-5.14-8.658-2.286-17.605-5.996-26.835-11.14-9.235-5.137-16.896-11.516-22.985-19.126-6.09-7.614-11.088-17.61-14.987-29.979-3.901-12.374-5.852-26.648-5.852-42.826 0-23.035 7.52-42.637 22.557-58.817-7.044-17.318-6.379-36.732 1.997-58.24 5.52-1.715 13.706-.428 24.554 3.853 10.85 4.283 18.794 7.952 23.84 10.994 5.046 3.041 9.089 5.618 12.135 7.708 17.705-4.947 35.976-7.421 54.818-7.421s37.117 2.474 54.823 7.421l10.849-6.849c7.419-4.57 16.18-8.758 26.262-12.565 10.088-3.805 17.802-4.853 23.134-3.138 8.562 21.509 9.325 40.922 2.279 58.24 15.036 16.18 22.559 35.787 22.559 58.817 0 16.178-1.958 30.497-5.853 42.966-3.9 12.471-8.941 22.457-15.125 29.979-6.191 7.521-13.901 13.85-23.131 18.986-9.232 5.14-18.182 8.85-26.84 11.136-8.662 2.286-18.415 4.004-29.263 5.146 9.894 8.562 14.842 22.077 14.842 40.539v60.237c0 3.422 1.19 6.279 3.572 8.562 2.379 2.279 6.136 2.95 11.276 1.995 44.163-14.653 80.185-41.062 108.068-79.226 27.88-38.161 41.825-81.126 41.825-128.906-.01-39.771-9.818-76.454-29.414-110.049z"
67+
)
68+
end
69+
end
70+
end
71+
end
72+
end

app/components/docs/header.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
module Components
4+
module Docs
5+
class Header < Components::Base
6+
def initialize(title: nil, description: nil)
7+
@title = title
8+
@description = description
9+
end
10+
11+
def view_template
12+
div(class: "space-y-2") do
13+
Components.Heading(level: 1) { @title }
14+
Text(as: "p", size: "5", class: "text-muted-foreground") { @description }
15+
end
16+
end
17+
18+
private
19+
20+
def alert_icon
21+
svg(
22+
xmlns: "http://www.w3.org/2000/svg",
23+
fill: "none",
24+
viewbox: "0 0 24 24",
25+
stroke_width: "1.5",
26+
stroke: "currentColor",
27+
class: "w-5 h-5"
28+
) do |s|
29+
s.path(
30+
stroke_linecap: "round",
31+
stroke_linejoin: "round",
32+
d:
33+
"M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
34+
)
35+
end
36+
end
37+
end
38+
end
39+
end
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# frozen_string_literal: true
2+
3+
module Components
4+
module Docs
5+
class TailwindConfig < Components::Base
6+
def view_template
7+
Text(size: "4", weight: "semibold") { "Update Tailwind Configuration" }
8+
Text do
9+
plain "Add the following to your "
10+
InlineCode(class: "whitespace-nowrap") { "tailwind.config.js" }
11+
plain " file"
12+
end
13+
Codeblock(tailwind_config, syntax: :javascript)
14+
end
15+
16+
private
17+
18+
def tailwind_config
19+
<<~CODE
20+
// For importing tailwind styles from ruby_ui gem
21+
const execSync = require('child_process').execSync;
22+
23+
// Import ruby_ui gem path (To make sure Tailwind loads classes used by ruby_ui gem)
24+
const outputRUBYUI = execSync('bundle show phlex_ui', { encoding: 'utf-8' });
25+
const ruby_ui_path = outputRUBYUI.trim() + '/**/*.rb';
26+
27+
const defaultTheme = require('tailwindcss/defaultTheme')
28+
29+
module.exports = {
30+
darkMode: ["class"],
31+
content: [
32+
'./app/views/**/*.{erb,haml,html,slim,rb}',
33+
'./app/helpers/**/*.rb',
34+
'./app/assets/stylesheets/**/*.css',
35+
'./app/javascript/**/*.js',
36+
ruby_ui_path
37+
],
38+
theme: {
39+
container: {
40+
center: true,
41+
padding: "2rem",
42+
screens: {
43+
"2xl": "1400px",
44+
},
45+
},
46+
extend: {
47+
colors: {
48+
border: "hsl(var(--border))",
49+
input: "hsl(var(--input))",
50+
ring: "hsl(var(--ring))",
51+
background: "hsl(var(--background))",
52+
foreground: "hsl(var(--foreground))",
53+
primary: {
54+
DEFAULT: "hsl(var(--primary))",
55+
foreground: "hsl(var(--primary-foreground))",
56+
},
57+
secondary: {
58+
DEFAULT: "hsl(var(--secondary))",
59+
foreground: "hsl(var(--secondary-foreground))",
60+
},
61+
destructive: {
62+
DEFAULT: "hsl(var(--destructive))",
63+
foreground: "hsl(var(--destructive-foreground))",
64+
},
65+
muted: {
66+
DEFAULT: "hsl(var(--muted))",
67+
foreground: "hsl(var(--muted-foreground))",
68+
},
69+
accent: {
70+
DEFAULT: "hsl(var(--accent))",
71+
foreground: "hsl(var(--accent-foreground))",
72+
},
73+
popover: {
74+
DEFAULT: "hsl(var(--popover))",
75+
foreground: "hsl(var(--popover-foreground))",
76+
},
77+
card: {
78+
DEFAULT: "hsl(var(--card))",
79+
foreground: "hsl(var(--card-foreground))",
80+
},
81+
warning: {
82+
DEFAULT: "hsl(var(--warning))",
83+
foreground: "hsl(var(--warning-foreground))",
84+
},
85+
success: {
86+
DEFAULT: "hsl(var(--success))",
87+
foreground: "hsl(var(--success-foreground))",
88+
},
89+
},
90+
borderRadius: {
91+
lg: `var(--radius)`,
92+
md: `calc(var(--radius) - 2px)`,
93+
sm: "calc(var(--radius) - 4px)",
94+
},
95+
fontFamily: {
96+
sans: ["var(--font-sans)", ...defaultTheme.fontFamily.sans],
97+
},
98+
},
99+
},
100+
# Not compatible with importmaps
101+
plugins: [
102+
require("tailwindcss-animate"),
103+
],
104+
}
105+
CODE
106+
end
107+
end
108+
end
109+
end

app/components/docs/tailwind_css.rb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# frozen_string_literal: true
2+
3+
module Components
4+
module Docs
5+
class TailwindCss < Components::Base
6+
def view_template
7+
Text(size: "4", weight: "semibold") { "Add CSS variables" }
8+
Text do
9+
plain "Add the following to your "
10+
InlineCode { "app/assets/stylesheets/application.tailwind.css" }
11+
plain " file"
12+
end
13+
code = css_variables
14+
Codeblock(code, syntax: :css)
15+
end
16+
17+
private
18+
19+
def css_variables
20+
<<~CODE
21+
@tailwind base;
22+
@tailwind components;
23+
@tailwind utilities;
24+
25+
26+
@layer base {
27+
:root {
28+
--background: 0 0% 100%;
29+
--foreground: 240 10% 3.9%;
30+
--card: 0 0% 100%;
31+
--card-foreground: 240 10% 3.9%;
32+
--popover: 0 0% 100%;
33+
--popover-foreground: 240 10% 3.9%;
34+
--primary: 240 5.9% 10%;
35+
--primary-foreground: 0 0% 98%;
36+
--secondary: 240 4.8% 95.9%;
37+
--secondary-foreground: 240 5.9% 10%;
38+
--muted: 240 4.8% 95.9%;
39+
--muted-foreground: 240 3.8% 46.1%;
40+
--accent: 240 4.8% 95.9%;
41+
--accent-foreground: 240 5.9% 10%;
42+
--destructive: 0 84.2% 60.2%;
43+
--destructive-foreground: 0 0% 98%;
44+
--border: 240 5.9% 90%;
45+
--input: 240 5.9% 90%;
46+
--ring: 240 5.9% 10%;
47+
--radius: 0.5rem;
48+
--warning: 38 92% 50%;
49+
--warning-foreground: 0 0% 100%;
50+
--success: 87 100% 37%;
51+
--success-foreground: 0 0% 100%;
52+
}
53+
54+
.dark {
55+
--background: 240 10% 3.9%;
56+
--foreground: 0 0% 98%;
57+
--card: 240 10% 3.9%;
58+
--card-foreground: 0 0% 98%;
59+
--popover: 240 10% 3.9%;
60+
--popover-foreground: 0 0% 98%;
61+
--primary: 0 0% 98%;
62+
--primary-foreground: 240 5.9% 10%;
63+
--secondary: 240 3.7% 15.9%;
64+
--secondary-foreground: 0 0% 98%;
65+
--muted: 240 3.7% 15.9%;
66+
--muted-foreground: 240 5% 64.9%;
67+
--accent: 240 3.7% 15.9%;
68+
--accent-foreground: 0 0% 98%;
69+
--destructive: 0 62.8% 30.6%;
70+
--destructive-foreground: 0 0% 98%;
71+
--border: 240 3.7% 15.9%;
72+
--input: 240 3.7% 15.9%;
73+
--ring: 240 4.9% 83.9%;
74+
--warning: 38 92% 50%;
75+
--warning-foreground: 0 0% 100%;
76+
--success: 84 81% 44%;
77+
--success-foreground: 0 0% 100%;
78+
}
79+
}
80+
81+
@layer base {
82+
* {
83+
@apply border-border;
84+
}
85+
body {
86+
@apply bg-background text-foreground;
87+
font-feature-settings: "rlig" 1, "calt" 1;
88+
}
89+
}
90+
CODE
91+
end
92+
end
93+
end
94+
end

0 commit comments

Comments
 (0)