-
Notifications
You must be signed in to change notification settings - Fork 212
feat(compass-components): add dark mode flag for using theme in components instead of darkreader COMPASS-5520 #2856
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ec88f28
Add theme HOC
Anemy f2ea714
Merge branch 'main' into COMPASS-5520-add-leafygreen-dark-mode-flag
Anemy 45c56a8
Add wraps around lg
Anemy 5a5b5b6
dont enable darkreader when flag is on, use wrapped components in oth…
Anemy 3fbb076
remove extra comments
Anemy b465546
Merge branch 'main' into COMPASS-5520-add-leafygreen-dark-mode-flag
Anemy 2b6148c
update scheme to schema where used in form
Anemy 0e97d3b
use explicit type casting with themed wrapped leafygreen components t…
Anemy 06aa9dd
forward ref in hoc
Anemy 806608e
remove comment
Anemy b07018e
Add example using theme in file-input
Anemy f15a9f7
Make darkMode param optional
Anemy 140cb50
Explicit cast result of generic forward ref, add theme props to with …
Anemy 7af2fbb
Merge branch 'main' into COMPASS-5520-add-leafygreen-dark-mode-flag
Anemy 447180a
update e2e test selectors
Anemy 02b7c95
fix-tls-selector
Anemy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/compass-components/src/components/confirmation-modal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/compass-components/src/components/inline-definition.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/compass-components/src/components/inline-info-link.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
packages/compass-components/src/components/leafygreen.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
import type React from 'react'; | ||
|
||
import { withTheme } from '../hooks/use-theme'; | ||
|
||
// This file exports `@leafygreen-ui` components and wraps some of | ||
// them with a listener to Compass' theme in the react context. | ||
|
||
// 1. Import the components we use from leafygreen. | ||
import { default as Badge } from '@leafygreen-ui/badge'; | ||
import { default as Banner } from '@leafygreen-ui/banner'; | ||
import { default as LeafyGreenButton } from '@leafygreen-ui/button'; | ||
import { default as LeafyGreenCheckbox } from '@leafygreen-ui/checkbox'; | ||
import { default as LeafyGreenCard } from '@leafygreen-ui/card'; | ||
import { default as LeafyGreenConfirmationModal } from '@leafygreen-ui/confirmation-modal'; | ||
import { default as Icon } from '@leafygreen-ui/icon'; | ||
import { default as LeafyGreenIconButton } from '@leafygreen-ui/icon-button'; | ||
import { | ||
AtlasLogoMark, | ||
MongoDBLogoMark, | ||
MongoDBLogo, | ||
} from '@leafygreen-ui/logo'; | ||
import { Menu, MenuSeparator, MenuItem } from '@leafygreen-ui/menu'; | ||
import { | ||
default as LeafyGreenModal, | ||
Footer as LeafyGreenFooter, | ||
} from '@leafygreen-ui/modal'; | ||
import { RadioBox, RadioBoxGroup } from '@leafygreen-ui/radio-box-group'; | ||
import { | ||
Radio, | ||
RadioGroup as LeafyGreenRadioGroup, | ||
} from '@leafygreen-ui/radio-group'; | ||
import { | ||
SegmentedControl as LeafyGreenSegmentedControl, | ||
SegmentedControlOption, | ||
} from '@leafygreen-ui/segmented-control'; | ||
import { | ||
Select as LeafyGreenSelect, | ||
Option, | ||
OptionGroup, | ||
} from '@leafygreen-ui/select'; | ||
import { | ||
Table as LeafyGreenTable, | ||
TableHeader, | ||
Row, | ||
Cell, | ||
} from '@leafygreen-ui/table'; | ||
import { Tabs as LeafyGreenTabs, Tab } from '@leafygreen-ui/tabs'; | ||
import { default as LeafyGreenTextArea } from '@leafygreen-ui/text-area'; | ||
import { default as LeafyGreenTextInput } from '@leafygreen-ui/text-input'; | ||
import { default as Toast } from '@leafygreen-ui/toast'; | ||
import { default as LeafyGreenToggle } from '@leafygreen-ui/toggle'; | ||
import { default as LeafyGreenTooltip } from '@leafygreen-ui/tooltip'; | ||
import { | ||
H1, | ||
H2, | ||
H3, | ||
Subtitle, | ||
Body, | ||
InlineCode, | ||
InlineKeyCode, | ||
Disclaimer, | ||
Overline, | ||
Label as LeafyGreenLabel, | ||
Link, | ||
Description as LeafyGreenDescription, | ||
} from '@leafygreen-ui/typography'; | ||
|
||
// 2. Wrap the components that accept darkMode with Compass' theme. | ||
const Button = withTheme( | ||
LeafyGreenButton as React.ComponentType< | ||
React.ComponentProps<typeof LeafyGreenButton> | ||
> | ||
) as typeof LeafyGreenButton; | ||
const Card: typeof LeafyGreenCard = withTheme( | ||
LeafyGreenCard as React.ComponentType< | ||
React.ComponentProps<typeof LeafyGreenCard> | ||
> | ||
) as typeof LeafyGreenCard; | ||
const Checkbox = withTheme( | ||
LeafyGreenCheckbox as React.ComponentType< | ||
React.ComponentProps<typeof LeafyGreenCheckbox> | ||
> | ||
) as typeof LeafyGreenCheckbox; | ||
const ConfirmationModal: typeof LeafyGreenConfirmationModal = withTheme( | ||
LeafyGreenConfirmationModal as React.ComponentType< | ||
React.ComponentProps<typeof LeafyGreenConfirmationModal> | ||
> | ||
) as typeof LeafyGreenConfirmationModal; | ||
const IconButton: typeof LeafyGreenIconButton = withTheme( | ||
LeafyGreenIconButton as React.ComponentType< | ||
React.ComponentProps<typeof LeafyGreenIconButton> | ||
> | ||
) as typeof LeafyGreenIconButton; | ||
const Footer: typeof LeafyGreenFooter = withTheme( | ||
LeafyGreenFooter | ||
) as typeof LeafyGreenFooter; | ||
const Modal = withTheme( | ||
LeafyGreenModal as React.ComponentType< | ||
React.ComponentProps<typeof LeafyGreenModal> | ||
> | ||
) as typeof LeafyGreenModal; | ||
const RadioGroup: typeof LeafyGreenRadioGroup = withTheme( | ||
LeafyGreenRadioGroup as React.ComponentType< | ||
React.ComponentProps<typeof LeafyGreenRadioGroup> | ||
> | ||
) as typeof LeafyGreenRadioGroup; | ||
const SegmentedControl: typeof LeafyGreenSegmentedControl = withTheme( | ||
LeafyGreenSegmentedControl | ||
) as typeof LeafyGreenSegmentedControl; | ||
const Select: typeof LeafyGreenSelect = withTheme( | ||
LeafyGreenSelect as React.ComponentType< | ||
React.ComponentProps<typeof LeafyGreenSelect> | ||
> | ||
) as typeof LeafyGreenSelect; | ||
const Table = withTheme(LeafyGreenTable) as typeof LeafyGreenTable; | ||
const Tabs = withTheme( | ||
LeafyGreenTabs as React.ComponentType< | ||
React.ComponentProps<typeof LeafyGreenTabs> | ||
> | ||
) as typeof LeafyGreenTabs; | ||
const TextArea: typeof LeafyGreenTextArea = withTheme(LeafyGreenTextArea); | ||
const TextInput: typeof LeafyGreenTextInput = withTheme(LeafyGreenTextInput); | ||
const Toggle = withTheme( | ||
LeafyGreenToggle as React.ComponentType< | ||
React.ComponentProps<typeof LeafyGreenToggle> | ||
> | ||
) as typeof LeafyGreenToggle; | ||
const Tooltip = withTheme( | ||
LeafyGreenTooltip as React.ComponentType< | ||
React.ComponentProps<typeof LeafyGreenTooltip> | ||
> | ||
) as typeof LeafyGreenTooltip; | ||
const Label = withTheme(LeafyGreenLabel) as typeof LeafyGreenLabel; | ||
const Description = withTheme( | ||
LeafyGreenDescription | ||
) as typeof LeafyGreenDescription; | ||
|
||
// 3. Export the leafygreen components. | ||
export { | ||
AtlasLogoMark, | ||
Badge, | ||
Banner, | ||
Button, | ||
Card, | ||
Checkbox, | ||
ConfirmationModal, | ||
Icon, | ||
IconButton, | ||
Footer, | ||
Menu, | ||
MenuItem, | ||
MenuSeparator, | ||
Modal, | ||
MongoDBLogoMark, | ||
MongoDBLogo, | ||
RadioBox, | ||
RadioBoxGroup, | ||
Radio, | ||
RadioGroup, | ||
SegmentedControl, | ||
SegmentedControlOption, | ||
Select, | ||
Option, | ||
OptionGroup, | ||
Table, | ||
TableHeader, | ||
Row, | ||
Cell, | ||
Tab, | ||
Tabs, | ||
TextArea, | ||
TextInput, | ||
Toast, | ||
Toggle, | ||
Tooltip, | ||
H1, | ||
H2, | ||
H3, | ||
Subtitle, | ||
Body, | ||
InlineCode, | ||
InlineKeyCode, | ||
Disclaimer, | ||
Overline, | ||
Label, | ||
Link, | ||
Description, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/compass-components/src/components/radio-box-group.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Working on a cleaner way to type the high order component that wraps these so we don't have to do this type casting.
We'll want to use this wrapper with some of our own custom components - checking to make sure those types work well too.
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.
Ok! let me know when i can review again
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.
Added
withTheme
to theFileInput
as an example/test of using the theme in a custom component, works smooth. I spent a while trying to get these types for these leafygreen components to work nicely yesterday and was having trouble finding a clean way without casting explicitly here. Do you think it's a blocker for merging? I'd be down to pair on looking at thewithTheme
hoc to see if there's anything we can do to avoid casts. If we do merge I'd definitely want to solidify these types before the epic is done, but for now we would be able to unblock theming other parts of this epic.It appears typescript tries to compare the inferred react prop types with the typescript prop definition and that results in a typing/compile error. To get around this we explicitly cast them to their leafygreen types.
Here's examples of the two errors we were seeing:
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.
@mcasimir Pushed an update to make the components that use the
withTheme
wrapper require an optionaldarkMode
prop. Also added an explicit cast to the generic type in the hoc.There's a good answer on it here: https://stackoverflow.com/a/58473012