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

new composant iconStatus #794

Merged
merged 4 commits into from
Nov 21, 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
55 changes: 55 additions & 0 deletions src/lib/components/statusicon/StatusIcon.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Icon, IconName } from '../icon/Icon.component';
import {
STATUS_WARNING,
STATUS_CRITICAL,
STATUS_HEALTHY,
} from '../../components/constants';
import { CoreUITheme } from '../../style/theme';
import { Loader } from '../loader/Loader.component';

export enum Status {
HEALTHY = 'healthy',
WARNING = 'warning',
CRITICAL = 'critical',
UNKNOWN = 'unknown',
momodaadaa99 marked this conversation as resolved.
Show resolved Hide resolved
LOADING = 'loading',
}

export const StatusIcon = ({ status }: { status: Status }) => {
if (status === 'loading') {
return <Loader />;
}
const icon: { color: keyof CoreUITheme; name: IconName; label: string } =
(() => {
switch (status) {
case STATUS_HEALTHY:
return {
color: 'statusHealthy',
name: 'Check-circle',
label: 'Healthy status icon',
};

case STATUS_WARNING:
return {
color: 'statusWarning',
name: 'Times-circle',
label: 'Warning status icon',
};

case STATUS_CRITICAL:
return {
color: 'statusCritical',
name: 'Times-circle',
label: 'Critical status icon',
};
default:
return {
color: 'textTertiary',
name: 'Info',
label: 'Information status icon',
};
}
})();

return <Icon color={icon.color} name={icon.name} aria-label={icon.label} />;
};
13 changes: 7 additions & 6 deletions src/lib/components/tablev2/TableUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const STATUS_CRITICAL = 'critical';
const STATUS_WARNING = 'warning';
const STATUS_NONE = 'none';
const STATUS_HEALTH = 'healthy';
export const STATUS_CRITICAL = 'critical';
export const STATUS_WARNING = 'warning';
export const STATUS_NONE = 'none';
export const STATUS_HEALTH = 'healthy';
export const STATUS_UNKNOWN = 'unknown';

type StatusType =
| typeof STATUS_CRITICAL
Expand Down Expand Up @@ -34,8 +35,8 @@ export function compareHealth(
return weights[status1] === weights[status2]
? 0
: weights[status1] > weights[status2]
? 1
: -1;
? 1
: -1;
}

export function convertRemToPixels(rem) {
Expand Down
46 changes: 46 additions & 0 deletions stories/statusicon.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import {
Status,
StatusIcon,
} from '../src/lib/components/statusicon/StatusIcon.component';
import { Wrapper } from './common';
import { Stack, Text } from '../src/lib';

export default {
title: 'Components/statusIcon',
component: StatusIcon,
};

export const Playground = {
args: {
status: 'healthy',
},
};
export const Default = {
render: ({}) => {
return (
<Wrapper>
<Stack>
<Text>Healthy status </Text>
<StatusIcon status={Status.HEALTHY} />{' '}
</Stack>
<Stack>
<Text>Warning status </Text>
<StatusIcon status={Status.WARNING} />
</Stack>
<Stack>
<Text>Critical status </Text>
<StatusIcon status={Status.CRITICAL} />
</Stack>
<Stack>
<Text>Loading status </Text>
<StatusIcon status={Status.LOADING} />
</Stack>
<Stack>
<Text>Unknown status </Text>
<StatusIcon status={Status.UNKNOWN} />
</Stack>
</Wrapper>
);
},
};
Loading