Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
refactor(knobs): Gallery optional/mandatory knobs -FRONT-926 (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joosthe committed Apr 1, 2020
1 parent c290ee3 commit abc9a1b
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 13 deletions.
27 changes: 27 additions & 0 deletions src/ec/packages/ec-component-gallery/ecl-gallery-overlay.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{% set _css_media_class = 'ecl-gallery__slider-media-container' %}
{% set _extra_attributes = '' %}
{% set _button_type = 'button' %}
{% set _button_variant = 'ghost' %}
{% set _overlay = overlay|default({}) %}
{% set _item = item|default({}) %}

Expand All @@ -47,6 +48,7 @@
<header class="ecl-gallery__close" data-ecl-gallery-overlay-header>
{% include '@ecl-twig/ec-component-button/ecl-button.html.twig' with _overlay.close|merge({
extra_classes: 'ecl-gallery__close-button',
variant: _button_variant,
type: _button_type,
extra_attributes: [
{ name: 'data-ecl-gallery-close' },
Expand All @@ -60,6 +62,14 @@
{% include '@ecl-twig/ec-component-button/ecl-button.html.twig' with _overlay.previous|merge({
extra_classes: 'ecl-gallery__slider-previous',
type: _button_type,
variant: _button_variant,
icon_position: 'before',
icon: _overlay.previous.icon|merge({
type: 'ui',
size: 'l',
transform: 'rotate-270',
name: 'corner-arrow',
}),
extra_attributes: [
{ name: 'data-ecl-gallery-overlay-previous' },
],
Expand All @@ -68,6 +78,13 @@
{% include '@ecl-twig/ec-component-button/ecl-button.html.twig' with _overlay.next|merge({
extra_classes: 'ecl-gallery__slider-next',
type: _button_type,
variant: _button_variant,
icon: _overlay.next.icon|merge({
type: 'ui',
size: 'l',
transform: 'rotate-90',
name: 'corner-arrow',
}),
extra_attributes: [
{ name: 'data-ecl-gallery-overlay-next' },
],
Expand All @@ -85,6 +102,11 @@
link: {
icon_position: 'after',
}|merge(_overlay.download.link),
icon: _overlay.download.icon|merge({
name: 'download',
size: 'fluid',
type: 'ui',
}),
extra_classes: 'ecl-gallery__download',
extra_attributes: [
{ name: 'data-ecl-gallery-overlay-download' },
Expand All @@ -95,6 +117,11 @@
link: {
icon_position: 'after',
}|merge(_overlay.share.link),
icon: _overlay.share.icon|merge({
name: 'share',
size: 'fluid',
type: 'general',
}),
extra_classes: 'ecl-gallery__share',
extra_attributes: [
{ name: 'data-ecl-gallery-overlay-share' },
Expand Down
8 changes: 8 additions & 0 deletions src/ec/packages/ec-component-gallery/ecl-gallery.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@
<section class="{{ _css_class }}" {{ _extra_attributes|raw }} data-ecl-gallery>
<ul class="ecl-gallery__list">
{% for _item in _items %}
{% set _item_class = _item.extra_classes ? _item.extra_classes : '' %}
{% set _item_attrs = _item.extra_attributes ? _item.extra_attributes : '' %}
{% include '@ecl-twig/ec-component-gallery/ecl-gallery-item.html.twig' with {
item: _item,
extra_attributes: _item_attrs,
extra_classes: _item_class
} only %}
{% endfor %}
</ul>
Expand All @@ -63,8 +67,12 @@
{% if _items[_selected_item_id] is not empty %}
{% set _selected_item = _items[_selected_item_id] %}
{% endif %}
{% set _overlay_class = overlay.extra_classes ? overlay.extra_classes : '' %}
{% set _overlay_attrs = overlay.extra_attributes ? overlay.extra_attributes : '' %}
{% include '@ecl-twig/ec-component-gallery/ecl-gallery-overlay.html.twig' with {
overlay: _overlay,
extra_attributes: _overlay_attrs,
extra_classes: _overlay_class,
item: _selected_item
} only %}
</section>
Expand Down
169 changes: 156 additions & 13 deletions src/ec/packages/ec-component-gallery/gallery.story.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,172 @@
/* eslint-disable no-param-reassign */
import { storiesOf } from '@storybook/html';
import { withKnobs } from '@storybook/addon-knobs';
import { withKnobs, text, select } from '@storybook/addon-knobs';
import { withNotes } from '@ecl-twig/storybook-addon-notes';
import { getExtraKnobs, buttonLabels } from '@ecl-twig/story-utils';
import withCode from '@ecl-twig/storybook-addon-code';

import defaultSprite from '@ecl/ec-resources-icons/dist/sprites/icons.svg';
import gallery from './ecl-gallery.html.twig';

import data from './demo/data';
import dataDefault from './demo/data';
import notes from './README.md';

data.items.forEach(item => {
if (item.icon) {
item.icon.path = defaultSprite; // eslint-disable-line no-param-reassign
const prepareGallery = data => {
data.items.forEach((item, i) => {
item.share_path = select(
`items[${i}].share_path`,
[item.share_path],
item.share_path,
buttonLabels.required
);
item.description = text(
`items[${i}].description`,
item.description,
buttonLabels.optional
);
item.meta = text(`items[${i}].meta`, item.meta, buttonLabels.optional);
item.alt = text(`items[${i}].alt`, item.alt, buttonLabels.optional);
item.extra_classes = text(
`items[${i}].extra_classes`,
item.extra_classes,
buttonLabels.optional
);
if (!item.extra_attributes) {
item.extra_attributes = [{}];
}
item.extra_attributes[0].name = text(
`items[${i}].extra_attributes[0].name`,
'',
buttonLabels.optional
);
item.extra_attributes[0].value = text(
`items[${i}].extra_attributes[0].value`,
item.extra_attributes[0].value,
buttonLabels.optional
);
if (!item.extra_attributes[0].value) {
delete item.extra_attributes[0].value;
}
if (item.extra_attributes[0].name === '') {
delete item.extra_attributes;
}
if (item.icon) {
item.icon.path = select(
`items[${i}].icon.path`,
[defaultSprite],
defaultSprite,
buttonLabels.required
);
}
if (item.video) {
item.video.sources[0].src = select(
`items[${i}].video.sources[0].src`,
[item.video.sources[0].src],
item.video.sources[0].src,
buttonLabels.required
);
}
});
data.items.selected_item_id = text(
'items.selected_item_id',
data.items.selected_item_id,
buttonLabels.optional
);
// Overlay knobs.
data.overlay.counter_separator = text(
'overlay.counter_separator',
data.overlay.counter_separator,
buttonLabels.required
);
data.overlay.extra_classes = text(
'data.overlay.extra_classes',
'',
buttonLabels.optional
);
if (!data.overlay.extra_attributes) {
data.overlay.extra_attributes = [{}];
}
data.overlay.extra_attributes[0].name = text(
'data.overlay.extra_attributes[0].name',
'',
buttonLabels.optional
);
data.overlay.extra_attributes[0].value = text(
`data.overlay.extra_attributes[0].value`,
data.overlay.extra_attributes[0].value,
buttonLabels.optional
);
if (!data.overlay.extra_attributes[0].value) {
delete data.overlay.extra_attributes[0].value;
}
if (data.overlay.extra_attributes[0].name === '') {
delete data.overlay.extra_attributes;
}
});
data.overlay.close.icon.path = defaultSprite;
data.overlay.previous.icon.path = defaultSprite;
data.overlay.next.icon.path = defaultSprite;
data.overlay.download.icon.path = defaultSprite;
data.overlay.share.icon.path = defaultSprite;
data.overlay.close.label = text(
'overlay.close.label',
data.overlay.close.label,
buttonLabels.required
);
data.overlay.close.icon.path = select(
'overlay.close.icon.path',
[defaultSprite],
defaultSprite,
buttonLabels.required
);
data.overlay.previous.label = text(
'overlay.previous.label',
data.overlay.previous.label,
buttonLabels.required
);
data.overlay.previous.icon.path = select(
'overlay.previous.icon.path',
[defaultSprite],
defaultSprite,
buttonLabels.required
);
data.overlay.next.label = text(
'overlay.next.label',
data.overlay.next.label,
buttonLabels.required
);
data.overlay.next.icon.path = select(
'overlay.next.icon.path',
[defaultSprite],
defaultSprite,
buttonLabels.required
);
data.overlay.download.link.label = text(
'overlay.download.link.label',
data.overlay.download.link.label,
buttonLabels.required
);
data.overlay.download.link.path = text(
'overlay.download.link.path',
data.overlay.download.link.path,
buttonLabels.required
);
data.overlay.download.icon.path = select(
'overlay.download.icon.path',
[defaultSprite],
defaultSprite,
buttonLabels.required
);
data.overlay.share.icon.path = select(
'overlay.share.icon.path',
[defaultSprite],
defaultSprite,
buttonLabels.required
);

getExtraKnobs(data);

return data;
};

storiesOf('Components/Gallery', module)
.addDecorator(withKnobs)
.addDecorator(withCode)
.addDecorator(withNotes)
.add('default', () => gallery(data), {
notes: { markdown: notes, json: data },
.add('default', () => gallery(prepareGallery(dataDefault)), {
notes: { markdown: notes, json: dataDefault },
});

0 comments on commit abc9a1b

Please sign in to comment.