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

Migration to emotionjs #4123

Merged
merged 26 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8bf66d5
migrated a few components to emotion
teodosii Mar 27, 2024
0fb3281
Merge branch 'dev' into rares/emotionjs-migration
teodosii Mar 28, 2024
e071a66
more components migrated to emotion
teodosii Apr 1, 2024
61a102e
Merge branch 'dev' into rares/emotionjs-migration
teodosii Apr 1, 2024
e1f31e2
migrated first classes to emotion
teodosii Apr 1, 2024
bd490d4
a few more
teodosii Apr 1, 2024
9cd117d
fixed mismatching between oncall vars and theme vars
teodosii Apr 2, 2024
1d90b87
fixed missmatch
teodosii Apr 2, 2024
6bbef54
migrated more stylesheets
teodosii Apr 3, 2024
c919250
migration
teodosii Apr 4, 2024
fb1734a
a few more
teodosii Apr 4, 2024
8eff14d
minor changes
teodosii Apr 8, 2024
45c3474
Merge branch 'dev' into rares/emotionjs-migration
teodosii Apr 8, 2024
83be693
linter
teodosii Apr 8, 2024
f39435a
componentDidUpdate to watch for theme change, fixed a few styles
teodosii Apr 8, 2024
0be92c7
lint
teodosii Apr 8, 2024
4f2ab5a
Merge branch 'dev' into rares/emotionjs-migration
teodosii Apr 8, 2024
2d127b6
Merge branch 'dev' into rares/emotionjs-migration
teodosii Apr 9, 2024
628a9ee
cleanup
teodosii Apr 9, 2024
61a9254
Merge branch 'rares/emotionjs-migration' of https://github.com/grafan…
teodosii Apr 9, 2024
8de437f
fixed failing tests
teodosii Apr 9, 2024
f4db89d
tests
teodosii Apr 9, 2024
67e786e
Merge branch 'dev' into rares/emotionjs-migration
teodosii Apr 9, 2024
5ecf6c4
test
teodosii Apr 9, 2024
7f0e759
Merge branch 'dev' into rares/emotionjs-migration
teodosii Apr 9, 2024
8472de4
fixed test
teodosii Apr 9, 2024
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
1 change: 0 additions & 1 deletion grafana-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
"@lifeomic/attempt": "^3.0.3",
"array-move": "^4.0.0",
"axios": "^1.6.7",
"babel-loader": "^9.1.3",
"change-case": "^4.1.1",
"circular-dependency-plugin": "^5.2.2",
"dayjs": "^1.11.5",
Expand Down
25 changes: 0 additions & 25 deletions grafana-plugin/src/components/Avatar/Avatar.module.css

This file was deleted.

32 changes: 32 additions & 0 deletions grafana-plugin/src/components/Avatar/Avatar.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { css } from '@emotion/css';
import { GrafanaTheme2 } from '@grafana/data';

export const getAvatarStyles = (_theme: GrafanaTheme2) => {
teodosii marked this conversation as resolved.
Show resolved Hide resolved
return {
avatar: css`
display: inline-block;
border-radius: 50%;
overflow: hidden;

&--xs {
width: 12px;
height: 12px;
}

&--small {
width: 16px;
height: 16px;
}

&--medium {
width: 24px;
height: 24px;
}

&--large {
width: 32px;
height: 32px;
}
`,
};
};
20 changes: 15 additions & 5 deletions grafana-plugin/src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import React, { FC } from 'react';

import cn from 'classnames/bind';
import { cx } from '@emotion/css';
import { useStyles2 } from '@grafana/ui';

import styles from './Avatar.module.css';
import { bem } from 'utils/utils';

import { getAvatarStyles } from './Avatar.styles';

interface AvatarProps {
src: string;
size: 'xs' | 'small' | 'medium' | 'large';
className?: string;
}

const cx = cn.bind(styles);

export const Avatar: FC<AvatarProps> = (props) => {
const { src, size, className, ...rest } = props;

const styles = useStyles2(getAvatarStyles);

if (!src) {
return null;
}

return <img src={src} className={cx('root', `avatarSize-${size}`, className)} data-testid="test__avatar" {...rest} />;
return (
<img
src={src}
className={cx(styles.avatar, bem(styles.avatar, size), className)}
data-testid="test__avatar"
{...rest}
/>
);
};
29 changes: 0 additions & 29 deletions grafana-plugin/src/components/CardButton/CardButton.module.css

This file was deleted.

40 changes: 40 additions & 0 deletions grafana-plugin/src/components/CardButton/CardButton.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { css } from '@emotion/css';
import { GrafanaTheme2 } from '@grafana/data';

export const getCardButtonStyles = (theme: GrafanaTheme2) => {
return {
root: css`
height: 88px;
position: relative;
cursor: pointer;
`,

icon: css`
position: absolute;
left: 20px;
top: 20px;
color: ${theme.colors.text.disabled};
`,

meta: css`
position: absolute;
top: 14px;
left: 90px;
`,

rootSelected: css`
{
&::before {
display: block;
content: '';
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 4px;
background-image: linear-gradient(270deg, #f55f3e 0%, #f83 100%);
}
}
`,
};
};
24 changes: 10 additions & 14 deletions grafana-plugin/src/components/CardButton/CardButton.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { FC } from 'react';

import { VerticalGroup } from '@grafana/ui';
import cn from 'classnames/bind';
import { cx } from '@emotion/css';
import { VerticalGroup, useStyles2 } from '@grafana/ui';

import { Block } from 'components/GBlock/Block';
import { Text } from 'components/Text/Text';

import styles from './CardButton.module.css';
import { getCardButtonStyles } from './CardButton.styles';

interface CardButtonProps {
icon: React.ReactElement;
Expand All @@ -16,27 +16,23 @@ interface CardButtonProps {
onClick: (selected: boolean) => void;
}

const cx = cn.bind(styles);

export const CardButton: FC<CardButtonProps> = (props) => {
const { icon, description, title, selected, onClick } = props;

const styles = useStyles2(getCardButtonStyles);

return (
<Block
onClick={() => onClick(!selected)}
withBackground
className={cx('root', { root_selected: selected })}
className={cx(styles.root, { [styles.rootSelected]: selected })}
data-testid="test__cardButton"
>
<div className={cx('icon')}>{icon}</div>
<div className={cx('meta')}>
<div className={cx(styles.icon)}>{icon}</div>
<div className={cx(styles.meta)}>
<VerticalGroup spacing="xs">
<Text type="secondary" className={cx('description')}>
{description}
</Text>
<Text.Title level={1} className={cx('title')}>
{title}
</Text.Title>
<Text type="secondary">{description}</Text>
<Text.Title level={1}>{title}</Text.Title>
</VerticalGroup>
</div>
</Block>
Expand Down
33 changes: 0 additions & 33 deletions grafana-plugin/src/components/CheatSheet/CheatSheet.module.scss

This file was deleted.

40 changes: 40 additions & 0 deletions grafana-plugin/src/components/CheatSheet/CheatSheet.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { css } from '@emotion/css';
import { GrafanaTheme2 } from '@grafana/data';

export const getCheatSheetStyles = (theme: GrafanaTheme2) => {
return {
cheatsheetContainer: css`
width: 40%;
height: 100%;
padding: 16px;
padding-right: 0;
border: 1px solid ${theme.colors.border.weak};
min-width: min-content;
overflow-y: scroll;
`,

cheatsheetInnerContainer: css`
padding-right: 16px;
overflow-y: scroll;
height: 100%;

& > div {
height: 100%;
max-height: 100%;
}
}`,

cheatsheetItem: css`
margin-bottom: 24px;

&--small {
margin-bottom: 16px;
width: 100%;
}
`,

code: css`
white-space: pre;
`,
};
};
28 changes: 16 additions & 12 deletions grafana-plugin/src/components/CheatSheet/CheatSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
import React from 'react';

import { HorizontalGroup, IconButton, VerticalGroup } from '@grafana/ui';
import cn from 'classnames/bind';
import { HorizontalGroup, IconButton, VerticalGroup, useStyles2 } from '@grafana/ui';
import CopyToClipboard from 'react-copy-to-clipboard';

import { Block } from 'components/GBlock/Block';
import { Text } from 'components/Text/Text';
import { openNotification } from 'utils/utils';
import { bem, openNotification } from 'utils/utils';
import { getUtilStyles } from 'utils/utils.styles';
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe better create a dedicate folder for styles like grafana-plugin/src/styles

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good idea


import { CheatSheetInterface, CheatSheetItem } from './CheatSheet.config';
import styles from './CheatSheet.module.scss';
import { getCheatSheetStyles } from './CheatSheet.styles';

interface CheatSheetProps {
cheatSheetName: string;
cheatSheetData: CheatSheetInterface;
onClose: () => void;
}

const cx = cn.bind(styles);

export const CheatSheet = (props: CheatSheetProps) => {
const { cheatSheetName, cheatSheetData, onClose } = props;

const styles = useStyles2(getCheatSheetStyles);
const utils = useStyles2(getUtilStyles);

return (
<div className={cx('cheatsheet-container')}>
<div className={cx('cheatsheet-innerContainer')}>
<div className={styles.cheatsheetContainer}>
<div className={styles.cheatsheetInnerContainer}>
<VerticalGroup>
<HorizontalGroup justify="space-between">
<Text strong>{cheatSheetName} cheatsheet</Text>
<IconButton aria-label="Close" name="times" onClick={onClose} />
</HorizontalGroup>
<Text type="secondary">{cheatSheetData.description}</Text>
<div className={cx('u-width-100')}>
<div className={utils.width100}>
{cheatSheetData.fields?.map((field: CheatSheetItem) => {
return (
<div key={field.name} className={cx('cheatsheet-item')}>
<div key={field.name} className={styles.cheatsheetItem}>
<CheatSheetListItem field={field} />
</div>
);
Expand All @@ -50,6 +52,8 @@ interface CheatSheetListItemProps {
}
const CheatSheetListItem = (props: CheatSheetListItemProps) => {
const { field } = props;
const styles = useStyles2(getCheatSheetStyles);

return (
<>
<Text>{field.name}</Text>
Expand All @@ -63,10 +67,10 @@ const CheatSheetListItem = (props: CheatSheetListItemProps) => {
</li>
)}
{item.codeExample && (
<div className={cx('cheatsheet-item-small')}>
<div className={bem(styles.cheatsheetItem, 'small')}>
<Block bordered fullWidth withBackground>
<HorizontalGroup justify="space-between">
<Text type="link" className={cx('code')}>
<Text type="link" className={styles.code}>
{item.codeExample}
</Text>
<CopyToClipboard text={item.codeExample} onCopy={() => openNotification('Example copied')}>
Expand Down
Loading
Loading