Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image blocks: add pattern background #6430

Merged
merged 9 commits into from
Jul 25, 2024
11 changes: 11 additions & 0 deletions panel/lab/components/block/3_figure/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
/>
</k-block-figure>
</k-lab-example>
<k-lab-example label="Back">
<k-block-figure
caption="This is a nice caption"
back="var(--pattern-light)"
>
<k-image-frame
ratio="16/9"
src="https://fakeimg.pl/1200x600/ff0000,0/333333,255/?text=Pattern"
/>
</k-block-figure>
</k-lab-example>
<k-lab-example label="Video">
<k-block-figure caption="This is a nice caption">
<k-frame :cover="true" ratio="16/9">
Expand Down
14 changes: 12 additions & 2 deletions panel/lab/components/frames/4_color/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
/>
</k-grid>
</k-lab-example>
<k-lab-example label="Pattern">
<k-grid style="--columns: 3; gap: var(--spacing-6)">
<k-color-frame
v-for="ratio in ratios"
:key="ratio"
:ratio="ratio"
color="var(--pattern)"
/>
</k-grid>
</k-lab-example>
</k-lab-examples>
</template>

Expand All @@ -33,7 +43,7 @@ export default {
computed: {
ratios() {
return ["1/1", "4/3", "16/9"];
},
},
}
}
};
</script>
4 changes: 2 additions & 2 deletions panel/src/components/Forms/Blocks/Block.vue
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export default {
<style>
.k-block-container {
position: relative;
padding: 0.75rem;
padding: var(--spacing-3);
background: var(--color-white);
border-radius: var(--rounded);
}
Expand Down Expand Up @@ -384,7 +384,7 @@ export default {
display: none;
position: absolute;
top: 0;
inset-inline-end: 0.75rem;
inset-inline-end: var(--spacing-3);
margin-top: calc(-1.75rem + 2px);
}
.k-block-container[data-last-selected="true"] > .k-block-options {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<template>
<div class="k-block-background-dropdown">
<k-button
:dropdown="true"
size="xs"
variant="filled"
@click="$refs.dropdown.toggle()"
>
<k-color-frame :color="value" ratio="1/1" />
</k-button>
<k-dropdown-content
ref="dropdown"
align-x="end"
:options="[
{ text: 'White', click: 'var(--color-white)' },
{
text: 'Pattern (light)',
click: 'var(--pattern-light)'
},
{ text: 'Pattern (dark)', click: 'var(--pattern)' }
]"
@action="$emit('input', $event)"
/>
</div>
</template>

<script>
export default {
props: {
value: String
}
};
</script>

<style>
.k-block-background-dropdown > .k-button {
--color-frame-size: 1.25rem;
--button-height: 1.5rem;
--button-padding: 0.125rem;
gap: 0.25rem;
box-shadow: var(--shadow);
}

.k-block .k-block-background-dropdown {
position: absolute;
inset-inline-end: var(--spacing-3);
bottom: var(--spacing-3);
opacity: 0;
transition: opacity 0.2s ease-in-out;
}
.k-block:hover .k-block-background-dropdown {
opacity: 1;
}
</style>
28 changes: 18 additions & 10 deletions panel/src/components/Forms/Blocks/Elements/BlockFigure.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template>
<figure class="k-block-figure">
<figure
:data-empty="isEmpty"
:style="{ '--block-figure-back': back }"
class="k-block-figure"
>
<k-button
v-if="isEmpty"
:disabled="disabled"
Expand All @@ -16,22 +20,22 @@
>
<slot />
</span>
<figcaption v-if="caption">
<k-writer
:disabled="disabled"
:inline="true"
:marks="captionMarks"
:value="caption"
@input="$emit('update', { caption: $event })"
/>
</figcaption>

<k-block-figure-caption
v-if="caption"
:disabled="disabled"
:marks="captionMarks"
:value="caption"
@input="$emit('update', { caption: $event })"
/>
</figure>
</template>

<script>
export default {
inheritAttrs: false,
props: {
back: String,
caption: String,
captionMarks: {
default: true,
Expand All @@ -47,6 +51,10 @@ export default {
</script>

<style>
.k-block-figure:not([data-empty="true"]) {
--block-figure-back: var(--color-white);
background: var(--block-figure-back);
}
.k-block-figure-container:not([data-disabled="true"]) {
cursor: pointer;
}
Expand Down
40 changes: 40 additions & 0 deletions panel/src/components/Forms/Blocks/Elements/BlockFigureCaption.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<template>
<figcaption class="k-block-figure-caption">
<k-writer
:disabled="disabled"
:inline="true"
:marks="marks"
:spellcheck="false"
:value="value"
@input="$emit('input', $event)"
/>
</figcaption>
</template>

<script>
export default {
props: {
disabled: Boolean,
marks: [Array, Boolean],
value: String
}
};
</script>

<style>
.k-block-figure-caption {
display: flex;
justify-content: center;
padding-top: var(--spacing-3);
}
.k-block-figure-caption .k-writer {
width: max-content;
text-align: center;
}

.k-block-figure-caption .k-writer .k-text {
color: var(--color-gray-600);
font-size: var(--text-sm);
mix-blend-mode: exclusion;
}
</style>
1 change: 0 additions & 1 deletion panel/src/components/Forms/Blocks/Types/Fields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import Block from "./Default.vue";
export default {
extends: Block,
props: {
endpoints: Object,
tabs: Object
},
data() {
Expand Down
63 changes: 46 additions & 17 deletions panel/src/components/Forms/Blocks/Types/Gallery.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<figure>
<figure :data-empty="isEmpty" :style="{ '--block-back': back }">
<ul @dblclick="open">
<template v-if="!content.images?.length">
<template v-if="isEmpty">
<li
v-for="index in 3"
:key="index"
Expand All @@ -20,17 +20,17 @@
:alt="image.alt"
/>
</li>

<k-block-background-dropdown :value="back" @input="onBack" />
</template>
</ul>
<figcaption v-if="content.caption">
<k-writer
:disabled="disabled"
:inline="true"
:marks="captionMarks"
:value="content.caption"
@input="$emit('update', { caption: $event })"
/>
</figcaption>
<k-block-figure-caption
v-if="content.caption"
:disabled="disabled"
:marks="captionMarks"
:value="content.caption"
@input="$emit('update', { caption: $event })"
/>
</figure>
</template>

Expand All @@ -42,21 +42,52 @@ import Block from "./Default.vue";
*/
export default {
extends: Block,
data() {
return {
back: this.onBack() ?? "white"
};
},
computed: {
captionMarks() {
return this.field("caption", { marks: true }).marks;
},
crop() {
return this.content.crop;
},
isEmpty() {
return !this.content.images?.length;
},
ratio() {
return this.content.ratio;
}
},
methods: {
onBack(value) {
const id = `kirby.galleryBlock.${this.endpoints.field}.${this.id}`;

if (value !== undefined) {
this.back = value;
sessionStorage.setItem(id, value);
} else {
return sessionStorage.getItem(id);
}
}
}
};
</script>

<style>
.k-block-container.k-block-container-type-gallery {
padding: 0;
}
.k-block-type-gallery > figure {
padding: var(--spacing-3);
border-radius: var(--rounded);
}
.k-block-type-gallery > figure:not([data-empty="true"]) {
background: var(--block-back);
}

.k-block-type-gallery ul {
display: grid;
grid-gap: 0.75rem;
Expand All @@ -68,16 +99,14 @@ export default {
.k-block-type-gallery:not([data-disabled="true"]) ul {
cursor: pointer;
}
.k-block-type-gallery ul .k-image-frame {
border-radius: var(--rounded-sm);
}

.k-block-type-gallery[data-disabled="true"] .k-block-type-gallery-placeholder {
background: var(--color-gray-250);
}
.k-block-type-gallery-placeholder {
background: var(--color-background);
}
.k-block-type-gallery figcaption {
padding-top: 0.5rem;
color: var(--color-gray-600);
font-size: var(--text-sm);
text-align: center;
}
</style>
Loading
Loading