Skip to content

Commit ee6baf0

Browse files
committed
Improved button component adding type parameter and removed dead code
1 parent 6210e89 commit ee6baf0

6 files changed

Lines changed: 75 additions & 49 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ To get the diff for a specific change, go to https://github.com/LIN3S/AdminBundl
66
To get the diff between two versions, go to https://github.com/LIN3S/AdminBundle/compare/v0.4.0...v0.5.0
77

88
* 0.6.0
9+
* Extracted panel independent Twig component.
10+
* Improved button component adding type parameter.
911
* Full refactor of AdminBundle's JavaScript.
1012
* Removed jQuery dependency
1113
* Migrated code to ES2015 standards using `class` approach

src/LIN3S/AdminBundle/Resources/private/scss/components/_paginator.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// This file is part of the Admin Bundle.
22
//
3-
// Copyright (c) 2015-2016 LIN3S <info@lin3s.com>
3+
// Copyright (c) 2015-present LIN3S <info@lin3s.com>
44
//
55
// For the full copyright and license information, please view the LICENSE
66
// file that was distributed with this source code.
77
//
88
// @author Gorka Laucirica <gorka.lauzirika@gmail.com>
99
// @author Beñat Espiña <benatespina@gmail.com>
1010

11-
@import './../../node_modules/lin3s-css-grid/scss/variables';
12-
1311
@import '../variables/colors';
12+
@import '../variables/grid';
1413

1514
$paginator-separator-color: $color-black !default;
1615

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
{% set button_type = button_type|default ? button_type : 'button' %}
12
{% set button_class = button_class|default ? 'button ' ~ button_class : 'button' %}
2-
{% set js_action = js_action|default ? ' ' ~ js_action : '' %}
3+
{% set button_js_action = js_action|default ? ' ' ~ js_action : '' %}
34

4-
<button class="{{ button_class }}{{ js_action }}">{{- button_title -}}</button>
5+
<button type="{{ button_type }}" class="{{ button_class }}{{ button_js_action }}">{{- button_title -}}</button>
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
{% macro submit(title, js_action) %}
2+
{% include 'Lin3sAdminBundle:components:button.html.twig' with {
3+
button_type: 'submit',
4+
button_title: title,
5+
button_class: 'button--secondary',
6+
button_js_action: js_action|default
7+
} %}
8+
{% endmacro %}
9+
110
{% macro primary(title, js_action) %}
211
{% include 'Lin3sAdminBundle:components:button.html.twig' with {
312
button_title: title,
4-
js_action: js_action|default
13+
button_js_action: js_action|default
514
} %}
615
{% endmacro %}
716

817
{% macro secondary(title, js_action) %}
918
{% include 'Lin3sAdminBundle:components:button.html.twig' with {
1019
button_title: title,
1120
button_class: 'button--secondary',
12-
js_action: js_action|default
21+
button_js_action: js_action|default
1322
} %}
1423
{% endmacro %}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% set panel_title %}{%- block panel_title -%}{%- endblock panel_title -%}{% endset %}
2+
{% set panel_content %}{%- block panel_content -%}{%- endblock panel_content -%}{% endset %}
3+
4+
<div class="panel">
5+
<div class="panel__header">
6+
<h2 class="panel__title">
7+
{{- panel_title -}}
8+
</h2>
9+
</div>
10+
<div class="panel__content">
11+
{{- panel_content -}}
12+
</div>
13+
</div>

src/LIN3S/AdminBundle/Resources/views/form.html.twig

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -119,35 +119,35 @@
119119
{%- endblock form_errors %}
120120

121121
{%- block form -%}
122-
{{ form_start(form) }}
123-
{% if(form.vars.groups is defined) %}
122+
{{- form_start(form) -}}
123+
124+
{% if form.vars.groups is defined %}
124125
<div class="form__column form__column--left">
125126
{% for group in form.vars.groups %}
126127
{% if group.position is not defined or group.position == 'left' %}
127-
{{ block('lin3s_admin_panel') }}
128+
{{- block('lin3s_admin_panel') -}}
128129
{% endif %}
129130
{% endfor %}
130131
</div>
131132
<div class="form__column form__column--right">
132-
{{ block('lin3s_admin_submit') }}
133+
{{- block('lin3s_admin_submit') -}}
133134
{% for group in form.vars.groups %}
134135
{% if group.position is defined and group.position == 'right' %}
135-
{{ block('lin3s_admin_panel') }}
136+
{{- block('lin3s_admin_panel') -}}
136137
{% endif %}
137138
{% endfor %}
138139
</div>
139140
{% else %}
140-
<div class="panel">
141-
<div class="panel__content">
141+
{% embed 'Lin3sAdminBundle:components:panel.html.twig' %}
142+
{%- block panel_content -%}
142143
{{- form_widget(form) -}}
143-
<input type="submit"
144-
class="button"
145-
value="{% trans %}lin3s_admin.form.save_changes{% endtrans %}">
146-
</div>
147-
</div>
148-
{{ block('lin3s_admin_submit') }}
144+
{%- endblock panel_content -%}
145+
{% endembed %}
146+
147+
{{- block('lin3s_admin_submit') -}}
149148
{% endif %}
150-
{{ form_end(form) }}
149+
150+
{{- form_end(form) -}}
151151
{%- endblock form -%}
152152

153153
{%- block form_start -%}
@@ -158,36 +158,38 @@
158158
{{- parent() -}}
159159
{%- endblock %}
160160

161-
{% block lin3s_admin_panel %}
162-
<div class="panel">
163-
<div class="panel__header">
164-
<h2 class="panel__title">{{ group.name | trans }}</h2>
165-
</div>
166-
<div class="panel__content">
167-
{% for field in group.fields %}
168-
{% set props = field | split('.') %}
169-
{% if props | length == 1 %}
170-
{{ form_row(form[props[0]]) }}
171-
{% elseif props | length == 2 %}
172-
{{ form_row(form[props[0]][props[1]]) }}
161+
{%- block lin3s_admin_panel -%}
162+
{% embed 'Lin3sAdminBundle:components:panel.html.twig' %}
163+
{%- block panel_title -%}
164+
{{- group.name|trans -}}
165+
{%- endblock panel_title -%}
166+
167+
{%- block panel_content -%}
168+
{%- for field in group.fields %}
169+
{% set props = field|split('.') %}
170+
{% if props|length == 1 %}
171+
{{- form_row(form[props[0]]) -}}
172+
{% elseif props|length == 2 %}
173+
{{- form_row(form[props[0]][props[1]]) -}}
173174
{% endif %}
174-
{% endfor %}
175-
</div>
176-
</div>
177-
{% endblock %}
175+
{% endfor -%}
176+
{%- endblock panel_content -%}
177+
{% endembed %}
178+
{%- endblock lin3s_admin_panel -%}
178179

179-
{% block lin3s_admin_submit %}
180-
<div class="panel">
181-
<div class="panel__header">
182-
<h2 class="panel__title">{% trans %}lin3s_admin.form.publish{% endtrans %}</h2>
183-
</div>
184-
<div class="panel__content">
180+
{%- block lin3s_admin_submit -%}
181+
{% embed 'Lin3sAdminBundle:components:panel.html.twig' %}
182+
{% import 'Lin3sAdminBundle:components/macros:buttons.html.twig' as buttons %}
183+
184+
{%- block panel_title -%}
185+
{{- 'lin3s_admin.form.publish'|trans -}}
186+
{%- endblock panel_title -%}
187+
188+
{%- block panel_content -%}
185189
<div class="form__group">
186190
<label>&nbsp;</label>
187-
<input type="submit"
188-
class="button button--secondary"
189-
value="{% trans %}lin3s_admin.form.save_changes{% endtrans %}">
191+
{{ buttons.submit('lin3s_admin.form.save_changes'|trans) }}
190192
</div>
191-
</div>
192-
</div>
193-
{% endblock %}
193+
{%- endblock panel_content -%}
194+
{% endembed %}
195+
{%- endblock lin3s_admin_submit -%}

0 commit comments

Comments
 (0)