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

111 lines
2.6 KiB
TypeScript
Raw Normal View History

2020-08-14 04:58:03 +00:00
import styled from "styled-components";
import { ThemeProp, Classes, CommonComponentProps } from "./common";
import { Theme } from "constants/DefaultTheme";
import { TypographyKeys } from "../../constants/typography";
2020-08-14 04:58:03 +00:00
export enum TextType {
P1 = "p1",
P2 = "p2",
P3 = "p3",
H1 = "h1",
H2 = "h2",
H3 = "h3",
H4 = "h4",
H5 = "h5",
H6 = "h6",
SIDE_HEAD = "sideHeading",
2020-08-14 04:58:03 +00:00
}
export enum Case {
UPPERCASE = "uppercase",
LOWERCASE = "lowercase",
CAPITALIZE = "capitalize",
}
export enum FontWeight {
BOLD = "bold",
NORMAL = "normal",
}
export type TextProps = CommonComponentProps & {
2020-08-14 04:58:03 +00:00
type: TextType;
underline?: boolean;
italic?: boolean;
case?: Case;
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
className?: string;
weight?: FontWeight | string;
highlight?: boolean;
textAlign?: string;
2021-10-20 07:38:17 +00:00
color?: string;
};
2020-08-14 04:58:03 +00:00
const typeSelector = (props: TextProps & ThemeProp): string => {
let color = "";
switch (props.type) {
case TextType.P1:
color = props.theme.colors.text.normal;
2020-08-14 04:58:03 +00:00
break;
case TextType.P2:
color = props.theme.colors.text.normal;
2020-08-14 04:58:03 +00:00
break;
case TextType.P3:
color = props.theme.colors.text.normal;
2020-08-14 04:58:03 +00:00
break;
default:
color = props.theme.colors.text.heading;
2020-08-14 04:58:03 +00:00
break;
}
return color;
};
const getFontWeight = ({
theme,
type,
weight,
}: {
theme: Theme;
weight: string | undefined;
type: TypographyKeys;
}) => {
if (weight) {
switch (weight) {
case FontWeight.BOLD:
return theme.fontWeights[2];
case FontWeight.NORMAL:
return "normal";
default:
return weight;
}
} else {
return theme.typography[type].fontWeight;
}
};
const Text = styled.span.attrs((props: TextProps) => ({
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
className: props.className ? props.className + Classes.TEXT : Classes.TEXT,
"data-cy": props.cypressSelector,
}))<TextProps>`
2020-12-24 04:32:25 +00:00
text-decoration: ${(props) => (props.underline ? "underline" : "unset")};
font-style: ${(props) => (props.italic ? "italic" : "normal")};
font-weight: ${(props) =>
getFontWeight({
theme: props.theme,
type: props.type,
weight: props.weight,
})};
2020-12-24 04:32:25 +00:00
font-size: ${(props) => props.theme.typography[props.type].fontSize}px;
line-height: ${(props) => props.theme.typography[props.type].lineHeight}px;
letter-spacing: ${(props) =>
2020-08-14 04:58:03 +00:00
props.theme.typography[props.type].letterSpacing}px;
2020-12-24 04:32:25 +00:00
color: ${(props) =>
2021-10-20 07:38:17 +00:00
props.highlight
? props.theme.colors.text.highlight
: props.color
? props.color
: typeSelector(props)};
2020-12-24 04:32:25 +00:00
text-transform: ${(props) => (props.case ? props.case : "none")};
text-align: ${(props) => (props.textAlign ? props.textAlign : "normal")};
2020-08-14 04:58:03 +00:00
`;
export default Text;