Skip to content

[IMP] Save/restore iconify name #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const App = () => {
const [iconSpec, setIconSpec] = useState({
version: VERSIONS[VERSIONS.length -1],
iconPath: null,
iconIconifyName: null,
color: DEFAULT_COLORS[Math.floor(Math.random()*DEFAULT_COLORS.length)],
size: 65,
});
Expand All @@ -44,6 +45,7 @@ const App = () => {
size: specs.iconSize * 100,
color: specs.backgroundColor,
iconPath: specs.iconPathData,
iconNameSanitized: specs.iconIconifyName,
}
setIconSpec(iconSpec => {return {...iconSpec, ...newSpecs}})
} else {
Expand All @@ -54,8 +56,8 @@ const App = () => {
reader.readAsText(file);
}, []);

const onChangeIconPicker = useCallback(iconPath => {
setIconSpec(iconSpec => {return {...iconSpec, iconPath}});
const onChangeIconPicker = useCallback(iconDetails => {
setIconSpec(iconSpec => {return {...iconSpec, ...iconDetails}});
}, []);

const {getRootProps} = useDropzone({
Expand All @@ -65,10 +67,11 @@ const App = () => {
})

useEffect(() => {
const {version, iconPath, color, size} = iconSpec;
const {version, iconPath, name, color, size} = iconSpec;
setLoading(true);
setIcon(new OdooIcons[version]({
iconPathData: iconPath,
iconIconifyName: name,
backgroundColor: color,
iconSize: size / 100,
}));
Expand Down
4 changes: 2 additions & 2 deletions src/components/IconifyIconPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Iconify from '@iconify/iconify'
const DEFAULT_ICON_NAME = "mdi:home";


const IconifyIconPicker = ({name, required, placeholder, defaultValue, onChange}) => {
const IconifyIconPicker = ({ name, required, placeholder, defaultValue, onChange }) => {

const [iconName, setIconName] = useState(defaultValue || DEFAULT_ICON_NAME);

Expand All @@ -27,7 +27,7 @@ const IconifyIconPicker = ({name, required, placeholder, defaultValue, onChange}
}
const iconSVG = Iconify.renderSVG(iconNameSanitized).outerHTML;
const iconPath = getCombinedPathFromSvg(iconSVG);
onChange && onChange(iconPath);
onChange && onChange({ iconPath: iconPath, name: iconNameSanitized });
})();
}, [iconName, onChange]);

Expand Down
1 change: 1 addition & 0 deletions src/icon/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class AbstractIcon {
iconSize: 1,
iconColor: "#000000",
iconPathData: "",
iconIconifyName: "",
}
}
get iconPathData() {
Expand Down