PromucFlow_constructor/app/client/src/components/ads/IconSelector.tsx

84 lines
2.2 KiB
TypeScript
Raw Normal View History

import React, { useState, useEffect } from "react";
import styled from "styled-components";
import AppIcon, { AppIconName, AppIconCollection } from "./AppIcon";
import { Size } from "./Button";
import { CommonComponentProps } from "./common";
type IconSelectorProps = CommonComponentProps & {
onSelect?: (icon: AppIconName) => void;
selectedColor: string;
selectedIcon?: AppIconName;
iconPalette?: AppIconName[];
fill?: boolean;
};
const IconPalette = styled.div<{ fill?: boolean }>`
display: flex;
align-items: center;
flex-wrap: wrap;
padding: ${props => props.theme.spaces[4]}px
${props => props.theme.spaces[5]}px;
width: ${props => (props.fill ? "100%" : "234px")};
`;
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
const IconBox = styled.div<{ selectedColor?: string }>`
width: 30px;
height: 30px;
display: flex;
justify-content: center;
align-items: center;
background-color: ${props =>
props.selectedColor || props.theme.colors.blackShades[2]};
margin: 0 ${props => props.theme.spaces[2]}px
${props => props.theme.spaces[2]}px 0;
position: relative;
&:nth-child(6n) {
margin-right: ${props => props.theme.spaces[0]}px;
}
`;
const IconSelector = (props: IconSelectorProps) => {
function firstSelectedIcon() {
if (props.iconPalette && props.iconPalette[0]) {
return props.iconPalette[0];
}
return AppIconCollection[0];
}
const [selected, setSelected] = useState<AppIconName>(firstSelectedIcon());
useEffect(() => {
if (props.selectedIcon) {
setSelected(props.selectedIcon);
}
}, [props.selectedIcon]);
return (
<IconPalette fill={props.fill} data-cy={props.cypressSelector}>
{props.iconPalette &&
props.iconPalette.map((iconName: AppIconName, index: number) => {
return (
<IconBox
key={index}
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
selectedColor={selected === iconName ? props.selectedColor : ""}
onClick={() => {
setSelected(iconName);
props.onSelect && props.onSelect(iconName);
}}
>
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
<AppIcon name={iconName} size={Size.small} />
</IconBox>
);
})}
</IconPalette>
);
};
IconSelector.defaultProps = {
fill: false,
iconPalette: AppIconCollection,
};
export default IconSelector;