-
Notifications
You must be signed in to change notification settings - Fork 46
API Formats
Topic | Guidelines |
---|---|
Boolean | Try to use the predefined boolean words |
String | Use the predefined conventions for levels and hierarchy |
Value of None | Don't use null and undefined
|
string-prop-name:
type: string
title: Prop Name
description: Prop description sentence.
default: medium
enum:
- large
- medium
- small
boolean-prop-name:
type: boolean
title: Prop Name
description: Prop description sentence.
default: false
- If you want a behavior that defaults to TRUE, then use a negative boolean prop. For example, if images should lazy load by default, use a "nolazy" prop so that users must explicitly opt out.
- This allows web components to always get the default value by simply omitting the prop
Changing the default is always a breaking change because usages that require the previous default would not have been passing a value at all.
For example, if images lazy loaded by default and you wanted to not lazy load by default, you'd have to:
- Add a new boolean property that did the opposite of the old one. In this case, you'd add "lazy" to replace the existing "nolazy"
- Remove the old property. This would have to be done in a major release, because it's impossible to write an adaptor for it.
The following are examples of positive and negative boolean naming. When possible, use a value from this table when adding a boolean prop.
Note that all the words in the table are adjectives or verbs. If your prop name makes more sense as a noun (e.g. "subtitles"), you should prefix it with a modifier like is
or has
(e.g. "has-subtitles").
Positive Boolean | Negative Boolean | Neutral Boolean |
---|---|---|
indeterminate | ||
loop | unloop | |
autoplay | noautoplay | |
checked | unchecked | |
enabled | disabled | |
active | inactive | |
selected | unselected | |
toggled | untoggled | |
interactive | nointeractive | |
styled | unstyled | |
clicked | unclicked | |
rounded | unrounded | |
visible | hidden, visuallyhidden |
If it's boolean, use boolean. If it's more than just true or false, use string.
{% include "@bolt/component-name.twig" with {
rounded: "rounded"
} %}
theme:
type: string
title: 'Theme'
description: 'Color theme options.'
default: xlight
enum:
- xlight
- light
- dark
- xdark
- none
In the above example, to truly remove theme, one has to explicitly set it to none. Since that's not boolean, true, false, and null would not work, only values from the schema would work. But these values won't be invalid, they will just return the schema default.
The following is invalid, don't do it.
{% include "@bolt/component-name.twig" with {
prop1: null,
prop2: ""
} %}
- Basic A11y Checklist
- Get started with Bolt locally
- Bolt Specific Standards and Conventions
- How to save SVG graphics and SVG icons
- Upgrade to minor release
- Upgrade to 4.x
- Upgrade to 5.x
- Release Workflow
- VS Code Configuration
- Bolt Doc Writing Guide
- Prefixing Custom Attributes
- Standard Props for Passing Content in Twig
- Building Websites with Bolt in Drupal
- From Design Mockup to Code
- Override with Utility Classes