Merge remote-tracking branch 'origin/color-variables' into color-variables

pull/7748/head
Guilherme Gazzo 8 years ago
commit 32e3760f04
  1. 2
      packages/rocketchat-authorization/package.js
  2. 2
      packages/rocketchat-message-attachments/package.js
  3. 2
      packages/rocketchat-theme/client/imports/components/message-box.css
  4. 14
      packages/rocketchat-theme/client/imports/forms/popup-list.css
  5. 18
      packages/rocketchat-theme/client/imports/forms/select-avatar.css
  6. 4
      packages/rocketchat-theme/client/imports/forms/switch.css
  7. 14
      packages/rocketchat-theme/client/imports/forms/tags.css
  8. 28
      packages/rocketchat-theme/client/imports/general/variables.css
  9. 16
      packages/rocketchat-theme/server/variables.js
  10. 160
      packages/rocketchat-ui-master/server/dynamic-css.js
  11. 2
      packages/rocketchat-ui-vrecord/package.js

@ -10,7 +10,7 @@ Package.onUse(function(api) {
api.use([
'ecmascript',
'underscore',
'rocketchat:lib',
'rocketchat:lib'
]);
api.use('mongo', ['client', 'server']);

@ -10,7 +10,7 @@ Package.onUse(function(api) {
'templating',
'ecmascript',
'underscore',
'rocketchat:lib',
'rocketchat:lib'
]);
api.addFiles('client/messageAttachment.html', 'client');

@ -15,7 +15,7 @@
width: 100%;
height: 24px;
color: var(---message-box-markdown-color);
color: var(--message-box-markdown-color);
justify-content: center;
&-item {

@ -7,8 +7,8 @@
width: 100%;
padding: 1rem;
border-radius: 2px;
background-color: var(--color-white);
border-radius: var(--popup-list-border-radius);
background-color: var(--popup-list-background);
box-shadow: 0 0 2px 0 rgba(47, 52, 61, 0.08), 0 0 12px 0 rgba(47, 52, 61, 0.12);
}
@ -19,15 +19,15 @@
cursor: pointer;
border-radius: 2px;
border-radius: var(--popup-list-border-radius);
align-items: center;
&.selected {
background-color: #f2f3f5;
background-color: var(--popup-list-selected-background);
}
&:hover {
background-color: #f2f3f5;
background-color: var(--popup-list-background-hover);
}
&-image {
@ -37,9 +37,9 @@
}
&-name {
color: #2d343d;
color: var(--popup-list-name-color);
font-size: 1rem;
font-size: var(--popup-list-name-size);
}
}
}

@ -3,10 +3,10 @@
align-items: flex-start;
&__preview {
flex: 0 0 150px;
flex: 0 0 var(--select-avatar-preview-size);
width: 150px;
height: 150px;
width: var(--select-avatar-preview-size);
height: var(--select-avatar-preview-size);
margin-right: 1rem;
}
@ -26,8 +26,8 @@
flex-wrap: wrap;
&-item {
width: 48px;
height: 48px;
width: var(--select-avatar-size);
height: var(--select-avatar-size);
margin-right: 10px;
margin-bottom: 10px;
@ -48,13 +48,13 @@
cursor: pointer;
color: #2d343d;
background: var(--color-gray-light);
color: var(--select-avatar-upload-color);
background: var(--select-avatar-upload-background);
}
&__upload-icon {
width: 48px;
height: 48px;
width: var(--select-avatar-size);
height: var(--select-avatar-size);
padding: 12px;
fill: currentColor;
}

@ -13,8 +13,8 @@
& + .rc-switch__button {
cursor: default;
border-color: var(--color-gray-light);
background-color: #f2f3f5;
border-color: var(--button-disabled-background);
background-color: var(--color-gray-lightest);
}
& ~ .rc-switch__text {

@ -5,9 +5,9 @@
min-height: 43px;
padding: 0 1rem 0 3.25rem;
border-width: 1px;
border-color: var(--color-gray-light);
border-radius: 2px;
border-width: var(--tags-border-width);
border-color: var(--tags-border-color);
border-radius: var(--tags-border-radius);
background-color: transparent;
flex-wrap: wrap;
justify-content: flex-start;
@ -18,13 +18,13 @@
margin: 0.25rem;
padding: 0.35rem 0.5rem;
color: var(--color-dark);
background: #f2f3f5;
color: var(--tags-text-color);
background: var(--tags-background);
align-items: center;
&-avatar {
width: 20px;
height: 20px;
width: var(--tags-avatar-size);
height: var(--tags-avatar-size);
margin-right: 0.5rem;
}

@ -75,6 +75,34 @@
--input-description-text-size: var(--input-font-size);
--input-error-color: var(--color-error);
/*
* Forms - popup list
*/
--popup-list-border-radius: var(--border-radius);
--popup-list-background: var(--color-white);
--popup-list-background-hover: var(--color-gray-lightest);
--popup-list-selected-background: var(--color-gray-lightest);
--popup-list-name-color: #2d343d;
--popup-list-name-size: 1rem;
/*
* Forms - tags
*/
--tags-border-width: var(--border);
--tags-border-radius: var(--border-radius);
--tags-border-color: var(--color-gray-light);
--tags-text-color: var(--color-dark);
--tags-background: #f2f3f5;
--tags-avatar-size: 20px;
/*
* Forms - select avatar
*/
--select-avatar-size: 48px;
--select-avatar-preview-size: 150px;
--select-avatar-upload-background: var(--color-gray-light);
--select-avatar-upload-color: #2d343d;
/*
* Modal
*/

@ -39,23 +39,7 @@ const minorColors= {
'status-offline': '@transparent-darker'
};
// const content = [
// {
// name: 'content',
// properties: ['background-color'],
// value: '#ffffff'
// },
// {
// name: 'content-color',
// properties: ['color'],
// value: '#414852'
// }
// ];
// content.forEach(setting => RocketChat.theme.addColor(setting.name, setting.value, 'Content', setting.properties));
// Bulk-add settings for color scheme
Object.keys(majorColors).forEach((key) => {
const value = majorColors[key];
RocketChat.theme.addPublicColor(key, value, 'Colors');

@ -2,7 +2,6 @@
'use strict';
export default () => {
const debounce = (func, wait, immediate) => {
let timeout;
return function(...args) {
@ -16,143 +15,46 @@ export default () => {
callNow && func.apply(this, args);
};
};
const cssVarPoly = {
init() {
console.time('cssVarPoly');
cssVarPoly.ratifiedVars = {};
cssVarPoly.varsByBlock = [];
cssVarPoly.oldCSS = [];
cssVarPoly.findCSS();
cssVarPoly.updateCSS();
console.timeEnd('cssVarPoly');
},
findCSS() {
const styleBlocks = Array.prototype.concat.apply([], document.querySelectorAll('#css-variables, link[type="text/css"].__meteor-css__'));
// we need to track the order of the style/link elements when we save off the CSS, set a counter
let counter = 1;
// loop through all CSS blocks looking for CSS variables being set
styleBlocks.map(block => {
// console.log(block.nodeName);
if (block.nodeName === 'STYLE') {
const theCSS = block.innerHTML;
cssVarPoly.findSetters(theCSS, counter);
cssVarPoly.oldCSS[counter++] = theCSS;
} else if (block.nodeName === 'LINK') {
const url = block.getAttribute('href');
cssVarPoly.oldCSS[counter] = '';
cssVarPoly.getLink(url, counter, function(counter, request) {
cssVarPoly.findSetters(request.responseText, counter);
cssVarPoly.oldCSS[counter++] = request.responseText;
cssVarPoly.updateCSS();
});
}
});
},
// find all the "--variable: value" matches in a provided block of CSS and add them to the master list
findSetters(theCSS, counter) {
// console.log(theCSS);
cssVarPoly.varsByBlock[counter] = theCSS.match(/(--[^:; ]+:..*?;)/g);
},
// run through all the CSS blocks to update the variables and then inject on the page
updateCSS: debounce(() => {
// first lets loop through all the variables to make sure later vars trump earlier vars
cssVarPoly.ratifySetters(cssVarPoly.varsByBlock);
// loop through the css blocks (styles and links)
cssVarPoly.oldCSS.filter(e => e).forEach((css, id) => {
const newCSS = cssVarPoly.replaceGetters(css, cssVarPoly.ratifiedVars);
const el = document.querySelector(`#inserted${ id }`);
if (el) {
// console.log("updating")
el.innerHTML = newCSS;
} else {
// console.log("adding");
const style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = newCSS;
style.classList.add('inserted');
style.id = `inserted${ id }`;
document.getElementsByTagName('head')[0].appendChild(style);
}
});
}, 100),
// parse a provided block of CSS looking for a provided list of variables and replace the --var-name with the correct value
replaceGetters(oldCSS, varList) {
return oldCSS.replace(/var\((--.*?)\)/gm, (all, variable) => varList[variable]);
},
const style = document.createElement('style');
style.type = 'text/css';
style.id = 'rocketchat-dynamic-css';
// determine the css variable name value pair and track the latest
ratifySetters(varList) {
// loop through each block in order, to maintain order specificity
varList.filter(curVars => curVars).forEach(curVars => {
// const curVars = varList[curBlock] || [];
curVars.forEach(function(theVar) {
// console.log(theVar);
// split on the name value pair separator
const matches = theVar.split(/:\s*/);
// console.log(matches);
// put it in an object based on the varName. Each time we do this it will override a previous use and so will always have the last set be the winner
// 0 = the name, 1 = the value, strip off the ; if it is there
cssVarPoly.ratifiedVars[matches[0]] = matches[1].replace(/;/, '');
});
});
Object.keys(cssVarPoly.ratifiedVars).filter(key => {
return cssVarPoly.ratifiedVars[key].indexOf('var') > -1;
}).forEach(key => {
cssVarPoly.ratifiedVars[key] = cssVarPoly.ratifiedVars[key].replace(/var\((--.*?)\)/gm, function(all, variable) {
return cssVarPoly.ratifiedVars[variable];
});
});
},
// get the CSS file (same domain for now)
getLink(url, counter, success) {
const request = new XMLHttpRequest();
request.open('GET', url, true);
request.overrideMimeType('text/css;');
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
// Success!
// console.log(request.responseText);
if (typeof success === 'function') {
success(counter, request);
}
} else {
// We reached our target server, but it returned an error
console.warn('an error was returned from:', url);
}
};
DynamicCss = typeof DynamicCss !=='undefined'? DynamicCss : {list:[]};
request.onerror = function() {
// There was a connection error of some sort
console.warn('we could not get anything from:', url);
};
const colors = setting => {
if (setting._id.indexOf('theme-color') > -1) {
return setting.properties.map(property => {
const temp = setting._id.replace('theme-color-', '').split(':');
const settingName = temp[0];
const pseudo = temp[1] || '';
const propertyName = property.replace('color', '').replace('-', '');
const className = propertyName ? `${ settingName }-${ propertyName }` : settingName;
request.send();
return `.${ className }${ pseudo ? ':' : '' }${ pseudo }{${ property }:${ setting.value }}`;
}).join('\n');
}
return '';
};
const stateCheck = setInterval(() => {
if (document.readyState === 'complete' && typeof Meteor !== 'undefined') {
clearInterval(stateCheck);
// document ready
cssVarPoly.init();
}
}, 100);
DynamicCss = typeof DynamicCss !=='undefined'? DynamicCss : {};
DynamicCss.test = () => window.CSS && window.CSS.supports && window.CSS.supports('(--foo: red)');
DynamicCss.run = debounce((replace = false) => {
const customCss = setting => setting._id.indexOf('theme-custom-css') > -1 ? setting.value : '';
const fontFamily = setting => setting._id.indexOf('theme-font-body-font-family') > -1 ? `body{${ setting.value }}` : '';
if (replace) {
document.querySelector('#css-variables').innerHTML = RocketChat.settings.get('theme-custom-variables');
}
cssVarPoly.init();
const properties = [fontFamily, colors, customCss];
const run = list => {
return list.filter(setting => setting.value && setting.properties || setting.type !== 'color')
.sort((a, b) => a._id.length - b._id.length)
.map(setting => properties.reduce((ret, f) => ret || f(setting), ''))
.join('\n');
};
DynamicCss.run = debounce(() => {
const list = typeof RocketChat !== 'undefined' ? RocketChat.settings.collection.find({_id:/theme/}).fetch() : [];
return style.innerHTML = run(list.length && list || DynamicCss.list);
}, 1000);
document.head.appendChild(style);
DynamicCss.run();
};

@ -12,7 +12,7 @@ Package.onUse(function(api) {
'templating',
'underscore',
'tracker',
'rocketchat:lib',
'rocketchat:lib'
]);

Loading…
Cancel
Save