From e282a7fb4bbd8fae33abc1747757e9c1cf1b06b6 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Tue, 13 Sep 2022 15:26:03 -0700 Subject: [PATCH] use code fences to document props in readme improve readme test: now includes checking readme lists correct type and default value for primitive-type props --- readme.md | 96 ++++++++++++++++++++++++++++++------ src/components/Slider.svelte | 5 +- src/lib/Masonry.svelte | 21 ++++---- tests/readme.test.ts | 22 +++++++-- tsconfig.json | 1 + 5 files changed, 114 insertions(+), 31 deletions(-) diff --git a/readme.md b/readme.md index 5a53ff7..25a5882 100644 --- a/readme.md +++ b/readme.md @@ -11,7 +11,7 @@ [![NPM version](https://img.shields.io/npm/v/svelte-bricks?color=blue&logo=NPM)](https://npmjs.com/package/svelte-bricks) [![Netlify Status](https://api.netlify.com/api/v1/badges/c3213069-e3cc-45ef-a446-b2358b9a35fb/deploy-status)](https://app.netlify.com/sites/svelte-bricks/deploys) [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/janosh/svelte-bricks/main.svg)](https://results.pre-commit.ci/latest/github/janosh/svelte-bricks/main) -[![Open in StackBlitz](https://img.shields.io/badge/Open%20in-StackBlitz-darkblue?logo=pytorchlightning)](https://stackblitz.com/github/janosh/svelte-bricks) +[![Open in StackBlitz](https://img.shields.io/badge/Open%20in-StackBlitz-darkblue?logo=stackblitz)](https://stackblitz.com/github/janosh/svelte-bricks) @@ -67,19 +67,87 @@ h) Additional optional props are: -- `items: (string | number | object)[]`: required -- `minColWidth: number = 330` (in `px`) -- `maxColWidth: number = 500` (in `px`) -- `gap: number = 20` (in `px`) -- `masonryWidth: number = 0`: Bound to the masonry `div`s width (in `px`). -- `masonryHeight: number = 0`: Bound to the masonry `div`s height (in `px`). -- `idKey: string = 'id'`: Name of the attribute to use as identifier if items are objects. -- `getId: (item) => string | number`: Custom function that maps masonry items to unique IDs. -- `animate: boolean = true`: Whether to [FLIP-animate](https://svelte.dev/tutorial/animate) masonry items when viewport resizing or other events cause `items` to rearrange. -- `style: string = ''`: Inline styles that will be applied to the top-level `div.masonry`. -- `duration: number = 200`: Transition duration in milli seconds when masonry items are rearranged or added/removed. Set to 0 to disable transitions. -- `class: string = ''`: Applies to the outer `div` wrapping all masonry columns. For use with CSS frameworks like Tailwind. -- `columnClass: string = ''`: Applies to each column `div`. +1. ```ts + animate: boolean = true + ``` + + Whether to [FLIP-animate](https://svelte.dev/tutorial/animate) masonry items when viewport resizing or other events cause `items` to rearrange. + +1. ```ts + class: string = '' + ``` + + Applies to the outer `div` wrapping all masonry columns. For use with CSS frameworks like Tailwind. + +1. ```ts + columnClass: string = '' + ``` + + Applies to each column `div`. + +1. ```ts + duration: number = 200 + ``` + + Transition duration in milli seconds when masonry items are rearranged or added/removed. Set to 0 to disable transitions. + +1. ```ts + gap: number = 20 + ``` + + Gap between columns and items within each column in `px`. + +1. ```ts + getId: (Item) => string | number = (item: Item) => { + if (typeof item === `number`) return item + if (typeof item === `string`) return item + return (item as Record)[idKey] + } + ``` + + Custom function that maps masonry items to unique IDs of type `string` or `number`. + +1. ```ts + idKey: string = 'id' + ``` + + Name of the attribute to use as identifier if items are objects. + +1. ```ts + items: (string | number | object)[] + ``` + + required + +1. ```ts + masonryHeight: number = 0 + ``` + + The masonry `div`s height in `px`. + +1. ```ts + masonryWidth: number = 0 + ``` + + The masonry `div`s width in `px`. + +1. ```ts + maxColWidth: number = 500 + ``` + + Maximum column width in `px`. + +1. ```ts + minColWidth: number = 330 + ``` + + Minimum column width in `px`. + +1. ```ts + style: string = '' + ``` + + Inline styles that will be applied to the top-level `div.masonry`. ## Styling diff --git a/src/components/Slider.svelte b/src/components/Slider.svelte index cc16a1e..b232b92 100644 --- a/src/components/Slider.svelte +++ b/src/components/Slider.svelte @@ -1,5 +1,8 @@