Skip to content

Commit 9807efe

Browse files
UI improvements (#34)
* Input with clear button * Props to input with clear button * Kern Table as shared component first draft * Changed logic for displaying sorting icon * Warning error fix * Build fix * Clicking on columns only without sort * Users table * Smaller changes for display values * Admin messages shared component * Tasks cell components added * Org buttons shared components added * Added cells for session table * Cache files components * Sort functions and badges as part of the submodules * cell components changes * Kern button as part of the submodules * New cells for kern table * Badges props added * New cells to kern table * Added label cell * Added tooltips to table header * Import updated * Submodules updated * Added more optional params to the config
1 parent 7f969a7 commit 9807efe

19 files changed

+967
-0
lines changed

components/Badges.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { BadgeProps } from "../types/badges";
2+
3+
export function KernBadge(props: BadgeProps) {
4+
return (
5+
<span
6+
className={`inline-flex items-center rounded px-2 py-0.5 text-xs font-medium ${props.bgColor} ${props.textColor} ${props.border ? "border" : ""}`}
7+
>
8+
<svg
9+
className={`mr-1.5 h-2 w-2 ${props.svgColor}`}
10+
fill="currentColor"
11+
viewBox="0 0 8 8"
12+
>
13+
<circle cx="4" cy="4" r="3" />
14+
</svg>
15+
{props.name}
16+
</span>
17+
);
18+
}
19+
20+
export function ActiveBadge() {
21+
return (
22+
<KernBadge
23+
name="Yes"
24+
bgColor="bg-green-100"
25+
textColor="text-green-800"
26+
svgColor="text-green-400"
27+
/>
28+
);
29+
}
30+
31+
export function InactiveBadge() {
32+
return (
33+
<KernBadge
34+
name="No"
35+
bgColor="bg-red-100"
36+
textColor="text-red-800"
37+
svgColor="text-red-400"
38+
/>
39+
);
40+
}
41+
42+
export function NotApplicableBadge() {
43+
return (
44+
<KernBadge
45+
name="n/a"
46+
bgColor="bg-gray-100"
47+
textColor="text-gray-800"
48+
svgColor="text-gray-400"
49+
border={true}
50+
/>
51+
);
52+
}

components/InputWithClearIcon.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { IconX } from "@tabler/icons-react";
2+
3+
export type InputWithClearIconProps = {
4+
value: string;
5+
onChange: (value: string) => void;
6+
classNames?: string;
7+
id?: string;
8+
}
9+
10+
export default function InputWithClearIcon(props: InputWithClearIconProps) {
11+
return (<div className={`relative ${props.classNames}`}>
12+
<input id={props.id} type="text" placeholder="Search"
13+
className="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
14+
value={props.value}
15+
onChange={(event) => props.onChange(event.target.value)}
16+
/>
17+
{props.value && (
18+
<IconX className='absolute right-2 top-1/2 transform -translate-y-1/2 cursor-pointer text-gray-500' onClick={() => props.onChange("")} />
19+
)}
20+
</div>)
21+
}

components/LoadingIcon.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { LoadingIconProps } from "@/submodules/react-components/types/loading";
2+
import { prepareColorClasses, prepareSize } from "@/submodules/react-components/helpers/loading-helper";
3+
import { memo, useState } from "react";
4+
5+
function LoadingIcon(props: LoadingIconProps) {
6+
const [colorClasses, setColorClasses] = useState(prepareColorClasses(props.color));
7+
const [sizeClasses, setSizeClasses] = useState(prepareSize(props.size));
8+
9+
return (
10+
<div role="status">
11+
<svg aria-hidden="true" className={`${props.removeMargin ? 'mx-0' : 'mx-2'} animate-spin rounded-full ${colorClasses} ${sizeClasses} border-0 cursor-default`}
12+
viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
13+
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor" />
14+
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill" />
15+
</svg>
16+
<span className="sr-only">Loading...</span>
17+
</div>
18+
)
19+
}
20+
21+
export default memo(LoadingIcon);

components/MultilineTooltipAuto.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { MultilineTooltipAutoProps as MultilineTooltipAutoContentProps } from "@/submodules/react-components/types/multiline-tooltip";
2+
import { extendArrayElementsByUniqueId } from "@/submodules/javascript-functions/id-prep";
3+
import { useMemo } from "react";
4+
5+
export default function MultilineTooltipAutoContent(props: MultilineTooltipAutoContentProps) {
6+
const splitOnMe = props.splitOn || "\n";
7+
const toolTipArray = useMemo(() => { return props.tooltip ? extendArrayElementsByUniqueId(props.tooltip.split(splitOnMe)) : [] }, [props.tooltip])
8+
9+
return (<div className="flex flex-col">
10+
{toolTipArray.map((line) => (
11+
<span key={line.id}>{line.value}</span>
12+
))}
13+
</div>)
14+
}

components/kern-button/KernButton.tsx

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import { combineClassNames } from "@/submodules/javascript-functions/general";
2+
import { IconLoader2 } from "@tabler/icons-react";
3+
import { Tooltip } from '@nextui-org/react'
4+
import { useState } from "react";
5+
import { IconCheck } from "@tabler/icons-react";
6+
7+
interface KernButtonProps {
8+
text?: string;
9+
type?: 'button' | 'submit' | 'reset';
10+
icon?: (props: any) => React.ReactNode;
11+
iconColor?: string;
12+
onClick?: (event?) => void;
13+
buttonColor?: string;
14+
textColor?: string;
15+
solidTheme?: boolean;
16+
fullWidth?: boolean;
17+
fullHeight?: boolean;
18+
innerRef?: any;
19+
disabled?: boolean;
20+
loading?: boolean;
21+
size?: 'small' | 'medium' | 'large' | 'solid-large';
22+
tooltip?: string;
23+
tooltipPlacement?: 'top' | 'bottom' | 'left' | 'right';
24+
confirm?: boolean;
25+
}
26+
27+
export default function KernButton(props: KernButtonProps) {
28+
29+
const [confirm, setConfirm] = useState<boolean>(false);
30+
31+
return (
32+
<button
33+
onClick={(e) => {
34+
if (props.onClick) {
35+
props.onClick(e);
36+
}
37+
if (props.confirm) {
38+
setConfirm(true);
39+
setTimeout(() => {
40+
setConfirm(false);
41+
}, 3000);
42+
}
43+
}}
44+
className={
45+
combineClassNames(
46+
'text-sm group flex gap-x-2 items-center rounded-md hover:shadow-sm transition duration-200 ease-in-out disabled:opacity-50 disabled:cursor-not-allowed',
47+
props.buttonColor ? (
48+
props.solidTheme ? (
49+
`border border-${props.buttonColor}-600 bg-${props.buttonColor}-600 hover:bg-${props.buttonColor}-600 active:bg-${props.buttonColor}-600 active:border-${props.buttonColor}-600`
50+
) : (
51+
`border border-${props.buttonColor}-300 bg-${props.buttonColor}-50 hover:bg-${props.buttonColor}-100 hover:border-${props.buttonColor}-400 active:bg-${props.buttonColor}-200 active:border-${props.buttonColor}-500`
52+
)
53+
) : (
54+
'border bg-white border-gray-200 hover:bg-gray-50 hover:border-gray-300 active:bg-gray-100 active:border-gray-400'
55+
),
56+
props.fullWidth ? (
57+
'w-full justify-center'
58+
) : (
59+
'w-fit'
60+
),
61+
props.fullHeight ? (
62+
'h-full'
63+
) : (
64+
''
65+
),
66+
props.size == 'small' ? (
67+
'px-1 p-0.5'
68+
) : props.size == 'large' ? (
69+
'px-3 py-1.5'
70+
) : props.size == 'medium' ? (
71+
'px-2 py-1'
72+
) : props.size == 'solid-large' ? (
73+
'px-3 py-2'
74+
) : (
75+
'px-2 py-1'
76+
)
77+
)
78+
}
79+
ref={props.innerRef}
80+
disabled={props.disabled}
81+
type={props.type || 'submit'}
82+
>
83+
{props.loading ? (
84+
<IconLoader2 className={combineClassNames(
85+
props.iconColor === "white" ? (
86+
`animate-spin text-white group-hover:text-white`
87+
) : (
88+
`animate-spin text-${props.iconColor}-500 group-hover:text-${props.iconColor}-600`
89+
),
90+
props.size == 'small' ? (
91+
'w-4 h-4'
92+
) : (
93+
props.size == 'large' ? (
94+
'w-6 h-6'
95+
) : (
96+
'w-5 h-5'
97+
)
98+
))
99+
} />
100+
) : props.icon ? (
101+
confirm ? (
102+
<IconCheck className={combineClassNames(`text-green-500 group-hover:text-green-600`,
103+
props.size == 'small' ? (
104+
'w-4 h-4'
105+
) : (
106+
props.size == 'large' ? (
107+
'w-6 h-6'
108+
) : (
109+
'w-5 h-5'
110+
)
111+
))} />
112+
) : (
113+
<props.icon className={combineClassNames(
114+
props.iconColor === "white" ? (
115+
`text-white group-hover:text-white`
116+
) : (
117+
`text-${props.iconColor}-500 group-hover:text-${props.iconColor}-600`
118+
),
119+
props.size == 'small' ? (
120+
'w-4 h-4'
121+
) : (
122+
props.size == 'large' ? (
123+
'w-6 h-6'
124+
) : (
125+
'w-5 h-5'
126+
)
127+
))} />
128+
)
129+
) : null}
130+
{props.text ? (
131+
<Tooltip className={props.disabled ? "cursor-not-allowed" : undefined} color="invert" content={props.tooltip} placement={props.tooltipPlacement || "bottom"} >
132+
<span className={combineClassNames(
133+
props.textColor ? (
134+
`text-${props.textColor} group-hover:text-${props.textColor}`
135+
) : (
136+
`text-${props.buttonColor}-700 group-hover:text-${props.buttonColor}-800`
137+
)
138+
)}>{props.text}</span>
139+
</Tooltip>
140+
) : null}
141+
</button>
142+
)
143+
}

components/kern-button/SaveButton.tsx

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import React, { useCallback, useMemo, useState } from 'react';
2+
import { IconDeviceFloppy, IconCheck, IconAlertTriangle } from '@tabler/icons-react';
3+
import { combineClassNames, } from "@/submodules/javascript-functions/general"
4+
import { Tooltip } from '@nextui-org/react';
5+
import { getButtonColorClasses, getDisabledClasses, getWidthClasses, getHeightClasses, getSizeClasses, buttonWarningColorClasses } from '../../helpers/button-helper';
6+
import { Loading } from '@nextui-org/react';
7+
8+
type SaveButtonProps = {
9+
text?: string;
10+
iconColor?: string;
11+
onClick?: (event?) => void;
12+
buttonColor?: string;
13+
fullWidth?: boolean;
14+
fullHeight?: boolean;
15+
innerRef?: any;
16+
disabled?: boolean;
17+
loading?: boolean;
18+
size?: 'small' | 'medium' | 'large';
19+
tooltip?: string;
20+
tooltipPlacement?: 'top' | 'bottom' | 'left' | 'right';
21+
confirm?: boolean;
22+
warningCue?: any
23+
}
24+
25+
export default function SaveButton(props: SaveButtonProps) {
26+
const [confirm, setConfirm] = useState(false);
27+
28+
const handleButtonClick = useCallback((e) => {
29+
if (props.onClick) {
30+
props.onClick(e);
31+
}
32+
if (props.confirm) {
33+
setConfirm(true);
34+
setTimeout(() => {
35+
setConfirm(false);
36+
}, 3000);
37+
}
38+
}, [props.onClick, props.confirm]);
39+
40+
const disabledClasses: string = useMemo(() => getDisabledClasses(props.disabled), [props.disabled]);
41+
42+
const buttonColorClasses: string = useMemo(() => getButtonColorClasses(props.buttonColor), [props.buttonColor]);
43+
44+
const widthClasses: string = useMemo(() => getWidthClasses(props.fullWidth), [props.fullWidth]);
45+
46+
const heightClasses: string = useMemo(() => getHeightClasses(props.fullHeight), [props.fullHeight]);
47+
48+
const sizeClasses: string = useMemo(() => getSizeClasses(props.size), [props.size]);
49+
50+
const buttonClasses = useMemo(() => combineClassNames("flex gap-x-1 items-center hover:shadow-sm rounded-lg px-2 py-1", disabledClasses, buttonColorClasses, widthClasses, heightClasses, props.warningCue && buttonWarningColorClasses),
51+
[disabledClasses, buttonColorClasses, widthClasses, heightClasses, props.warningCue]);
52+
53+
return (
54+
<div className='text-sm group flex items-center rounded-md transition duration-200 ease-in-out' >
55+
{(props.warningCue) ?
56+
<Tooltip className="flex items-center justify-center mr-2" content="Warning: Potential invalid config!" color="invert">
57+
<IconAlertTriangle className="h-4 w-4 text-orange-400" />
58+
</Tooltip> : null}
59+
<button
60+
onClick={handleButtonClick}
61+
className={buttonClasses}
62+
ref={props.innerRef}
63+
disabled={props.disabled}
64+
type='submit'
65+
>
66+
{props.loading ? (
67+
<div className={combineClassNames(`inline-flex items-center justify-center text-${props.iconColor}-500 group-hover:text-${props.iconColor}-600`, sizeClasses)}>
68+
<Loading size="sm" type="spinner" color="currentColor" />
69+
</div>
70+
71+
) : confirm ? (
72+
<IconCheck className={combineClassNames(`text-green-500 group-hover:text-green-600`,
73+
sizeClasses)} />
74+
) : (
75+
<IconDeviceFloppy className={combineClassNames(`text-${props.iconColor}-500 group-hover:text-${props.iconColor}-600`,
76+
sizeClasses)} />
77+
)
78+
}
79+
{props.text ? (
80+
<Tooltip className={props.disabled ? "cursor-not-allowed" : undefined} color="invert" content={props.tooltip} placement={props.tooltipPlacement || "bottom"} >
81+
<span className={`text-${props.buttonColor}-700 group-hover:text-${props.buttonColor}-800}`}>{props.text}</span>
82+
</Tooltip>
83+
) : null}
84+
</button>
85+
</div >
86+
)
87+
}

0 commit comments

Comments
 (0)