Material-UI Sizing Confusion - material-ui

In the sizing documentation, it says "Easily make an element as wide or as tall (relative to its parent) with the width and height utilities.".
What I realize is that almost all the examples in system section of documentation, examples mostly related to Box component. I tried some of the tricks from there on Button element. And expectedly nothing changed.

Well for those who is new on material (actually UI) this is a bit tricky. first, they use Box because as per box documentation they said box generated using material styled (not the styled-components) "The Box component packages all the style functions that are exposed in #material-ui/system. It's created using the styled() function of #material-ui/core/styles."
So, I went to the github and material core repository to understand how to do that.
export const styleFunction = css(
compose(
borders,
display,
flexbox,
grid,
positions,
palette,
shadows,
sizing,
spacing,
typography,
),
);
css and compose are also exported from #material-ui/system
then at the end of the file;
const Box = styled(BoxRoot, { shouldForwardProp }, { muiName: 'MuiBox' })(styleFunction);
export default Box;
The styled used here is from an experimentalStyled package (an internal package) but that does not matter. Cuz, Material guys exporting a styled function/hook for our use.
import { styled } from "#material-ui/core/styles";
I tried this styled function for Button component.
const CustomButton = styled(Button)(sizing);
adn yes it worked. I am now able to apply magical styling skills defined in the system section of material UI.
For those who wants to use this instead of other methods. I pushed an npm package too.
material-ui-styled-hook

Related

What is the best way to add colors to Material-UI more than Primary/Secondary?

I've looked through the documentation. I've scoured YT for tuts and googled to no avail. Maybe this is just beyond the scope of MUI, but it seems really counter-productive.
I'm just looking for a non-hacky, semantically-correct way of having my color palette defined where components can access the different colors (I know the color prop needs a wrapper, but even a style with the color var is ok to me for this).
My color object is as follows:
const colors = {
cultured: '#FCFAF9',
darkGray: '#333333',
turquoise: '#48E5C2',
unbleachedSilk: '#F3D3BD',
mediumGray: '#5e5e5e'
}
What I'm hoping to achieve is to use the primary/secondary palettes for most of it, but for pop colors, or decorations, I wanted to add more colors to the palette without using a semantically-wrong palette object (for instance, using 'error' to set a color, when the object doesn't really represent an error).
Are you really relegated to only two main colors with MUI? How are you guys defining 5 colors to use in a way that doesn't break logic?
My idea (pseudo-code):
<Button onClick={() => doSomething} color={{colors.mediumGray}} or style={{backgroundColor: colors.mediumGray}}>
Button
</Button>
After consulting with the repo, it appears that Material UI v5 fixes this issue, and using one of the workarounds is the only way to do it until v5 becomes a stable release (they said sometime in 2021).

Inspect widget font, margin, padding and other properties

Using flutter inspector I'm not able to find a list of widget's properties like font size, font family, border color, padding, margin ...
For example, in a Text widget the available properties are textDirection, textAlign, size, and a few more, like in screenshot below:
I would like to see all computed properties, like browsers do:
Of course they are different tools, but i would like to know if there is a way to check more properties.
I also found a code-based solution, to access widget properties after it has been rendered, like in this question:
How to get the TextFormField text color,fontsize, etc using controller in flutter?
Is that the best way to achieve the result? Is it possible to use Keys in a way which allows to access widget properties without using a custom widget (i would like to save the reference to a Text, Row, etc. widgets and print all their properties)?
I also tried to use toDiagnosticsNode and toStringDeep methods as follows (_textWidget is of course a Text widget created above, this code is called when i click a button):
var test = _textWidget.toDiagnosticsNode().getProperties();
if (test != null && test.isNotEmpty) {
test.forEach((element) {
print(element.toStringDeep());
});
}
Is it possible to play a bit with a recursive function to get all the properties? All i can see with that code is the text displayed.

Configure Alfresco.util.PopupManagers YUI Dialog

I'm trying to configure the width for Alfresco.util.PopupManager.displayPrompt() but I don't see how to do it.
YUI Dialog has a width property, but the only config that I've managed to see, defaultDisplayPromptConfig object, doesn't seem to pay much attention to my messing with it.
Specifically, I tried setting Alfresco.util.PopupManager.defaultDisplayPromptConfig.width but it didn't work :)
I'm also trying to style up the panel I'm loading (create-site style injected panel), but it does not work for now.
Is there a way to configure the PopupManager Prompt object?
TIA
If you look at the source for Alfresco.util.PopupManager.displayPrompt() contained in alfresco.js then you'll see that the method creates an instance of YAHOO.widget.SimpleDialog, which does support a width property.
The problem is that displayPrompt() takes only specific configuration options which it passes through to the SimpleDialog, so adding an additional width parameter to your config will not have any effect, as you can see.
// Create the SimpleDialog that will display the text
var prompt = new YAHOO.widget.SimpleDialog("prompt",
{
close: c.close,
constraintoviewport: c.constraintoviewport,
draggable: c.draggable,
effect: c.effect,
modal: c.modal,
visible: c.visible,
zIndex: this.zIndex++
});
// Show the title if it exists
if (c.title)
{
prompt.setHeader($html(c.title));
}
// Show the prompt text
prompt.setBody(c.noEscape ? c.text : $html(c.text));
// Show the icon if it exists
if (c.icon)
{
prompt.cfg.setProperty("icon", c.icon);
}
// Add the buttons to the dialog
if (c.buttons)
{
prompt.cfg.queueProperty("buttons", c.buttons);
}
// Add the dialog to the dom, center it and show it.
prompt.render(parent);
prompt.center();
prompt.show();
I like the idea of enhancing the function to support a width property and possibly others, but in the meantime you are best off using SimpleDialog directly in your own code, modifying the above to add a width parameter.

Themeing GtkNotebook (tab panels)

I'm trying to customize a theme - I want to remove the rounded corners for a theme I'm using in xfce.
In the gtkrc
style "clearlooks-notebook-bg"
{
bg[NORMAL] = #bg_color
}
style "clearlooks-notebook" = "clearlooks-notebook-bg"
{
xthickness = 5
ythickness = 0
}
Those aren't the properties I'm looking for..so I browse over to http://developer.gnome.org/gtk/stable/GtkNotebook.html#GtkNotebook.style-properties and there really isn't anything I am seeing that points me to the panels.
I see /usr/lib/gtk-2.0/2.10.0/engines/libclearlooks.so but I don't know where the theme files are located (xubuntu) so that I can see how clearlooks is handling the style of the tabs.
Pointers please
Theme resource file i.e. gtkrc is generally located under /usr/share/themes/<theme-name>/gtk-2.0/. For Clearlooks on Fedora 15, I can see gtkrc under /usr/share/themes/Clearlooks/gtk-2.0/.
What you are looking for cannot be achieved simple change in the gtkrc file. You have to understand that Clearlooks provides a Gtk Engine (/usr/lib/gtk-2.0/2.10.0/engines/libclearlooks.so is loadable module with the implementation of Gtk Engine for Clearlooks theme) along with theme resource file. Gtk Engine is responsible for implementation of drawing functions. These drawing functions override the ones provided by gtk+ library (GtkStyle, GtkRCStyle source files in Gtk) Thus you need to update the source of Clearlooks for changing the appearance. Source code is not very large (about ~10 files or so)! To get the source code of Clearlooks Gtk Engine on your system, check the package name for clearlooks (dpkg -S /usr/lib/gtk-2.0/2.10.0/engines/libclearlooks.so) & get the source for the package (apt-get source <clearlooks-package-name>). Modify the source code (look for draw_*/clearlooks_draw_* functions, clearlooks has code for drawing rounded rectangle thus draw_*/clearlooks_draw_* functions draw rounded rectangle as needed so change it to draw normal rectangle instead), build, install & have fun with new sharp unrounded tab corners!
Hope this helps!

ui.helper vs ui.item in jQuery UI

I was studying the jQuery UI Sortable widget and it said that all callback functions receive a ui object. Two of its properties are ui.helper nad ui.item. ui.helper is mentioned to be mostly a clone of ui.item, but I can't get the significance of calling it 'helper'. Also, the offset and position properties are defined in terms of the helper and not the item. What's the difference between the two ?
One of the answers mention that the helper fills the void, but the I read in the docs that the helper element is "used for dragging display". What exactly is this helper element and why is it named so?
From what I understand ui.helper is a "clone" of the ui.item. It is cloned so you can edit it with css and make it look like whatever you want it to look like while you are dragging it and it won't effect the original ui.item. So if you had a box and while it was being dragged you wanted it to turn into a blue box with curved edges but only while it was dragging you can by modifying ui.helper.
The helper is the element that fills the void (with visibility: hidden) when the item is dragged.