Skip to content
This repository has been archived by the owner on Oct 6, 2018. It is now read-only.

Commit

Permalink
Non-backwards compatible: adding a new Hide utility and removing the …
Browse files Browse the repository at this point in the history
…hide utilities from the Display utility
  • Loading branch information
Chris Pearce committed Apr 9, 2015
1 parent 9524eca commit 3569a05
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 192 deletions.
205 changes: 13 additions & 192 deletions utilities/_u-display.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


/**
* A utility for applying the most common types of box renderings and for
* hiding/showing elements.
* A utility for applying the most common types of box renderings.
*
* @todo
* Look at adding 'Flexbox'?
Expand All @@ -25,34 +24,11 @@ $u-display-apply-at-breakpoints-for-inline: false !default;

$u-display-apply-at-breakpoints-for-inline-block: false !default;

$u-display-apply-at-breakpoints-for-table: false !default;

$u-display-apply-at-breakpoints-for-table-row: false !default;

$u-display-apply-at-breakpoints-for-table-cell: false !default;

$u-display-apply-at-breakpoints-for-inherit: false !default;

$u-display-apply-at-breakpoints-for-hide: false !default;

$u-display-apply-at-breakpoints-for-hide-invisible: false !default;

$u-display-apply-at-breakpoints-for-hide-visually: false !default;

/**
* Classes to detect if JavaScript is on or off.
*/

$u-display-js-is-on-class: js !default;

$u-display-js-is-off-class: no-js !default;


/**
* Block, inline, and inline-block display.
* Block.
*/

// Block
%u-display-block,
.u-display-block {display: block;}

Expand All @@ -61,7 +37,11 @@ $u-display-js-is-off-class: no-js !default;
$u-display-apply-at-breakpoints) {display: block;}
}// end if

// Inline

/**
* Inline.
*/

%u-display-inline,
.u-display-inline {display: inline;}

Expand All @@ -70,174 +50,15 @@ $u-display-js-is-off-class: no-js !default;
$u-display-apply-at-breakpoints) {display: inline;}
}// end if

// Inline block

/**
* Inline-block.
*/

%u-display-inline-block,
.u-display-inline-block {display: inline-block;}

@if $u-display-apply-at-breakpoints-for-inline-block {
@include generate-at-breakpoints('.u-display-inline-block',
$u-display-apply-at-breakpoints) {display: inline-block;}
}// end if


/**
* Table display.
*/

// Table
%u-display-table,
.u-display-table {display: table;}

@if $u-display-apply-at-breakpoints-for-table {
@include generate-at-breakpoints('.u-display-table',
$u-display-apply-at-breakpoints) {display: table;}
}// end if

// Table row
%u-display-table-row,
.u-display-table-row {display: table-row;}

@if $u-display-apply-at-breakpoints-for-table-row {
@include generate-at-breakpoints('.u-display-table-row',
$u-display-apply-at-breakpoints) {display: table-row;}
}// end if

// Table cell
%u-display-table-cell,
.u-display-table-cell {display: table-cell;}

@if $u-display-apply-at-breakpoints-for-table-cell {
@include generate-at-breakpoints('.u-display-table-cell',
$u-display-apply-at-breakpoints) {display: table-cell;}
}// end if


/**
* Inherit.
*/

%u-display-inherit,
.u-display-inherit {display: inherit;}

@if $u-display-apply-at-breakpoints-for-inherit {
@include generate-at-breakpoints('.u-display-inherit',
$u-display-apply-at-breakpoints) {display: inherit;}
}// end if


/**
* Hide elements from both screen readers and the document flow.
*/

%u-hide,
.u-hide {
display: none;
visibility: hidden;
}

@if $u-display-apply-at-breakpoints-for-hide {
@include generate-at-breakpoints('.u-hide', $u-display-apply-at-breakpoints) {
display: none;
visibility: hidden;
}
}// end if


/**
* Hide elements without affecting the document flow.
*/

%u-hide-invisible,
.u-hide-invisible {visibility: hidden;}

@if $u-display-apply-at-breakpoints-for-hide-invisible {
@include generate-at-breakpoints('.u-hide-invisible',
$u-display-apply-at-breakpoints) {visibility: hidden;}
}// end if


/**
* Hide elements only visually but have it available for screen readers.
*/

%u-hide-visually,
.u-hide-visually {
position: absolute;
height: 1px;
width: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
margin: -1px;
padding: 0;
border: 0;


/**
* Form `legend`s need different treatment.
*/

&.legend {left: $off-screen-distance;}
}

@if $u-display-apply-at-breakpoints-for-hide-visually {
@include generate-at-breakpoints('.u-hide-visually',
$u-display-apply-at-breakpoints) {
position: absolute;
height: 1px;
width: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
margin: -1px;
padding: 0;
border: 0;


/**
* Form `legend`s need different treatment.
*/

&.legend {left: $off-screen-distance;}
}
}// end if


/**
* Hide elements for JavaScript users and non-JavaScript users, this is
* necessary when building accessibile and progressively enhanced UI's.
*
* N.B. this will require functionality that can append a hook to an element
* (typically the `html` element) if JavaScript is on.
*
* N.B. it is okay to use `!important` here as we're doing it pre-emptively
* i.e. you know you will always want the rule it's applied too to take
* precedence.
*/

// Hide / show elements if JavaScript is on
.#{$u-display-js-is-on-class} .u-hide-if-js-is-on {display: none !important;}

// Hide / show elements if JavaScript is off
.#{$u-display-js-is-off-class} .u-hide-if-js-is-off {display: none !important;}


/**
* Hide / show elements for print media.
*/

// Show
.u-show-for-print,
.u-show-for-print-inline,
.u-show-for-print-inline-block {display: none;}

@media print {

// Hide
.u-hide-for-print {display: none;}

// Show
.u-show-for-print {display: block;}

.u-show-for-print-inline {display: inline;}

.u-show-for-print-inline-block {display: inline-block;}
}
}// end if
142 changes: 142 additions & 0 deletions utilities/_u-hide.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/* ============================================================================
@UTILITIES -> HIDE
========================================================================= */


/**
* A utility for hiding (and showing) elements.
*/


/**
* Apply at these breakpoints (turned off by default).
*/

$u-hide-apply-at-breakpoints: $default-breakpoints !default;

// From the above breakpoints choose which utilities you wish to apply it too
$u-hide-apply-at-breakpoints-for-hide: false !default;

$u-hide-apply-at-breakpoints-for-hide-invisible: false !default;

$u-hide-apply-at-breakpoints-for-hide-visually: false !default;

/**
* Classes to detect if JavaScript is on or off.
*/

$u-hide-js-is-on-class: js !default;

$u-hide-js-is-off-class: no-js !default;


/**
* Hide elements from both screen readers and the document flow.
*/

%u-hide,
.u-hide {
display: none;
visibility: hidden;
}

@if $u-hide-apply-at-breakpoints-for-hide {
@include generate-at-breakpoints('.u-hide', $u-hide-apply-at-breakpoints) {
display: none;
visibility: hidden;
}
}// end if


/**
* Hide elements without affecting the document flow.
*/

%u-hide-invisible,
.u-hide-invisible {visibility: hidden;}

@if $u-hide-apply-at-breakpoints-for-hide-invisible {
@include generate-at-breakpoints('.u-hide-invisible',
$u-hide-apply-at-breakpoints) {visibility: hidden;}
}// end if


/**
* Hide elements only visually but have it available for screen readers.
*/

%u-hide-visually,
.u-hide-visually {
position: absolute;
height: 1px;
width: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
margin: -1px;
padding: 0;
border: 0;


/**
* Form `legend`s need different treatment.
*/

&.legend {left: $off-screen-distance;}
}

@if $u-hide-apply-at-breakpoints-for-hide-visually {
@include generate-at-breakpoints('.u-hide-visually',
$u-hide-apply-at-breakpoints) {
position: absolute;
height: 1px;
width: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
margin: -1px;
padding: 0;
border: 0;

&.legend {left: $off-screen-distance;}
}
}// end if


/**
* Hide elements for JavaScript users and non-JavaScript users, this is
* necessary when building accessibile and progressively enhanced UI's. This
* will require functionality that can append a hook to an element
* (typically the `html` element) if JavaScript is on.
*
* N.B. it is okay to use `!important` here as we're doing it pre-emptively
* i.e. you know you will always want the rule it's applied too to take
* precedence.
*/

// Hide/show elements if JavaScript is on
.#{$u-hide-js-is-on-class} .u-hide-if-js-is-on {display: none !important;}

// Hide/show elements if JavaScript is off
.#{$u-hide-js-is-off-class} .u-hide-if-js-is-off {display: none !important;}


/**
* Hide/show elements for print media.
*/

// Show
.u-show-for-print,
.u-show-for-print-inline,
.u-show-for-print-inline-block {display: none;}

@media print {

// Hide
.u-hide-for-print {display: none;}

// Show
.u-show-for-print {display: block;}

.u-show-for-print-inline {display: inline;}

.u-show-for-print-inline-block {display: inline-block;}
}

0 comments on commit 3569a05

Please sign in to comment.