-
Notifications
You must be signed in to change notification settings - Fork 576
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create docs, upload button, ordered first
- Loading branch information
1 parent
6bd674c
commit 2076bbf
Showing
7 changed files
with
123 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { LitElement, html } from 'lit'; | ||
import { ref, createRef } from 'lit/directives/ref.js'; | ||
import '@shoelace-style/shoelace/dist/components/button/button.js'; | ||
import { convertJSONToDTCG, convertZIPToDTCG } from '../../../lib/utils/convertToDTCG.js'; | ||
import { downloadJSON, downloadZIP } from '../../../lib/utils/downloadFile.js'; | ||
|
||
class SdDtcgConvert extends LitElement { | ||
fileInputRef = createRef(); | ||
|
||
render() { | ||
return html` | ||
<sl-button @click=${this.triggerUpload} variant="primary">Convert tokens to DTCG</sl-button> | ||
<input | ||
${ref(this.fileInputRef)} | ||
@change=${this.upload} | ||
id="upload-tokens-input" | ||
type="file" | ||
accept="application/*, text/*" | ||
aria-hidden="true" | ||
hidden | ||
/> | ||
`; | ||
} | ||
|
||
triggerUpload() { | ||
const fileInput = this.fileInputRef.value; | ||
if (fileInput) { | ||
fileInput.dispatchEvent(new MouseEvent('click')); | ||
} | ||
} | ||
|
||
async upload(ev: Event) { | ||
if (ev.target instanceof HTMLInputElement) { | ||
const file = ev.target.files?.[0]; | ||
if (file) { | ||
const today = new Date(Date.now()); | ||
const filename = `dtcg-tokens_${today.getFullYear()}-${today.getMonth()}-${( | ||
'0' + today.getDate() | ||
).slice(-2)}`; | ||
|
||
if (file.type.includes('zip')) { | ||
const zipBlob = await convertZIPToDTCG(file); | ||
await downloadZIP(zipBlob, `${filename}.zip`); | ||
} else if (file.type.includes('json')) { | ||
const jsonBlob = await convertJSONToDTCG(file); | ||
await downloadJSON(jsonBlob, `${filename}.json`); | ||
} else { | ||
throw new Error('Only ZIP and JSON type uploads are supported.'); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
customElements.define('sd-dtcg-convert', SdDtcgConvert); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
title: Design Token Community Group | ||
sidebar: | ||
order: 4 | ||
--- | ||
|
||
import tokens from '/public/demo-tokens.json'; | ||
|
||
There is a [W3C Design Token Community Group](https://www.w3.org/community/design-tokens/), whose goal it is to "provide standards upon which products and design tools can rely for sharing stylistic pieces of a design system at scale". | ||
|
||
What that boils down to right now is a [draft specification for how Design Tokens ought to be formatted](https://design-tokens.github.io/community-group/format/), for cross-tool and cross-platform interoperability. | ||
Since Style Dictionary v4, we have first-class support for this format. | ||
|
||
## Convert your Tokens to DTCG | ||
|
||
We also export a tool that allows you to convert your design tokens in the old format to the DTCG format: | ||
|
||
<div spacer></div> | ||
<sd-dtcg-convert></sd-dtcg-convert> | ||
|
||
What it does: | ||
|
||
- Turn `value`, `type` and `description` design token property keys into `$value`, `$type` and `$description` respectively. | ||
- Move the `$type` properties from the design tokens onto the uppermost common ancestor token group | ||
|
||
What it does not do (atm, feel free to raise suggestions): | ||
|
||
- Refactor type values commonly used to the DTCG types, e.g. size -> dimension. | ||
|
||
## Live demo | ||
|
||
<sd-playground tokens={JSON.stringify({ value: JSON.stringify(tokens, null, 2), lang: 'json'})} default-selected="tokens" id="main-demo"> | ||
|
||
<div style="height: 100%" slot="monaco-editor"></div> | ||
</sd-playground> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
--- | ||
title: Architecture | ||
sidebar: | ||
order: 2 | ||
--- | ||
|
||
This is how Style Dictionary works under the hood. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
--- | ||
title: Package Structure | ||
sidebar: | ||
order: 3 | ||
--- | ||
|
||
import { FileTree } from '@astrojs/starlight/components'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters