-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2371] Improve color management in View
Bug: #2371 Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
- Loading branch information
1 parent
b03349d
commit ba95fc9
Showing
71 changed files
with
1,415 additions
and
216 deletions.
There are no files selected for viewing
This file contains 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 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 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
99 changes: 99 additions & 0 deletions
99
packages/core/frontend/sirius-components-core/src/color/getCSSColor.ts
This file contains 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,99 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
import { | ||
amber, | ||
blue, | ||
blueGrey, | ||
brown, | ||
common, | ||
cyan, | ||
deepOrange, | ||
deepPurple, | ||
green, | ||
grey, | ||
indigo, | ||
lightBlue, | ||
lightGreen, | ||
lime, | ||
orange, | ||
pink, | ||
purple, | ||
red, | ||
teal, | ||
yellow, | ||
} from '@material-ui/core/colors'; | ||
import { Theme } from '@material-ui/core/styles'; | ||
|
||
const muiColors = { | ||
amber: amber, | ||
blue: blue, | ||
blueGrey: blueGrey, | ||
brown: brown, | ||
common: common, | ||
cyan: cyan, | ||
deepOrange: deepOrange, | ||
deepPurple: deepPurple, | ||
green: green, | ||
grey: grey, | ||
indigo: indigo, | ||
lightBlue: lightBlue, | ||
lightGreen: lightGreen, | ||
lime: lime, | ||
orange: orange, | ||
pink: pink, | ||
purple: purple, | ||
red: red, | ||
teal: teal, | ||
yellow: yellow, | ||
}; | ||
|
||
export const getCSSColor = (value: string, theme: Theme): string | null => { | ||
let cssColor: string | null = null; | ||
if (value) { | ||
if (value === 'theme.palette.primary.main') { | ||
cssColor = theme.palette.primary.main; | ||
} else if (value === 'theme.palette.primary.light') { | ||
cssColor = theme.palette.primary.light; | ||
} else if (value === 'theme.palette.primary.dark') { | ||
cssColor = theme.palette.primary.dark; | ||
} else if (value === 'theme.palette.secondary.main') { | ||
cssColor = theme.palette.secondary.main; | ||
} else if (value === 'theme.palette.secondary.light') { | ||
cssColor = theme.palette.secondary.light; | ||
} else if (value === 'theme.palette.secondary.dark') { | ||
cssColor = theme.palette.secondary.dark; | ||
} else if (value === 'theme.palette.text.primary') { | ||
cssColor = theme.palette.text.primary; | ||
} else if (value === 'theme.palette.text.disabled') { | ||
cssColor = theme.palette.text.disabled; | ||
} else if (value === 'theme.palette.text.hint') { | ||
cssColor = theme.palette.text.hint; | ||
} else if (value === 'theme.palette.error.main') { | ||
cssColor = theme.palette.error.main; | ||
} else if (value === 'theme.palette.error.light') { | ||
cssColor = theme.palette.error.light; | ||
} else if (value === 'theme.palette.error.dark') { | ||
cssColor = theme.palette.error.dark; | ||
} else { | ||
const colorName: string = value.substring(0, value.indexOf('[')); | ||
const colorValue: string = value.substring(value.indexOf('[') + 1, value.length - 1); | ||
if (colorName && colorValue) { | ||
cssColor = muiColors[colorName][colorValue]; | ||
} | ||
if (!cssColor) { | ||
cssColor = value; | ||
} | ||
} | ||
} | ||
return cssColor; | ||
}; |
This file contains 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 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.