139 lines
3.6 KiB
Python
139 lines
3.6 KiB
Python
from grapple.helpers import register_streamfield_block
|
|
from grapple.models import (
|
|
GraphQLImage,
|
|
GraphQLPage,
|
|
GraphQLStreamfield,
|
|
GraphQLString,
|
|
)
|
|
from wagtail import blocks
|
|
from wagtail.images.blocks import ImageChooserBlock
|
|
|
|
|
|
@register_streamfield_block
|
|
class ImageWithTextBlock(blocks.StructBlock):
|
|
image = ImageChooserBlock(
|
|
label="Bilde",
|
|
)
|
|
image_format = blocks.ChoiceBlock(
|
|
choices=[
|
|
("fullwidth", "Fullbredde"),
|
|
("bleed", "Utfallende"),
|
|
("original", "Uendret størrelse"),
|
|
],
|
|
default="fullwidth",
|
|
icon="cup",
|
|
label="Bildeformat",
|
|
)
|
|
text = blocks.CharBlock(
|
|
label="Tekst",
|
|
required=False,
|
|
max_length=512,
|
|
)
|
|
|
|
graphql_fields = [
|
|
GraphQLImage("image", required=True),
|
|
GraphQLString("image_format", required=True),
|
|
GraphQLString("text"),
|
|
]
|
|
|
|
class Meta:
|
|
icon = "image"
|
|
|
|
|
|
@register_streamfield_block
|
|
class ImageSliderItemBlock(blocks.StructBlock):
|
|
image = ImageChooserBlock(
|
|
label="Bilde",
|
|
)
|
|
text = blocks.CharBlock(
|
|
label="Tekst",
|
|
required=False,
|
|
max_length=512,
|
|
)
|
|
|
|
graphql_fields = [GraphQLImage("image", required=True), GraphQLString("text")]
|
|
|
|
class Meta:
|
|
icon = "image"
|
|
|
|
|
|
@register_streamfield_block
|
|
class ImageSliderBlock(blocks.StructBlock):
|
|
images = blocks.ListBlock(
|
|
ImageSliderItemBlock(),
|
|
min_num=1,
|
|
label="Bilder",
|
|
)
|
|
|
|
graphql_fields = [GraphQLStreamfield("images", required=True)]
|
|
|
|
class Meta:
|
|
icon = "image"
|
|
|
|
|
|
@register_streamfield_block
|
|
class HorizontalRuleBlock(blocks.StructBlock):
|
|
COLOR_CHOICES = (
|
|
("deepBrick", "Dyp tegl"),
|
|
("neufPink", "Griserosa"),
|
|
("goldenOrange", "Gyllen oransje"),
|
|
("goldenBeige", "Gyllen beige"),
|
|
("chateauBlue", "Slottsblå"),
|
|
)
|
|
|
|
color = blocks.ChoiceBlock(
|
|
label="Farge",
|
|
required=False,
|
|
choices=COLOR_CHOICES,
|
|
)
|
|
|
|
graphql_fields = [GraphQLString("color", required=False)]
|
|
|
|
class Meta:
|
|
icon = "minus"
|
|
|
|
|
|
@register_streamfield_block
|
|
class FeaturedBlock(blocks.StructBlock):
|
|
IMAGE_POSITION_CHOICES = (
|
|
("left", "Venstre"),
|
|
("right", "Høyre"),
|
|
)
|
|
|
|
title = blocks.CharBlock(max_length=64, required=True, label="Tittel")
|
|
text = blocks.RichTextBlock(features=["bold", "italic", "link"], required=True, label="Tekst")
|
|
featured_page = blocks.PageChooserBlock(header="Fremhevet side", required=True)
|
|
link_text = blocks.CharBlock(
|
|
max_length=64,
|
|
label="Lenketekst",
|
|
default="Les mer",
|
|
required=True,
|
|
help_text='Lenketeksten som tar deg videre til siden. Tips: Ikke start med "Trykk her"',
|
|
)
|
|
image_position = blocks.ChoiceBlock(
|
|
required=True,
|
|
choices=IMAGE_POSITION_CHOICES,
|
|
label="Bildeplassering",
|
|
)
|
|
featured_image_override = ImageChooserBlock(
|
|
header="Overstyr bilde",
|
|
help_text=(
|
|
"Bildet som er tilknyttet undersiden du vil fremheve, vil automatisk brukes. "
|
|
"Om det mangler eller du vil overstyre hvilket bilde som et brukes, "
|
|
"kan du velge et her."
|
|
),
|
|
required=False,
|
|
)
|
|
|
|
graphql_fields = [
|
|
GraphQLString("title", required=True),
|
|
GraphQLString("text", required=True),
|
|
GraphQLString("link_text", required=True),
|
|
GraphQLString("image_position", required=True),
|
|
GraphQLImage("featured_image_override"),
|
|
GraphQLPage("featured_page", required=True),
|
|
]
|
|
|
|
class Meta:
|
|
icon = "arrow-right-full"
|