Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement updated design notification banners #7

Merged
merged 13 commits into from
May 7, 2024
22 changes: 22 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": [
"wikimedia/mediawiki",
"wikimedia/client/common",
"wikimedia/language/es2020"
],
"globals": {
"require": "readonly",
"module": "readonly",
"OO": "readonly"
},
"rules": {
"space-before-function-paren": "off",
"no-jquery/no-global-selector": "off",
"vars-on-top": "off",
"one-var": "off",
"no-use-before-define": "off",
"mediawiki/class-doc": "off",
"mediawiki/no-nodelist-unsupported-methods": "off",
"jsdoc/require-param-type": "off"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/node_modules/
composer.lock
package-lock.json
.idea/
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@
"minus-x fix .",
"phpcbf"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
3 changes: 3 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
"styles": [
"styles/ext.networknotice.Notice.less"
],
"scripts": [
"scripts/ext.networknotice.Notice.js"
],
"position": "bottom"
}
},
Expand Down
5 changes: 3 additions & 2 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"networknotice-delete-network-notice-heading": "Delete network notice",
"networknotice-preview-heading": "Preview",
"networknotice-delete-network-notice-deletion-heading": "Confirm deletion",
"networknotice-close-button": "Close notification",

"networknotice-create-notice-desc": "Creates network notices (site notices) that can be displayed network wide, with more features than standard site notices.",
"networknotice-create-notice-label-label": "Label:",
Expand Down Expand Up @@ -56,9 +57,9 @@
"networknotice-button-delete-label": "delete",
"networknotice-text-false-label": "false",
"networknotice-text-true-label": "true",

"networknotice-success-updated": "Network notice successfully updated!",
"networknotice-success-created": "Network notice successfully created!",

"lpextmenu-networknotice": "Network Notice"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"license": "MIT",
"private": true,
"devDependencies": {
"eslint-config-wikimedia": "*",
"stylelint-config-wikimedia": "*"
},
"scripts": {
Expand Down
55 changes: 55 additions & 0 deletions resources/scripts/ext.networknotice.Notice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
( function ( window, document ) {
'use strict';

const LOCAL_STORAGE_KEY = 'networknotice';

function init() {
if ( 'localStorage' in window ) {
document.querySelectorAll( '[data-component="network-notice"]' ).forEach( function( notice ) {
const key = notice.dataset.id;
if ( isInStorage( key ) ) {
notice.classList.add( 'd-none' );
} else {
const closeButton = notice.querySelector(
'[data-component="network-notice-close-button"]'
);
closeButton.onclick = function() {
notice.classList.add( 'd-none' );
putIntoStorage( key );
};
}
} );
}
}

function getItemsFromStorage() {
const items = localStorage.getItem( LOCAL_STORAGE_KEY );
return items ? JSON.parse( items ) : [ ];
}

function putIntoStorage( key ) {
const items = getItemsFromStorage();
if ( !items.includes( key ) ) {
items.push( key );
localStorage.setItem( LOCAL_STORAGE_KEY, JSON.stringify( items ) );
}
}

function isInStorage( key ) {
const items = getItemsFromStorage();
return items.includes( key );
}

/**
* Check on document readyState
*/
if ( document.readyState === 'complete' ) {
init();
} else {
document.addEventListener( 'readystatechange', () => {
if ( document.readyState === 'complete' ) {
init();
}
} );
}
}( window, document ) );
232 changes: 77 additions & 155 deletions resources/styles/ext.networknotice.Notice.less
Original file line number Diff line number Diff line change
@@ -1,171 +1,93 @@
.networknotice {
margin-top: 0.1875rem;
display: block;
text-align: center;
padding: 0.3125rem 1.5rem 0.3125rem 0.3125rem;
margin-bottom: 0.4375rem;
border-left-width: 0.3125rem;
border-left-style: solid;
.network-notice {
min-height: 3rem;
display: grid;
grid-template-columns: auto 3rem;
box-shadow: 0 0.0625rem 0.25rem 0 rgba( 0, 0, 0, 0.12 );
border-radius: 0.5rem;
position: relative;
padding: 0 0 0 1.5rem;
font-size: 0.875rem;
align-items: center;
background-color: #ffffff; // default for Bruinen & LakesideView light theme
margin-bottom: 0.5rem;

a,
a:visited,
a:hover,
a:visited:hover {
color: inherit;
font-weight: bold;
text-decoration: underline;
@media ( min-width: 768px ) {
grid-template-columns: auto 3.75rem;
}

.make-networknotice-skin(
~'default',
var( --network-notice-default-color, #444444 ),
var( --network-notice-default-background-color, #ccccff ),
var( --network-notice-default-border-color, #0000ff )
);

.make-networknotice-skin(
~'inverse',
var( --network-notice-inverse-color, #ffffff ),
var( --network-notice-inverse-background-color, #333333 ),
var( --network-notice-inverse-border-color, #000000 )
);

.make-networknotice(
~'red',
var( --network-notice-red-color, #444444 ),
var( --network-notice-red-background-color, #ffcccc ),
var( --network-notice-red-border-color, #ff0000 )
);

.make-networknotice(
~'green',
var( --network-notice-green-color, #444444 ),
var( --network-notice-green-background-color, #ccffcc ),
var( --network-notice-green-border-color, #00ff00 )
);
.theme--dark & {
background-color: #26292d;
}

.make-networknotice(
~'blue',
var( --network-notice-blue-color, #444444 ),
var( --network-notice-blue-background-color, #ccccff ),
var( --network-notice-blue-border-color, #0000ff )
);
&::before {
content: '';
width: 0.5rem;
top: 0;
bottom: 0;
left: 0;
position: absolute;
background-color: var( --clr-wiki-primary );
border-radius: 0.5rem 0 0 0.5rem;
}

.make-networknotice(
~'lightgrey',
var( --network-notice-lightgrey-color, #444444 ),
var( --network-notice-lightgrey-background-color, #eeeeee ),
var( --network-notice-lightgrey-border-color, #000000 )
);
&__content {
word-break: break-word;

.make-networknotice(
~'darkgrey',
var( --network-notice-darkgrey-color, #444444 ),
var( --network-notice-darkgrey-background-color, #cccccc ),
var( --network-notice-darkgrey-border-color, #333333 )
);
&-wrapper {
border-right: 0.0625rem solid rgba( 0, 0, 0, 0.16 );
margin: 0.5rem 0;
padding-right: 1rem;
display: flex;
align-items: center;
grid-column: 1;

.make-networknotice(
~'yellow',
var( --network-notice-yellow-color, #444444 ),
var( --network-notice-yellow-background-color, #ffffcc ),
var( --network-notice-yellow-border-color, #ffff00 )
);
.theme--dark & {
border-right-color: rgba( 255, 255, 255, 0.16 );
}
}

.make-networknotice(
~'purple',
var( --network-notice-purple-color, #444444 ),
var( --network-notice-purple-background-color, #ffccff ),
var( --network-notice-purple-border-color, #ff00ff )
);
&-icon {
display: inline-flex;
width: 1.5rem;
height: 1.5rem;
align-items: center;
justify-content: center;
margin-right: 0.75rem;
font-size: 1.125rem;
opacity: 0.7;

.make-networknotice(
~'turquoise',
var( --network-notice-turquoise-color, #444444 ),
var( --network-notice-turquoise-background-color, #ccffff ),
var( --network-notice-turquoise-border-color, #00ffff )
);
}
@media ( max-width: 768px ) {
display: none;
}
}
}

html.theme--light .networknotice {
--network-notice-default-color: var( --clr-wiki-on-primary-container );
--network-notice-default-background-color: var( --clr-wiki-primary-container );
--network-notice-default-border-color: var( --clr-wiki-on-primary-container );
--network-notice-inverse-color: var( --clr-wiki-on-primary );
--network-notice-inverse-background-color: var( --clr-wiki-primary );
--network-notice-inverse-border-color: var( --clr-wiki-on-primary-container );
--network-notice-red-color: var( --clr-semantic-negative-10 );
--network-notice-red-background-color: var( --clr-semantic-negative-90 );
--network-notice-red-border-color: var( --clr-semantic-negative-40 );
--network-notice-green-color: var( --clr-semantic-positive-10 );
--network-notice-green-background-color: var( --clr-semantic-positive-90 );
--network-notice-green-border-color: var( --clr-semantic-positive-40 );
--network-notice-blue-color: var( --clr-sapphire-90 );
--network-notice-blue-background-color: var( --clr-sapphire-10 );
--network-notice-blue-border-color: var( --clr-sapphire-90 );
--network-notice-lightgrey-color: var( --clr-on-surface-variant );
--network-notice-lightgrey-background-color: var( --clr-surface-variant );
--network-notice-lightgrey-border-color: var( --clr-on-surface-variant );
--network-notice-darkgrey-color: var( --clr-surface-variant );
--network-notice-darkgrey-background-color: var( --clr-on-surface-variant );
--network-notice-darkgrey-border-color: var( --clr-surface-variant );
--network-notice-yellow-color: var( --clr-sun-10 );
--network-notice-yellow-background-color: var( --clr-sun-90 );
--network-notice-yellow-border-color: var( --clr-sun-40 );
--network-notice-purple-color: var( --clr-redviolet-10 );
--network-notice-purple-background-color: var( --clr-redviolet-90 );
--network-notice-purple-border-color: var( --clr-redviolet-40 );
--network-notice-turquoise-color: var( --clr-elm-10 );
--network-notice-turquoise-background-color: var( --clr-elm-80 );
--network-notice-turquoise-border-color: var( --clr-elm-40 );
}
&__close-button {
width: 2.75rem;
height: 2.75rem;
display: flex;
align-items: center;
justify-content: center;
margin: 0 0.625rem 0 0.375rem;
grid-column: 2;
cursor: pointer;
border-radius: 0.25rem;
transition: background-color 0.2s ease-in-out;

html.theme--dark .networknotice {
--network-notice-default-color: #ffffff;
--network-notice-default-background-color: var( --clr-primary-30 );
--network-notice-default-border-color: var( --clr-primary-30 );
--network-notice-inverse-color: var( --clr-primary-10 );
--network-notice-inverse-background-color: var( --clr-primary-80 );
--network-notice-inverse-border-color: var( --clr-primary-80 );
--network-notice-red-color: #ffffff;
--network-notice-red-background-color: var( --clr-semantic-negative-20 );
--network-notice-red-border-color: var( --clr-semantic-negative-20 );
--network-notice-green-color: #ffffff;
--network-notice-green-background-color: var( --clr-semantic-positive-20 );
--network-notice-green-border-color: var( --clr-semantic-positive-20 );
--network-notice-blue-color: #ffffff;
--network-notice-blue-background-color: var( --clr-sapphire-20 );
--network-notice-blue-border-color: var( --clr-sapphire-20 );
--network-notice-lightgrey-color: var( --clr-moon-20 );
--network-notice-lightgrey-background-color: var( --clr-moon-90 );
--network-notice-lightgrey-border-color: var( --clr-moon-90 );
--network-notice-darkgrey-color: #ffffff;
--network-notice-darkgrey-background-color: var( --clr-moon-20 );
--network-notice-darkgrey-border-color: var( --clr-moon-20 );
--network-notice-yellow-color: var( --clr-sun-90 );
--network-notice-yellow-background-color: var( --clr-sun-10 );
--network-notice-yellow-border-color: var( --clr-sun-10 );
--network-notice-purple-color: var( --clr-redviolet-90 );
--network-notice-purple-background-color: var( --clr-redviolet-10 );
--network-notice-purple-border-color: var( --clr-redviolet-10 );
--network-notice-turquoise-color: var( --clr-elm-80 );
--network-notice-turquoise-background-color: var( --clr-elm-10 );
--network-notice-turquoise-border-color: var( --clr-elm-10 );
}
@media ( min-width: 768px ) {
width: 2rem;
height: 2rem;
margin: 0 1rem 0 0.75rem;
}

.make-networknotice-skin( @theme, @color, @background, @border ) {
&.networknotice-@{theme} {
color: @color;
background-color: @background;
border-left-color: @border;
}
}
@media ( hover: hover ) {
&:hover {
background-color: rgba( 0, 0, 0, 0.16 );

.make-networknotice( @theme, @color, @background, @border ) {
&.networknotice-@{theme} {
color: @color;
background-color: @background;
border-left-color: @border;
.theme--dark & {
background-color: rgba( 255, 255, 255, 0.16 );
}
}
}
}
}
Loading
Loading