flex-like states in CSS/grabbing multiple id-ed elements at once - css

Suppose I have a ui with a button. The ui has four states, each with the button in a different corner.
In Flex, this is easy to achieve, you simply define these four states (topLeft, topRight, bottomRight, bottomLeft), and each has an override for the button's position values.
How would you do this using CSS in a way that can be triggered by a simple assignment?
Flex: skin.currentState="topRight"
JS: ???
I've defined the classes in css:
#button.topRight {...}
#button.topLeft{...}
#button.bottomRight {...}
#button.bottomLeft {...}
Now, without having to know of the existence of #button, how in one line of code can I apply one of the four states to all the elements on the page that have that state defined?

jQuery provides a handy abstraction layer in JavaScript to so this:
$('.someClassName').addClass('blueOnLeft')
$('.someClassName').removeClass('blueOnLeft')
This will target every element with a class name of "someClassName".

Related

Class inherit other css styling - ng-deep problem

I have a problem, a button that belongs to an InfoWindow component. The button isn't created in the HTML part of the code but is called whenever the card component is open. I use this InfoCard in two places of the application, and in each component, I change the position of the button using ::ng-deep, because without it the changes won't be applied. The problem is whenever I change from one page to another, the component child1 inherits the child2 CSS of the button, and the same way when I check child1 first. I thought about adding a class to each button and changing in the CSS the call of classes .class1.button and .class2.button, but the problem is the button isn't displayed until I click in the showInfo button to display the card, so in typescript the class is displayed none, and I can't add a class to a class with display none.
Any help on how I can solve that?
The problem is rather difficult to understand for me given your description. However, you might take a look at the following docs. E.g. :host-context can be used to differentiate style application based on the context, e.g. the presence of some class in some ancestor component - assuming you apply some StyleEncapsulation.

angular showing/hiding DOM elements based on what class they have

I'm going to simplify my problem a bit, because I really want to avoid adding a lot of code, because this is a gigantic project we are working on if I started adding code snippets, there would be a lot of it.
My project has one feature, where you have a list of different div elements in the left column of the page, and they can be individually dragged to the right column, where you can make your own list out of these elements in the order you choose.
These div elements are all the same child component. My task is to add a dropdown to these div elements, but only to the ones that have been dragged to the right column (you can choose additional preferences, once it's in the right column). It shouldn't be there on the divs in the left column.
The only way to differentiate between them is by the class name. The ones on the left have a class="left" and the ones on the right get the class="right".
Now I'm wondering if there's a way where I can write some code to the effect: if the element has the class 'left', hide the dropdown, else show the dropdown?
Yes, this is definitely possible.
Create a Directive that has a #HostBinding() for a specific class and just add the directive to every component.
Inject ChildComponent into the constructor of that Directive. You can also inject ViewContainerRef and then call this.viewContainerRef["_data"].componentView.component This will give you reference to that child element that the directive is put on.
Once the #HostBinding('.left') event handler is triggered this will be the function that gets called when the class you're looking for is added. Here you can then access that ChildComponent and then presumably call a method on that child component to show/hide the mat-select
I haven't actually tested this but thats the approach I would take.
You might also achieve this thru your css. Something like
div[class*="left"] dropdown-element {
display: none;
~or~
visibility: hidden;
}

Radio inputs in two separate shadow doms not respecting name attribute

I am using a MDC Radio Element so I thought I would wrap it up in a nice little <mdc-radio name="the-name" value="the-value"></mdc-radio>.
Everything was going well, but then I realized when I use it multiple times w/ the same name attribute...
<mdc-radio name="the-name" value="the-value-1"></mdc-radio>
<mdc-radio name="the-name" value="the-value-2"></mdc-radio>
.. it does not toggle the other selected mdc-radio with the same name. I assume it is because the radios are in two separate shadow dom containers. Is this correct? is there a way around this behavior?
dang... that was a dumb question. I assumed using Shadow DOM was required for Custom Elements, but it isn't. Just appending the MDC Radio markup to this inside of the constructor for a HTMLElement did the trick

Add another element type to definition using Sass§

Is it possible to add another element to a definition something like
input {
&:not[type="submit"], &,textarea {
// styles that apply to inputs that are not submit buttons, and text areas
}
// other styles here that I don't want to apply to textareas
// do want to apply to inputs
}
I've had a look through the sass documentation but can't see anything, if anyone can suggest a way to do this that would be awesome.
Thanks
No, this is not possible. Keep in mind that nesting is a feature, not a requirement. Nest when it makes sense, don't nest when it doesn't.
Your problem might be better solved with this answer, since there are more than 2 subsets of input elements (text, date, button, checkbox/radio, slider, color picker, etc.) and styles that should be applied to text style inputs generally don't work well on any other type.

What's the easiest way to create an extensible custom container in Flex?

I want to create an MXML container component that has some of its own chrome -- a standard query display, et al -- and that supports the addition of child components to it. Something a lot like the existing mx:Panel class, which includes a title label, but acts like a plain mx:Box with regards to adding children.
What's the easiest way to do this?
Edit:
To be clear, I want to be able to extend the container using MXML, so the "Multiple visual children" problem is relevant.
Extend a container and add a title label. Probably the <mx:Canvas/> will work here. Make the title a public var and include a var for the styleName of the label.
Then override the addChild() method so that any child that is added is added instead to the that is your container.
Leave enough space for your title when you position your Box element (i.e., give its y property enough space. If there is no title you may want to reclaim that space.
That's the basics. Customize to your heart's content.
EDITED TO ADD: I do this creating an ActionScript class first, extending the container I am targeting, and I add the "furniture" — items the class will always use, like title in your case — by overriding createChildren and calling super.addChild(item) for those items. Calling addChild from then on, even in MXML markup, adds items to the inner container.
We do this with states.
We put the chrome for the base container in a state (in mx:AddChild elements) and then use the initialize event to switch to that state when the control is created. All the chrome is then added to the container.
That gets round the multiple sets of visual children problem.
The downsides to this approach are:
You don't see the chrome when editing descendents of the base.
You can't directly access the parent chrome controls from descendent components as they are not there at compile time (instead, you need to define properties, methods or events on the base that the descendents can access)
However, it works well for us.

Resources