Changing the bar under the tabpanel labels in ExtJS 4.2 - css

I'm developing a Web App using ExtJS 4.2, and I want the layout to look something like this:
So far, I've implemented the different colors for the Tab Label. I made a css file with the following properties:
.x-tab-first.x-tab-default-top{
background: rgb(0, 169, 180) !important;
}
.x-tab-second.x-tab-default-top{
background: rgb(251, 183, 18) !important;
}
.x-tab-third.x-tab-default-top{
background: rgb(2, 153, 130) !important;
}
And in each of the tab in the tab panel, I assigned the corresponding class as their cls, so the first tab has x-tab-first as its cls, and so on.
But as you can see in the following photo, if I click on "Find us here", the tab contents changes accordingly, but the bar below does not change:
And for the other two tabs, the bar below does not change as well, it just stays as is.
I have tried this:
.x-tab-second-active.x-tab-bar-body{
background: rgb(251, 183, 18) !important;
}
However I am not quite sure where and how to place this code.
I want the bar below the tab titles to follow the color as well.

As per your requirement, you need to add your activeTab cls to tabbar-strip by manually on tabchange event.
In this FIDDLE, I have created a demo using tabpanel. I hope this will help/guide you to achieve your requirement.
CODE SNIPPET
CSS part
<style>
.x-my-tabpanel .x-tab-bar {
background: red;
}
.x-my-tabpanel .x-tab-default-top {
border: 0px !important;
box-shadow: 0px 0px 0px;
}
.x-my-tabpanel .x-tab-bar-strip {
top: 23px;
height: 5px !important;
}
.x-tab-first.x-tab-default-top,
.x-tab-first.x-tab-bar-strip {
background: rgb(0, 169, 180);
border-color: rgb(0, 169, 180);
}
.x-tab-second.x-tab-default-top,
.x-tab-second.x-tab-bar-strip {
background: rgb(251, 183, 18);
border-color: rgb(251, 183, 18);
}
.x-tab-third.x-tab-default-top,
.x-tab-third.x-tab-bar-strip {
background: rgb(2, 153, 130);
border-color: rgb(2, 153, 130);
}
.x-my-tabpanel .x-tab .x-tab-inner {
color: #fff;
}
</style>
ExtJS part
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.tab.Panel', {
height: 200,
renderTo: Ext.getBody(),
cls: 'x-my-tabpanel',
activeTab: 0,
defaults: {
padding: 10
},
items: [{
title: 'What to Expect',
html: 'What to Expect'
}, {
title: 'Find us here',
html: 'Find us here'
}, {
title: 'Game Machenics',
html: 'Game Machenics'
}],
listeners: {
/*
* this event will fire on view render
*/
afterrender: function (panel) {
var clsArr = ['first', 'second', 'third'];
panel.query('tab').forEach((item, index) => {
let cls = `x-tab-${clsArr[index]}`;
item.addCls(cls);
item.cls = cls;
});
this.addToStripCls();
},
/*
* this event will fire on tab change
*/
tabchange: function (panel, newtab) {
this.addToStripCls();
}
},
/*
* this function will set active tab cls to strip
* before to adding we need to remove previous cls
*/
addToStripCls: function () {
var strip = Ext.get(this.el.query('.x-tab-bar-strip')[0]),
clsArr = ['first', 'second', 'third']
clsArr.forEach(el => {
if (strip.hasCls(`x-tab-${el}`)) {
strip.removeCls(`x-tab-${el}`);
}
});
strip.addCls(this.activeTab.tab.cls);
}
});
}
});

Related

Add custom bindTooltip class

I am trying to add custom class to my bindTooltip but the new class do not show up. My method based on this question.
My custom popup class is working fine but if I want to overwrite the tooltip class than it is now working.
My JS code:
var PopupClass={'className': 'class-popup'}
var TooltipClass={'className': 'class-tooltip'}
L.marker(
[46.17319713, 21.34458608],
{icon: OnlineMarker}
).bindPopup(
'Test Popup',
PopupClass
).bindTooltip(
'Test Tooltip',
{direction: 'top', permanent: true, offset: [10,0]},
TooltipClass
).addTo(MyMap)
My CSS code:
/* popup-class*/
.class-popup .leaflet-popup-content-wrapper {
background:#2980b9;
color:#fff;
font-size:10px;
line-height:10px;
}
.class-popup .leaflet-popup-content-wrapper a {
color:#2980b9;
}
.class-popup .leaflet-popup-tip-container {
width:40px;
height:20px;
}
.class-popup .leaflet-popup-tip {
background:#2980b9;
}
/* tooltip-class*/
.class-tooltip{
background: green;
border: 2px solid cyan
}
.leaflet-tooltip-left.class-tooltip::before {
border-left-color: cyan;
}
.leaflet-tooltip-right.class-tooltip::before {
border-right-color: cyan;
}
You have 2 issues:
You try to specify your Tooltip class using a 3rd argument of .bindTooltip, which does not do anything as per Leaflet doc. Instead, you should merge your className key in the 2nd argument (options). For that, you can either:
write it directly within the options
extend your TooltipClass with your options: L.Util.extend(myOptions, TooltipClass)
use the ES2018 spread operator to do the same as the above point.
Your .class-tooltip selector in CSS is not enough to override the default Leaflet style. Increase your selector specificity, e.g. adding the Leaflet tooltip class: .leaflet-tooltip.class-tooltip
var MyMap = L.map('map').setView([46.17319713, 21.34458608], 11);
var PopupClass = {
'className': 'class-popup'
}
var TooltipClass = {
'className': 'class-tooltip'
}
L.marker([46.17319713, 21.34458608])
.bindPopup('Test Popup', PopupClass)
.bindTooltip('Test Tooltip', {
direction: 'top',
permanent: true,
offset: [10, 0],
//'className': 'class-tooltip'
...TooltipClass // using spread operator (ES2018)
}, TooltipClass) // 3rd argument does not do anything
.addTo(MyMap);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(MyMap);
/* popup-class*/
.class-popup .leaflet-popup-content-wrapper {
background: #2980b9;
color: #fff;
font-size: 10px;
line-height: 10px;
}
.class-popup .leaflet-popup-content-wrapper a {
color: #2980b9;
}
.class-popup .leaflet-popup-tip-container {
width: 40px;
height: 20px;
}
.class-popup .leaflet-popup-tip {
background: #2980b9;
}
/* tooltip-class*/
.leaflet-tooltip.class-tooltip {
background: green;
border: 2px solid cyan
}
.leaflet-tooltip-left.class-tooltip::before {
border-left-color: cyan;
}
.leaflet-tooltip-right.class-tooltip::before {
border-right-color: cyan;
}
<link rel="stylesheet" href="https://unpkg.com/leaflet#1.3.1/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin="" />
<script src="https://unpkg.com/leaflet#1.3.1/dist/leaflet-src.js" integrity="sha512-IkGU/uDhB9u9F8k+2OsA6XXoowIhOuQL1NTgNZHY1nkURnqEGlDZq3GsfmdJdKFe1k1zOc6YU2K7qY+hF9AodA==" crossorigin=""></script>
<div id="map" style="height: 180px"></div>

how to add border to header and body of tabpanel xtype

Creating an EXT js file:
Add border to header and body of tabpanel.
I have tried adding below stuff in .scss file, but did not work.
*.scss
.maintabpanel1 {
.x-tab-bar-plain { border:1px solid red !important;
}
.x-tab-bar-top+.x-panel-body, .x-panel.x-tabpanel-child {
border: 1px solid green !important;`enter code here`
}
You need to provide cls and bodyCls to your tabpanel.
An cls optional extra CSS class that will be added to this component's Element. The value can be a string, a list of strings separated by spaces, or an array of strings. This can be useful for adding customized styles to the component or any of its children using standard CSS rules.
A bodyCls class, space-delimited string of classes, or array of classes to be applied to the panel's body element.
In this gitlab-repo, I have created a demo using ExtJS6.2. I hope this will help/guide you to achieve your requirements.
screenshot from my local.
CODE SNIPPET
Ext.define('GeoLocation.view.main.Main', {
extend: 'Ext.tab.Panel',
xtype: 'app-main',
cls: 'x-geo-tab',
bodyCls: 'x-geo-tab-body',
controller: 'main',
titleRotation: 0,
tabRotation: 0,
activeTab: 0,
items: [{
title: 'Tab 1',
html: 'it is tab 1'
}, {
title: 'Tab 2',
html: 'it is tab 2'
}, {
title: 'Tab 3',
html: 'it is tab 3'
}]
});
CSS part
.x-geo-tab {
.x-tab-bar-default {
background-color: #ece2e2;
border: 2px solid red !important;
padding: 5px;
.x-tab-bar-strip-default {
background-color: red;
height: 2px !important;
}
}
.x-geo-tab-body {
border: 2px solid green !important;
padding: 10px;
}
}

How to assign different colors to multiple markercluster groups?

I am working with the leaflet.markercluster plugin and have it working so it clusters my markers. Is it possible to assign a specific color to multiple cluster groups? Right now, all the cluster marker colors are the same between various layer groups and it's hard to differientate which layers represent which.
I want to use the default markerCluster marker styles, but I want to assign a different background-color to each group.
Example:
Group 1
var trucksGroup = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
return L.divIcon({ /* assign color here?? */ });
}
});
var carsGroup = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
return L.divIcon({ /* assign color here?? */ });
}
});
The default marker CSS:
.marker-cluster-small {
background-color: rgba(181, 226, 140, 0.6);
}
.marker-cluster-small div {
background-color: rgba(110, 204, 57, 0.6);
}
.marker-cluster-medium {
background-color: rgba(241, 211, 87, 0.6);
}
.marker-cluster-medium div {
background-color: rgba(240, 194, 12, 0.6);
}
.marker-cluster-large {
background-color: rgba(253, 156, 115, 0.6);
}
.marker-cluster-large div {
background-color: rgba(241, 128, 23, 0.6);
}`
I haven't tried it this, but here's what I recommend attempting:
Instead of returning L.divIcon() from your function, get the default icon by calling _defaultIconCreateFunction() on your markerClusterGroup, e.g., trucksGroup._defaultIconCreateFunction(cluster).
Add a new class to that default icon to denote what group it's in. E.g., icon.options.className += ' trucks-group'.
Add new styles in your CSS for .truck-group.marker-cluster-small, .truck-group.marker-cluster-medium, etc.
Putting the first two steps together:
var trucksGroup = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
var icon = trucksGroup._defaultIconCreateFunction(cluster);
icon.options.className += ' trucks-group';
return icon;
}
});
var carsGroup = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
var icon = carsGroup._defaultIconCreateFunction(cluster);
icon.options.className += ' cars-group';
return icon;
}
});

How can I bring the tooltip to the top of chart

I now have a google chart like this bellow picture
Now I want to move the tooltip to the top of chart (dont care the position of my mouse).
How can I do it.
Here is my code :
var chartData = new google.visualization.DataTable();
chartData.addColumn('string', 'Time');
chartData.addColumn('number', 'Average Score');
chartData.addColumn({ 'type': 'string', 'role': 'tooltip', 'p': { 'html': true } });
chartData.addRows(data);
var options = {
chartArea: { left: 0, top: 100, width: "100%", height: "100%" },
title: '',
opacity: 100,
backgroundColor : {fill: '#000'},
hAxis: {
textPosition: 'none',
titleTextStyle: {color: '#333'},
titleTextStyle: {color: '#2902A3'},
},
vAxis: {
textPosition: 'none',
opacity: 100,
minValue: 0,
gridlines: { color: '#0D2B56', count: 10 },
baselineColor: 'white',
},
series:{
0:{
color: '#3C93FF',
areaOpacity: '0.68'
}
},
crosshair: {
orientation: 'vertical',
trigger: 'focus',
color: '#fff'
},
legend: 'none',
tooltip: {isHtml: true},
};
google.load("visualization", "1", { packages: ["corechart"] });
var chart = new google.visualization.AreaChart(document.getElementById('chart'));
chart.draw(chartData, options);
I also use this function to create tooltip's content
var createToolTip = function (name, value) {
return '<div class="googletooltip" ><span>' + name + ':</span><span style="padding-left:20px" >' + value + '</span></div>';
}
and this style also
.googletooltip{
color:#fff;
border-style: solid;
border-width: 2px;
border-color: #3882C4;
background: #000;
padding:2px 15px 2px 15px;
font-weight: bold;
}
Thank a lot
Try adding a top property and a position property for the .googletooltip class. If not, try using the margin property if the other properties are not working. Work around these three properties and see if you will be able to move tooltip up. Let me know if it still isn't working.
.googletooltip{
color:#fff;
border-style: solid;
border-width: 2px;
border-color: #3882C4;
background: #000;
padding:2px 15px 2px 15px;
font-weight: bold;
}
Where are you calling createToolTip function? Is it called while generating data chartData.addRows(data);?
Ref: check how createCustomHTMLContent function is used # https://developers.google.com/chart/interactive/docs/customizing_tooltip_content#custom_html_content

Input effect on keyboard tab -> focus, but NOT on click

When a user 'tabs over' to an input, I want the focus effect to be normally displayed, but on click, I don't want it to be visible.
User hits tab, now focussed on toggle button, I would like the toggle button to have slight glowing outline, which I'm currently able to do.
Now,
User clicks on the toggle button or it's associated label, toggle changes as usual,
BUT, I want the glow to never appear in the first place, or to disappear as quickly as possible.
I know about .blur(), and right now I'm having to use a setTimeout for a lazy fix, but I'd like to know if there's a better way to accomplish this, or if there's possibly a CSS only solution
I think a lot of front-end developers struggle to find a balance between aesthetics and the best-practices for accessibility. This seems like a great compromise.
Here's how I do it. The idea is to toggle outlining on when the user uses the tab key and turn it back off when they click.
JS
document.addEventListener('keydown', function(e) {
if (e.keyCode === 9) {
$('body').addClass('show-focus-outlines');
}
});
document.addEventListener('click', function(e) {
$('body').removeClass('show-focus-outlines');
});
Styles
body:not(.show-focus-outlines) button:focus,
body:not(.show-focus-outlines) [tabindex]:focus {
outline: none;
}
I'm currently doing something similar for my company. Unfortunately you must use JavaScript since CSS doesn't support this use case.
Here's what I've done.
var btns = document.querySelectorAll('button');
var onMouseDown = function (evt) {
evt.target.dataset.pressed = 'true';
};
var onMouseUp = function (evt) {
evt.target.dataset.pressed = 'false';
};
var onFocus = function (evt) {
var element = evt.target;
if (element.dataset.pressed !== 'true') {
element.classList.add('focus');
}
};
var onBlur = function (evt) {
evt.target.classList.remove('focus');
};
for(var i = 0, l = btns.length; i < l; i++) {
btns[i].addEventListener('mousedown', onMouseDown);
btns[i].addEventListener('mouseup', onMouseUp);
btns[i].addEventListener('focus', onFocus);
btns[i].addEventListener('blur', onBlur);
}
* { box-sizing: border-box; }
body { background-color: white; }
button {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
min-width: 100px;
margin: 0 1px;
padding: 12px 10px;
font-size: 15px;
color: white;
background-color: #646e7c;
border: none;
border-radius: 5px;
box-shadow: 0 2px 2px 0 rgba(0,0,0,.2);
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
button:focus { outline: none; }
button:active {
-webkit-transform: translateY(1px);
-moz-transform: translateY(1px);
transform: translateY(1px);
box-shadow: 0 0 2px 0 rgba(0, 0, 0, 0.2);
}
button.focus {
font-weight: bold;
}
button.primary { background-color: #2093d0; }
button.success { background-color: #71a842; }
button.danger { background-color: #ef4448; }
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<button>Default</button>
<button class="primary">Primary</button>
<button class="success">Success</button>
<button class="danger">Danger</button>
</body>
</html>
Basically instead of relying on browser's native focus I add/remove a focus class on my button depending on the situation.
If you use the what-input.js plugin you can apply styles specifically for keyboard users. You can use the following code to highlight a button that has been tabbed to. I've found what-input to be a reliable plugin (comes bundled with Zurb Foundation) and is currently regularly maintained.
// scss
body[data-whatinput="keyboard"] {
button {
&:focus {
// other highlight code here
box-shadow: 0 0 5px rgba(81, 203, 238, 1);
}
}
}
or
/* vanilla css */
body[data-whatinput="keyboard"] button:focus {
box-shadow: 0 0 5px rgba(81, 203, 238, 1);
}

Resources