2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
title: Adding options
|
|
|
|
order: 140
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-02-20 14:35:50 +01:00
|
|
|
You know what your bib should look like, and you have the _head_ measurement
|
2021-08-25 16:09:31 +02:00
|
|
|
to work with. But there's still a number of choices you have to make:
|
|
|
|
|
2022-02-20 14:44:38 +01:00
|
|
|
- How large should the neck opening be?
|
|
|
|
- How wide should the bib be?
|
|
|
|
- How long should the bib be?
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
You can make all of these choices for the user and set them in stone, so to speak.
|
|
|
|
|
|
|
|
But since you're designing a pattern in code, it's trivial to make your pattern
|
|
|
|
flexible and let the user decide. All you have to do is add options to your pattern.
|
|
|
|
|
|
|
|
## Add the neckRatio option
|
|
|
|
|
2022-02-19 08:04:25 +01:00
|
|
|
The first option we're going to add controls the ratio between the neck opening
|
2021-08-25 16:09:31 +02:00
|
|
|
and the head circumference. Let's call it `neckRatio`.
|
|
|
|
|
2022-07-02 22:52:31 +02:00
|
|
|
Open the config file at `design/config.js` and add this to the options:
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
```js
|
|
|
|
options: {
|
|
|
|
// Remove this size option
|
|
|
|
//size: { pct: 50, min: 10, max: 100 }
|
|
|
|
// And add the neckRatio options
|
|
|
|
neckRatio: { pct: 80, min: 70, max: 90 },
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Can you guess what it means?
|
|
|
|
|
2022-02-20 14:44:38 +01:00
|
|
|
- We've added a option of type percentage
|
|
|
|
- Its minimum value is 70%
|
|
|
|
- Its maximum value is 90%
|
|
|
|
- Its default value is 80%
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
<Note>
|
|
|
|
|
|
|
|
There are different types of options, but percentages are the most common ones.
|
2022-04-30 14:07:54 -04:00
|
|
|
They are all documented [in the API docs](/reference/api/config/options).
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
</Note>
|
|
|
|
|
|
|
|
Let's do something similar for the width and length of our bib:
|
|
|
|
|
|
|
|
```js
|
|
|
|
options: {
|
|
|
|
neckRatio: { pct: 80, min: 70, max: 90 },
|
|
|
|
widthRatio: { pct: 45, min: 35, max: 55 },
|
2021-08-25 16:16:51 +02:00
|
|
|
lengthRatio: { pct: 75, min: 55, max: 85 },
|
2021-08-25 16:09:31 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-02-20 14:44:38 +01:00
|
|
|
- You've added `widthRatio` and `lengthRatio` options
|
|
|
|
- You've given all options sensible defaults
|
|
|
|
- You've given all options sensible maximum and minimum boundaries
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
<Note>
|
|
|
|
|
|
|
|
Later, you'll test-drive your pattern to see how it behaves when you adapt the options
|
|
|
|
between their minimum and maximum values. At that time, you can still tweak these values.
|
|
|
|
|
|
|
|
</Note>
|
|
|
|
|
2022-07-02 22:52:31 +02:00
|
|
|
Before you close the `design/config.js` file, make sure to update the `optionGroups` entry as follows:
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
```js
|
|
|
|
optionGroups: {
|
|
|
|
fit: ["neckRatio", "widthRatio", "lengthRatio"]
|
|
|
|
},
|
|
|
|
```
|
|
|
|
|
|
|
|
<Note>
|
|
|
|
|
2022-02-19 08:04:25 +01:00
|
|
|
The `optionGroups` entry does not do anything for your pattern as such.
|
2021-08-25 16:09:31 +02:00
|
|
|
Instead it signals to the frontend that this is how options should be grouped together and presented to the user.
|
|
|
|
|
|
|
|
</Note>
|
|
|
|
|
|
|
|
Because you have removed the `box` option, the pattern no longer draws a box.
|
|
|
|
So let's start drawing your bib instead.
|