Skip to content

Commit

Permalink
Title bar below image
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrookes committed Sep 4, 2020
1 parent 18b0931 commit 5fe8a48
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 34 deletions.
9 changes: 6 additions & 3 deletions docs/pages/api-docs/image-list-item-bar.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ The `MuiImageListItemBar` name can be used for providing [default props](/custom
| <span class="prop-name">actionIcon</span> | <span class="prop-type">node</span> | | An IconButton element to be used as secondary action target (primary action target is the item itself). |
| <span class="prop-name">actionPosition</span> | <span class="prop-type">'left'<br>&#124;&nbsp;'right'</span> | <span class="prop-default">'right'</span> | Position of secondary action IconButton. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">position</span> | <span class="prop-type">'below'<br>&#124;&nbsp;'bottom'<br>&#124;&nbsp;'top'</span> | <span class="prop-default">'bottom'</span> | Position of the title bar. |
| <span class="prop-name">subtitle</span> | <span class="prop-type">node</span> | | String or element serving as subtitle (support text). |
| <span class="prop-name">title</span> | <span class="prop-type">node</span> | | Title to be displayed on item. |
| <span class="prop-name">titlePosition</span> | <span class="prop-type">'bottom'<br>&#124;&nbsp;'top'</span> | <span class="prop-default">'bottom'</span> | Position of the title bar. |

The `ref` is forwarded to the root element.

Expand All @@ -44,10 +44,13 @@ Any other props supplied will be provided to the root element (native element).
| Rule name | Global class | Description |
|:-----|:-------------|:------------|
| <span class="prop-name">root</span> | <span class="prop-name">.MuiImageListItemBar-root</span> | Styles applied to the root element.
| <span class="prop-name">titlePositionBottom</span> | <span class="prop-name">.MuiImageListItemBar-titlePositionBottom</span> | Styles applied to the root element if `titlePosition="bottom"`.
| <span class="prop-name">titlePositionTop</span> | <span class="prop-name">.MuiImageListItemBar-titlePositionTop</span> | Styles applied to the root element if `titlePosition="top"`.
| <span class="prop-name">rootSubtitle</span> | <span class="prop-name">.MuiImageListItemBar-rootSubtitle</span> | Styles applied to the root element if a `subtitle` is provided.
| <span class="prop-name">positionBottom</span> | <span class="prop-name">.MuiImageListItemBar-positionBottom</span> | Styles applied to the root element if `position="bottom"`.
| <span class="prop-name">positionTop</span> | <span class="prop-name">.MuiImageListItemBar-positionTop</span> | Styles applied to the root element if `position="top"`.
| <span class="prop-name">positionBelow</span> | <span class="prop-name">.MuiImageListItemBar-positionBelow</span> | Styles applied to the root element if `position="below"`.
| <span class="prop-name">positionBelowSubtitle</span> | <span class="prop-name">.MuiImageListItemBar-positionBelowSubtitle</span> | Styles applied to the root element if `position="below"` and a `subtitle` is provided.
| <span class="prop-name">titleWrap</span> | <span class="prop-name">.MuiImageListItemBar-titleWrap</span> | Styles applied to the title and subtitle container element.
| <span class="prop-name">titleWrapBelow</span> | <span class="prop-name">.MuiImageListItemBar-titleWrapBelow</span> | Styles applied to the title and subtitle container element if `position="below"`.
| <span class="prop-name">titleWrapActionPosLeft</span> | <span class="prop-name">.MuiImageListItemBar-titleWrapActionPosLeft</span> | Styles applied to the container element if `actionPosition="left"`.
| <span class="prop-name">titleWrapActionPosRight</span> | <span class="prop-name">.MuiImageListItemBar-titleWrapActionPosRight</span> | Styles applied to the container element if `actionPosition="right"`.
| <span class="prop-name">title</span> | <span class="prop-name">.MuiImageListItemBar-title</span> | Styles applied to the title container element.
Expand Down
1 change: 1 addition & 0 deletions docs/pages/api-docs/image-list-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Any other props supplied will be provided to the root element (native element).
|:-----|:-------------|:------------|
| <span class="prop-name">root</span> | <span class="prop-name">.MuiImageListItem-root</span> | Styles applied to the root element.
| <span class="prop-name">img</span> | <span class="prop-name">.MuiImageListItem-img</span> | Styles applied to an `img` element to ensure it covers the item.
| <span class="prop-name">standard</span> | <span class="prop-name">.MuiImageListItem-standard</span> | Styles applied to the root element if `variant="standard"`.
| <span class="prop-name">woven</span> | <span class="prop-name">.MuiImageListItem-woven</span> | Styles applied to the root element if `variant="woven"`.

You can override the style of the component thanks to one of these customization points:
Expand Down
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
7 changes: 6 additions & 1 deletion docs/src/pages/components/image-list/QuiltedImageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export default function QuiltedImageList() {
const classes = useStyles();

return (
<ImageList cols={4} rowHeight={121} className={classes.root}>
<ImageList
variant="quilted"
cols={4}
rowHeight={121}
className={classes.root}
>
{itemData.map((item) => (
<ImageListItem
key={item.img}
Expand Down
7 changes: 6 additions & 1 deletion docs/src/pages/components/image-list/QuiltedImageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export default function QuiltedImageList() {
const classes = useStyles();

return (
<ImageList cols={4} rowHeight={121} className={classes.root}>
<ImageList
variant="quilted"
cols={4}
rowHeight={121}
className={classes.root}
>
{itemData.map((item) => (
<ImageListItem
key={item.img}
Expand Down
50 changes: 50 additions & 0 deletions docs/src/pages/components/image-list/TitlebarBelowImageList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 './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>}
position="below"
/>
</ImageListItem>
))}
</ImageList>
);
}
50 changes: 50 additions & 0 deletions docs/src/pages/components/image-list/TitlebarBelowImageList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 './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>}
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
10 changes: 10 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,16 @@ The overlay can accommodate a `title`, `subtitle` and secondary action - in this

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

### Title bar below image (Standard)

The title bar can be placed below the image.

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

### Title bar below image (Masonry)

{{"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
13 changes: 12 additions & 1 deletion packages/material-ui/src/ImageListItem/ImageListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@ import ImageListContext from '../ImageList/ImageListContext';
export const styles = {
/* Styles applied to the root element. */
root: {
display: 'inline-block',
position: 'relative',
lineHeight: 0,
lineHeight: 0, // Fix masonry item spacing
},
/* Styles applied to an `img` element to ensure it covers the item. */
img: {
objectFit: 'cover',
width: '100%',
height: '100%',
},
/* Styles applied to the root element if `variant="standard"`. */
standard: {
// For titlebar under list item
display: 'flex',
flexDirection: 'column',
'& $img': {
height: 'auto',
flexGrow: 1,
},
},
/* Styles applied to the root element if `variant="woven"`. */
woven: {
height: '100%',
Expand Down
22 changes: 14 additions & 8 deletions packages/material-ui/src/ImageListItemBar/ImageListItemBar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ 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 a `subtitle` is provided. */
rootSubtitle?: 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 `position="below"`. */
positionBelow?: string;
/** Styles applied to the root element if `position="below"` and a `subtitle` is provided. */
positionBelowSubtitle?: string;
/** Styles applied to the title and subtitle container element. */
titleWrap?: string;
/** Styles applied to the title and subtitle container element if `position="below"`. */
titleWrapBelow?: string;
/** Styles applied to the container element if `actionPosition="left"`. */
titleWrapActionPosLeft?: string;
/** Styles applied to the container element if `actionPosition="right"`. */
Expand All @@ -39,6 +45,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 +57,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 5fe8a48

Please sign in to comment.