Skip to content

Commit

Permalink
Merge branch 'layer5io:master' into redux/middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhsharma1997 authored Aug 14, 2024
2 parents 28a1e06 + 52bfc6f commit 229e4e3
Show file tree
Hide file tree
Showing 23 changed files with 310 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useTheme } from '@mui/material';
import React from 'react';
import { Box } from '../../base/Box';
import { Card } from '../../base/Card';
Expand Down Expand Up @@ -30,6 +31,7 @@ export function CustomColumnVisibilityControl({
}: CustomColumnVisibilityControlProps): JSX.Element {
const [open, setOpen] = React.useState(false);
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const theme = useTheme();

const handleOpen = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
Expand All @@ -54,7 +56,7 @@ export function CustomColumnVisibilityControl({
<TooltipIcon
title="View Columns"
onClick={handleOpen}
icon={<ColumnIcon fill="#3c494f" />}
icon={<ColumnIcon fill={theme.palette.icon.default} />}
arrow
/>
<PopperListener
Expand Down Expand Up @@ -87,7 +89,7 @@ export function CustomColumnVisibilityControl({
flexDirection: 'column',
padding: '1rem',
boxShadow: open ? '0px 4px 8px rgba(0, 0, 0, 0.2)' : 'none',
background: '#f4f5f7'
background: theme.palette.background.surfaces
}}
>
{columns.map((col) => (
Expand Down
3 changes: 2 additions & 1 deletion src/custom/CustomImage/CustomImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ const CustomImage: React.FC<ImageComponentProps> = ({ src, alt, ...props }) => {
background: 'transparent',
boxShadow: 'none',
overflow: 'auto',
maxWidth: '60rem'
maxWidth: '100%'
}
}}
>
<img
src={src}
alt={alt}
onClick={handleZoomClose}
style={{
objectFit: 'contain',
maxWidth: '100%',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ColView, updateVisibleColumns } from './responsive-column';

export { updateVisibleColumns };
export type { ColView };
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// colViews screen size reference
/*
na: Not visible at any screen width
xs: width < 585,
s: width > 585 && width < 690,
m: width > 690 && width < 775,
l: width > 775 && width < 915,
xl: width > 915 && width < 1140
All columns except "na" are visible for width > 1140
*/

export interface ColView {
0: string; // column name
1: 'na' | 'xs' | 's' | 'm' | 'l' | 'xl'; // screen size
}

export const updateVisibleColumns = (
colViews: ColView[],
width: number
): Record<string, boolean> => {
// showCols object contains key value pairs that represent whether a column is visible or hidden.
// i.e, Here, key = column name, and value = true/false where true means visible and false means hidden
const showCols: Record<string, boolean> = {};

// colViews is a 2D array where each element is an array of 2 elements namely,
// column name and the screen size till which they are visible
colViews.forEach((col) => {
// Hide the columns for any screen size
if (col[1] === 'na') {
showCols[col[0]] = false;
} else if (width > 1140) {
// Display all columns above width 1140
showCols[col[0]] = true;
} else if (width >= 915 && width < 1140) {
if (['xs', 's', 'm', 'l', 'xl'].includes(col[1])) {
showCols[col[0]] = true;
} else {
showCols[col[0]] = false;
}
} else if (width >= 775 && width < 915) {
if (['xs', 's', 'm', 'l'].includes(col[1])) {
showCols[col[0]] = true;
} else {
showCols[col[0]] = false;
}
} else if (width >= 690 && width < 775) {
if (['xs', 's', 'm'].includes(col[1])) {
showCols[col[0]] = true;
} else {
showCols[col[0]] = false;
}
} else if (width >= 585 && width < 690) {
if (['xs', 's'].includes(col[1])) {
showCols[col[0]] = true;
} else {
showCols[col[0]] = false;
}
} else if (width < 585) {
if (col[1] === 'xs') {
showCols[col[0]] = true;
} else {
showCols[col[0]] = false;
}
}
});

return showCols;
};
4 changes: 3 additions & 1 deletion src/custom/Markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
StyledMarkdownH6,
StyledMarkdownLi,
StyledMarkdownP,
StyledMarkdownPre,
StyledMarkdownTd,
StyledMarkdownTh,
StyledMarkdownTooltipP,
Expand Down Expand Up @@ -51,7 +52,8 @@ export const RenderMarkdown: React.FC<RenderMarkdownProps> = ({ content }) => {
ul: ({ ...props }) => <StyledMarkdownUl>{props.children}</StyledMarkdownUl>,
li: ({ ...props }) => <StyledMarkdownLi>{props.children}</StyledMarkdownLi>,
th: ({ ...props }) => <StyledMarkdownTh>{props.children}</StyledMarkdownTh>,
td: ({ ...props }) => <StyledMarkdownTd>{props.children}</StyledMarkdownTd>
td: ({ ...props }) => <StyledMarkdownTd>{props.children}</StyledMarkdownTd>,
pre: ({ ...props }) => <StyledMarkdownPre>{props.children}</StyledMarkdownPre>
}}
>
{content}
Expand Down
7 changes: 6 additions & 1 deletion src/custom/Markdown/style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { styled } from '@mui/material';
import { text } from '../../theme/colors/colors';

export const StyledMarkdown = styled('a')(({ theme }) => ({
color: theme.palette.text.brand,
color: theme.palette.background.brand?.default,
textDecoration: 'none',
'&:hover': {
textDecoration: 'underline'
Expand Down Expand Up @@ -71,3 +71,8 @@ export const StyledMarkdownTd = styled('td')(({ theme }) => ({
marginBlock: '0px',
...theme.typography.textB1Regular
}));

export const StyledMarkdownPre = styled('pre')(({ theme }) => ({
background: theme.palette.background.code,
whiteSpace: 'pre-line'
}));
117 changes: 115 additions & 2 deletions src/custom/ResponsiveDataTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,96 @@
import { Theme, ThemeProvider, createTheme } from '@mui/material';
import { Theme, ThemeProvider, createTheme, styled } from '@mui/material';
import MUIDataTable from 'mui-datatables';
import React, { useCallback } from 'react';
import { Checkbox, Collapse, ListItemIcon, ListItemText, Menu, MenuItem } from '../base';
import { ShareIcon } from '../icons';
import { EllipsisIcon } from '../icons/Ellipsis';
import TooltipIcon from './TooltipIcon';

export const IconWrapper = styled('div')<{ disabled?: boolean }>(({ disabled = false }) => ({
cursor: disabled ? 'not-allowed' : 'pointer',
opacity: disabled ? '0.5' : '1',
display: 'flex',
'& svg': {
cursor: disabled ? 'not-allowed' : 'pointer'
}
}));

export const DataTableEllipsisMenu: React.FC<{
actionsList: NonNullable<Column['options']>['actionsList'];
}> = ({ actionsList }) => {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const [isSocialShareOpen, setIsSocialShareOpen] = React.useState(false);

const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
setIsSocialShareOpen(false);
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleActionClick = (action: any) => {
if (action.type === 'share-social') {
setIsSocialShareOpen(!isSocialShareOpen);
} else {
if (action.onClick) {
action.onClick();
}
handleClose();
}
};

return (
<>
<TooltipIcon title="View Actions" onClick={handleClick} icon={<EllipsisIcon />} arrow />
<Menu id="basic-menu" anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={handleClose}>
{actionsList &&
actionsList.map((action, index) => (
<React.Fragment key={index}>
{action.type === 'share-social' ? (
<>
<MenuItem
sx={{
width: '-webkit-fill-available'
// background: theme.palette.background.surfaces
}}
onClick={() => handleActionClick(action)}
disabled={action.disabled}
>
<ListItemIcon>
<ShareIcon width={24} height={24} />
</ListItemIcon>
<ListItemText>{action.title}</ListItemText>
</MenuItem>
<Collapse variant="submenu" in={isSocialShareOpen} unmountOnExit>
{action.customComponent}
</Collapse>
</>
) : (
<>
<IconWrapper key={index} disabled={action.disabled}>
<MenuItem
sx={{
width: '-webkit-fill-available'
// background: theme.palette.background.surfaces
}}
key={index}
onClick={() => handleActionClick(action)}
disabled={action.disabled}
>
<ListItemIcon>{action.icon}</ListItemIcon>
<ListItemText>{action.title}</ListItemText>
</MenuItem>
</IconWrapper>
</>
)}
</React.Fragment>
))}
</Menu>
</>
);
};

const dataTableTheme = (theme: Theme) =>
createTheme({
Expand Down Expand Up @@ -115,6 +205,15 @@ const dataTableTheme = (theme: Theme) =>
}
}
}
},
MuiTableRow: {
styleOverrides: {
root: {
'&.Mui-disabled': {
cursor: 'not-allowed'
}
}
}
}
}
});
Expand All @@ -129,6 +228,14 @@ export interface Column {
display?: boolean;
sortDescFirst?: boolean;
customBodyRender?: (value: string | number | boolean | object) => JSX.Element;
actionsList?: {
title: string;
icon: JSX.Element;
onClick: () => void;
disabled?: boolean;
customComponent?: JSX.Element;
type?: string;
}[];
};
}

Expand Down Expand Up @@ -167,6 +274,11 @@ const ResponsiveDataTable = ({

const updatedOptions = {
...options,
print: false,
download: false,
search: false,
filter: false,
viewColumns: false,
rowsPerPageOptions: rowsPerPageOptions,
onViewColumnsChange: (column: string, action: string) => {
switch (action) {
Expand Down Expand Up @@ -244,7 +356,8 @@ const ResponsiveDataTable = ({
}, [updateColumnsEffect]);

const components = {
ExpandButton: () => ''
ExpandButton: () => '',
Checkbox: Checkbox
};

return (
Expand Down
16 changes: 7 additions & 9 deletions src/custom/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const customTheme = (theme: Theme) =>
MuiTextField: {
styleOverrides: {
root: {
'--TextField-brandBorderColor': 'rgba(0, 0, 0, 0.5)',
'--TextField-brandBorderColor': theme.palette.border.strong,
'--TextField-brandBorderHoverColor': theme.palette.background.graphics?.default,
'--TextField-brandBorderFocusedColor': theme.palette.background.graphics?.default,
'& label.Mui-focused': {
Expand All @@ -39,6 +39,7 @@ const customTheme = (theme: Theme) =>
MuiInput: {
styleOverrides: {
root: {
color: theme.palette.text.default,
'&::before': {
borderBottom: '2px solid var(--TextField-brandBorderColor)'
},
Expand All @@ -61,21 +62,18 @@ export interface SearchBarProps {
onClear?: () => void;
expanded: boolean;
setExpanded: (expanded: boolean) => void;
iconFill?: string;
}

function SearchBar({
onSearch,
placeholder,
onClear,
expanded,
setExpanded,
iconFill
setExpanded
}: SearchBarProps): JSX.Element {
const [searchText, setSearchText] = React.useState('');
const searchRef = React.useRef<HTMLInputElement | null>(null);

const outerTheme = useTheme();
const theme = useTheme();

const handleSearchChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
setSearchText(event.target.value);
Expand Down Expand Up @@ -123,7 +121,7 @@ function SearchBar({
}}
>
<div>
<ThemeProvider theme={customTheme(outerTheme)}>
<ThemeProvider theme={customTheme(theme)}>
<TextField
variant="standard"
value={searchText}
Expand All @@ -144,14 +142,14 @@ function SearchBar({
<TooltipIcon
title="Close"
onClick={handleClearIconClick}
icon={<CloseIcon fill={iconFill} />}
icon={<CloseIcon fill={theme.palette.icon.default} />}
arrow
/>
) : (
<TooltipIcon
title="Search"
onClick={handleSearchIconClick}
icon={<SearchIcon fill={iconFill} />}
icon={<SearchIcon fill={theme.palette.icon.default} />}
arrow
/>
)}
Expand Down
6 changes: 6 additions & 0 deletions src/custom/SetupPrerequisite/style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ const Card = styled('a')(({ theme }) => ({
borderRadius: '10px',
'&:hover': {
boxShadow: 'rgb(0, 211, 169) 0px 0px 7px'
},
'& a': {
margin: '0 !important',
'&:hover': {
color: theme.palette.background.brand?.default
}
}
}));

Expand Down
Loading

0 comments on commit 229e4e3

Please sign in to comment.