Material-ui: Is there a way to import all components?

Created on 14 Mar 2018  路  12Comments  路  Source: mui-org/material-ui

I would like to do:

import * as MaterialUI from "material-ui";

To have all components accessible as properties on the MaterialUI object. Is there a way to do this or something similar?

Right now when I do that I just get an object with a colors property.

  • [X] I have searched the issues of this repository and believe that this is not a duplicate.

Context

I am trying to create async wrappers for each component inside of my build system.

question

Most helpful comment

My bad, they are already enumerable:
https://github.com/mui-org/material-ui/blob/caf5513c6f19d1b776801c96d1715b1dd1a6d1b0/src/index.spec.js#L11-L21

import * as MaterialUI from "material-ui";

console.log(Object.keys(MaterialUI).length); // 101

All 12 comments

Right now when I do that I just get an object with a colors property.

@ryanpcmcquen I would expect it to work.

I am trying to create async wrappers for each component inside of my build system.

What's the purpuse of the async wrapper?

Well, we want to be able to 'hot-load' components using React Habitat in our CMS.

@ryanpcmcquen All the components are present, but non enumerable.

@oliviertassinari, is there a way to make them enumerable?

My bad, they are already enumerable:
https://github.com/mui-org/material-ui/blob/caf5513c6f19d1b776801c96d1715b1dd1a6d1b0/src/index.spec.js#L11-L21

import * as MaterialUI from "material-ui";

console.log(Object.keys(MaterialUI).length); // 101

Thank you @oliviertassinari!

@oliviertassinari, is there any way to exclude the utilities and colors that get included with that list (so it is just components)?

is there any way to exclude the utilities and colors that get included with that list (so it is just components)

@ryanpcmcquen I don't think so. You need a (white/black)list.

@oliviertassinari, do they all begin with a lowercase letter?

@ryanpcmcquen The uppercasing can be as good filter. You can prune all the lowercase modules. They will never be react components. But you can get some classes that aren't component with an uppercase.

So this may be of use to someone in the future:

import * as MaterialUI from "material-ui";

const MaterialUIComponents = Object.keys(MaterialUI).filter((key) => {
    const firstLetter = key.slice(0, 1);
    return firstLetter === firstLetter.toUpperCase() ? key : false;
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

newoga picture newoga  路  3Comments

sys13 picture sys13  路  3Comments

finaiized picture finaiized  路  3Comments

TimoRuetten picture TimoRuetten  路  3Comments

ghost picture ghost  路  3Comments