-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathdev.exs
More file actions
1155 lines (1048 loc) · 40.5 KB
/
dev.exs
File metadata and controls
1155 lines (1048 loc) · 40.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# dev.exs — Standalone dev server for petal_components contributors
#
# Setup (first time only):
# mix deps.get
# mix tailwind.install
#
# Run:
# iex -S mix run dev.exs
#
# Then open http://localhost:4000 in your browser.
# Changes to components in lib/ trigger live reload automatically.
# -- ErrorView ----------------------------------------------------------------
defmodule Dev.ErrorHTML do
def render(template, _assigns) do
Phoenix.Controller.status_message_from_template(template)
end
end
# -- Layout -------------------------------------------------------------------
defmodule Dev.Layouts do
use Phoenix.Component
def root(assigns) do
~H"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="csrf-token" content={Plug.CSRFProtection.get_csrf_token()} />
<.live_title>Petal Components Playground</.live_title>
</head>
<body class="bg-white antialiased">
<script src="/assets/phoenix/phoenix.js">
</script>
<script src="/assets/phoenix_live_view/phoenix_live_view.js">
</script>
<script>
window.hooks = {}
window.uploaders = {}
let liveSocket = new window.LiveView.LiveSocket("/live", window.Phoenix.Socket, {hooks, uploaders})
liveSocket.connect()
</script>
{@inner_content}
</body>
</html>
"""
end
def live(assigns) do
~H"""
{@inner_content}
"""
end
end
# -- Playground LiveView ------------------------------------------------------
defmodule Dev.PlaygroundLive do
use Phoenix.LiveView,
layout: {Dev.Layouts, :live},
global_prefixes: ~w(x-)
use PetalComponents
alias Phoenix.LiveView.JS
@avatar_src "https://avatars.githubusercontent.com/u/82628117?v=4"
@impl true
def mount(_params, _session, socket) do
changeset = build_changeset()
{:ok,
assign(socket,
page_title: "Petal Components Playground",
count: 0,
form: to_form(changeset, as: :user),
active_tab: "buttons",
group_size: "md",
avatar_src: @avatar_src,
user_menu_items: [
%{path: "/", icon: "hero-user", label: "My Profile"},
%{path: "/", icon: "hero-cog-6-tooth", label: "Settings"},
%{path: "/", icon: "hero-arrow-right-on-rectangle", label: "Sign out", method: :delete}
]
)}
end
@impl true
def handle_event("inc", _, socket), do: {:noreply, update(socket, :count, &(&1 + 1))}
def handle_event("dec", _, socket), do: {:noreply, update(socket, :count, &(&1 - 1))}
def handle_event("change_size", %{"size" => size}, socket),
do: {:noreply, assign(socket, :group_size, size)}
def handle_event("switch_tab", %{"tab" => tab}, socket),
do: {:noreply, assign(socket, :active_tab, tab)}
def handle_event("validate", %{"user" => user_params}, socket) do
changeset =
user_params
|> build_changeset()
|> Map.put(:action, :validate)
{:noreply, assign(socket, form: to_form(changeset, as: :user))}
end
def handle_event("submit", %{"user" => user_params}, socket) do
changeset = build_changeset(user_params)
case Ecto.Changeset.apply_action(changeset, :validate) do
{:ok, _} ->
socket =
socket
|> put_flash(:success, "Form submitted successfully!")
|> assign(form: to_form(changeset, as: :user))
{:noreply, socket}
{:error, changeset} ->
{:noreply, assign(socket, form: to_form(changeset, as: :user))}
end
end
def handle_event(_event, _params, socket), do: {:noreply, socket}
defp build_changeset(params \\ %{}) do
data = %{}
types = %{
name: :string,
email: :string,
number: :integer,
password: :string,
search: :string,
tel: :string,
url: :string,
time: :time,
date: :date,
week: :string,
month: :string,
datetime: :naive_datetime,
color: :string,
file: :string,
range: :integer,
textarea: :string,
select: :string,
switch: :boolean,
checkbox: :boolean,
checkbox_group: {:array, :string},
radio_group: :string,
radio_card: :string
}
{data, types}
|> Ecto.Changeset.cast(params, Map.keys(types))
|> Ecto.Changeset.validate_required([:name, :email])
|> Ecto.Changeset.validate_length(:name, min: 2, max: 50)
|> Ecto.Changeset.validate_format(:email, ~r/@/)
end
@impl true
def render(assigns) do
~H"""
<link rel="stylesheet" href="/assets/app.css" />
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/collapse@3.x.x/dist/cdn.min.js">
</script>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js">
</script>
<.container max_width="xl" class="py-10">
<div class="mb-8">
<.h1>Petal Components Playground</.h1>
<.p class="text-gray-500">
Edit components in <code class="text-sm bg-gray-100 px-1.5 py-0.5 rounded">lib/petal_components/</code>
and see changes live.
</.p>
</div>
<%!-- Navigation tabs --%>
<div class="flex gap-1 mb-8 border-b border-gray-200">
<button
:for={
{label, key} <- [
{"Buttons", "buttons"},
{"Forms", "forms"},
{"Feedback", "feedback"},
{"Data Display", "data"},
{"Navigation", "navigation"},
{"Layout", "layout"}
]
}
phx-click="switch_tab"
phx-value-tab={key}
class={[
"px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors",
if(@active_tab == key,
do: "border-primary-500 text-primary-600",
else: "border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"
)
]}
>
{label}
</button>
</div>
<%!-- ============================================================ --%>
<%!-- BUTTONS TAB --%>
<%!-- ============================================================ --%>
<div :if={@active_tab == "buttons"} class="space-y-10">
<%!-- All Colors --%>
<section>
<.h2 class="mb-4">All Colors</.h2>
<div class="flex flex-wrap gap-3">
<.button color="primary" label="Primary" />
<.button color="secondary" label="Secondary" />
<.button color="white" label="White" />
<.button color="pure_white" label="Pure White" />
<.button color="info" label="Info" />
<.button color="success" label="Success" />
<.button color="warning" label="Warning" />
<.button color="danger" label="Danger" />
<.button color="gray" label="Gray" />
<.button color="light" label="Light" />
<.button color="dark" label="Dark" />
</div>
</section>
<%!-- Sizes --%>
<section>
<.h3 class="mb-4">Sizes</.h3>
<div class="flex flex-wrap items-center gap-3">
<.button size="xs" label="Extra Small" />
<.button size="sm" label="Small" />
<.button size="md" label="Medium" />
<.button size="lg" label="Large" />
<.button size="xl" label="Extra Large" />
</div>
</section>
<%!-- Variant: Light --%>
<section>
<.h3 class="mb-4">Variant: Light</.h3>
<div class="flex flex-wrap gap-3">
<.button variant="light" color="primary" label="Primary" />
<.button variant="light" color="secondary" label="Secondary" />
<.button variant="light" color="info" label="Info" />
<.button variant="light" color="success" label="Success" />
<.button variant="light" color="warning" label="Warning" />
<.button variant="light" color="danger" label="Danger" />
</div>
</section>
<%!-- Variant: Outline --%>
<section>
<.h3 class="mb-4">Variant: Outline</.h3>
<div class="flex flex-wrap gap-3">
<.button variant="outline" color="primary" label="Primary" />
<.button variant="outline" color="secondary" label="Secondary" />
<.button variant="outline" color="info" label="Info" />
<.button variant="outline" color="success" label="Success" />
<.button variant="outline" color="warning" label="Warning" />
<.button variant="outline" color="danger" label="Danger" />
</div>
</section>
<%!-- Variant: Inverted --%>
<section>
<.h3 class="mb-4">Variant: Inverted</.h3>
<div class="flex flex-wrap gap-3">
<.button variant="inverted" color="primary" label="Primary" />
<.button variant="inverted" color="secondary" label="Secondary" />
<.button variant="inverted" color="info" label="Info" />
<.button variant="inverted" color="success" label="Success" />
<.button variant="inverted" color="warning" label="Warning" />
<.button variant="inverted" color="danger" label="Danger" />
</div>
</section>
<%!-- Variant: Ghost --%>
<section>
<.h3 class="mb-4">Variant: Ghost</.h3>
<div class="flex flex-wrap gap-3">
<.button variant="ghost" color="primary" label="Primary" />
<.button variant="ghost" color="secondary" label="Secondary" />
<.button variant="ghost" color="info" label="Info" />
<.button variant="ghost" color="success" label="Success" />
<.button variant="ghost" color="danger" label="Danger" />
</div>
</section>
<%!-- Variant: Shadow --%>
<section>
<.h3 class="mb-4">Variant: Shadow</.h3>
<div class="flex flex-wrap gap-3">
<.button variant="shadow" color="primary" label="Primary" />
<.button variant="shadow" color="secondary" label="Secondary" />
<.button variant="shadow" color="info" label="Info" />
<.button variant="shadow" color="success" label="Success" />
<.button variant="shadow" color="danger" label="Danger" />
</div>
</section>
<%!-- Radius Options --%>
<section>
<.h3 class="mb-4">Radius Options</.h3>
<div class="flex flex-wrap items-center gap-3">
<.button radius="none" label="none" />
<.button radius="sm" label="sm" />
<.button radius="md" label="md" />
<.button radius="lg" label="lg" />
<.button radius="xl" label="xl" />
<.button radius="full" label="full" />
</div>
</section>
<%!-- Disabled & Loading --%>
<section>
<.h3 class="mb-4">Disabled & Loading States</.h3>
<div class="flex flex-wrap items-center gap-3">
<.button disabled label="Disabled" />
<.button disabled color="danger" label="Disabled Danger" />
<.button loading label="Loading" />
<.button loading color="success" label="Loading Success" />
</div>
</section>
<%!-- Button with Icon --%>
<section>
<.h3 class="mb-4">Button with Icon</.h3>
<div class="flex flex-wrap gap-3">
<.button icon="hero-plus" label="Add Item" />
<.button color="danger" icon="hero-trash" label="Delete" />
<.button color="info" icon="hero-arrow-down-tray" label="Download" />
</div>
</section>
<%!-- Icon Buttons --%>
<section>
<.h3 class="mb-4">Icon Buttons</.h3>
<div class="flex flex-wrap items-center gap-3">
<.icon_button size="xs" tooltip="Extra small">
<.icon name="hero-heart" class="w-3 h-3" />
</.icon_button>
<.icon_button size="sm" tooltip="Small">
<.icon name="hero-heart" class="w-4 h-4" />
</.icon_button>
<.icon_button size="md" color="primary" tooltip="Medium primary">
<.icon name="hero-heart" class="w-5 h-5" />
</.icon_button>
<.icon_button size="lg" color="danger" tooltip="Large danger">
<.icon name="hero-trash" class="w-5 h-5" />
</.icon_button>
<.icon_button size="xl" color="success" tooltip="Extra large success">
<.icon name="hero-check" class="w-6 h-6" />
</.icon_button>
</div>
</section>
<%!-- Button as Link --%>
<section>
<.h3 class="mb-4">Button as Link</.h3>
<div class="flex flex-wrap gap-3">
<.button link_type="a" to="/" label="link_type=a" />
<.button link_type="a" to="/" color="secondary" label="Secondary Link" />
</div>
</section>
<%!-- Button Group --%>
<section>
<.h3 class="mb-4">Button Group</.h3>
<.button_group aria_label="Size options" size={@group_size}>
<:button label="XS" phx-click="change_size" phx-value-size="xs" />
<:button label="SM" phx-click="change_size" phx-value-size="sm" />
<:button label="MD" phx-click="change_size" phx-value-size="md" />
<:button label="LG" phx-click="change_size" phx-value-size="lg" />
<:button label="XL" phx-click="change_size" phx-value-size="xl" />
</.button_group>
<.p class="mt-2 text-sm text-gray-500">Current size: {@group_size}</.p>
</section>
<%!-- Counter --%>
<section>
<.h3 class="mb-4">Counter (LiveView Interaction)</.h3>
<div class="flex items-center gap-4">
<.button phx-click="dec" color="danger" size="sm" label="-" />
<span class="text-2xl font-bold tabular-nums">{@count}</span>
<.button phx-click="inc" color="success" size="sm" label="+" />
</div>
</section>
</div>
<%!-- ============================================================ --%>
<%!-- FORMS TAB --%>
<%!-- ============================================================ --%>
<div :if={@active_tab == "forms"} class="space-y-10">
<%!-- Form with Changeset Validation --%>
<section>
<.h2 class="mb-4">Form with Validation</.h2>
<.form for={@form} phx-submit="submit" phx-change="validate" class="space-y-4 max-w-lg">
<.field
field={@form[:name]}
type="text"
label="Name"
placeholder="eg. Sally"
help_text="Must be between 2 and 50 characters"
phx-debounce="blur"
required
/>
<.field
field={@form[:email]}
type="email"
label="Email"
placeholder="sally@example.com"
help_text="Must contain an @ symbol"
phx-debounce="blur"
required
/>
<.field
field={@form[:number]}
type="number"
label="Number"
placeholder="42"
/>
<.field
field={@form[:password]}
type="password"
label="Password"
placeholder="Enter password"
/>
<.field
field={@form[:search]}
type="search"
label="Search"
placeholder="Search..."
clearable
/>
<.field
field={@form[:tel]}
type="tel"
label="Phone"
placeholder="+1 555 000 0000"
clearable
/>
<.field
field={@form[:url]}
type="url"
label="URL"
placeholder="https://example.com"
/>
<.field
field={@form[:time]}
type="time"
label="Time"
/>
<.field
field={@form[:date]}
type="date"
label="Date"
/>
<.field
field={@form[:week]}
type="week"
label="Week"
/>
<.field
field={@form[:month]}
type="month"
label="Month"
/>
<.field
field={@form[:datetime]}
type="datetime-local"
label="Date & Time"
/>
<.field
field={@form[:color]}
type="color"
label="Favorite Color"
/>
<.field
field={@form[:file]}
type="file"
label="File Upload"
/>
<.field
field={@form[:range]}
type="range"
label="Volume"
/>
<.field
field={@form[:textarea]}
type="textarea"
label="Bio"
placeholder="Tell us about yourself..."
rows="3"
help_text="Optional but appreciated"
/>
<%!-- Select --%>
<.field
field={@form[:select]}
type="select"
label="Role"
options={["Admin", "Editor", "Viewer"]}
/>
<%!-- Switch --%>
<.field field={@form[:switch]} type="switch" label="Enable notifications" />
<%!-- Checkbox --%>
<.field field={@form[:checkbox]} type="checkbox" label="I agree to the terms" />
<%!-- Checkbox Group (Column) --%>
<.field
field={@form[:checkbox_group]}
type="checkbox-group"
label="Interests (column layout)"
group_layout="col"
options={[{"Elixir", "elixir"}, {"Phoenix", "phoenix"}, {"LiveView", "liveview"}]}
/>
<%!-- Checkbox Group (Row) --%>
<.field
field={@form[:checkbox_group]}
type="checkbox-group"
label="Interests (row layout)"
group_layout="row"
options={[{"Elixir", "elixir"}, {"Phoenix", "phoenix"}, {"LiveView", "liveview"}]}
/>
<%!-- Radio Group (Column) --%>
<.field
field={@form[:radio_group]}
type="radio-group"
label="Plan (column layout)"
group_layout="col"
options={[{"Free", "free"}, {"Pro", "pro"}, {"Enterprise", "enterprise"}]}
/>
<%!-- Radio Group (Row) --%>
<.field
field={@form[:radio_group]}
type="radio-group"
label="Plan (row layout)"
group_layout="row"
options={[{"Free", "free"}, {"Pro", "pro"}, {"Enterprise", "enterprise"}]}
/>
<%!-- Radio Card --%>
<.field
field={@form[:radio_card]}
type="radio-card"
label="Server Size"
options={[
%{label: "8-core CPU", value: "high", description: "32 GB RAM"},
%{label: "6-core CPU", value: "mid", description: "24 GB RAM"},
%{label: "4-core CPU", value: "low", description: "16 GB RAM", disabled: true}
]}
size="md"
variant="outline"
group_layout="row"
help_text="Choose your server configuration"
required
/>
<div class="flex justify-end">
<.button type="submit" label="Submit" />
</div>
</.form>
</section>
</div>
<%!-- ============================================================ --%>
<%!-- FEEDBACK TAB --%>
<%!-- ============================================================ --%>
<div :if={@active_tab == "feedback"} class="space-y-8">
<section>
<.h2 class="mb-4">Alerts</.h2>
<div class="space-y-3">
<.alert with_icon color="info" label="This is an info alert." heading="Info" />
<.alert with_icon color="success" label="Operation completed successfully." heading="Success" />
<.alert with_icon color="warning" label="Please review before continuing." heading="Warning" />
<.alert with_icon color="danger" label="Something went wrong." heading="Error" />
</div>
</section>
<section>
<.h2 class="mb-4">Badges</.h2>
<div class="flex flex-wrap gap-2">
<.badge color="primary" label="Primary" />
<.badge color="secondary" label="Secondary" />
<.badge color="info" label="Info" />
<.badge color="success" label="Success" />
<.badge color="warning" label="Warning" />
<.badge color="danger" label="Danger" />
<.badge color="gray" label="Gray" />
</div>
</section>
<section>
<.h2 class="mb-4">Progress</.h2>
<div class="space-y-4 max-w-md">
<.progress size="sm" value={25} max={100} label="25%" />
<.progress size="md" value={50} max={100} label="50%" />
<.progress size="lg" value={75} max={100} label="75%" color="success" />
<.progress size="xl" value={100} max={100} label="100%" color="info" />
</div>
</section>
<section>
<.h2 class="mb-4">Rating</.h2>
<.rating include_label rating={3.5} total={5} />
</section>
<section>
<.h2 class="mb-4">Loading</.h2>
<div class="flex gap-4">
<.spinner show={true} />
<.spinner show={true} size="md" />
<.spinner show={true} size="lg" />
</div>
</section>
<section>
<.h2 class="mb-4">Skeleton</.h2>
<.skeleton />
</section>
<section>
<.h2 class="mb-4">Modal</.h2>
<.button phx-click={PetalComponents.Modal.show_modal("modal")} label="Open Modal" />
<.modal max_width="sm" title="Example Modal" hide>
<.p>This is a modal dialog. Click outside or press Escape to close.</.p>
<div class="flex justify-end mt-4">
<.button label="Close" phx-click={PetalComponents.Modal.hide_modal()} />
</div>
</.modal>
</section>
<section>
<.h2 class="mb-4">Slide Over</.h2>
<.button phx-click={PetalComponents.SlideOver.show_slide_over("right", "slide-over")} label="Open Slide Over" />
<.slide_over title="Example Slide Over" origin="right" hide>
<.p>Content goes here.</.p>
<div class="flex justify-end mt-4">
<.button
label="Close"
phx-click={PetalComponents.SlideOver.hide_slide_over("right")}
/>
</div>
</.slide_over>
</section>
</div>
<%!-- ============================================================ --%>
<%!-- DATA DISPLAY TAB --%>
<%!-- ============================================================ --%>
<div :if={@active_tab == "data"} class="space-y-8">
<%!-- Table --%>
<section>
<.h2 class="mb-4">Table</.h2>
<.table
id="example-table"
rows={[
%{id: 1, name: "Phoenix", language: "Elixir", stars: "21k"},
%{id: 2, name: "Rails", language: "Ruby", stars: "56k"},
%{id: 3, name: "Next.js", language: "JavaScript", stars: "128k"}
]}
>
<:col :let={row} label="Name">{row.name}</:col>
<:col :let={row} label="Language">{row.language}</:col>
<:col :let={row} label="Stars">{row.stars}</:col>
</.table>
</section>
<%!-- Card with Media and Footer --%>
<section>
<.h2 class="mb-4">Card</.h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 max-w-2xl">
<.card>
<.card_media src="https://images.unsplash.com/photo-1497032628192-86f99bcd76bc?w=600&h=400&fit=crop" />
<.card_content category="Guide" heading="Getting Started">
<.p class="mt-2 text-sm text-gray-500">
Learn how to install and configure Petal Components in your Phoenix project.
</.p>
</.card_content>
<.card_footer>
<div class="flex justify-between items-center w-full">
<span class="text-sm text-gray-500">5 min read</span>
<.button size="xs" variant="ghost" label="Read more" />
</div>
</.card_footer>
</.card>
<.card>
<.card_media src="https://images.unsplash.com/photo-1555066931-4365d14bab8c?w=600&h=400&fit=crop" />
<.card_content category="Reference" heading="Component API">
<.p class="mt-2 text-sm text-gray-500">
Browse the full list of available components and their props.
</.p>
</.card_content>
<.card_footer>
<div class="flex justify-between items-center w-full">
<span class="text-sm text-gray-500">10 min read</span>
<.button size="xs" variant="ghost" label="Read more" />
</div>
</.card_footer>
</.card>
</div>
</section>
<%!-- Avatar with Image --%>
<section>
<.h2 class="mb-4">Avatar (with image)</.h2>
<div class="flex gap-3 items-center">
<.avatar size="xs" src={@avatar_src} />
<.avatar size="sm" src={@avatar_src} />
<.avatar size="md" src={@avatar_src} />
<.avatar size="lg" src={@avatar_src} />
<.avatar size="xl" src={@avatar_src} />
</div>
</section>
<%!-- Avatar with Initials --%>
<section>
<.h2 class="mb-4">Avatar (with initials)</.h2>
<div class="flex gap-3 items-center">
<.avatar size="sm" name="John Doe" random_color />
<.avatar size="md" name="Jane Smith" random_color />
<.avatar size="lg" name="Bob Wilson" random_color />
<.avatar size="xl" name="Alice Brown" random_color />
</div>
</section>
<%!-- Avatar Group --%>
<section>
<.h2 class="mb-4">Avatar Group</.h2>
<.avatar_group
size="md"
avatars={[
@avatar_src,
"https://i.pravatar.cc/150?img=32",
"https://i.pravatar.cc/150?img=12",
"https://i.pravatar.cc/150?img=5",
"https://i.pravatar.cc/150?img=8"
]}
/>
</section>
<%!-- Skeleton Variants --%>
<section>
<.h2 class="mb-4">Skeleton Variants</.h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<.h4 class="mb-2">Image</.h4>
<.skeleton kind={:image} />
</div>
<div>
<.h4 class="mb-2">Video</.h4>
<.skeleton kind={:video} />
</div>
<div>
<.h4 class="mb-2">Text</.h4>
<.skeleton kind={:text} />
</div>
<div>
<.h4 class="mb-2">Card</.h4>
<.skeleton kind={:card} />
</div>
<div>
<.h4 class="mb-2">Widget</.h4>
<.skeleton kind={:widget} />
</div>
<div>
<.h4 class="mb-2">List</.h4>
<.skeleton kind={:list} />
</div>
<div>
<.h4 class="mb-2">Testimonial</.h4>
<.skeleton kind={:testimonial} />
</div>
</div>
</section>
<%!-- Accordion --%>
<section>
<.h2 class="mb-4">Accordion</.h2>
<.accordion>
<:item heading="What is Petal Components?">
A set of HEEX components for Phoenix developers -- like Shadcn, but for LiveView.
</:item>
<:item heading="How do I install it?">
Add <code>petal_components</code> to your mix.exs dependencies and follow the setup guide.
</:item>
<:item heading="Is it free?">
Yes! Petal Components is open source and MIT licensed.
</:item>
</.accordion>
</section>
</div>
<%!-- ============================================================ --%>
<%!-- NAVIGATION TAB --%>
<%!-- ============================================================ --%>
<div :if={@active_tab == "navigation"} class="space-y-8">
<%!-- Tabs Component --%>
<section>
<.h2 class="mb-4">Tabs (pill style)</.h2>
<.tabs>
<.tab is_active link_type="a" to="/" label="Dashboard" />
<.tab link_type="a" to="/" label="Settings" />
<.tab link_type="a" to="/" label="Users" />
<.tab link_type="a" to="/" label="Billing" disabled />
</.tabs>
</section>
<section>
<.h2 class="mb-4">Tabs (underline style)</.h2>
<.tabs underline>
<.tab underline is_active link_type="a" to="/" label="Overview" number={12} />
<.tab underline link_type="a" to="/" label="Activity" number={5} />
<.tab underline link_type="a" to="/" label="Settings" />
</.tabs>
</section>
<%!-- Breadcrumbs --%>
<section>
<.h2 class="mb-4">Breadcrumbs (slash separator)</.h2>
<.breadcrumbs links={[
%{label: "Home", to: "/", icon: "hero-home"},
%{label: "Components", to: "/"},
%{label: "Breadcrumbs", to: "/"}
]} />
</section>
<section>
<.h2 class="mb-4">Breadcrumbs (chevron separator)</.h2>
<.breadcrumbs
separator="chevron"
links={[
%{label: "Home", to: "/", icon: "hero-home"},
%{label: "Projects", to: "/"},
%{label: "Petal Components", to: "/"},
%{label: "Settings", to: "/"}
]}
/>
</section>
<%!-- User Dropdown Menu --%>
<section>
<.h2 class="mb-4">User Dropdown Menu</.h2>
<.user_dropdown_menu
current_user_name="Matt Platts"
avatar_src={@avatar_src}
user_menu_items={@user_menu_items}
/>
</section>
<%!-- Pagination --%>
<section>
<.h2 class="mb-4">Pagination</.h2>
<.pagination link_type="live_patch" path="/" current_page={3} total_pages={10} />
</section>
<%!-- Links --%>
<section>
<.h2 class="mb-4">Links</.h2>
<div class="flex flex-wrap gap-4">
<.a to="/" link_type="a" label="Standard link (a)" />
<.a to="/" link_type="live_patch" label="Live Patch link" />
<.a to="/" link_type="live_redirect" label="Live Redirect link" />
</div>
</section>
<%!-- Stepper --%>
<section>
<.h2 class="mb-4">Stepper</.h2>
<.stepper
steps={[
%{name: "Account", description: "Create account", complete?: true, active?: false},
%{name: "Profile", description: "Set up profile", complete?: true, active?: true},
%{name: "Review", description: "Review & confirm", complete?: false, active?: false}
]}
orientation="horizontal"
size="md"
/>
</section>
<%!-- Dropdown --%>
<section>
<.h2 class="mb-4">Dropdown</.h2>
<.dropdown label="Options">
<.dropdown_menu_item type="button">
<.icon name="hero-pencil-mini" class="w-4 h-4" /> Edit
</.dropdown_menu_item>
<.dropdown_menu_item type="button">
<.icon name="hero-document-duplicate-mini" class="w-4 h-4" /> Duplicate
</.dropdown_menu_item>
<.dropdown_menu_item type="button">
<.icon name="hero-trash-mini" class="w-4 h-4" /> Delete
</.dropdown_menu_item>
</.dropdown>
</section>
<%!-- Vertical Menu --%>
<section>
<.h2 class="mb-4">Vertical Menu</.h2>
<div class="max-w-xs">
<.vertical_menu
title="Settings"
current_page={:general}
menu_items={[
%{name: :general, label: "General", path: "/", icon: "hero-cog-6-tooth"},
%{name: :profile, label: "Profile", path: "/", icon: "hero-user"},
%{name: :billing, label: "Billing", path: "/", icon: "hero-credit-card"}
]}
/>
</div>
</section>
</div>
<%!-- ============================================================ --%>
<%!-- LAYOUT TAB --%>
<%!-- ============================================================ --%>
<div :if={@active_tab == "layout"} class="space-y-8">
<section>
<.h2 class="mb-4">Typography</.h2>
<div class="space-y-2">
<.h1>Heading 1</.h1>
<.h2>Heading 2</.h2>
<.h3>Heading 3</.h3>
<.h4>Heading 4</.h4>
<.h5>Heading 5</.h5>
<.p>A paragraph of text. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</.p>
</div>
</section>
<section>
<.h2 class="mb-4">Lists</.h2>
<div class="flex gap-8">
<div>
<.h4 class="mb-2">Unordered</.h4>
<.ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</.ul>
</div>
<div>
<.h4 class="mb-2">Ordered</.h4>
<.ol>
<li>First step</li>
<li>Second step</li>
<li>Third step</li>
</.ol>
</div>
</div>
</section>
<section>
<.h2 class="mb-4">Prose</.h2>
<.prose>
<h3>Rich Content Block</h3>
<p>
The <code>.prose</code> component applies beautiful typographic defaults.
It handles paragraphs, lists, code blocks, and more.
</p>
<ul>
<li>Automatic spacing</li>
<li>Readable line lengths</li>
<li>Styled inline elements</li>
</ul>
</.prose>
</section>
<%!-- Container with all max_width variants --%>
<section>
<.h2 class="mb-4">Container (max_width variants)</.h2>
<div class="space-y-3">
<.container max_width="full" class="bg-gray-100 p-4 rounded">
<.p class="text-sm text-gray-600">max_width="full"</.p>
</.container>
<.container max_width="xl" class="bg-gray-100 p-4 rounded">
<.p class="text-sm text-gray-600">max_width="xl"</.p>
</.container>
<.container max_width="lg" class="bg-gray-100 p-4 rounded">
<.p class="text-sm text-gray-600">max_width="lg"</.p>
</.container>
<.container max_width="md" class="bg-gray-100 p-4 rounded">
<.p class="text-sm text-gray-600">max_width="md"</.p>
</.container>
<.container max_width="sm" class="bg-gray-100 p-4 rounded">
<.p class="text-sm text-gray-600">max_width="sm"</.p>
</.container>
</div>
</section>