Skip to content

Commit

Permalink
change index lang list to use default colors (fiqus#46)
Browse files Browse the repository at this point in the history
use text color accordingly
  • Loading branch information
mlambir authored Jan 8, 2020
1 parent d0ed691 commit 547bace
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
11 changes: 2 additions & 9 deletions assets/js/languageColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,12 @@ const colors:{ [key: string]: string; } = {
"Zephir": "#118f9e",
"Zig": "#ec915c",
"ZIL": "#dc75e5",
"other": "#444444"
}

function getLangColor(lang:string, dark:boolean=false) {
function getLangColor(lang:string) {
let color = colors[lang];
color = color?color:"#CCCCCC";
if(dark){
let col = new TinyColor(color).desaturate(30);
if(col.isLight()){
col = col.darken(30)
}
const colstr = col.toString();
color = colstr?colstr:"#AAAAAA"
}
return color;
}

Expand Down
7 changes: 5 additions & 2 deletions assets/js/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import _ from "lodash";
import getLangColor from '../languageColors';
import CountUp from 'react-countup';
import {GoGlobe, GoCode} from "react-icons/all";
import { mostReadable, TinyColor} from '@ctrl/tinycolor';


type CountersResponse = ApiResponse<Counters>;
type LanguagesResponse = ApiResponse<[TotalLanguage]>;
Expand Down Expand Up @@ -101,9 +103,10 @@ const HomePage: React.FC<RouteComponentProps> = () => {
</div>
<div className="language-button-container">
{Object.keys(languagesResponse.data).map(lang => {
const color = getLangColor(lang, true);
const color = getLangColor(lang);
const readable = (mostReadable(color, ["#111", "#555", "#CCC", "#eee"]) || new TinyColor("#000")).toHexString();
return (
<Button key={lang} tag={Link} style={{backgroundColor: color}} to={'/languages/' + lang.toLowerCase()}>
<Button key={lang} tag={Link} style={{backgroundColor: color, color: readable}} to={'/languages/' + lang.toLowerCase()}>
{lang}
</Button>
)
Expand Down

0 comments on commit 547bace

Please sign in to comment.