Skip to content
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
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 69 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@
"showFileHeader": false,
"outputReferences": true
}
},
{
"destination": "theme.css",
"format": "scss/variables",
"filter": {
"attributes": {
"category": "theme"
}
},
"options": {
"showFileHeader": true,
"outputReferences": true
}
}
]
},
Expand All @@ -29,16 +42,30 @@
"showFileHeader": true,
"outputReferences": true
}
},
{
"destination": "_theme.scss",
"format": "scss/variables",
"filter": {
"attributes": {
"category": "theme"
}
},
"options": {
"showFileHeader": true,
"outputReferences": true
}
}
]
},

"js": {
"buildPath": "build/js/",
"transformGroup": "js",
"files": [
{
"destination": "colors.js",
"format": "javascript/umd",
"format": "javascript/es6",
Copy link
Contributor Author

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
},

"filter": {
"attributes": {
"category": "color"
Expand All @@ -50,7 +77,7 @@
},
{
"destination": "font.js",
"format": "javascript/umd",
"format": "javascript/es6",
"filter": {
"attributes": {
"category": "font"
Expand All @@ -59,6 +86,18 @@
"options": {
"outputReferences": true
}
},
{
"destination": "theme.js",
"format": "javascript/es6",
"filter": {
"attributes": {
"category": "theme"
}
},
"options": {
"outputReferences": true
}
}
]
},
Expand Down Expand Up @@ -87,6 +126,18 @@
"category": "color"
}
}
},
{
"destination": "theme.xml",
"format": "android/resources",
"options": {
"outputReferences": true
},
"filter": {
"attributes": {
"category": "theme"
}
}
}
]
},
Expand All @@ -96,7 +147,7 @@
"prefix": "xpl",
"files": [
{
"destination": "StyleDictionaryColor.swift",
"destination": "ApolloFoundationColor.swift",
"format": "ios-swift/enum.swift",
"className": "StyleDictionaryColor",
"options": {
Expand All @@ -109,7 +160,7 @@
}
},
{
"destination": "StyleDictionaryFont.swift",
"destination": "ApolloFoundationSize.swift",
"format": "ios-swift/enum.swift",
"className": "StyleDictionaryFont",
"type": "float",
Expand All @@ -121,6 +172,20 @@
"category": "size"
}
}
},
{
"destination": "ApolloFoundationTheme.swift",
"format": "ios-swift/enum.swift",
"className": "StyleDictionaryFont",
"type": "float",
"options": {
"outputReferences": true
},
"filter": {
"attributes": {
"category": "theme"
}
}
}
]
}
Expand Down
164 changes: 164 additions & 0 deletions theming/colorGen.js
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;
}
6 changes: 3 additions & 3 deletions tokens/color/SemanticPalette.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
"dm": {"value": "{color.transparent.value}"}
},
"information": {
"lm": {"value": "{color.secondary.lm.value}","comment": "uses themable token"},
"dm": {"value": "{color.secondary.dm.value}","comment": "uses themable token"}
"lm": {"value": "{color.secondary.lm.value}"},
"dm": {"value": "{color.secondary.dm.value}"}
},
"information-bg": {
"lm": {"value": "{color.secondary-bg.lm.value}","comment": "uses themable token"},
"lm": {"value": "{color.secondary-bg.lm.value}"},
"dm": {"value": "{color.transparent.value}"}
},
"trivial": {
Expand Down
3 changes: 2 additions & 1 deletion tokens/color/accentPalette.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"green": {"value": "{color.green.200.value}"},
"yellow": {"value": "{color.yellow.200.value}"},
"pink": {"value": "{color.pink.300.value}"},
"purple": {"value": "{color.purple.300.value}"}
"purple": {"value": "{color.purple.300.value}"},
"blue": {"value": "{color.blue.200.value}"}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions tokens/color/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@
"800": {"value": "#961305ff"},
"900": {"value": "#731409ff"}
},
"blue": {
"50": {"value": "#0F3999FF"},
"100": {"value": "#2253B3FF"},
"200": {"value": "#356CCCFF"},
"300": {"value": "#5088D6FF"},
"400": {"value": "#6AA3E0FF"},
"500": {"value": "#85BFEBFF"},
"600": {"value": "#9FDAF5FF"},
"700": {"value": "##BAF6FFFF"},
"800": {"value": "#D1F9FFFF"},
"900": {"value": "#E8FCFFFF"}
},
"transparent": {"value": "#ffffff00"}
}
}
20 changes: 10 additions & 10 deletions tokens/color/primaryPalette.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@
"dm": {"value": "{color.gray.600.value}"}
},
"primary": {
"lm": {"value": "{color.orange.600.value}", "themable": true, "comment": "themable"},
"dm": {"value": "{color.orange.400.value}", "themable": true, "comment": "themable"}
"lm": {"value": "{color.orange.600.value}"},
"dm": {"value": "{color.orange.400.value}"}
},
"primary-bg": {
"lm": {"value": "{color.orange.50.value}", "themable": true, "comment": "themable"},
"dm": {"value": "{color.gray.900.value}", "themable": true, "comment": "themable"}
"lm": {"value": "{color.orange.50.value}"},
"dm": {"value": "{color.gray.900.value}"}
},
"secondary": {
"lm": {"value": "{color.purple.700.value}", "themable": true, "comment": "themable"},
"dm": {"value": "{color.purple.300.value}", "themable": true, "comment": "themable"}
"lm": {"value": "{color.purple.700.value}"},
"dm": {"value": "{color.purple.300.value}"}
},
"secondary-hover": {
"lm": {"value": "{color.purple.800.value}", "themable": true, "comment": "themable"},
"dm": {"value": "{color.purple.400.value}", "themable": true, "comment": "themable"}
"lm": {"value": "{color.purple.800.value}"},
"dm": {"value": "{color.purple.400.value}"}
},
"secondary-bg": {
"lm": {"value": "{color.purple.50.value}", "themable": true, "comment": "themable"},
"dm": {"value": "{color.gray.900.value}", "themable": true, "comment": "themable"}
"lm": {"value": "{color.purple.50.value}"},
"dm": {"value": "{color.gray.900.value}"}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tokens/color/text.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"dm": {"value": "{color.red.300.value}"}
},
"action": {
"lm": {"value": "{color.primary.lm.value}","comment": "uses themable token"},
"dm": {"value": "{color.primary.dm.value}","comment": "uses themable token"}
"lm": {"value": "{color.primary.lm.value}"},
"dm": {"value": "{color.primary.dm.value}"}
},
"reverse": {
"lm": {"value": "{color.gray.0.value}"},
Expand Down
Loading