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

Style engine: update type for getCSSValueFromRawStyle #64528

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 5 additions & 3 deletions packages/style-engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,21 @@ _Changelog_

### getCSSValueFromRawStyle

Returns a WordPress CSS custom var value from incoming style preset value. The preset value follows the pattern `var:description|context|slug`.
Returns a WordPress CSS custom var value from incoming style preset value, if one is detected.

The preset value is a string and follows the pattern `var:description|context|slug`.

Example:

`getCSSValueFromRawStyle( 'var:preset|color|heavenlyBlue' )` // returns 'var(--wp--preset--color--heavenly-blue)'

_Parameters_

- _styleValue_ `string | any`: A raw style value.
- _styleValue_ `CSSStyleValue`: A raw style value.

_Returns_

- `string | unknown`: A CSS var value.
- `CSSStyleValue`: A CSS var value.

<!-- END TOKEN(Autogenerated API docs) -->

Expand Down
14 changes: 8 additions & 6 deletions packages/style-engine/src/styles/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ export function generateBoxRules(
}

/**
* Returns a WordPress CSS custom var value from incoming style preset value.
* The preset value follows the pattern `var:description|context|slug`.
* Returns a WordPress CSS custom var value from incoming style preset value,
* if one is detected.
*
* The preset value is a string and follows the pattern `var:description|context|slug`.
*
* Example:
*
Expand All @@ -139,9 +141,9 @@ export function generateBoxRules(
* @return A CSS var value.
*/

export function getCSSValueFromRawStyle(
styleValue: string | any
): string | unknown {
export function getCSSValueFromRawStyle< CSSStyleValue = string >(
styleValue: CSSStyleValue
): CSSStyleValue {
if (
typeof styleValue === 'string' &&
styleValue.startsWith( VARIABLE_REFERENCE_PREFIX )
Expand All @@ -160,7 +162,7 @@ export function getCSSValueFromRawStyle(
} )
)
.join( VARIABLE_PATH_SEPARATOR_TOKEN_STYLE );
return `var(--wp--${ variable })`;
return `var(--wp--${ variable })` as CSSStyleValue;
}
return styleValue;
}
Expand Down
Loading