material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Do not require material icons to be imported from remote

Open bgits opened this issue 8 years ago • 13 comments

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] Often a project already has material-ui/icons in node_modules, so there is no need to load it from a remote resource and as pollute the global space.

Describe the solution you'd like A clear and concise description of what you want to happen. The required icons should already either be part of the library or can be imported directly where material-table is being used.

example:

import React, { Fragment, memo } from 'react'
import MaterialTable from 'material-table'
import Icons from '@material-ui/icons'

const myTable = ({ data }) => (
  <Fragment>
    <MaterialTable
      Icons={Icons}
      columns={[
        { title: 'Profile Id', field: 'idGiver', type: 'numeric' },
        { title: 'Name', field: 'name' },
        { title: 'Url', field: 'url' },
        { title: 'Commit Time', field: 'commitTime', type: 'numeric' },
        { title: 'cancel', field: 'canceled' }
      ]}
      data={data}
      title="Funding Profiles"
    />
  </Fragment>
)

export default memo(myTable)

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

bgits avatar Dec 02 '18 13:12 bgits

Very clear alternative to cdn import. I will try and do this. Thank @bgits

mbrn avatar Dec 02 '18 14:12 mbrn

im having issues doing this/it's not working as advertised. I used the code above (except the property icons needs to be lower case). But then it gives this error:

TS2739: Type 'typeof import("/Users/michael/path/to/projecti/node_modules/@material-ui/icons/index")' is missing the following properties from type 'Icons': DetailPanel, Export, NextPage, PreviousPage, ThirdStateCheck

So then I do something like:

import {
    Search,
    ViewColumn,
    SaveAlt,
    ChevronLeft,
    ChevronRight,
    FirstPage,
    LastPage,
    Add,
    Check,
    FilterList,
    Remove,
} from '@material-ui/icons'
...
icons={ 
    Check: Check,
    DetailPanel: ChevronRight,
    Export: SaveAlt,
    Filter: FilterList,
    FirstPage: FirstPage,
    LastPage: LastPage,
    NextPage: ChevronRight,
    PreviousPage: ChevronLeft,
    Search: Search,
    ThirdStateCheck: Remove,
}

That fails with:

TS2322: Type '{ Check: ComponentType<SvgIconProps>; DetailPanel: ComponentType<SvgIconProps>; Export: ComponentType<SvgIconProps>; Filter: ComponentType<SvgIconProps>; FirstPage: ComponentType<SvgIconProps>; ... 5 more ...; ViewColumn: ComponentType<...>; }' is not assignable to type 'Icons'.
Types of property 'Check' are incompatible.
Type 'ComponentType<SvgIconProps>' is not assignable to type '() => ReactElement<any>'.        
Type 'ComponentClass<SvgIconProps, any>' is not assignable to type '() => ReactElement<any>'.
Type 'ComponentClass<SvgIconProps, any>' provides no match for the signature '(): ReactElement<any>'.

How does one use this feature? Thanks much for you response.

michaeljtobias avatar Jan 23 '19 22:01 michaeljtobias

this worked:

import { SvgIconProps } from '@material-ui/core/SvgIcon'

import Search from '@material-ui/icons/Search'
import ViewColumn from '@material-ui/icons/ViewColumn'
import SaveAlt from '@material-ui/icons/SaveAlt'
import ChevronLeft from '@material-ui/icons/ChevronLeft'
import ChevronRight from '@material-ui/icons/ChevronRight'
import FirstPage from '@material-ui/icons/FirstPage'
import LastPage from '@material-ui/icons/LastPage'
import Add from '@material-ui/icons/Add'
import Check from '@material-ui/icons/Check'
import FilterList from '@material-ui/icons/FilterList'
import Remove from '@material-ui/icons/Remove'

import MaterialTable from 'material-table';

...

<MaterialTable
icons={{ 
                        Check: () => <Check /> as React.ReactElement<SvgIconProps>,
                        Export: () => <SaveAlt /> as React.ReactElement<SvgIconProps>,
                        Filter: () => <FilterList /> as React.ReactElement<SvgIconProps>,
                        FirstPage: () => <FirstPage /> as React.ReactElement<SvgIconProps>,
                        LastPage: () => <LastPage /> as React.ReactElement<SvgIconProps>,
                        NextPage: () => <ChevronRight /> as React.ReactElement<SvgIconProps>,
                        PreviousPage: () => <ChevronLeft /> as React.ReactElement<SvgIconProps>,
                        Search: () => <Search /> as React.ReactElement<SvgIconProps>,
                        ThirdStateCheck: () => <Remove /> as React.ReactElement<SvgIconProps>,
                        ViewColumn: () => <ViewColumn /> as React.ReactElement<SvgIconProps>,
                        DetailPanel: () => <ChevronRight /> as React.ReactElement<SvgIconProps>,
                      }}

michaeljtobias avatar Jan 24 '19 00:01 michaeljtobias

Thank you! It worked

import Search from '@material-ui/icons/Search'
import ViewColumn from '@material-ui/icons/ViewColumn'
import SaveAlt from '@material-ui/icons/SaveAlt'
import ChevronLeft from '@material-ui/icons/ChevronLeft'
import ChevronRight from '@material-ui/icons/ChevronRight'
import FirstPage from '@material-ui/icons/FirstPage'
import LastPage from '@material-ui/icons/LastPage'
import Add from '@material-ui/icons/Add'
import Check from '@material-ui/icons/Check'
import FilterList from '@material-ui/icons/FilterList'
import Remove from '@material-ui/icons/Remove'

import MaterialTable from 'material-table';
...
<MaterialTable
          icons={{ 
            Check: Check,
            DetailPanel: ChevronRight,
            Export: SaveAlt,
            Filter: FilterList,
            FirstPage: FirstPage,
            LastPage: LastPage,
            NextPage: ChevronRight,
            PreviousPage: ChevronLeft,
            Search: Search,
            ThirdStateCheck: Remove,
          }}

sfDev001 avatar Jan 25 '19 06:01 sfDev001

Specifying icons and using Editable together will result in an error. Is there a way to use it together? https://mbrn.github.io/material-table/#/docz-examples-15-example-editable img

sfDev001 avatar Apr 17 '19 00:04 sfDev001

It should be resolved with latest versions.

mbrn avatar May 04 '19 17:05 mbrn

i need diffrent icon on each filter.

bhavna-it-talents avatar Feb 11 '20 13:02 bhavna-it-talents

A complete version:

import Search from "@material-ui/icons/Search";

import ViewColumn from "@material-ui/icons/ViewColumn";

import SaveAlt from "@material-ui/icons/SaveAlt";

import ChevronLeft from "@material-ui/icons/ChevronLeft";

import ChevronRight from "@material-ui/icons/ChevronRight";

import FirstPage from "@material-ui/icons/FirstPage";

import LastPage from "@material-ui/icons/LastPage";

import Add from "@material-ui/icons/Add";

import Check from "@material-ui/icons/Check";

import FilterList from "@material-ui/icons/FilterList";

import Remove from "@material-ui/icons/Remove";

import ArrowDownward from "@material-ui/icons/ArrowDownward";

import Clear from "@material-ui/icons/Clear";

import DeleteOutline from "@material-ui/icons/DeleteOutline";

import Edit from "@material-ui/icons/Edit";

export default {
  Check: Check,
  DetailPanel: ChevronRight,
  Delete: DeleteOutline,
  Export: SaveAlt,
  Filter: FilterList,
  FirstPage: FirstPage,
  LastPage: LastPage,
  NextPage: ChevronRight,
  PreviousPage: ChevronLeft,
  Search: Search,
  ThirdStateCheck: Remove,
  Add: Add,
  SortArrow: ArrowDownward,
  Clear: Clear,
  Edit: Edit,
  ViewColumn: ViewColumn
};

ghost avatar Feb 27 '20 01:02 ghost

My icon Clear does not render, How do I do? My version: "@material-ui/core": "^4.9.5", "@material-ui/icons": "^4.9.1", "@material-ui/styles": "^4.9.0", "material-table": "^1.57.2",

CristianaYasuda avatar Mar 02 '20 18:03 CristianaYasuda

@CristianaYasuda check the way you're importing the icons and the version, in my project I'm using the same version that you're for the Material Table and the version 4.5.1 for the Material UI Icons

ghost avatar Mar 04 '20 01:03 ghost

@CristianaYasuda Follow the instructions described in the README.md, they are more up-to-date than the comments in this thread. https://github.com/mbrn/material-table#installation

blumk avatar Mar 18 '20 14:03 blumk

Is it completely necessary to import the icons? Why cant the icons just be used by default? It's kind of annoying to have to specify these icons whenever i make a table.

matthewtridoan avatar Jul 14 '20 22:07 matthewtridoan

@matthewcoding0 agree!

PeaceS avatar Aug 06 '20 09:08 PeaceS