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

feat: Group color tiles by name #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 91 additions & 25 deletions src/components/Canvas/Sections/Colors.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
<template>
<div>
<StickySectionHeader id="section-colors">
<ButtonGroup>
<Button
class="w-full sm:w-32"
:selected="selectedProp === 'backgroundColor'"
@click="selectedProp = 'backgroundColor'"
>
Background
</Button>
<Button
class="w-full sm:w-32"
:selected="selectedProp === 'textColor'"
@click="selectedProp = 'textColor'"
>
Text
</Button>
<Button
class="w-full sm:w-32"
:selected="selectedProp === 'borderColor'"
@click="selectedProp = 'borderColor'"
>
Border
</Button>
</ButtonGroup>
<div class="flex">
<ButtonGroup>
<Button
class="w-full sm:w-32"
:selected="selectedProp === 'backgroundColor'"
@click="selectedProp = 'backgroundColor'"
>
Background
</Button>
<Button
class="w-full sm:w-32"
:selected="selectedProp === 'textColor'"
@click="selectedProp = 'textColor'"
>
Text
</Button>
<Button
class="w-full sm:w-32"
:selected="selectedProp === 'borderColor'"
@click="selectedProp = 'borderColor'"
>
Border
</Button>
</ButtonGroup>
<span class="flex items-center mx-4 dark:text-white">
<input type="checkbox" id="groupColors" v-model="groupColors" class="mr-2">
<label class="cursor-pointer" for="groupColors">Group colors</label>
</span>
</div>
</StickySectionHeader>
<div class="flex flex-wrap -mb-4 mt-6">

<div v-if="!groupColors" class="flex flex-wrap -mb-4 mt-6">
<div
v-for="(value, prop) in selectedColorItems"
:key="prop"
Expand All @@ -49,6 +56,33 @@
/>
</div>
</div>

<template v-else>
<div v-for="(items, groupName) in groupedColorItems" :key="groupName">
<h3 class="text-xl mt-6 mb-2 font-semibold capitalize dark:text-white">{{ groupName }}</h3>
<ul class="flex-container">
<li v-for="item in items" :key="item.id" class="flex-item">
<div
class="mb-2 flex-none w-full md:w-36 h-16 md:h-36 flex items-center justify-center"
:class="{'border border-gray-300': selectedProp === 'textColor'}"
:style="tileStyle(item.value)"
>
<span
class="text-3xl"
:style="{
color: item.value
}"
v-if="selectedProp === 'textColor'">Aa</span>
</div>
<CanvasBlockLabel
:label="`${selectedPropClassPrefix}-${item.key}`"
:value="item.value"
/>
</li>
</ul>
</div>
</template>

</div>
</template>

Expand All @@ -75,7 +109,8 @@ export default {

data () {
return {
selectedProp: 'backgroundColor'
selectedProp: 'backgroundColor',
groupColors: false
}
},

Expand All @@ -84,6 +119,10 @@ export default {
return this.data[this.selectedProp]
},

groupedColorItems () {
return this.groupColorByName(this.selectedColorItems)
},

selectedPropClassPrefix () {
const map = {
backgroundColor: 'bg',
Expand All @@ -108,7 +147,34 @@ export default {
border: `2px solid ${value}`
}
}
},
groupColorByName (items) {
const groups = {}
for (const key in items) {
if (items.hasOwnProperty(key)) {
const group = key.substring(0, key.lastIndexOf('-'))
if (!groups[group]) {
groups[group] = []
}
groups[group].push({ key, value: items[key] })
}
}
return groups
}
}
}
</script>

<style>
.flex-container {
display: flex;
flex-wrap: wrap;
gap: 16px;
justify-content: flex-start;
align-items: flex-start;
}

.flex-item {
flex-basis: 5%;
}
</style>