Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
ribbons statements and theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Goyet committed Apr 5, 2017
1 parent 8764086 commit 573d684
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 29 deletions.
134 changes: 132 additions & 2 deletions dest/css/ribbons.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dest/css/ribbons.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 71 additions & 8 deletions src/scss/ribbons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,92 @@
@import 'utils/enables';
@import 'utils/syntaxes';
@import 'utils/trowel-variables';
@import 'utils/mixin-example';
@import 'utils/mixin-ribbons';
@import 'utils/mixin-ribbons-band';

$ribbon--selector: selector(new 'ribbon' with $ribbons--syntax);

@if $ribbons--enabled {
$ribbon--selector: selector(new 'ribbon' with $ribbons--syntax);

@include statement($ribbon--selector, (
('@include ribbons--mixin-example', null),
('font-size', $ribbons--font-size),
('font-family', $ribbons--font-family),
('font-weight', $ribbons--font-weight),
('text-transform', $ribbons--text-transform),
('letter-spacing', $ribbons--letter-spacing),
('line-height', $ribbons--line-height),
('text-align', $ribbons--text-align),
('text-decoration', $ribbons--text-decoration),
('margin', $ribbons--margin),
('border-width', $ribbons--border-width),
('border-style', $ribbons--border-style),
('border-color', $ribbons--border-color),
('border-radius', $ribbons--border-radius),
('color', $ribbons--color),
('box-shadow', $ribbons--box-shadow),
('background', $ribbons--background),
('position', relative),
('width', $ribbons--size),
('height', $ribbons--size),
('overflow', hidden),
('pointer-events', none),
('display', block),
));


$ribbon-band--selector: selector(set $ribbon--selector element 'band');

@include statement($ribbon-band--selector, (
('@include ribbons--position', $ribbons--position),
('@include ribbons-band--width', $ribbons--gutter),
('background-color', $ribbons--background-color),
('position', absolute),
('top', 0),
('height', $ribbons--height),
('text-align', center),
('user-select', none),
('display', block),
));


$ribbon-band-before--selector: selector(set $ribbon-band--selector pseudo-element 'before');

@include statement($ribbon-band-before--selector, (
('@include ribbons-band-pseudos--commons', ''),
('background-color', $ribbons--background-color),
('left', 100%),
));


$ribbon-band-after--selector: selector(set $ribbon-band--selector pseudo-element 'after');

@include statement($ribbon-band-after--selector, (
('@include ribbons-band-pseudos--commons', ''),
('background-color', $ribbons--background-color),
('right', 100%),
));


$ribbon-content--selector: selector(set $ribbon--selector element 'content');

@include statement($ribbon-content--selector, (
('position', absolute),
('top', 50%),
('left', 50%),
('transform', translate(-50%, -50%)),
('z-index', 1),
('white-space', nowrap),
('overflow', hidden),
('display', block),
));


$ribbon-content-before--selector: selector(set $ribbon-content--selector pseudo-element 'before');

@include statement($ribbon-content-before--selector, (
('content', ''),
('background-color', $ribbons--background-color),
('position', absolute),
('top', -1px),
('bottom', -1px),
('left', -1px),
('right', -1px),
('z-index', -1),
('overflow', hidden),
))
}
28 changes: 28 additions & 0 deletions src/scss/utils/_get-hypotenuse.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@function square-root($r) {
$x0: 1;
$x1: $x0;

@for $i from 1 through 10 {
$x1: $x0 - ($x0 * $x0 - abs($r)) / (2 * $x0);
$x0: $x1;
}

@return $x1;
}

@function strip-units($number) {
@return $number / ($number * 0 + 1);
}

@function square($number) {
$unitless: strip-units($number);
@return ($unitless * $unitless);
}

@function get-hypotenuse($ab, $ac) {
@if unit($ab) == unit($ac) {
@return square-root(square($ab) + square($ac)) + unquote(unit($ab));
} @else {
@error 'The two value into the get-hypotenuse() function must share the same unit type';
}
}
5 changes: 0 additions & 5 deletions src/scss/utils/_mixin-example.scss

This file was deleted.

26 changes: 26 additions & 0 deletions src/scss/utils/_mixin-ribbons-band.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@import './get-hypotenuse';

@function ribbons-band--width($gutter, $flags) {
@return (
('width', get-hypotenuse($gutter, $gutter), $flags),
);
}


// (1) Big static value in order to make sure that for any gutter value the
// before and after goes off the thumbnail element
// (2) We set a negative margin on x axis in order to avoid a very thin band
// where the `::after` and `::before` pseudo elements are not perfectly
// sticked to the `.thumbnail__ribbon`.

@function ribbons-band-pseudos--commons($nothing, $flags) {
@return (
('content', ''),
('display', block),
('position', absolute),
('top', 0),
('height', 100%),
('width', 10000px), // (1)
('margin', 0 -1px), // (2)
);
}
19 changes: 19 additions & 0 deletions src/scss/utils/_mixin-ribbons.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@function ribbons--position($orientation, $flags) {
$property-affected: if($orientation == 'right', 'left', 'right');

@if $orientation == 'right' or $orientation == 'left' {
$rotate-direction: if($orientation == 'left', -1, 1);

@return (
($property-affected, 100%, $flags),
($orientation, auto, $flags),
('margin-#{$property-affected}', value($ribbons--gutter, $flags) * -1, $flags),
('margin-#{$orientation}', 0, $flags),
('transform-origin', top #{$property-affected}, $flags),
('transform', rotate(45deg * $rotate-direction), $flags),
);
} @else {
@error "The parameter `$orientation` must be a string value that can only be 'right' or 'left'";
}

}
24 changes: 16 additions & 8 deletions src/scss/utils/_trowel-variables.scss
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
$ribbons--font-size: 1rem !default;
$ribbons--font-size: trwl-theme-size('md') !default;
$ribbons--font-family: null !default;
$ribbons--font-weight: null !default;
$ribbons--text-transform: null !default;
$ribbons--letter-spacing: null !default;
$ribbons--line-height: null !default;
$ribbons--text-align: null !default;
$ribbons--text-decoration: null !default;
$ribbons--margin: null !default;
$ribbons--border-width: null !default;
$ribbons--border-style: null !default;
$ribbons--border-color: null !default;
$ribbons--border-radius: null !default;
$ribbons--color: null !default;
$ribbons--color: rgb(255, 255, 255) !default;
$ribbons--box-shadow: null !default;
$ribbons--background: null !default;
$ribbons--background-color: null !default;
$ribbons--background-color: (
'default': trwl-theme-color('gray-darker'),
'-primary': trwl-theme-color('primary'),
'-success': trwl-theme-color('success'),
'-warning': trwl-theme-color('warning'),
'-danger': trwl-theme-color('danger'),
) !default;
$ribbons--size: 7.5em !default;
$ribbons--position: (
'default': 'left',
'-right': 'right',
) !default; // 'left' or 'right'
$ribbons--gutter: 3.75em !default;
$ribbons--height: 1.875em !default;
13 changes: 10 additions & 3 deletions src/twig/ribbon.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

{% set blockSelector = syntax.prefix|default(false) ? syntax.prefix ~ syntax.separator.prefix ~ 'ribbon' : 'ribbon' %}

<div class="{{ blockSelector }}">
{{ block('body') }}
</div>
{% set modifiersClass = '' %}
{% for modifier in modifiers|default([]) %}
{% set modifiersClass = modifiersClass ~ ' ' ~ blockSelector ~ syntax.separator.modifier ~ modifier %}
{% endfor %}

<span class="{{ blockSelector }}{{ modifiersClass }}">
<span class="{{ blockSelector }}__band">
<span class="{{ blockSelector }}__content">{{ block('content') }}</span>
</span>
</span>
12 changes: 10 additions & 2 deletions test/src/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
</h1>

{% embed '../../src/twig/ribbon.html.twig' %}
{% block body %}hello world !{% endblock %}
{% block content %}default{% endblock %}
{% endembed %}


{% embed '../../src/twig/ribbon.html.twig' with { modifiers: ['right'] } %}
{% block content %}on right{% endblock %}
{% endembed %}

{% for theme in ['primary', 'success', 'warning', 'danger'] %}
{% embed '../../src/twig/ribbon.html.twig' with { modifiers: [theme] } %}
{% block content %}{{ theme }}{% endblock %}
{% endembed %}
{% endfor %}
</body>
</html>

0 comments on commit 573d684

Please sign in to comment.