Skip to content

Commit

Permalink
feat: new skip style, defined by the UX team (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Mar 3, 2019
1 parent 75e1509 commit 0848df2
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
import React from 'react'
import styled from '@emotion/styled'

// const Example = styled.span
const Example = styled.span`
a.dnb-skip-link {
const ChangeStylesOfSkipLink = styled.span`
a.dnb-show-skip-link {
position: relative;
top: 0;
left: 0;
z-index: 1;
}
a.dnb-skip-link:active,
a.dnb-skip-link:focus {
margin: 0;
&::after {
content: none;
}
}
`

export default () => (
<Example>
<a className="dnb-skip-link dnb-anchor--focus" href="#dnb-app-content">
Skip to content
</a>
</Example>
)
export default () => {
const onClick = e => {
try {
document.querySelector('a.dnb-skip-link').focus()
e.preventDefault()
} catch (e) {
console.log(e)
}
}
return (
<ChangeStylesOfSkipLink>
<a
className="dnb-show-skip-link"
onClick={onClick}
href="#dnb-app-content"
>
Show Skip-Link
</a>
</ChangeStylesOfSkipLink>
)
}
82 changes: 5 additions & 77 deletions packages/dnb-ui-lib/src/style/core/helper-classes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,81 +22,12 @@
.dnb-focus-ring {
@include fakeBorder($focusRingColor, $focusRingWidth, null, !important);
}
@import './helper-classes/skip-link.scss';

// Wraps content inside a visual section banner.
.dnb-section {
position: relative;
z-index: 1;

&::after {
content: '';
position: absolute;
z-index: -1;
left: -50vw;
top: 0;
width: 100vw;
height: 100%;
background-color: var(--color-mint-green-12);

// we use box-shadow to avoid a horizontal scrollbar
box-shadow: 100vw 0 0 0 var(--color-mint-green-12);
}
}
.dnb-section--spacing {
padding-top: 2rem;
padding-bottom: 2rem;
}
.dnb-section--white {
&::after {
background-color: var(--color-white);
box-shadow: 100vw 0 0 0 var(--color-white);
}
}

// How to use the "skip-link"
// 1. Have this on the top of Your App: <a class="dnb-skip-link dnb-button" href="#dnb-app-content">Skip to content</a>
// 2. Place this id="dnb-app-content" on Your main content container
a.dnb-skip-link {
user-select: none;

position: fixed;
z-index: -9999;
top: -100vh;
overflow: hidden;

width: auto;
height: auto;

margin: 0;
padding: 0.75rem 1rem 0.625rem 1rem;
border-radius: 0.5rem;

white-space: nowrap;

font-size: var(--font-size-medium);
color: var(--color-sea-green);
text-decoration: none;
background-color: var(--color-white);

@include fakeFocus();
}
a.dnb-skip-link:hover {
color: var(--color-sea-green);
background-color: var(--color-mint-green-50);
}
a.dnb-skip-link:active {
color: var(--color-white);
background-color: var(--color-emerald-green);
}
a.dnb-skip-link:focus,
a.dnb-skip-link:active {
z-index: 9999;
top: auto;

margin: 1rem 45vw;
@include allBelow(small) {
margin: 1rem 35%;
}
// Cosmetic helpers
@import './helper-classes/dnb-section.scss';
.dnb-unstyled-list {
@include unstyledList();
}

// Layout management
Expand Down Expand Up @@ -157,9 +88,6 @@ a.dnb-skip-link:active {
.dnb-not-sr-only {
@include notSrOnly();
}
.dnb-unstyled-list {
@include unstyledList();
}

// Form
.dnb-form-group {
Expand Down
29 changes: 29 additions & 0 deletions packages/dnb-ui-lib/src/style/core/helper-classes/dnb-section.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Wraps content inside a visual section banner.
.dnb-section {
position: relative;
z-index: 1;

&::after {
content: '';
position: absolute;
z-index: -1;
left: -50vw;
top: 0;
width: 100vw;
height: 100%;
background-color: var(--color-mint-green-12);

// we use box-shadow to avoid a horizontal scrollbar
box-shadow: 100vw 0 0 0 var(--color-mint-green-12);
}
}
.dnb-section--spacing {
padding-top: 2rem;
padding-bottom: 2rem;
}
.dnb-section--white {
&::after {
background-color: var(--color-white);
box-shadow: 100vw 0 0 0 var(--color-white);
}
}
102 changes: 102 additions & 0 deletions packages/dnb-ui-lib/src/style/core/helper-classes/skip-link.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
@mixin skipLink() {
position: fixed;
z-index: 9999;
top: 35%;
left: 40%;

margin: 0;
padding: 0.8125rem 1rem 0.6875rem 1rem;

white-space: nowrap;

font-size: var(--font-size-default);
color: var(--color-sea-green);
text-decoration: none;
text-align: center;

user-select: none;
outline: none;

background-color: transparent;
border-radius: 0;
border: none;
box-shadow: none;

&::after {
content: '';
position: absolute;
z-index: -2;
left: -200vw;
top: -200vh;
width: 150vw;
height: 150vh;

background-color: rgba(255, 255, 255, 0.85);

// we use box-shadow to avoid a horizontal scrollbar
box-shadow: 150vw 150vh 0 0 rgba(255, 255, 255, 0.85);
}

&::before {
content: '';
position: absolute;
z-index: -1;
left: 0;
top: 0;
width: 100%;
height: 100%;
border-radius: 1.5rem; //same as anchor

background-color: var(--color-white);

@include fakeFocus('mouse');
}

&:hover::before {
background-color: var(--color-mint-green-50);
}
&:active::before {
background-color: var(--color-emerald-green);
}
//focus
&:focus:not(:active)::before {
@include fakeFocus();
}

//focus
&:focus {
opacity: 1;
}
&:hover,
&:focus:not(:hover):not(:active) {
color: var(--color-sea-green);
background-color: transparent;
box-shadow: none;
}
// stylelint-disable-next-line
&:active {
color: var(--color-white);
background-color: transparent;
}
}

// How to use the "skip-link"
// 1. Have this on the top of Your App: <a class="dnb-skip-link dnb-button" href="#dnb-app-content">Skip to content</a>
// 2. Place this id="dnb-app-content" on Your main content container
a.dnb-skip-link {
position: fixed;
z-index: -9999;
top: -100vh;
opacity: 0.3;
transition: opacity 0.2s ease-out;
// @include allBelow(medium) {
// display: none;
// }
}
a.dnb-show-skip-link,
a.dnb-skip-link:focus {
@include skipLink();
}
[dnb-is-touch] a.dnb-skip-link {
display: none;
}
13 changes: 2 additions & 11 deletions packages/dnb-ui-lib/stories/helperStories.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ const stories = []
export default stories

const SkipLinkReset = styled.div`
${'' /* background: blue; */}
a.dnb-skip-link {
position: relative;
top: 0;
z-index: 1;
}
a.dnb-skip-link:active,
a.dnb-skip-link:focus {
margin: 0;
}
/* empty */
`

stories.push([
Expand All @@ -30,7 +21,7 @@ stories.push([
<Box>
<SkipLinkReset>
<a
className="dnb-skip-link dnb-anchor--focus"
className="dnb-show-skip-link"
href="#dnb-app-content"
onClick={e => e.preventDefault()}
>
Expand Down
4 changes: 2 additions & 2 deletions packages/dnb-ui-lib/stories/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const Box = styled.div`
content: '';
position: absolute;
left: -50vw;
right: -50vw;
bottom: 0;
width: 100vw;
width: 200vw;
border-bottom: dashed 1px rgb(0, 200, 200);
box-shadow: 100vw 0 0 0 rgb(0, 200, 200);
}
`

0 comments on commit 0848df2

Please sign in to comment.