Skip to content

Commit

Permalink
add colour picker for intro title, subtitle and button
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Coulson committed Jan 13, 2025
1 parent 2f3e83f commit 4acec50
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 5 deletions.
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"url": "^0.11.3",
"uuid": "^9.0.0",
"vue": "^3.4.37",
"vue-accessible-color-picker": "^5.1.1",
"vue-class-component": "^8.0.0-rc.1",
"vue-final-modal": "^4.4.5",
"vue-i18n": "^9.2.2",
Expand Down
95 changes: 95 additions & 0 deletions src/components/helpers/colour-picker-input.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<template>
<div class="flex flex-col items-start relative">
<div class="metadata-input flex flex-col p-0 w-full">
<div class="flex">
<div
@click="togglePicker"
@keypress.enter="togglePicker"
:style="{ 'background-color': selectedColour }"
:class="!disabled ? 'cursor-pointer' : ''"
class="flex flex-1 rounded w-10 mr-1"
:tabindex="!disabled ? 0 : -1"
v-tippy="{
delay: '200',
placement: 'top',
content: !disabled
? isOpen
? $t('editor.colourPicker.close')
: $t('editor.colourPicker.open')
: '',
animateFill: true
}"
>
<span v-if="isOpen" class="text-white mx-auto self-center font-bold mix-blend-difference">X</span>
</div>
<input
:disabled="disabled"
class="text-center my-2"
:aria-label="name"
:value="selectedColour"
@input="(evt) => selectedColour = (evt.target as HTMLInputElement).value"
/>
</div>
<ColorPicker
v-if="isOpen"
:color="value"
alpha-channel="hide"
:visible-formats="['hex']"
default-format="hex"
@color-change="(evt: any) => this.selectedColour = evt.cssColor"
>
<template #copy-button></template>
</ColorPicker>
</div>
</div>
</template>

<script lang="ts">
import { Prop, Vue, Watch } from 'vue-property-decorator';
export default class LoadingPageV extends Vue {
@Prop() value!: string;
@Prop() name!: string;
@Prop() disabled?: boolean;
isOpen: boolean = false;
selectedColour: string = '';
beforeMount(): void {
this.selectedColour = this.value;
}
/**
* If component is enabled, toggle the colour picker visibility.
*/
togglePicker(): void {
if (!this.disabled) this.isOpen = !this.isOpen;
}
/**
* Watches the selectedColour property and emits a change event when it changes. The event emitted mimics an "HTMLInputEvent" so that
* we don't need to make any modifications to the `metadataChanged` event listener in `metadata-content.vue`.
* @param evt a string representing the new colour value.
*/
@Watch('selectedColour')
colourChanged(evt: Event): void {
// If the value didn't change, don't fire the event.
if (this.value === this.selectedColour) return;
this.$emit('change', {
target: {
name: this.name,
value: this.selectedColour
}
});
}
}
</script>

<style scoped lang="scss">
:deep(.vacp-color-inputs),
:deep(.vacp-copy-button),
:deep(.vacp-range-input-label-text--hue) {
display: none;
}
</style>
37 changes: 36 additions & 1 deletion src/components/helpers/metadata-content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,35 @@
</div>
<p v-if="!editing">{{ metadata.logoAltText || $t('editor.metadataForm.na') }}</p>
</div>
<div class="flex flex-wrap gap-4">
<div class="metadata-item">
<span class="metadata-label">{{ $t('editor.introTitleColour') }}</span>
<ColourPickerInput
name="titleColour"
:value="metadata.titleColour"
@change="metadataChanged"
:disabled="!editing"
/>
</div>
<div class="metadata-item">
<span class="metadata-label">{{ $t('editor.introSubtitleColour') }}</span>
<ColourPickerInput
name="subtitleColour"
:value="metadata.subtitleColour"
@change="metadataChanged"
:disabled="!editing"
/>
</div>
<div class="metadata-item">
<span class="metadata-label">{{ $t('editor.introButtonColour') }}</span>
<ColourPickerInput
name="buttonColour"
:value="metadata.buttonColour"
@change="metadataChanged"
:disabled="!editing"
/>
</div>
</div>
</section>
</section>
<!-- Section: End of page information -->
Expand Down Expand Up @@ -239,8 +268,14 @@

<script lang="ts">
import { MetadataContent } from '@/definitions';
import { Prop, Vue } from 'vue-property-decorator';
import { Options, Prop, Vue } from 'vue-property-decorator';
import ColourPickerInput from './colour-picker-input.vue';
@Options({
components: {
ColourPickerInput: ColourPickerInput
}
})
export default class MetadataEditorV extends Vue {
@Prop() metadata!: MetadataContent;
@Prop({ default: true }) editing!: boolean;
Expand Down
20 changes: 19 additions & 1 deletion src/components/metadata-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,9 @@ export default class MetadataEditorV extends Vue {
logoPreview: '',
logoName: '',
logoAltText: '',
titleColour: '#1f2937',
subtitleColour: '#6b7280',
buttonColour: '#00d2d3',
contextLink: '',
contextLabel: '',
tocOrientation: '',
Expand All @@ -695,6 +698,9 @@ export default class MetadataEditorV extends Vue {
logoPreview: '',
logoName: '',
logoAltText: '',
titleColour: '',
subtitleColour: '',
buttonColour: '',
contextLink: '',
contextLabel: '',
tocOrientation: '',
Expand Down Expand Up @@ -917,7 +923,10 @@ export default class MetadataEditorV extends Vue {
src: ''
},
title: this.metadata.introTitle,
subtitle: this.metadata.introSubtitle
subtitle: this.metadata.introSubtitle,
titleColour: this.metadata.titleColour,
subtitleColour: this.metadata.subtitleColour,
buttonColour: this.metadata.buttonColour
},
slides: [],
contextLabel: this.metadata.contextLabel,
Expand Down Expand Up @@ -1295,6 +1304,9 @@ export default class MetadataEditorV extends Vue {
this.metadata.title = config.title;
this.metadata.introTitle = config.introSlide.title;
this.metadata.introSubtitle = config.introSlide.subtitle;
this.metadata.titleColour = config.introSlide.titleColour ?? '#1f2937';
this.metadata.subtitleColour = config.introSlide.subtitleColour ?? '#6b7280';
this.metadata.buttonColour = config.introSlide.buttonColour ?? '#00d2d3';
this.metadata.contextLink = config.contextLink;
this.metadata.contextLabel = config.contextLabel;
this.metadata.tocOrientation = config.tocOrientation;
Expand Down Expand Up @@ -1510,6 +1522,9 @@ export default class MetadataEditorV extends Vue {
config.title = this.metadata.title;
config.introSlide.title = this.metadata.introTitle;
config.introSlide.subtitle = this.metadata.introSubtitle;
config.introSlide.titleColour = this.metadata.titleColour;
config.introSlide.subtitleColour = this.metadata.subtitleColour;
config.introSlide.buttonColour = this.metadata.buttonColour;
config.contextLink = this.metadata.contextLink;
config.contextLabel = this.metadata.contextLabel;
config.tocOrientation = this.metadata.tocOrientation;
Expand Down Expand Up @@ -1557,6 +1572,9 @@ export default class MetadataEditorV extends Vue {
title: '',
introTitle: '',
introSubtitle: '',
titleColour: '',
subtitleColour: '',
buttonColour: '',
contextLink: '',
contextLabel: '',
dateModified: '',
Expand Down
6 changes: 6 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export interface MetadataContent {
logoPreview: string;
logoName: string;
logoAltText: string;
titleColour?: string;
subtitleColour?: string;
buttonColour?: string;
contextLink: string;
contextLabel: string;
tocOrientation: string;
Expand Down Expand Up @@ -133,6 +136,9 @@ export interface Intro {
title: string;
subtitle: string;
blurb?: string;
titleColour?: string;
subtitleColour?: string;
buttonColour?: string;
}

export interface Slide {
Expand Down
5 changes: 5 additions & 0 deletions src/lang/lang.csv
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ editor.logoPreview,Logo preview,1,Aperçu du logo,1
editor.logoPreviewAltText,Preview of product logo,1,Aperçu du logo du produit,0
editor.logoAltText,Logo alt text,1,Lien contextuel,1
editor.logoAltText.desc,"For accessibility purposes, provide description text for the logo.",1,"Pour des raisons d'accessibilité, fournissez un texte descriptif pour le logo.",0
editor.introTitleColour,"Title colour",1,Couleur du titre,0
editor.introSubtitleColour,"Subtitle colour",1,Couleur du sous-titre,0
editor.introButtonColour,"Button colour",1,Couleur du bouton,0
editor.colourPicker.open,Open colour picker,1,Ouvrir le sélecteur de couleur,0
editor.colourPicker.close,Close colour picker,1,Fermer le sélecteur de couleur,0
editor.contextLink,Context link,1,Lien contextuel,1
editor.contextLink.info,Context link shows up at the bottom of the page to provide additional resources for interested users.,1,Le lien contextuel apparaît au bas de la page et fournit des ressources supplémentaires aux utilisateurs intéressés.,1
editor.contextLabel,Context label,1,Étiquette de contexte,1
Expand Down
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import HighchartsVue from 'highcharts-vue';
import Message from 'vue-m-message';
import 'vue-m-message/dist/style.css';

import ColorPicker from 'vue-accessible-color-picker';
import 'vue-accessible-color-picker/styles';

import StorylinesViewer from 'ramp-storylines_demo-scenarios-pcar';
import 'ramp-storylines_demo-scenarios-pcar/dist/style.css';

Expand All @@ -51,6 +54,7 @@ app.use(pinia)
.use(Message)
.use(StorylinesViewer)
.use(VueMarkdownEditor)
.use(ColorPicker)
.use(vfm);

app.directive('focus-container', FocusContainer);
Expand Down
1 change: 1 addition & 0 deletions src/shims-vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ declare module 'vue-m-message';
declare module 'vue3-json-editor';
declare module 'highcharts-vue';
declare module 'vue-tippy';
declare module 'vue-accessible-color-picker';

0 comments on commit 4acec50

Please sign in to comment.