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

Add button component (twig) #188

Merged
merged 10 commits into from
May 24, 2022
Merged
37 changes: 37 additions & 0 deletions src/backend/views/components/button.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{#
Reusable button component.
Available props:
- label
- icon
- name
- style: primary, secondary or warning
- size: small, default
- url: URL to navigate in case if button is the navigation link
- class: additional class for the button

Usage example:
{% include 'components/button.twig' with {label: 'Label', icon: 'check', style: 'secondary', size: 'default'} %}
#}

{% set mainClass = 'docs-button' %}


{% set tag = 'button' %}

{% if url is not empty %}
{% set tag = 'a' %}
{% endif %}

<{{tag}}
{{ name is not empty ? 'name="' ~ name ~ '"': '' }}
class="{{ mainClass }} {{ mainClass }}--{{ style|default('primary') }} {{ mainClass }}--{{ size|default('default') }} {{ icon ? mainClass ~ '--with-icon' : '' }} {{ class ?? '' }}"
{{ url is not empty ? 'href="' ~ url ~ '"' : '' }}
>
{% if icon %}
<div class="{{mainClass}}__icon">
{{ svg(icon) }}
</div>
{% endif %}

{{ label }}
</{{tag}}>
7 changes: 2 additions & 5 deletions src/backend/views/components/header.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
<ul class="docs-header__menu">
{% if isAuthorized == true %}
<li class="docs-header__menu-add">
<a class="docs-header__button" href="/page/new">
{{ svg('plus') }}
Add Page
</a>
{% include 'components/button.twig' with {label: 'Add page', icon: 'plus', size: 'small', url: '/page/new'} %}
</li>
{% endif %}
{% for option in config.menu %}
<li>
<a
<a class="docs-header__menu-link"
{% if option.uri %}
href="{{ option.uri }}"
{% else %}
Expand Down
9 changes: 5 additions & 4 deletions src/backend/views/pages/form.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block body %}
<style>
.docs-header__button {
.docs-header__menu-add {
visibility: hidden;
}
</style>
Expand Down Expand Up @@ -56,12 +56,13 @@
<div class="writing-editor">
<div id="editorjs"></div>
</div>
<div class="writing-buttons">
<span class="writing-header__save" name="js-submit-save">Save</span>

<div class="writing-buttons">
{% include 'components/button.twig' with {label: 'Save changes', name: 'js-submit-save', icon: 'check'} %}
{% if page._id is not empty %}
<span class="writing-buttons__remove" name="js-submit-remove">Remove</span>
{% include 'components/button.twig' with {label: 'Delete doc', name: 'js-submit-remove', icon: 'trash', style: 'warning'} %}
{% endif %}
</div>

</section>
{% endblock %}
8 changes: 3 additions & 5 deletions src/backend/views/pages/page.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
{% endif %}
<time class="page__header-time">
Last edit {{ (page.body.time / 1000) | date("M d Y") }}
{% if isAuthorized == true %}
<a href="/page/edit/{{ page._id }}" class="page__header-button">
Edit
</a>
{% endif %}
</time>
{% if isAuthorized == true %}
{% include 'components/button.twig' with {label: 'Edit', icon: 'pencil', size: 'small', url: '/page/edit/' ~ page._id, class: 'page__header-button'} %}
{% endif %}
</header>
<h1 class="page__title">
{{ page.title }}
Expand Down
83 changes: 83 additions & 0 deletions src/frontend/styles/components/button.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
.docs-button {
display: inline-flex;
align-items: center;
justify-content: center;
height: var(--height);
padding-left: 12px;
padding-right: 12px;
color: white;
font-size: 14px;
font-weight: 500;
border: none;
cursor: pointer;
transition-property: background-color;
transition-duration: 0.1s;
border-radius: 8px;

@supports(-webkit-mask-box-image: url('')){
border-radius: 0;
-webkit-mask-box-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 10.3872C0 1.83334 1.83334 0 10.3872 0H13.6128C22.1667 0 24 1.83334 24 10.3872V13.6128C24 22.1667 22.1667 24 13.6128 24H10.3872C1.83334 24 0 22.1667 0 13.6128V10.3872Z' fill='black'/%3E%3C/svg%3E%0A") 48% 41% 37.9% 53.3%;;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
}

&__icon {
display: inline-flex;
align-items: center;
justify-content: center;
margin-right: 4px;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved

svg {
width: 24px;
height: 24px;
display: block;
}
}

&--default {
--height: 40px;
}

&--small {
--height: 32px;
padding-right: 8px;
}

&--primary {
background: var(--color-button-primary);

&:hover {
background: var(--color-button-primary-hover);
}

&:active {
background: var(--color-button-primary-active);
}
}

&--secondary {
background: var(--color-button-secondary);

&:hover {
background: var(--color-button-secondary-hover);
}

&:active {
background: var(--color-button-secondary-active);
}
}

&--warning {
background: var(--color-button-warning);

&:hover {
background: var(--color-button-warning-hover);
}

&:active {
background: var(--color-button-warning-active);
}
}

&--with-icon {
padding-left: 8px;
}
}
22 changes: 10 additions & 12 deletions src/frontend/styles/components/header.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
line-height: 40px;
}

a {
&__menu-link,
&__logo {
display: inline-block;
text-decoration: none;
}

&__logo {
Expand Down Expand Up @@ -55,24 +55,22 @@
a {
@media (--mobile) {
font-size: 0;
padding: 8px;
padding: 0 4px;
margin-right: 0;
}
}
}

a:not(.docs-header__button) {
color: inherit;
.docs-button__icon {
@media (--mobile) {
margin-right: 0;
}
}
}

&-link {
&:hover {
color: var(--color-link-active);
}
}
}

&__button {
@apply --button;
@apply --button-primary;
margin: auto 30px auto auto;
}
}
8 changes: 3 additions & 5 deletions src/frontend/styles/components/page.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

&__header {
display: flex;
align-items: center;
color: var(--color-text-second);

@media (--mobile) {
Expand Down Expand Up @@ -40,11 +41,8 @@
}

&-button {
@apply --button;
@apply --button-primary;
padding: 5px 10px;
font-size: 13px;
margin-left: 10px;
margin-left: 20px;
text-decoration: none;
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/frontend/styles/components/writing.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
}

.writing-buttons {
&__remove {
@apply --button;
@apply --button-danger;
display: flex;

button:not(:last-child) {
margin-right: 20px;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/frontend/styles/main.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@import './components/page.pcss';
@import './components/landing.pcss';
@import './components/auth.pcss';
@import './components/button.pcss';

body {
font-family: system-ui, Helvetica, Arial, Verdana;
Expand All @@ -19,3 +20,8 @@ body {
svg {
fill: currentColor;
}

a {
text-decoration: none;
color: inherit
}
23 changes: 13 additions & 10 deletions src/frontend/styles/vars.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@
--color-text-second: #5d6068;
--color-line-gray: #E8E8EB;
--color-link-active: #2071cc;
--color-button-danger: #ff5159;
--color-bg-light: #f8f7fa;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
--color-page-active: #ff1767;

--color-button-primary: #3389FF;
--color-button-primary-hover: #2E7AE6;
--color-button-primary-active: #296DCC;

--color-button-secondary: #717682;
--color-button-secondary-hover: #5D6068;
--color-button-secondary-active: #4B4F5B;

--color-button-warning: #EF5C5C;
--color-button-warning-hover: #D65151;
--color-button-warning-active: #BD4848;


/**
* Site layout sizes
*/
Expand Down Expand Up @@ -47,15 +59,6 @@
}
}

--button-danger {
background: var(--color-button-danger);
color: #fff;
box-shadow: none;

&:hover {
background: color-mod(var(--color-button-danger) blackness(+10%));
}
}

--button-primary {
background: var(--color-link-active);
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/svg/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/frontend/svg/pencil.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/frontend/svg/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/frontend/svg/trash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.