how to remove an style from material ui component - material-ui

I know its possible to use "sx" prop or createTheme() function to override an style in material ui component. but is there any way to remove any of default styles from its components?

Yes, you can use genereic css property.
all: "initial"
<Button sx={{ all: "initial" }}>Click me</Button>
<Button style={{ all: "initial" }}>Click me</Button>
When you use it its going to reset the stylisation of the component and after it you can write your own.

Related

#circlon/angular-tree-component: How to customize checkbox template

I want to use custom templates for the tree nodes as shown here on their website
https://angular2-tree.readme.io/docs/templates
But I also need the checkbox tri-state functionality as demonstrated here
https://angular2-tree.readme.io/docs/tri-state-checkboxes
In this custom treeNodeFullTemplate example they have a checkbox as part of the template but it doesn't have the tri-state relationship between the parents and children. Is there a way to have a custom checkbox and keep all the correct event listeners etc.? I can't seem to find any documentation on the checkboxes API if there is one.
<tree-root id="tree" [focused]="true" [nodes]="nodes">
<ng-template #treeNodeFullTemplate let-node let-index="index" let-templates="templates">
<div class="tree-node">
<input type="checkbox" [checked]="node.isActive" (change)="node.toggleActivated(true)" />
<tree-node-expander [node]="node"></tree-node-expander>
<div
class="node-content-wrapper"
[class.node-content-wrapper-active]="node.isActive"
[class.node-content-wrapper-focused]="node.isFocused"
(click)="node.toggleActivated(true)">
<span [class]="node.data.className + 'Index'">{{ index }}</span>
<span [class]="node.data.className" [class.title]="true">{{ node.data.title }}</span>
</div>
<tree-node-children [node]="node" [templates]="templates"></tree-node-children>
</div>
</ng-template>
</tree-root>
I can see that the (change) method on the checkbox is not right but do I need to write my own one to get the parent and children and determine state on click? It seems strange that I can't just tap into an existing API.

Material-UI v5 Datepicker - expand to the full width of its parent

In Material-UI v4 the fullWidth prop could be passed to the Datepicker component. However, in v5 this prop is not listed in the component API. All css selectors for this component are non-deterministic and so I am unable to use the width css property. Is there any alternative that I have missed?
Example:
https://codesandbox.io/s/material-ui-v5-forked-fvc3er?file=/src/App.js
For both the DatePicker and TimePicker components in Material-UI v5, you need to set the renderInput prop. When using the TextField component as a rendering component, you can then use the fullWidth prop to expand to the width of its parent.
<DatePicker
inputFormat="MM/dd/yyyy"
value={date}
onChange={(value) => setDate(value)}
renderInput={(params) => <TextField {...params} fullWidth />} <--- This right here
/>
For me the fullWidth Attribute didn't work. I am using the following versions: "#mui/lab": "^5.0.0-alpha.61", and "#mui/material": "^5.2.3".
My solution was simply exchange fullWidth width sx-styles like:
<DatePicker
inputFormat="MM/dd/yyyy"
value={date}
onChange={(value) => setDate(value)}
renderInput={(params) => <TextField {...params} sx={{width: '100%'}} />
Posting an answer for future reference since the above answers didn't work for me.
renderInput={(params) => <TextField {...params} sx={{ gridColumn: "span 4" }}/>
You can change the value of span to increase or decrease length according to your need.
Assuming that the original intention of the thread was for devs like myself who just wanted to know how to customize the size of Material UI's StaticDatePicker component here is my solution to this problem.
In Material v5 we can use the styled to customize any components we like. I also chose to customize the CalendarPicker over the StaticDatePicker because it was easier to target the .MuiCalendarPicker-root class this way.

Add flex-grow to material ui Grid

Is it possible to add "flex-grow" to a Grid item in material ui? Seams a bit weird that I have to choose Box in order to get access to Flexbox https://material-ui.com/system/flexbox/?
Yes, you can add flex-grow using the style attribute.
<Grid item style={{ flexGrow: 1 }}>
<Typography variant="h1" color="textPrimary" >
Title
</Typography>
</Grid>
or you can create a separate class for multiple Grid items.

Why does Ionic components render the <Host> and then inside, the <TagType>, instead of just rendering the <TagType>?

Refering to the documentation for a Ionic button component I see that the component renders the <Host>, and then, inside the <TagType>. I would like to know what is the reason behind.
For example, why not just rendering the <TagType> ?
Along with this question, I also see that all the classes are attached to the <Host>, instead of to the <TagType>. I would also like to know what is the reason behind this. Why not adding the classes directly to the <TagType> ?
This is the tsx for the Ionic button component :
return (
<Host
onClick={this.handleClick}
aria-disabled={disabled ? 'true' : null}
class={{
...createColorClasses(color),
[mode]: true,
[buttonType]: true,
[`${buttonType}-${expand}`]: expand !== undefined,
[`${buttonType}-${finalSize}`]: finalSize !== undefined,
[`${buttonType}-${shape}`]: shape !== undefined,
[`${buttonType}-${fill}`]: true,
[`${buttonType}-strong`]: strong,
'button-has-icon-only': hasIconOnly,
'button-disabled': disabled,
'ion-activatable': true,
'ion-focusable': true,
}}
>
<TagType
{...attrs}
class="button-native"
disabled={disabled}
onFocus={this.onFocus}
onBlur={this.onBlur}
>
<span class="button-inner">
<slot name="icon-only"></slot>
<slot name="start"></slot>
<slot></slot>
<slot name="end"></slot>
</span>
{mode === 'md' && <ion-ripple-effect type={this.rippleType}></ion-ripple-effect>}
</TagType>
</Host>
);
and This is how it gets rendered :
<ion-button size="small" class="ios button button-small button-solid ion-activatable ion-focusable hydrated">Default</ion-button>
#shadow-root
<button type="button" class="button-native">
<span class="button-inner">
<slot name="icon-only"></slot>
<slot name="start"></slot>
<slot></slot>
<slot name="end"></slot>
</span>
</button>
As you can see, the classes are inserted on the Host (ion-button), instead of on the <TagType>. I would like to understand what benefit lies behind this decission.
Also, I would like to understand what is the reason for having a <span class="button-inner"> inside the <TagType> (button) ? Why not just throwing the <slot></slot> directly into the <TagType> ?
I am new to Stencil and Ionic, and I am very eager about understanding the best possible way to build components. So, I would be much appreciated if anyone can kindly help me understand the reasons that lies behind this descisions!
Host is used to add classes, event listeners, and attributes on the ion-button it self, and not any nested DOM of the component. This is because when doing things like class bindings, we only really care about the element itself, not the internals of the components. With cross-component communication and shadow DOM, it's not possible to get internal references to things like TageType in this situation.
And the reason for the slot is to handle cross browser differences in how text/styles are applied for buttons. More internal knowledge for us at Ionic, and not things that others need to know about.

FlexBox Item growFactor is not updating the style if the binding is changing

Here is the plunker link: http://plnkr.co/edit/XVINtJ1RbNrkaCAFbZti?p=preview
I have a view with a FlexBox with 2 items that span 100% width.
<FlexBox width="100%">
<items>
<Button press="onButtonLeftPress" text="{LayoutModel>/left}" width="100%" type="Emphasized" >
<layoutData>
<FlexItemData growFactor="{LayoutModel>/left}" />
</layoutData>
</Button>
<Button press="onButtonRightPress" text="{LayoutModel>/right}" width="100%" type="Reject">
<layoutData>
<FlexItemData growFactor="{LayoutModel>/right}" />
</layoutData>
</Button>
</items>
</FlexBox>
The growFactor of the 2 FlexBox items are bound to a LayoutModel that is initialized in index.html
var layoutModel = new sap.ui.model.json.JSONModel();
layoutModel.setData({
left: 2,
right: 1
});
ui5Core.setModel(layoutModel, "LayoutModel");
By pressing the buttons I update the model properties "left" and "right". The values are updated as you can see but the style for the items is not updated.
I see that FlexBox is taking into consideration only at initialization the values, but if the value is changed the UI is not updated.
The main idea is that I'm trying to obtain a layout with 2-3 columns that collapse/expand.
Do you have any ideas how to obtain this? or how to solve this FlexBox bug?
Many thanks
You have to call invalidate() on the FlexBox instance inside your handler functions. This will make the FlexBox rerender and everything works as expected. Here is a "One-File" jsbin example: https://jsbin.com/pisadigene/edit?html,output
I did not check the code of the FlexBox but I guess that updating the GrowFactor of a FlexBox item does not trigger a change (i.e. rerendering). I guess it’s just a one-time thing...
However, you should be aware that using invalidate() will trigger a re-rendering for all content inside the FlexBox. So that is not a good idea in case you have a lot of content inside the FlexBox because it can have a negative effect on performance… I am not very sure what you try to achieve but using flexboxes for a complete layout of the app might not be a good idea. Instead you should check the other opportunities you have with SAPUI5, i.e. MatrixLayout etc.