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(lemon-ui): Properly indicate clickable and disabled LemonTag #23853

Merged
merged 4 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function CategoryPill({
type={isActive ? 'primary' : canInteract ? 'option' : 'muted'}
data-attr={`taxonomic-tab-${groupType}`}
onClick={canInteract ? onClick : undefined}
weight="normal"
aria-disabled
Copy link
Member Author

@Twixes Twixes Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EDsCODE Looks like this aria-disabled was added in #22385. What was the reason?

disabledReason={!canInteract ? 'No results' : null}
className="font-normal"
>
{group?.render ? (
group?.name
Expand Down
26 changes: 23 additions & 3 deletions frontend/src/lib/lemon-ui/LemonTag/LemonTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,37 @@ export type LemonTagType =
| 'none'
| 'breakdown'

export interface LemonTagProps extends React.HTMLAttributes<HTMLDivElement> {
export interface LemonTagProps {
type?: LemonTagType
children: React.ReactNode
size?: 'small' | 'medium'
weight?: 'normal'
icon?: JSX.Element
closable?: boolean
onClose?: () => void
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void
popover?: LemonButtonDropdown
className?: string
disabledReason?: string | null
title?: string
'data-attr'?: string
}

export const LemonTag: React.FunctionComponent<LemonTagProps & React.RefAttributes<HTMLDivElement>> = forwardRef(
function LemonTag(
{ type = 'default', children, className, size = 'medium', weight, icon, closable, onClose, popover, ...props },
{
type = 'default',
children,
className,
size = 'medium',
weight,
icon,
closable,
onClose,
popover,
disabledReason,
...props
},
ref
): JSX.Element {
return (
Expand All @@ -42,11 +59,14 @@ export const LemonTag: React.FunctionComponent<LemonTagProps & React.RefAttribut
className={clsx(
'LemonTag',
`LemonTag--size-${size}`,
!!props.onClick && 'cursor-pointer',
disabledReason ? 'cursor-not-allowed' : props.onClick ? 'cursor-pointer' : undefined,
`LemonTag--${type}`,
weight && `LemonTag--${weight}`,
className
)}
role={props.onClick ? 'button' : undefined}
title={disabledReason || undefined}
aria-disabled={disabledReason ? true : undefined}
{...props}
>
{icon && <span className="LemonTag__icon">{icon}</span>}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/queries/nodes/DataTable/renderColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function renderColumn(
if (value === loadingColumn) {
return <Spinner />
} else if (value === errorColumn) {
return <LemonTag color="red">Error</LemonTag>
return <LemonTag className="text-danger">Error</LemonTag>
} else if (queryContextColumnName && queryContextColumn?.render) {
const Component = queryContextColumn?.render
return (
Expand Down
11 changes: 3 additions & 8 deletions frontend/src/scenes/instance/SystemStatus/RenderMetricValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ export function RenderMetricValue(
if (value && isSecret) {
return (
<LemonTag
style={{ color: 'var(--muted)', backgroundColor: '#fee5b3' }}
className="uppercase"
icon={isSecret ? <IconLock style={{ color: 'var(--warning)' }} /> : undefined}
className="uppercase text-muted bg-mark"
icon={isSecret ? <IconLock className="text-warning" /> : undefined}
>
Secret
</LemonTag>
Expand All @@ -46,11 +45,7 @@ export function RenderMetricValue(
}

if (value === null || value === undefined || value === '') {
return (
<LemonTag className="uppercase" style={{ color: 'var(--muted)' }}>
{emptyNullLabel ?? 'Unknown'}
</LemonTag>
)
return <LemonTag className="uppercase text-muted">{emptyNullLabel ?? 'Unknown'}</LemonTag>
}

if (value_type === 'int' || typeof value === 'number') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function PluginJobOptions({
<>
<h3 className="l3 mt-8">
Jobs
<LemonTag type="warning" className="uppercase" style={{ verticalAlign: '0.125em', marginLeft: 6 }}>
<LemonTag type="warning" className="uppercase align-[0.125em] ml-1.5">
BETA
</LemonTag>
</h3>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/surveys/Surveys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export function StatusTag({ survey }: { survey: Survey }): JSX.Element {
} as Record<ProgressStatus, LemonTagType>
const status = getSurveyStatus(survey)
return (
<LemonTag type={statusColors[status]} style={{ fontWeight: 600 }} data-attr="status">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder how this crept in past the eslint rule? It was only added 3 months ago

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the rule only applies to props on HTML elements, and not React components 🤔

<LemonTag type={statusColors[status]} className="font-semibold" data-attr="status">
{status.toUpperCase()}
</LemonTag>
)
Expand Down
Loading