0.0.16 • Published 2 years ago

svelte-gallery-view v0.0.16

Weekly downloads
-
License
LGPL-3.0+
Repository
github
Last release
2 years ago

Svelte Gallery View

A collection of Svalte components for displaying photos, and currently focusing on a component that provides a layout used by Google Photos / 500px.

Screenshot

npm.io Known Vulnerabilities Renovate enabled PRs Welcome

Table of Contents

  1. Features
  2. Getting started
  3. APIs
  4. Developing
  5. Testing
  6. Publishing to npm
  7. Frequently Asked Questions

Features

GalleryView (default)

GalleryView provides a layout used by Google Photos and 500px as what shows in the screenshot above which I think could be used in most scenarios. It displays photos with the same height in each line and keeps the original aspect ratio of each photo.

The implementation was inspired by a post Pure CSS implementation of Google Photos / 500px image layout.

Getting Started

  1. Install the module:
npm install svelte-gallery-view
  1. Import the module:
import GalleryView from 'svelte-gallery-view'
  1. Add GalleryView to your view:
<GalleryView
    photos={photos}
    gutter={2}
    baseHeight={200}
    photoClass="photo"
    onPhotoClick={(photo) => {
        showPhotoDetails(photo.id);
    }}
/>

APIs

GalleryView

Properties

  • photos (required)
interface Photo {
	/**
 	* URL or the function to retrieve URL of the photo.
    */
	url: string | (() => CancelablePromise<string>);
	/**
 	* Width of the photo.
    */
	width: number;
	/**
 	* Height of the photo.
    */
	height: number;
	/**
 	* Extra information which shown as a tooltip text on the photo.
    */
	title?: string;
	/**
 	* Any properties could be useful in callback function onPhotoClick.
    */
	[key: string]: unknown;
};

//...

photos: Photo[] = [];
  • baseHeight (optional, default: 200)
/**
/* Base height of each line, in px. The final height of each line
/* would be various because of adjustments.
*/
baseHeight: number = 200;
  • gutter (optional, default: 2)
/**
/* Gap between every two photos, in px.
*/
gutter: number = 2;
  • photoClass (optional, default: undefined)
/**
/* Extra class names would be applied to the photo elements.
*/
photoClass: string | undefined;
  • onPhotoClick (optional, default: undefined)
/**
/* Callback function which handles click events triggered by each photo.
*/
onPhotoClick: ((photo: Photo) => any) | undefined;

Developing

  1. Start SvelteKit:
npm run dev
  1. Edit the component files in src/lib, save it and watch the magic happens.

  2. Navigate to localhost:7070 to see the components live.

Testing

Interaction testing

This is a simple and intuitive method that can be done through Storybook, with the help of Cypress. And example and pre-made test scripts can be found in this repository, and more info can be found in Storybook's docs.

Snapshot testing

In this repo you'll find a basic workflow that uses Chromatic for snapshot testing.

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago