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 placeholder_color param to Figure #104

Merged
merged 6 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
- **Figure**
- Add the `placeholder_color` param to Figure ([51f625d](https://github.com/studiometa/ui/commit/51f625d), [#100](https://github.com/studiometa/ui/issues/100))
titouanmathis marked this conversation as resolved.
Show resolved Hide resolved

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

### Added
Expand Down
25 changes: 24 additions & 1 deletion packages/docs/components/atoms/Figure/twig-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ Use absolute position on the image holder instead of relative.

Wether to enable the display of the figure inline or not. When `inline`, the root element will have a max-width set corresponding to the `width` given. Use with caution.

### `placeholder`

- Type: `string`

Use a custom placeholder instead of the generic placeholder :
antoine4livre marked this conversation as resolved.
Show resolved Hide resolved
```twig
{%- set placeholder_markup -%}
<svg xmlns="http://www.w3.org/2000/svg"
viewbox="0 0 {{ width }} {{ height }}"
width="{{ width }}"
height="{{ height }}">
<rect x="0" y="0" width="{{ width }}" height="{{ height }}" fill="{{ placeholder_color }}" />
</svg>
{%- endset -%}
{% set generic_placeholder = 'data:image/svg+xml,%s'|format(placeholder_markup|url_encode) %}
```

### `placeholder_color`

- Type: `string`
- Default: `"#eee"`

Set an hexadecimal custom color for the generic placeholder.
antoine4livre marked this conversation as resolved.
Show resolved Hide resolved

### `attr`

- Type: `array`
Expand All @@ -100,7 +124,6 @@ Custom attributes for the image element.

Custom attributes for the caption element.


## Blocks

### `caption`
Expand Down
7 changes: 6 additions & 1 deletion packages/ui/atoms/Figure/Figure.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
* @param boolean $inline
* Wether to enable the display of the figure inline or not. When `inline`, the root element
* will have a max-width set corresponding to the `width` given. Use with caution.
* @param string $placeholder
* Use a custom placeholder.
* @param string $placeholder_color
* Set an hexadecimal custom color for the generic placeholder.
* @param array $attr
* Custom attributes for the root element.
* @param array $inner_attr
Expand All @@ -44,12 +48,13 @@
{% set width = width|default(100) %}
{% set lazy = lazy ?? true %}

{% set placeholder_color = placeholder_color|default('#eee') %}
{%- set placeholder_markup -%}
<svg xmlns="http://www.w3.org/2000/svg"
viewbox="0 0 {{ width }} {{ height }}"
width="{{ width }}"
height="{{ height }}">
<rect x="0" y="0" width="{{ width }}" height="{{ height }}" fill="#eee" />
<rect x="0" y="0" width="{{ width }}" height="{{ height }}" fill="{{ placeholder_color }}" />
</svg>
{%- endset -%}
{% set generic_placeholder = 'data:image/svg+xml,%s'|format(placeholder_markup|url_encode) %}
Expand Down