Skip to content

Commit e12dfcb

Browse files
authored
Dashboard: sandbox card first draft (#3959)
* responsive grid - first draft * 220 not 240! * add sandbox card - first draft * make scale smoother
1 parent 0c1f58d commit e12dfcb

File tree

3 files changed

+72
-9
lines changed
  • packages
    • app/src/app/pages/NewDashboard
    • components/src/components/Stats

3 files changed

+72
-9
lines changed
Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,76 @@
11
import React from 'react';
2-
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
3-
import { Element, Link } from '@codesandbox/components';
2+
// import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
3+
import { Stack, Element, Text, Menu, Stats } from '@codesandbox/components';
44
import css from '@styled-system/css';
55

66
export const SandboxCard = ({ sandbox }) => (
7-
<Element
7+
<Stack
8+
direction="vertical"
9+
gap={2}
810
css={css({
911
width: '100%',
1012
height: 240,
1113
border: '1px solid',
1214
borderColor: 'grays.600',
1315
borderRadius: 'medium',
16+
overflow: 'hidden',
17+
transition: 'all ease-in-out',
18+
transitionDuration: theme => theme.speeds[4],
19+
':hover, :focus': {
20+
transform: 'scale(0.98)',
21+
},
1422
})}
1523
>
16-
<Link href={sandboxUrl({ id: sandbox.id, alias: sandbox.alias })}>
17-
{sandbox.title || sandbox.alias || sandbox.id}
18-
</Link>
19-
</Element>
24+
<Element
25+
as="div"
26+
css={{
27+
height: 160,
28+
backgroundImage: `url(https://codesandbox.io/api/v1/sandboxes/${sandbox.id}/screenshot.png)`,
29+
backgroundSize: 'cover',
30+
backgroundPosition: 'center center',
31+
backgroundRepeat: 'no-repeat',
32+
}}
33+
/>
34+
<Stack justify="space-between" align="center" marginLeft={4}>
35+
<Text size={3} weight="medium">
36+
{sandbox.title || sandbox.alias || sandbox.id}
37+
</Text>
38+
<Menu>
39+
<Menu.IconButton name="more" size={9} title="Sandbox options" />
40+
<Menu.List>
41+
<Menu.Item onSelect={() => {}}>Show in Folder</Menu.Item>
42+
<Menu.Item onSelect={() => {}}>Open sandbox</Menu.Item>
43+
<Menu.Item onSelect={() => {}}>Open sandbox in new tab</Menu.Item>
44+
<Menu.Item onSelect={() => {}}>Copy sandbox link</Menu.Item>
45+
<Menu.Item onSelect={() => {}}>Fork sandbox</Menu.Item>
46+
<Menu.Item onSelect={() => {}}>Export sandbox</Menu.Item>
47+
<Menu.Item onSelect={() => {}}>Rename sandbox</Menu.Item>
48+
<Menu.Item onSelect={() => {}}>Make sandbox a template</Menu.Item>
49+
<Menu.Item onSelect={() => {}}>Delete sandbox</Menu.Item>
50+
</Menu.List>
51+
</Menu>
52+
</Stack>
53+
<Stack marginX={4}>
54+
<Stats
55+
css={css({ fontSize: 2 })}
56+
sandbox={{
57+
viewCount: kFormatter(10300),
58+
likeCount: kFormatter(800),
59+
forkCount: kFormatter(25),
60+
}}
61+
/>
62+
</Stack>
63+
</Stack>
2064
);
65+
66+
const kFormatter = (num: number): number | string => {
67+
if (num > 999999) {
68+
return (num / 1000000).toFixed(1) + 'M';
69+
}
70+
71+
if (num > 999) {
72+
return (num / 1000).toFixed(1) + 'K';
73+
}
74+
75+
return num;
76+
};

packages/app/src/app/pages/NewDashboard/Content/routes/StartSandboxes/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,19 @@ export const StartSandboxes = () => {
9292
>
9393
<Column>
9494
<Button
95+
variant="link"
9596
onClick={() => modalOpened({ modal: 'newSandbox' })}
9697
css={css({
9798
height: 240,
99+
fontSize: 3,
98100
border: '1px solid',
99101
borderColor: 'grays.600',
100102
borderRadius: 'medium',
103+
transition: 'all ease-in',
104+
transitionDuration: theme => theme.speeds[2],
105+
':hover, :focus': {
106+
transform: 'scale(0.98)',
107+
},
101108
})}
102109
>
103110
New Sandbox

packages/components/src/components/Stats/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export const formatNumber = (count: number): string | number => {
4040
return count;
4141
};
4242

43-
export const Stats = ({ sandbox }) => (
44-
<Stack gap={4}>
43+
export const Stats = ({ sandbox, ...props }) => (
44+
<Stack gap={4} {...props}>
4545
<Stack gap={1} align="center">
4646
<Text variant="muted" style={{ display: 'flex', alignItems: 'center' }}>
4747
<HeartIcon />

0 commit comments

Comments
 (0)