Skip to content

Commit 08994a7

Browse files
authored
chore(lint): turn on dynamic css rule, move more styles to constants (#7421)
1 parent 7e7e48a commit 08994a7

File tree

16 files changed

+105
-40
lines changed

16 files changed

+105
-40
lines changed

configs/eslint-config-compass/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ module.exports = {
9898
plugins: [...shared.plugins, '@mongodb-js/compass', 'chai-friendly'],
9999
rules: {
100100
...shared.rules,
101-
'@mongodb-js/compass/no-inline-emotion-css': 'warn',
101+
'@mongodb-js/compass/no-inline-emotion-css': 'error',
102102
'@mongodb-js/compass/no-leafygreen-outside-compass-components': 'error',
103103
'@mongodb-js/compass/unique-mongodb-log-id': [
104104
'error',

packages/compass-aggregations/src/components/aggregation-side-panel/stage-wizard-use-cases/match/match-group-form.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ const groupHeaderStyles = css({
131131
gap: spacing[400],
132132
});
133133

134+
const nestedGroupButtonContainerStyles = css({
135+
display: 'inherit',
136+
});
137+
134138
const MatchGroupForm = ({
135139
fields,
136140
group,
@@ -259,7 +263,7 @@ const MatchGroupForm = ({
259263
justify="middle"
260264
enabled={disableAddNestedGroupBtn}
261265
trigger={
262-
<div style={{ display: 'inherit' }}>
266+
<div className={nestedGroupButtonContainerStyles}>
263267
<Button
264268
size="xsmall"
265269
disabled={disableAddNestedGroupBtn}

packages/compass-assistant/src/components/assistant-chat.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ const assistantChatFixesLightStyles = css({
130130
},
131131
});
132132

133+
const chatContainerOverrideStyle = {
134+
height: '100%',
135+
width: '100%',
136+
};
137+
133138
const messageFeedFixesStyles = css({
134139
display: 'flex',
135140
flexDirection: 'column-reverse',
@@ -205,6 +210,14 @@ const welcomeTextStyles = css({
205210
margin: `${spacing[100]}px 0 0 0`,
206211
});
207212

213+
const sparkleIconOverrideStyle = {
214+
color: palette.green.dark1,
215+
};
216+
217+
const inputBarTextareaProps = {
218+
placeholder: 'Ask a question',
219+
};
220+
208221
export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
209222
chat,
210223
hasNonGenuineConnections,
@@ -369,7 +382,7 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
369382
assistantChatFixesStyles,
370383
darkMode ? assistantChatFixesDarkStyles : assistantChatFixesLightStyles
371384
)}
372-
style={{ height: '100%', width: '100%' }}
385+
style={chatContainerOverrideStyle}
373386
>
374387
<LeafyGreenChatProvider variant={Variant.Compact}>
375388
<ChatWindow title="MongoDB Assistant" className={chatWindowFixesStyles}>
@@ -469,7 +482,7 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
469482
<Icon
470483
glyph="Sparkle"
471484
size="large"
472-
style={{ color: palette.green.dark1 }}
485+
style={sparkleIconOverrideStyle}
473486
/>
474487
<span>MongoDB Assistant</span>
475488
</h4>
@@ -488,9 +501,7 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
488501
void handleMessageSend(messageBody)
489502
}
490503
state={status === 'submitted' ? 'loading' : undefined}
491-
textareaProps={{
492-
placeholder: 'Ask a question',
493-
}}
504+
textareaProps={inputBarTextareaProps}
494505
/>
495506
</div>
496507
<DisclaimerText className={disclaimerTextStyles}>

packages/compass-assistant/src/components/confirmation-message.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ButtonVariant,
77
spacing,
88
css,
9+
cx,
910
palette,
1011
useDarkMode,
1112
} from '@mongodb-js/compass-components';
@@ -42,6 +43,11 @@ const buttonGroupStyles = css({
4243
},
4344
});
4445

46+
const confirmationMessageDarkModeStyles = css({
47+
backgroundColor: palette.gray.dark3,
48+
borderColor: palette.gray.dark2,
49+
});
50+
4551
interface ConfirmationMessageProps {
4652
state: 'confirmed' | 'rejected' | 'pending';
4753
title: string;
@@ -57,11 +63,10 @@ export const ConfirmationMessage: React.FunctionComponent<
5763

5864
return (
5965
<div
60-
className={confirmationMessageStyles}
61-
style={{
62-
backgroundColor: darkMode ? palette.gray.dark3 : palette.gray.light3,
63-
borderColor: darkMode ? palette.gray.dark2 : palette.gray.light2,
64-
}}
66+
className={cx(
67+
confirmationMessageStyles,
68+
darkMode && confirmationMessageDarkModeStyles
69+
)}
6570
>
6671
<Body className={confirmationTitleStyles}>{title}</Body>
6772

packages/compass-components/src/components/actions/item-action-group.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const containerStyle = css({
2121
gap: spacing[100],
2222
});
2323

24+
const itemActionGroupContainerStyles = css({
25+
display: 'inherit',
26+
});
27+
2428
export type ItemActionGroupProps<Action extends string> = {
2529
actions: (GroupedItemAction<Action> | ItemSeparator)[];
2630
onAction(actionName: Action): void;
@@ -98,7 +102,9 @@ export function ItemActionGroup<Action extends string>({
98102
{...tooltipProps}
99103
// Wrapping the item in a div, because the `trigger` must accept and render `children`
100104
// See docs for the prop for more information
101-
trigger={<div style={{ display: 'inherit' }}>{item}</div>}
105+
trigger={
106+
<div className={itemActionGroupContainerStyles}>{item}</div>
107+
}
102108
>
103109
{tooltip}
104110
</Tooltip>

packages/compass-components/src/components/bson-value.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@ export const BSONValueContainer: React.FunctionComponent<
6868
}
6969
> = ({ type, children, className, ...props }) => {
7070
const darkMode = useDarkMode();
71-
const color = useMemo(() => {
71+
const colorStyle = useMemo(() => {
7272
if (!type) {
7373
return;
7474
}
75-
return VALUE_COLOR_BY_THEME_AND_TYPE[darkMode ? Theme.Dark : Theme.Light][
76-
type
77-
];
75+
return {
76+
color:
77+
VALUE_COLOR_BY_THEME_AND_TYPE[darkMode ? Theme.Dark : Theme.Light][
78+
type
79+
],
80+
};
7881
}, [type, darkMode]);
7982

8083
return (
@@ -88,7 +91,7 @@ export const BSONValueContainer: React.FunctionComponent<
8891
type ? type.toLowerCase() : 'unknown'
8992
}`
9093
)}
91-
style={{ color }}
94+
style={colorStyle}
9295
>
9396
{children}
9497
</div>

packages/compass-components/src/components/document-list/element.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -550,30 +550,37 @@ export const HadronElement: React.FunctionComponent<{
550550
}
551551
};
552552

553-
const lineNumberMinWidth = useMemo(() => {
553+
const lineNumberMinWidthStyle = useMemo(() => {
554554
// Only account for ~ line count length if we are in editing mode
555555
if (editingEnabled) {
556556
const charCount = String(lineNumberSize).length;
557-
return charCount > 2 ? `${charCount}.5ch` : spacing[400];
557+
return {
558+
minWidth: charCount > 2 ? `${charCount}.5ch` : spacing[400],
559+
};
558560
}
559-
return spacing[400];
561+
return {
562+
minWidth: spacing[400],
563+
};
560564
}, [lineNumberSize, editingEnabled]);
561565

562-
const elementSpacerWidth = useMemo(
563-
() => calculateElementSpacerWidth(editable, level, extraGutterWidth),
566+
const elementSpacerWidthStyle = useMemo(
567+
() => ({
568+
width: calculateElementSpacerWidth(editable, level, extraGutterWidth),
569+
}),
564570
[editable, level, extraGutterWidth]
565571
);
566572

567573
// To render the "Show more" toggle for the nested expandable elements we need
568574
// to calculate a proper offset so that it aligns with the nesting level
569-
const nestedElementsVisibilityToggleOffset = useMemo(
570-
() =>
571-
calculateShowMoreToggleOffset({
575+
const nestedElementsVisibilityToggleOffsetStyle = useMemo(
576+
() => ({
577+
paddingLeft: calculateShowMoreToggleOffset({
572578
editable,
573579
level,
574580
alignWithNestedExpandIcon: true,
575581
extraGutterWidth,
576582
}),
583+
}),
577584
[editable, level, extraGutterWidth]
578585
);
579586

@@ -649,7 +656,7 @@ export const HadronElement: React.FunctionComponent<{
649656
? lineNumberRemoved
650657
: editingEnabled && !isValid && lineNumberInvalid
651658
)}
652-
style={{ minWidth: lineNumberMinWidth }}
659+
style={lineNumberMinWidthStyle}
653660
>
654661
<div
655662
className={cx(
@@ -684,7 +691,7 @@ export const HadronElement: React.FunctionComponent<{
684691
</div>
685692
</div>
686693
)}
687-
<div className={elementSpacer} style={{ width: elementSpacerWidth }}>
694+
<div className={elementSpacer} style={elementSpacerWidthStyle}>
688695
{/* spacer for nested documents */}
689696
</div>
690697
<div className={elementExpand}>
@@ -849,9 +856,7 @@ export const HadronElement: React.FunctionComponent<{
849856
// this for "performance" reasons
850857
step={editingEnabled ? DEFAULT_VISIBLE_ELEMENTS : 1000}
851858
onSizeChange={handleVisibleElementsChanged}
852-
style={{
853-
paddingLeft: nestedElementsVisibilityToggleOffset,
854-
}}
859+
style={nestedElementsVisibilityToggleOffsetStyle}
855860
></VisibleFieldsToggle>
856861
</>
857862
)}

packages/compass-components/src/components/file-picker-dialog.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ const disabledDescriptionDarkStyles = css({
132132
color: palette.gray.light1,
133133
});
134134

135+
const displayNoneStyles = css({
136+
display: 'none',
137+
});
138+
135139
type FileInputVariant = 'default' | 'small' | 'vertical';
136140

137141
// Matches Electron's file dialog options.
@@ -502,13 +506,13 @@ function FilePickerDialog({
502506
</div>
503507
<input
504508
data-testid={dataTestId ?? 'file-input'}
509+
className={displayNoneStyles}
505510
ref={inputRef}
506511
id={`${id}_file_input`}
507512
name={id}
508513
type="file"
509514
multiple={multi}
510515
onChange={onFilesChanged}
511-
style={{ display: 'none' }}
512516
// Force a re-render when the values change so
513517
// the component is controlled by the prop.
514518
// This is also useful for testing.

packages/compass-components/src/components/file-selector.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import React, { type InputHTMLAttributes, useRef } from 'react';
2+
import { css } from '@leafygreen-ui/emotion';
3+
4+
const displayNoneStyles = css({
5+
display: 'none',
6+
});
27

38
type FileSelectorTriggerProps = {
49
onClick: () => void;
@@ -33,7 +38,7 @@ export function FileSelector({
3338
ref={inputRef}
3439
type="file"
3540
onChange={onFilesChanged}
36-
style={{ display: 'none' }}
41+
className={displayNoneStyles}
3742
/>
3843
{trigger({
3944
onClick: () => inputRef.current?.click(),

packages/compass-components/src/components/icons/logo-icon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const LogoIcon = ({
2222
const fill = color || (darkMode ? palette.white : palette.black);
2323
return (
2424
<svg
25-
className={cx(iconStyles, className, css(`height: ${height}px`))}
25+
className={cx(iconStyles, className)}
2626
height={height}
2727
viewBox="0 0 15 32"
2828
fill="none"

0 commit comments

Comments
 (0)