Skip to content

Commit

Permalink
fix/buttonStyle (#56)
Browse files Browse the repository at this point in the history
* fix: button given default nowrap style

* feat: save multiselect button given a compact mode

---------

Co-authored-by: Timur Bazhirov <timur@exabyte.io>
  • Loading branch information
seankwarren and timurbazhirov authored Jan 3, 2024
1 parent 4e57545 commit 63cb72a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
21 changes: 13 additions & 8 deletions src/mui/components/button/ButtonMultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* Usage:
* To use this component, define an array of ButtonConfig objects, each representing a button's configuration.
* Pass this array along with a localStorage key (for saving the selected button's state) to the component.
* Optionally, you can also specify the size of the buttons (see https://mui.com/material-ui/react-button/#sizes).
*
* Example:
* ```
Expand All @@ -20,6 +19,8 @@
* ]}
* localStorageKey="myButtonSelectKey"
* size="medium"
* isLoading={false}
* isCompact={true}
* />
* ```
*/
Expand All @@ -46,6 +47,7 @@ type ButtonMultiSelectProps = {
size?: "small" | "medium" | "large";
localStorageKey: string;
isLoading?: boolean;
isCompact?: boolean;
};

function ButtonMultiSelect({
Expand All @@ -54,6 +56,7 @@ function ButtonMultiSelect({
size = "small",
localStorageKey,
isLoading = false,
isCompact = false,
}: ButtonMultiSelectProps) {
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
const [selectedOption, setSelectedOption] = useState<ButtonConfig>(buttonConfigs[0]);
Expand Down Expand Up @@ -87,20 +90,22 @@ function ButtonMultiSelect({

return (
<>
<ButtonGroup
variant="contained"
size={size}
aria-label="outlined primary button group"
sx={{ height: "fit-content" }}>
<ButtonGroup variant="contained" size={size} sx={{ height: "fit-content" }}>
<LoadingButton
id={id}
ref={mainButtonRef}
size={size}
onClick={selectedOption.onClick}
variant="contained"
loading={isLoading}
startIcon={<IconByName name={selectedOption.iconName} fontSize={size} />}>
{selectedOption.label}
startIcon={
!isCompact && <IconByName name={selectedOption.iconName} fontSize={size} />
}>
{isCompact ? (
<IconByName name={selectedOption.iconName} fontSize={size} />
) : (
selectedOption.label
)}
</LoadingButton>
<Button onClick={handleExpandClick} size={size}>
<IconByName name="shapes.arrow.dropdown" fontSize={size} />
Expand Down
7 changes: 6 additions & 1 deletion src/theme/components/buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { Theme } from "@mui/material/styles";

const buttons = (theme: Theme) => {
const config = {
styleOverrides: {
root: {
// b/c of https://github.com/material-components/material-components-web/issues/4894
whiteSpace: "nowrap",
},
},
variants: [
{
props: { size: "large" },
Expand All @@ -28,7 +34,6 @@ const buttons = (theme: Theme) => {
color: theme.palette.primary.main,
boxShadow: theme.shadows[2],
padding: "8px 22px",

"&:hover": {
backgroundColor: "rgba(16,86,190,0.2)",
},
Expand Down

0 comments on commit 63cb72a

Please sign in to comment.