Skip to content

Commit

Permalink
DCOS-57982: component for rendering badges in a text input (#401)
Browse files Browse the repository at this point in the history
DCOS-57982: component for rendering badges in a text input

Co-authored-by: Georgi Todorov <[email protected]>
  • Loading branch information
Daniel Schmidt and GeorgiSTodorov authored Sep 17, 2019
2 parents 6f831d7 + dbf141b commit 6c78795
Show file tree
Hide file tree
Showing 18 changed files with 2,256 additions and 80 deletions.
16 changes: 9 additions & 7 deletions packages/badge/components/badge.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import * as React from "react";
import { badge } from "../style";

export type BadgeAppearance =
| "default"
| "success"
| "primary"
| "warning"
| "danger"
| "outline";

export interface BadgeProps {
appearance?:
| "default"
| "success"
| "primary"
| "warning"
| "danger"
| "outline";
appearance?: BadgeAppearance;
children: JSX.Element | string;
}

Expand Down
1 change: 1 addition & 0 deletions packages/badge/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import getCSSVarValue from "../utilities/components/getCSSVarValue";

const badgeAppearanceStyle = (color, isOutlined?: boolean) => {
const bgColor = isOutlined ? getCSSVarValue(themeBgPrimary) : color;

return css`
background-color: ${bgColor};
border-color: ${color};
Expand Down
11 changes: 9 additions & 2 deletions packages/selectInput/components/SelectInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { select, selectIcon, selectContainer } from "../style";
import {
inputContainer,
getInputAppearanceStyle,
getLabelStyle
getLabelStyle,
getIconAppearanceStyle
} from "../../shared/styles/formStyles";
import {
inputReset,
Expand Down Expand Up @@ -158,7 +159,13 @@ class SelectInput extends React.PureComponent<
/* tslint:enable */
))}
</select>
<span className={cx(selectIcon, padding("horiz", "m"))}>
<span
className={cx(
selectIcon,
padding("horiz", "m"),
getIconAppearanceStyle(this.getInputAppearance())
)}
>
<Icon
shape={SystemIcons.TriangleDown}
size={iconSizeXs}
Expand Down
81 changes: 56 additions & 25 deletions packages/shared/styles/formStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const getFocusFieldBg = color => hexToRgbA(color, 0.05);

const toggleInputHeight = 16;
const toggleInputBorderWidth = 1;
export const textInputHeight = 36;

export const toggleInput = css`
border-color: ${themeBorder};
Expand Down Expand Up @@ -70,36 +71,79 @@ export const toggleInputApperances = {
`
};

export const getInputAppearanceStyle = appearance => {
export const getIconAppearanceStyle = appearance => {
switch (appearance) {
case "standard":
return css`
background-color: ${themeBgPrimary};
border-color: ${themeBorder};
svg {
fill: ${themeTextColorPrimary};
}
`;
case "disabled":
return css`
svg {
fill: ${themeTextColorDisabled};
}
`;
case "error":
return css`
svg {
fill: ${themeError};
}
`;
case "success":
return css`
svg {
fill: ${themeSuccess};
}
`;
case "standard-focus":
return css`
svg {
fill: ${themeBrandPrimary};
}
`;
case "error-focus":
return css`
svg {
fill: ${themeError};
}
`;
case "success-focus":
return css`
svg {
fill: ${themeSuccess};
}
`;
default:
return "";
}
};

export const getInputAppearanceStyle = appearance => {
switch (appearance) {
case "standard":
return css`
background-color: ${themeBgPrimary};
border-color: ${themeBorder};
&:focus {
background-color: ${getFocusFieldBg(
getCSSVarValue(themeBrandPrimary)
)};
border-color: ${themeBrandPrimary};
svg {
fill: ${themeBrandPrimary};
}
}
`;
case "disabled":
return css`
background-color: ${themeBgDisabled};
border-color: ${themeBgDisabled};
color: ${themeTextColorDisabled};
svg {
fill: ${themeTextColorDisabled};
}
&::placeholder {
color: ${themeTextColorDisabled};
}
input {
color: ${themeTextColorDisabled};
::placeholder {
Expand All @@ -111,9 +155,7 @@ export const getInputAppearanceStyle = appearance => {
return css`
background-color: ${themeBgPrimary};
border-color: ${themeError};
svg {
fill: ${themeError};
}
&:focus {
background-color: ${getFocusFieldBg(getCSSVarValue(themeError))};
}
Expand All @@ -122,9 +164,7 @@ export const getInputAppearanceStyle = appearance => {
return css`
background-color: ${themeBgPrimary};
border-color: ${themeSuccess};
svg {
fill: ${themeSuccess};
}
&:focus {
background-color: ${getFocusFieldBg(getCSSVarValue(themeSuccess))};
}
Expand All @@ -133,25 +173,16 @@ export const getInputAppearanceStyle = appearance => {
return css`
background-color: ${getFocusFieldBg(getCSSVarValue(themeBrandPrimary))};
border-color: ${themeBrandPrimary};
svg {
fill: ${themeBrandPrimary};
}
`;
case "error-focus":
return css`
background-color: ${getFocusFieldBg(getCSSVarValue(themeError))};
border-color: ${themeError};
svg {
fill: ${themeError};
}
`;
case "success-focus":
return css`
background-color: ${getFocusFieldBg(getCSSVarValue(themeSuccess))};
border-color: ${themeSuccess};
svg {
fill: ${themeSuccess};
}
`;
default:
return "";
Expand All @@ -162,7 +193,7 @@ export const inputContainer = css`
border: 1px solid;
border-radius: ${borderRadiusSmall};
color: inherit;
height: 36px;
height: ${textInputHeight}px;
font-size: inherit;
${padding("horiz", "m")};
&::placeholder {
Expand Down
3 changes: 3 additions & 0 deletions packages/textInput/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ If the `tooltipContent` prop is set, an icon tooltip with the given text will be

## TextInputWithIcon
`TextInputWithIcon` extends the `TextInput` component but adds two additional props, `iconStart` & `iconEnd`. These props can be provided a `ReactNode` to be rendered either at the start or end of the `TextInput` or both.

## TextInputWithBadges
`TextInputWithBadges` extends the `TextInputWithIcon` component. More info coming soon...
Loading

0 comments on commit 6c78795

Please sign in to comment.