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
|
|
|
|
2023-01-06 19:29:29 -08:00
|
|
|
We know what our bib should look like, and we have the _head_ measurement
|
|
|
|
to work with. But there's still a number of choices we have to make:
|
2021-08-25 16:09:31 +02:00
|
|
|
|
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
|
|
|
|
2023-01-06 19:29:29 -08:00
|
|
|
We can make all of these choices for the user and set them in stone, so to speak.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2023-01-06 19:29:29 -08:00
|
|
|
But since we're designing a pattern in code, it's trivial to make our pattern
|
|
|
|
flexible and let the user decide. All we have to do is add options to our part.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
## 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-10-09 23:47:32 +02:00
|
|
|
We'll add a new `options` key to our part object for this:
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-09 23:47:32 +02:00
|
|
|
```design/src/bib.mjs
|
|
|
|
function draftBib({ part }) {
|
|
|
|
|
|
|
|
return part
|
|
|
|
}
|
|
|
|
|
|
|
|
export const bib = {
|
2023-08-06 14:00:10 +00:00
|
|
|
|
2022-10-09 23:47:32 +02:00
|
|
|
name: 'tutorial.bib',
|
2023-08-08 13:20:46 -05:00
|
|
|
draft: draftBib,
|
2023-08-06 14:00:10 +00:00
|
|
|
from: false,
|
|
|
|
hide: {
|
2023-08-08 13:20:46 -05:00
|
|
|
self: false,
|
|
|
|
from: false,
|
|
|
|
after: false
|
2023-08-06 14:00:10 +00:00
|
|
|
},
|
2022-10-11 01:37:09 +02:00
|
|
|
// highlight-start
|
2021-08-25 16:09:31 +02:00
|
|
|
options: {
|
2023-01-06 19:29:29 -08:00
|
|
|
neckRatio: { pct: 80, min: 70, max: 90, menu: 'fit' },
|
2022-10-09 23:47:32 +02:00
|
|
|
},
|
2022-10-11 01:37:09 +02:00
|
|
|
// highlight-end
|
2023-08-06 14:00:10 +00:00
|
|
|
measurements: [],
|
|
|
|
optionalMeasurements: [],
|
|
|
|
plugins: []
|
2022-10-09 23:47:32 +02:00
|
|
|
}
|
2023-08-06 14:00:10 +00:00
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
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%
|
2022-10-09 23:47:32 +02:00
|
|
|
- We've added this option to the *fit* menu
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
<Note>
|
|
|
|
|
|
|
|
There are different types of options, but percentages are the most common ones.
|
2022-10-09 23:47:32 +02:00
|
|
|
They are all documented [in the part reference docs](/reference/api/part/config/options).
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
</Note>
|
|
|
|
|
2022-10-09 23:47:32 +02:00
|
|
|
## Add the widthRatio and lengthRatio options
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
Let's do something similar for the width and length of our bib:
|
|
|
|
|
2022-10-09 23:47:32 +02:00
|
|
|
```design/src/bib.mjs
|
2021-08-25 16:09:31 +02:00
|
|
|
options: {
|
2023-01-06 19:29:29 -08:00
|
|
|
neckRatio: { pct: 80, min: 70, max: 90, menu: 'fit' },
|
|
|
|
widthRatio: { pct: 45, min: 35, max: 55, menu: 'style' },
|
|
|
|
lengthRatio: { pct: 75, min: 55, max: 85, menu: 'style' },
|
2021-08-25 16:09:31 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2023-01-06 19:29:29 -08:00
|
|
|
- We've added `widthRatio` and `lengthRatio` options
|
|
|
|
- We've given all options sensible defaults
|
|
|
|
- We've given all options sensible maximum and minimum boundaries
|
|
|
|
- We've added these two new options to the *style* menu
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2023-01-06 19:29:29 -08:00
|
|
|
Later, we'll test-drive our pattern to see how it behaves when we adapt the options
|
|
|
|
between their minimum and maximum values. At that time, we can still tweak these values.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-09 23:47:32 +02:00
|
|
|
With that out of the way, let's start drawing our bib.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-09 23:47:32 +02:00
|
|
|
## Notes
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2023-01-06 19:29:29 -08:00
|
|
|
The `menu` key on an option does not do anything for our pattern as such.
|
2022-10-09 23:47:32 +02:00
|
|
|
Instead it signals to the frontend that this is how options should be grouped
|
|
|
|
together and presented to the user.
|