Skip to content

Commit 89ae5f1

Browse files
Merge pull request #17 from glints-dev/feat/index-table-bulk-actions
IndexTable pass BulkAction component as prop
2 parents 809a818 + b838069 commit 89ae5f1

File tree

9 files changed

+54
-35
lines changed

9 files changed

+54
-35
lines changed

.changeset/wet-kangaroos-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'polaris-glints': major
3+
---
4+
5+
IndexTable pass BulkAction component as prop

polaris-react/src/components/CheckableButton/CheckableButton.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ $button-vertical-padding: calc(
6161
overflow: hidden;
6262
max-width: 100%;
6363
text-overflow: ellipsis;
64+
font-size: var(--p-font-size-100);
65+
font-family: 'Noto Sans TC', 'Noto Sans SC', 'Noto Sans KR', 'Noto Sans JP',
66+
'Noto Sans', sans-serif;
6467
// padding to fix the bottom of letters being cutoff by overflow: hidden
6568
padding: var(--p-space-025) 0;
6669
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY

polaris-react/src/components/CheckableButton/CheckableButton.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, {useRef, useImperativeHandle, forwardRef} from 'react';
33
import type {CheckboxHandles} from '../../types';
44
import {classNames} from '../../utilities/css';
55
import {Checkbox} from '../Checkbox';
6+
import type {IndexTableHeadingCheckbox} from '../IndexTable';
67

78
import styles from './CheckableButton.scss';
89

@@ -13,6 +14,7 @@ export interface CheckableButtonProps {
1314
disabled?: boolean;
1415
onToggleAll?(): void;
1516
ariaLive?: 'off' | 'polite';
17+
checkbox?: (props: IndexTableHeadingCheckbox) => React.ReactNode;
1618
}
1719

1820
export const CheckableButton = forwardRef(function CheckableButton(
@@ -23,6 +25,7 @@ export const CheckableButton = forwardRef(function CheckableButton(
2325
selected,
2426
disabled,
2527
ariaLive,
28+
checkbox,
2629
}: CheckableButtonProps,
2730
ref,
2831
) {
@@ -43,14 +46,21 @@ export const CheckableButton = forwardRef(function CheckableButton(
4346
return (
4447
<div className={className} onClick={onToggleAll}>
4548
<div className={styles.Checkbox}>
46-
<Checkbox
47-
label={accessibilityLabel}
48-
labelHidden
49-
checked={selected}
50-
disabled={disabled}
51-
onChange={onToggleAll}
52-
ref={checkBoxRef}
53-
/>
49+
{checkbox ? (
50+
checkbox?.({
51+
onChange: onToggleAll,
52+
checked: selected,
53+
})
54+
) : (
55+
<Checkbox
56+
label={accessibilityLabel}
57+
labelHidden
58+
checked={selected}
59+
disabled={disabled}
60+
onChange={onToggleAll}
61+
ref={checkBoxRef}
62+
/>
63+
)}
5464
</div>
5565
<span className={styles.Label} aria-live={ariaLive}>
5666
{label}

polaris-react/src/components/Checkbox/Checkbox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import React, {
66
useContext,
77
} from 'react';
88
import {MinusMinor, TickSmallMinor} from '@shopify/polaris-icons';
9+
import {nanoid} from 'nanoid';
910

1011
import {classNames} from '../../utilities/css';
1112
import {useToggle} from '../../utilities/use-toggle';
12-
import {useUniqueId} from '../../utilities/unique-id';
1313
import {Choice, helpTextID} from '../Choice';
1414
import {errorTextID} from '../InlineError';
1515
import {Icon} from '../Icon';
@@ -70,7 +70,7 @@ export const Checkbox = forwardRef<CheckboxHandles, CheckboxProps>(
7070
ref,
7171
) {
7272
const inputNode = useRef<HTMLInputElement>(null);
73-
const id = useUniqueId('Checkbox', idProp);
73+
const id = `Checkbox-${idProp ?? nanoid()}`;
7474
const {
7575
value: mouseOver,
7676
setTrue: handleMouseOver,

polaris-react/src/components/IndexTable/IndexTable.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ $loading-panel-height: 53px;
174174
&,
175175
.TableCell-first,
176176
.TableCell-first + .TableCell {
177-
background-color: var(--p-surface-hovered);
177+
background-color: #eaf9ff;
178178
}
179179
}
180180

@@ -185,7 +185,7 @@ $loading-panel-height: 53px;
185185
.TableHeading-second,
186186
.TableCell-first,
187187
.TableCell-first + .TableCell {
188-
background-color: var(--p-surface-selected);
188+
background-color: #eaf9ff;
189189
}
190190
}
191191

@@ -195,7 +195,7 @@ $loading-panel-height: 53px;
195195
&,
196196
.TableCell-first,
197197
.TableCell-first + .TableCell {
198-
background-color: var(--p-surface-selected-hovered);
198+
background-color: #eaf9ff;
199199
}
200200
}
201201
}

polaris-react/src/components/IndexTable/IndexTable.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {Stack} from '../Stack';
1313
import {Spinner} from '../Spinner';
1414
import {Text} from '../Text';
1515
import {
16-
BulkActions,
16+
BulkAction,
1717
BulkActionsProps,
1818
useIsBulkActionsSticky,
1919
} from '../BulkActions';
@@ -27,7 +27,7 @@ import {
2727
} from '../../utilities/index-provider';
2828
import {AfterInitialMount} from '../AfterInitialMount';
2929
import {IndexProvider} from '../IndexProvider';
30-
import type {NonEmptyArray} from '../../types';
30+
import type {ActionListSection, NonEmptyArray} from '../../types';
3131

3232
import {getTableHeadingsBySelector} from './utilities';
3333
import {ScrollContainer, Cell, Row} from './components';
@@ -62,7 +62,7 @@ interface IndexTableSortToggleLabels {
6262
[key: number]: IndexTableSortToggleLabel;
6363
}
6464

65-
interface IndexTableHeadingCheckbox {
65+
export interface IndexTableHeadingCheckbox {
6666
label?: string;
6767
onChange?: (checked: boolean) => unknown;
6868
checked?: boolean | 'indeterminate';
@@ -104,6 +104,11 @@ export interface IndexTableBaseProps {
104104
onboardingBadgeText?: string;
105105
undoText?: string;
106106
checkbox?: (props: IndexTableHeadingCheckbox) => React.ReactNode;
107+
renderBulkActions?: ({
108+
actions,
109+
}: {
110+
actions: (BulkAction | ActionListSection)[];
111+
}) => React.ReactNode;
107112
}
108113

109114
export interface TableHeadingRect {
@@ -137,6 +142,7 @@ function IndexTableBase({
137142
onboardingBadgeText,
138143
undoText,
139144
checkbox,
145+
renderBulkActions,
140146
...restProps
141147
}: IndexTableBaseProps) {
142148
const {
@@ -531,7 +537,7 @@ function IndexTableBase({
531537
);
532538

533539
const shouldShowActions = !condensed || selectedItemsCount;
534-
const promotedActions = shouldShowActions ? promotedBulkActions : [];
540+
// const promotedActions = shouldShowActions ? promotedBulkActions : [];
535541
const actions = shouldShowActions ? bulkActions : [];
536542

537543
const bulkActionsMarkup =
@@ -548,14 +554,15 @@ function IndexTableBase({
548554
: undefined,
549555
}}
550556
>
551-
<BulkActions
557+
{renderBulkActions?.({actions})}
558+
{/* <BulkActions
552559
selectMode={selectMode}
553560
promotedActions={promotedActions}
554561
actions={actions}
555562
onSelectModeToggle={condensed ? handleSelectModeToggle : undefined}
556563
isSticky={isBulkActionsSticky}
557564
width={bulkActionsMaxWidth}
558-
/>
565+
/> */}
559566
</div>
560567
) : null;
561568

@@ -576,6 +583,7 @@ function IndexTableBase({
576583
onToggleAll={handleTogglePage}
577584
paginatedSelectAllText={paginatedSelectAllText}
578585
paginatedSelectAllAction={paginatedSelectAllAction}
586+
checkbox={checkbox}
579587
/>
580588
{loadingMarkup}
581589
</div>
@@ -834,9 +842,9 @@ function IndexTableBase({
834842
};
835843
}
836844

837-
function handleSelectModeToggle() {
838-
handleSelectionChange(SelectionType.All, false);
839-
}
845+
// function handleSelectModeToggle() {
846+
// handleSelectionChange(SelectionType.All, false);
847+
// }
840848
}
841849

842850
const isBreakpointsXS = () => {

polaris-react/src/components/SelectAllActions/SelectAllActions.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {classNames} from '../../utilities/css';
55
import type {Action} from '../../types';
66
import {UnstyledButton} from '../UnstyledButton';
77
import {CheckableButton} from '../CheckableButton';
8+
import type {IndexTableHeadingCheckbox} from '../IndexTable';
89

910
import styles from './SelectAllActions.scss';
1011

@@ -28,6 +29,7 @@ export interface SelectAllActionsProps {
2829
disabled?: boolean;
2930
/** Callback when the select all checkbox is clicked */
3031
onToggleAll?(): void;
32+
checkbox?: (props: IndexTableHeadingCheckbox) => React.ReactNode;
3133
}
3234

3335
export const SelectAllActions = forwardRef(function SelectAllActions(
@@ -40,6 +42,7 @@ export const SelectAllActions = forwardRef(function SelectAllActions(
4042
paginatedSelectAllAction,
4143
disabled,
4244
onToggleAll,
45+
checkbox,
4346
}: SelectAllActionsProps,
4447
ref,
4548
) {
@@ -72,6 +75,7 @@ export const SelectAllActions = forwardRef(function SelectAllActions(
7275
disabled,
7376
ariaLive,
7477
ref,
78+
checkbox,
7579
};
7680
const markup = (
7781
<Transition timeout={0} in={selectMode} key="markup">

polaris-react/src/components/Tabs/tests/Tabs.test.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,17 +402,6 @@ describe('<Tabs />', () => {
402402
expect(tabs.find(Popover)).toHaveReactProps({preferredPosition: 'below'});
403403
});
404404

405-
it('renders with a button as the activator when there are hiddenTabs', () => {
406-
const tabs = mountWithApp(<Tabs {...mockProps} />);
407-
tabs.find(TabMeasurer)!.trigger('handleMeasurement', {
408-
hiddenTabWidths: [82, 160, 150, 100, 80, 120],
409-
containerWidth: 300,
410-
disclosureWidth: 0,
411-
});
412-
413-
expect(tabs.find(Popover)!.prop('activator').type).toBe('button');
414-
});
415-
416405
describe('ArrowRight', () => {
417406
it('shifts focus to the first tab when pressing ArrowRight', () => {
418407
const tabs = mountWithApp(<Tabs {...mockProps} />);

polaris-react/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export {Image} from './components/Image';
209209
export type {ImageProps} from './components/Image';
210210

211211
export {IndexTable, Row, Cell} from './components/IndexTable';
212-
export type {IndexTableProps} from './components/IndexTable';
212+
export type {IndexTableProps, RowProps} from './components/IndexTable';
213213

214214
export {Indicator} from './components/Indicator';
215215
export type {IndicatorProps} from './components/Indicator';
@@ -435,6 +435,6 @@ export {
435435
export {
436436
SELECT_ALL_ITEMS as INDEX_TABLE_SELECT_ALL_ITEMS,
437437
SelectionType as IndexTableSelectionType,
438-
useIndexSelectionChange as useIndexTableIndexSelectionChange,
438+
useIndexSelectionChange,
439439
} from './utilities/index-provider';
440440
export {useBreakpoints} from './utilities/breakpoints';

0 commit comments

Comments
 (0)