Skip to content

Commit

Permalink
Merge tag '0.2.23' into develop
Browse files Browse the repository at this point in the history
v0.2.23
  • Loading branch information
titouanmathis committed Nov 17, 2022
2 parents e8bacfe + 0553abf commit 2934b32
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 22 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## v0.2.23 (2022-11-17)

### Added
- **FigureTwicpics:**
- Add support for Twicpics placeholders ([6c55dbe](https://github.com/studiometa/ui/commit/6c55dbe))

### Fixed
- Fix dead links in the docs preventing build ([e10257b](https://github.com/studiometa/ui/commit/e10257b))
- **FigureTwicpics:**
- Fix a bug where image were loaded multiple times ([a3480ca](https://github.com/studiometa/ui/commit/a3480ca))

## v0.2.22 (2022-11-17)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "studiometa/ui",
"version": "0.2.22",
"version": "0.2.23",
"description": "A set of opiniated, unstyled and accessible components.",
"license": "MIT",
"require": {
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/ui-workspace",
"version": "0.2.22",
"version": "0.2.23",
"private": true,
"workspaces": [
"packages/*"
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/components/atoms/FigureTwicpics/js-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ outline: deep

# JS API

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

## Options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
lazy: false,
twic_domain: 'studiometa.twic.pics',
twic_path: 'ui',
twic_transform: { focus: 'auto', crop: '300x300', placeholder: 'auto' }
twic_transform: { focus: 'auto', crop: '300x300', placeholder: 'auto' },
twic_placeholder: 'maincolor'
} %}
{% include '@ui/atoms/Figure/FigureTwicpics.twig' with {
src: '/-/image-2.jpg',
width: '500',
height: '500',
twic_placeholder: 'meancolor'
} %}
{% include '@ui/atoms/Figure/FigureTwicpics.twig' with {
src: '/-/image-3.jpg',
width: '500',
height: '500',
twic_transform: { focus: 'auto', crop: '300x300', placeholder: 'auto' }
twic_transform: { focus: 'auto', crop: '300x300', placeholder: 'auto' },
twic_placeholder: 'preview'
} %}
</div>
2 changes: 1 addition & 1 deletion packages/docs/components/atoms/FigureTwicpics/twig-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ outline: deep

# Twig API

The `FigureTwicpics` template extends the [`Figure` template](/atoms/Figure/twig-api.html) and adds support for TwicPics API.
The `FigureTwicpics` template extends the [`Figure` template](/components/atoms/Figure/twig-api.html) and adds support for TwicPics API.

## Parameters

Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/ui-docs",
"version": "0.2.22",
"version": "0.2.23",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/ui-tests",
"version": "0.2.22",
"version": "0.2.23",
"private": true,
"type": "module",
"scripts": {
Expand Down
9 changes: 8 additions & 1 deletion packages/ui/atoms/Figure/Figure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ export class Figure<T extends BaseProps = BaseProps> extends withMountWhenInView
this.$refs.img.src = value;
}

/**
* Get the original source.
*/
get original() {
return this.$refs.img.dataset.src;
}

/**
* Load on mount.
*/
Expand All @@ -66,7 +73,7 @@ export class Figure<T extends BaseProps = BaseProps> extends withMountWhenInView
throw new Error('[Figure] The `img` ref must be an `<img>` element.');
}

const { src } = img.dataset;
const src = this.original;

if (this.$options.lazy && src && src !== this.src) {
let tempImg = new Image();
Expand Down
21 changes: 14 additions & 7 deletions packages/ui/atoms/Figure/FigureTwicpics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class FigureTwicpics<T extends BaseProps = BaseProps> extends Figure<
/**
* Get the Twicpics path.
*/
get path():string {
get path(): string {
return withoutTrailingSlash(withoutLeadingSlash(this.$options.path));
}

Expand All @@ -67,15 +67,22 @@ export class FigureTwicpics<T extends BaseProps = BaseProps> extends Figure<
}

/**
* Add Twicpics transforms, path and domain to the URL.
* Get formattted original source.
*/
set src(value: string) {
const url = new URL(value, 'https://localhost');
get original() {
return this.formatSrc(super.original);
}

/**
* Format the source for Twicpics.
*/
formatSrc(src: string): string {
const url = new URL(src, 'https://localhost');
url.host = this.domain;
url.port = '';

if (this.path) {
url.pathname = `/${this.path}${url.pathname}`
url.pathname = `/${this.path}${url.pathname}`;
}

const width = normalizeSize(this, 'offsetWidth');
Expand All @@ -90,14 +97,14 @@ export class FigureTwicpics<T extends BaseProps = BaseProps> extends Figure<

url.search = decodeURIComponent(url.search);

super.src = url.toString();
return url.toString();
}

/**
* Reassign the source from the original on resize.
*/
resized() {
this.src = this.$refs.img.dataset.src;
this.src = this.original;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/ui/atoms/Figure/FigureTwicpics.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* The Twicpics path to use.
* @param object $twic_transform
* Custom transforms for Twicpics.
* @param string $twic_placeholder
* Define how the placeholder should be treated. Possible values: meancolor, maincolor, preview.
*/
#}

Expand Down Expand Up @@ -37,3 +39,7 @@
{% set src = src.withPath(twic_path ~ src.getPath()) %}
{% set attr = (attr ?? {})|merge({ data_option_path: twic_path }) %}
{% endif %}

{% if twic_placeholder is defined %}
{% set placeholder = src.withQueryParameter('twic', '%s/output=%s'|format(twic_param, twic_placeholder)) %}
{% endif %}
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/ui",
"version": "0.2.22",
"version": "0.2.23",
"description": "A set of opiniated, unstyled and accessible components",
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit 2934b32

Please sign in to comment.