Skip to content

Commit

Permalink
Refactor(web-twig): Rename Tabs components to same names as we have i…
Browse files Browse the repository at this point in the history
…n react package
  • Loading branch information
literat committed Jul 30, 2022
1 parent dfb68d1 commit e352145
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 42 deletions.
2 changes: 1 addition & 1 deletion packages/web-twig/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<!-- There should always be "Unreleased" section at the beginning. -->
## Unreleased
- Require compiler as separate dependency
- Refactor components and update their readme

## 1.8.0 - 2022-07-18
- Update `Tag` - add sizes, split theme and color classes, allow elementType change
- Bugfix `isRequired` functionality in `TextField` component
- Introduce `Pill` component
- Introduce `Tabs` component
- Refactor components and update their readme
- Refactor components directory tree

## 1.7.0 - 2022-05-09
Expand Down
46 changes: 23 additions & 23 deletions packages/web-twig/src/Resources/components/Tabs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@ This is Twig implementation of the [Tabs] component.
Basic example usage:

```html
<Tabs>
<TabsItem>
<TabsLink isSelected id="pane1-tab" ariaTarget="pane1">
<TabList>
<TabItem>
<TabLink isSelected id="pane1-tab" ariaTarget="pane1">
Item selected
</TabsLink>
</TabsItem>
<TabsItem>
</TabLink>
</TabItem>
<TabItem>
<TabsLink id="pane2-tab" ariaTarget="pane2">
Item
</TabsLink>
</TabsItem>
<TabsItem>
<TabsLink href="https://www.example.com">
</TabItem>
<TabItem>
<TabLink href="https://www.example.com">
Item link
</TabsLink>
</TabsItem>
</Tabs>
<TabsPane id="pane1" isSelected label="pane1-tab">
</TabLink>
</TabItem>
</TabList>
<TabPane id="pane1" isSelected label="pane1-tab">
Pane 1
</TabsPane>
<TabsPane id="pane2" label="pane2-tab">
</TabPane>
<TabPane id="pane2" label="pane2-tab">
Pane 2
</TabsPane>
</TabPane>
```

Without lexer:
```twig
{% embed "@spirit/tabs.twig" %}
{% embed "@spirit/tabList.twig" %}
{% block content %}
{% embed "@spirit/tabsItem.twig" %}
{% embed "@spirit/tabItem.twig" %}
{% block content %}
{% embed "@spirit/tabsLink.twig" with { props: {
{% embed "@spirit/tabLink.twig" with { props: {
isSelected: true,
id: 'panel1-tab',
target: 'panel1',
Expand All @@ -55,19 +55,19 @@ Without lexer:

The Tabs itself consists of many components which cannot be used independently.

### Tabs
### TabList

| Prop name | Type | Default | Required | Description |
|-----------|----------|---------|----------|-----------------------|
| `class` | `string` | `null` | no | Additional class name |

### TabsItem
### TabItem

| Prop name | Type | Default | Required | Description |
|-----------|----------|---------|----------|-----------------------|
| `class` | `string` | `null` | no | Additional class name |

### TabsLink
### TabLink

| Prop name | Type | Default | Required | Description |
|--------------|-----------|---------|----------|------------------------------|
Expand All @@ -77,7 +77,7 @@ The Tabs itself consists of many components which cannot be used independently.
| `isSelected` | `boolean` | `false` | no | Whether is tab item selected |
| `ariaTarget` | `string` | `null` | no | Target pane of the tab item |

### TabsPane
### TabPane

| Prop name | Type | Default | Required | Description |
|--------------|-----------|---------|----------|--------------------------------|
Expand Down
12 changes: 12 additions & 0 deletions packages/web-twig/src/Resources/components/Tabs/TabItem.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{# API #}
{%- set _class = props.class | default(null) -%}

{# Class names #}
{%- set _rootClassName = _spiritClassPrefix ~ 'Tabs__item' -%}

{# Miscellaneous #}
{%- set _classNames = [ _rootClassName, _class ] -%}

<li {{ mainProps(props) }} {{ classProp(_classNames)}}>
{% block content %}{% endblock %}
</li>
39 changes: 39 additions & 0 deletions packages/web-twig/src/Resources/components/Tabs/TabLink.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{# API #}
{%- set _ariaTarget = props.ariaTarget | default(null) -%}
{%- set _class = props.class | default(null) -%}
{%- set _href = props.href | default(null) -%}
{%- set _id = props.id | default(null) -%}
{%- set _isSelected = props.isSelected | default(false) -%}

{# Class names #}
{%- set _isSelectedClassName = _isSelected == 'true' ? 'is-selected' : null -%}
{%- set _rootClassName = _spiritClassPrefix ~ 'Tabs__link' -%}

{# Attributes #}
{%- set _ariaSelectedAttr = _isSelected ? 'true' : 'false' -%}
{%- set _ariaControlsAttr = _ariaTarget ? 'aria-controls=' ~ _ariaTarget : null -%}
{%- set _dataTargetAttr = _ariaTarget ? 'data-target=#' ~ _ariaTarget : null -%}
{%- set _dataToggleAttr = _href ? null : 'data-toggle=tabs' -%}
{%- set _hrefAttr = _href ? 'href=' ~ _href : null -%}
{%- set _idAttr = _id ? ' id=' ~ _id : null -%}
{%- set _roleAttr = _href ? 'role=tab' : null -%}
{%- set _typeAttr = _href ? null : 'type=button' -%}

{# Miscellaneous #}
{%- set _classNames = [ _rootClassName, _isSelectedClassName, _class ] -%}
{%- set _elementType = _href ? 'a' : 'button' -%}

<{{ _elementType }}
{{ mainProps(props) }}
{{ classProp(_classNames) }}
{{ _hrefAttr | raw }}
{{ _idAttr }}
{{ _roleAttr }}
{{ _typeAttr }}
{{ _dataToggleAttr | raw }}
aria-selected="{{ _ariaSelectedAttr }}"
{{ _dataTargetAttr | raw }}
{{ _ariaControlsAttr }}
>
{% block content %}{% endblock %}
</{{ _elementType }}>
12 changes: 12 additions & 0 deletions packages/web-twig/src/Resources/components/Tabs/TabList.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{# API #}
{%- set _class = props.class | default(null) -%}

{# Class names #}
{%- set _rootClassName = _spiritClassPrefix ~ 'Tabs' -%}

{# Miscellaneous #}
{%- set _classNames = [ _rootClassName, _class ] -%}

<ul {{ mainProps(props) }} {{ classProp(_classNames) }} role="tablist">
{% block content %}{% endblock %}
</ul>
26 changes: 26 additions & 0 deletions packages/web-twig/src/Resources/components/Tabs/TabPane.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{# API #}
{%- set _class = props.class | default(null) -%}
{%- set _id = props.id | default(null) -%}
{%- set _isSelected = props.isSelected | default(false) -%}
{%- set _label = props.label | default(null) -%}

{# Class names #}
{%- set _isSelectedClassName = _isSelected == 'true' ? 'is-selected' : null -%}
{%- set _rootClassName = _spiritClassPrefix ~ 'Tabs-pane' -%}

{# Attributes #}
{%- set _ariaLabelAttr = _label ? ' aria-labelledby=' ~ _label : null -%}
{%- set _idAttr = _id ? ' id=' ~ _id : null -%}

{# Miscellaneous #}
{%- set _classNames = [ _rootClassName, _isSelectedClassName, _class ] -%}

<div
{{ mainProps(props) }}
{{ classProp(_classNames) }}
{{ _idAttr }}
role="tabpanel"
{{ _ariaLabelAttr }}
>
{% block content %}{% endblock %}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends '@spirit/Tabs/TabItem.twig' %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends '@spirit/Tabs/TabLink.twig' %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends '@spirit/Tabs/TabList.twig' %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends '@spirit/Tabs/TabPane.twig' %}
36 changes: 18 additions & 18 deletions packages/web-twig/tests/components-fixtures/tabsDefault.twig
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Tabs>
<TabsItem>
<TabsLink isSelected id="pane1-tab" target="pane1">
<TabList>
<TabItem>
<TabLink isSelected id="pane1-tab" target="pane1">
Item selected
</TabsLink>
</TabsItem>
<TabsItem>
<TabsLink id="pane2-tab" target="pane2">
</TabLink>
</TabItem>
<TabItem>
<TabLink id="pane2-tab" target="pane2">
Item
</TabsLink>
</TabsItem>
<TabsItem>
<TabsLink href="https://www.example.com">
</TabLink>
</TabItem>
<TabItem>
<TabLink href="https://www.example.com">
Item link
</TabsLink>
</TabsItem>
</Tabs>
<TabsPane id="pane1" isSelected label="pane1-tab">
</TabLink>
</TabItem>
</TabList>
<TabPane id="pane1" isSelected label="pane1-tab">
Pane 1
</TabsPane>
<TabsPane id="pane2" label="pane2-tab">
</TabPane>
<TabPane id="pane2" label="pane2-tab">
Pane 2
</TabsPane>
</TabPane>

0 comments on commit e352145

Please sign in to comment.