-
Notifications
You must be signed in to change notification settings - Fork 261
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
Migration to emotionjs #4123
Conversation
this.styles = getEscalationPolicyStyles(this.props.theme); | ||
this.forceUpdate(); | ||
} | ||
} |
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.
I think just as in functional components we could just define it in render like
render() {
const styles = getEscalationPolicyStyles(props.theme);
...
}
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.
agree, ideally styles should be just in render body and nowhere else
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.
Too many render functions, that means 1 line for each subrender where we're using the styles... not worth it, it takes 3 lines with cDU lifecycle.
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'; |
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.
maybe better create a dedicate folder for styles like grafana-plugin/src/styles
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.
That's a good idea
className={cx('integrationBlock__heading', { | ||
'integrationBlock__heading--noBorderBottom': !noContent, | ||
className={cx(styles.integrationBlockHeading, { | ||
[bem(styles.integrationBlockHeading, 'noBorderBottom')]: !noContent, |
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.
className={cx(styles.integrationBlockHeading, {
[bem(styles.integrationBlockHeading, 'noBorderBottom')]: !noContent
})}
looks too ease to make typos, how does grafana core deal with nested selectors? I'm pretty sure it does not use bem.
And in general styling looks overcomplicated, to style something we need too much stuff to import
import { cx } from '@emotion/css';
import { useStyles2 } from '@grafana/ui';
import { bem } from 'utils/utils';
import { getIntegrationBlockStyles } from './IntegrationBlock.styles';
Can we remove at least one thing? the most suitable candidate seems to be a bem.
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.
Grafana doesn't use BEM pattern. Why remove any of it? I don't understand your reasons...
cx
is for composition
useStyles2
is mandatory ...
bem
is too build line blocks following BEM pattern so that you don't need to repeat the block, but instead rely on a helper that does that. BEM is very useful because it clearly expresses what the element modifier is supposed to do.
getIntegrationBlockStyles
is outside the file so that we don't have too much code in the main file
I strongly recommend reading on https://getbem.com/
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.
The code above has more in it because it depends on a conditional, is just like the old compose cx
styles.integrationBlockHeading
gets appended
integrationBlockHeading--noBorderBottom'
gets appended if noContent
is false/undefined
…a/oncall into rares/emotionjs-migration
c76b26d
to
5ecf6c4
Compare
lint
8ac0d9a
to
8472de4
Compare
What this PR does
Migrate existing CSS/SCSS to emotion
Which issue(s) this PR closes
Closes #2666