-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2542 from Shopify/funcify-bulkactionbutton
[BulkActionButton] Converted to a functional component
- Loading branch information
Showing
2 changed files
with
33 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 32 additions & 37 deletions
69
...ents/ResourceList/components/BulkActions/components/BulkActionButton/BulkActionButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,46 @@ | ||
import React, {createRef} from 'react'; | ||
import React, {useRef} from 'react'; | ||
import {DisableableAction} from '../../../../../../types'; | ||
import {Button} from '../../../../../Button'; | ||
import {useComponentDidMount} from '../../../../../../utilities/use-component-did-mount'; | ||
|
||
import styles from '../../BulkActions.scss'; | ||
|
||
export type BulkActionButtonProps = { | ||
disclosure?: boolean; | ||
handleMeasurement?(width: number): void; | ||
} & DisableableAction; | ||
|
||
export class BulkActionButton extends React.PureComponent< | ||
BulkActionButtonProps, | ||
never | ||
> { | ||
private bulkActionButton = createRef<HTMLDivElement>(); | ||
export function BulkActionButton({ | ||
handleMeasurement, | ||
url, | ||
external, | ||
onAction, | ||
content, | ||
disclosure, | ||
accessibilityLabel, | ||
disabled, | ||
}: BulkActionButtonProps) { | ||
const bulkActionButton = useRef<HTMLDivElement>(null); | ||
|
||
componentDidMount() { | ||
const {handleMeasurement} = this.props; | ||
if (handleMeasurement && this.bulkActionButton.current) { | ||
const width = this.bulkActionButton.current.getBoundingClientRect().width; | ||
useComponentDidMount(() => { | ||
if (handleMeasurement && bulkActionButton.current) { | ||
const width = bulkActionButton.current.getBoundingClientRect().width; | ||
handleMeasurement(width); | ||
} | ||
} | ||
|
||
render() { | ||
const { | ||
url, | ||
external, | ||
onAction, | ||
content, | ||
disclosure, | ||
accessibilityLabel, | ||
disabled, | ||
} = this.props; | ||
}); | ||
|
||
return ( | ||
<div className={styles.BulkActionButton} ref={this.bulkActionButton}> | ||
<Button | ||
external={external} | ||
url={url} | ||
aria-label={accessibilityLabel} | ||
onClick={onAction} | ||
disabled={disabled} | ||
disclosure={disclosure} | ||
> | ||
{content} | ||
</Button> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div className={styles.BulkActionButton} ref={bulkActionButton}> | ||
<Button | ||
external={external} | ||
url={url} | ||
aria-label={accessibilityLabel} | ||
onClick={onAction} | ||
disabled={disabled} | ||
disclosure={disclosure} | ||
> | ||
{content} | ||
</Button> | ||
</div> | ||
); | ||
} |