generated from it-at-m/oss-repository-en-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#716: add set increase contrast logic in app
- Loading branch information
1 parent
1b77249
commit 3516f0e
Showing
8 changed files
with
190 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
digiwf-apps/packages/apps/digiwf-tasklist/src/components/UI/ContrastModeSelection.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<script lang="ts"> | ||
import {defineComponent} from "vue"; | ||
import {useTheme} from "../../plugins/vuetify"; | ||
import {useAccessibility} from "../../store/modules/accessibility"; | ||
export default defineComponent({ | ||
setup: () => { | ||
const theme = useTheme(); | ||
const {isHighContrastModeEnabled, setHighContrastModeEnabled} = useAccessibility(); | ||
const changeMode = () => { | ||
const isEnabled = isHighContrastModeEnabled(); | ||
if (isEnabled) { | ||
theme.deactivateContrastMode(); | ||
} else { | ||
theme.activateContrastMode(); | ||
} | ||
setHighContrastModeEnabled(!isEnabled); | ||
}; | ||
return { | ||
onClick: changeMode, | ||
isHighContrastModeEnabled | ||
}; | ||
} | ||
}); | ||
</script> | ||
|
||
<template> | ||
<button | ||
:aria-label="isHighContrastModeEnabled() ? 'Hohen Kontrast deaktivieren' : 'Hohen Kontrast aktivieren'" | ||
@click.stop="onClick" > | ||
{{ isHighContrastModeEnabled() ? "Hohen Kontrast deaktivieren" : "Hohen Kontrast aktivieren" }} | ||
</button> | ||
</template> | ||
|
||
<style scoped> | ||
</style> |
68 changes: 59 additions & 9 deletions
68
digiwf-apps/packages/apps/digiwf-tasklist/src/plugins/vuetify.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,72 @@ | ||
import '@mdi/font/css/materialdesignicons.css'; | ||
import Vue from 'vue'; | ||
import Vue, {getCurrentInstance} from 'vue'; | ||
import Vuetify from 'vuetify'; | ||
import {VuetifyThemeVariant} from "vuetify/types/services/theme"; | ||
import store from '../store'; | ||
|
||
Vue.use(Vuetify); | ||
|
||
export const lightTheme: Partial<VuetifyThemeVariant> = { | ||
primary: '#ff7c02', | ||
secondary: '#333333', | ||
accent: '#7BA4D9', | ||
success: '#69BE28', | ||
error: '#FF0000', | ||
|
||
}; | ||
|
||
export const highContrastTheme: Partial<VuetifyThemeVariant> = { | ||
primary: { | ||
base: "#000000", | ||
lighten5: "#FFF3E0", | ||
lighten4: "#FFE0B2", | ||
lighten3: "#FFCC80", | ||
lighten2: "#FFB74D", | ||
lighten1: "#FFA726", | ||
darken1: "#FB8C00", | ||
darken2: "#F57C00", | ||
darken3: "#EF6C00", | ||
darken4: "#E65100" | ||
}, | ||
secondary: '#ff0000', | ||
accent: '#acff1c', | ||
success: '#008dff', | ||
error: '#d24eff', | ||
anchor: "#ffea4b" | ||
|
||
}; | ||
|
||
// https://medium.com/@jogarcia/vuetify-multiple-themes-c580f41ece65 | ||
const theme = { | ||
themes: { | ||
light: { | ||
primary: '#ff7c02', | ||
secondary: '#333333', | ||
accent: '#7BA4D9', | ||
success: '#69BE28', | ||
error: '#FF0000', | ||
}, | ||
light: store.getters["accessibility/isHighContrastModeEnabled"] ? highContrastTheme : lightTheme, | ||
}, | ||
options: {customProperties: true}, // enable css vars | ||
}; | ||
|
||
export default new Vuetify({ | ||
const vuetify = new Vuetify({ | ||
theme: theme | ||
}); | ||
|
||
export const useVuetify = () => { | ||
const instance = getCurrentInstance(); | ||
if (!instance) { | ||
throw new Error("useVuetify should be called in setup()."); | ||
} | ||
return instance.proxy.$vuetify; | ||
}; | ||
|
||
export const useTheme = () => { | ||
const vuetify = useVuetify(); | ||
return { | ||
currentTheme: vuetify.theme.currentTheme, | ||
activateContrastMode: () => { | ||
vuetify.theme.themes.light = highContrastTheme as any; | ||
}, | ||
deactivateContrastMode: () => { | ||
vuetify.theme.themes.light = lightTheme as any; | ||
}, | ||
}; | ||
}; | ||
|
||
export default vuetify; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
digiwf-apps/packages/apps/digiwf-tasklist/src/store/modules/accessibility.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {accessibility, AccessibilityState} from "./accessibility"; | ||
|
||
describe("accessibility", () => { | ||
describe("getters:isHighContrastModeEnabled", () => { | ||
it("should return current value if high contrast mode is set to false", () => { | ||
const state: AccessibilityState = { | ||
highContrastModeEnabled: false, | ||
}; | ||
const result = accessibility.getters.isHighContrastModeEnabled(state); | ||
expect(result).toBeFalsy(); | ||
|
||
}); | ||
it("should return current value if high contrast mode is set to true", () => { | ||
const state: AccessibilityState = { | ||
highContrastModeEnabled: true, | ||
}; | ||
const result = accessibility.getters.isHighContrastModeEnabled(state); | ||
expect(result).toBeTruthy(); | ||
}); | ||
it("should return default value false if no value is set", () => { | ||
const state: AccessibilityState = { | ||
highContrastModeEnabled: undefined, | ||
} as any; // so that we can set value to undefined | ||
const result = accessibility.getters.isHighContrastModeEnabled(state); | ||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
digiwf-apps/packages/apps/digiwf-tasklist/src/store/modules/accessibility.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {useStore} from "../../hooks/store"; | ||
|
||
export interface AccessibilityState { | ||
highContrastModeEnabled: boolean; | ||
} | ||
|
||
const defaultAccessibilityState: AccessibilityState = { | ||
highContrastModeEnabled: false, | ||
}; | ||
|
||
export const accessibility = { | ||
namespaced: true, | ||
state:defaultAccessibilityState, | ||
getters: { | ||
isHighContrastModeEnabled: (state: AccessibilityState): boolean => { | ||
return state.highContrastModeEnabled !== undefined | ||
? state.highContrastModeEnabled | ||
: state.highContrastModeEnabled; | ||
} | ||
}, | ||
mutations: { | ||
setHighContrastModeEnabled: (state: AccessibilityState, enabled: boolean) => state.highContrastModeEnabled = enabled, | ||
} | ||
}; | ||
export const useAccessibility = () => { | ||
const store = useStore(); | ||
return { | ||
isHighContrastModeEnabled: () => store.getters["accessibility/isHighContrastModeEnabled"], | ||
setHighContrastModeEnabled: (enabled: boolean) => store.commit("accessibility/setHighContrastModeEnabled", enabled), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters