-
Notifications
You must be signed in to change notification settings - Fork 84
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
LF-4711 Make the Online/Offline badge and make it into a Table Cell Kind #3676
Changes from all commits
fcbb512
57996c6
85f3730
b161a5b
69eaea8
6e1691d
e95db32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2025 LiteFarm.org | ||
* This file is part of LiteFarm. | ||
* | ||
* LiteFarm is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiteFarm is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import clsx from 'clsx'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Tooltip } from '@mui/material'; | ||
import { ReactComponent as StatusIndicatorDot } from '../../assets/images/status-indicator-dot.svg'; | ||
import styles from './styles.module.scss'; | ||
import { Semibold, Main } from '../Typography'; | ||
|
||
export enum Status { | ||
ONLINE = 'ONLINE', | ||
OFFLINE = 'OFFLINE', | ||
} | ||
|
||
export interface StatusIndicatorPillProps { | ||
status: Status; | ||
pillText: string; | ||
tooltipText?: string; | ||
showHoverTooltip?: boolean; | ||
} | ||
|
||
export const StatusIndicatorPill = ({ | ||
status, | ||
pillText, | ||
tooltipText = '', | ||
showHoverTooltip = true, | ||
}: StatusIndicatorPillProps) => { | ||
const { t } = useTranslation(); | ||
|
||
const isOnline = status === Status.ONLINE; | ||
|
||
const hoverContent = <Main className={styles.hoverText}>{t(tooltipText)}</Main>; | ||
|
||
// https://mui.com/material-ui/react-tooltip/#distance-from-anchor | ||
const PopperProps = { | ||
modifiers: [ | ||
{ | ||
name: 'offset', | ||
options: { | ||
offset: [0, 4], | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const statusPill = ( | ||
<div | ||
className={clsx( | ||
styles.pill, | ||
isOnline ? styles.online : styles.offline, | ||
showHoverTooltip && styles.hover, | ||
)} | ||
> | ||
<StatusIndicatorDot /> | ||
<Semibold className={styles.pillText}>{t(pillText)}</Semibold> | ||
</div> | ||
); | ||
|
||
return showHoverTooltip ? ( | ||
<Tooltip | ||
title={hoverContent} | ||
placement="bottom-end" | ||
classes={{ | ||
tooltip: styles.tooltipContainer, | ||
}} | ||
PopperProps={PopperProps} | ||
enterTouchDelay={0} | ||
leaveTouchDelay={900000} | ||
> | ||
{statusPill} | ||
</Tooltip> | ||
) : ( | ||
statusPill | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2025 LiteFarm.org | ||
* This file is part of LiteFarm. | ||
* | ||
* LiteFarm is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiteFarm is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
.pill { | ||
display: inline-flex; | ||
align-items: center; | ||
gap: 4px; | ||
|
||
padding: 2px 4px; | ||
border-radius: 40px; | ||
|
||
&.hover { | ||
cursor: default; | ||
} | ||
} | ||
|
||
.pill.online { | ||
background: var(--Colors-Secondary-Secondary-green-100); | ||
|
||
.pillText { | ||
color: var(--Colors-Secondary-Secondary-green-700); | ||
} | ||
|
||
&.hover:hover { | ||
background: var(--Colors-Secondary-Secondary-green-700); | ||
|
||
.pillText { | ||
color: var(--Colors-Secondary-Secondary-green-50); | ||
} | ||
|
||
svg circle { | ||
fill: var(--Colors-Secondary-Secondary-green-50); | ||
} | ||
} | ||
} | ||
|
||
.pill.offline { | ||
background: var(--Colors-Accent---singles-Red-light); | ||
|
||
svg circle { | ||
fill: var(--Colors-Accent---singles-Red-full); | ||
} | ||
|
||
.pillText { | ||
color: var(--Colors-Accent---singles-Red-full); | ||
} | ||
|
||
&.hover:hover { | ||
background: var(--Colors-Accent---singles-Red-full); | ||
|
||
.pillText { | ||
color: var(--Colors-Accent---singles-Red-light); | ||
} | ||
|
||
svg circle { | ||
fill: var(--Colors-Accent---singles-Red-light); | ||
} | ||
} | ||
} | ||
|
||
.pillText, | ||
.hoverText { | ||
font-family: 'Open Sans'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this not inherited from somewhwere else? With that special malayalam font etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmmm 🤔 I never considered this! Does this mean that all the places in our codebase that still say (I'll double-check on this component, but often when the font is specified inheritance is not working for some reason so it does have to get restated sometimes) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats my understanding, but ideally then we shouldnt have to specify except globally and if really needed maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember for sure but I think the reason we have to specify this in a million places might be MUI styles getting in the way |
||
user-select: none; | ||
font-weight: 400; | ||
} | ||
|
||
.pillText { | ||
font-size: 16px; | ||
line-height: 20px; | ||
} | ||
|
||
.hoverText { | ||
font-size: 14px; | ||
line-height: normal; | ||
color: #000; | ||
} | ||
|
||
.tooltipContainer { | ||
margin: 0 !important; // override MUI's default margin | ||
padding: 8px 16px; | ||
border-radius: 8px; | ||
background: var(--white, #fff); | ||
box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.25); | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this just be a new pure css component? A circle is also used for the filter dot (border radius should probably be 50%)