Skip to content

Commit bf697f0

Browse files
author
Omar Adobati
committed
Add setting option to exclude mode from token value
* new setting to allow to only preserve mode in token name but exclude it from token value * add documentation in README.md * extend Checkbox component to ember Info component inline to the checkbox label * update jest moduleMapper to resolve "@src"
1 parent 2ef9a84 commit bf697f0

File tree

14 files changed

+176
-136
lines changed

14 files changed

+176
-136
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,12 @@ You can define any additional prefix via this option, e.g `*`. This can be helpf
315315

316316
### Reference mode in variables
317317

318-
In the output JSON generated by the variables, the mode names are included. You can configure whether to include these mode names in the output JSON or not. By default, the mode names are included.
318+
![Design Tokens plugin mode export settings](/_resources/settings_mode.png)
319+
320+
In the output JSON generated by the variables, the mode names are included. You can configure whether to include these mode names in the output JSON or not.
321+
By default, the mode names are included in both the token names and the token values. You can turn off this behavior by disabling the "Enable/Disable mode referencing" checkbox.
322+
If you wish to keep the mode in the token names, but not in the token values, you can disable the first option and enable "Avoid mode in token value".
323+
This last options is disabled when the first one is enabled.
319324

320325
### Aliases (Standard format only)
321326

_resources/_archive/settings.png

-187 KB
Binary file not shown.

_resources/settings.png

130 KB
Loading

_resources/settings_mode.png

241 KB
Loading

dist/plugin.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ui.html

Lines changed: 63 additions & 63 deletions
Large diffs are not rendered by default.

dist/ui.js

Lines changed: 63 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
"version": "npm run set-version && npm run build && git add --all"
2727
},
2828
"author": "Lukas Oppermann <[email protected]> (https://vea.re)",
29+
"contributors": [
30+
{
31+
"name": "Omar Adobati <[email protected]> (http://github.com/0m4r)"
32+
}
33+
],
2934
"license": "MIT",
3035
"devDependencies": {
3136
"@ctrl/tinycolor": "^3.4.0",
@@ -141,7 +146,8 @@
141146
"**/tests/unit/!(skip.)*.test.[jt]s?(x)"
142147
],
143148
"moduleNameMapper": {
144-
"^@config/(.*)$": "<rootDir>/src/config/$1"
149+
"^@config/(.*)$": "<rootDir>/src/config/$1",
150+
"^@src/(.*)$": "<rootDir>/src/$1"
145151
}
146152
},
147153
"dependencies": {

src/config/defaultSettings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const defaultSettings: Settings = {
2121
keyInName: false,
2222
prefixInName: true,
2323
modeReference: true,
24+
modeInTokenName: true,
2425
prefix: {
2526
color: 'color',
2627
gradient: 'gradient',

src/ui/components/Checkbox.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { css } from '@emotion/css'
22
import * as React from 'react'
3+
import { Info } from './Info'
34

45
const style = css`
56
&.checkbox {
@@ -139,6 +140,10 @@ type props = {
139140
value: boolean,
140141
event: React.ChangeEvent<HTMLInputElement>
141142
) => void;
143+
info?: {
144+
width: number,
145+
label: string
146+
}
142147
}
143148

144149
export const Checkbox = ({
@@ -149,7 +154,8 @@ export const Checkbox = ({
149154
label,
150155
defaultValue,
151156
checked,
152-
onChange
157+
onChange,
158+
info,
153159
}: props) => {
154160
let inputConfig: any = {
155161
id: id || `${type}--${(Math.random() * 100000000).toFixed(0)}`
@@ -192,6 +198,9 @@ export const Checkbox = ({
192198
/>
193199
<label className={`${type}__label`} htmlFor={inputConfig.id}>
194200
{label}
201+
{info && info.label &&
202+
<Info width={info.width} label={info.label} />
203+
}
195204
</label>
196205
</div>
197206
)

src/ui/components/GeneralSettings.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,9 @@ export const GeneralSettings = () => {
230230
<div>
231231
<Title size="small" weight="bold">
232232
Reference mode in variables
233-
<Info
234-
width={240}
235-
label="If disabled, the exported json will not include the mode of variables."
236-
/>
233+
237234
</Title>
235+
238236
<Checkbox
239237
label="Enable/disable mode referencing"
240238
type="switch"
@@ -244,6 +242,25 @@ export const GeneralSettings = () => {
244242
draft.modeReference = value;
245243
})
246244
}
245+
info={{
246+
width: 240,
247+
label:"If disabled, the exported json will not include the mode of variables, nor in the token name, nor in the token value"
248+
}}
249+
/>
250+
<Checkbox
251+
label="Avoid mode referencing in token values"
252+
type="switch"
253+
checked={settings.modeInTokenName}
254+
isDisabled={!settings.modeReference}
255+
onChange={(value) =>
256+
updateSettings((draft) => {
257+
draft.modeInTokenName = value;
258+
})
259+
}
260+
info={{
261+
width: 240,
262+
label:"If enabled, the exported json will not include the mode of variables in the token value."
263+
}}
247264
/>
248265
</div>
249266
</div>

src/utilities/getVariables.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ export const getVariables = (figma: PluginAPI, settings: Settings) => {
7777
// return each mode value as a separate variable
7878
return Object.entries(variable.valuesByMode).map(([id, value]) => {
7979
// Only add mode if there's more than one
80-
const addMode = settings.modeReference && modes.length > 1
80+
const addMode = modes.length > 1 && (settings.modeInTokenName || settings.modeReference)
8181
return {
8282
...extractVariable(
8383
variable,
8484
value,
8585
modes.find(({ modeId }) => modeId === id)
8686
),
87-
// name is contstructed from collection, mode and variable name
87+
// name is constructed from collection, mode and variable name
8888

8989
name: addMode
9090
? `${collection}/${

tests/unit/settings.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const baseSettings = {
3636
keyInName: false,
3737
prefixInName: true,
3838
modeReference: true,
39+
modeInTokenName: true,
3940
prefix: {
4041
color: 'color',
4142
gradient: 'gradient',

types/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type Settings = {
2727
keyInName: boolean,
2828
prefixInName: boolean,
2929
modeReference: boolean,
30+
modeInTokenName: boolean,
3031
prefix: {
3132
color: string,
3233
gradient: string,

0 commit comments

Comments
 (0)