Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add a FigureShopify JS component #303

Merged
merged 10 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- Add a [FigureShopify](https://ui.studiometa.dev/-/components/atoms/FigureShopify/) component ([#303](https://github.com/studiometa/ui/pull/303))

## [v1.0.0-alpha.8](https://github.com/studiometa/ui/compare/1.0.0-alpha.7..1.0.0-alpha.8) (2024-09-25)

### Added
Expand Down
178 changes: 172 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions packages/docs/components/atoms/FigureShopify/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: FigureShopify examples
---

# Examples

## Simple

This is a simple example using a 1 Γ— 1 pixels transparent PNG as a placeholder.

<PreviewPlayground
:html="() => import('./stories/app.liquid?raw')"
:script="() => import('./stories/app.js?raw')"
/>

## Blurred placeholder

This example uses a small sized image with a maximum width of 10 pixels with a blur backdrop-filter as a placeholder.

<PreviewPlayground
:html="() => import('./stories/blurred.liquid?raw')"
:script="() => import('./stories/app.js?raw')"
/>
47 changes: 47 additions & 0 deletions packages/docs/components/atoms/FigureShopify/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
badges: [JS]
---

# FigureShopify <Badges :texts="$frontmatter.badges" />

Use the `FigureShopify` component to display responsive images with [Shopify CDN `image_url` API](https://shopify.dev/docs/api/liquid/filters/image_url).

## Table of content

- [Examples](./examples.html)
- [JS API](./js-api.html)

## Usage

Register the component in your JavaScript app and use it in your templates. The component will transform the `data-src` URL to load an image at the dimension of the `<img>` DOM element.

```js {2,8}
import { Base, createApp } from '@studiometa/js-toolkit';
import { FigureShopify } from '@studiometa/ui';

class App extends Base {
static config = {
name: 'Base',
components: {
Figure: FigureShopify,
}
};
}

export default createApp(App);
```

```liquid
<div class="card">
<figure data-component="Figure">
<img
data-ref="img"
src="placeholder.png"
data-src="{{ product | image_url }}"
width="200"
height="200"
alt="">
</figure>
</div>
```

31 changes: 31 additions & 0 deletions packages/docs/components/atoms/FigureShopify/js-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: FigureShopify JS API
outline: deep
---

# JS API

The `FigureShopify` class extends the [`Figure` class](/components/atoms/Figure/js-api.html) and adds support for TwicPics API.

## Options

### `step`

- Type: `number`
- Default: `50`

The step used to round up image size calculation. Default to `50`, which means that a size of `320Γ—380` will be rounded to `350Γ—400`.

### `crop`

- Type: `string`
- Default: `'top' | 'left' | 'right' | 'bottom' | 'center'`

If the image should be cropped (cover like), use the `crop` option with one the allowed value.

### `disable`

- Type: `boolean`
- Default: `false`

Use this option to disable the features of this component.
13 changes: 13 additions & 0 deletions packages/docs/components/atoms/FigureShopify/stories/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Base, createApp } from '@studiometa/js-toolkit';
import { FigureShopify } from '@studiometa/ui';

class App extends Base {
static config = {
name: 'App',
components: {
Figure: FigureShopify,
},
};
}

export default createApp(App, document.body);
Loading
Loading