Skip to content

Commit 2d22503

Browse files
Update utils/css-variables
1 parent 4a598b6 commit 2d22503

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

packages/minimal-shared/src/utils/css-variables/css-variables.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getCssVarName } from './css-variables';
1+
import { parseCssVar } from './css-variables';
22

33
// ----------------------------------------------------------------------
44

5-
describe('getCssVarName()', () => {
5+
describe('parseCssVar()', () => {
66
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
77

88
afterEach(() => {
@@ -14,11 +14,11 @@ describe('getCssVarName()', () => {
1414
});
1515

1616
it('1. Extracts variable without fallback', () => {
17-
expect(getCssVarName('var(--palette-Tooltip-bg)')).toBe('--palette-Tooltip-bg');
17+
expect(parseCssVar('var(--palette-Tooltip-bg)')).toBe('--palette-Tooltip-bg');
1818
});
1919

2020
it('2. Extracts variable with fallback', () => {
21-
expect(getCssVarName('var(--palette-Tooltip-bg, rgba(69, 79, 91, 0.92))')).toBe(
21+
expect(parseCssVar('var(--palette-Tooltip-bg, rgba(69, 79, 91, 0.92))')).toBe(
2222
'--palette-Tooltip-bg'
2323
);
2424
});
@@ -27,7 +27,7 @@ describe('getCssVarName()', () => {
2727
const badInputs = [null, undefined, '', 123, {}, true];
2828

2929
for (const val of badInputs) {
30-
expect(getCssVarName(val)).toBe('');
30+
expect(parseCssVar(val)).toBe('');
3131
}
3232

3333
expect(errorSpy).toHaveBeenCalledTimes(badInputs.length);
@@ -38,7 +38,7 @@ describe('getCssVarName()', () => {
3838
const invalidFormats = ['rgba(0,0,0,0.5)', 'var(-bad)', 'var()', 'var(--bad value)'];
3939

4040
for (const val of invalidFormats) {
41-
expect(getCssVarName(val)).toBe('');
41+
expect(parseCssVar(val)).toBe('');
4242
}
4343

4444
expect(errorSpy).toHaveBeenCalledTimes(invalidFormats.length);

packages/minimal-shared/src/utils/css-variables/css-variables.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
* @returns The extracted CSS variable name (e.g., '--palette-Tooltip-bg').
66
*
77
* @example
8-
* getCssVarName('var(--palette-Tooltip-bg)'); // → '--palette-Tooltip-bg'
9-
* getCssVarName('var(--palette-Tooltip-bg, rgba(69, 79, 91, 0.92))'); // → '--palette-Tooltip-bg'
10-
* getCssVarName(theme.vars.palette.Tooltip.bg); // → '--palette-Tooltip-bg'
8+
* parseCssVar('var(--palette-Tooltip-bg)'); // → '--palette-Tooltip-bg'
9+
* parseCssVar('var(--palette-Tooltip-bg, rgba(69, 79, 91, 0.92))'); // → '--palette-Tooltip-bg'
10+
* parseCssVar(theme.vars.palette.Tooltip.bg); // → '--palette-Tooltip-bg'
1111
*/
12-
export function getCssVarName(cssValue: unknown): string {
12+
export function parseCssVar(cssValue: unknown): string {
1313
if (typeof cssValue !== 'string' || !cssValue.trim()) {
1414
console.error('Invalid input: CSS value must be a non-empty string');
1515
return '';

0 commit comments

Comments
 (0)