Skip to content

Commit c476fdf

Browse files
authored
Merge pull request #558 from techniq/calendar-html
docs(Calendar): Add html example
2 parents dc9ae2e + 9d4f93d commit c476fdf

3 files changed

Lines changed: 72 additions & 2 deletions

File tree

.changeset/four-taxes-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'layerchart': patch
3+
---
4+
5+
fix(Calendar): Pass `cellSize` to children snippet (useful when responsive)

packages/layerchart/src/lib/components/Calendar.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*/
4444
tooltipContext?: TooltipContextValue;
4545
46-
children?: Snippet<[{ cells: CalendarCell[] }]>;
46+
children?: Snippet<[{ cells: CalendarCell[]; cellSize: [number, number] }]>;
4747
} & Omit<
4848
RectPropsWithoutHTML,
4949
'children' | 'x' | 'y' | 'width' | 'height' | 'fill' | 'onpointermove' | 'onpointerleave'
@@ -117,7 +117,7 @@
117117
</script>
118118

119119
{#if children}
120-
{@render children({ cells })}
120+
{@render children({ cells, cellSize })}
121121
{:else}
122122
{#each cells as cell}
123123
<Rect

packages/layerchart/src/routes/docs/components/Calendar/+page.svelte

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,68 @@
183183
</Chart>
184184
</div>
185185
</Preview>
186+
187+
<h2>Html</h2>
188+
189+
<Preview {data}>
190+
<div class="h-[200px] p-4 border rounded-sm">
191+
<Chart
192+
{data}
193+
x="date"
194+
c="value"
195+
cScale={scaleThreshold().unknown('transparent')}
196+
cDomain={[25, 50, 75]}
197+
cRange={[
198+
'var(--color-primary-100)',
199+
'var(--color-primary-300)',
200+
'var(--color-primary-500)',
201+
'var(--color-primary-700)',
202+
]}
203+
padding={{ top: 13 }}
204+
>
205+
{#snippet children({ context })}
206+
<Layer type="html">
207+
<Calendar start={firstDayOfYear} end={lastDayOfYear} tooltipContext={context.tooltip}>
208+
{#snippet children({ cells, cellSize })}
209+
{#each cells as cell}
210+
<div
211+
class="absolute p-px"
212+
style:left="{cell.x}px"
213+
style:top="{cell.y}px"
214+
style:width="{cellSize[0]}px"
215+
style:height="{cellSize[1]}px"
216+
onpointermove={(e) => context.tooltip?.show(e, cell.data)}
217+
onpointerleave={(e) => context.tooltip?.hide()}
218+
>
219+
<div
220+
class="w-full h-full rounded-sm"
221+
style:background-color={cell.color === 'transparent'
222+
? 'rgb(0 0 0 / 5%)'
223+
: cell.color}
224+
></div>
225+
</div>
226+
{/each}
227+
{/snippet}
228+
</Calendar>
229+
</Layer>
230+
231+
<Tooltip.Root>
232+
{#snippet children({ data })}
233+
<Tooltip.Header value={data.date} format="day" />
234+
235+
{#if data.value != null}
236+
<Tooltip.List>
237+
<Tooltip.Item
238+
label="value"
239+
value={data.value}
240+
format="integer"
241+
valueAlign="right"
242+
/>
243+
</Tooltip.List>
244+
{/if}
245+
{/snippet}
246+
</Tooltip.Root>
247+
{/snippet}
248+
</Chart>
249+
</div>
250+
</Preview>

0 commit comments

Comments
 (0)