How to change color / styles in tabs-component in Vaadin-application - vaadin

In my Vaadin application (Vaadin 23.2.0) I use tabs to group my content. The main colours of my application are white, grey and some accents in red. Accordingly, I would like to style my selected tabs in red.
I have already managed the following:
Unselected tabs are displayed in black.
Selected tabs are displayed in red.
Now Vaadin has a transition between clicking on the tab and the selection of the tab. By default, this transition is kept in Vaadin blue, which of course does not fit my theme. And I can't manage to style this transition. I would like to either style it dark red (to make the transition from dark red to my already used lighter red #DE323C) or omit it completely.
How does this work in Vaadin?
For styling the tabs I have used the following CSS snippets so far:
vaadin-tab[selected] {
colour: #DE323C;
}
vaadin-tab[selected]::before, vaadin-tab[selected]::after {
background-color: #DE323C;
}
I did some more tests with ::before and ::after, but Vaadin is very unimpressed.
Here is a simplified version of my Java code:
package ch.abacus.apihub.views.list;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Paragraph;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.tabs.Tab;
import com.vaadin.flow.component.tabs.Tabs;
import com.vaadin.flow.component.tabs.TabsVariant;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
#PageTitle("Test")
#Route(value = "test", layout = MainLayout.class)
public class TestView extends Div {
private final Tab tab1;
private final Tab tab2;
private final Tab tab3;
private final VerticalLayout content;
public TestView() {
// Create Tabs
tab1 = new Tab("This is tab 1");
tab2 = new Tab("This is tab 2");
tab3 = new Tab("This is tab 3");
// Event-Listener for clicking tabs
Tabs tabs = new Tabs(tab1, tab2, tab3);
tabs.addSelectedChangeListener(event ->
setContent(event.getSelectedTab())
);
// Tabs use available space
tabs.addThemeVariants(TabsVariant.LUMO_EQUAL_WIDTH_TABS);
// Create VerticalLayout for Tabs
content = new VerticalLayout();
content.setSpacing(false);
setContent(tabs.getSelectedTab());
// Add Tabs to created VerticalLayout
add(tabs, content);
}
private void setContent(Tab tab) {
content.removeAll();
if (tab.equals(tab1)) {
Paragraph tab1Paragraph = new Paragraph("Test tab 1");
content.add(tab1Paragraph);
} else if (tab.equals(tab2)) {
Paragraph tab2Paragraph = new Paragraph("Test tab 2");
content.add(tab2Paragraph);
} else if (tab.equals(tab3)) {
Paragraph tab3Paragraph = new Paragraph("Test tab 3");
content.add(tab3Paragraph);
}
}
}

You should create a file called vaadin-tab.css in frontend/themes//components
Inside that you can style all styles of a component
For example:
:host {
color: var(--lumo-primary-text-color);
font-weight: 400;
}
:host([selected]) {
color: black;
background-color: var(--tosca-selection-nonfocus);
transition: 0.6s color;
}
:host([selected].focused) {
color: black;
background-color: #8fc8d5;
transition: 0.6s color;
}
:host([selected])::before, :host([selected])::after {
display: none;
}
Learn more about styling components:
https://vaadin.com/docs/latest/styling/custom-theme/styling-components

Thank you very much for your answers.
The typo only crept in on Stackoverflow. It is not present in my CSS.
I placed the CSS code in the styles.css file.
I have now created a separate style sheet for the tabs. It probably wouldn't have been necessary, but I find it quite good that all the style things for the tabs can then be found in one place.
I was able to solve the problem by copying the default styles of the tabs from the #shadow-root of the tabs and overwriting them. My vaadin-tab.css now looks like this:
:host { /* Styling tab not focused etc. */
box-sizing: border-box;
padding: 0.5rem 0.75rem;
font-size : 16px;
line-height: 1;
font-weight: 500;
opacity: 1;
color: #282828;
transition: 0.15s color, 0.2s transform;
flex-shrink: 0;
display: flex;
align-items: center;
position: relative;
transform-origin: 50% 100%;
outline: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
overflow: hidden;
min-width: var(--lumo-size-m);
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
text-transform : UPPERCASE;
letter-spacing : 1px;
}
:host(:hover), :host([focus-ring]) { /* Styling tab hovered */
color: #B11D24; /* darker red */
}
:host([selected]) { /* Styling tab selected */
color: #DE323C;
transition: 0.6s color;
}
:host([active]:not([selected])) { /* relevant for transition */
color: #DE323C;
transition-duration: 0.1s;
}
:host::before, :host::after { /* Styling color line below text of tab */
content: '';
position: absolute;
display: var(--_lumo-tab-marker-display, block);
bottom: 0;
left: 50%;
width: var(--lumo-size-s);
height: 2px;
background-color: #282828;
border-radius: var(--lumo-border-radius-s) var(--lumo-border-radius-s) 0 0;
transform: translateX(-50%) scale(0);
transform-origin: 50% 100%;
transition: 0.14s transform cubic-bezier(0.12, 0.32, 0.54, 1);
will-change: transform;
}
:host([selected])::before, :host([selected])::after { /* Styling color line below text of tab selected */
background-color: #DE323C;
}
Probably some CSS configurations could be removed, but I am quite satisfied: When hovering over it, the tabs are displayed in dark red and when clicking on a tab, the transition to my lighter red takes place. The Vaadin blue has now completely disappeared.

Related

Styling ion-refresher

I am trying to style the ion-refresher component background on one specific page, because it has a header. It works like expected in Safari, but on the device, it overlays everything on top.
I have tried some stuff with z-index (also with pseudo element) + positioning absolute, but I cannot get the ion-refresher to sit where it normally is. As soon as I add a background-color to the ion-refresher, it will overlay on top.
Any ideas on how to style the background of this element?
The CSS I used. Please note it only overlays everything when I add a background-color.
ion-refresher:global(.ios) {
height: 120px;
ion-refresher-content {
position: relative;
padding-top: 18px;
justify-content: start !important;
&::after {
content: '';
display: block;
width: 100%;
height: 120px;
position: absolute;
top: 0;
z-index: -9999;
background-color: purple;
}
}
:global(.refresher-pulling-icon) {
color: white;
}
ion-spinner {
color: white;
}
}
Any advice on how to debug this?

How to style arrow in antd tooltip like this

I have tooltip component created with antd library.
I would like to change arrow style to something like that.
import { Button, Tooltip } from 'antd';
import styled from 'styled-components';
export const TooltipOK = () => (
<>
<Tooltip placement='topLeft' title="Cool Tooltip" color='purple' getPopupContainer={(triggerNode) => triggerNode}>
<Button>Cool Text</Button>
</Tooltip>
</ >
);
export default TooltipOK;
const StyledTooltip = styled.div`
.ant-tooltip-arrow { // arrow wrapper
right: 0;
left: initial;
}
.ant-tooltip-arrow-content { // arrow itself
background: white;
}
.ant-tooltip-inner { // tooltip
background-color: white;
box-shadow: none;
border: 1px solid #D04A02;
color: black;
}
`

I have a dropdown menu and want to show a partial depending on the answer in Rails

I have a menu and I want to link to an apartment booking menu depending on the option chosen. There are three cities and when one city is selected I want to render the partial that contains the booking form.
The dropdown works, but I can't get it to show the correct partial based on selection. The partial contains different booking forms that are widgets coming from an external website. Once the partial is linked properly I can use ajax to make sure the page doesn't refresh when the partial is being loaded.
I'm very new to Rails and can't get this done. Am I on the right track here? Any help would be greatly appreciated!
<select name="locations">
<option value="basingstoke">Basingstoke</option>
<option value="cardiff">Cardiff</option>
<option value="sheffield">Sheffield</option>
<% if option_value_selected?(basingstoke, selected) %>
<%= render 'components/book_basingstoke' %>
<% elsif option_value_selected?(cardiff, selected) %>
<%= render 'components/book_cardiff' %>
<% else option_value_selected?(sheffield, selected) %>
<%= render 'components/book_sheffield' %>
<% end %>
</select>
Ruby on Rails is not a reactive view library like react.js. option_value_selected is evaluated at rendering time from server side. (Is not something you are looking for)
I would recommend you look this link jquery example.
Basically you need to render all three views at server side and hide them using js.
$(function() {
$('#colorselector').change(function() {
$('.colors').hide();
$('#' + $(this).val()).show();
});
});
// [forked from](http://jsfiddle.net/FvMYz/)
// [show-hide-based-on-select-option-jquery)(http://stackoverflow.com/questions/2975521/show-hide-div-based-on-select-option-jquery/2975565#2975565)
/* https://gist.github.com/toddparker/32fc9647ecc56ef2b38a */
/* Some basic page styles */
body {
font: 100%/1.5 AvenirNext-Regular, Corbel, "Lucida Grande", "Trebuchet Ms", sans-serif;
color: #111;
background-color: #fff;
margin: 2em 10%
}
/* Label styles: style as needed */
label {
display: block;
margin: 2em 1em .25em .75em;
font-size: 1.25em;
color: #333;
}
/* Container used for styling the custom select, the buttom class adds the bg gradient, corners, etc. */
.dropdown {
position: relative;
display: block;
margin-top: 0.5em;
padding: 0;
}
/* This is the native select, we're making everything the text invisible so we can see the button styles in the wrapper */
.dropdown select {
width: 100%;
margin: 0;
background: none;
border: 1px solid transparent;
outline: none;
/* Prefixed box-sizing rules necessary for older browsers */
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
/* Remove select styling */
appearance: none;
-webkit-appearance: none;
/* Magic font size number to prevent iOS text zoom */
font-size: 1.25em;
/* General select styles: change as needed */
/* font-weight: bold; */
color: #444;
padding: .6em 1.9em .5em .8em;
line-height: 1.3;
}
.dropdown select,
label {
font-family: AvenirNextCondensed-DemiBold, Corbel, "Lucida Grande", "Trebuchet Ms", sans-serif;
}
/* Custom arrow sits on top of the select - could be an image, SVG, icon font, etc. or the arrow could just baked into the bg image on the select */
.dropdown::after {
content: "";
position: absolute;
width: 9px;
height: 8px;
top: 50%;
right: 1em;
margin-top: -4px;
z-index: 2;
background: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 12'%3E%3Cpolygon fill='rgb(102,102,102)' points='8,12 0,0 16,0'/%3E%3C/svg%3E") 0 0 no-repeat;
/* These hacks make the select behind the arrow clickable in some browsers */
pointer-events: none;
}
/* This hides native dropdown button arrow in IE 10/11+ so it will have the custom appearance, IE 9 and earlier get a native select */
#media screen and (-ms-high-contrast: active),
(-ms-high-contrast: none) {
.dropdown select::-ms-expand {
display: none;
}
/* Removes the odd blue bg color behind the text in IE 10/11 and sets the text to match the focus style text */
select:focus::-ms-value {
background: transparent;
color: #222;
}
}
/* Firefox >= 2 -- Older versions of FF (v2 - 6) won't let us hide the native select arrow, so we'll just hide the custom icon and go with native styling */
/* Show only the native arrow */
body:last-child .dropdown::after,
x:-moz-any-link {
display: none;
}
/* reduce padding */
body:last-child .dropdown select,
x:-moz-any-link {
padding-right: .8em;
}
/* Firefox 7+ -- Will let us hide the arrow, but inconsistently (see FF 30 comment below). We've found the simplest way to hide the native styling in FF is to make the select bigger than its container. */
/* The specific FF selector used below successfully overrides the previous rule that turns off the custom icon; other FF hacky selectors we tried, like `*>.dropdown::after`, did not undo the previous rule */
/* Set overflow:hidden on the wrapper to clip the native select's arrow, this clips hte outline too so focus styles are less than ideal in FF */
_::-moz-progress-bar,
body:last-child .dropdown {
overflow: hidden;
}
/* Show only the custom icon */
_::-moz-progress-bar,
body:last-child .dropdown:after {
display: block;
}
_::-moz-progress-bar,
body:last-child .dropdown select {
/* increase padding to make room for menu icon */
padding-right: 1.9em;
/* `window` appearance with these text-indent and text-overflow values will hide the arrow FF up to v30 */
-moz-appearance: window;
text-indent: 0.01px;
text-overflow: "";
/* for FF 30+ on Windows 8, we need to make the select a bit longer to hide the native arrow */
width: 110%;
}
/* At first we tried the following rule to hide the native select arrow in Firefox 30+ in Windows 8, but we'd rather simplify the CSS and widen the select for all versions of FF since this is a recurring issue in that browser */
/* #supports (-moz-appearance:meterbar) and (background-blend-mode:difference,normal) {
.dropdown select { width:110%; }
} */
/* Firefox 7+ focus style - This works around the issue that -moz-appearance: window kills the normal select focus. Using semi-opaque because outline doesn't handle rounded corners */
_::-moz-progress-bar,
body:last-child .dropdown select:focus {
outline: 2px solid rgba(180, 222, 250, .7);
}
/* Opera - Pre-Blink nix the custom arrow, go with a native select button */
x:-o-prefocus,
.dropdown::after {
display: none;
}
/* Hover style */
.dropdown:hover {
border: 1px solid #888;
}
/* Focus style */
select:focus {
outline: none;
box-shadow: 0 0 1px 3px rgba(180, 222, 250, 1);
background-color: transparent;
color: #222;
border: 1px solid #aaa;
}
/* Firefox focus has odd artifacts around the text, this kills that */
select:-moz-focusring {
color: transparent;
text-shadow: 0 0 0 #000;
}
option {
font-weight: normal;
}
/* These are just demo button-y styles, style as you like */
.button {
border: 1px solid #bbb;
border-radius: .3em;
box-shadow: 0 1px 0 1px rgba(0, 0, 0, .04);
background: #f3f3f3;
/* Old browsers */
background: -moz-linear-gradient(top, #ffffff 0%, #e5e5e5 100%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ffffff), color-stop(100%, #e5e5e5));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffffff 0%, #e5e5e5 100%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffffff 0%, #e5e5e5 100%);
/* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffffff 0%, #e5e5e5 100%);
/* IE10+ */
background: linear-gradient(to bottom, #ffffff 0%, #e5e5e5 100%);
/* W3C */
}
.output {
margin: 0 auto;
padding: 1em;
}
.colors {
padding: 2em;
color: #fff;
display: none;
}
.red {
background: #c04;
}
.yellow {
color: #000;
background: #f5e000;
}
.blue {
background: #079;
}
footer {
margin: 5em auto 3em;
padding: 2em 2.5%;
text-align: center;
}
a {
color: #c04;
text-decoration: none;
}
a:hover {
color: #903;
text-decoration: underline;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label class="wrapper" for="states">This label is stacked above the select</label>
<div class="button dropdown">
<select id="colorselector">
<option value="red">Red</option>
<option value="yellow">Yellow</option>
<option value="blue">Blue</option>
</select>
</div>
<div class="output">
<div id="red" class="colors red"> “Good artists copy, great artists steal” Pablo Picasso</div>
<div id="yellow" class="colors yellow"> “Art is the lie that enables us to realize the truth” Pablo Picasso</div>
<div id="blue" class="colors blue"> “If I don't have red, I use blue” Pablo Picasso</div>
</div>

How to make jqgrid top toolbar custom buttons bigger like standard buttons

Style based on question jqGrid - How can I make the paging buttons bigger? is used to make jqgrid top level toolbar buttons bigger:
.ui-jqgrid .ui-jqgrid-toppager { height:35px !important; }
.ui-jqgrid .ui-pg-button { height:30px !important; width:30px !important;}
.ui-jqgrid .ui-jqgrid-toppager .ui-icon { position:relative; margin: 0px 10px;}
.ui-jqgrid .ui-jqgrid-toppager .ui-pg-div span.ui-icon {
margin: 0 10px !important;
}
/* some settings to place Button in jqGrid */
.ui-jqgrid .ui-pg-table .my-nav-checkbox
{
margin: 0px;
padding: 0px;
float: left;
height: 18px;
}
.ui-jqgrid .ui-pg-table .my-nav-checkbox > input
{
padding: 1px;
}
.ui-jqgrid .ui-pg-table .my-nav-checkbox > label
{
margin: 0px;
border-width: 0px;
}
.ui-jqgrid .ui-pg-table .my-nav-checkbox:hover > label
{
margin: 0px;
border-width: 1px;
}
/* fixing CSS of jQuery UI Buttons */
.ui-jqgrid .ui-pg-table .my-nav-checkbox > .ui-button > span.ui-button-text
{
margin: 0px;
padding: 1px 2px 1px 16px;
}
.ui-button-icon-only
{
width: 16px;
}
.ui-jqgrid .ui-pg-table .my-nav-checkbox > .ui-button > span.ui-button-icon-primary
{
margin: -8px 0px 0px -8px;
}
jqgrid toolbar contains also custom checkable buttons based on Oleg answer defined like:
var autoedit = false;
$("#grid_toppager_left table.navtable tbody tr").append(
'<td class="ui-pg-button ui-corner-all">' +
'<div class="ui-pg-div my-nav-checkbox">' +
'<input tabindex="-1" type="checkbox" id="AutoEdit" ' + (autoedit ? 'checked ' : '')+'/>' +
'<label title="Press to toggle"' +
' for="AutoEdit">Press to toggle</label></div></td>'
);
$("#AutoEdit").button({
text: false,
icons: {primary: "ui-icon-star"}
}).click(function () {
autoedit = !autoedit;
});
this custom button (star icon) in toolbar appears in wrong position: too right and together with next button:
Also width is smaller than standard button and top alignment is too big:
How to make custom button like standard button ?
If you need to use toolbar icons which are larger as standard I would recommend you to use Font Awesome icons in the navigator toolbar instead of standard jQuery UI icons. I described in the answer.
For example if I set just the following CSS in the old demo
.ui-jqgrid .ui-jqgrid-toppager { height:30px !important;}
.ui-jqgrid .ui-jqgrid-toppager .ui-pg-div>span { margin: 0 5px; font-size: 20px; }
I can use 20px icons in the top toolbar. The demo will shows the following results
Because all icons from Font Awesome are implemented just as vector fonts one get perfect results for any font size (icon size). One need of cause to post all other custom solution (like checkable buttons) to Font Awesome, but after some investments you could get very good final results.

jQuery combobox Styling issue

I am rendering a jQuery combobox, but the height of input element does not match the height of toggle button as shown in screen shot below. This is happening in both, IE 9 and FireFox 13.
The style being used for jQuery combobox is as below.
<style>
.ui-combobox {
position: relative;
display: inline-block;
}
.ui-combobox-toggle {
position: absolute;
top: 0;
bottom: 0;
margin-left: -1px;
padding: 0;
/* adjust styles for IE 6/7 */
*height: 1.7em;
*top: 0.1em;
}
.ui-combobox-input {
margin: 0;
padding: 0.3em;
}
.ui-autocomplete { height: 200px; overflow-y: auto; }
</style>
You should update your combo-box widget from the jqueryui page. and make sure that you use the latest jquery-ui (this issue was fixed recently).
this helped me...

Resources