Skip to content

Commit

Permalink
Add Label to Searchbar and improve Menu component (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhubaibQaiser authored Aug 2, 2022
1 parent 6c5c99e commit c8ffa35
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gudangada/design-system",
"version": "0.1.29",
"version": "0.1.30",
"description": "Gada Design System",
"main": "lib/index.js",
"module": "lib/index.esm.js",
Expand Down
1 change: 1 addition & 0 deletions src/components/core/Searchbar/Searchbar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Template: Story<iSearchbarProps> = (props) => {
return (
<SearchbarUI
{...props}
label="Search label"
value={value}
onChangeValue={handleChange}
onClickCancel={handleReset}
Expand Down
56 changes: 31 additions & 25 deletions src/components/core/Searchbar/Searchbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Box, FormControl, IconButton, InputAdornment } from "@mui/material";
import * as React from "react";
import { CrossCircleIcon, SearchIcon } from "../../../assets";
import { Label } from "../../inputs";
import { Col } from "../Col";
import { StyledOutlinedInput } from "./styles";
import { iSearchbarProps } from "./types";

Expand All @@ -11,6 +13,7 @@ const Searchbar: React.VFC<iSearchbarProps> = (props) => {
onClickCancel,
onChangeValue,
size = "default",
label,
...rest
} = props;

Expand All @@ -24,32 +27,35 @@ const Searchbar: React.VFC<iSearchbarProps> = (props) => {
};

return (
<FormControl variant="outlined" {...formControlProps}>
<StyledOutlinedInput
{...rest}
size={size === "default" ? undefined : "small"}
onChange={(event) => onChangeValue(event.target.value)}
startAdornment={
<InputAdornment position="start">
<SearchIcon />
</InputAdornment>
}
inputRef={inputRef}
endAdornment={
withEndAdornment && (
<InputAdornment position="end" style={{ paddingRight: 0 }}>
{props.value ? (
<IconButton onClick={handleClickCancel}>
<CrossCircleIcon />
</IconButton>
) : (
<Box width={48} />
)}
<Col spacing={8}>
{label && <Label>{label}</Label>}
<FormControl variant="outlined" {...formControlProps}>
<StyledOutlinedInput
{...rest}
size={size === "default" ? undefined : "small"}
onChange={(event) => onChangeValue(event.target.value)}
startAdornment={
<InputAdornment position="start">
<SearchIcon />
</InputAdornment>
)
}
/>
</FormControl>
}
inputRef={inputRef}
endAdornment={
withEndAdornment && (
<InputAdornment position="end" style={{ paddingRight: 0 }}>
{props.value ? (
<IconButton onClick={handleClickCancel}>
<CrossCircleIcon />
</IconButton>
) : (
<Box width={48} />
)}
</InputAdornment>
)
}
/>
</FormControl>
</Col>
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/AutoComplete/styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from "@emotion/styled";
import { outlinedInputClasses } from "@mui/material";
import { Col } from "../../core";
import { Col } from "../../core/Col";

export const StyledAutoCompleteContainer = styled(Col)<{ isError?: boolean }>(
({ theme: { palette }, isError }) => ({
Expand Down
13 changes: 9 additions & 4 deletions src/components/navigation/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Menu as MuiMenu } from "@mui/material";
import { iMenuProps } from "./types";
import MenuItem from "./MenuItem";

const Menu: React.VFC<iMenuProps> = ({
const Menu: React.FC<iMenuProps> = ({
menuItems,
children,
handleClose,
...menuProps
}) => {
Expand All @@ -18,12 +19,16 @@ const Menu: React.VFC<iMenuProps> = ({
vertical: "top",
horizontal: "center",
}}
BackdropProps={{ style: { backgroundColor: "rgba(0,0,0,0.001)" } }}
PaperProps={{ elevation: 1 }}
{...menuProps}
onClose={handleClose}
>
{menuItems.map((menuItem) => {
return <MenuItem key={menuItem.label} {...menuItem} />;
})}
{menuItems
? menuItems.map((menuItem) => {
return <MenuItem key={menuItem.label} {...menuItem} />;
})
: children}
</MuiMenu>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/navigation/Menu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export interface iMenuItemProps {
}

export interface iMenuProps extends MenuProps {
menuItems: iMenuItemProps[];
menuItems?: iMenuItemProps[];
handleClose: VoidFunction;
}

0 comments on commit c8ffa35

Please sign in to comment.