-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To ensure the `MaterialButtonReaderTeaser` and `MaterialButtonsFindOnShelf` have identical behavior, I created a shared component to eliminate code duplication.
- Loading branch information
1 parent
c6f8bc6
commit 256b15d
Showing
4 changed files
with
78 additions
and
68 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
58 changes: 58 additions & 0 deletions
58
src/components/material/material-buttons/generic/MaterialSecondaryButton.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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { FC } from "react"; | ||
import { Button } from "../../../Buttons/Button"; | ||
import { ButtonSize } from "../../../../core/utils/types/button"; | ||
|
||
interface MaterialSecondaryButtonProps { | ||
label: string; | ||
size: ButtonSize; | ||
onClick: () => void; | ||
dataCy?: string; | ||
ariaDescribedBy: string; | ||
} | ||
|
||
const MaterialSecondaryButton: FC<MaterialSecondaryButtonProps> = ({ | ||
label, | ||
size, | ||
onClick, | ||
dataCy, | ||
ariaDescribedBy | ||
}) => { | ||
// If element is currently focused on, we would like to let users open it using enter | ||
const handleKeyUp = (key: string) => { | ||
if (key === "Enter") { | ||
onClick(); | ||
} | ||
}; | ||
|
||
if (size !== "small") { | ||
return ( | ||
<Button | ||
label={label} | ||
buttonType="none" | ||
variant="outline" | ||
disabled={false} | ||
collapsible={false} | ||
size="large" | ||
onClick={onClick} | ||
dataCy={dataCy} | ||
ariaDescribedBy={ariaDescribedBy} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<button | ||
className="link-tag text-small-caption material-manifestation-item__find capitalize-all btn-ui" | ||
aria-describedby={ariaDescribedBy} | ||
onClick={onClick} | ||
onKeyUp={(e) => handleKeyUp(e.key)} | ||
tabIndex={0} | ||
type="button" | ||
data-cy={dataCy} | ||
> | ||
{label} | ||
</button> | ||
); | ||
}; | ||
|
||
export default MaterialSecondaryButton; |
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
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