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

128 lines
3.4 KiB
TypeScript
Raw Normal View History

import React, { useState, useEffect, useRef } from "react";
import styled from "styled-components";
import AppIcon, { AppIconName, AppIconCollection } from "./AppIcon";
import { Size } from "./Button";
import { CommonComponentProps, Classes } from "./common";
import ScrollIndicator from "./ScrollIndicator";
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;
2020-12-24 04:32:25 +00:00
padding: ${(props) => props.theme.spaces[4]}px 0px
${(props) => props.theme.spaces[4]}px ${(props) => props.theme.spaces[5]}px;
width: ${(props) => (props.fill ? "100%" : "234px")};
max-height: 90px;
overflow-y: auto;
&&::-webkit-scrollbar-thumb {
2020-12-24 04:32:25 +00:00
background-color: ${(props) => props.theme.colors.modal.scrollbar};
}
&::-webkit-scrollbar {
width: 4px;
}
`;
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;
2020-12-24 04:32:25 +00:00
background-color: ${(props) =>
props.selectedColor || props.theme.colors.appIcon.background};
2020-12-24 04:32:25 +00:00
margin: 0 ${(props) => props.theme.spaces[2]}px
${(props) => props.theme.spaces[2]}px 0;
position: relative;
&:nth-child(6n) {
2020-12-24 04:32:25 +00:00
margin-right: ${(props) => props.theme.spaces[0]}px;
}
2020-12-24 04:32:25 +00:00
${(props) =>
props.selectedColor
? `.${Classes.APP_ICON} {
svg {
path {
fill: #fff;
}
}
}`
: null};
`;
const IconSelector = (props: IconSelectorProps) => {
const iconRef = useRef<HTMLDivElement>(null);
const [selected, setSelected] = useState<AppIconName>(firstSelectedIcon());
const iconPaletteRef = React.createRef<HTMLDivElement>();
useEffect(() => {
if (props.selectedIcon && iconRef.current) {
setSelected(props.selectedIcon);
}
}, [props.selectedIcon]);
useEffect(() => {
if (selected && iconRef.current) {
setTimeout(() => {
if (iconRef.current)
iconRef.current.scrollIntoView({ behavior: "smooth" });
}, 0);
}
}, []);
function firstSelectedIcon() {
if (props.iconPalette && props.iconPalette[0]) {
return props.iconPalette[0];
}
return AppIconCollection[0];
}
return (
<IconPalette
fill={props.fill}
data-cy={props.cypressSelector}
ref={iconPaletteRef}
>
{props.iconPalette &&
props.iconPalette.map((iconName: AppIconName, index: number) => {
return (
<IconBox
{...(selected === iconName ? { ref: iconRef } : {})}
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 : ""}
className={
selected === iconName
? "t--icon-selected"
: "t--icon-not-selected"
}
onClick={() => {
if (iconName !== selected) {
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>
);
})}
<ScrollIndicator containerRef={iconPaletteRef} mode="DARK" />
</IconPalette>
);
};
IconSelector.defaultProps = {
fill: false,
iconPalette: AppIconCollection,
};
export default IconSelector;