generalize img card

Signed-off-by: Ky <virginie.ky@gmail.com>
This commit is contained in:
Ky 2020-03-10 00:27:18 +01:00
parent e1e85ab452
commit 762cb6bba6
10 changed files with 51 additions and 21 deletions

View File

@ -0,0 +1,23 @@
import styled from 'styled-components';
import PropTypes from 'prop-types';
const Border = styled.div`
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
display: none;
border: 2px solid #007eff;
${({ checked }) => checked && 'display: block;'}
`;
Border.defaultProps = {
checked: false,
};
Border.propTypes = {
checked: PropTypes.bool,
};
export default Border;

View File

@ -6,8 +6,8 @@ import CardImgWrapper from '../CardImgWrapper';
import CardPreview from '../CardPreview'; import CardPreview from '../CardPreview';
import Wrapper from './Wrapper'; import Wrapper from './Wrapper';
import Title from './Title'; import Title from './Title';
import Border from './Border';
// TODO - adapt with the real data
const Card = ({ const Card = ({
checked, checked,
children, children,
@ -15,7 +15,6 @@ const Card = ({
hasError, hasError,
mime, mime,
name, name,
onChange,
small, small,
size, size,
type, type,
@ -26,6 +25,7 @@ const Card = ({
<div> <div>
<CardImgWrapper small={small} checked={checked} hasError={hasError}> <CardImgWrapper small={small} checked={checked} hasError={hasError}>
<CardPreview type={mime || type} url={url} /> <CardPreview type={mime || type} url={url} />
<Border checked={checked} />
{children} {children}
</CardImgWrapper> </CardImgWrapper>
<Title fontSize="md" fontWeight="bold" ellipsis> <Title fontSize="md" fontWeight="bold" ellipsis>
@ -41,9 +41,10 @@ const Card = ({
Card.defaultProps = { Card.defaultProps = {
checked: false, checked: false,
children: null, children: null,
errorMessage: null,
hasError: false, hasError: false,
mime: null,
name: null, name: null,
onChange: () => {},
size: 0, size: 0,
small: false, small: false,
type: null, type: null,
@ -53,9 +54,10 @@ Card.defaultProps = {
Card.propTypes = { Card.propTypes = {
checked: PropTypes.bool, checked: PropTypes.bool,
children: PropTypes.node, children: PropTypes.node,
errorMessage: PropTypes.string,
hasError: PropTypes.bool, hasError: PropTypes.bool,
mime: PropTypes.string,
name: PropTypes.string, name: PropTypes.string,
onChange: PropTypes.func,
size: PropTypes.number, size: PropTypes.number,
small: PropTypes.bool, small: PropTypes.bool,
type: PropTypes.string, type: PropTypes.string,

View File

@ -8,8 +8,7 @@ const Wrapper = styled.div`
align-items: center; align-items: center;
width: 24px; width: 24px;
height: 24px; height: 24px;
margin-left: auto; margin-left: 5px;
margin-right: 5px;
background-color: ${({ theme }) => theme.main.colors.white}; background-color: ${({ theme }) => theme.main.colors.white};
border: 1px solid #e3e9f3; border: 1px solid #e3e9f3;
border-radius: ${({ theme }) => theme.main.sizes.borderRadius}; border-radius: ${({ theme }) => theme.main.sizes.borderRadius};

View File

@ -1,10 +1,22 @@
import styled from 'styled-components'; import styled from 'styled-components';
import PropTypes from 'prop-types';
const CardControlsWrapper = styled.div` const CardControlsWrapper = styled.div`
position: absolute;
top: 10px;
right: 5px;
display: flex; display: flex;
position: absolute;
top: 0;
${({ leftAlign }) => (leftAlign ? 'left: 0;' : 'right: 0;')};
width: fit-content;
height: auto;
margin: 10px;
`; `;
CardControlsWrapper.defaultProps = {
leftAlign: false,
};
CardControlsWrapper.propTypes = {
leftAlign: PropTypes.bool,
};
export default CardControlsWrapper; export default CardControlsWrapper;

View File

@ -12,12 +12,6 @@ const CardImgWrapper = styled.div`
.card-control-wrapper { .card-control-wrapper {
display: none; display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding: 10px;
} }
&:hover { &:hover {
@ -44,7 +38,6 @@ const CardImgWrapper = styled.div`
.card-control-wrapper { .card-control-wrapper {
display: flex; display: flex;
z-index: 1050; z-index: 1050;
border: 2px solid #007EFF;
} }
`} `}
`; `;

View File

@ -9,6 +9,9 @@ const FileWrapper = styled(CardImgWrapper)`
width: 100%; width: 100%;
object-fit: contain; object-fit: contain;
margin: auto; margin: auto;
position: absolute;
top: 0;
left: 0;
} }
.cropper-view-box { .cropper-view-box {

View File

@ -1,5 +1,4 @@
import styled from 'styled-components'; import styled from 'styled-components';
import { themePropTypes } from 'strapi-helper-plugin';
const Container = styled.div` const Container = styled.div`
width: 44%; width: 44%;

View File

@ -5,6 +5,7 @@ import { Checkbox } from '@buffetjs/core';
import createMatrix from '../../utils/createMatrix'; import createMatrix from '../../utils/createMatrix';
import Card from '../Card'; import Card from '../Card';
import CardControlsWrapper from '../CardControlsWrapper';
import Wrapper from './Wrapper'; import Wrapper from './Wrapper';
const List = ({ data, onChange, selectedItems }) => { const List = ({ data, onChange, selectedItems }) => {
@ -22,9 +23,9 @@ const List = ({ data, onChange, selectedItems }) => {
return ( return (
<div className="col-xs-12 col-md-6 col-xl-3" key={JSON.stringify(item)}> <div className="col-xs-12 col-md-6 col-xl-3" key={JSON.stringify(item)}>
<Card small checked={checked} {...item} url={`${strapi.backendURL}${url}`}> <Card small checked={checked} {...item} url={`${strapi.backendURL}${url}`}>
<div className="card-control-wrapper"> <CardControlsWrapper leftAlign className="card-control-wrapper">
<Checkbox name={`${id}`} onChange={onChange} value={checked} /> <Checkbox name={`${id}`} onChange={onChange} value={checked} />
</div> </CardControlsWrapper>
</Card> </Card>
</div> </div>
); );

View File

@ -4,7 +4,6 @@ import PropTypes from 'prop-types';
import Card from '../Card'; import Card from '../Card';
import CardControl from '../CardControl'; import CardControl from '../CardControl';
import CardControlsWrapper from '../CardControlsWrapper'; import CardControlsWrapper from '../CardControlsWrapper';
import CardImgWrapper from '../CardImgWrapper';
import InfiniteLoadingIndicator from '../InfiniteLoadingIndicator'; import InfiniteLoadingIndicator from '../InfiniteLoadingIndicator';
const RowItem = ({ const RowItem = ({

View File

@ -1,6 +1,5 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { Button } from '@buffetjs/core'; import { Button } from '@buffetjs/core';
import createMatrix from '../../utils/createMatrix'; import createMatrix from '../../utils/createMatrix';
import getTrad from '../../utils/getTrad'; import getTrad from '../../utils/getTrad';