Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add keyboard support to CardHorizontalBarChart and InfoTooltip #4165

Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
},
"rules": {
"jsx-a11y/label-has-associated-control": "warn",
"jsx-a11y/anchor-has-content":"warn",
"jsx-a11y/role-supports-aria-props":"warn",
"jsx-a11y/anchor-has-content": "warn",
"jsx-a11y/role-supports-aria-props": "warn",
"jsx-a11y/no-noninteractive-element-to-interactive-role": "warn",
"jsx-a11y/click-events-have-key-events": "Warn",
"jsx-a11y/no-static-element-interactions": "warn",
"jsx-a11y/no-autofocus": "warn",
"jsx-a11y/img-redundant-alt":"warn",
"jsx-a11y/img-redundant-alt": "warn",
"jsx-a11y/mouse-events-have-key-events": "warn",
"jsx-a11y/iframe-has-title": "warn",
"jsx-a11y/no-noninteractive-tabindex": "warn",
"jsx-a11y/anchor-is-valid": "warn",
"jsx-a11y/no-noninteractive-element-interactions": "warn",
"jsx-a11y/interactive-supports-focus": "warn",
"jsx-a11y/interactive-supports-focus": "warn",
"jsx-quotes": "error",
"unused-imports/no-unused-imports": "error",
"import/order": [
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ permissions:
jobs:
comment:
permissions:
issues: write # for peter-evans/create-or-update-comment to create or update comment
pull-requests: write # for peter-evans/create-or-update-comment to create or update comment
issues: write # for peter-evans/create-or-update-comment to create or update comment
pull-requests: write # for peter-evans/create-or-update-comment to create or update comment
mohammedfirdouss marked this conversation as resolved.
Show resolved Hide resolved
name: Comment
runs-on: ubuntu-latest
steps:
Expand Down
9 changes: 9 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This configuration file was automatically generated by Gitpod.
mohammedfirdouss marked this conversation as resolved.
Show resolved Hide resolved
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.

# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- init: npm install && npm run build
command: npm run start
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
import Text from "components/atoms/Typography/text";
import Tooltip from "components/atoms/Tooltip/tooltip";
import colors from "../../../lib/utils/color.json";

export interface AllSimpleColors {
Expand All @@ -17,28 +18,16 @@ export interface LanguageObject {

interface CardHorizontalBarChartProps {
languageList: LanguageObject[];
withDescription: boolean;
}

const languageToColor: AllSimpleColors = colors as AllSimpleColors;

const CardHorizontalBarChart = ({ languageList }: CardHorizontalBarChartProps): JSX.Element => {
const CardHorizontalBarChart = ({ languageList, withDescription }: CardHorizontalBarChartProps): JSX.Element => {
const sortedLangArray = languageList.sort((a, b) => b.percentageUsed - a.percentageUsed);
// used this state to calculate thte percentage of each language
const [percentage, setPercentage] = useState<any>(0);

useEffect(() => {
if (sortedLangArray.length === 0) return;

const totalSumOfFirstFivePercentage = sortedLangArray
.slice(0, 4)
.map((lang) => lang.percentageUsed)
.reduce((prev: number, next: number) => prev + next); // need some help fixing this type error, used any to bypass 🙏
setPercentage(totalSumOfFirstFivePercentage);
}, [percentage, sortedLangArray]);

return (
<div className="flex flex-col gap-1 min-w-[120px]">
{/* Progress Bar */}
<div className="flex items-center w-full justify-end rounded-full gap-0.5 overflow-hidden">
{sortedLangArray.map(({ languageName, percentageUsed }, index) => {
return (
Expand All @@ -47,16 +36,36 @@ const CardHorizontalBarChart = ({ languageList }: CardHorizontalBarChartProps):
key={index}
className="h-2 transition-all duration-500 ease-in-out"
style={{
width: `${percentageUsed < 20 ? (percentageUsed / percentage) * 100 : percentageUsed}%`,
width: `${percentageUsed}%`,
backgroundColor: languageToColor[languageName]
? (languageToColor[languageName].color as string)
: NOTSUPPORTED,
}}
/>
>
<span className="sr-only">{`${languageName} ${percentageUsed}%`}</span>
</div>
)
);
})}
</div>
{withDescription && (
<div className="flex gap-2 w-32 items-baseline">
<div
className={"w-2 h-2 rounded-full"}
style={{
backgroundColor: languageToColor[sortedLangArray[0]?.languageName]
? (languageToColor[sortedLangArray[0]?.languageName].color as string)
: NOTSUPPORTED,
}}
/>
{/* Always display the most-used language (first item in sorted array) instead of interactive language selection */}
<Tooltip className="max-w-[100px]" content={sortedLangArray[0]?.languageName}>
<Text className="!text-xs !truncate !font-semibold !text-light-slate-11">
{sortedLangArray[0]?.languageName}
</Text>
</Tooltip>
</div>
)}
</div>
);
};
Expand Down
10 changes: 6 additions & 4 deletions components/shared/InfoTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { HiOutlineInformationCircle } from "react-icons/hi";
export default function InfoTooltip({ information, icon }: { information: string; icon?: React.ReactNode }) {
const [open, setOpen] = useState(false);

const handleOpenChange = (isOpen: boolean) => {
setOpen(isOpen);
};

return (
<Tooltip open={open}>
<Tooltip open={open} onOpenChange={handleOpenChange}>
<TooltipTrigger asChild>
<button onMouseOver={() => setOpen(true)} onMouseLeave={() => setOpen(false)} onClick={() => setOpen(!open)}>
{icon ? icon : <HiOutlineInformationCircle className="text-slate-500" />}
</button>
<button>{icon ? icon : <HiOutlineInformationCircle className="text-slate-500" />}</button>
</TooltipTrigger>
<TooltipPortal>
<TooltipContent
Expand Down
Loading
Loading