Skip to content

Commit f84cf7b

Browse files
committed
implemented skeleton loading for tailwind preset
1 parent c171fca commit f84cf7b

File tree

6 files changed

+146
-10
lines changed

6 files changed

+146
-10
lines changed

examples/pagination/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn App() -> impl IntoView {
1414

1515
view! {
1616
<div class="rounded-md overflow-clip m-10 border dark:border-gray-700".to_string()>
17-
<table class="text-sm text-left text-gray-500 dark:text-gray-400 mb-[-1px]">
17+
<table class="text-sm text-left text-gray-500 dark:text-gray-400 mb-[-1px] w-[calc(100vw-5rem)]">
1818
<TableContent
1919
rows=rows
2020
display_strategy=DisplayStrategy::Pagination {

examples/pagination/src/tailwind.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ impl TableClassesProvider for TailwindClassesPreset {
5151
)
5252
}
5353

54+
fn loading_cell(&self, prop_class: &str) -> String {
55+
format!("{} {}", "px-5 py-2", prop_class)
56+
}
57+
58+
fn loading_cell_inner(&self, row_index: usize, prop_class: &str) -> String {
59+
let width = match row_index % 4 {
60+
0 => "w-[calc(85%-2.5rem)]",
61+
1 => "w-[calc(90%-2.5rem)]",
62+
2 => "w-[calc(75%-2.5rem)]",
63+
_ => "w-[calc(60%-2.5rem)]",
64+
};
65+
format!(
66+
"animate-pulse h-2 bg-gray-200 rounded-full dark:bg-gray-700 inline-block align-middle {} {}",
67+
width, prop_class
68+
)
69+
}
70+
5471
fn cell(&self, template_classes: &str) -> String {
5572
format!("{} {}", "px-5 py-2", template_classes)
5673
}

examples/pagination/style/output.css

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,16 @@ video {
556556
margin: 2.5rem;
557557
}
558558

559+
.mx-5 {
560+
margin-left: 1.25rem;
561+
margin-right: 1.25rem;
562+
}
563+
564+
.my-2 {
565+
margin-top: 0.5rem;
566+
margin-bottom: 0.5rem;
567+
}
568+
559569
.mb-\[-1px\] {
560570
margin-bottom: -1px;
561571
}
@@ -572,6 +582,10 @@ video {
572582
margin-inline-end: 0.5rem;
573583
}
574584

585+
.inline-block {
586+
display: inline-block;
587+
}
588+
575589
.flex {
576590
display: flex;
577591
}
@@ -600,6 +614,10 @@ video {
600614
height: 0.875rem;
601615
}
602616

617+
.h-2 {
618+
height: 0.5rem;
619+
}
620+
603621
.w-3 {
604622
width: 0.75rem;
605623
}
@@ -608,6 +626,80 @@ video {
608626
width: 0.875rem;
609627
}
610628

629+
.w-\[60\%\] {
630+
width: 60%;
631+
}
632+
633+
.w-\[75\%\] {
634+
width: 75%;
635+
}
636+
637+
.w-\[80\%\] {
638+
width: 80%;
639+
}
640+
641+
.w-\[90\%\] {
642+
width: 90%;
643+
}
644+
645+
.w-\[calc\(60\%-2\.5rem\)\] {
646+
width: calc(60% - 2.5rem);
647+
}
648+
649+
.w-\[calc\(75\%-2\.5rem\)\] {
650+
width: calc(75% - 2.5rem);
651+
}
652+
653+
.w-\[calc\(80\%-2\.5rem\)\] {
654+
width: calc(80% - 2.5rem);
655+
}
656+
657+
.w-\[calc\(90\%-2\.5rem\)\] {
658+
width: calc(90% - 2.5rem);
659+
}
660+
661+
.w-\[calc\(100vw-10rem\)\] {
662+
width: calc(100vw - 10rem);
663+
}
664+
665+
.w-\[calc\(100vw-50rem\)\] {
666+
width: calc(100vw - 50rem);
667+
}
668+
669+
.w-\[calc\(100vw-5rem\)\] {
670+
width: calc(100vw - 5rem);
671+
}
672+
673+
.w-\[calc\(85\%-2\.5rem\)\] {
674+
width: calc(85% - 2.5rem);
675+
}
676+
677+
.max-w-\[60\%\] {
678+
max-width: 60%;
679+
}
680+
681+
.max-w-\[75\%\] {
682+
max-width: 75%;
683+
}
684+
685+
.max-w-\[80\%\] {
686+
max-width: 80%;
687+
}
688+
689+
.max-w-\[90\%\] {
690+
max-width: 90%;
691+
}
692+
693+
@keyframes pulse {
694+
50% {
695+
opacity: .5;
696+
}
697+
}
698+
699+
.animate-pulse {
700+
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
701+
}
702+
611703
.cursor-pointer {
612704
cursor: pointer;
613705
}
@@ -642,6 +734,10 @@ video {
642734
border-radius: 0.5rem;
643735
}
644736

737+
.rounded-full {
738+
border-radius: 9999px;
739+
}
740+
645741
.rounded-e-lg {
646742
border-start-end-radius: 0.5rem;
647743
border-end-end-radius: 0.5rem;
@@ -694,6 +790,11 @@ video {
694790
background-color: rgb(239 246 255 / var(--tw-bg-opacity));
695791
}
696792

793+
.bg-gray-300 {
794+
--tw-bg-opacity: 1;
795+
background-color: rgb(209 213 219 / var(--tw-bg-opacity));
796+
}
797+
697798
.px-5 {
698799
padding-left: 1.25rem;
699800
padding-right: 1.25rem;
@@ -718,6 +819,10 @@ video {
718819
text-align: left;
719820
}
720821

822+
.align-middle {
823+
vertical-align: middle;
824+
}
825+
721826
.text-sm {
722827
font-size: 0.875rem;
723828
line-height: 1.25rem;

src/class_providers/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,19 @@ pub trait TableClassesProvider {
5353
prop_class.to_string() + if selected { " selected" } else { "" }
5454
}
5555

56+
/// Get the classes for the elements inside of the cells of rows that are currently
57+
/// being loaded.
58+
/// The `prop_class` parameter contains the classes specified in the
59+
/// `loading_cell_class` prop of the [`TableContent`] component.
60+
fn loading_cell(&self, prop_class: &str) -> String {
61+
prop_class.to_string()
62+
}
63+
5664
/// Get the classes for the elements inside of the cells of rows that are currently
5765
/// being loaded. Usually this will be some loading indicator like a sceleton bar.
5866
/// The `prop_class` parameter contains the classes specified in the
59-
/// `loading_row_inner_class` prop of the [`TableContent`] component.
60-
fn loading_row_inner(&self, prop_class: &str) -> String {
67+
/// `loading_cell_inner_class` prop of the [`TableContent`] component.
68+
fn loading_cell_inner(&self, row_index: usize, prop_class: &str) -> String {
6169
prop_class.to_string()
6270
}
6371

src/components/row.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ pub fn DefaultErrorRowRenderer(err: String, index: usize, col_count: usize) -> i
4747
#[allow(unused_variables)]
4848
pub fn DefaultLoadingRowRenderer(
4949
class: Signal<String>,
50-
inner_class: Signal<String>,
50+
cell_class: Signal<String>,
51+
inner_cell_class: Signal<String>,
5152
index: usize,
5253
col_count: usize,
5354
) -> impl IntoView {
5455
view! {
5556
<tr class=class>
5657
{
5758
(0..col_count).map(|_| view! {
58-
<td>
59-
<div class=inner_class></div>
59+
<td class=cell_class>
60+
<div class=inner_cell_class></div>
6061
" "
6162
</td>
6263
}).collect_view()

src/components/table_content.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ renderer_fn!(
4949
);
5050

5151
renderer_fn!(
52-
LoadingRowRendererFn(class: Signal<String>, inner_class: Signal<String>, index: usize, col_count: usize)
52+
LoadingRowRendererFn(class: Signal<String>, cell_class: Signal<String>, cell_inner_class: Signal<String>, index: usize, col_count: usize)
5353
default DefaultLoadingRowRenderer
5454
);
5555

@@ -73,7 +73,8 @@ pub fn TableContent<Row, DataP, ClsP>(
7373
#[prop(optional, into)] thead_class: MaybeSignal<String>,
7474
#[prop(optional, into)] thead_row_class: MaybeSignal<String>,
7575
#[prop(optional, into)] tbody_class: MaybeSignal<String>,
76-
#[prop(optional, into)] loading_row_inner_class: MaybeSignal<String>,
76+
#[prop(optional, into)] loading_cell_class: MaybeSignal<String>,
77+
#[prop(optional, into)] loading_cell_inner_class: MaybeSignal<String>,
7778
#[prop(default = create_rw_signal(VecDeque::new()), into)] sorting: RwSignal<
7879
VecDeque<(usize, ColumnSort)>,
7980
>,
@@ -114,7 +115,8 @@ where
114115
let class_provider = ClsP::new();
115116

116117
let row_class = Signal::derive(move || row_class.get());
117-
let loading_row_inner_class = Signal::derive(move || loading_row_inner_class.get());
118+
let loading_cell_inner_class = Signal::derive(move || loading_cell_inner_class.get());
119+
let loading_cell_class = Signal::derive(move || loading_cell_class.get());
118120
let thead_class = Signal::derive(move || class_provider.thead(&thead_class.get()));
119121
let thead_row_class = Signal::derive(move || class_provider.thead_row(&thead_row_class.get()));
120122
let tbody_class = Signal::derive(move || class_provider.tbody(&tbody_class.get()));
@@ -433,7 +435,10 @@ where
433435
move || class_provider.row(i, false, &row_class.get())
434436
),
435437
Signal::derive(
436-
move || class_provider.loading_row_inner(&loading_row_inner_class.get())
438+
move || class_provider.loading_cell(&loading_cell_class.get())
439+
),
440+
Signal::derive(
441+
move || class_provider.loading_cell_inner(i, &loading_cell_inner_class.get())
437442
),
438443
i,
439444
Row::COLUMN_COUNT,

0 commit comments

Comments
 (0)