|
1 | 1 | import React from 'react'; |
2 | | -import { Link as RouterLink } from 'react-router-dom'; |
3 | | -import { Stack, Link, Text, Input } from '@codesandbox/components'; |
| 2 | +import { Stack, Text, Input } from '@codesandbox/components'; |
4 | 3 | import css from '@styled-system/css'; |
5 | 4 | import { MenuOptions } from './Menu'; |
6 | 5 |
|
7 | 6 | export const FolderCard = ({ |
8 | 7 | name, |
9 | 8 | path, |
10 | 9 | numberOfSandboxes, |
| 10 | + // interactions |
| 11 | + selected, |
| 12 | + onClick, |
| 13 | + onDoubleClick, |
11 | 14 | // editing |
12 | 15 | editing, |
13 | 16 | enterEditing, |
14 | 17 | isNewFolder, |
15 | 18 | newName, |
16 | 19 | inputRef, |
17 | 20 | onChange, |
18 | | - onKeyDown, |
| 21 | + onInputKeyDown, |
19 | 22 | onSubmit, |
20 | | - onBlur, |
| 23 | + onInputBlur, |
21 | 24 | // drop target |
22 | 25 | showDropStyles, |
23 | 26 | // drag preview |
24 | 27 | thumbnailRef, |
25 | 28 | opacity, |
26 | | - // menu conflict |
27 | | - onClick, |
28 | 29 | ...props |
29 | 30 | }) => ( |
30 | | - <Link |
31 | | - as={RouterLink} |
32 | | - to={`/new-dashboard/all` + path} |
| 31 | + <Stack |
| 32 | + direction="vertical" |
| 33 | + gap={2} |
33 | 34 | onClick={onClick} |
| 35 | + onDoubleClick={onDoubleClick} |
34 | 36 | {...props} |
| 37 | + css={css({ |
| 38 | + width: '100%', |
| 39 | + height: 240, |
| 40 | + backgroundColor: 'grays.700', |
| 41 | + border: '1px solid', |
| 42 | + borderRadius: 'medium', |
| 43 | + overflow: 'hidden', |
| 44 | + transition: 'all ease-in-out', |
| 45 | + transitionDuration: theme => theme.speeds[4], |
| 46 | + // drop target |
| 47 | + borderColor: getBorderColor(selected, showDropStyles), |
| 48 | + boxShadow: theme => |
| 49 | + showDropStyles ? '0 4px 16px 0 ' + theme.colors.grays[900] : null, |
| 50 | + |
| 51 | + // drag state, |
| 52 | + opacity, |
| 53 | + |
| 54 | + ':hover, :focus, :focus-within': { |
| 55 | + cursor: editing ? 'normal' : 'pointer', |
| 56 | + boxShadow: theme => '0 4px 16px 0 ' + theme.colors.grays[900], |
| 57 | + }, |
| 58 | + })} |
35 | 59 | > |
36 | 60 | <Stack |
37 | | - direction="vertical" |
38 | | - gap={2} |
| 61 | + as="div" |
| 62 | + justify="center" |
| 63 | + align="center" |
| 64 | + ref={thumbnailRef} |
39 | 65 | css={css({ |
40 | | - width: '100%', |
41 | | - height: 240, |
42 | | - backgroundColor: 'grays.700', |
43 | | - border: '1px solid', |
44 | | - borderRadius: 'medium', |
45 | | - overflow: 'hidden', |
46 | | - transition: 'all ease-in-out', |
47 | | - transitionDuration: theme => theme.speeds[4], |
48 | | - // drop target |
49 | | - borderColor: showDropStyles ? 'grays.400' : 'grays.500', |
50 | | - boxShadow: theme => |
51 | | - showDropStyles ? '0 4px 16px 0 ' + theme.colors.grays[900] : null, |
52 | | - |
53 | | - // drag state, |
54 | | - opacity, |
55 | | - |
56 | | - ':hover, :focus, :focus-within': { |
57 | | - cursor: editing ? 'normal' : 'pointer', |
58 | | - boxShadow: theme => '0 4px 16px 0 ' + theme.colors.grays[900], |
59 | | - }, |
| 66 | + height: 160, |
| 67 | + borderStyle: 'solid', |
| 68 | + borderWidth: 0, |
| 69 | + borderBottomWidth: 1, |
| 70 | + borderColor: 'grays.500', |
| 71 | + backgroundColor: 'grays.600', |
60 | 72 | })} |
61 | 73 | > |
62 | | - <Stack |
63 | | - as="div" |
64 | | - justify="center" |
65 | | - align="center" |
66 | | - ref={thumbnailRef} |
67 | | - css={css({ |
68 | | - height: 160, |
69 | | - borderStyle: 'solid', |
70 | | - borderWidth: 0, |
71 | | - borderBottomWidth: 1, |
72 | | - borderColor: 'grays.500', |
73 | | - backgroundColor: 'grays.600', |
74 | | - })} |
75 | | - > |
76 | | - <svg width={56} height={49} fill="none" viewBox="0 0 56 49"> |
77 | | - <path |
78 | | - fill="#6CC7F6" |
79 | | - d="M20.721 0H1.591A1.59 1.59 0 000 1.59v45.82C0 48.287.712 49 1.59 49h52.82A1.59 1.59 0 0056 47.41V7.607a1.59 1.59 0 00-1.59-1.59H28L21.788.41A1.59 1.59 0 0020.72 0z" |
| 74 | + <svg width={56} height={49} fill="none" viewBox="0 0 56 49"> |
| 75 | + <path |
| 76 | + fill="#6CC7F6" |
| 77 | + d="M20.721 0H1.591A1.59 1.59 0 000 1.59v45.82C0 48.287.712 49 1.59 49h52.82A1.59 1.59 0 0056 47.41V7.607a1.59 1.59 0 00-1.59-1.59H28L21.788.41A1.59 1.59 0 0020.72 0z" |
| 78 | + /> |
| 79 | + </svg> |
| 80 | + </Stack> |
| 81 | + <Stack justify="space-between" align="center" marginLeft={4}> |
| 82 | + {editing ? ( |
| 83 | + <form onSubmit={onSubmit}> |
| 84 | + <Input |
| 85 | + value={newName} |
| 86 | + ref={inputRef} |
| 87 | + onChange={onChange} |
| 88 | + onKeyDown={onInputKeyDown} |
| 89 | + onBlur={onInputBlur} |
80 | 90 | /> |
81 | | - </svg> |
82 | | - </Stack> |
83 | | - <Stack justify="space-between" align="center" marginLeft={4}> |
84 | | - {editing ? ( |
85 | | - <form onSubmit={onSubmit}> |
86 | | - <Input |
87 | | - value={newName} |
88 | | - ref={inputRef} |
89 | | - onChange={onChange} |
90 | | - onKeyDown={onKeyDown} |
91 | | - onBlur={onBlur} |
92 | | - /> |
93 | | - </form> |
94 | | - ) : ( |
95 | | - <Text size={3} weight="medium"> |
96 | | - {name} |
97 | | - </Text> |
98 | | - )} |
99 | | - {!isNewFolder ? ( |
100 | | - <MenuOptions path={path} onRename={enterEditing} /> |
101 | | - ) : null} |
102 | | - </Stack> |
| 91 | + </form> |
| 92 | + ) : ( |
| 93 | + <Text size={3} weight="medium"> |
| 94 | + {name} |
| 95 | + </Text> |
| 96 | + )} |
103 | 97 | {!isNewFolder ? ( |
104 | | - <Stack marginLeft={4}> |
105 | | - <Text size={3} block variant="muted"> |
106 | | - {numberOfSandboxes || 0}{' '} |
107 | | - {numberOfSandboxes === 1 ? 'sandbox' : 'sandboxes'} |
108 | | - </Text> |
109 | | - </Stack> |
| 98 | + <MenuOptions path={path} onRename={enterEditing} /> |
110 | 99 | ) : null} |
111 | 100 | </Stack> |
112 | | - </Link> |
| 101 | + {!isNewFolder ? ( |
| 102 | + <Stack marginLeft={4}> |
| 103 | + <Text size={3} block variant="muted"> |
| 104 | + {numberOfSandboxes || 0}{' '} |
| 105 | + {numberOfSandboxes === 1 ? 'sandbox' : 'sandboxes'} |
| 106 | + </Text> |
| 107 | + </Stack> |
| 108 | + ) : null} |
| 109 | + </Stack> |
113 | 110 | ); |
| 111 | + |
| 112 | +const getBorderColor = (selected, showDropStyles) => { |
| 113 | + if (selected) return 'blues.600'; |
| 114 | + if (showDropStyles) return 'grays.400'; |
| 115 | + return 'grays.500'; |
| 116 | +}; |
0 commit comments