Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style Modes #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 59 additions & 14 deletions schemas/entity-styles.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,55 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Entity Styles",
"type": "object",
"definitions": {
"styles": {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to suggestions on better structuring of the schema

How I'd write the TS types:

type Image = {
  uri: string
  alt: string
}

type Color = {
  color: string
}

type BaseESD = {
  thumbnail: Image
  hero: Image
  background: Color
  text: Color
}

type StyleMode = {
  mode: string
  styles: BaseESD
}

type BasicESD = BaseESD & {
  style_mode: StyleMode
}

type ThemedESD = {
  light: BasicESD
  dark: BasicESD
}

type ESD = BasicESD | ThemedESD

"type": "object",
"additionalProperties": false,
"properties": {
"thumbnail": {
"$ref": "#/definitions/image"
},
"hero": {
"$ref": "#/definitions/image"
},
"background": {
"$ref": "#/definitions/color"
},
"text": {
"$ref": "#/definitions/color"
},
"style_modes": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"mode": { "type": "string" },
"styles": { "$ref": "#/definitions/nestedStyles" }
},
"required": ["mode", "styles"]
}
}
}
},
"nestedStyles": {
"type": "object",
"additionalProperties": false,
"properties": {
"thumbnail": {
"$ref": "#/definitions/image"
},
"hero": {
"$ref": "#/definitions/image"
},
"background": {
"$ref": "#/definitions/color"
},
"text": {
"$ref": "#/definitions/color"
}
}
},
"image": {
"type": "object",
"properties": {
Expand All @@ -27,18 +74,16 @@
"required": ["color"]
}
},
"properties": {
"thumbnail": {
"$ref": "#/definitions/image"
},
"hero": {
"$ref": "#/definitions/image"
},
"background": {
"$ref": "#/definitions/color"
},
"text": {
"$ref": "#/definitions/color"
"oneOf": [
{ "$ref": "#/definitions/styles" },
{
"type": "object",
"minProperties": 1,
"additionalProperties": false,
"properties": {
"light": { "$ref": "#/definitions/styles" },
"dark": { "$ref": "#/definitions/styles" }
}
}
}
]
}
32 changes: 31 additions & 1 deletion spec/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ _Entity Style Descriptors_ are a resource format that defines a set of suggested
```
:::

An _Entity Style Descriptor_ ****must**** be an object composed in one of the follow ways:

An _Entity Style Descriptor_ ****must**** be an object composed of the following properties:
### Basic

- The object ****MAY**** contain a `thumbnail` property, and if present, its value ****MUST**** be an object with the following optional properties:
- The object ****MUST**** contain a `uri` property, and if present its value ****MUST**** be a valid URI string to an image resource.
Expand All @@ -69,6 +70,35 @@ An _Entity Style Descriptor_ ****must**** be an object composed of the following
- The object ****MAY**** contain a `color` property, and if present its value ****MUST**** be a HEX string color value (e.g. #000000).
- The object ****MAY**** contain a `text` property, and if present, its value ****MUST**** be an object with the following optional properties:
- The object ****MAY**** contain a `color` property, and if present its value ****MUST**** be a HEX string color value (e.g. #000000).
- The object ****MAY**** contain a `style_modes` property, and if present, its value ****MUST**** be an array of [ref:Style Mode Objects].

### Light and Dark Mode

::: example Light and Dark Mode
```json
[[insert: ./test/entity-styles/simple-light-dark.json]]
```
:::

- The object ****MAY**** contain `light` and/or `dark` properties, and if present, their values ****MUST**** be Basic Entity Style Descriptors

## Entity Style Modes

::: example Modes
```json
[[insert: ./test/entity-styles/simple-light-dark.json]]
```
:::

A _Entity Style Mode_ ****must**** be an object composed of the following properties:

- The object ****MUST**** contain a `mode` property and its value ****MUST**** be a string
- This string ****MUST**** be unique within the containing `style_modes` array
- The object ****MUST**** contain a `styles` property and its value ****MUST**** be a [ref:Entity Style Descriptor] omitting the `style_modes` property

### Applying Modes

When a style mode its `styles` property ****MUST**** be merged with its containing [ref:Entity Style Descriptor]

## Data Display

Expand Down
44 changes: 44 additions & 0 deletions test/entity-styles/modes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"light": {
"thumbnail": {
"uri": "https://dol.wa.com/logo.png",
"alt": "Washington State Seal"
},
"hero": {
"uri": "https://dol.wa.com/people-working.png",
"alt": "People working on serious things"
},
"background": {
"color": "#ff0000"
},
"text": {
"color": "#d4d400"
},
"style_modes": [
{
"mode": "red-green-color-blind",
"styles": {
"background": {
"color": "#800080"
}
}
}
]
},
"dark": {
"thumbnail": {
"uri": "https://dol.wa.com/logo-alt.png",
"alt": "Washington State Seal"
},
"hero": {
"uri": "https://dol.wa.com/people-working-alt.png",
"alt": "People working on serious things"
},
"background": {
"color": "#00FFFF"
},
"text": {
"color": "#0000D4"
}
}
}
34 changes: 34 additions & 0 deletions test/entity-styles/simple-light-dark.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"light": {
"thumbnail": {
"uri": "https://dol.wa.com/logo.png",
"alt": "Washington State Seal"
},
"hero": {
"uri": "https://dol.wa.com/people-working.png",
"alt": "People working on serious things"
},
"background": {
"color": "#ff0000"
},
"text": {
"color": "#d4d400"
}
},
"dark": {
"thumbnail": {
"uri": "https://dol.wa.com/logo-alt.png",
"alt": "Washington State Seal"
},
"hero": {
"uri": "https://dol.wa.com/people-working-alt.png",
"alt": "People working on serious things"
},
"background": {
"color": "#00FFFF"
},
"text": {
"color": "#0000D4"
}
}
}