Skip to content

Commit

Permalink
feat: enhance support for nested theme token structures
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Dec 17, 2024
1 parent 46dcfc1 commit 48ef5a0
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion packages/styled-system/src/utils/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,43 @@ const toNegativeValue = (scale, absoluteValue, options) => {
};

export const getter = (scale, value, options) => {
const result = get(scale, value);
let result = get(scale, value);

// Extract the `value` property if the result is an object.
//
// Example usage:
// ```
// <Box color="white.primary" />
// <Box color="black.primary" />
// ```
//
// The `colors` scale in the theme:
// ```js
// {
// colors: {
// white: {
// primary: {
// value: 'rgba(255, 255, 255, .92)',
// },
// secondary: {
// value: 'rgba(255, 255, 255, .60)',
// },
// },
// black: {
// primary: {
// value: 'rgba(0, 0, 0, .92)',
// },
// secondary: {
// value: 'rgba(0, 0, 0, .65)',
// },
// },
// },
// }
// ```
if (typeof result === 'object') {
result = result?.value;
}

if (result === undefined) {
return value; // fallback to value if result is undefined
}
Expand Down

0 comments on commit 48ef5a0

Please sign in to comment.