Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New DS core component: accordion #632

Merged
merged 11 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Not released

- New DS core component: accordion [#632](https://github.com/CartoDB/carto-react/pull/632)
- Storybook documentation and fixes [#629](https://github.com/CartoDB/carto-react/pull/629)
- Note component cleaned styles from makeStyles [#630](https://github.com/CartoDB/carto-react/pull/630)
- OpacityControl component migrated from makeStyles to styled-components + cleanup [#631](https://github.com/CartoDB/carto-react/pull/631)
Expand Down
54 changes: 54 additions & 0 deletions packages/react-ui/src/components/molecules/AccordionGroup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Accordion, AccordionDetails, AccordionSummary } from '@mui/material';
import { styled } from '@mui/material/styles';

const AccordionContainer = styled('div', {
shouldForwardProp: (prop) => prop !== 'variant'
})(({ variant, theme }) => ({
width: '100%',
borderRadius: theme.spacing(0.5),

...(variant === 'outlined' && {
backgroundColor: theme.palette.background.paper,
boxShadow: `inset 0 0 0 1px ${theme.palette.divider}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity.

We've got theme.shadows. Are they of no use here? If not, when they should be used (they are used in extensively in cloud-native)

Copy link
Contributor Author

@vmilan vmilan Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This boxShadow use is custom, to simulate a border indeed... Designers wanted to have this line inside the element itself, and using an inset border didn't work properly.

But yes, we use theme.shadows for common use cases.

})
}));

const AccordionGroup = ({ variant, items, ...otherProps }) => {
return (
<AccordionContainer {...otherProps} variant={variant}>
{items.map((item, index) => (
<Accordion
key={index}
disabled={item.disabled}
defaultExpanded={item.defaultExpanded}
onChange={item.onChange}
>
<AccordionSummary aria-controls={`${index}-content`} id={`${index}-header`}>
{item.summary}
</AccordionSummary>
<AccordionDetails>{item.content}</AccordionDetails>
</Accordion>
))}
</AccordionContainer>
);
};

AccordionGroup.defaultProps = {
variant: 'standard'
};
AccordionGroup.propTypes = {
variant: PropTypes.oneOf(['standard' | 'outlined']),
items: PropTypes.arrayOf(
PropTypes.shape({
summary: PropTypes.string.isRequired,
content: PropTypes.oneOfType([PropTypes.element, PropTypes.string]).isRequired,
disabled: PropTypes.boolean,
defaultExpanded: PropTypes.boolean,
onChange: PropTypes.func
})
).isRequired
};

export default AccordionGroup;
6 changes: 4 additions & 2 deletions packages/react-ui/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import {
ICON_SIZE_SMALL,
ICON_SIZE_MEDIUM,
ICON_SIZE_LARGE
} from './theme/themeconstants';
} from './theme/themeConstants';
import AccordionGroup from './components/molecules/AccordionGroup';

export {
theme,
Expand Down Expand Up @@ -80,5 +81,6 @@ export {
Avatar,
ICON_SIZE_SMALL,
ICON_SIZE_MEDIUM,
ICON_SIZE_LARGE
ICON_SIZE_LARGE,
AccordionGroup
};
4 changes: 3 additions & 1 deletion packages/react-ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
ICON_SIZE_MEDIUM,
ICON_SIZE_LARGE
} from './theme/themeConstants';
import AccordionGroup from './components/molecules/AccordionGroup';

const featureSelectionIcons = {
CursorIcon,
Expand Down Expand Up @@ -87,5 +88,6 @@ export {
Avatar,
ICON_SIZE_SMALL,
ICON_SIZE_MEDIUM,
ICON_SIZE_LARGE
ICON_SIZE_LARGE,
AccordionGroup
};
61 changes: 61 additions & 0 deletions packages/react-ui/src/theme/sections/components/surfaces.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React from 'react';
import { getSpacing } from '../../themeUtils';
import { APPBAR_SIZE } from '../../themeConstants';
import { commonPalette } from '../palette';
import { themeShadows } from '../shadows';
import { ExpandMoreOutlined } from '@mui/icons-material';
import { themeTypography } from '../typography';

export const surfacesOverrides = {
// AppBar
Expand Down Expand Up @@ -34,5 +37,63 @@ export const surfacesOverrides = {
}
}
}
},

// MuiAccordion
MuiAccordion: {
defaultProps: {
disableGutters: true,
elevation: 0
},
styleOverrides: {
root: {
...themeTypography.body2,
backgroundColor: 'transparent',
boxShadow: `inset 0 -1px 0 0 ${commonPalette.divider}`,

'&:last-of-type': {
boxShadow: 'none'
},
'&::before': {
content: 'none'
},
'&.Mui-disabled': {
backgroundColor: 'transparent'
}
}
}
},
// MuiAccordionSummary
MuiAccordionSummary: {
defaultProps: {
expandIcon: <ExpandMoreOutlined />
},
styleOverrides: {
root: {
...themeTypography.button,

'&.Mui-disabled': {
opacity: 1,
color: commonPalette.text.disabled
}
},
expandIconWrapper: {
'& svg': {
color: commonPalette.text.secondary,

'.Mui-disabled &': {
color: commonPalette.text.disabled
}
}
}
}
},
// MuiAccordionDetails
MuiAccordionDetails: {
styleOverrides: {
root: {
paddingBottom: getSpacing(3)
}
}
}
};
14 changes: 14 additions & 0 deletions packages/react-ui/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,17 @@ export type LabelWithIndicatorProps = {
export interface AvatarProps extends MuiAvatarProps {
size?: 'large' | 'medium' | 'small' | 'xsmall';
}

// AccordionGroup
export type AccordionGroupProps = {
variant?: 'standard' | 'outlined';
items: [
{
summary: string;
content: string | React.ReactElement;
disabled?: boolean;
defaultExpanded?: boolean;
onChange?: Function;
}
];
};
Loading