diff --git a/.github/workflows/release-snapshot.yml b/.github/workflows/release-snapshot.yml index 09fa18d4..ca64c8e1 100644 --- a/.github/workflows/release-snapshot.yml +++ b/.github/workflows/release-snapshot.yml @@ -1,13 +1,52 @@ name: Release Snapshot -on: workflow_dispatch +on: + workflow_dispatch: + inputs: + tag: + description: "Tag used on changeset version and NPM package" + required: false + type: string jobs: get-snapshot-tag: - name: Split branch name runs-on: ubuntu-latest + permissions: + contents: write + id-token: write steps: - - id: split + - name: Split branch name + id: split env: BRANCH: ${{ github.ref_name }} - run: echo "::set-output name=fragment::${BRANCH##*/}" + run: echo "fragment=${BRANCH##*snapshot-}" >> $GITHUB_OUTPUT + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get last author info + id: author + run: | + echo "authorName=$(git log -1 --pretty=format:'%an')" >> $GITHUB_OUTPUT + echo "authorEmail=$(git log -1 --pretty=format:'%ae')" >> $GITHUB_OUTPUT + - uses: moonrepo/setup-toolchain@v0 + with: + auto-install: true + - run: moon setup + - run: moon run :build --query "projectSource~packages/*" + - name: Snapshot release + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + SNAPSHOT_TAG: ${{ inputs.tag || steps.split.outputs.fragment }} + USERNAME: ${{ steps.author.outputs.authorName }} + EMAIL: ${{ steps.author.outputs.authorEmail }} + run: | + pnpm changeset version --snapshot $SNAPSHOT_TAG + git config --global user.name "$USERNAME" + git config --global user.email "$EMAIL" + git add . + git commit -m "chore: snapshot release $SNAPSHOT_TAG" + npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN + pnpm changeset publish --tag $SNAPSHOT_TAG + git push origin HEAD + git push origin --tags diff --git a/.moon/workspace.yml b/.moon/workspace.yml index c6718bfb..2efe93a4 100644 --- a/.moon/workspace.yml +++ b/.moon/workspace.yml @@ -2,6 +2,7 @@ $schema: "https://moonrepo.dev/schemas/workspace.json" projects: tokens: "packages/tokens" + componentSchemas: "packages/component-schemas" visualizer: "docs/visualizer" site: "docs/site" root: "." diff --git a/docs/site/lib/components.js b/docs/site/lib/components.js index f4c22447..05b36c1e 100644 --- a/docs/site/lib/components.js +++ b/docs/site/lib/components.js @@ -101,8 +101,16 @@ export async function getAllComponentSlugs() { } export async function getComponentData(slug) { + // not sure, if this should use the public/schemas folder, like getAllComponentSlugs() const schemaDir = path.resolve( - path.join(process.cwd(), "..", "..", "packages", "tokens", "schemas"), + path.join( + process.cwd(), + "..", + "..", + "packages", + "component-schemas", + "schemas", + ), ); const file = await readJSON( path.join(schemaDir, "components", `${slug}.json`), diff --git a/docs/site/moon.yml b/docs/site/moon.yml index 7622c353..495942b7 100644 --- a/docs/site/moon.yml +++ b/docs/site/moon.yml @@ -16,7 +16,18 @@ fileGroups: target: - "/site/[!visualizer]" tasks: - copySchema: + copyComponentSchema: + command: + - cp + - -r + - ../../packages/component-schemas/schemas + - public/ + platform: system + inputs: + - /packages/component-schemas/schemas/**/*.json + outputs: + - public/schemas + copyTokenTypeSchema: command: - cp - -r @@ -33,7 +44,8 @@ tasks: - build platform: node deps: - - ~:copySchema + - ~:copyComponentSchema + - ~:copyTokenTypeSchema outputs: - "/site/" clean: diff --git a/docs/site/public/schemas/components/action-button.json b/docs/site/public/schemas/components/action-button.json index 9486045f..9acf63fb 100644 --- a/docs/site/public/schemas/components/action-button.json +++ b/docs/site/public/schemas/components/action-button.json @@ -22,9 +22,8 @@ }, "size": { "type": "string", - "enum": ["s", "m", "l", "xl"], - "default": "m", - "pattern": "^(x?s|m|x{0,3}l)$" + "enum": ["xs", "s", "m", "l", "xl"], + "default": "m" }, "isQuiet": { "type": "boolean", @@ -40,7 +39,8 @@ }, "staticColor": { "type": "string", - "enum": ["white", "black"] + "enum": ["white", "black"], + "description": "Static color must not be set for the default version of this component." }, "selectedTextColor": { "$ref": "https://opensource.adobe.com/spectrum-tokens/schemas/types/hex-color.json" diff --git a/docs/site/public/schemas/components/avatar.json b/docs/site/public/schemas/components/avatar.json index f61c419a..8e28b0b5 100644 --- a/docs/site/public/schemas/components/avatar.json +++ b/docs/site/public/schemas/components/avatar.json @@ -15,7 +15,9 @@ "default": 100 }, "image": { - "type": "string" + "type": "string", + "enum": ["text", "image"], + "default": "image" }, "isDisabled": { "type": "boolean", diff --git a/docs/site/public/schemas/components/button.json b/docs/site/public/schemas/components/button.json index 25650650..345797b7 100644 --- a/docs/site/public/schemas/components/button.json +++ b/docs/site/public/schemas/components/button.json @@ -27,7 +27,8 @@ }, "staticColor": { "type": "string", - "enum": ["white", "black"] + "enum": ["white", "black"], + "description": "Static color must not be set for the default version of this component." }, "style": { "type": "string", diff --git a/docs/site/public/schemas/components/close-button.json b/docs/site/public/schemas/components/close-button.json index b2fe7e46..83315b1a 100644 --- a/docs/site/public/schemas/components/close-button.json +++ b/docs/site/public/schemas/components/close-button.json @@ -20,7 +20,7 @@ "staticColor": { "type": "string", "enum": ["white", "black"], - "default": null + "description": "Static color must not be set for the default version of this component." }, "isDisabled": { "type": "boolean", diff --git a/docs/site/public/schemas/components/link.json b/docs/site/public/schemas/components/link.json index bd45e29d..55b1d6d7 100644 --- a/docs/site/public/schemas/components/link.json +++ b/docs/site/public/schemas/components/link.json @@ -21,7 +21,7 @@ "staticColor": { "type": "string", "enum": ["white", "black"], - "default": null + "description": "Static color must not be set for the default version of this component." }, "state": { "type": "string", diff --git a/docs/site/public/schemas/components/popover.json b/docs/site/public/schemas/components/popover.json index e3184032..a0a25889 100644 --- a/docs/site/public/schemas/components/popover.json +++ b/docs/site/public/schemas/components/popover.json @@ -10,7 +10,7 @@ "type": "object", "properties": { "width": { - "type": "integer" + "type": "number" }, "height": { "type": "number" diff --git a/docs/site/public/schemas/components/rating.json b/docs/site/public/schemas/components/rating.json index 2cd95f5f..69289000 100644 --- a/docs/site/public/schemas/components/rating.json +++ b/docs/site/public/schemas/components/rating.json @@ -10,9 +10,10 @@ "type": "object", "properties": { "value": { - "type": "integer", - "minimum": 0, - "maximum": 5 + "type": "number", + "enum": [0, 1, 2, 3, 4, 5], + "default": 0, + "description": "From 0 to 5" }, "isEmphasized": { "type": "boolean", diff --git a/docs/site/public/schemas/components/search-field.json b/docs/site/public/schemas/components/search-field.json new file mode 100644 index 00000000..6fd4e1a5 --- /dev/null +++ b/docs/site/public/schemas/components/search-field.json @@ -0,0 +1,50 @@ +{ + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/component.json", + "$id": "https://opensource.adobe.com/spectrum-tokens/schemas/components/search-field.json", + "title": "Search field", + "description": "A search field is used for searching and filtering items.", + "meta": { + "category": "inputs", + "documentationUrl": "https://spectrum.adobe.com/page/search-field/" + }, + "type": "object", + "properties": { + "label": { + "type": "string" + }, + "value": { + "type": "string" + }, + "width": { + "type": "number" + }, + "size": { + "type": "string", + "enum": ["s", "m", "l", "xl"], + "default": "m", + "pattern": "^(x?s|m|x{0,3}l)$" + }, + "isQuiet": { + "type": "boolean", + "default": false + }, + "isDisabled": { + "type": "boolean", + "default": false + }, + "description": { + "type": "string" + }, + "state": { + "type": "string", + "enum": [ + "default", + "hover", + "focus + hover", + "focus + not hover", + "keyboard focus" + ], + "default": "default" + } + } +} diff --git a/docs/site/public/schemas/components/tabs.json b/docs/site/public/schemas/components/tabs.json index 10eeeb59..ef9f5cb4 100644 --- a/docs/site/public/schemas/components/tabs.json +++ b/docs/site/public/schemas/components/tabs.json @@ -9,24 +9,46 @@ }, "type": "object", "properties": { - "label": { - "type": "string" + "orientation": { + "type": "string", + "enum": ["horizontal", "vertical"], + "default": "vertical" }, - "icon": { - "$ref": "https://opensource.adobe.com/spectrum-tokens/schemas/types/workflow-icon.json" + "size": { + "type": "string", + "enum": ["s", "m", "l", "xl"], + "default": "m" }, - "isSelected": { + "density": { + "type": "string", + "enum": ["compact", "regular"], + "default": "regular" + }, + "isFluid": { + "type": "boolean", + "default": false, + "description": "This overrides density and is only applicable to horizontal tabs." + }, + "isQuiet": { "type": "boolean", "default": false }, - "isDisabled": { + "isEmphasized": { "type": "boolean", "default": false }, - "state": { + "alignment": { + "type": "string", + "enum": ["start", "center"], + "default": "start" + }, + "selectedItem": { + "description": "(list of available items)" + }, + "keyboardActivation": { "type": "string", - "enum": ["default", "hover", "down", "keyboard focus"], - "default": "default" + "enum": ["manual", "automatic"], + "default": "manual" } } } diff --git a/packages/component-schemas/CHANGELOG.md b/packages/component-schemas/CHANGELOG.md new file mode 100644 index 00000000..376cb168 --- /dev/null +++ b/packages/component-schemas/CHANGELOG.md @@ -0,0 +1,31 @@ +# @adobe/spectrum-component-api-schemas + +## 0.0.0-schema-20240821152525 + +### Patch Changes + +- [#353](https://github.com/adobe/spectrum-tokens/pull/353) [`dc2d6c6`](https://github.com/adobe/spectrum-tokens/commit/dc2d6c6e12c1ea4fdc0d891b3fd50ea0b1697dd7) Thanks [@karstens](https://github.com/karstens)! - Making adjustments to bring the schema more in line with what was on the spectrum website. + +## 0.0.0-schema-20240620220450 + +### Minor Changes + +- [#353](https://github.com/adobe/spectrum-tokens/pull/353) [`64379eb`](https://github.com/adobe/spectrum-tokens/commit/64379ebeaf9402fe77ca1adfd020f42df60c60d9) Thanks [@karstens](https://github.com/karstens)! - Added schema for search-field and fixed some path bugs in testing + +## 0.0.0-schema-20240618053842 + +### Minor Changes + +- [#353](https://github.com/adobe/spectrum-tokens/pull/353) [`b5c1579`](https://github.com/adobe/spectrum-tokens/commit/b5c15792ec5f5e5c269bfa7bf58af3df42e648c1) Thanks [@karstens](https://github.com/karstens)! - Initial release + +## 0.0.0-schema-20240614194147 + +### Patch Changes + +- [#353](https://github.com/adobe/spectrum-tokens/pull/353) [`9805167`](https://github.com/adobe/spectrum-tokens/commit/980516791c0bef9e2f0bbeffe6515f103f3ad7a2) Thanks [@karstens](https://github.com/karstens)! - fixed some bugs + +## 0.0.0-schema-20240613154750 + +### Patch Changes + +- [#353](https://github.com/adobe/spectrum-tokens/pull/353) [`6ff5ad7`](https://github.com/adobe/spectrum-tokens/commit/6ff5ad7a75356f4b93d07a2818b357da19ce5b4b) Thanks [@karstens](https://github.com/karstens)! - Initial release diff --git a/packages/component-schemas/README.md b/packages/component-schemas/README.md new file mode 100644 index 00000000..8d10f2bb --- /dev/null +++ b/packages/component-schemas/README.md @@ -0,0 +1,42 @@ +# Spectrum Component Schemas + +An NPM package of JSON Schema for Spectrum components. Used in the table of options on the Spectrum Design System website (example). + +| **Property** | **Values** | **Default value** | +| ------------------- | --------------------------------------- | ----------------- | +| label | text | - | +| hide label | yes / no | no | +| icon | icon / nothing | nothing | +| size | s / m / l / xl | m | +| is quiet | yes / no | no | +| is selected | yes / no | no | +| is emphasized | yes / no | no | +| static color | white / black | none | +| selected text color | hex value | #000000 | +| has hold icon | yes / no | no | +| is disabled | yes / no | no | +| state | default / hover / down / keyboard focus | default | + +## Helper functions + +- `schemaFileNames` +- `getSchemaFile()` +- `getAllSchemas()` +- `getAllSlugs()` + +## Project file structure + +``` +├── schemas +│ ├── components +│ │ └── // component json files +│ ├── types +│ │ └── // shared types like hex-color +├── test +│ └── // tests +├── CHANGELOG.md // generated by changeset +├── index.js // helpful functions for fetching the schema file data +├── moon.yml // config file for moon monorepo task management +├── package.json +└── README.md // this file! +``` diff --git a/packages/component-schemas/index.js b/packages/component-schemas/index.js new file mode 100644 index 00000000..4f72bb3b --- /dev/null +++ b/packages/component-schemas/index.js @@ -0,0 +1,92 @@ +/* +Copyright 2024 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ +import { glob } from "glob"; +import { isAbsolute, resolve } from "path"; +import { readFile } from "fs/promises"; +import * as url from "url"; + +export const getSlugFromDocumentationUrl = (documentationUrl) => + documentationUrl + .split("/") + .filter((part) => part !== "") + .pop(); + +export const readJson = async (fileName) => + JSON.parse(await readFile(fileName, "utf8")); + +export const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); + +export const schemaFileNames = await glob( + `${resolve(__dirname, "./schemas")}/**/*.json`, +); + +/** + * Accepts either a schema name or an absolute path + * + * @param schemaFileName + * @return {Promise} + */ +export const getSchemaFile = async (schemaFileName) => { + let filePath = resolve(__dirname, "schemas", schemaFileName); + if (isAbsolute(schemaFileName)) { + filePath = schemaFileName; + } + return await readJson(resolve(filePath)); +}; + +export const getAllSlugs = async () => { + return await Promise.all(schemaFileNames.map(getSchemaFile)) + .then((schemaFileDataAr) => { + return schemaFileDataAr.reduce( + (slugs, schemaFileData) => [ + ...slugs, + ...(Object.hasOwn(schemaFileData, "meta") && + Object.hasOwn(schemaFileData.meta, "documentationUrl") + ? [ + getSlugFromDocumentationUrl( + schemaFileData.meta.documentationUrl, + ), + ] + : []), + ], + [], + ); + }) + .then((slugs) => slugs.sort()); +}; + +export const getAllSchemas = async () => { + return await Promise.all( + schemaFileNames.map(async (schemaFileName) => { + const data = await getSchemaFile(schemaFileName); + if ( + Object.hasOwn(data, "meta") && + Object.hasOwn(data.meta, "documentationUrl") + ) { + return { + ...data, + ...{ slug: getSlugFromDocumentationUrl(data.meta.documentationUrl) }, + }; + } else return data; + }), + ); +}; + +export const getSchemaBySlug = async (slug) => { + const schema = await getAllSchemas().then((schemas) => + schemas.find((schema) => { + return Object.hasOwn(schema, "slug") && schema.slug === slug; + }), + ); + delete schema.slug; + return schema; +}; diff --git a/packages/component-schemas/moon.yml b/packages/component-schemas/moon.yml new file mode 100644 index 00000000..b923b7cd --- /dev/null +++ b/packages/component-schemas/moon.yml @@ -0,0 +1,32 @@ +# Copyright 2024 Adobe. All rights reserved. +# This file is licensed to you under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. You may obtain a copy +# of the License at http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software distributed under +# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +# OF ANY KIND, either express or implied. See the License for the specific language +# governing permissions and limitations under the License. +$schema: "https://moonrepo.dev/schemas/project.json" +type: library +fileGroups: + schemas: + - "schemas/**/*.{yaml,yml,json}" + tests: + - "test/**/*" +tasks: + test: + command: + - pnpm + - ava + inputs: + - "@globs(schemas)" + - "@globs(tests)" + - index.js + platform: node + test-watch: + command: + - ava + - --watch + local: true + platform: node diff --git a/packages/component-schemas/package.json b/packages/component-schemas/package.json new file mode 100644 index 00000000..6af087e4 --- /dev/null +++ b/packages/component-schemas/package.json @@ -0,0 +1,28 @@ +{ + "name": "@adobe/spectrum-component-api-schemas", + "version": "0.0.0-schema-20240821152525", + "description": "", + "type": "module", + "main": "index.js", + "scripts": {}, + "repository": { + "type": "git", + "url": "git+https://github.com/adobe/spectrum-tokens.git" + }, + "author": "Garth Braithwaite (https://garthdb.com/)", + "bugs": { + "url": "https://github.com/adobe/spectrum-tokens/issues" + }, + "publishConfig": { + "provenance": true + }, + "homepage": "https://github.com/adobe/spectrum-tokens/tree/main/packages/component-schemas#readme", + "license": "Apache-2.0", + "dependencies": { + "glob": "^10.3.12" + }, + "devDependencies": { + "ajv": "^8.12.0", + "ajv-formats": "^3.0.1" + } +} diff --git a/packages/tokens/schemas/component.json b/packages/component-schemas/schemas/component.json similarity index 100% rename from packages/tokens/schemas/component.json rename to packages/component-schemas/schemas/component.json diff --git a/packages/tokens/schemas/components/action-bar.json b/packages/component-schemas/schemas/components/action-bar.json similarity index 100% rename from packages/tokens/schemas/components/action-bar.json rename to packages/component-schemas/schemas/components/action-bar.json diff --git a/packages/tokens/schemas/components/action-button.json b/packages/component-schemas/schemas/components/action-button.json similarity index 89% rename from packages/tokens/schemas/components/action-button.json rename to packages/component-schemas/schemas/components/action-button.json index 9486045f..9acf63fb 100644 --- a/packages/tokens/schemas/components/action-button.json +++ b/packages/component-schemas/schemas/components/action-button.json @@ -22,9 +22,8 @@ }, "size": { "type": "string", - "enum": ["s", "m", "l", "xl"], - "default": "m", - "pattern": "^(x?s|m|x{0,3}l)$" + "enum": ["xs", "s", "m", "l", "xl"], + "default": "m" }, "isQuiet": { "type": "boolean", @@ -40,7 +39,8 @@ }, "staticColor": { "type": "string", - "enum": ["white", "black"] + "enum": ["white", "black"], + "description": "Static color must not be set for the default version of this component." }, "selectedTextColor": { "$ref": "https://opensource.adobe.com/spectrum-tokens/schemas/types/hex-color.json" diff --git a/packages/tokens/schemas/components/action-group.json b/packages/component-schemas/schemas/components/action-group.json similarity index 100% rename from packages/tokens/schemas/components/action-group.json rename to packages/component-schemas/schemas/components/action-group.json diff --git a/packages/tokens/schemas/components/alert-banner.json b/packages/component-schemas/schemas/components/alert-banner.json similarity index 100% rename from packages/tokens/schemas/components/alert-banner.json rename to packages/component-schemas/schemas/components/alert-banner.json diff --git a/packages/tokens/schemas/components/alert-dialog.json b/packages/component-schemas/schemas/components/alert-dialog.json similarity index 100% rename from packages/tokens/schemas/components/alert-dialog.json rename to packages/component-schemas/schemas/components/alert-dialog.json diff --git a/packages/tokens/schemas/components/avatar.json b/packages/component-schemas/schemas/components/avatar.json similarity index 90% rename from packages/tokens/schemas/components/avatar.json rename to packages/component-schemas/schemas/components/avatar.json index f61c419a..8e28b0b5 100644 --- a/packages/tokens/schemas/components/avatar.json +++ b/packages/component-schemas/schemas/components/avatar.json @@ -15,7 +15,9 @@ "default": 100 }, "image": { - "type": "string" + "type": "string", + "enum": ["text", "image"], + "default": "image" }, "isDisabled": { "type": "boolean", diff --git a/packages/tokens/schemas/components/badge.json b/packages/component-schemas/schemas/components/badge.json similarity index 100% rename from packages/tokens/schemas/components/badge.json rename to packages/component-schemas/schemas/components/badge.json diff --git a/packages/tokens/schemas/components/body.json b/packages/component-schemas/schemas/components/body.json similarity index 100% rename from packages/tokens/schemas/components/body.json rename to packages/component-schemas/schemas/components/body.json diff --git a/packages/tokens/schemas/components/bottom-navigation-android.json b/packages/component-schemas/schemas/components/bottom-navigation-android.json similarity index 100% rename from packages/tokens/schemas/components/bottom-navigation-android.json rename to packages/component-schemas/schemas/components/bottom-navigation-android.json diff --git a/packages/tokens/schemas/components/breadcrumbs.json b/packages/component-schemas/schemas/components/breadcrumbs.json similarity index 100% rename from packages/tokens/schemas/components/breadcrumbs.json rename to packages/component-schemas/schemas/components/breadcrumbs.json diff --git a/packages/tokens/schemas/components/button-group.json b/packages/component-schemas/schemas/components/button-group.json similarity index 100% rename from packages/tokens/schemas/components/button-group.json rename to packages/component-schemas/schemas/components/button-group.json diff --git a/packages/tokens/schemas/components/button.json b/packages/component-schemas/schemas/components/button.json similarity index 92% rename from packages/tokens/schemas/components/button.json rename to packages/component-schemas/schemas/components/button.json index 25650650..345797b7 100644 --- a/packages/tokens/schemas/components/button.json +++ b/packages/component-schemas/schemas/components/button.json @@ -27,7 +27,8 @@ }, "staticColor": { "type": "string", - "enum": ["white", "black"] + "enum": ["white", "black"], + "description": "Static color must not be set for the default version of this component." }, "style": { "type": "string", diff --git a/packages/tokens/schemas/components/checkbox-group.json b/packages/component-schemas/schemas/components/checkbox-group.json similarity index 100% rename from packages/tokens/schemas/components/checkbox-group.json rename to packages/component-schemas/schemas/components/checkbox-group.json diff --git a/packages/tokens/schemas/components/checkbox.json b/packages/component-schemas/schemas/components/checkbox.json similarity index 100% rename from packages/tokens/schemas/components/checkbox.json rename to packages/component-schemas/schemas/components/checkbox.json diff --git a/packages/tokens/schemas/components/close-button.json b/packages/component-schemas/schemas/components/close-button.json similarity index 91% rename from packages/tokens/schemas/components/close-button.json rename to packages/component-schemas/schemas/components/close-button.json index b2fe7e46..83315b1a 100644 --- a/packages/tokens/schemas/components/close-button.json +++ b/packages/component-schemas/schemas/components/close-button.json @@ -20,7 +20,7 @@ "staticColor": { "type": "string", "enum": ["white", "black"], - "default": null + "description": "Static color must not be set for the default version of this component." }, "isDisabled": { "type": "boolean", diff --git a/packages/tokens/schemas/components/code.json b/packages/component-schemas/schemas/components/code.json similarity index 100% rename from packages/tokens/schemas/components/code.json rename to packages/component-schemas/schemas/components/code.json diff --git a/packages/tokens/schemas/components/color-area.json b/packages/component-schemas/schemas/components/color-area.json similarity index 100% rename from packages/tokens/schemas/components/color-area.json rename to packages/component-schemas/schemas/components/color-area.json diff --git a/packages/tokens/schemas/components/color-loupe.json b/packages/component-schemas/schemas/components/color-loupe.json similarity index 100% rename from packages/tokens/schemas/components/color-loupe.json rename to packages/component-schemas/schemas/components/color-loupe.json diff --git a/packages/tokens/schemas/components/color-slider.json b/packages/component-schemas/schemas/components/color-slider.json similarity index 100% rename from packages/tokens/schemas/components/color-slider.json rename to packages/component-schemas/schemas/components/color-slider.json diff --git a/packages/tokens/schemas/components/color-wheel.json b/packages/component-schemas/schemas/components/color-wheel.json similarity index 100% rename from packages/tokens/schemas/components/color-wheel.json rename to packages/component-schemas/schemas/components/color-wheel.json diff --git a/packages/tokens/schemas/components/combo-box.json b/packages/component-schemas/schemas/components/combo-box.json similarity index 100% rename from packages/tokens/schemas/components/combo-box.json rename to packages/component-schemas/schemas/components/combo-box.json diff --git a/packages/tokens/schemas/components/contextual-help.json b/packages/component-schemas/schemas/components/contextual-help.json similarity index 100% rename from packages/tokens/schemas/components/contextual-help.json rename to packages/component-schemas/schemas/components/contextual-help.json diff --git a/packages/tokens/schemas/components/detail.json b/packages/component-schemas/schemas/components/detail.json similarity index 100% rename from packages/tokens/schemas/components/detail.json rename to packages/component-schemas/schemas/components/detail.json diff --git a/packages/tokens/schemas/components/divider.json b/packages/component-schemas/schemas/components/divider.json similarity index 100% rename from packages/tokens/schemas/components/divider.json rename to packages/component-schemas/schemas/components/divider.json diff --git a/packages/tokens/schemas/components/field-label.json b/packages/component-schemas/schemas/components/field-label.json similarity index 100% rename from packages/tokens/schemas/components/field-label.json rename to packages/component-schemas/schemas/components/field-label.json diff --git a/packages/tokens/schemas/components/heading.json b/packages/component-schemas/schemas/components/heading.json similarity index 100% rename from packages/tokens/schemas/components/heading.json rename to packages/component-schemas/schemas/components/heading.json diff --git a/packages/tokens/schemas/components/help-text.json b/packages/component-schemas/schemas/components/help-text.json similarity index 100% rename from packages/tokens/schemas/components/help-text.json rename to packages/component-schemas/schemas/components/help-text.json diff --git a/packages/tokens/schemas/components/in-line-alert.json b/packages/component-schemas/schemas/components/in-line-alert.json similarity index 100% rename from packages/tokens/schemas/components/in-line-alert.json rename to packages/component-schemas/schemas/components/in-line-alert.json diff --git a/packages/tokens/schemas/components/link.json b/packages/component-schemas/schemas/components/link.json similarity index 90% rename from packages/tokens/schemas/components/link.json rename to packages/component-schemas/schemas/components/link.json index bd45e29d..55b1d6d7 100644 --- a/packages/tokens/schemas/components/link.json +++ b/packages/component-schemas/schemas/components/link.json @@ -21,7 +21,7 @@ "staticColor": { "type": "string", "enum": ["white", "black"], - "default": null + "description": "Static color must not be set for the default version of this component." }, "state": { "type": "string", diff --git a/packages/tokens/schemas/components/menu.json b/packages/component-schemas/schemas/components/menu.json similarity index 100% rename from packages/tokens/schemas/components/menu.json rename to packages/component-schemas/schemas/components/menu.json diff --git a/packages/tokens/schemas/components/meter.json b/packages/component-schemas/schemas/components/meter.json similarity index 100% rename from packages/tokens/schemas/components/meter.json rename to packages/component-schemas/schemas/components/meter.json diff --git a/packages/tokens/schemas/components/picker.json b/packages/component-schemas/schemas/components/picker.json similarity index 100% rename from packages/tokens/schemas/components/picker.json rename to packages/component-schemas/schemas/components/picker.json diff --git a/packages/tokens/schemas/components/popover.json b/packages/component-schemas/schemas/components/popover.json similarity index 98% rename from packages/tokens/schemas/components/popover.json rename to packages/component-schemas/schemas/components/popover.json index e3184032..a0a25889 100644 --- a/packages/tokens/schemas/components/popover.json +++ b/packages/component-schemas/schemas/components/popover.json @@ -10,7 +10,7 @@ "type": "object", "properties": { "width": { - "type": "integer" + "type": "number" }, "height": { "type": "number" diff --git a/packages/tokens/schemas/components/progress-bar.json b/packages/component-schemas/schemas/components/progress-bar.json similarity index 100% rename from packages/tokens/schemas/components/progress-bar.json rename to packages/component-schemas/schemas/components/progress-bar.json diff --git a/packages/tokens/schemas/components/progress-circle.json b/packages/component-schemas/schemas/components/progress-circle.json similarity index 100% rename from packages/tokens/schemas/components/progress-circle.json rename to packages/component-schemas/schemas/components/progress-circle.json diff --git a/packages/tokens/schemas/components/radio-group.json b/packages/component-schemas/schemas/components/radio-group.json similarity index 100% rename from packages/tokens/schemas/components/radio-group.json rename to packages/component-schemas/schemas/components/radio-group.json diff --git a/packages/tokens/schemas/components/rating.json b/packages/component-schemas/schemas/components/rating.json similarity index 87% rename from packages/tokens/schemas/components/rating.json rename to packages/component-schemas/schemas/components/rating.json index 2cd95f5f..69289000 100644 --- a/packages/tokens/schemas/components/rating.json +++ b/packages/component-schemas/schemas/components/rating.json @@ -10,9 +10,10 @@ "type": "object", "properties": { "value": { - "type": "integer", - "minimum": 0, - "maximum": 5 + "type": "number", + "enum": [0, 1, 2, 3, 4, 5], + "default": 0, + "description": "From 0 to 5" }, "isEmphasized": { "type": "boolean", diff --git a/packages/tokens/schemas/components/scroll-zoom-bar.json b/packages/component-schemas/schemas/components/scroll-zoom-bar.json similarity index 100% rename from packages/tokens/schemas/components/scroll-zoom-bar.json rename to packages/component-schemas/schemas/components/scroll-zoom-bar.json diff --git a/packages/component-schemas/schemas/components/search-field.json b/packages/component-schemas/schemas/components/search-field.json new file mode 100644 index 00000000..6fd4e1a5 --- /dev/null +++ b/packages/component-schemas/schemas/components/search-field.json @@ -0,0 +1,50 @@ +{ + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/component.json", + "$id": "https://opensource.adobe.com/spectrum-tokens/schemas/components/search-field.json", + "title": "Search field", + "description": "A search field is used for searching and filtering items.", + "meta": { + "category": "inputs", + "documentationUrl": "https://spectrum.adobe.com/page/search-field/" + }, + "type": "object", + "properties": { + "label": { + "type": "string" + }, + "value": { + "type": "string" + }, + "width": { + "type": "number" + }, + "size": { + "type": "string", + "enum": ["s", "m", "l", "xl"], + "default": "m", + "pattern": "^(x?s|m|x{0,3}l)$" + }, + "isQuiet": { + "type": "boolean", + "default": false + }, + "isDisabled": { + "type": "boolean", + "default": false + }, + "description": { + "type": "string" + }, + "state": { + "type": "string", + "enum": [ + "default", + "hover", + "focus + hover", + "focus + not hover", + "keyboard focus" + ], + "default": "default" + } + } +} diff --git a/packages/tokens/schemas/components/side-navigation.json b/packages/component-schemas/schemas/components/side-navigation.json similarity index 100% rename from packages/tokens/schemas/components/side-navigation.json rename to packages/component-schemas/schemas/components/side-navigation.json diff --git a/packages/tokens/schemas/components/slider.json b/packages/component-schemas/schemas/components/slider.json similarity index 100% rename from packages/tokens/schemas/components/slider.json rename to packages/component-schemas/schemas/components/slider.json diff --git a/packages/tokens/schemas/components/status-light.json b/packages/component-schemas/schemas/components/status-light.json similarity index 100% rename from packages/tokens/schemas/components/status-light.json rename to packages/component-schemas/schemas/components/status-light.json diff --git a/packages/tokens/schemas/components/swatch-group.json b/packages/component-schemas/schemas/components/swatch-group.json similarity index 100% rename from packages/tokens/schemas/components/swatch-group.json rename to packages/component-schemas/schemas/components/swatch-group.json diff --git a/packages/tokens/schemas/components/swatch.json b/packages/component-schemas/schemas/components/swatch.json similarity index 100% rename from packages/tokens/schemas/components/swatch.json rename to packages/component-schemas/schemas/components/swatch.json diff --git a/packages/tokens/schemas/components/switch.json b/packages/component-schemas/schemas/components/switch.json similarity index 100% rename from packages/tokens/schemas/components/switch.json rename to packages/component-schemas/schemas/components/switch.json diff --git a/packages/tokens/schemas/components/tab-bar-ios.json b/packages/component-schemas/schemas/components/tab-bar-ios.json similarity index 100% rename from packages/tokens/schemas/components/tab-bar-ios.json rename to packages/component-schemas/schemas/components/tab-bar-ios.json diff --git a/packages/component-schemas/schemas/components/tabs.json b/packages/component-schemas/schemas/components/tabs.json new file mode 100644 index 00000000..ef9f5cb4 --- /dev/null +++ b/packages/component-schemas/schemas/components/tabs.json @@ -0,0 +1,54 @@ +{ + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/component.json", + "$id": "https://opensource.adobe.com/spectrum-tokens/schemas/components/tabs.json", + "title": "Tabs", + "description": "Tabs organize content into multiple sections and allow users to navigate between them. The content under the set of tabs should be related and form a coherent unit.", + "meta": { + "category": "navigation", + "documentationUrl": "https://spectrum.adobe.com/page/tabs/" + }, + "type": "object", + "properties": { + "orientation": { + "type": "string", + "enum": ["horizontal", "vertical"], + "default": "vertical" + }, + "size": { + "type": "string", + "enum": ["s", "m", "l", "xl"], + "default": "m" + }, + "density": { + "type": "string", + "enum": ["compact", "regular"], + "default": "regular" + }, + "isFluid": { + "type": "boolean", + "default": false, + "description": "This overrides density and is only applicable to horizontal tabs." + }, + "isQuiet": { + "type": "boolean", + "default": false + }, + "isEmphasized": { + "type": "boolean", + "default": false + }, + "alignment": { + "type": "string", + "enum": ["start", "center"], + "default": "start" + }, + "selectedItem": { + "description": "(list of available items)" + }, + "keyboardActivation": { + "type": "string", + "enum": ["manual", "automatic"], + "default": "manual" + } + } +} diff --git a/packages/tokens/schemas/components/tag.json b/packages/component-schemas/schemas/components/tag.json similarity index 100% rename from packages/tokens/schemas/components/tag.json rename to packages/component-schemas/schemas/components/tag.json diff --git a/packages/tokens/schemas/components/text-area.json b/packages/component-schemas/schemas/components/text-area.json similarity index 100% rename from packages/tokens/schemas/components/text-area.json rename to packages/component-schemas/schemas/components/text-area.json diff --git a/packages/tokens/schemas/components/text-field.json b/packages/component-schemas/schemas/components/text-field.json similarity index 100% rename from packages/tokens/schemas/components/text-field.json rename to packages/component-schemas/schemas/components/text-field.json diff --git a/packages/tokens/schemas/components/toast.json b/packages/component-schemas/schemas/components/toast.json similarity index 100% rename from packages/tokens/schemas/components/toast.json rename to packages/component-schemas/schemas/components/toast.json diff --git a/packages/tokens/schemas/components/tooltip.json b/packages/component-schemas/schemas/components/tooltip.json similarity index 100% rename from packages/tokens/schemas/components/tooltip.json rename to packages/component-schemas/schemas/components/tooltip.json diff --git a/packages/tokens/schemas/components/tray.json b/packages/component-schemas/schemas/components/tray.json similarity index 100% rename from packages/tokens/schemas/components/tray.json rename to packages/component-schemas/schemas/components/tray.json diff --git a/packages/tokens/schemas/components/tree-view.json b/packages/component-schemas/schemas/components/tree-view.json similarity index 100% rename from packages/tokens/schemas/components/tree-view.json rename to packages/component-schemas/schemas/components/tree-view.json diff --git a/packages/tokens/schemas/types/hex-color.json b/packages/component-schemas/schemas/types/hex-color.json similarity index 100% rename from packages/tokens/schemas/types/hex-color.json rename to packages/component-schemas/schemas/types/hex-color.json diff --git a/packages/tokens/schemas/types/typography-classification.json b/packages/component-schemas/schemas/types/typography-classification.json similarity index 100% rename from packages/tokens/schemas/types/typography-classification.json rename to packages/component-schemas/schemas/types/typography-classification.json diff --git a/packages/tokens/schemas/types/typography-script.json b/packages/component-schemas/schemas/types/typography-script.json similarity index 100% rename from packages/tokens/schemas/types/typography-script.json rename to packages/component-schemas/schemas/types/typography-script.json diff --git a/packages/tokens/schemas/types/workflow-icon.json b/packages/component-schemas/schemas/types/workflow-icon.json similarity index 100% rename from packages/tokens/schemas/types/workflow-icon.json rename to packages/component-schemas/schemas/types/workflow-icon.json diff --git a/packages/tokens/test/componentSchemaValidator.test.js b/packages/component-schemas/test/componentSchemaValidator.test.js similarity index 100% rename from packages/tokens/test/componentSchemaValidator.test.js rename to packages/component-schemas/test/componentSchemaValidator.test.js diff --git a/packages/component-schemas/test/index.test.js b/packages/component-schemas/test/index.test.js new file mode 100644 index 00000000..77186d57 --- /dev/null +++ b/packages/component-schemas/test/index.test.js @@ -0,0 +1,78 @@ +/* +Copyright 2024 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +import { + schemaFileNames, + getSchemaFile, + getAllSchemas, + getSlugFromDocumentationUrl, + getAllSlugs, + __dirname, + getSchemaBySlug, +} from "../index.js"; +import test from "ava"; +import { glob } from "glob"; +import { resolve, parse } from "path"; + +test("the number of schema returned by getAllSchemas should match the number of schema returned by schemaFileNames", async (t) => { + const allSchemas = await getAllSchemas(); + t.is(schemaFileNames.length, allSchemas.length); +}); +test("getSchemaFile should fetch schema data", async (t) => { + const relativeSchemaComponent = await getSchemaFile("component.json"); + t.is(relativeSchemaComponent.title, "Component"); + + const relativeSchemaActionBar = await getSchemaFile( + "components/action-bar.json", + ); + t.is(relativeSchemaActionBar.title, "Action bar"); + + const absoluteSchemaComponent = await getSchemaFile( + resolve(__dirname, "schemas", "component.json"), + ); + t.is(absoluteSchemaComponent.title, "Component"); + + const absoluteSchemaActionBar = await getSchemaFile( + resolve(__dirname, "schemas", "components", "action-bar.json"), + ); + t.is(absoluteSchemaActionBar.title, "Action bar"); + // t.snapshot(await getSchemaFile(schemaFileNames[0])); +}); +test("getSlugFromDocumentationUrl should return last part of documentationUrl", (t) => { + t.is( + getSlugFromDocumentationUrl("https://spectrum.adobe.com/page/tooltip/"), + "tooltip", + ); +}); +test("getSlugFromDocumentationUrl should return last part of documentationUrl even without trailing slash", (t) => { + t.is( + getSlugFromDocumentationUrl("https://spectrum.adobe.com/page/tooltip"), + "tooltip", + ); +}); +test("getAllSlugs should return all component slugs", async (t) => { + const slugs = await glob( + `${resolve(__dirname, "./schemas/components")}/**/*.json`, + ); + t.deepEqual( + await getAllSlugs(), + slugs.map((slug) => parse(slug).name).sort(), + ); +}); +test("getSchemaBySlug should return a schema", async (t) => { + t.deepEqual( + await getSchemaBySlug("tooltip"), + await getSchemaFile( + resolve(__dirname, "./schemas/components/tooltip.json"), + ), + ); +}); diff --git a/packages/component-schemas/test/snapshots/index.test.js.md b/packages/component-schemas/test/snapshots/index.test.js.md new file mode 100644 index 00000000..c3fe6ada --- /dev/null +++ b/packages/component-schemas/test/snapshots/index.test.js.md @@ -0,0 +1,51 @@ +# Snapshot report for `test/index.test.js` + +The actual snapshot is saved in `index.test.js.snap`. + +Generated by [AVA](https://avajs.dev). + +## getSchemaFile should fetch schema data + +> Snapshot 1 + + { + $id: 'https://opensource.adobe.com/spectrum-tokens/schemas/component.json', + $schema: 'https://json-schema.org/draft/2020-12/schema', + properties: { + meta: { + properties: { + category: { + enum: [ + 'actions', + 'containers', + 'data visualization', + 'feedback', + 'inputs', + 'navigation', + 'status', + 'typography', + ], + type: 'string', + }, + documentationUrl: { + format: 'uri', + type: 'string', + }, + }, + required: [ + 'category', + 'documentationUrl', + ], + type: 'object', + }, + }, + required: [ + 'meta', + 'title', + 'description', + 'properties', + '$id', + ], + title: 'Component', + type: 'object', + } diff --git a/packages/component-schemas/test/snapshots/index.test.js.snap b/packages/component-schemas/test/snapshots/index.test.js.snap new file mode 100644 index 00000000..92c69a34 Binary files /dev/null and b/packages/component-schemas/test/snapshots/index.test.js.snap differ diff --git a/packages/tokens/schemas/components/tabs.json b/packages/tokens/schemas/components/tabs.json deleted file mode 100644 index 10eeeb59..00000000 --- a/packages/tokens/schemas/components/tabs.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/component.json", - "$id": "https://opensource.adobe.com/spectrum-tokens/schemas/components/tabs.json", - "title": "Tabs", - "description": "Tabs organize content into multiple sections and allow users to navigate between them. The content under the set of tabs should be related and form a coherent unit.", - "meta": { - "category": "navigation", - "documentationUrl": "https://spectrum.adobe.com/page/tabs/" - }, - "type": "object", - "properties": { - "label": { - "type": "string" - }, - "icon": { - "$ref": "https://opensource.adobe.com/spectrum-tokens/schemas/types/workflow-icon.json" - }, - "isSelected": { - "type": "boolean", - "default": false - }, - "isDisabled": { - "type": "boolean", - "default": false - }, - "state": { - "type": "string", - "enum": ["default", "hover", "down", "keyboard focus"], - "default": "default" - } - } -} diff --git a/packages/tokens/schemas/types/component-size.json b/packages/tokens/schemas/types/component-size.json deleted file mode 100644 index e7283124..00000000 --- a/packages/tokens/schemas/types/component-size.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://opensource.adobe.com/spectrum-tokens/schemas/types/component-size.json", - "title": "component-size", - "description": "T-shirt sizes for components", - "type": "string", - "enum": ["xs", "s", "m", "l", "xl", "xxl", "xxxl"] -} diff --git a/packages/tokens/test/schemaValidator.test.js b/packages/tokens/test/schemaValidator.test.js deleted file mode 100644 index e7504bb4..00000000 --- a/packages/tokens/test/schemaValidator.test.js +++ /dev/null @@ -1,74 +0,0 @@ -/* -Copyright 2024 Adobe. All rights reserved. -This file is licensed to you under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. You may obtain a copy -of the License at http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under -the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS -OF ANY KIND, either express or implied. See the License for the specific language -governing permissions and limitations under the License. -*/ - -import test from "ava"; -import Ajv from "ajv/dist/2020.js"; -import addFormats from "ajv-formats"; -import { glob } from "glob"; -import { readFile } from "fs/promises"; - -const readJSON = async (filePath) => - JSON.parse(await readFile(filePath, "utf8")); -const componentSchema = await readJSON("schemas/component.json"); - -const fileNames = await glob("schemas/components/*.json"); -const files = await Promise.all( - fileNames.map(async (fileName) => { - return { fileName, json: await readJSON(fileName) }; - }), -); - -const ajv = new Ajv(); -addFormats(ajv); -ajv.addMetaSchema(componentSchema); -const schemaFiles = await glob("schemas/types/*.json"); -for (const schemaFile of schemaFiles) { - const schema = await readJSON(schemaFile); - ajv.addSchema(schema); -} - -for (const keyword of Object.keys(componentSchema.properties)) { - ajv.addKeyword({ keyword, metaSchema: componentSchema.properties[keyword] }); -} - -test("component schema should be valid", async (t) => { - const valid = ajv.validateSchema(componentSchema); - t.true(valid); -}); - -test("Every component schema should validate against the definition", (t) => { - let valid = true; - for (const file of files) { - if (!ajv.validateSchema(file.json)) { - valid = false; - console.log(`${file.fileName} failed validation`); - console.log(ajv.errors); - } - } - t.true(valid); -}); - -test("component examples should validate against the definition", (t) => { - let valid = true; - for (const file of files) { - const validate = ajv.compile(file.json); - if (!Object.hasOwn(file.json, "examples")) file.json.examples = []; - for (const example of file.json.examples) { - if (!validate(example)) { - valid = false; - console.log(`${file.fileName} failed validation`); - console.log(validate.errors); - } - } - } - t.true(valid); -}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d995b4bb..62b326a0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -142,6 +142,19 @@ importers: specifier: ^5.3.4 version: 5.4.0(@types/node@20.14.14) + packages/component-schemas: + dependencies: + glob: + specifier: ^10.3.12 + version: 10.4.2 + devDependencies: + ajv: + specifier: ^8.12.0 + version: 8.16.0 + ajv-formats: + specifier: ^3.0.1 + version: 3.0.1(ajv@8.16.0) + packages/tokens: devDependencies: ajv: