Skip to content

Commit 85829fe

Browse files
committed
feat(progress-bar): add ionColor
1 parent 7212005 commit 85829fe

2 files changed

Lines changed: 45 additions & 16 deletions

File tree

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { rgba, currentColor, mix, dynamicFont } from '../../utils/theme';
1+
import { rgba, currentColor, ionColor, mix, dynamicFont } from '../../utils/theme';
22
import { defaultTheme as baseDefaultTheme } from '../base/default.tokens';
33
import { colors as baseColors } from '../base/shared.tokens';
44
import type { DefaultTheme } from '../themes.interfaces';
@@ -604,9 +604,7 @@ export const defaultTheme: DefaultTheme = {
604604
indeterminate: {
605605
progress: {
606606
default: {
607-
// TODO: Replace with ionColor() once that utility is merged
608-
// ion-color(primary, base) -> ionColor('primary', 'base')
609-
background: 'var(--ion-color-primary-bold)',
607+
background: ionColor('primary', 'base'),
610608
},
611609

612610
semantic: {
@@ -619,9 +617,7 @@ export const defaultTheme: DefaultTheme = {
619617
buffer: {
620618
bar: {
621619
default: {
622-
// TODO: Replace rgba() with ionColor() once that utility is merged
623-
// ion-color(primary, base, 0.3) -> ionColor('primary', 'base', { alpha: 0.3 }),
624-
background: rgba('var(--ion-color-primary-bold-rgb)', 0.3),
620+
background: ionColor('primary', 'base', { alpha: 0.3 }),
625621
},
626622

627623
semantic: {
@@ -636,9 +632,7 @@ export const defaultTheme: DefaultTheme = {
636632
determinate: {
637633
progress: {
638634
default: {
639-
// TODO: Replace with ionColor() once that utility is merged
640-
// ion-color(primary, base) -> ionColor('primary', 'base')
641-
background: 'var(--ion-color-primary-bold)',
635+
background: ionColor('primary', 'base'),
642636
},
643637

644638
semantic: {
@@ -651,9 +645,7 @@ export const defaultTheme: DefaultTheme = {
651645
buffer: {
652646
bar: {
653647
default: {
654-
// TODO: Replace rgba() with ionColor() once that utility is merged
655-
// ion-color(primary, base, 0.3) -> ionColor('primary', 'base', { alpha: 0.3 }),
656-
background: rgba('var(--ion-color-primary-bold-rgb)', 0.3),
648+
background: ionColor('primary', 'base', { alpha: 0.3 }),
657649
},
658650

659651
semantic: {
@@ -665,9 +657,7 @@ export const defaultTheme: DefaultTheme = {
665657

666658
circles: {
667659
default: {
668-
// TODO: Replace rgba() with ionColor() once that utility is merged
669-
// ion-color(primary, base, 0.3) -> ionColor('primary', 'base', { alpha: 0.3 })
670-
background: rgba('var(--ion-color-primary-bold-rgb)', 0.3),
660+
background: ionColor('primary', 'base', { alpha: 0.3 }),
671661
},
672662

673663
semantic: {

core/src/utils/theme.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,45 @@ export function currentColor(variation: string, alpha: number | string | null =
622622
}
623623
}
624624

625+
interface IonColorOptions {
626+
alpha?: number | string | null;
627+
rgb?: boolean;
628+
subtle?: boolean;
629+
}
630+
631+
export function ionColor(name: string, variation: string, options: IonColorOptions = {}): string {
632+
const { alpha = null, rgb = false, subtle = false } = options;
633+
634+
// Build base variable name
635+
const base = subtle ? `--ion-color-${name}-subtle` : `--ion-color-${name}`;
636+
const variationSuffix = variation === 'base' ? '' : `-${variation}`;
637+
let variable = `${base}${variationSuffix}`;
638+
639+
// Build the fallback variable name (only for bold colors)
640+
let fallbackVariable: string | null = null;
641+
642+
if (!subtle) {
643+
const fallbackBase = `--ion-color-${name}-bold`;
644+
fallbackVariable = `${fallbackBase}${variationSuffix}`;
645+
}
646+
647+
// Handle alpha transparency
648+
if (alpha !== null) {
649+
const rgbVar = `${variable}-rgb`;
650+
const fallbackRgb = fallbackVariable ? `${fallbackVariable}-rgb` : null;
651+
652+
return fallbackRgb ? `rgba(var(${rgbVar}, var(${fallbackRgb})), ${alpha})` : `rgba(var(${rgbVar}), ${alpha})`;
653+
}
654+
655+
// Handle RGB variables
656+
if (rgb) {
657+
variable = `${variable}-rgb`;
658+
fallbackVariable = fallbackVariable ? `${fallbackVariable}-rgb` : null;
659+
}
660+
661+
return fallbackVariable ? `var(${variable}, var(${fallbackVariable}))` : `var(${variable})`;
662+
}
663+
625664
/**
626665
* Mimics the CSS `clamp` function logic.
627666
*

0 commit comments

Comments
 (0)