-
Notifications
You must be signed in to change notification settings - Fork 1
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
Initial commit for Additional Theming Variables #6
Open
DanRader
wants to merge
4
commits into
main
Choose a base branch
from
Theming
base: main
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.
+327
−20
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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,164 @@ | ||
function generateColorList(primaryColor, secondaryColor) { | ||
|
||
const themePrimary50 = chroma.mix(primaryColor, 'white', 0.9, 'hsl').hex(); | ||
const themePrimary200 = chroma.mix(primaryColor, 'white', 0.6, 'hsl').hex(); | ||
const themePrimary300 = chroma.mix(primaryColor, 'white', 0.4, 'hsl').hex(); | ||
const themePrimary400 = chroma.mix(primaryColor, 'white', 0.2, 'hsl').hex(); | ||
const themePrimary500 = chroma(primaryColor).hex(); | ||
const themePrimary600 = chroma.mix(primaryColor, 'black', 0.2, 'hsl').hex(); | ||
const themePrimaryGradStart = chroma.mix(primaryColor, 'white', 0.2, 'hsl').alpha(.2).hex(); | ||
const themePrimaryGradEnd = chroma.mix(primaryColor, 'white', 0.2, 'hsl').alpha(.0).hex(); | ||
|
||
const themeSecondary50 = chroma.mix(secondaryColor, 'white', 0.9, 'hsl').hex(); | ||
const themeSecondary200 = chroma.mix(secondaryColor, 'white', 0.6, 'hsl').hex(); | ||
const themeSecondary300 = chroma.mix(secondaryColor, 'white', 0.4, 'hsl').hex(); | ||
const themeSecondary400 = chroma.mix(secondaryColor, 'white', 0.2, 'hsl').hex(); | ||
const themeSecondary500 = chroma(secondaryColor).hex(); | ||
const themeSecondary600 = chroma.mix(secondaryColor, 'black', 0.2, 'hsl').hex(); | ||
const themeSecondaryGradStart = chroma.mix(secondaryColor, 'white', 0.2, 'hsl').alpha(.2).hex(); | ||
const themeSecondaryGradEnd = chroma.mix(secondaryColor, 'white', 0.2, 'hsl').alpha(.0).hex(); | ||
|
||
// contrast | ||
|
||
const contrastTarget = 4.5 | ||
const textPrimary = _styleDictionary.color.text.primary.lm.value | ||
var themePrimaryTextOn = "" | ||
var themeSecondaryTextOn = "" | ||
|
||
const primaryContrast = chroma.contrast(textPrimary, primaryColor); | ||
const secondaryContrast = chroma.contrast(textPrimary, secondaryColor); | ||
|
||
if (primaryContrast > contrastTarget) { | ||
themePrimaryTextOn = _styleDictionary.color.text.primary.lm.value | ||
} else { | ||
themePrimaryTextOn = _styleDictionary.color.text.reverse.lm.value | ||
} | ||
|
||
if (secondaryContrast > contrastTarget) { | ||
themeSecondaryTextOn = _styleDictionary.color.text.primary.lm.value | ||
} else { | ||
themeSecondaryTextOn = _styleDictionary.color.text.reverse.lm.value | ||
} | ||
|
||
const colorList = { | ||
theme: { | ||
primary: { | ||
main: { | ||
lm: themePrimary500, | ||
dm: themePrimary200 | ||
}, | ||
focus: { | ||
lm: themePrimary600, | ||
dm: themePrimary300 | ||
}, | ||
surface: { | ||
lm: themePrimary50, | ||
dm: ColorBackground2Dm | ||
}, | ||
textOn: { | ||
lm: themePrimary500, | ||
dm: themePrimary200 | ||
}, | ||
gradientStart: { | ||
lm: themePrimary400, | ||
dm: themePrimaryGradStart | ||
}, | ||
gradientEnd: { | ||
lm: themePrimary500, | ||
dm: themePrimaryGradEnd | ||
}, | ||
textOn: { | ||
lm: themePrimaryTextOn, | ||
dm: ColorTextPrimaryDm | ||
}, | ||
}, | ||
secondary: { | ||
main: { | ||
lm: themeSecondary500, | ||
dm: themeSecondary200 | ||
}, | ||
focus: { | ||
lm: themeSecondary600, | ||
dm: themeSecondary300 | ||
}, | ||
surface: { | ||
lm: themeSecondary50, | ||
dm: ColorBackground2Dm | ||
}, | ||
textOn: { | ||
lm: themeSecondary500, | ||
dm: themeSecondary200 | ||
}, | ||
gradientStart: { | ||
lm: themeSecondary400, | ||
dm: themeSecondaryGradStart | ||
}, | ||
gradientEnd: { | ||
lm: themeSecondary500, | ||
dm: themeSecondaryGradEnd | ||
}, | ||
surfaceGradientStart: { | ||
lm: themeSecondary50, | ||
dm: themeSecondaryGradStart | ||
}, | ||
surfaceGradientEnd: { | ||
lm: themeSecondary50, | ||
dm: themeSecondaryGradEnd | ||
}, | ||
textOn: { | ||
lm: themeSecondaryTextOn, | ||
dm: ColorTextPrimaryDm | ||
}, | ||
} | ||
}, | ||
fixed: { | ||
foreground: { | ||
lm: ColorForegroundLm, | ||
dm: ColorForegroundDm | ||
}, | ||
background: { | ||
lm: ColorBackgroundLm, | ||
dm: ColorBackgroundDm | ||
}, | ||
background2: { | ||
lm: ColorBackground2Lm, | ||
dm: ColorBackground2Dm | ||
}, | ||
stroke: { | ||
lm: ColorStrokeLm, | ||
dm: ColorStrokeDm | ||
}, | ||
disabled: { | ||
lm: ColorActionDisabledLm, | ||
dm: ColorActionDisabledDm | ||
}, | ||
buttontextprimary: { | ||
lm: ColorTextPrimaryLm, | ||
dm: ColorTextPrimaryLm | ||
}, | ||
text: { | ||
primary: { | ||
lm: ColorTextPrimaryLm, | ||
dm: ColorTextPrimaryDm | ||
}, | ||
secondary: { | ||
lm: ColorTextSecondaryLm, | ||
dm: ColorTextSecondaryDm | ||
}, | ||
reverse: { | ||
lm: ColorTextReverseLm, | ||
dm: ColorTextReverseDm | ||
}, | ||
warning: { | ||
lm: ColorTextWarningLm, | ||
dm: ColorTextWarningDm | ||
}, | ||
success: { | ||
lm: ColorPositiveLm, | ||
dm: ColorPositiveDm | ||
} | ||
} | ||
} | ||
} | ||
return colorList; | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This basically changes the output so that variables can be used more directly. The other format was causing problems because some of the names had hyphens and It didn't like it.
in UMD it looked like
background2: {
lm: _styleDitcionary.color.background-2.lm.value,
dm: color.background-2.dm.value
},
in ES6 it looks like
background2: {
lm: ColorBackground2Lm,
dm: ColorBackground2Dm
},