Skip to content

Commit

Permalink
WIP title bar below image
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrookes committed Sep 2, 2020
1 parent 18b0931 commit 1dc8c64
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/src/pages/components/image-list/CustomImageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function AdvancedImageList() {
<img src={item.img} alt={item.title} />
<ImageListItemBar
title={item.title}
titlePosition="top"
position="top"
actionIcon={
<IconButton
aria-label={`star ${item.title}`}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/image-list/CustomImageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function AdvancedImageList() {
<img src={item.img} alt={item.title} />
<ImageListItemBar
title={item.title}
titlePosition="top"
position="top"
actionIcon={
<IconButton
aria-label={`star ${item.title}`}
Expand Down
60 changes: 60 additions & 0 deletions docs/src/pages/components/image-list/TitlebarBelowImageList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import ImageList from '@material-ui/core/ImageList';
import ImageListItem from '@material-ui/core/ImageListItem';
import ImageListItemBar from '@material-ui/core/ImageListItemBar';
import IconButton from '@material-ui/core/IconButton';
import InfoIcon from '@material-ui/icons/Info';
import itemData from './itemData';

const useStyles = makeStyles({
root: {
width: 500,
height: 450,
},
icon: {
color: 'rgba(255, 255, 255, 0.54)',
},
});

/**
* The example data is structured as follows:
*
* import image from 'path/to/image.jpg';
* [etc...]
*
* const itemData = [
* {
* img: 'image-path',
* title: 'text',
* author: 'name',
* },
* { etc... },
* ];
*/
export default function TitlebarBelowImageList() {
const classes = useStyles();

return (
<ImageList className={classes.root}>
{itemData.map((item) => (
<ImageListItem key={item.img}>
<img src={item.img} alt={item.title} />
<ImageListItemBar
title={item.title}
subtitle={<span>by: {item.author}</span>}
actionIcon={
<IconButton
aria-label={`info about ${item.title}`}
className={classes.icon}
>
<InfoIcon />
</IconButton>
}
position="below"
/>
</ImageListItem>
))}
</ImageList>
);
}
60 changes: 60 additions & 0 deletions docs/src/pages/components/image-list/TitlebarBelowImageList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import ImageList from '@material-ui/core/ImageList';
import ImageListItem from '@material-ui/core/ImageListItem';
import ImageListItemBar from '@material-ui/core/ImageListItemBar';
import IconButton from '@material-ui/core/IconButton';
import InfoIcon from '@material-ui/icons/Info';
import itemData from './itemData';

const useStyles = makeStyles({
root: {
width: 500,
height: 450,
},
icon: {
color: 'rgba(255, 255, 255, 0.54)',
},
});

/**
* The example data is structured as follows:
*
* import image from 'path/to/image.jpg';
* [etc...]
*
* const itemData = [
* {
* img: 'image-path',
* title: 'text',
* author: 'name',
* },
* { etc... },
* ];
*/
export default function TitlebarBelowImageList() {
const classes = useStyles();

return (
<ImageList className={classes.root}>
{itemData.map((item) => (
<ImageListItem key={item.img}>
<img src={item.img} alt={item.title} />
<ImageListItemBar
title={item.title}
subtitle={<span>by: {item.author}</span>}
actionIcon={
<IconButton
aria-label={`info about ${item.title}`}
className={classes.icon}
>
<InfoIcon />
</IconButton>
}
position="below"
/>
</ImageListItem>
))}
</ImageList>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import ImageList from '@material-ui/core/ImageList';
import ImageListItem from '@material-ui/core/ImageListItem';
import ImageListItemBar from '@material-ui/core/ImageListItemBar';
import itemData from './peerItemData';

const useStyles = makeStyles({
root: {
width: 500,
height: 450,
overflowY: 'scroll',
},
});

/**
* The example data is structured as follows:
*
* const itemData = [
* {
* img: 'image-path',
* title: 'text',
* author: 'name'
* },
* { etc... },
* ];
*
*/
export default function TitlebarBelowMasonryImageList() {
const classes = useStyles();

return (
<div className={classes.root}>
<ImageList variant="masonry" cols={3} spacing={8}>
{itemData.map((item) => (
<ImageListItem key={item.img}>
<img src={item.img} alt={item.title} />
<ImageListItemBar position="below" title={item.author} />
</ImageListItem>
))}
</ImageList>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import ImageList from '@material-ui/core/ImageList';
import ImageListItem from '@material-ui/core/ImageListItem';
import ImageListItemBar from '@material-ui/core/ImageListItemBar';
import itemData from './peerItemData';

const useStyles = makeStyles({
root: {
width: 500,
height: 450,
overflowY: 'scroll',
},
});

/**
* The example data is structured as follows:
*
* const itemData = [
* {
* img: 'image-path',
* title: 'text',
* author: 'name'
* },
* { etc... },
* ];
*
*/
export default function TitlebarBelowMasonryImageList() {
const classes = useStyles();

return (
<div className={classes.root}>
<ImageList variant="masonry" cols={3} spacing={8}>
{itemData.map((item) => (
<ImageListItem key={item.img}>
<img src={item.img} alt={item.title} />
<ImageListItemBar position="below" title={item.author} />
</ImageListItem>
))}
</ImageList>
</div>
);
}
2 changes: 0 additions & 2 deletions docs/src/pages/components/image-list/TitlebarImageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const useStyles = makeStyles({
* img: 'image-path',
* title: 'text',
* author: 'name',
* rows: 2,
* cols: 2,
* },
* { etc... },
* ];
Expand Down
2 changes: 0 additions & 2 deletions docs/src/pages/components/image-list/TitlebarImageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const useStyles = makeStyles({
* img: 'image-path',
* title: 'text',
* author: 'name',
* rows: 2,
* cols: 2,
* },
* { etc... },
* ];
Expand Down
6 changes: 6 additions & 0 deletions docs/src/pages/components/image-list/image-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ The overlay can accommodate a `title`, `subtitle` and secondary action - in this

{{"demo": "pages/components/image-list/TitlebarImageList.js", "hideEditButton": true}}

The title bar can be placed below the image.

{{"demo": "pages/components/image-list/TitlebarBelowImageList.js", "hideEditButton": true}}

{{"demo": "pages/components/image-list/TitlebarBelowMasonryImageList.js", "hideEditButton": true}}

## Custom image list

In this example the items have a customized titlebar, positioned at the top and with a custom gradient `titleBackground`.
Expand Down
4 changes: 3 additions & 1 deletion packages/material-ui/src/ImageListItem/ImageListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export const styles = {
/* Styles applied to the root element. */
root: {
position: 'relative',
lineHeight: 0,
lineHeight: 0, // Fix masonry item spacing
// display: 'flex',
// flexDirection: 'column',
},
/* Styles applied to an `img` element to ensure it covers the item. */
img: {
Expand Down
16 changes: 8 additions & 8 deletions packages/material-ui/src/ImageListItemBar/ImageListItemBar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export interface ImageListItemBarProps
classes?: {
/** Styles applied to the root element. */
root?: string;
/** Styles applied to the root element if `titlePosition="bottom"`. */
titlePositionBottom?: string;
/** Styles applied to the root element if `titlePosition="top"`. */
titlePositionTop?: string;
/** Styles applied to the root element if `position="bottom"`. */
positionBottom?: string;
/** Styles applied to the root element if `position="top"`. */
positionTop?: string;
/** Styles applied to the root element if a `subtitle` is provided. */
rootSubtitle?: string;
/** Styles applied to the title and subtitle container element. */
Expand All @@ -39,6 +39,10 @@ export interface ImageListItemBarProps
/** Styles applied to the actionIcon if `actionPosition="left"`. */
actionIconActionPosLeft?: string;
};
/**
* Position of the title bar.
*/
position?: 'below' | 'top' | 'bottom';
/**
* String or element serving as subtitle (support text).
*/
Expand All @@ -47,10 +51,6 @@ export interface ImageListItemBarProps
* Title to be displayed on item.
*/
title?: React.ReactNode;
/**
* Position of the title bar.
*/
titlePosition?: 'top' | 'bottom';
}

export type ImageListItemBarClassKey = keyof NonNullable<ImageListItemBarProps['classes']>;
Expand Down
Loading

0 comments on commit 1dc8c64

Please sign in to comment.