Skip to content

Commit

Permalink
feat(badges): css improvements and added is-splited class
Browse files Browse the repository at this point in the history
  • Loading branch information
guastallaigor committed Dec 19, 2018
1 parent 9e198e1 commit 656f186
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 41 deletions.
11 changes: 7 additions & 4 deletions docs/badge.stories.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { storiesOf } from '@storybook/html'; // eslint-disable-line import/no-extraneous-dependencies
import { // eslint-disable-line import/no-extraneous-dependencies
withKnobs, radios,
withKnobs, radios, boolean,
} from '@storybook/addon-knobs';

const stories = storiesOf('Badges', module);
stories.addDecorator(withKnobs);

stories.add('badges', () => {
const optionsLeft = radios('class-left', {
const optionsLeft = radios('left/only', {
'is-dark': 'is-dark',
'is-success': 'is-success',
'is-primary': 'is-primary',
'is-warning': 'is-warning',
'is-error': 'is-error',
}, 'is-dark');

const optionsRight = radios('class-right', {
const optionsRight = radios('right', {
'is-dark': 'is-dark',
'is-success': 'is-success',
'is-primary': 'is-primary',
Expand All @@ -29,7 +29,10 @@ stories.add('badges', () => {
'is-large': 'is-large',
}, 'is-medium');

return `<span class="nes-badge ${sizes}">
const isSplited = boolean('is-splited', true) ? 'is-splited' : '';
const selectedClasses = [sizes, isSplited].join(' ');

return `<span class="nes-badge ${selectedClasses}">
<span class="${optionsLeft}">npm</span>
<span class="${optionsRight}">1.0.0</span>
</span>`;
Expand Down
79 changes: 42 additions & 37 deletions scss/elements/badges.scss
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
@mixin span-style($color, $background, $left) {
@mixin span-style($color, $background, $option, $width: 50%) {
position: absolute;
top: 0;
width: 50%;
width: $width;
color: $color;
background-color: $background;

@if $left == 0 {
@if $option == left {
left: 0;
} @else {
} @else if $option == right {
right: 0;
}
}

@mixin badge-style($color, $background) {
&:first-child {
@include span-style($color, $background, 0);
// prettier-ignore
box-shadow:
0 4px $background,
0 -4px $background,
0 0 $background,
-4px 0 $background;
}
@mixin badge-style($color, $background, $is-splited: true) {
$box-shadow-first-two: 0 0.5em $background, 0 -0.5em $background;

@if $is-splited == true {
&:first-child {
@include span-style($color, $background, left);

box-shadow: $box-shadow-first-two, 0 0 $background, -0.5em 0 $background;
}
&:last-child {
@include span-style($color, $background, right);

&:last-child {
@include span-style($color, $background, 1);
// prettier-ignore
box-shadow:
0 4px $background,
0 -4px $background,
4px 0 $background,
0 0 $background;
box-shadow: $box-shadow-first-two, 0.5em 0 $background, 0 0 $background;
}
} @else {
&:first-child {
@include span-style($color, $background, 0, 100%);

box-shadow: $box-shadow-first-two, 0.5em 0 $background, -0.5em 0 $background;
}
}
}

Expand All @@ -43,21 +44,20 @@

// Default style
.nes-badge {
$border-size: 4px;

position: relative;
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0.75em;
margin: $border-size;
margin: 4px;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: $cursor-click-url;
user-select: none;
border: none;
@include setup(7px);

// Other styles
// prettier-ignore
Expand All @@ -69,22 +69,27 @@
"error" $background-color map-get($error-colors, "normal");

@each $type in $types {
& span.is-#{nth($type, 1)} {
@include badge-style(nth($type, 2), nth($type, 3));
&.is-splited {
& span.is-#{nth($type, 1)} {
@include badge-style(nth($type, 2), nth($type, 3));
}
}
}

@include setup(9px);

&.is-small {
@include setup(5px);
& span.is-#{nth($type, 1)} {
@include badge-style(nth($type, 2), nth($type, 3), false);
}
}

&.is-medium {
@include setup(7px);
}
// Other sizes
// prettier-ignore
$sizes:
"small" 5px,
"medium" 7px,
"large" 9px;

&.is-large {
@include setup(9px);
@each $size in $sizes {
&.is-#{nth($size, 1)} {
@include setup(nth($size, 2));
}
}
}

0 comments on commit 656f186

Please sign in to comment.