Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: expose the controls label for localization within Table #1603

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/dull-melons-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@bigcommerce/big-design': minor
'@bigcommerce/docs': minor
---

Enables the localization of the Table component's controls label. The controls label names the toolbar, which contains all pagination and selection inputs for the table.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface ActionsProps<T> {
selectedItems: Set<T>;
stickyHeader?: boolean;
tableId: string;
label: string;
}

const InternalActions = <T extends TableItem>({
Expand All @@ -31,6 +32,7 @@ const InternalActions = <T extends TableItem>({
selectedItems,
stickyHeader,
tableId,
label,
...props
}: ActionsProps<T>) => {
const isSelectable = typeof onSelectionChange === 'function';
Expand Down Expand Up @@ -59,7 +61,7 @@ const InternalActions = <T extends TableItem>({
<StyledFlex
alignItems="center"
aria-controls={tableId}
aria-label="Table Controls"
aria-label={label}
flexDirection="row"
justifyContent="stretch"
ref={forwardedRef}
Expand Down
18 changes: 9 additions & 9 deletions packages/big-design/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ import { HeaderCell } from './HeaderCell';
import { DragIconHeaderCell, HeaderCheckboxCell } from './HeaderCell/HeaderCell';
import { Row } from './Row';
import { StyledTable, StyledTableFigure } from './styled';
import { TableColumn, TableItem, TableProps } from './types';
import { Localization, TableColumn, TableItem, TableProps } from './types';

interface Localization {
ascendingOrder: string;
descendingOrder: string;
}

const defaultLocalization: Localization = {
const defaultLocalization: Required<Localization> = {
ascendingOrder: 'Ascending order',
descendingOrder: 'Descending order',
controlsLabel: 'Table Controls',
};

const InternalTable = <T extends TableItem>(
Expand All @@ -38,7 +34,7 @@ const InternalTable = <T extends TableItem>(
itemName,
items,
keyField = 'id',
localization = defaultLocalization,
localization: customLocalization,
onRowDrop,
pagination: undiscriminatedPagination,
selectable,
Expand All @@ -47,7 +43,10 @@ const InternalTable = <T extends TableItem>(
style,
...rest
} = props;

const localization = useMemo(
() => ({ ...defaultLocalization, ...customLocalization }),
[customLocalization],
);
const pagination = useMemo(
() => undiscriminatedPagination && discriminatePagination(undiscriminatedPagination),
[undiscriminatedPagination],
Expand Down Expand Up @@ -258,6 +257,7 @@ const InternalTable = <T extends TableItem>(
forwardedRef={actionsRef}
itemName={itemName}
items={items}
label={localization.controlsLabel}
onSelectionChange={selectable?.onSelectionChange}
pagination={pagination}
selectedItems={selectedItems}
Expand Down
7 changes: 4 additions & 3 deletions packages/big-design/src/components/Table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ export type TablePaginationProps =
| WithoutMarginProps<OffsetPaginationProps>
| WithoutMarginProps<StatelessPaginationPropsWithItemTotal>;

interface Localization {
ascendingOrder: string;
descendingOrder: string;
export interface Localization {
ascendingOrder?: string;
descendingOrder?: string;
controlsLabel?: string;
}

export interface TableProps<T> extends ComponentPropsWithoutRef<'table'> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface ActionsProps<T> {
setSelectedParentRowsCrossPages: Dispatch<SetStateAction<Set<string>>>;
selectedParentRowsCrossPages: Set<string>;
isChildrenRowsSelectable?: boolean;
label: string;
}

const InternalActions = <T extends TableItem>({
Expand All @@ -47,6 +48,7 @@ const InternalActions = <T extends TableItem>({
setSelectedParentRowsCrossPages,
selectedParentRowsCrossPages,
isChildrenRowsSelectable,
label,
...props
}: ActionsProps<T>) => {
const isSelectable = typeof onSelectionChange === 'function';
Expand Down Expand Up @@ -75,7 +77,7 @@ const InternalActions = <T extends TableItem>({
<StyledFlex
alignItems="center"
aria-controls={tableId}
aria-label="Table Controls"
aria-label={label}
flexDirection="row"
justifyContent="stretch"
ref={forwardedRef}
Expand Down
18 changes: 9 additions & 9 deletions packages/big-design/src/components/TableNext/TableNext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ import { getPagedIndex } from './helpers';
import { useExpandable, useSelectable } from './hooks';
import { RowContainer } from './RowContainer';
import { StyledTable, StyledTableFigure } from './styled';
import { TableColumn, TableItem, TableProps } from './types';
import { Localization, TableColumn, TableItem, TableProps } from './types';

interface Localization {
ascendingOrder: string;
descendingOrder: string;
}

const defaultLocalization: Localization = {
const defaultLocalization: Required<Localization> = {
ascendingOrder: 'Ascending order',
descendingOrder: 'Descending order',
controlsLabel: 'Table Controls',
};

const InternalTableNext = <T extends TableItem>(
Expand All @@ -44,7 +40,7 @@ const InternalTableNext = <T extends TableItem>(
itemName,
items,
keyField = 'id',
localization = defaultLocalization,
localization: customLocalization,
pagination: undiscriminatedPagination,
selectable,
sortable,
Expand All @@ -60,7 +56,10 @@ const InternalTableNext = <T extends TableItem>(
},
...rest
} = props;

const localization = useMemo(
() => ({ ...defaultLocalization, ...customLocalization }),
[customLocalization],
);
const pagination = useMemo(
() => undiscriminatedPagination && discriminatePagination(undiscriminatedPagination),
[undiscriminatedPagination],
Expand Down Expand Up @@ -288,6 +287,7 @@ const InternalTableNext = <T extends TableItem>(
isChildrenRowsSelectable={isChildrenRowsSelectable}
itemName={itemName}
items={items}
label={localization.controlsLabel}
onSelectionChange={selectable?.onSelectionChange}
pagination={pagination}
selectedItems={selectedItems}
Expand Down
7 changes: 4 additions & 3 deletions packages/big-design/src/components/TableNext/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ export type TablePaginationProps =
| WithoutMarginProps<OffsetPaginationProps>
| WithoutMarginProps<StatelessPaginationPropsWithItemTotal>;

interface Localization {
ascendingOrder: string;
descendingOrder: string;
export interface Localization {
ascendingOrder?: string;
descendingOrder?: string;
controlsLabel?: string;
}

export interface TableProps<T> extends ComponentPropsWithoutRef<'table'> {
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/PropTables/TablePropTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const tableProps: Prop[] = [
},
{
name: 'localization',
types: '{ ascendingOrder: string, descendingOrder: string }',
types: '{ ascendingOrder?: string, descendingOrder?: string, controlsLabel?: string }',
description: 'Overrides the labels with localized text.',
},
];
Expand Down