Skip to content

Commit e8ff69d

Browse files
authored
getTintColor support options, should reverse on dark prop (#2321)
* getTintColor support options, should reverse on dark prop * Fixed review notes * Changed shouldReverseOnDark option prop to avoidReverseOnDark and funciton logic
1 parent 85157b1 commit e8ff69d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/style/colors.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Scheme, {Schemes, SchemeType} from './scheme';
1212

1313
export type DesignToken = {semantic?: [string]; resource_paths?: [string]; toString: Function};
1414
export type TokensOptions = {primaryColor: string};
15+
export type GetColorTintOptions = {avoidReverseOnDark?: boolean};
1516

1617
export class Colors {
1718
[key: string]: any;
@@ -162,7 +163,7 @@ export class Colors {
162163
return validColors ? undefined : results[0];
163164
}
164165

165-
getColorTint(colorValue: string | OpaqueColorValue, tintKey: string | number) {
166+
getColorTint(colorValue: string | OpaqueColorValue, tintKey: string | number, options: GetColorTintOptions = {}) {
166167
if (_.isUndefined(tintKey) || isNaN(tintKey as number) || _.isUndefined(colorValue)) {
167168
// console.error('"Colors.getColorTint" must accept a color and tintKey params');
168169
return colorValue;
@@ -179,10 +180,9 @@ export class Colors {
179180
if (colorKey) {
180181
const colorKeys = [1, 5, 10, 20, 30, 40, 50, 60, 70, 80];
181182
const keyIndex = _.indexOf(colorKeys, Number(tintKey));
182-
const key =
183-
this.shouldSupportDarkMode && Scheme.getSchemeType() === 'dark'
184-
? colorKeys[colorKeys.length - 1 - keyIndex]
185-
: tintKey;
183+
const shouldReverseOnDark =
184+
!options?.avoidReverseOnDark && this.shouldSupportDarkMode && Scheme.getSchemeType() === 'dark';
185+
const key = shouldReverseOnDark ? colorKeys[colorKeys.length - 1 - keyIndex] : tintKey;
186186
const requiredColorKey = `${colorKey.slice(0, -2)}${key}`;
187187
const requiredColor = this[requiredColorKey];
188188

0 commit comments

Comments
 (0)