How to check a prop to output a block of code on a styled object in Emotion - emotion-js

What is the best practice to output a block of code on a styled object in Emotion?
A simple boolean statement looks like this:
const StyledComponent = styled('div')(({ check }) => ({
position: check ? 'relative' : undefined
})
But what is the best solution for a block of code like the following example if I don't want to check each line of code?
const StyledComponent = styled('div')(({ check }) => ({
// some style here
// ...
// only load pseud element if "check" is true
'&::before': {
content: `''`,
position: 'absolute',
left: '0%',
top: '0%',
width: '100%',
height: '100%',
background: 'blue'
}
}))
I have some solutions in mind.
Add the if statement on the content: as without content the rest won't show. It is not my favourite because the rest of the code still getting loaded.
Add the if statement to load a new div inside this component. This way I can target this specific div instead of using the pseudo-class before.

I gave it some thought and got to this solution:
const StyledComponent = styled('div')(
{
// some style here
position: 'relative'
},
({ check }) =>
// only load pseudo element if "check" is true
check
? {
'&::before': {
content: `''`,
position: 'absolute',
left: '0%',
top: '0%',
width: '100%',
height: '100%'
}
}
: undefined
)

Related

Referencing another Rule in Material UI

I have the following code where I need to reference another rule name to avoid style duplication in material ui. Unfortunately the rules aren't reflecting.
const useNavStyles = makeStyles((theme) => ({
active: {
color: 'green'
},
listItem: {
borderTopRightRadius: 100,
borderBottomRightRadius: 100,
paddingBottom: 12,
paddingTop: 12,
backgroundColor: theme.palette.background.paper,
},
subListItem: {
"&$listItem": { // I wish to copy over the properties from the above listItem rule and only add padding to it, but it isn't working.
paddingLeft: theme.spacing(4),
},
},
How do I resolve this?
Thanks
Referencing a local rule name does not "copy over" other styles. It changes your selector. You will still need to apply all those classes to your elements, which in return will then also apply the respective styles.
listItem: {
color: 'hotpink',
},
subListItem: {
"&$listItem": {
fontWeight: 'bold'
}
}
this compiles to
.listItem-1: {
color: hotpink;
}
.subListItem-0.listItem-1: {
font-weight: bold;
}
In other words, this will apply styles to an element that has both these classes:
<div className={clsx(classes.listItem, classes.subListItem)}>
hotpink and bold
</div>
<div className={classes.subListItem}>no styles at all</div>

Merged headers in ag-grid

Is the following format possible with ag-grid:
Merged header with blank name
Merged header with name in 2 lines ("Original Values")
Parent header centered ("Header with children")
Thank you, for the question I know it is been too late for the answer but just to help another people know it.
Yes, it is possible with an updated version of ag-grid, please check it out.
`var columnDefs = [ {
headerName: 'Athlete Details',
children: [
{
headerName: 'Athlete',
field: 'athlete',
width: 150,
suppressSizeToFit: true,
enableRowGroup: true,
rowGroupIndex: 0,
},
{
headerName: 'Age',
field: 'age',
width: 90,
minwidth: 75,
maxWidth: 100,
enableRowGroup: true,
}
]
}];
`
https://plnkr.co/edit/?p=preview&preview
I'm struggling with this for quite a while, but i can not find a good solution. Anyway i figured out a solution (at least for my self).
In my case, the headers are dynamic. Only some headers have children.
Here is the solution:
Figure out how many rowspan should a header have
Apply class to header
In your columnDefs, use 'headerClass'
const rowSpanClass = ..... // This is calculated base on the data you have or set it static
columnDefs = {
....
....
headerClass: rowSpanClass, // In my case, if it is 2 rowspan, i call it 'header-row-span-2'
......
}
Apply style on the custom header class
.header-row-span-2 {
position: fixed;
top: 50px;
height: 100px;
}
.header-row-span-3 {
position: fixed;
top: 100px;
height: 150px;
}
The value of 'top' and 'height' need to be changed accordingly (ag-grid header height is 50px by default)
Just to share. I think this is not possible using the headers in ag-grid. So, instead, I set the headerheight to 0 and use the row cells to achieve the header format.

Position Highcharts label to right side

I have a basic chart with a custom label, eg:
labels: {
items: [{
html: 'Testing Label',
style: {
left: '50px',
top: '50px'
}
}]
}
This works, but I'd like to position the label from the right side, I tried doing:
style: {
right: '50px',
top: '50px'
}
but this doesn't work...
JsFiddle link:
http://jsfiddle.net/0ze2u47h/3/
It seems that right property is not supported in chart.labels. For more complex configuration you can render the label using SVGRenderer:
chart: {
events: {
load: function() {
var chart = this,
renderer = chart.renderer;
var label = this.renderer.label('Test label', null, 100).add();
label.attr({
x: chart.plotWidth + chart.plotLeft - label.width
});
}
}
}
Live demo: http://jsfiddle.net/kkulig/aob1e197/
The advantage of rendering labels via renderer (not via constructor options) is that you can access parameters of the already created chart and label (chart.plotWidth, chart.plotLeft, label.width in this case).
API reference: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#label

ExtJS - How to highlight form itself

I want to highlight ExtJS Form Panel itself after a specific event. I have been trying the code added below but it just highlights the container panel which is hardly seen.
Code Snippet
myForm.getEl().highlight("ffff9c", {
attr: "backgroundColor",
endColor: "ffc333",
easing: 'easeIn',
duration: 1000
});
Sencha Fiddle Link: https://fiddle.sencha.com/#fiddle/fij
Your code is working correct. You are selecting the container element by using getEl() method on your formpanel. The textarea is covering your panel, so you see the easing effect at the bottom. If you want to highlight your fields, you have to iterate through the form fields by using the each method:
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.create('Ext.form.Panel', {
title: 'My Form',
id: 'myform',
renderTo: Ext.getBody(),
width: 500,
height: 250,
items: [{
xtype: 'textarea',
width: '100%',
hideLabel: true,
value: 'Some text'
},
{
xtype: 'textfield',
width: '100%',
hideLabel: true,
value: 'Some other text'
}],
buttons: [{
text: 'Highlight',
handler: function() {
Ext.getCmp('myform').getForm().getFields().each(function(field) {
field.inputEl.highlight("ffff9c", {
attr: "backgroundColor",
endColor: "ffc333",
easing: 'easeIn',
duration: 1000
});
});
}
}]
});
}
});
In this working example, you are changing the background color. The standard css class contains a background image for input fields, so you have to remove it temporarily during the effect. This can be made with a custom css class to override the background-image property.
Hope it helps
....or even Better just get the form's Targeted EL.
App.myFormPanel.getTargetEl().highlight();
You won't have to manually iterate through each elements within the form.

Can't assign a class to an infoBox in Google Maps v3

Is anyone else having problems with InfoBox?
Is there a better way to create infoBoxes and assign them classes? I can't set a class!
var myOptions = {
content: boxText,
disableAutoPan: false,
boxClass: "CLASS", <----
pixelOffset: new google.maps.Size(-140, 0),
zIndex: null,
boxStyle: {
background: "url('tipbox.gif') no-repeat",
opacity: 0.75,
width: "280px"
},
closeBoxMargin: "10px 2px 2px 2px",
closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
Seems to work for me:
JsFiddle Example
Element Attributes: