Skip to content

Commit 4285b66

Browse files
authored
feat: add localization support and deprecate old props in DataTable (jbetancur#1323)
1 parent 7e95078 commit 4285b66

7 files changed

Lines changed: 120 additions & 5 deletions

File tree

apps/docs/package-lock.json

Lines changed: 30 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dependencies": {
1212
"@astrojs/react": "^4.2.0",
1313
"@astrojs/tailwind": "^5.1.4",
14+
"@shikijs/langs": "^4.1.0",
1415
"astro": "^5.7.0",
1516
"react": "^18.3.1",
1617
"react-data-table-component": "*",

apps/docs/src/pages/docs/api.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ Column-level footers live on each [`TableColumn<T>`](#tablecolumnt) as the `foot
165165
| `onColumnOrderChange` | `(columns: TableColumn<T>[]) => void` | - | Called after a drag-to-reorder column operation with the new column order. |
166166
| `onColumnGroupOrderChange` | `(groups: ColumnGroup[], columns: TableColumn<T>[]) => void` | - | Called after a group drag-reorder with the new group order and the matching updated column order. |
167167

168+
### Localization
169+
170+
| Prop | Type | Default | Description |
171+
|---|---|---|---|
172+
| `localization` | `Localization` | - | Override every user-visible string and aria-label in the table. Pass a pre-built locale or build your own. See [Localization](/docs/localization). |
173+
| ~~`columnFilterOptions`~~ | `ColumnFilterOptions` | - | **Deprecated.** Use `localization={{ filter: { ... } }}` instead. Will be removed in v9. |
174+
| ~~`expandableRowsOptions`~~ | `ExpandableRowsOptions` | - | **Deprecated.** Use `localization={{ expandable: { ... } }}` instead. Will be removed in v9. |
175+
168176
## ColumnGroup
169177

170178
Defines a spanning group header above one or more columns. Pass an array to the `columnGroups` prop.

apps/docs/src/pages/docs/changelog.astro

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,56 @@ import CodeBlock from '../../components/CodeBlock.astro';
1111
<a href="https://github.com/jbetancur/react-data-table-component/commits/master" target="_blank" rel="noreferrer">repository on GitHub</a>.
1212
</p>
1313

14+
<h2>8.3.0</h2>
15+
16+
<h3>New features</h3>
17+
<ul>
18+
<li>
19+
<strong>Localization</strong> — new <code>localization</code> prop on <code>DataTable</code>
20+
replaces the three separate option props (<code>columnFilterOptions</code>,
21+
<code>expandableRowsOptions</code>, and pagination aria-label fields on
22+
<code>paginationComponentOptions</code>). Pass a single object to translate every string and
23+
aria-label in the table — filter panel, pagination navigation, and expand/collapse buttons.
24+
→ <a href="/docs/localization">Localization docs</a>
25+
</li>
26+
<li>
27+
<strong>Built-in locales</strong> — import pre-built translations from the
28+
<code>react-data-table-component/locales</code> subpath. Ships with:
29+
English (<code>en</code>), French (<code>fr</code>), Spanish (<code>es</code>),
30+
German (<code>de</code>), Brazilian Portuguese (<code>ptBR</code>),
31+
Arabic — Modern Standard (<code>ar</code>), Egyptian (<code>arEG</code>), Levantine (<code>arLV</code>),
32+
Hebrew (<code>he</code>),
33+
Chinese Simplified (<code>zhCN</code>), Chinese Traditional (<code>zhTW</code>),
34+
Japanese (<code>ja</code>), Korean (<code>ko</code>), Ukrainian (<code>uk</code>).
35+
Each locale is individually tree-shakeable.
36+
</li>
37+
<li>
38+
New utility exports: <code>emptyFilterState(type)</code> and <code>isFilterActive(filter)</code>.
39+
→ <a href="/docs/filtering#utility-exports">Filtering docs</a>
40+
</li>
41+
</ul>
42+
43+
<h3>Deprecations</h3>
44+
<p>The following will continue to work in 8.x but will be removed in v9. TypeScript will show a deprecation hint.</p>
45+
<ul>
46+
<li>
47+
<code>columnFilterOptions</code> prop — use <code>localization</code> with a <code>filter</code> key instead.
48+
</li>
49+
<li>
50+
<code>expandableRowsOptions</code> prop — use <code>localization</code> with an <code>expandable</code> key instead.
51+
</li>
52+
<li>
53+
Pagination aria-label fields on <code>paginationComponentOptions</code>
54+
(<code>navigationAriaLabel</code>, <code>firstPageAriaLabel</code>, <code>previousPageAriaLabel</code>,
55+
<code>nextPageAriaLabel</code>, <code>lastPageAriaLabel</code>) —
56+
use <code>localization</code> with a <code>pagination</code> key instead.
57+
</li>
58+
<li>
59+
<code>ColumnFilterOptions</code> and <code>ExpandableRowsOptions</code> types —
60+
use <code>Localization['filter']</code> and <code>Localization['expandable']</code> instead.
61+
</li>
62+
</ul>
63+
1464
<h2>8.2.0</h2>
1565

1666
<h3>New features</h3>

src/components/DataTable.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ function DataTableInner<T>(props: TableProps<T>, ref: React.ForwardedRef<DataTab
109109
columnGroups,
110110
filterValues: controlledFilterValues,
111111
onFilterChange: onFilterChangeProp,
112-
localization = {},
112+
localization: localizationProp = {},
113+
columnFilterOptions,
114+
expandableRowsOptions,
113115
resizable = false,
114116
initialColumnWidths,
115117
onColumnResize,
@@ -122,6 +124,12 @@ function DataTableInner<T>(props: TableProps<T>, ref: React.ForwardedRef<DataTab
122124
ariaLabel,
123125
} = props;
124126

127+
const localization = {
128+
...localizationProp,
129+
filter: { ...columnFilterOptions, ...localizationProp.filter },
130+
expandable: { ...expandableRowsOptions, ...localizationProp.expandable },
131+
};
132+
125133
// Intentionally reading @deprecated props for backward compat; cast prevents TS hint 6385 here
126134
const {
127135
sortIcon: sortIconProp,

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export type {
3535
PaginationOptions,
3636
PaginationServerOptions,
3737
Localization,
38+
/** @deprecated Use `Localization['filter']` instead. Will be removed in v9. */
39+
ColumnFilterOptions,
40+
/** @deprecated Use `Localization['expandable']` instead. Will be removed in v9. */
41+
ExpandableRowsOptions,
3842
SortFunction,
3943
Selector,
4044
FilterType,

src/types.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ type ExpandableProps<T> = {
165165
expandOnRowClicked?: boolean;
166166
expandOnRowDoubleClicked?: boolean;
167167
onRowExpandToggled?: ExpandRowToggled<T>;
168+
/**
169+
* @deprecated Use the `localization` prop instead: `localization={{ expandable: { ... } }}`. Will be removed in v9.
170+
*/
171+
expandableRowsOptions?: ExpandableRowsOptions;
168172
};
169173

170174
type SortProps<T> = {
@@ -246,6 +250,10 @@ type BaseTableProps<T> = {
246250
onFilterChange?: (columnId: string | number, filter: FilterState) => void;
247251
/** Override every user-visible string in DataTable. Pass a pre-built locale or build your own. */
248252
localization?: Localization;
253+
/**
254+
* @deprecated Use the `localization` prop instead: `localization={{ filter: { ... } }}`. Will be removed in v9.
255+
*/
256+
columnFilterOptions?: ColumnFilterOptions;
249257
onColumnOrderChange?: (nextOrder: TableColumn<T>[]) => void;
250258
/** Called after a group drag reorder with the new group order and matching column order. */
251259
onColumnGroupOrderChange?: (nextGroups: ColumnGroup[], nextColumns: TableColumn<T>[]) => void;
@@ -482,6 +490,16 @@ export interface PaginationOptions {
482490
selectAllRowsItemText?: string;
483491
}
484492

493+
/**
494+
* @deprecated Use `Localization['filter']` instead. Will be removed in v9.
495+
*/
496+
export type ColumnFilterOptions = NonNullable<Localization['filter']>;
497+
498+
/**
499+
* @deprecated Use `Localization['expandable']` instead. Will be removed in v9.
500+
*/
501+
export type ExpandableRowsOptions = NonNullable<Localization['expandable']>;
502+
485503
/** All user-visible strings rendered by DataTable, grouped by feature area. */
486504
export interface Localization {
487505
pagination?: {

0 commit comments

Comments
 (0)