변형
블록 변형API을 사용하면 기존 블록에 사용자 지정 변형을 등록할 수 있습니다.
간단한 선택 필드의 값에 따라 두 가지 변형이 표시되는 블록을 만든다고 가정해 보겠습니다.
JSON
{
"$schema": "https://blockstudio.dev/schema/block",
"name": "blockstudio/variations",
"title": "Native Variation",
"description": "Native Blockstudio Variation block.",
"icon": "star-filled",
"variations": [
{
"name": "variation-2",
"title": "Native Variation 2",
"description": "Native Blockstudio Variation block 2.",
"attributes": {
"select": {
"value": "variation-2"
}
}
}
],
"blockstudio": {
"attributes": [
{
"id": "select",
"type": "select",
"label": "Select",
"options": [
{
"value": "variation-1",
"label": "Variation 1"
},
{
"value": "variation-2",
"label": "Variation 2"
}
],
"default": {
"value": "variation-1"
}
}
]
}
}
위 코드는 삽입기에 기본 블록 하나와 변형 두 개, 총 세 개의 블록을 만듭니다.
속성 숨기기
속성은 사이드바에 적절한 입력 필드를 자동으로 표시합니다. 변형 블록은 특정 속성값에 따라 동작하므로 사이드바에서 해당 필드를 숨기고 싶을 수 있습니다. 그러려면 hidden 옵션을 사용하세요.
JSON
{
"blockstudio": {
"attributes": [
{
"id": "select",
"type": "select",
"label": "Select",
"hidden": true,
"options": [
{
"value": "variation-1",
"label": "Variation 1"
},
{
"value": "variation-2",
"label": "Variation 2"
}
]
}
]
}
}