-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(ui-next): Adds appearance dialog with theme presets and custom theme support #6041
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
Open
dan-rukas
wants to merge
30
commits into
OHIF:master
Choose a base branch
from
dan-rukas:feat/appearance-dialog-simple
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+868
−3
Open
Changes from 11 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
80baba9
Remove hard coded colors
dan-rukas f6806dd
Removed hard coded colors from icons
dan-rukas 969a9e5
Fix helper icon colors
dan-rukas 21e555d
Revert legacy ui icons to hard coded colors
dan-rukas 1986e02
Fixes for loading spinner in toast
dan-rukas cf08bda
Simpler theme apply
dan-rukas 351c5a6
Add i18n for appearance modal strings
dan-rukas b1bb5be
Fix classList mutation during iteration in ActiveThemeProvider cleanup
dan-rukas 887f2e0
Remove duplicate className
dan-rukas 12b16f0
Sanitize custom theme input to prevent CSS injection
dan-rukas 179c56c
Remove duplicated custom theme cleanup from appearance modal
dan-rukas 67a7990
Clean up unused prop, unnecessary directive, and redundant theme tokens
dan-rukas 852dbf4
Centralize theme state in ActiveThemeProvider and fix custom theme re…
dan-rukas e3bedd0
Merge branch 'OHIF:master' into feat/appearance-dialog-simple
dan-rukas 1d16c7d
Merge branch 'OHIF:master' into feat/appearance-dialog-simple
dan-rukas 2592507
Merge branch 'OHIF:master' into fix/hardcoded-colors
dan-rukas f6f74c8
Merge branch 'fix/hardcoded-colors' into feat/appearance-dialog-simple
dan-rukas 6e96854
Merge branch 'OHIF:master' into feat/appearance-dialog-simple
dan-rukas 5f621b5
Merge branch 'feat/appearance-dialog-simple' of https://github.com/da…
dan-rukas a5e5f96
Revert "Merge branch 'fix/hardcoded-colors' into feat/appearance-dial…
dan-rukas ada965f
strip CSS comment tokens from custom theme input
dan-rukas ef7296b
harden custom CSS parsing and theme state validation
dan-rukas 3b8faad
Merge branch 'master' into feat/appearance-dialog-simple
dan-rukas 40b0a94
Added Appearance dialog to ui-next Study List
dan-rukas 03c4aed
Merge branch 'master' into feat/appearance-dialog-simple
dan-rukas 44d2e14
Merge branch 'master' into feat/appearance-dialog-simple
dan-rukas 53b5701
make Appearance dialog opt-in via named customization module
dan-rukas 7635fb2
rename theme module + conditional ActiveThemeProvider
dan-rukas 7ae5eae
move ActiveThemeProvider registration to extension via serviceProvide…
dan-rukas 71fd609
Merge branch 'master' into feat/appearance-dialog-simple
dan-rukas 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
128 changes: 128 additions & 0 deletions
128
extensions/default/src/customizations/appearanceModalCustomization.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,128 @@ | ||
| import React from 'react'; | ||
| import { | ||
| AppearanceModal, | ||
| Select, | ||
| SelectTrigger, | ||
| SelectValue, | ||
| SelectContent, | ||
| SelectItem, | ||
| Button, | ||
| useActiveTheme, | ||
| themePresets, | ||
| } from '@ohif/ui-next'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| function AppearanceModalDefault() { | ||
| const { activeTheme, setActiveTheme, customCss, applyCustomTheme, clearCustomTheme } = | ||
| useActiveTheme(); | ||
| const { t } = useTranslation('AppearanceModal'); | ||
|
|
||
| const [draftCss, setDraftCss] = React.useState(() => customCss); | ||
| const [isCustomOpen, setIsCustomOpen] = React.useState(() => activeTheme === 'custom'); | ||
|
|
||
| const handleToggleCustom = () => { | ||
| setIsCustomOpen(!isCustomOpen); | ||
| }; | ||
|
|
||
| const handleSave = () => { | ||
| applyCustomTheme(draftCss); | ||
| }; | ||
|
|
||
| const handleClear = () => { | ||
| clearCustomTheme(); | ||
| setDraftCss(''); | ||
| setIsCustomOpen(false); | ||
| }; | ||
|
|
||
| const handlePresetChange = (value: string) => { | ||
| if (value === 'custom') { | ||
| setIsCustomOpen(true); | ||
| if (draftCss) { | ||
| applyCustomTheme(draftCss); | ||
| } | ||
| } else { | ||
| setIsCustomOpen(false); | ||
| setActiveTheme(value); | ||
| } | ||
| }; | ||
|
|
||
| const handleTextChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
| setDraftCss(e.target.value); | ||
| }; | ||
|
|
||
| return ( | ||
| <AppearanceModal> | ||
| <AppearanceModal.Body> | ||
| <div className="grid grid-cols-[auto_1fr] items-center gap-x-6 gap-y-4"> | ||
| <AppearanceModal.SectionLabel>{t('Theme')}</AppearanceModal.SectionLabel> | ||
| <div> | ||
| <Select | ||
| value={activeTheme} | ||
| onValueChange={handlePresetChange} | ||
| > | ||
| <SelectTrigger className="w-[200px]"> | ||
| <SelectValue /> | ||
| </SelectTrigger> | ||
| <SelectContent> | ||
| <SelectItem value="default">{t('Default Theme')}</SelectItem> | ||
| {themePresets.map(preset => ( | ||
| <SelectItem | ||
| key={preset.name} | ||
| value={preset.name} | ||
| > | ||
| {preset.label} | ||
| </SelectItem> | ||
| ))} | ||
| {(customCss || draftCss) && ( | ||
| <SelectItem value="custom">{t('Custom')}</SelectItem> | ||
| )} | ||
| </SelectContent> | ||
| </Select> | ||
| </div> | ||
|
|
||
| <div className="col-start-2"> | ||
| <Button | ||
| variant="ghost" | ||
| size="sm" | ||
| onClick={handleToggleCustom} | ||
| > | ||
| {isCustomOpen ? t('Hide') : t('Custom Theme')} | ||
| </Button> | ||
| </div> | ||
| </div> | ||
|
|
||
| {isCustomOpen && ( | ||
| <div className="mt-4 flex flex-col space-y-2"> | ||
| <textarea | ||
| value={draftCss} | ||
| onChange={handleTextChange} | ||
| placeholder={t('Paste your custom theme color tokens here')} | ||
| rows={8} | ||
| className="bg-muted text-foreground border-input placeholder:text-muted-foreground rounded-md border px-3 py-2 font-mono text-sm focus:outline-none focus:ring-1 focus:ring-inset focus:ring-ring" | ||
| /> | ||
| <div className="flex space-x-2"> | ||
| <Button | ||
| variant="default" | ||
| size="sm" | ||
| onClick={handleSave} | ||
| > | ||
| {t('Apply')} | ||
| </Button> | ||
| <Button | ||
| variant="ghost" | ||
| size="sm" | ||
| onClick={handleClear} | ||
| > | ||
| {t('Clear')} | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </AppearanceModal.Body> | ||
| </AppearanceModal> | ||
| ); | ||
| } | ||
|
|
||
| export default { | ||
| 'ohif.appearanceModal': AppearanceModalDefault, | ||
| }; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "Appearance": "Appearance", | ||
| "Theme": "Theme", | ||
| "Default Theme": "Tonal: OHIF Blue", | ||
| "Custom": "Custom", | ||
| "Custom Theme": "Custom Theme", | ||
| "Hide": "Hide", | ||
| "Apply": "Apply", | ||
| "Clear": "Clear", | ||
| "Paste your custom theme color tokens here": "Paste your custom theme color tokens here" | ||
| } |
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
38 changes: 38 additions & 0 deletions
38
platform/ui-next/src/components/OHIFModals/AppearanceModal.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,38 @@ | ||
| import * as React from 'react'; | ||
| import { cn } from '../../lib/utils'; | ||
|
|
||
| interface AppearanceModalProps { | ||
| children: React.ReactNode; | ||
| className?: string; | ||
| } | ||
|
|
||
| export function AppearanceModal({ children, className }: AppearanceModalProps) { | ||
| return ( | ||
| <div className={cn('flex max-h-[80vh] w-full max-w-md flex-col overflow-hidden', className)}> | ||
| {children} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| interface BodyProps { | ||
| children: React.ReactNode; | ||
| className?: string; | ||
| } | ||
| function Body({ children, className }: BodyProps) { | ||
| return ( | ||
| <div className={cn('flex-1 overflow-y-auto', className)}> | ||
| <div className="mt-1 mb-4 flex flex-col space-y-4">{children}</div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| interface SectionLabelProps { | ||
| children: React.ReactNode; | ||
| className?: string; | ||
| } | ||
| function SectionLabel({ children, className }: SectionLabelProps) { | ||
| return <span className={cn('text-muted-foreground text-lg', className)}>{children}</span>; | ||
| } | ||
|
|
||
| AppearanceModal.Body = Body; | ||
| AppearanceModal.SectionLabel = SectionLabel; |
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export { UserPreferencesModal } from './UserPreferencesModal'; | ||
| export { ImageModal } from './ImageModal'; | ||
| export { AboutModal } from './AboutModal'; | ||
| export { AppearanceModal } from './AppearanceModal'; |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.