DocsGuides

Guides

Custom Icons Guide

How to use custom icons such as from Font Awesome in Shadcn Table

Shadcn Table uses Lucide icons by default for all of its internal icons.

Example

If you need to, you can customize and replace some or all of the icons with your own custom icons. You can either use other Lucide icons or icons from a completely different library.

Icon editions

The table ships one edition per icon library: Lucide (shadcn-table), Tabler, Phosphor, Hugeicons and Remix Icon (shadcn-table-<library>). Each one installs the same icons.ts with that library's icons and adds only its icon package. To switch, pick the library and run the command with --overwrite:

pnpm dlx shadcn@latest add https://www.shadcn-table.com/r/base/shadcn-table.json --overwrite

The previous icon package stays in package.json: remove it with your package manager when nothing else uses it. The docs examples use Lucide for their own buttons; swap those imports for your set.

The icons option below overrides single icons on any edition.

Every edition maps every icon key. Where a library has no match for a Lucide glyph, its edition uses the closest icon instead and says so in a comment in its icons.ts (for example the view settings icon, the sticky header and alternating rows toggles, and in some editions the density icons). The three grid line icons (GridLinesAllIcon, GridLinesRowsIcon, GridLinesColumnsIcon) are drawn by the library itself (ST_GridLinesAllIcon, ST_GridLinesRowsIcon, ST_GridLinesColumnsIcon) and are the same in every edition.

Icon Keys for the Toolbar and Column Menu

Besides the long-standing keys, these keys draw the chrome of the column menu, the filter chips, the sort editor, the view settings panel and the scroll cues (Lucide defaults in brackets):

  • AddIcon (Plus): "+ Filter" and "Add sort"
  • DeleteIcon (Trash2): delete all filters, remove a sort rule, "Delete sort"
  • SwapVertIcon (ArrowUpDown): the sort button and the sort chip
  • ArrowUpwardIcon (ArrowUp): the ascending sort arrow and Sort ascending (with ArrowDownwardIcon, ArrowDown)
  • ExpandMoreIcon (ChevronDown): the column menu chevron and the chip caret
  • LockIcon (Lock): locked columns and the Fixed position item
  • PushPinIcon (Pin) and PushPinOffIcon (PinOff): pin items, unpin, and the view settings pin toggles
  • SettingsIcon (Settings2): the view settings button
  • ViewColumnIcon (Columns3): the Columns row
  • DensitySmallIcon, DensityMediumIcon, DensityLargeIcon (Rows4, Rows3, Rows2): the density row and button
  • WrapTextIcon (WrapText) and SingleLineIcon (ArrowRightToLine): Wrap cell text off and on
  • GridLinesNoneIcon (Square), GridLinesRowsIcon, GridLinesColumnsIcon, GridLinesAllIcon: the grid lines row
  • StickyHeaderOnIcon (PanelTop) and StickyHeaderOffIcon (PanelTopDashed)
  • StripedOnIcon (GapVertical) and StripedOffIcon (SquareCenterlineDashedVertical): Alternating row colors
  • RowNumbersOnIcon (ListOrdered) and RowNumbersOffIcon (List)
  • RestartAltIcon (RotateCcw): Reset view
  • ChevronLeftIcon and ChevronRightIcon (ChevronLeft, ChevronRight): the scroll cues

Column-type icons (a calendar for dates, a hash for numbers) are not icon keys: set them per column with columnDef.icon, see the Column Icons Guide.

Relevant Table Options

Prop NameTypeDescription
iconsPartial<ST_Icons>;Replaces single icons of this table. The table merges ST_Default_Icons, then the icons of the nearest ST_DefaultsProvider, then this option, so this option wins for its keys.

Replace with Custom Icons

To replace a default icon, specify the icon in the icons table option. You should get TS hints for the name of the icons you can replace, but you can also consult this source file for a list of all the icons you can replace.

<ShadcnTable
  columns={columns}
  data={data}
  icons={{
    //change sort icon, connect internal props so that it gets styled correctly
    ArrowDownwardIcon: (props) =>  <FontAwesomeIcon icon={faSortDown} {...props} />,
    SearchIcon: () => <FontAwesomeIcon icon={faSearch} />,
    SortIcon: (props) => (<FontAwesomeIcon icon={faArrowDownWideShort} {...props} />), //best practice
  }}

Some icons have style props that get applied to them internally. So, in order to preserve the ability of those Icons to be styled with the correct paddings, margins, or rotations, you should pass in {...props} to your custom icon component as a best practice.

One Icon Set for Every Table

To give every table in a part of your app the same icons without passing icons to each one, wrap them in <ST_DefaultsProvider icons={...}>. Each table merges ST_Default_Icons, then the provider's icons, then its own icons option, so one table can still override a single key:

import { ST_DefaultsProvider } from '@/components/ui/shadcn-table';
import { ST_Default_Icons as tabler } from '@/components/ui/shadcn-table/icons/tabler';

<ST_DefaultsProvider icons={tabler}>
  <ShadcnTable columns={columns} data={data} />
  <ShadcnTable
    columns={columns}
    data={data}
    icons={{ AddIcon: (props) => <PlusCircle {...props} /> }}
  />
</ST_DefaultsProvider>

The map can be a whole icon set, such as another edition's icons.ts saved as icons/<library>.ts, or only the keys you change. The docs' theme panel uses this provider for its Icon Library select. See <ST_DefaultsProvider />.

Font Awesome Example

Here is an example where we use icons from a completely different library, Font Awesome.

Storybook

On this page