1
0
mirror of https://github.com/NigelOToole/pixel-borders.git synced 2025-09-01 09:53:41 +02:00

Minor refactor and restructure of project

This commit is contained in:
Nigel O'Toole
2019-05-23 10:36:35 +01:00
parent 2cddd8cb8b
commit 6f63c6a540
16 changed files with 848 additions and 1093 deletions

View File

@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pixel borders - A SASS mixin to add pixelated borders to HTML elements</title>
<title>Pixel borders - SASS mixin to add pixelated borders to HTML elements</title>
<link rel="stylesheet" href="styles/site.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Cutive+Mono|Lato:300,400">
@@ -30,7 +30,7 @@
<div class="fullwidth">
<div class="container separator">
<h2 class="m-0">A SASS mixin to add pixelated borders to HTML elements, which can be customized for different sizes, colour coding,inset borders.</h2>
<h2 class="m-0">A SASS mixin to add pixelated borders to HTML elements, which can be customized for different sizes, styles and colour coding.</h2>
</div>
</div>
@@ -84,9 +84,13 @@
<h3>Import</h3>
<p>After adding the repo as a dependency you can import it into your SASS files. Alternatively you can download the pixel-borders.scss from this repo and add it to your project folder directly.</p>
<p>After installation you can import it into your SASS files with the statement below.</p>
<pre><code>@import "node_modules/pixel-borders/src/styles/pixel-borders.scss";</code></pre>
<pre><code>@import "pixel-borders/src/styles/pixel-borders.scss";</code></pre>
<p>You can also just import the mixins without the demo styles.</p>
<pre><code>@import "pixel-borders/src/styles/pixel-borders/pixel-borders-mixins";</code></pre>
<h4>Pixel borders mixin options</h4>

View File

@@ -1,228 +1,2 @@
// Generate SVG image for pixelated corners
@function pixel-borders-image($corner-size, $color) {
$svg: '';
$svg-path: '';
$svg-size: $corner-size * 6;
$color: str-replace('' + $color, '#', '%23');
@if $corner-size == 1 {
$svg-path: 'M0 2h2v2H0zM2 0h2v2H2zM4 2h2v2H4zM2 4h2v2H2z';
} @else {
$svg-path: 'M2 2h2v2H2zM4 0h2v2H4zM10 4h2v2h-2zM0 4h2v2H0zM6 0h2v2H6zM8 2h2v2H8zM8 8h2v2H8zM6 10h2v2H6zM0 6h2v2H0zM10 6h2v2h-2zM4 10h2v2H4zM2 8h2v2H2z';
}
$svg: 'data:image/svg+xml,<svg xmlns=\'http://www.w3.org/2000/svg\' width=\'#{$svg-size}\' height=\'#{$svg-size}\'><path d=\'#{$svg-path}\' fill=\'#{$color}\' /></svg>';
@return $svg;
}
// String replace function - replace `$search` with `$replace` in `$string`
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
// Pixel border
@mixin pixel-borders($corner-size: 1, $border-size: 4px, $border-color: #000, $border-inset-color: false) {
@supports (border-image-source: none) {
border-radius: ($border-size * ($corner-size + 2)) + ($corner-size * 2);
}
border-style: solid;
border-width: $border-size;
border-color: $border-color;
border-image-slice: $corner-size * 2;
border-image-width: $corner-size;
border-image-outset: 0;
border-image-source: url(pixel-borders-image($corner-size, $border-color));
@if $border-inset-color {
@include pixel-inset-border($border-size, $border-inset-color);
}
}
// Pixel inset border
@mixin pixel-inset-border($border-inset-size: 4px, $border-inset-color: #ddd, $border-inset-sides: 'bottom-right', $border-inset-color-br: false, $border-inset-color-tl: false) {
$box-shadow: '';
@if not($border-inset-color-br) {
$border-inset-color-br: $border-inset-color;
}
@if not($border-inset-color-tl) {
$border-inset-color-tl: $border-inset-color;
}
position: relative;
&::after {
content: '';
position: absolute;
z-index: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
@if $border-inset-sides == 'bottom-right' or $border-inset-sides == false {
$box-shadow: inset -#{$border-inset-size} -#{$border-inset-size} $border-inset-color-br;
}
@if $border-inset-sides == 'top-left' {
$box-shadow: inset $border-inset-size $border-inset-size $border-inset-color-tl;
}
@if $border-inset-sides == 'all' {
$box-shadow: inset -#{$border-inset-size} -#{$border-inset-size} $border-inset-color-br, inset $border-inset-size $border-inset-size $border-inset-color-tl;
}
box-shadow: $box-shadow;
}
}
// Pixel box - Colours for border and inset are calculated using $background-color unless $border-color is passed
@mixin pixel-box($corner-size, $border-size, $background-color, $border-color: false, $border-inset: true, $border-inset-size: false, $border-inset-color: false, $border-inset-sides: false, $border-inset-color-br: false, $border-inset-color-tl: false) {
$background-color-hover: darken($background-color, 5);
@if not($border-color) {
$border-color: darken($background-color, 20);
}
@include pixel-borders($corner-size: $corner-size, $border-size: $border-size, $border-color: $border-color);
@if $border-inset-sides == 'all' and not($border-inset-color) {
$border-inset-color-br: darken($background-color, 10);
$border-inset-color-tl: lighten($background-color, 15);
}
@if not($border-inset-color) {
$border-inset-color: darken($background-color, 10);
}
@if $border-inset-sides == 'top-left' {
$border-inset-color: lighten($background-color, 15);
}
@if $border-inset {
@include pixel-inset-border($border-inset-size: $border-size, $border-inset-color: $border-inset-color, $border-inset-sides: $border-inset-sides, $border-inset-color-br: $border-inset-color-br, $border-inset-color-tl: $border-inset-color-tl);
}
background-color: $background-color;
&:hover, &:focus {
background-color: $background-color-hover;
}
}
// ----- Demo styles -----
.pixel-borders {
position: relative;
display: inline-block;
margin: 0 15px 15px 0;
padding: 15px 20px;
background-color: #fff;
font-family: "Press Start 2P", Arial Black, Arial Bold, Arial, sans-serif;
}
// Simple examples with default styling
.pixel-borders--1 {
@include pixel-borders();
}
.pixel-borders--1-inset {
@include pixel-borders($border-inset-color: #ddd);
}
.pixel-borders--2 {
@include pixel-borders($corner-size: 2);
}
.pixel-borders--2-inset {
@include pixel-borders($corner-size: 2);
&::after {
@include pixel-borders($corner-size: 1, $border-color: #ddd);
content: '';
position: absolute;
z-index: 0;
bottom: 0;
right: 0;
border-image-width: 0 1 1 0;
width: calc(100% - 4px);
height: calc(100% - 4px);
}
}
// Examples using the pixel box mixin to colour code the elements
.pixel-box--light {
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #fff);
}
.pixel-box--primary {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #209cee);
}
.pixel-box--success {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #92cc41);
}
.pixel-box--warning {
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #f7d51d);
}
.pixel-box--error {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #e76e55);
}
// Custom examples to show flexibility of the mixins
.pixel-box--light-custom {
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #fff, $border-inset-color: #999, $border-inset-sides: 'all');
}
.pixel-box--primary-custom {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #209cee, $border-inset: false);
}
.pixel-box--success-custom {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #92cc41, $border-inset-sides: 'top-left');
}
.pixel-box--warning-custom {
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #f7d51d, $border-inset-sides: 'all');
}
.pixel-box--error-custom {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #e76e55, $border-color: #000);
}
@import "pixel-borders/pixel-borders-mixins";
@import "pixel-borders/pixel-borders";

View File

@@ -0,0 +1,133 @@
// Generate SVG image for pixelated corners
@function pixel-borders-image($corner-size, $color) {
$svg: '';
$svg-path: '';
$svg-size: $corner-size * 6;
$color: str-replace('' + $color, '#', '%23');
@if $corner-size == 1 {
$svg-path: 'M0 2h2v2H0zM2 0h2v2H2zM4 2h2v2H4zM2 4h2v2H2z';
} @else {
$svg-path: 'M2 2h2v2H2zM4 0h2v2H4zM10 4h2v2h-2zM0 4h2v2H0zM6 0h2v2H6zM8 2h2v2H8zM8 8h2v2H8zM6 10h2v2H6zM0 6h2v2H0zM10 6h2v2h-2zM4 10h2v2H4zM2 8h2v2H2z';
}
$svg: 'data:image/svg+xml,<svg xmlns=\'http://www.w3.org/2000/svg\' width=\'#{$svg-size}\' height=\'#{$svg-size}\'><path d=\'#{$svg-path}\' fill=\'#{$color}\' /></svg>';
@return $svg;
}
// String replace function - replace `$search` with `$replace` in `$string`
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
// Pixel border
@mixin pixel-borders($corner-size: 1, $border-size: 4px, $border-color: #000, $border-inset-color: false) {
@supports (border-image-source: none) {
border-radius: ($border-size * ($corner-size + 2)) + ($corner-size * 2);
}
border-style: solid;
border-width: $border-size;
border-color: $border-color;
border-image-slice: $corner-size * 2;
border-image-width: $corner-size;
border-image-outset: 0;
border-image-source: url(pixel-borders-image($corner-size, $border-color));
@if $border-inset-color {
@include pixel-inset-border($border-size, $border-inset-color);
}
}
// Pixel inset border
@mixin pixel-inset-border($border-inset-size: 4px, $border-inset-color: #ddd, $border-inset-sides: 'bottom-right', $border-inset-color-br: false, $border-inset-color-tl: false) {
$box-shadow: '';
@if not($border-inset-color-br) {
$border-inset-color-br: $border-inset-color;
}
@if not($border-inset-color-tl) {
$border-inset-color-tl: $border-inset-color;
}
position: relative;
&::after {
content: '';
position: absolute;
z-index: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
@if $border-inset-sides == 'bottom-right' or $border-inset-sides == false {
$box-shadow: inset -#{$border-inset-size} -#{$border-inset-size} $border-inset-color-br;
}
@if $border-inset-sides == 'top-left' {
$box-shadow: inset $border-inset-size $border-inset-size $border-inset-color-tl;
}
@if $border-inset-sides == 'all' {
$box-shadow: inset -#{$border-inset-size} -#{$border-inset-size} $border-inset-color-br, inset $border-inset-size $border-inset-size $border-inset-color-tl;
}
box-shadow: $box-shadow;
}
}
// Pixel box - Colours for border and inset are calculated using $background-color unless $border-color is passed
@mixin pixel-box($corner-size, $border-size, $background-color, $border-color: false, $border-inset: true, $border-inset-size: false, $border-inset-color: false, $border-inset-sides: false, $border-inset-color-br: false, $border-inset-color-tl: false) {
$background-color-hover: darken($background-color, 5);
@if not($border-color) {
$border-color: darken($background-color, 20);
}
@include pixel-borders($corner-size: $corner-size, $border-size: $border-size, $border-color: $border-color);
@if $border-inset-sides == 'all' and not($border-inset-color) {
$border-inset-color-br: darken($background-color, 10);
$border-inset-color-tl: lighten($background-color, 15);
}
@if not($border-inset-color) {
$border-inset-color: darken($background-color, 10);
}
@if $border-inset-sides == 'top-left' {
$border-inset-color: lighten($background-color, 15);
}
@if $border-inset {
@include pixel-inset-border($border-inset-size: $border-size, $border-inset-color: $border-inset-color, $border-inset-sides: $border-inset-sides, $border-inset-color-br: $border-inset-color-br, $border-inset-color-tl: $border-inset-color-tl);
}
background-color: $background-color;
&:hover, &:focus {
background-color: $background-color-hover;
}
}

View File

@@ -0,0 +1,93 @@
// ----- Border styles -----
.pixel-borders {
position: relative;
display: inline-block;
margin: 0 15px 15px 0;
padding: 15px 20px;
background-color: #fff;
font-family: "Press Start 2P", Arial Black, Arial Bold, Arial, sans-serif;
}
// One pixel borders
.pixel-borders--1 {
@include pixel-borders();
}
.pixel-borders--1-inset {
@include pixel-borders($border-inset-color: #ddd);
}
// Two pixel borders
.pixel-borders--2 {
@include pixel-borders($corner-size: 2);
}
.pixel-borders--2-inset {
@include pixel-borders($corner-size: 2);
&::after {
@include pixel-borders($corner-size: 1, $border-color: #ddd);
content: '';
position: absolute;
z-index: 0;
bottom: 0;
right: 0;
border-image-width: 0 1 1 0;
width: calc(100% - 4px);
height: calc(100% - 4px);
}
}
// Examples using the pixel box mixin to colour code the elements
.pixel-box--light {
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #fff);
}
.pixel-box--primary {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #209cee);
}
.pixel-box--success {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #92cc41);
}
.pixel-box--warning {
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #f7d51d);
}
.pixel-box--error {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #e76e55);
}
// Custom examples to show flexibility of the mixins
.pixel-box--light-custom {
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #fff, $border-inset-color: #999, $border-inset-sides: 'all');
}
.pixel-box--primary-custom {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #209cee, $border-inset: false);
}
.pixel-box--success-custom {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #92cc41, $border-inset-sides: 'top-left');
}
.pixel-box--warning-custom {
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #f7d51d, $border-inset-sides: 'all');
}
.pixel-box--error-custom {
color: #fff;
@include pixel-box($corner-size: 1, $border-size: 4px, $background-color: #e76e55, $border-color: #000);
}

View File

@@ -1,222 +1,2 @@
// ----- Demo site styles -----
@import "normalize";
// ----- Base styles -----
*,
*:before,
*:after {
box-sizing: border-box;
}
body {
font-family: "Lato", -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #333;
background-color: #fff;
}
a {
color: #1976D2;
text-decoration: none;
transition: color 0.3s;
&:hover, &:focus {
color: #2196F3;
}
}
// Type
h1, h2, h3, h4, h5, h6 {
font-weight: 300;
small {
font-size: 60%;
}
}
h1, h2 {
margin: 0 0 1rem 0;
}
h3, h4, h5, h6 {
margin: 0 0 .5rem 0;
}
h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.75rem; }
h4 { font-size: 1.5rem; }
h5 { font-size: 1.25rem; }
h6 { font-size: 1rem; }
p {
margin: 0 0 1rem 0;
}
strong, th {
font-weight: 800;
}
pre, code {
font-family: 'Cutive Mono', monospace;
background-color: #f3f3f3;
}
pre {
display: block;
padding: .75rem 1rem;
margin: 0 0 1.5rem 0;
overflow: auto;
font-size: 1rem;
word-break: break-all;
word-wrap: break-word;
border: 1px solid #bbb;
border-radius: 4px;
}
.table {
width: 100%;
margin: 0 0 1rem 0;
border-collapse: collapse;
th, td {
padding: .25rem .5rem;
text-align: left;
vertical-align: top;
border: 1px solid #ddd;
}
}
// ----- Layout -----
.fullwidth {
.container {
width: 100%;
padding-top: 2rem;
padding-bottom: 2rem;
}
}
.fullwidth--sm {
.container {
padding-top: 1rem;
padding-bottom: 1rem;
}
}
.container {
width: 100%;
max-width: 1140px;
margin: 0 auto;
padding-left: 1rem;
padding-right: 1rem;
}
.subsection {
margin: 0 0 2rem 0;
}
.separator {
border-bottom: 1px solid #ddd;
}
// ----- Header and footer -----
.header {
position: sticky;
top: 0;
z-index: 100;
width: 100%;
padding: .5rem 0;
color: #fff;
background-color: #1976D2;
box-shadow: 0 0 6px 6px rgba(0,0,0,0.1);
@media (min-width: 768px) {
padding: 1rem 0;
}
.container {
display: flex;
@media (max-width: 767px) {
flex-flow: column;
}
@media (min-width: 768px) {
align-items: center;
}
}
}
.logo-text {
margin: 0;
@media (max-width: 767px) {
font-size: 1.75rem;
}
}
.header--links {
.btn-demo {
margin: .5rem 0;
&:last-child {
margin-left: .5rem;
}
}
@media (min-width: 768px) {
margin-left: auto;
}
}
.footer {
text-align: center;
}
// ----- Buttons -----
.btn-demo {
display: inline-block;
text-align: center;
vertical-align: middle;
cursor: pointer;
border: 1px solid #bbb;
padding: 4px 12px 6px 12px;
font-size: 18px;
background-color: #fff;
border-radius: 4px;
transition: background-color .3s, color .3s;
&:hover, &:active {
background-color: #f3f3f3;
}
}
.btn-demo--white {
color: #fff;
border-color: #fff;
background-color: transparent;
}
// ----- Utilities -----
.m-0 {
margin: 0;
}
@import "site/normalize";
@import "site/site";

217
src/styles/site/_site.scss Normal file
View File

@@ -0,0 +1,217 @@
// ----- Base styles -----
*,
*:before,
*:after {
box-sizing: border-box;
}
body {
font-family: "Lato", -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #333;
background-color: #fff;
}
a {
color: #1976D2;
text-decoration: none;
transition: color 0.3s;
&:hover, &:focus {
color: #2196F3;
}
}
// Type
h1, h2, h3, h4, h5, h6 {
font-weight: 300;
small {
font-size: 60%;
}
}
h1, h2 {
margin: 0 0 1rem 0;
}
h3, h4, h5, h6 {
margin: 0 0 .5rem 0;
}
h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.75rem; }
h4 { font-size: 1.5rem; }
h5 { font-size: 1.25rem; }
h6 { font-size: 1rem; }
p {
margin: 0 0 1rem 0;
}
strong, th {
font-weight: 800;
}
pre, code {
font-family: 'Cutive Mono', monospace;
background-color: #f3f3f3;
}
pre {
display: block;
padding: .75rem 1rem;
margin: 0 0 1.5rem 0;
overflow: auto;
font-size: 1rem;
word-break: break-all;
word-wrap: break-word;
border: 1px solid #bbb;
border-radius: 4px;
}
.table {
width: 100%;
margin: 0 0 1rem 0;
border-collapse: collapse;
th, td {
padding: .25rem .5rem;
text-align: left;
vertical-align: top;
border: 1px solid #ddd;
}
}
// ----- Layout -----
.fullwidth {
.container {
width: 100%;
padding-top: 2rem;
padding-bottom: 2rem;
}
}
.fullwidth--sm {
.container {
padding-top: 1rem;
padding-bottom: 1rem;
}
}
.container {
width: 100%;
max-width: 1140px;
margin: 0 auto;
padding-left: 1rem;
padding-right: 1rem;
}
.subsection {
margin: 0 0 2rem 0;
}
.separator {
border-bottom: 1px solid #ddd;
}
// ----- Header and footer -----
.header {
position: sticky;
top: 0;
z-index: 100;
width: 100%;
padding: .5rem 0;
color: #fff;
background-color: #1976D2;
box-shadow: 0 0 6px 6px rgba(0,0,0,0.1);
@media (min-width: 768px) {
padding: 1rem 0;
}
.container {
display: flex;
@media (max-width: 767px) {
flex-flow: column;
}
@media (min-width: 768px) {
align-items: center;
}
}
}
.logo-text {
margin: 0;
@media (max-width: 767px) {
font-size: 1.75rem;
}
}
.header--links {
.btn-demo {
margin: .5rem 0;
&:last-child {
margin-left: .5rem;
}
}
@media (min-width: 768px) {
margin-left: auto;
}
}
.footer {
text-align: center;
}
// ----- Buttons -----
.btn-demo {
display: inline-block;
text-align: center;
vertical-align: middle;
cursor: pointer;
border: 1px solid #bbb;
padding: 4px 12px 6px 12px;
font-size: 18px;
background-color: #fff;
border-radius: 4px;
transition: background-color .3s, color .3s;
&:hover, &:active {
background-color: #f3f3f3;
}
}
.btn-demo--white {
color: #fff;
border-color: #fff;
background-color: transparent;
}
// ----- Utilities -----
.m-0 {
margin: 0;
}