Skip to content

Commit

Permalink
Feat(web-twig): Extend Stack component #JALL-107
Browse files Browse the repository at this point in the history
  • Loading branch information
dlouhak committed Apr 27, 2023
1 parent c79319b commit def3ef1
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 7 deletions.
14 changes: 9 additions & 5 deletions packages/web-twig/src/Resources/components/Stack/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Stack

This is Twig implementation of the [Stack] component.
[Stack] is a component that allows you to compose elements vertically.

Basic example usage:

Expand All @@ -15,7 +15,7 @@ Basic example usage:
Advanced example usage:

```html
<Stack elementType="ul">
<Stack elementType="ul" hasMiddleDividers hasTopDivider hasBottomDivider>
<li>
<div>List item 1</div>
</li>
Expand Down Expand Up @@ -50,9 +50,13 @@ Without lexer:

## API

| Prop name | Type | Default | Required | Description |
| ------------- | -------- | ------- | -------- | ------------------ |
| `elementType` | `string` | `div` | no | HTML tag to render |
| Prop name | Type | Default | Required | Description |
| ------------------- | -------- | ------- | -------- | -------------------------------------- |
| `elementType` | `string` | `div` | no | Element type of the wrapper element |
| `hasBottomDivider` | `bool` | `false` | no | Render a divider after the last item |
| `hasMiddleDividers` | `bool` | `false` | no | Render dividers between items |
| `hasSpacing` | `bool` | `false` | no | Apply a spacing between items |
| `hasTopDivider` | `bool` | `false` | no | Render a divider before the first item |

You can add `id`, `data-*` or `aria-*` attributes to further extend component's
descriptiveness and accessibility. Also, UNSAFE styling props are available,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,23 @@
{# Stack Blocks #}
{% include '@components/Stack/stories/StackBlocks.twig' %}

<div class="spirit-v1-stack-no-default-gap">
<h2 class="docs-Heading">Feature flag <code>spirit-v1-stack-no-default-gap</code></h2>

{# Stack Blocks with `spirit-v1-stack-no-default-gap` #}
{% include '@components/Stack/stories/StackV1NoDefaultGapBlocks.twig' %}

{# Stack Blocks with `spirit-v1-stack-no-default-gap` and Vertical Spacing #}
{% include '@components/Stack/stories/StackV1NoDefaultGapBlocksWithVerticalSpacing.twig' %}

{# Stack Blocks with `spirit-v1-stack-no-default-gap`, Inner Dividers and Vertical Spacing #}
{% include '@components/Stack/stories/StackV1NoDefaultGapBlocksWithInnerDividersAndVerticalSpacing.twig' %}

{# Stack Blocks with `spirit-v1-stack-no-default-gap`, Inner and Outer Dividers and Vertical Spacing #}
{% include '@components/Stack/stories/StackV1NoDefaultGapBlocksWithInnerAndOuterDividersAndVerticalSpacing.twig' %}

{# Stack Blocks with `spirit-v1-stack-no-default-gap`, Inner Dividers without Vertical Spacing #}
{% include '@components/Stack/stories/StackV1NoDefaultGapBlocksWithInnerDividersWithoutVerticalSpacing.twig' %}
</div>

{% endblock %}
17 changes: 16 additions & 1 deletion packages/web-twig/src/Resources/components/Stack/Stack.twig
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
{# API #}
{%- set props = props | default([]) -%}
{%- set _elementType = props.elementType | default('div') -%}
{%- set _hasBottomDivider = props.hasBottomDivider | default(false) | boolprop -%}
{%- set _hasMiddleDividers = props.hasMiddleDividers | default(false) | boolprop -%}
{%- set _hasSpacing = props.hasSpacing | default(false) | boolprop -%}
{%- set _hasTopDivider = props.hasTopDivider | default(false) | boolprop -%}

{# Class names #}
{%- set _rootClassName = _spiritClassPrefix ~ 'Stack' -%}
{%- set _rootBottomDividerClassName = _hasBottomDivider ? _spiritClassPrefix ~ 'Stack--hasBottomDivider' : null -%}
{%- set _rootMiddleDividersClassName = _hasMiddleDividers ? _spiritClassPrefix ~ 'Stack--hasMiddleDividers' : null -%}
{%- set _rootSpacingClassName = _hasSpacing ? _spiritClassPrefix ~ 'Stack--hasSpacing' : null -%}
{%- set _rootTopDividerClassName = _hasTopDivider ? _spiritClassPrefix ~ 'Stack--hasTopDivider' : null -%}

{# Miscellaneous #}
{%- set _styleProps = useStyleProps(props) -%}
{%- set _classNames = [ _rootClassName, _styleProps.className ] -%}
{%- set _classNames = [
_rootClassName,
_rootBottomDividerClassName,
_rootMiddleDividersClassName,
_rootSpacingClassName,
_rootTopDividerClassName,
_styleProps.className,
] -%}

<{{ _elementType }} {{ mainProps(props) }} {{ styleProp(_styleProps) }} {{ classProp(_classNames) }}>
{%- block content %}{% endblock -%}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<section class="docs-Section">

<h3 class="docs-Heading">Stacked Blocks</h3>

<Stack elementType="ul">
{% for i in 1..3 %}
<li>
<div class="docs-Box">
Block {{ i }}
</div>
</li>
{% endfor %}
</Stack>

</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<section class="docs-Section">

<h3 class="docs-Heading">Stacked Blocks with Inner and Outer Dividers and Vertical Spacing</h3>

<Stack elementType="ul" hasSpacing hasMiddleDividers hasTopDivider hasBottomDivider>
{% for i in 1..3 %}
<li>
<div class="docs-Box">
Block {{ i }}
</div>
</li>
{% endfor %}
</Stack>

</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<section class="docs-Section">

<h3 class="docs-Heading">Stacked Blocks with Inner Dividers and Vertical Spacing</h3>

<Stack elementType="ul" hasSpacing hasMiddleDividers>
{% for i in 1..3 %}
<li>
<div class="docs-Box">
Block {{ i }}
</div>
</li>
{% endfor %}
</Stack>

</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<section class="docs-Section">

<h3 class="docs-Heading">Stacked Blocks with Vertical Spacing</h3>

<Stack elementType="ul" hasMiddleDividers>
{% for i in 1..3 %}
<li>
<div class="docs-Box">
Block {{ i }}
</div>
</li>
{% endfor %}
</Stack>

</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<section class="docs-Section">

<h3 class="docs-Heading">Stacked Blocks with Vertical Spacing</h3>

<Stack elementType="ul" hasSpacing>
{% for i in 1..3 %}
<li>
<div class="docs-Box">
Block {{ i }}
</div>
</li>
{% endfor %}
</Stack>

</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div class="Stack Stack--hasBottomDivider Stack--hasMiddleDividers Stack--hasTopDivider">
<div>
Block 1
</div>
<div>
Block 2
</div>
<div>
Block 3
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<ul class="Stack Stack--hasBottomDivider Stack--hasMiddleDividers Stack--hasSpacing Stack--hasTopDivider">
<li>
<div>
List item 1
</div>
</li>
<li>
<div>
List item 1
</div>
</li>
<li>
<div>
List item 1
</div>
</li>
</ul>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<li>
<div>List item 1</div>
</li>
</Stack>
</Stack>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Stack hasBottomDivider hasMiddleDividers hasTopDivider>
<div>Block 1</div>
<div>Block 2</div>
<div>Block 3</div>
</Stack>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Stack elementType="ul" hasBottomDivider hasMiddleDividers hasTopDivider hasSpacing>
<li>
<div>List item 1</div>
</li>
<li>
<div>List item 1</div>
</li>
<li>
<div>List item 1</div>
</li>
</Stack>

0 comments on commit def3ef1

Please sign in to comment.