Skip to content

Commit fd0f67f

Browse files
committed
feat(themes): use native colors for ionic
1 parent 6ae28ab commit fd0f67f

2 files changed

Lines changed: 40 additions & 116 deletions

File tree

core/src/themes/ionic/default.tokens.ts

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
import * as colorTokens from 'outsystems-design-tokens/tokens/color scheme.json';
2-
import * as primitiveTokens from 'outsystems-design-tokens/tokens/primitives.json';
3-
import * as lightTokens from 'outsystems-design-tokens/tokens/theme/light.json';
4-
import * as typographyTokens from 'outsystems-design-tokens/tokens/typography.json';
5-
6-
import { currentColor, cachedResolveOsToken } from '../../utils/theme';
1+
import { rgba, currentColor } from '../../utils/theme';
72
import { defaultTheme as baseDefaultTheme } from '../base/default.tokens';
83
import type { DefaultTheme } from '../themes.interfaces';
94

105
import { darkTheme } from './dark.tokens';
116
import { lightTheme } from './light.tokens';
127

13-
const tokenMap = {
14-
colorTokens,
15-
primitiveTokens,
16-
lightTokens,
17-
typographyTokens,
8+
const colors = {
9+
backgroundColor: 'var(--ion-background-color, #fff)',
10+
backgroundColorRgb: 'var(--ion-background-color-rgb, 255, 255, 255)',
11+
textColor: 'var(--ion-text-color, #000)',
12+
textColorRgb: 'var(--ion-text-color-rgb, 0, 0, 0)',
1813
};
1914

2015
export const defaultTheme: DefaultTheme = {
@@ -96,26 +91,38 @@ export const defaultTheme: DefaultTheme = {
9691
cursor: 'auto',
9792

9893
padding: {
99-
vertical: primitiveTokens.scale['150'].$value,
100-
horizontal: primitiveTokens.scale['200'].$value,
94+
vertical: '6px',
95+
horizontal: '8px',
10196
},
10297

103-
typography: cachedResolveOsToken(typographyTokens.body.sm.medium.$value, tokenMap),
104-
lineHeight: primitiveTokens.font['line-height']['full'].$value,
105-
gap: cachedResolveOsToken(primitiveTokens.space['100'].$value, tokenMap),
98+
lineHeight: '20px',
99+
gap: '4px',
100+
101+
typography: {
102+
fontFamily:
103+
'-apple-system, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
104+
fontWeight: 500,
105+
lineHeight: '20px',
106+
fontSize: '12px',
107+
letterSpacing: '0%',
108+
paragraphSpacing: 20,
109+
paragraphIndent: 0,
110+
textCase: 'none',
111+
textDecoration: 'none',
112+
},
106113

107114
// Sizes
108115
size: {
109116
small: {
110-
minHeight: primitiveTokens.scale['600'].$value,
117+
minHeight: '24px',
111118
font: {
112-
size: primitiveTokens.font['font-size']['300'].$value,
119+
size: '12px',
113120
},
114121
},
115122
large: {
116-
minHeight: primitiveTokens.scale['800'].$value,
123+
minHeight: '32px',
117124
font: {
118-
size: primitiveTokens.font['font-size']['350'].$value,
125+
size: '14px',
119126
},
120127
},
121128
},
@@ -127,8 +134,8 @@ export const defaultTheme: DefaultTheme = {
127134
},
128135
focus: {
129136
ring: {
130-
color: lightTokens.primitives.blue['400'].$value,
131-
width: primitiveTokens.scale['050'].$value,
137+
color: '#b5c0f7',
138+
width: '2px',
132139
},
133140
},
134141
},
@@ -137,26 +144,26 @@ export const defaultTheme: DefaultTheme = {
137144
shape: {
138145
soft: {
139146
border: {
140-
radius: primitiveTokens.scale['100'].$value,
147+
radius: '4px',
141148
},
142149
},
143150
round: {
144151
border: {
145-
radius: primitiveTokens.scale['400'].$value,
152+
radius: '16px',
146153
},
147154
},
148155
rectangular: {
149156
border: {
150-
radius: primitiveTokens.scale['0'].$value,
157+
radius: '0px',
151158
},
152159
},
153160
},
154161

155162
// Hues
156163
hue: {
157164
bold: {
158-
bg: cachedResolveOsToken(colorTokens.bg.neutral.bold.default, tokenMap),
159-
color: cachedResolveOsToken(colorTokens.bg.surface.default, tokenMap),
165+
bg: rgba(colors.textColorRgb, 0.12),
166+
color: rgba(colors.textColorRgb, 0.87),
160167

161168
// Any of the semantic colors like primary, secondary, etc.
162169
semantic: {
@@ -166,8 +173,8 @@ export const defaultTheme: DefaultTheme = {
166173
},
167174

168175
subtle: {
169-
bg: cachedResolveOsToken(lightTokens.primitives.neutral['100'], tokenMap),
170-
color: lightTokens.primitives.neutral['800'].$value,
176+
bg: rgba(colors.textColorRgb, 0.05),
177+
color: rgba(colors.textColorRgb, 0.6),
171178

172179
semantic: {
173180
color: currentColor('contrast', null, true), // ADD THIS TO THE COMPONENT SCSS
@@ -181,11 +188,11 @@ export const defaultTheme: DefaultTheme = {
181188
outline: {
182189
border: {
183190
color: {
184-
bold: cachedResolveOsToken(colorTokens.text.default, tokenMap),
185-
subtle: cachedResolveOsToken(lightTokens.primitives.neutral['300'], tokenMap),
191+
bold: rgba(colors.textColorRgb, 0.32),
192+
subtle: rgba(colors.textColorRgb, 0.16),
186193
},
187194

188-
width: primitiveTokens.scale['025'].$value,
195+
width: '1px',
189196
},
190197

191198
semantic: {
@@ -200,7 +207,7 @@ export const defaultTheme: DefaultTheme = {
200207
},
201208

202209
icon: {
203-
size: primitiveTokens.font['font-size']['400'].$value,
210+
size: '16px',
204211
},
205212
},
206213
},

core/src/utils/theme.ts

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -601,86 +601,3 @@ export function currentColor(variation: string, alpha: number | string | null =
601601
export function clamp(min: number | string, val: number | string, max: number | string): string {
602602
return `clamp(${min}, ${val}, ${max})`;
603603
}
604-
605-
// Create a cache to store results
606-
const cache = new Map<any, any>();
607-
608-
export const cachedResolveOsToken = (tokenPath: any, tokenMap: Record<string, any>): any => {
609-
// Use the path/object as the key
610-
// (Note: For objects, this caches by reference)
611-
if (cache.has(tokenPath)) {
612-
return cache.get(tokenPath);
613-
}
614-
615-
// Use your existing resolveOsToken function with the global tokenMap
616-
const result = resolveOsToken(tokenPath, tokenMap);
617-
618-
cache.set(tokenPath, result);
619-
return result;
620-
};
621-
622-
export const resolveOsToken = (tokenPath: any, tokenMap: Record<string, any>): any => {
623-
// 1. Handle Objects (like Typography maps)
624-
if (typeof tokenPath === 'object' && tokenPath !== null) {
625-
// If it's a leaf-node token object, unwrap the $value immediately
626-
if ('$value' in tokenPath) {
627-
return resolveOsToken(tokenPath.$value, tokenMap);
628-
}
629-
630-
// Otherwise, it's a map of multiple tokens, resolve each key
631-
const resolvedObject: Record<string, any> = {};
632-
for (const [key, val] of Object.entries(tokenPath)) {
633-
resolvedObject[key] = resolveOsToken(val, tokenMap);
634-
}
635-
return resolvedObject;
636-
}
637-
638-
// 2. Handle Reference Strings: "{category.path.item}"
639-
let lookupPath = tokenPath;
640-
let isPath = false;
641-
642-
if (typeof tokenPath === 'string' && tokenPath.startsWith('{') && tokenPath.endsWith('}')) {
643-
const reference = tokenPath.slice(1, -1).trim();
644-
const [refCategory, ...refPath] = reference.split('.');
645-
646-
let rootKey: string | null = null;
647-
switch (refCategory) {
648-
case 'semantics':
649-
rootKey = 'colorTokens';
650-
break;
651-
case 'font':
652-
rootKey = 'primitiveTokens';
653-
break;
654-
case 'primitives':
655-
rootKey = 'lightTokens';
656-
break;
657-
case 'typography':
658-
rootKey = 'typographyTokens';
659-
break;
660-
case 'scale':
661-
rootKey = 'primitiveTokens';
662-
break; // Added 'scale' based on your example
663-
}
664-
665-
if (!rootKey) return tokenPath;
666-
667-
lookupPath = `${rootKey}.${refCategory}.${refPath.join('.')}`;
668-
isPath = true;
669-
}
670-
671-
// 3. ONLY run the reduce if we have confirmed this is a path to be searched
672-
if (isPath) {
673-
const value = lookupPath.split('.').reduce((acc: any, key: string) => {
674-
if (acc && typeof acc === 'object' && key in acc) {
675-
return acc[key];
676-
}
677-
return undefined;
678-
}, tokenMap);
679-
680-
// Recursively resolve the result of the lookup
681-
return resolveOsToken(value, tokenMap);
682-
}
683-
684-
// 4. If it's not a path or a reference, it's a Literal Value (Hex, Font-stack, etc.)
685-
return tokenPath;
686-
};

0 commit comments

Comments
 (0)