-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redesign categories and subjects (#2040)
* Redesign categories and subjects * update font weight * create getValidatedHexColor function * update delete icon
- Loading branch information
1 parent
8b4752c
commit 67208b6
Showing
8 changed files
with
149 additions
and
81 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
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,11 @@ | ||
import palette from '~/styles/app-theme/app.pallete' | ||
|
||
const HEX_COLOR_PATTERN = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i | ||
|
||
export const getValidatedHexColor = ( | ||
color: string, | ||
fallbackColor: string = palette.success[500] | ||
): string => { | ||
const isValidHex = HEX_COLOR_PATTERN.test(color) | ||
return isValidHex ? color : fallbackColor | ||
} |
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,32 @@ | ||
import { getValidatedHexColor } from '~/utils/get-validated-hex-color' | ||
import palette from '~/styles/app-theme/app.pallete' | ||
|
||
describe('getValidatedHexColor', () => { | ||
it('should return the color if it is a valid 6-digit hex', () => { | ||
const color = '#FFFFFF' | ||
expect(getValidatedHexColor(color)).toBe(color) | ||
}) | ||
|
||
it('should return the color if it is a valid 3-digit hex', () => { | ||
const color = '#FFF' | ||
expect(getValidatedHexColor(color)).toBe(color) | ||
}) | ||
|
||
it('should return the fallback color if the input is not a valid hex color', () => { | ||
const invalidColor = '#WWWWWW' | ||
expect(getValidatedHexColor(invalidColor)).toBe(palette.success[500]) | ||
}) | ||
|
||
it('should return the fallback color if the input is an empty string', () => { | ||
const invalidColor = '' | ||
expect(getValidatedHexColor(invalidColor)).toBe(palette.success[500]) | ||
}) | ||
|
||
it('should return the custom fallback color if the input is not a valid hex color', () => { | ||
const invalidColor = '#WWWWWW' | ||
const customFallbackColor = '#FF5733' | ||
expect(getValidatedHexColor(invalidColor, customFallbackColor)).toBe( | ||
customFallbackColor | ||
) | ||
}) | ||
}) |