Skip to content

Commit

Permalink
fix: add missing expand config types, docs note (#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenbroekema authored Sep 17, 2024
1 parent 1e784a0 commit b48d0e9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-pugs-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'style-dictionary': patch
---

Add missing type interfaces, most notably the ExpandConfig types.
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,29 @@ describe('utils', () => {
const sortedRet = ret.sort(sortBy('value'));
expect(sortedRet).to.eql(sortedExpectedRet);
});

it('should return nested leaf node values using DTCG spec as an array', () => {
const tokens = {
color: {
black: {
name: 'color.black',
$value: '#000000',
$type: 'color',
},
white: {
name: 'color.white',
$value: '#FFFFFF',
$type: 'color',
},
},
};
const ret = flattenTokens(tokens, { usesDtcg: true });

const expected_ret = [tokens.color.black, tokens.color.white];
const sortedExpectedRet = expected_ret.sort(sortBy('value'));
const sortedRet = ret.sort(sortBy('value'));

expect(sortedRet).to.eql(sortedExpectedRet);
});
});
});
4 changes: 4 additions & 0 deletions docs/src/content/docs/reference/Utils/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ These utilities have to do with processing/formatting tokens object.

Flatten dictionary tokens object to an array of flattened tokens.

:::note
Only the "value" / "$value" property is required for this utility to consider a leaf node a "token" to be added to the flattened array output.
:::

```javascript title="build-tokens.js"
import StyleDictionary from 'style-dictionary';
import { flattenTokens } from 'style-dictionary/utils';
Expand Down
2 changes: 1 addition & 1 deletion lib/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class Register {
}

/**
* @param {import('../types/Parser.ts').Parser} parser
* @param {Parser} parser
* @param {typeof Register | Register} target
*/
static __registerParser(parser, target) {
Expand Down
11 changes: 10 additions & 1 deletion types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
export type { Action } from './Action.ts';

export type { PlatformConfig, Config, LocalOptions, LogConfig } from './Config.ts';
export type {
PlatformConfig,
Config,
LocalOptions,
LogConfig,
Hooks,
ExpandFilter,
Expand,
ExpandConfig,
} from './Config.ts';

export type {
DesignToken,
Expand Down

0 comments on commit b48d0e9

Please sign in to comment.