Skip to content

Commit f99047c

Browse files
MichaelDeBoeySaraVieira
authored andcommitted
🔨 Switch Icon to use useOvermind (codesandbox#2564)
1 parent de4fa91 commit f99047c

File tree

1 file changed

+71
-69
lines changed
  • packages/app/src/app/pages/Sandbox/Editor/Workspace/Project/SandboxConfig/Icon

1 file changed

+71
-69
lines changed
Lines changed: 71 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { inject, hooksObserver } from 'app/componentConnectors';
2-
import React, { useState } from 'react';
3-
import { usePopoverState } from 'reakit/Popover';
41
import * as templates from '@codesandbox/common/lib/templates';
5-
import * as Icons from '@codesandbox/template-icons';
62
import getIcon from '@codesandbox/common/lib/templates/icons';
3+
import * as Icons from '@codesandbox/template-icons';
4+
import React, { FunctionComponent, useState } from 'react';
5+
import { usePopoverState } from 'reakit/Popover';
6+
7+
import { useOvermind } from 'app/overmind';
78

89
import { Item, PropertyName } from '../../elements';
910
import {
@@ -15,74 +16,75 @@ import {
1516
Arrow,
1617
} from './elements';
1718

18-
export const Icon = inject('store', 'signals')(
19-
hooksObserver(
20-
({
21-
signals: {
22-
workspace: { editTemplate },
19+
export const Icon: FunctionComponent = () => {
20+
const {
21+
actions: {
22+
workspace: { editTemplate },
23+
},
24+
state: {
25+
editor: {
26+
currentSandbox: { customTemplate, template },
2327
},
24-
store: {
25-
editor: {
26-
currentSandbox: { template, customTemplate },
27-
},
28+
},
29+
} = useOvermind();
30+
const popover = usePopoverState();
31+
32+
const [selectedIcon, setSelectedIcon] = useState(customTemplate.iconUrl);
33+
34+
const DefaultIcon = getIcon(template);
35+
const defaultColor =
36+
(customTemplate && customTemplate.color) ||
37+
templates.default(template).color();
38+
39+
const setIcon = (key: string) => {
40+
setSelectedIcon(key);
41+
popover.hide();
42+
editTemplate({
43+
template: {
44+
...customTemplate,
45+
iconUrl: key,
2846
},
29-
}) => {
30-
const popover = usePopoverState();
47+
});
48+
};
49+
const TemplateIcon = Icons[selectedIcon];
50+
51+
return (
52+
<Item>
53+
<PropertyName>Icon </PropertyName>
3154

32-
const [selectedIcon, setSelectedIcon] = useState(customTemplate.iconUrl);
55+
<Value>
56+
<Button {...popover} color={defaultColor}>
57+
{selectedIcon && TemplateIcon ? (
58+
<TemplateIcon width={24} />
59+
) : (
60+
<DefaultIcon width={24} />
61+
)}
62+
</Button>
3363

34-
const DefaultIcon = getIcon(template);
35-
const defaultColor =
36-
(customTemplate && customTemplate.color) ||
37-
templates.default(template).color();
64+
<IconWrapper
65+
hideOnEsc
66+
hideOnClickOutside
67+
{...popover}
68+
aria-label="Choose an Icon"
69+
>
70+
<Arrow {...popover} />
3871

39-
const setIcon = (key: string) => {
40-
setSelectedIcon(key);
41-
popover.hide();
42-
editTemplate({
43-
template: {
44-
...customTemplate,
45-
iconUrl: key,
46-
},
47-
});
48-
};
49-
const TemplateIcon = Icons[selectedIcon];
72+
<List>
73+
{Object.keys(Icons).map((i: string) => {
74+
const TemplateIconMap = Icons[i];
5075

51-
return (
52-
<Item>
53-
<PropertyName>Icon </PropertyName>
54-
<Value>
55-
<Button {...popover} color={defaultColor}>
56-
{selectedIcon && TemplateIcon ? (
57-
<TemplateIcon width={24} />
58-
) : (
59-
<DefaultIcon width={24} />
60-
)}
61-
</Button>
62-
<IconWrapper
63-
hideOnEsc
64-
hideOnClickOutside
65-
{...popover}
66-
aria-label="Choose an Icon"
67-
>
68-
<Arrow {...popover} />
69-
<List>
70-
{Object.keys(Icons).map((i: string) => {
71-
const TemplateIconMap = Icons[i];
72-
return (
73-
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role
74-
<li role="button" tabIndex={0} onClick={() => setIcon(i)}>
75-
<IconButton>
76-
<TemplateIconMap width={24} />
77-
</IconButton>
78-
</li>
79-
);
80-
})}
81-
</List>
82-
</IconWrapper>
83-
</Value>
84-
</Item>
85-
);
86-
}
87-
)
88-
);
76+
return (
77+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role
78+
<li role="button" tabIndex={0} onClick={() => setIcon(i)}>
79+
<IconButton>
80+
<TemplateIconMap width={24} />
81+
</IconButton>
82+
</li>
83+
);
84+
})}
85+
</List>
86+
</IconWrapper>
87+
</Value>
88+
</Item>
89+
);
90+
};

0 commit comments

Comments
 (0)