-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(themes): enable dynamic values for interactive color tokens (#5269)
- Loading branch information
Showing
9 changed files
with
82 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright IBM Corp. 2018, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @jest-environment node | ||
*/ | ||
|
||
import Color from 'color'; | ||
import { adjustLightness } from '../tools'; | ||
import { blue60 } from '@carbon/colors'; | ||
|
||
describe('tools', () => { | ||
describe('adjustLightness', () => { | ||
const SHIFT_AMOUNT = 5; | ||
|
||
const baseColor = Color(blue60); | ||
const baseLightness = baseColor | ||
.hsl() | ||
.round() | ||
.object().l; | ||
|
||
it('should increase lightness by a specified amount', () => { | ||
const newColor = Color(adjustLightness(blue60, SHIFT_AMOUNT)); | ||
const newLightness = newColor | ||
.hsl() | ||
.round() | ||
.object().l; | ||
expect(newLightness).toEqual(baseLightness + SHIFT_AMOUNT); | ||
}); | ||
|
||
it('should decrease lightness by a specified amount when given a negative shift', () => { | ||
const newColor = Color(adjustLightness(blue60, SHIFT_AMOUNT * -1)); | ||
const newLightness = newColor | ||
.hsl() | ||
.round() | ||
.object().l; | ||
|
||
expect(newLightness).toEqual(baseLightness - SHIFT_AMOUNT); | ||
}); | ||
}); | ||
}); |
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
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,27 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import Color from 'color'; | ||
|
||
/** | ||
* Adjust a given token's lightness by a specified percentage | ||
* Example: token = hsl(10, 10, 10); | ||
* adjustLightness(token, 5) === hsl(10, 10, 15); | ||
* adjustLightness(token, -5) === hsl(10, 10, 5); | ||
* @param {string} token | ||
* @param {integer} shift The number of percentage points (positive or negative) by which to shift the lightness of a token. | ||
* @returns {string} | ||
*/ | ||
export function adjustLightness(token, shift) { | ||
const original = Color(token) | ||
.hsl() | ||
.object(); | ||
|
||
return Color({ ...original, l: (original.l += shift) }) | ||
.round() | ||
.hex() | ||
.toLowerCase(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6708,7 +6708,7 @@ [email protected]: | |
color-convert "^1.9.1" | ||
color-string "^1.5.2" | ||
|
||
color@^3.0.0: | ||
color@^3.0.0, color@^3.1.2: | ||
version "3.1.2" | ||
resolved "https://registry.yarnpkg.com/color/-/color-3.1.2.tgz#68148e7f85d41ad7649c5fa8c8106f098d229e10" | ||
integrity sha512-vXTJhHebByxZn3lDvDJYw4lR5+uB3vuoHsuYA5AKuxRVn5wzzIfQKGLBmgdVRHKTJYeK5rvJcHnrd0Li49CFpg== | ||
|