-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a4f253
commit 995fbc5
Showing
8 changed files
with
238 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import './style.scss'; | ||
import './js/index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './segmented-control'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { domReady } from '../utils'; // Global utils. | ||
|
||
domReady( function () { | ||
function segmented_control( element ) { | ||
const header = element.querySelector( '.newspack-ui__segmented-control__tabs' ); | ||
const tab_headers = [ ...header.children ]; | ||
const tab_body = element.querySelector( '.newspack-ui__segmented-control__content' ); | ||
let tab_contents = []; | ||
|
||
if ( null !== tab_body ) { | ||
tab_contents = [ ...tab_body.children ]; | ||
} | ||
|
||
tab_headers.forEach( ( tab, i ) => { | ||
if ( tab_contents.length !== 0 && tab.classList.contains( 'selected' ) ) { | ||
tab_contents[ i ].classList.add( 'selected' ); | ||
} | ||
|
||
tab.addEventListener( 'click', function () { | ||
tab_headers.forEach( t => t.classList.remove( 'selected' ) ); | ||
this.classList.add( 'selected' ); | ||
|
||
if ( tab_contents.length !== 0 ) { | ||
tab_contents.forEach( content => content.classList.remove( 'selected' ) ); | ||
tab_contents[ i ].classList.add( 'selected' ); | ||
} | ||
} ); | ||
} ); | ||
} | ||
|
||
[ ...document.querySelectorAll( '.newspack-ui__segmented-control' ) ].forEach( x => | ||
segmented_control( x ) | ||
); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Util functions. | ||
*/ | ||
|
||
/** | ||
* Specify a function to execute when the DOM is fully loaded. | ||
* | ||
* @see https://github.com/WordPress/gutenberg/blob/trunk/packages/dom-ready/ | ||
* | ||
* @param {Function} callback A function to execute after the DOM is ready. | ||
* @return {void} | ||
*/ | ||
export const domReady = callback => { | ||
if ( typeof document === 'undefined' ) { | ||
return; | ||
} | ||
if ( | ||
document.readyState === 'complete' || // DOMContentLoaded + Images/Styles/etc loaded, so we call directly. | ||
document.readyState === 'interactive' // DOMContentLoaded fires at this point, so we call directly. | ||
) { | ||
return void callback(); | ||
} | ||
// DOMContentLoaded has not fired yet, delay callback until then. | ||
document.addEventListener( 'DOMContentLoaded', callback ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.newspack-ui { | ||
&__segmented-control { | ||
align-items: center; | ||
display: flex; | ||
gap: var( --newspack-ui-spacer-2 ); | ||
flex-direction: column; | ||
|
||
&:not( :last-child ) { | ||
margin-bottom: var( --newspack-ui-spacer-2 ); | ||
} | ||
|
||
&__tabs { | ||
background: var( --newspack-ui-color-neutral-10 ); | ||
border-radius: var( --newspack-ui-border-radius-m ); | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: calc( var( --newspack-ui-spacer-base ) / 2 ); | ||
justify-content: center; | ||
padding: calc( var( --newspack-ui-spacer-base ) / 2 ); | ||
|
||
.newspack-ui__button { | ||
background: transparent; | ||
border: 1px solid transparent; | ||
color: var( --newspack-ui-color-neutral-60 ); | ||
margin: 0; | ||
|
||
&.selected { | ||
background: var( --newspack-ui-color-neutral-0 ); | ||
border-color: var( --newspack-ui-color-neutral-30 ); | ||
color: var( --newspack-ui-color-neutral-90 ); | ||
} | ||
} | ||
} | ||
|
||
&__content { | ||
width: 100%; | ||
|
||
> *:not( .selected ) { | ||
display: none; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters