Skip to content

Commit 9a46566

Browse files
authored
fix: TimelineItem for default order (#1884)
* fix: TimelineItem for default order * fix: coderabbitai fix * fix: coderabbitai fix
1 parent 8383938 commit 9a46566

File tree

8 files changed

+44
-8
lines changed

8 files changed

+44
-8
lines changed

src/lib/timeline/Timeline.svelte

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
let { children, order = "default", class: className, ...restProps }: TimelineProps = $props();
99
1010
const theme = $derived(getTheme("timeline"));
11-
12-
$effect(() => {
13-
setContext<TimelineVariants["order"]>("order", order);
14-
});
11+
// svelte-ignore state_referenced_locally
12+
setContext<TimelineVariants["order"]>("order", order);
1513
const olCls = $derived(timeline({ order, class: clsx(theme, className) }));
1614
</script>
1715

@@ -23,10 +21,10 @@
2321
@component
2422
[Go to docs](https://flowbite-svelte.com/)
2523
## Type
26-
[TimelineProps](https://github.com/themesberg/flowbite-svelte/blob/main/src/lib/types.ts#L1953)
24+
[TimelineProps](https://github.com/themesberg/flowbite-svelte/blob/main/src/lib/types.ts#L1811)
2725
## Props
2826
@prop children
2927
@prop order = "default"
3028
@prop class: className
3129
@prop ...restProps
32-
-->
30+
-->

src/lib/timeline/TimelineItem.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
<script lang="ts">
23
import { getContext, untrack } from "svelte";
34
import { timelineItem, type TimelineVariants } from "./theme";
@@ -15,6 +16,7 @@
1516
isLast = false,
1617
svgClass,
1718
liClass,
19+
defaultDivClass,
1820
divClass,
1921
timeClass,
2022
h3Class,
@@ -46,10 +48,13 @@
4648
connector: connectorClass
4749
});
4850
51+
4952
const theme = $derived(getTheme("timelineItem"));
5053
let order = getContext<TimelineVariants["order"]>("order");
5154
52-
const { base, div, time, h3, svg, connector } = $derived(timelineItem({ order, color, isLast }));
55+
const { base, div, defaultDiv, time, h3, svg, connector } = $derived(timelineItem({ order, color, isLast }));
56+
57+
const defaultDivCls = $derived(defaultDivClass ? defaultDivClass : defaultDiv());
5358
5459
function formatDisplayDate(dateStr: string, format: DateFormat) {
5560
const date = new Date(dateStr);
@@ -101,6 +106,7 @@
101106
</div>
102107
{/if}
103108
{:else if date}
109+
<div class={defaultDivCls} aria-hidden="true"></div>
104110
<time datetime={date} class={time({ class: clsx(theme?.time, styling.time) })}>
105111
{datePrefix}
106112
{formatDisplayDate(date, dateFormat)}

src/lib/timeline/theme.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const groupItem = tv({
4040
img: "me-3 mb-3 w-12 h-12 rounded-full sm:mb-0",
4141
div: "text-gray-600 dark:text-gray-400",
4242
title: "text-base font-normal",
43-
span: "inline-flex items-center text-xs font-normal text-gray-500 dark:text-gray-400",
43+
span: "inline-flex items-center bg-gray-100 border border-gray-200 text-xs font-medium px-1.5 py-0.5 rounded",
4444
svg: "me-1 h-3 w-3"
4545
}
4646
});
@@ -109,6 +109,7 @@ export const timelineItem = tv({
109109
slots: {
110110
base: "relative",
111111
div: "",
112+
defaultDiv: "absolute w-2 h-2 bg-gray-200 rounded-full mt-1.5 -start-5 border border-buffer",
112113
time: "",
113114
h3: "",
114115
svg: "w-4 h-4",

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,7 @@ export interface TimelineItemProps extends TimelineItemVariants, HTMLLiAttribute
19641964
date: string;
19651965
svgClass?: string;
19661966
liClass?: string;
1967+
defaultDivClass?: string;
19671968
divClass?: string;
19681969
timeClass?: string;
19691970
h3Class?: string;

src/routes/docs-examples/components/timeline/Activity.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
import { Activity, ActivityItem } from "flowbite-svelte";
33
let activities = [
44
{
5+
id:'activity-1',
56
title:
67
'Bonnie moved <a href="/" class="font-semibold text-primary-600 dark:text-primary-500 hover:underline">Jese Leos</a> to <span class="bg-gray-100 text-gray-800 text-xs font-normal me-2 px-2.5 py-0.5 rounded-sm dark:bg-gray-600 dark:text-gray-300">Funny Group</span>',
78
date: "just now",
89
alt: "image alt here",
910
src: "/images/profile-picture-2.webp"
1011
},
1112
{
13+
id:'activity-2',
1214
title: "We don’t serve their kind here! What? Your droids. ",
1315
date: "2 hours ago",
1416
alt: "image alt here",
1517
src: "/images/profile-picture-2.webp",
1618
text: "The approach will not be easy. You are required to maneuver straight down this trench and skim the surface to this point. The target area is only two meters wide. "
1719
},
1820
{
21+
id:'activity-3',
1922
title: "They’ll have to wait outside. We don’t want them here. ",
2023
date: "1 day ago",
2124
alt: "image alt here",

src/routes/docs-examples/components/timeline/Grouped.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import { Group, GroupItem } from "flowbite-svelte";
33
let groupTimelines = [
44
{
5+
id:'group-1',
6+
name: '<span class="font-medium">Laura Romeros</span> likes <span class="font-medium">Bonnie Green\'s</span> post in <span class="font-medium"> How to start with Flowbite library</span>',
57
title:
68
'<span class="font-medium text-gray-900 dark:text-white">Jese Leos</span> likes <span class="font-medium text-gray-900 dark:text-white">Bonnie Green\'s</span> post in <span class="font-medium text-gray-900 dark:text-white"> How to start with Flowbite library</span>',
79
src: "/images/profile-picture-1.webp",
@@ -11,6 +13,8 @@
1113
comment: '"I wanted to share a webinar zeroheight."'
1214
},
1315
{
16+
id:'group-2',
17+
name: '<span class="font-medium">Jese Leos</span> likes <span class="font-medium">Bonnie Green\'s</span> post in <span class="font-medium"> How to start with Flowbite library</span>',
1418
title: '<span class="font-medium text-gray-900 dark:text-white">Bonnie Green</span> react to <span class="font-medium text-gray-900 dark:text-white">Thomas Lean\'s</span> comment',
1519
src: "/images/profile-picture-2.webp",
1620
alt: "alt here",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script lang="ts">
2+
import type { PageProps } from "./$types";
3+
4+
let { data }: PageProps = $props();
5+
let Content = $derived(data.content);
6+
</script>
7+
8+
<Content />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { PageLoad } from "./$types";
2+
import { error } from "@sveltejs/kit";
3+
4+
export const load: PageLoad = async ({ params }) => {
5+
try {
6+
const post = await import(`../${params.slug}.svelte`);
7+
const content = post.default;
8+
9+
return {
10+
content,
11+
};
12+
} catch (err) {
13+
throw error(404, `Timeline example "${params.slug}" not found`);
14+
}
15+
};

0 commit comments

Comments
 (0)