Appcelerator hierarchical selector for TSS - appcelerator

How can we set style using hierarchical selector in TSS?
For example in index.xml file I have
<TableView id="myTable">
<TableViewRow>
<Label text="Row"></Label>
</TableViewRow>
</TableView>
For this I want to set Set style to Label inside #myTable
Like in CSS we can do it
#myTable Label{
//style
}
But this is not working in TSS.
So does anyone know how can we set style using an hierarchical selector?

TSS isn't CSS, though both are designed to allow setting visual properties. I am almost positive there is no way to hierarchically set a TSS rule. You must apply to the object directly or to the object as a class. So, you could create a class called 'tablelabel' and set it's properties, then apply the class to the label object in the table... But it's a direct assignment not a hierarchical one.

Related

Multiple jss in components when using react-planet which override other components' styles

I added the <Planet/> (from react-planet) to my App and the placement of some <Grid/> (from the Material UI) components changed.
While looking inside "Elements" in DevTool I noticed that divs inside the <Planet/> component have two classes jss3 and jss{i} where i is the next integral number. Each has different properties inside which overwrites every component in App that is using one of the jss{i} classes.
I also noticed that at first render i iteration, which applies to jss{i} used in newly created divs, starts from 1 and ends at 9 - because I have 6 planets so 1 for the main div, 2 for the central planet, 3 for divs' first class, and 4-9 for the six divs' second class. After the second render number goes from 10 to 18.
Screenshots of Elements at first render and second.
The class ={jss3 jss4} example
The class ={jss3 jss5} example
I assume that after creating planets by <Planet/>, whose children have two classes, the newly created class jss{i}, based on makeStyles-root-{i}, is overwriting properties of jss{i}, which is used somewhere else on page by <Grid/> components thus changing placement for the whole page.
Code where <Planet/> component is used:
return (
<Grid
item
container
justifyContent = "center"
style = {{ margin: 30 }}
>
<Planet
centerContent={
<Fab size="small" color="primary" aria-label="add" onClick={handleOpen}>
<AddIcon />
</Fab>
}
open={isOpen}
autoClose
orbitRadius= {50}
rotation = {90}
hideOrbit
friction = {20}
>
<div/>
<div/>
<div/>
<Fab size="small" color="primary" aria-label="addBarIcon" onClick={handleChartAddLineChart}>
<ShowChartIcon />
</Fab>
<Fab size="small" color="primary" aria-label="addBarIcon" onClick={handleChartAddBarChart}>
<BarChartIcon />
</Fab>
<Fab size="small" color="primary" aria-label="addBarIcon" onClick={handleChartAddPieChart}>
<PieChartIcon />
</Fab>
</Planet>
</Grid>
);
I tried putting only <div/> components inside <Planet/> but nothing changed. Changing from <Grid/> to normal <div/>, also didn't change anything.
Also, I tried to find a similar problem on StackOverflow or somewhere else but I am not sure how to describe the problem using proper keywords.
I am not sure if it is some bug in the react-planet library that makes react-planet and material-ui impossible to use together or if there is a problem inside my code.
I am not sure what was exactly the cause of the "multiply class in one component" bug, but I copied Planet.tsx and Orbit.tsx from the react-planet repository and changed some code, get rid of makeStyles and problem solved. It was probably of nested makeStyles in all of those components in react-planet which conflicted with each other at different component rendering levels causing it to render multiple times in one object.
Additionally, it was overriding Material UI components styles due to simplified class naming from MUI makeStyle to css class while building production (makeStyles-root-{i} -> jss{i}, makeStyles -> jss).
Overriding styles were probably caused by the react-planets dependency of the old/different MUI version than I have for the rest of the code which created two styles generators for each of those versions as mentioned in MUI FAQ. The first generator created class from makeStyle for all of my page naming every class jss{i++} for i starting at i=1 and ending when all classes are renamed, then the react-planet generator created styles for its objects naming every class jss{i++} starting from i=1 leading to overriding every previous class=jss{i} with new properties.

How to override strapis "primary button"

I'm a graphic designer who has to customize a project done with strapi - and I am sooo lost. I managed to change backgroundcolors, backgroundimages so far - no problem. BUT: I am totally unable to customize the elements like the primary buttons.
I found lots of class definitions ".primary", changed them - without a result ... in the end I removed them all ... but the primary buttons stills look the same. How? Why?
The only why to get rid of the visual appearance of the primary button, was by removing (e.g. of the login page -> within the index.js under admin/src/containers/AuthPage) "primary" of the buttons declaration.
<Button primary label="users-permissions.Auth.form.button.login" type="submit" />
But that's not what I wanted. I want to customize e.g. the primary buttons. Not getting rid of it.
I searched stackoverflow for strapi customization or ui issues but couldn't find a solution. I found a lot of strategies of overriding bootstrap CSS, e.g.:
How can I override Bootstrap CSS styles?
But strapis SCSS seems to something different I obviously don't understand yet.
If anyone has an idea or did already overrides to e.g. primary button - please let me know.
Thanks in advance, Stef.
You have two ways to override the default style of a button
You can pass a style prop to the component
<Button label="Label" type="button" style={{ background: 'red' }} />
You can pass a custom className prop:
In order to do so, you need to add the class in your 'plugins/users-permissions/admin/src/containers/Auth/styles.scss` file (where the component is going to be used)
.customButton {
background: red;
}
Then in your index.js file
import Button from 'components/Button';
import styles from './styles.scss';
render() {
return (
<Button label="label" className={styles.customButton} />
);
}

Titanium if attribute and Alloy.Globals not working

According to the documentation it is possible to:
In the XML markup, add the if attribute to an element and assign it to the property passed to the createController() method. Prefix the property name with the $.args namespace. Based on the property passed to the method, the application displays a different label.
So this means that if I put:
<Label if="Alloy.Globals.property" color="blue">Foobar</Label
Wont work?? Right now I´m not using the createController method, because it is added on the XML by a Require tag. Is there any way to do this?
As you can see in the docs there are some examples.
One of which:
<Alloy>
<Window>
<Label if="$.args.fooBar" color="blue">Foobar</Label>
<Label if="$.args.fooBaz" color="red">Foobaz</Label>
</Window>
</Alloy>
So yes, this will just work. As long as the property you provide is already set when rendering. Once your variable changes while the view is open it won't update it. For that you'll need data binding

Set textfield to numeric only Nativescript

I trying to do textfield accept numeric only and text align to center, but it no take any effect, Isn't I set wrong properties or another way to set?
<TextField id="btn" android:inputType="number" android:numeric="number" android:textAlignment="center" col="1" backgroundColor="#ffffff" col="2"/>
First. You want to set the keyboardType to number. See the documentation on EditableTextBase
Second, about styling. You really want to set the styling within a CSS file as it helps you separate markup and style. Take a look at the documentation about styling.
But if you want you can use inline styles. However what you've done is that you've tried to pass styling as xml parameters. What you want to do is that you want to pass the styling to the style param like this:
<TextField style="text-align: center;"/>
compare that to what you did:
<TextField textAlignment="center"/>
But as said. You're gonna be a happier developer if you write your style in a separate CSS file, like:
<TextField cssClass="myClass">
and then in your CSS file:
.myClass {
text-align: left;
}
On your submit event you could add in some validation to ensure that the input is a number. You can check this using console.log(typeof var) where var is the value of the text field, it should return integer.
You're best off setting the text-alignment within your CSS file.

JavaFX Scene Builder 2.0 how to add an Image to a Label

I am using JavaFX Scene Builder 2.0 and I would like to add an image to a label using FXML.
In oracle docs, we can find how to achieve this using Java code, but I would like to achieve this using Scene Builder
There are two ways to achieve this
Using FXML
Using CSS
FXML
<Label text="My Image">
<graphic>
<ImageView fitWidth="150" preserveRatio="true" smooth="true">
<image>
<Image url="myImage.png"/>
</image>
</ImageView>
</graphic>
</Label>
Inside Scene Builder, drag an ImageView on top of a Label and it will automatically be set as a graphic for the label. Then select the ImageView and type the url of the image into the ImageView's image field in the Scene Builder properties pane.
CSS
Assign an id to the Label in your FXML. You will also find an id as the property of the Label in Scene Builder
<Label text= "My Image" id = "labelwithimage"/>
Now you can either assign the css values directly in fxml(makes things clumsy) or create a new css file and define your attributes in it
Direct Assignment
<Label text= "My Image" id = "labelwithimage" style="-fx-graphic:url('myImage.png'); -fx-graphic-text-gap : 10;"/>
For defining it in a css file, you need to create a css file, define the atrributes against the id assigned to the Label and include it in the FXML
mycss.css
#labelwithimage {
-fx-graphic: url("myImage.png");
-fx-graphic-text-gap : 10;
}
As you might have already guessed, -fx-graphic does everything that we wrote inside <graphic></graphic>, there are few other attributes like -fx-graphic-text-gap. You can find all the tags that can be used on Label in the css reference guide for label
Now the last thing in css is loading the css in the fxml. For this you need to include the following tag inside you fxml
<stylesheets>
<URL value="#mycss.css" />
</stylesheets>
Just make sure to have the proper imports in the FXML
It is also possible to do it directly in the Scene Builder, without touching the FXML or CSS manually.
Just drag and drop an ImageView node onto your label. You can then set the path to the image on the added ImageView node.
Alternatively, you may just drag an image file from your file explorer (or equivalent) to the label in Scene Builder. Scene Builder will add the intermediate ImageView node automatically. You may then adjust the path to your needs (document-relative, classpath-relative, etc.).
Actually the method is the same as in Java code and the direct modifications of the FXML: just set an ImageView as being the 'graphic' node of the label.
This also works the same for buttons.

Resources