Added color lightening function, removed hardcoded colors from theme
This commit is contained in:
1 parent
76e34149e9
commit
6bd8fec119
4 files changed
+48
-51
No files matched your search
@@ -1,3 +1,5 @@
|
|||||||
.label {
|
.label {
|
||||||
border: 1px solid #000;
|
border: 1px solid #000;
|
||||||
|
display: inline-flex;
|
||||||
|
justify-content: center;
|
||||||
}
|
}
|
||||||
@@ -2,38 +2,47 @@ import PropTypes from "prop-types";
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { useTheme } from "@mui/material";
|
import { useTheme } from "@mui/material";
|
||||||
|
|
||||||
|
// Produces a lighter color based on a hex color and a percent
|
||||||
|
// lightenColor("#067647", 20) will produce a color 20% lighter than #067647
|
||||||
|
const lightenColor = (color, percent) => {
|
||||||
|
let r = parseInt(color.substring(1, 3), 16);
|
||||||
|
let g = parseInt(color.substring(3, 5), 16);
|
||||||
|
let b = parseInt(color.substring(5, 7), 16);
|
||||||
|
|
||||||
|
const amt = Math.round((255 * percent) / 100);
|
||||||
|
|
||||||
|
r = r + amt <= 255 ? r + amt : 255;
|
||||||
|
g = g + amt <= 255 ? g + amt : 255;
|
||||||
|
b = b + amt <= 255 ? b + amt : 255;
|
||||||
|
|
||||||
|
r = r.toString(16).padStart(2, "0");
|
||||||
|
g = g.toString(16).padStart(2, "0");
|
||||||
|
b = b.toString(16).padStart(2, "0");
|
||||||
|
|
||||||
|
return `#${r}${g}${b}`;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Props
|
* @typedef {Object} Props
|
||||||
* @property {string} label - The label of the button
|
* @property {string} label - The label of the button
|
||||||
|
* @property {string} color - The base color of the label
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Label = ({ label, color }) => {
|
const Label = ({ label, color }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const config = {
|
// If an invalid color is passed, default to the labelGray color
|
||||||
orange: {
|
if (
|
||||||
borderColor: theme.palette.labelOrange.borderColor,
|
typeof color !== "string" ||
|
||||||
bgColor: theme.palette.labelOrange.bgColor,
|
!/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(color)
|
||||||
textColor: theme.palette.labelOrange.textColor,
|
) {
|
||||||
},
|
color = theme.palette.labelGray.textColor;
|
||||||
gray: {
|
console.log(color);
|
||||||
borderColor: theme.palette.labelGray.borderColor,
|
}
|
||||||
bgColor: theme.palette.labelGray.bgColor,
|
|
||||||
textColor: theme.palette.labelGray.textColor,
|
|
||||||
},
|
|
||||||
purple: {
|
|
||||||
borderColor: theme.palette.labelPurple.borderColor,
|
|
||||||
bgColor: theme.palette.labelPurple.bgColor,
|
|
||||||
textColor: theme.palette.labelPurple.textColor,
|
|
||||||
},
|
|
||||||
green: {
|
|
||||||
borderColor: theme.palette.labelGreen.borderColor,
|
|
||||||
bgColor: theme.palette.labelGreen.bgColor,
|
|
||||||
textColor: theme.palette.labelGreen.textColor,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const { borderColor, bgColor, textColor } = config[color];
|
// Calculate lighter shades for border and bg
|
||||||
|
const borderColor = lightenColor(color, 20);
|
||||||
|
const bgColor = lightenColor(color, 75);
|
||||||
const { borderRadius } = theme.shape;
|
const { borderRadius } = theme.shape;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -42,7 +51,8 @@ const Label = ({ label, color }) => {
|
|||||||
borderRadius: borderRadius,
|
borderRadius: borderRadius,
|
||||||
borderColor: borderColor,
|
borderColor: borderColor,
|
||||||
backgroundColor: bgColor,
|
backgroundColor: bgColor,
|
||||||
color: textColor,
|
color: color,
|
||||||
|
padding: theme.spacing(1 * 0.75, 2),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ import DropdownTeamMember from "../../Components/DropdownTeamMember";
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
import Button from "../../Components/Button";
|
import Button from "../../Components/Button";
|
||||||
import Label from "../../Components/Label";
|
import Label from "../../Components/Label";
|
||||||
|
import { useTheme } from "@mui/material";
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
|
const theme = useTheme();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div>Home</div>
|
<div>Home</div>
|
||||||
<DropdownTeamMember />
|
<DropdownTeamMember />
|
||||||
<div
|
<div>
|
||||||
style={{ display: "flex", flexDirection: "column", marginTop: "2rem" }}
|
|
||||||
>
|
|
||||||
<h4>Buttons</h4>
|
<h4>Buttons</h4>
|
||||||
<div>
|
<div>
|
||||||
<Button level="primary" label="Primary" />
|
<Button level="primary" label="Primary" />
|
||||||
@@ -27,10 +27,10 @@ const Home = () => {
|
|||||||
</div>
|
</div>
|
||||||
<h4>Labels</h4>
|
<h4>Labels</h4>
|
||||||
<div>
|
<div>
|
||||||
<Label label="Label" color="orange" />
|
<Label label="Label" color={theme.palette.labelOrange.textColor} />
|
||||||
<Label label="Label" color="gray" />
|
<Label label="Label" color={theme.palette.labelGray.textColor} />
|
||||||
<Label label="Label" color="purple" />
|
<Label label="Label" color={theme.palette.labelPurple.textColor} />
|
||||||
<Label label="Label" color="green" />
|
<Label label="Label" color={theme.palette.labelGreen.textColor} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,28 +1,21 @@
|
|||||||
import { createTheme } from "@mui/material";
|
import { createTheme } from "@mui/material";
|
||||||
|
|
||||||
// Colors for MUI theme
|
// Colors for MUI theme
|
||||||
|
const primaryMain = "#1570EF";
|
||||||
const secondaryMain = "#475467";
|
const secondaryMain = "#475467";
|
||||||
const tertiaryMain = "#475467";
|
const tertiaryMain = "#475467";
|
||||||
|
|
||||||
// Label Colors
|
// Label Colors
|
||||||
const labelBorderOrange = "#F9DBAF";
|
|
||||||
const labelBgOrange = "#FEF6EE";
|
|
||||||
const labelTextOrange = "#B93815";
|
const labelTextOrange = "#B93815";
|
||||||
|
const labelTextGray = "#475467";
|
||||||
const labelBorderGray = "#EAECF0";
|
|
||||||
const labelBgGray = "#F9FAFB";
|
|
||||||
const labelTextGray = "#344054";
|
|
||||||
|
|
||||||
const labelBorderPurple = "#E9D7FE";
|
|
||||||
const labelBgPurple = "#F9F5FF";
|
|
||||||
const labelTextPurple = "#6941C6";
|
const labelTextPurple = "#6941C6";
|
||||||
|
|
||||||
const labelBorderGreen = "#AAEFC6";
|
|
||||||
const labelBgGreen = "#ECFDF3";
|
|
||||||
const labelTextGreen = "#067647";
|
const labelTextGreen = "#067647";
|
||||||
|
|
||||||
const theme = createTheme({
|
const theme = createTheme({
|
||||||
palette: {
|
palette: {
|
||||||
|
primary: {
|
||||||
|
main: primaryMain,
|
||||||
|
},
|
||||||
secondary: {
|
secondary: {
|
||||||
main: secondaryMain,
|
main: secondaryMain,
|
||||||
},
|
},
|
||||||
@@ -30,23 +23,15 @@ const theme = createTheme({
|
|||||||
main: tertiaryMain,
|
main: tertiaryMain,
|
||||||
},
|
},
|
||||||
labelOrange: {
|
labelOrange: {
|
||||||
borderColor: labelBorderOrange,
|
|
||||||
bgColor: labelBgOrange,
|
|
||||||
textColor: labelTextOrange,
|
textColor: labelTextOrange,
|
||||||
},
|
},
|
||||||
labelGray: {
|
labelGray: {
|
||||||
borderColor: labelBorderGray,
|
|
||||||
bgColor: labelBgGray,
|
|
||||||
textColor: labelTextGray,
|
textColor: labelTextGray,
|
||||||
},
|
},
|
||||||
labelPurple: {
|
labelPurple: {
|
||||||
borderColor: labelBorderPurple,
|
|
||||||
bgColor: labelBgPurple,
|
|
||||||
textColor: labelTextPurple,
|
textColor: labelTextPurple,
|
||||||
},
|
},
|
||||||
labelGreen: {
|
labelGreen: {
|
||||||
borderColor: labelBorderGreen,
|
|
||||||
bgColor: labelBgGreen,
|
|
||||||
textColor: labelTextGreen,
|
textColor: labelTextGreen,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user