|
10 | 10 | import { Badge, InteractiveText, Layout, Popover, Typography } from '@appwrite.io/pink-svelte';
|
11 | 11 | import { menuOpen } from '$lib/components/menu/store';
|
12 | 12 |
|
13 |
| - export let time: string = ''; |
| 13 | + export let time: string | null = null; |
14 | 14 | export let placement: ComponentProps<Popover>['placement'] = 'bottom';
|
15 | 15 |
|
16 | 16 | function timeDifference(dateString: string): string {
|
|
75 | 75 | $: timeToString = time ? timeDifference(time) : 'Invalid time';
|
76 | 76 | </script>
|
77 | 77 |
|
78 |
| -<Popover let:show let:hide {placement} portal> |
79 |
| - <button |
80 |
| - on:mouseenter={() => { |
81 |
| - if (!$menuOpen) { |
82 |
| - setTimeout(show, 150); |
83 |
| - } |
84 |
| - }} |
85 |
| - on:mouseleave={() => hidePopover(hide)}> |
86 |
| - <slot>{capitalize(timeFromNow(time))}</slot> |
87 |
| - </button> |
88 |
| - |
89 |
| - <div |
90 |
| - let:hide |
91 |
| - slot="tooltip" |
92 |
| - role="tooltip" |
93 |
| - style:padding="1rem" |
94 |
| - style:margin="-1rem" |
95 |
| - on:mouseenter={() => (isMouseOverTooltip = true)} |
96 |
| - on:mouseleave={() => hidePopover(hide, false)}> |
97 |
| - <Layout.Stack gap="s" alignContent="flex-start"> |
98 |
| - <!-- `Raw time` as per design --> |
99 |
| - <Typography.Caption color="--fgcolor-neutral-tertiary" variant="400"> |
100 |
| - {#if $$slots.title} |
101 |
| - <slot name="title" /> |
102 |
| - {:else} |
103 |
| - {timeToString} |
104 |
| - {/if} |
105 |
| - </Typography.Caption> |
106 |
| - |
107 |
| - <!-- `Absolute time` as per design --> |
108 |
| - <Layout.Stack gap="xxs"> |
109 |
| - <Layout.Stack |
110 |
| - direction="row" |
111 |
| - alignItems="center" |
112 |
| - alignContent="center" |
113 |
| - justifyContent="space-between"> |
114 |
| - <InteractiveText |
115 |
| - isVisible |
116 |
| - variant="copy" |
117 |
| - text={toLocaleDateTime(time, false, 'UTC')} |
118 |
| - value={toISOString(time)} /> |
119 |
| - |
120 |
| - <Badge variant="secondary" content="UTC" size="xs" /> |
121 |
| - </Layout.Stack> |
122 |
| - |
123 |
| - <Layout.Stack |
124 |
| - direction="row" |
125 |
| - alignItems="center" |
126 |
| - alignContent="center" |
127 |
| - justifyContent="space-between"> |
128 |
| - <InteractiveText |
129 |
| - isVisible |
130 |
| - variant="copy" |
131 |
| - text={toLocaleDateTime(time)} |
132 |
| - value={toLocalDateTimeISO(time)} /> |
133 |
| - <Badge variant="secondary" content="Local" size="xs" /> |
| 78 | +{#if time} |
| 79 | + <Popover let:show let:hide {placement} portal> |
| 80 | + <button |
| 81 | + on:mouseenter={() => { |
| 82 | + if (!$menuOpen) { |
| 83 | + setTimeout(show, 150); |
| 84 | + } |
| 85 | + }} |
| 86 | + on:mouseleave={() => hidePopover(hide)}> |
| 87 | + <slot>{capitalize(timeFromNow(time))}</slot> |
| 88 | + </button> |
| 89 | + |
| 90 | + <div |
| 91 | + let:hide |
| 92 | + slot="tooltip" |
| 93 | + role="tooltip" |
| 94 | + style:padding="1rem" |
| 95 | + style:margin="-1rem" |
| 96 | + on:mouseenter={() => (isMouseOverTooltip = true)} |
| 97 | + on:mouseleave={() => hidePopover(hide, false)}> |
| 98 | + <Layout.Stack gap="s" alignContent="flex-start"> |
| 99 | + <!-- `Raw time` as per design --> |
| 100 | + <Typography.Caption color="--fgcolor-neutral-tertiary" variant="400"> |
| 101 | + {#if $$slots.title} |
| 102 | + <slot name="title" /> |
| 103 | + {:else} |
| 104 | + {timeToString} |
| 105 | + {/if} |
| 106 | + </Typography.Caption> |
| 107 | + |
| 108 | + <!-- `Absolute time` as per design --> |
| 109 | + <Layout.Stack gap="xxs"> |
| 110 | + <Layout.Stack |
| 111 | + direction="row" |
| 112 | + alignItems="center" |
| 113 | + alignContent="center" |
| 114 | + justifyContent="space-between"> |
| 115 | + <InteractiveText |
| 116 | + isVisible |
| 117 | + variant="copy" |
| 118 | + text={toLocaleDateTime(time, false, 'UTC')} |
| 119 | + value={toISOString(time)} /> |
| 120 | + |
| 121 | + <Badge variant="secondary" content="UTC" size="xs" /> |
| 122 | + </Layout.Stack> |
| 123 | + |
| 124 | + <Layout.Stack |
| 125 | + direction="row" |
| 126 | + alignItems="center" |
| 127 | + alignContent="center" |
| 128 | + justifyContent="space-between"> |
| 129 | + <InteractiveText |
| 130 | + isVisible |
| 131 | + variant="copy" |
| 132 | + text={toLocaleDateTime(time)} |
| 133 | + value={toLocalDateTimeISO(time)} /> |
| 134 | + <Badge variant="secondary" content="Local" size="xs" /> |
| 135 | + </Layout.Stack> |
134 | 136 | </Layout.Stack>
|
135 | 137 | </Layout.Stack>
|
136 |
| - </Layout.Stack> |
137 |
| - </div> |
138 |
| -</Popover> |
| 138 | + </div> |
| 139 | + </Popover> |
| 140 | +{:else} |
| 141 | + <Typography.Text>{time === null || time === undefined ? 'null' : time}</Typography.Text> |
| 142 | +{/if} |
0 commit comments