Skip to content

Commit

Permalink
feat(app-board): improve cards scale on panel
Browse files Browse the repository at this point in the history
  • Loading branch information
rams23 committed Jan 18, 2021
1 parent c5a907b commit 2533af7
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ const AnimatedGrid: React.FC<Props> = ({
);

const parseChildren = useCallback(() => {
const elementsPerRow = calculateItemsPerRow(itemWidth, margin, containerWidth);
let elementsPerRow = calculateItemsPerRow(itemWidth, margin, containerWidth);
if (elementsPerRow < 1) {
elementsPerRow = 1;
}
const newMargin = margin;
return Children.map(children, (child, index) => {
const { row, col } = calculateItemPosition(index, elementsPerRow);
Expand Down
24 changes: 16 additions & 8 deletions packages/game-app/src/_shared/components/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import styled from 'styled-components';
import styled, { css } from 'styled-components';
import { Card, CardTags, CardTypes } from '@pipeline/common';
import React from 'react';

type CardProps = Card & { headerTitle?: string; readOnly?: boolean; imgURL?: string; dragging?: boolean };
import { PANEL_CARD_SCALE } from '../../../dimensions';

type CardProps = Card & {
headerTitle?: string;
readOnly?: boolean;
imgURL?: string;
dragging?: boolean;
bigger?: boolean;
};

interface CardHeaderProps {
type: CardTypes;
Expand Down Expand Up @@ -30,19 +37,19 @@ const tagObj = {
},
} as { [key in CardTags]: { backgroundColor: string } };

const CardWrapper = styled.div<{ dragging?: boolean }>`
const CardWrapper = styled.div<{ dragging?: boolean; bigger?: boolean }>`
padding: 0 0 16px;
width: 280px;
height: 200px;
border-radius: 10px;
background: #f9f9f9;
box-sizing: border-box;
${props => (props.bigger ? `transform:scale(${PANEL_CARD_SCALE});transform-origin:0 0;` : '')}
${props =>
props.dragging
? `
transform: rotate(6deg);
transform: rotate(6deg) ${props.bigger && `scale(${PANEL_CARD_SCALE})`};
box-shadow: 0px 80px 20px #10182026;
`
: `
Expand Down Expand Up @@ -104,7 +111,7 @@ const CardBodySubTitle = styled.h3`
`;

const CardContent = styled.div`
font-size: 10px;
font-size: 8px;
margin-top: 8px;
`;

Expand All @@ -117,10 +124,11 @@ const CardComponent: React.FC<CardProps> = ({
readOnly = true,
tags,
dragging,
bigger,
...other
}) => {
return (
<CardWrapper dragging={dragging}>
<CardWrapper dragging={dragging} bigger={bigger}>
<CardHeader type={type}>
<CardHeading>{type}</CardHeading>
<CardHeadingTags>
Expand Down
10 changes: 10 additions & 0 deletions packages/game-app/src/dimensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const DEFAULT_CARD_SIZE = { width: 280, height: 200 };

export const PANEL_CARD_SCALE = 1.5 / window.devicePixelRatio;
export const PANEL_CARD_SIZE = {
width: DEFAULT_CARD_SIZE.width * PANEL_CARD_SCALE,
height: DEFAULT_CARD_SIZE.height * PANEL_CARD_SCALE,
};

export const PANEL_TWO_COLUMNS_WIDTH = PANEL_CARD_SIZE.width * 2 + 16 + 40 * 2;
export const PANEL_ONE_COLUMNS_WIDTH = PANEL_CARD_SIZE.width + 40 * 2;
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ const CardsGameListeners: React.FC<Props> = ({ onEvent, children, currentGameSta
{children}
{createPortal(
<DragOverlay adjustScale dropAnimation={null} modifiers={modifiers} className="transform-0">
{draggingCardId ? <ConnectedCard dragging={true} id={draggingCardId} /> : null}
{draggingCardId ? <ConnectedCard bigger dragging={true} id={draggingCardId} /> : null}
</DragOverlay>,
document.body,
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { Card } from '@pipeline/components';
type Props = {
id: string;
dragging?: boolean;
bigger?: boolean;
};

const ConnectedCard: React.FC<Props> = ({ id, dragging }) => {
const ConnectedCard: React.FC<Props> = ({ id, dragging, bigger }) => {
const cardData = useSelector(selectors.getCardById(id))!;

return <Card {...cardData} dragging={dragging} />;
return <Card {...cardData} dragging={dragging} bigger={bigger} />;
};

ConnectedCard.displayName = 'ConnectedCard';
Expand Down
21 changes: 16 additions & 5 deletions packages/game-app/src/gameView/components/DeckPanel/DeckPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { useState } from 'react';
import DraggableCard from '../DraggableCard';
import styled from 'styled-components';
import styled, { css } from 'styled-components';
import { IconButton, AnimatedGrid } from '@pipeline/components';
import { ReactComponent as StackedIcon } from '@assets/icons/stacked-cards.svg';
import DroppablePanelArea from '../DroppablePanelArea';
import { PANEL_CARD_SIZE, PANEL_ONE_COLUMNS_WIDTH, PANEL_TWO_COLUMNS_WIDTH } from '../../../dimensions';
import { CardWrapper } from '../DraggableCard/DraggableCard';

export type PanelMode = 'stacked' | 'tow-columns';

Expand All @@ -15,6 +17,15 @@ const DeckPanelContent = styled.div<{ mode: PanelMode }>`
::-webkit-scrollbar {
display: none;
}
${props =>
props.mode === 'stacked'
? css`
${CardWrapper}:hover {
transform: translate(0, -100px);
}
`
: ''}
`;

const PanelButtons = styled.div`
Expand Down Expand Up @@ -47,16 +58,16 @@ const DeckPanel: React.FC<Props> = ({ cardsIds }) => {
</PanelButtons>
<DeckPanelContent mode={panelMode}>
<AnimatedGrid
itemWidth={280}
itemHeight={200}
itemWidth={PANEL_CARD_SIZE.width}
itemHeight={PANEL_CARD_SIZE.height}
margin={16}
marginVertical={panelMode === 'tow-columns' ? 16 : -90}
containerWidth={panelMode === 'tow-columns' ? 576 : 360}
containerWidth={panelMode === 'tow-columns' ? PANEL_TWO_COLUMNS_WIDTH - 80 : PANEL_ONE_COLUMNS_WIDTH - 80}
transitionTime="400ms"
transitionTimingFunction="ease-in-out"
>
{cardsIds.map(id => (
<DraggableCard key={id} id={id} />
<DraggableCard bigger key={id} id={id} />
))}
</AnimatedGrid>
</DeckPanelContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ConnectedCard from '../ConnectedCard';

type Props = {
id: string;
bigger?: boolean;
};

export const CardWrapper = styled.div`
Expand All @@ -17,7 +18,7 @@ export const CardWrapper = styled.div`
/**
* A card enhanced with dragging capability
*/
const DraggableCard: React.FC<Props> = ({ id }) => {
const DraggableCard: React.FC<Props> = ({ id, bigger }) => {
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
id,
});
Expand All @@ -41,7 +42,7 @@ const DraggableCard: React.FC<Props> = ({ id }) => {
{...attributes}
className={`${isDragging ? 'dragging' : ''}`}
>
<ConnectedCard id={id} />
<ConnectedCard bigger={bigger} id={id} />
</CardWrapper>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useCallback, useState } from 'react';
import { useDroppable } from '@dnd-kit/core';
import styled from 'styled-components';
import { PanelMode } from '../DeckPanel/DeckPanel';
import { PANEL_ONE_COLUMNS_WIDTH, PANEL_TWO_COLUMNS_WIDTH } from '../../../dimensions';

type Props = {
mode: PanelMode;
Expand All @@ -23,9 +24,10 @@ const FixedPanel = styled.div<{ closed: boolean; mode: PanelMode }>`
transition: transform 0.5s, width 0.5s;
${props =>
props.closed ? `transform: translate(${props.mode === 'stacked' ? 300 : 594}px);` : 'transform: translate(0);'}
${props => (props.mode === 'stacked' ? 'width: 360px;' : 'width: 656px;')}
props.closed
? `transform: translate(${props.mode === 'stacked' ? 300 : 594}px);`
: 'transform: translate(0);'} ${props =>
props.mode === 'stacked' ? `width: ${PANEL_ONE_COLUMNS_WIDTH}px;` : `width: ${PANEL_TWO_COLUMNS_WIDTH}px;`}
`;

const ToggleWrapper = styled.div`
Expand Down

0 comments on commit 2533af7

Please sign in to comment.